move disk enumeration to its own file for the sake of modularity

This commit is contained in:
mykola2312 2024-08-07 06:49:49 +03:00
parent a6a65f790d
commit ac89fe8c32
3 changed files with 37 additions and 30 deletions

View file

@ -97,7 +97,7 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s
$(AS) $(ASFLAGS) -o $@ $< $(AS) $(ASFLAGS) -o $@ $<
$(OBJCOPY) --remove-section .note.gnu.property $@ $(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) mbr_test: $(MBR_TEST_OBJ) $(DISK)
$(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ) $(LD) -T src/mbr_test.ld -o $(BIN_DIR)/mbr_test.bin $(MBR_TEST_OBJ)

View file

@ -36,34 +36,6 @@ entry:
.bootloader: .bootloader:
call serial_init call serial_init
# enumerate all system disks call 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
nop
.halt: .halt:
jmp .halt jmp .halt
.section .rodata
disk_enum_msg: .asciz "Disk "
.section .bss
disk_id: .word

35
src/test_disk_enum.s Normal file
View file

@ -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