So I have to allocate 56 bytes (sizeof(Tos) on 386) of space above
the
top of stack (before copying argc and argv) and set AX to that
address, correct?
Yes. And you need to maintain it.
At the very least you need to initialize tos->pid
and update it on return from rfork.
I set EAX before starting the executable, but still no luck :(
On Plan 9, for /bin/mk:
acid: symbols("_tos")
_tos D 0x00016084
acid: mem(0x00016084, "X")
0xdfffefc8
I'm probing address 0x16084 on linux after every instruction (using
ptrace's singlestep), and it consistently returns 0. EIP at the
beginning of the program is 0x9fe4, and sure enough:
acid: asm(0x9fe4)
_main SUBL $0x48, SP
_main+0x3 MOVL AX, _tos(SB)
...
So (MOVL, _tos(SB)) is definitely executed, but for some reason, the
value of AX is not stored in 0x16084. That brings me to the question
of how 8a decides what address to put values like that in? Is the
address the same everytime, i.e. hardcoded into the binary? (certainly
seems to be)
I strip the symbol table from plan 9 executables and store only data,
text and initialize bss in memory - maybe that has something to do
with it. Does the symbol table need to be in memory too for
instructions like (MOVL AX, _tos(SB)) to work?
Regards,
Anant