自己实现引导扇区
Makefile
all:
gcc -ggdb -c mbr.S
ld mbr.o -Ttext 0x7c00
objcopy -S -O binary -j .text a.out mbr.img
clean:
rm *.o *.img a.out -f
fda:
qemu-system-x86_64 -boot a -fda mbr.img -s -S
hda:
qemu-system-x86_64 mbr.img -s -S
debug:
gdb -x init.gdb
mbr.S
#define SECTOR_SIZE 512
// use mbr.S, not mbr.s, otherwise gcc make error
.code16
.globl _start
_start:
lea (msg), %si
again:
movb (%si), %al
incw %si
orb %al, %al
jz done
movb $0x0e, %ah
movb $0x00, %bh
int $0x10
jmp again
done:
jmp .
msg:
.asciz "hello, mbr!\r\n"
.org SECTOR_SIZE - 2
.byte 0x55, 0xAA