From ac89fe8c32dd69650f8a547f1d0d34bbdcb2a6bf Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Wed, 7 Aug 2024 06:49:49 +0300 Subject: [PATCH] move disk enumeration to its own file for the sake of modularity --- Makefile | 2 +- src/mbr_test.s | 30 +----------------------------- src/test_disk_enum.s | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 src/test_disk_enum.s diff --git a/Makefile b/Makefile index d0df868..4703939 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 obj/serial.o obj/itoa.o obj/util.o +MBR_TEST_OBJ = obj/mbr_test.o obj/serial.o obj/itoa.o obj/util.o obj/test_disk_enum.o mbr_test: $(MBR_TEST_OBJ) $(DISK) $(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ) diff --git a/src/mbr_test.s b/src/mbr_test.s index 9c3a7d5..2a8140b 100644 --- a/src/mbr_test.s +++ b/src/mbr_test.s @@ -36,34 +36,6 @@ entry: .bootloader: call serial_init - # enumerate all system disks - movw $127, disk_id - #mov $128, %dl # already set bit 7 to 1 for fixed disk type -.disk_enum: - # set disk id in DL with fixed disk bit on - movw disk_id, %dx - or $128, %dx - - mov $0x15, %ah - int $0x13 - - cmp $3, %ah # is fixed disk - jnz .disk_skip - - # it's working fixed disk, lets print its number - movw disk_id, %ax - mov $disk_enum_msg, %si - call prints_number -.disk_skip: - decw disk_id - jns .disk_enum - - nop + call test_disk_enum .halt: jmp .halt - -.section .rodata -disk_enum_msg: .asciz "Disk " - -.section .bss -disk_id: .word diff --git a/src/test_disk_enum.s b/src/test_disk_enum.s new file mode 100644 index 0000000..ed89f5e --- /dev/null +++ b/src/test_disk_enum.s @@ -0,0 +1,35 @@ +.section .text +.code16 + +.globl test_disk_enum + +# enumerate all system disks +test_disk_enum: + movw $127, disk_id + #mov $128, %dl # already set bit 7 to 1 for fixed disk type +.disk_enum: + # set disk id in DL with fixed disk bit on + movw disk_id, %dx + or $128, %dx + + mov $0x15, %ah + int $0x13 + + cmp $3, %ah # is fixed disk + jnz .disk_skip + + # it's working fixed disk, lets print its number + movw disk_id, %ax + mov $disk_enum_msg, %si + call prints_number +.disk_skip: + decw disk_id + jns .disk_enum + + ret + +.section .rodata +disk_enum_msg: .asciz "Disk " + +.section .bss +disk_id: .word