diff --git a/Makefile b/Makefile index ccdc612..88eb605 100644 --- a/Makefile +++ b/Makefile @@ -97,7 +97,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s $(AS) $(ASFLAGS) -o $@ $< $(OBJCOPY) --remove-section .note.gnu.property $@ -MBR_TEST_OBJ = obj/mbr_test.o +MBR_TEST_OBJ = obj/mbr_test.o obj/print.o mbr_test: $(MBR_TEST_OBJ) $(DISK) $(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ) @@ -106,6 +106,9 @@ mbr_test_clean: rm $(BIN_DIR)/mbr_test.bin rm $(OBJ_DIR)/mbr_test.o +mbr_test_objdump: + objdump -b binary -mi386 -Maddr16,data16 -D $(BIN_DIR)/mbr_test.bin + mbr_test_qemu: mbr_test $(QEMU) -accel tcg,thread=single \ -cpu core2duo \ diff --git a/src/mbr_test.s b/src/mbr_test.s index 4b1c00e..de5d2b2 100644 --- a/src/mbr_test.s +++ b/src/mbr_test.s @@ -24,17 +24,15 @@ # far jump to new memory region jmp $0x0050,$.bootloader .bootloader: + # initialize stack + mov $0x07DF, %ax + mov %ax, %ss + xor %sp, %sp - mov $msg, %si -.putc_loop: - lodsb - or %al, %al - jz .halt +.entry: + push $msg + call print - mov $0x0E, %ah - mov $0x00, %bh - int $0x10 - jmp .putc_loop .halt: jmp .halt diff --git a/src/print.s b/src/print.s new file mode 100644 index 0000000..ee6995f --- /dev/null +++ b/src/print.s @@ -0,0 +1,35 @@ +.section .text +.code16 + +.globl print + +# (%bp) - old bp +# 2(%bp) - ret addr +# 4(%bp) - arg 1 + +# arg 1 - string addr +print: + push %bp + mov %sp, %bp + + push %bx + push %si + + mov 4(%bp), %si + cld +.putc: + lodsb + or %al, %al + jz .end + + mov $0x0E, %ah + xor %bh, %bh + int $0x10 + jmp .putc +.end: + + pop %si + pop %bx + + pop %bp + ret