ref: 8107a788ff769af07e522f6972653949b3c13046
parent: e80a611c3978315ffbec1fabad9fd742696c7609
author: 9ferno <[email protected]>
date: Mon Jan 17 15:54:03 EST 2022
working forth pexit need to fix why JMP terminate(SB) does not work though
--- a/os/pc64/bindings.s
+++ b/os/pc64/bindings.s
@@ -141,7 +141,32 @@
MOVQ 32(SP), CX /* read return value == 0, check if fd is stdin */
TESTQ CX, CX
JNZ fsread_continue
- JMP terminate(SB) /* and fd == 0, terminate */
+ /* and fd == 0, terminate */
+ ADDQ $40, SP
+ /* TODO
+ * this should have been JMP terminate(SB), but it is raising a #GP error.
+ * CALL terminate(SB) works fine.
+ * Would have to dig through the amd64 manuals and
+ * https://www.felixcloutier.com/x86/jmp to figure out why.
+ * until then, use the label to jump to
+
+JMP to a label: JMP _fthterminate
+2011b8 4883c428 (644) ADDQ $40,SP
+2011bc e9d0fcffff (493) JMP ,200e91
+2011c1 4883c428 (656) ADDQ $40,SP
+
+JMP to symbol: JMP terminate(SB)
+2011b8 4883c428 (645) ADDQ $40,SP
+2011bc ff2425910e2000 (654) JMP ,terminate+0(SB)
+2011c3 4883c428 (657) ADDQ $40,SP
+
+CALL to symbol: CALL terminate(SB)
+2011b8 4883c428 (645) ADDQ $40,SP
+2011bc e8d0fcffff (655) CALL ,200e91+terminate
+2011c1 4883c428 (657) ADDQ $40,SP
+ */
+ JMP _fthterminate
+ /* TODO fix this JMP terminate(SB) */
fsread_continue:
ADDQ $40, SP
--- a/os/pc64/forth.s
+++ b/os/pc64/forth.s
@@ -245,10 +245,11 @@
NEXT
TEXT terminate(SB), 1, $-4 /* ( n -- ) */
+_fthterminate:
MOVQ TOP, AX
RET
-TEXT fthdump(SB), 1, $-4 /* ( n -- ) */
+TEXT fthdump(SB), 1, $8 /* ( n -- ) */
INT $0
CALL dumpstack(SB)
RET
--- a/os/port/devforth.c
+++ b/os/port/devforth.c
@@ -329,8 +329,8 @@
forthentry(void *fmem)
{
up->type = Forth;
- loadforthdictionary((u8*)fmem);
+ loadforthdictionary((u8*)fmem);
/* load dictionary */
print("forthentry pid %d forthmem 0x%zx end 0x%zx forthmem+RSTACK 0x%zx\n",
up->pid, (intptr)fmem, ((intptr*)fmem)[1], (intptr)fmem+RSTACK);
@@ -341,11 +341,6 @@
poperror();
}else
forthmain((u8*)fmem);
- print("after forthmain\n");
-/*for(;;){
-up->state = Moribund;
-sched();
-}*/
free(fmem);
flock();
@@ -358,7 +353,6 @@
}
nforthprocs--;
funlock();
- print("before pexit\n");
pexit("exit", 0);
}
@@ -835,7 +829,8 @@
snprint(path, 64, "#f/forth/%ud/ctl", p->pid);
free(c->path);
c->path = newpath(path);
- print("forthopen: new proc pid %d slot %d SLOT(c->qid) %d chanpath(c) %s c->aux 0x%p\n",
+ print("forthopen: new proc pid %d slot %d SLOT(c->qid) %d chanpath(c) %s\n"
+ " c->aux 0x%p\n",
p->pid, slot, SLOT(c->qid), chanpath(c), c->aux);
}
funlock();