Nasm: issues with writing to .text section
Posted: Tue Oct 09, 2007 5:04 am
I'm compiling my OS on a different computer that has a later version of NASM than I'm used to.
I have a variable, initialEsp that I use to record the stack pointer as GRUB gives it (So I can move the stack elsewhere later in remapStack). Before, I had something like:
And that worked fine. I declared initialEsp as extern in my .cc files and everything was happy. However, the latest version of NASM doesn't like programs writing to the .text section. (It screams fatal at me)
So I decided to try putting it in the .bss or .data sections - no joy, they get linked to some random location (0xf004 or something equally troublesome). So I tried declaring initialEsp in one of my .cc files and extern'ing it in my NASM boot file. No joy - ended up trying to write to 0x0 (I was observing the effects of these in objdump, as well as by trying to run the program).
In the end I opted for a major hack-o-rama:
Which works, but I don't like hacks and this is a mother of one!
anyone got any ideas? I assume FASM will work the same way.
Cheers
James
I have a variable, initialEsp that I use to record the stack pointer as GRUB gives it (So I can move the stack elsewhere later in remapStack). Before, I had something like:
Code: Select all
initialEsp:
dd 0
--code here--
So I decided to try putting it in the .bss or .data sections - no joy, they get linked to some random location (0xf004 or something equally troublesome). So I tried declaring initialEsp in one of my .cc files and extern'ing it in my NASM boot file. No joy - ended up trying to write to 0x0 (I was observing the effects of these in objdump, as well as by trying to run the program).
In the end I opted for a major hack-o-rama:
Code: Select all
start: ;This is where all my multiboot stuff goes
dd 0 ; I added this line to reserve some space at 0x100000
dd MULTIBOOT BLEH
dd MULTIBOOT_MORE_BLEH
...
absolute 0x100000
initialEsp resw 2 ; initialEsp = 2 words (4 bytes) at 0x100000.
[SECTION .text] ; back to text section
--code--
anyone got any ideas? I assume FASM will work the same way.
Cheers
James