The article correctly mentions the importance of setting up segment registers, yet like most neglects to set up CS (which is 0×0000). This is one nasty latent bug that shows itself as soon as you try doing indirect jumps. So if you want to use something like threaded code in your first stage bootloader set CS by "jmp 0×07c0:foo" first.
The article correctly mentions the importance of setting up segment registers, yet like most neglects to set up CS (which is 0×0000). This is one nasty latent bug that shows itself as soon as you try doing indirect jumps. So if you want to use something like threaded code in your first stage bootloader set CS by "jmp 0×07c0:foo" first.
You’re right – it would have been "good practice" to set the CS register. However, the CS register is already correctly set by the BIOS. If it were not set … a computer would never boot up! CS (code segment) and IP (instruction pointer) are both set to point directly at 0000:7C00 which is where the BIOS loads the bootsector into.
As far as using threaded code – that shouldn’t be necessary during a first stage loader. There isn’t enough room inside of 512 bytes to do anything fancier than loading the next stage. Especially from a generic point of view. Any additional configurations (protected mode, memory models, etc.) should be handled within the binary image that the first stage loads and jumps to.
CS Register Setting by VnutZ :: NR10 :: Show
The article correctly mentions the importance of setting up segment registers, yet like most neglects to set up CS (which is 0×0000). This is one nasty latent bug that shows itself as soon as you try doing indirect jumps. So if you want to use something like threaded code in your first stage bootloader set CS by "jmp 0×07c0:foo" first.
You’re right – it would have been "good practice" to set the CS register. However, the CS register is already correctly set by the BIOS. If it were not set … a computer would never boot up! CS (code segment) and IP (instruction pointer) are both set to point directly at 0000:7C00 which is where the BIOS loads the bootsector into.
As far as using threaded code – that shouldn’t be necessary during a first stage loader. There isn’t enough room inside of 512 bytes to do anything fancier than loading the next stage. Especially from a generic point of view. Any additional configurations (protected mode, memory models, etc.) should be handled within the binary image that the first stage loads and jumps to.