diff --git a/Makefile b/Makefile index 655350d..9142253 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,19 @@ CC = gcc +AS = as +LD = ld +OBJCOPY = objcopy CLFAGS = -g -Wall +ASFLAGS = LDFLAGS = -g +SRC_DIR = src +OBJ_DIR = obj +BIN_DIR = bin + UID := $(shell id -u) GID := $(shell id -g) -DISK = bin/disk.img +DISK = $(BIN_DIR)/disk.img DISK_SIZE = 268435456 DISK_LOOP = /dev/loop690 @@ -84,6 +92,19 @@ $(DISK): mnt sudo losetup -d $(PART3_LOOP) sudo losetup -d $(DISK_LOOP) +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.s + $(AS) $(ASFLAGS) -o $@ $< + $(OBJCOPY) --remove-section .note.gnu.property $@ + +MBR_TEST_OBJ = obj/mbr_test.o + +mbr_test: $(MBR_TEST_OBJ) $(DISK) + $(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ) + +mbr_test_clean: + rm $(BIN_DIR)/mbr_test.bin + rm $(OBJ_DIR)/mbr_test.o + clean: rm -f bin/* rm -f obj/* diff --git a/src/mbr_test.ld b/src/mbr_test.ld new file mode 100644 index 0000000..e670f11 --- /dev/null +++ b/src/mbr_test.ld @@ -0,0 +1,31 @@ +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 +} + +SECTIONS +{ + . = 0x7C00; + .text : { + *(.text) + *(.data) + } > BOOTLOADER + + .unique_id : { + SHORT(0x1234) + } > UNIQUE_ID + + .reserved : { + SHORT(0x0000) + } > RESERVED + + .mbr_magic : { + SHORT(0xAA55) + } > MBR_MAGIC +} + +OUTPUT_FORMAT(binary) \ No newline at end of file diff --git a/src/mbr_test.s b/src/mbr_test.s new file mode 100644 index 0000000..672cdaf --- /dev/null +++ b/src/mbr_test.s @@ -0,0 +1,21 @@ +.section .text +.code16 + + mov $0x07C0, %ax + mov %ax, %dx + + mov msg, %si +.putc_loop: + lodsb + or %al, %al + jz .halt + + mov $0x0E, %ah + mov $0, %al + int $0x10 + jmp .putc_loop +.halt: + hlt + +.section .data +msg: .asciz "Test MBR hello world\x0D\x0A" # len 22