bootloader icon indicating copy to clipboard operation
bootloader copied to clipboard

Question on second stage

Open boredcoder411 opened this issue 11 months ago • 5 comments

I've read the through the first bootsector's code, and everything looks good with objdump: _second_stage_start label is supposed to be at ram 0x7e00 and the code calls it, but I'm trying to make my own second stage and don't understand just how the second stage is placed after the first one. I've tried assembling a program with nasm -f bin and just cat appending to the original file, but that doesn't seem to work, even if the new code is at offset 0x7e00. Am I missing something?

boredcoder411 avatar Jan 12 '25 01:01 boredcoder411

create_mbr_disk inserts padding as necessary to write it to the right location on the disk. And the first stage then loads a fixed sector on the disk to a fixed address in ram.

bjorn3 avatar Jan 12 '25 06:01 bjorn3

So I can't just write bytes at the second sector?

boredcoder411 avatar Jan 12 '25 11:01 boredcoder411

Looks like the second stage is actually written to the second sector: https://github.com/rust-osdev/bootloader/blob/086c248e89ec3519f77dadda6c74d193e6fa22fd/src/mbr.rs#L31 When cat'ing are you sure the first file for the boot sector is exactly 512 bytes?

bjorn3 avatar Jan 12 '25 11:01 bjorn3

Yep! Because the linker script fills with 00 and 55aa at the 511 and 512 bytes

boredcoder411 avatar Jan 12 '25 21:01 boredcoder411

https://github.com/boredcoder411/rust_boot If you want to check it out, but it looks fine to me

boredcoder411 avatar Jan 14 '25 12:01 boredcoder411