diff --git a/Makefile b/Makefile index 9142253..ccdc612 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ OBJCOPY = objcopy CLFAGS = -g -Wall ASFLAGS = LDFLAGS = -g +QEMU = qemu-system-x86_64 SRC_DIR = src OBJ_DIR = obj @@ -105,6 +106,20 @@ mbr_test_clean: rm $(BIN_DIR)/mbr_test.bin rm $(OBJ_DIR)/mbr_test.o +mbr_test_qemu: mbr_test + $(QEMU) -accel tcg,thread=single \ + -cpu core2duo \ + -m 128 \ + -no-reboot \ + -serial stdio \ + -smp 1 \ + -vga std \ + -d int \ + -d guest_errors \ + -s \ + -drive format=raw,media=disk,file=$(BIN_DIR)/mbr_test.bin \ + -drive format=raw,media=disk,file=$(BIN_DIR)/disk.img + clean: rm -f bin/* rm -f obj/* diff --git a/src/mbr_test.ld b/src/mbr_test.ld index e670f11..0e4d1a7 100644 --- a/src/mbr_test.ld +++ b/src/mbr_test.ld @@ -1,18 +1,21 @@ MEMORY { - BOOTLOADER (RWX) : ORIGIN = 0x7C00, LENGTH = 440 - UNIQUE_ID (R) : ORIGIN = 0x7DB8, LENGTH = 4 - RESERVED (R) : ORIGIN = 0x7DBC, LENGTH = 2 - PTABLE (R) : ORIGIN = 0x7DBE, LENGTH = 64 - MBR_MAGIC (R) : ORIGIN = 0x7DFE, LENGTH = 2 + BOOTLOADER (RWX) : ORIGIN = 0x0000, LENGTH = 440 + UNIQUE_ID (R) : ORIGIN = 0x01B8, LENGTH = 4 + RESERVED (R) : ORIGIN = 0x01BC, LENGTH = 2 + PTABLE (R) : ORIGIN = 0x01BE, LENGTH = 64 + MBR_MAGIC (R) : ORIGIN = 0x01FE, LENGTH = 2 } SECTIONS { - . = 0x7C00; + . = 0; .text : { + BOOTLOADER_START = .; *(.text) *(.data) + BOOTLOADER_END = .; + BOOTLOADER_SIZE = BOOTLOADER_END - BOOTLOADER_START; } > BOOTLOADER .unique_id : { diff --git a/src/mbr_test.s b/src/mbr_test.s index 672cdaf..a505820 100644 --- a/src/mbr_test.s +++ b/src/mbr_test.s @@ -1,21 +1,24 @@ .section .text .code16 + mov $BOOTLOADER_SIZE, %ax + mov $0x07C0, %ax - mov %ax, %dx + mov %ax, %ds mov msg, %si + cld .putc_loop: lodsb or %al, %al jz .halt mov $0x0E, %ah - mov $0, %al + mov $0x00, %bh int $0x10 jmp .putc_loop .halt: - hlt + jmp .halt .section .data -msg: .asciz "Test MBR hello world\x0D\x0A" # len 22 +msg: .asciz "Test MBR hello world\r\n"