NASM and ORG directive after short jmp
Posted: Sat Dec 01, 2018 5:16 am
Hello cloud of wisdom!
Novice level OS dev here.
I am struggling to find a solution to a conceptual question I am having. I hope you guys could help with it.
I am rolling my own bootloader and so far I am doing good progress (slow pace but learning a lot).
This is the situation I have right now, which works perfectly:
* References to data strings work correct as well, because the second sector is copied immediately after the first one, so it is contiguous in the machine code file and in memory.
What I cannot make it work is if I decide to load in memory the second sector somewhere else, either before or after the boot sector.
Things I have tried:
- Tried to use a second [ORG] directive in the middle of the file. NASM does not assemble it.
- Load the second sector a bit further (0x8000), then pad the file using TIMES directive, SECTION directive and manual NOP. Even though I thought this was going to work, it did not (or I did it wrong).
- In case I want to load it in, let's say 0x1000, I am blank coming with any solution for this.
Does anyone know a solution for this? Maybe having another file with different [ORG] and using linker afterwards? Maybe using a fixed offset in every op required in the second stage?
Thanks in advance!!
Novice level OS dev here.
I am struggling to find a solution to a conceptual question I am having. I hope you guys could help with it.
I am rolling my own bootloader and so far I am doing good progress (slow pace but learning a lot).
This is the situation I have right now, which works perfectly:
- - Windows environment with Bochs
- Bin file created using NASM with 2 sectors of 512 bytes each. (No file system, just a binary blob)
- First sector does some standard stuff and:- - Copies the second sector to memory, right after the boot sector, starting at 0x0:0x7E00
- Does a short jump to that address
- - Copies the second sector to memory, right after the boot sector, starting at 0x0:0x7E00
- - Some other standard stuff and a couple of functions and some string data.
* References to data strings work correct as well, because the second sector is copied immediately after the first one, so it is contiguous in the machine code file and in memory.
What I cannot make it work is if I decide to load in memory the second sector somewhere else, either before or after the boot sector.
Things I have tried:
- Tried to use a second [ORG] directive in the middle of the file. NASM does not assemble it.
- Load the second sector a bit further (0x8000), then pad the file using TIMES directive, SECTION directive and manual NOP. Even though I thought this was going to work, it did not (or I did it wrong).
- In case I want to load it in, let's say 0x1000, I am blank coming with any solution for this.
Does anyone know a solution for this? Maybe having another file with different [ORG] and using linker afterwards? Maybe using a fixed offset in every op required in the second stage?
Thanks in advance!!