commit cc8fe1a7405f48e3ca08f6559c01b4b305cc7db5
parent 43548acf4c60f144ed9892d9e8a6ff105de197de
Author: erai <erai@omiltem.net>
Date: Sat, 30 Mar 2024 11:21:00 -0400
ud2 at end of _start
Diffstat:
4 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/as.c b/as.c
@@ -63,6 +63,7 @@ enum {
OP_HLT = 0xf4,
OP_NOP = 0x90,
OP_WBINVD = 0x0f09,
+ OP_UD2 = 0x0f0b,
OP_INVLPGM = 0x070f01,
OP_LLDM = 0x020f00,
@@ -606,6 +607,10 @@ emit_add(c: *assembler) {
as_opr(c, OP_PUSHR, R_RAX);
}
+emit_ud(c: *assembler) {
+ as_op(c, OP_UD2);
+}
+
emit_ret(c: *assembler) {
as_opr(c, OP_POPR, R_RAX);
as_modrr(c, OP_MOVE, R_RSP, R_RBP);
diff --git a/cc0.c b/cc0.c
@@ -4918,6 +4918,12 @@ tfunc(struct decl *d)
tstmt(d->body);
emit_num(0);
+
+ if (!cmp(d->name, (unsigned char *)"_start")) {
+ emit(0x0f);
+ emit(0x0b);
+ }
+
emit_ret();
}
diff --git a/cc1.c b/cc1.c
@@ -350,6 +350,11 @@ compile_func(c: *compiler, d: *decl) {
emit_preamble(c.as, offset, pragma);
compile_stmt(c, d, d.func_def.b, 0:*label, 0:*label);
emit_num(c.as, 0);
+
+ if (pragma) {
+ emit_ud(c.as);
+ }
+
emit_ret(c.as);
}
diff --git a/kernel.c b/kernel.c
@@ -1,7 +1,6 @@
// in out iretq rdmsr wrmsr wrcr rdcr lgdt lldt lidt ltr hlt cli sti syscall sysret wbinvld invlpg
_start() {
- loop { }
}
ru32(p: *byte): int {