When you do a near call, it pushes eip onto the stack. Before paging is enabled, this eip will be the physical address to return to after the call, which (because the label immediately follows the call) is the physical address of the label. By popping that back into eax, we now have to physical address of the label in eax. It would be easier if we could just say 'mov eax, eip' but you can't do that.
Now that we have the physical address of that one place, we can do a couple of different things. If you just want that one physical address, you're all done, its in eax. If you want the physical address of other things, we can calculate the offset from the linked address to the physical address by subtracting the linked address of the label. Then we have an offset that we can add to any linked address (including that label, any other label, any other variable, etc) to get the physical address.
That just reminded me of one thing. You can't move a value directly into your 'var' because that will be resolved to its linked address, so a command like
Will end up looking something like
Or whatever the linked address of the variable is. To actually access this variable before enabling paging and mapping the linked address to the physical address, you need to use that offset we found whenever dealing with any non-relative code (such as variable and label locations), so what you really want is:
Which will end up looking something like
Code: Select all
mov [0xc000023d + 0x40000000], eax
or
mov [0x10023d], eax
Assuming that your linked address was 0xc0000000 and the kernel was loaded at 0x100000
i hope this makes it a little clearer...
- Brandon