This is the function that I use to read the disk:
Code: Select all
;***********************************;
; Reads a series of sectors ;
; Parameters: ;
; dl => bootdrive ;
; ax => sectors count ;
; ebx => address to load to ;
; ecx => LBA address ;
; Returns: ;
; cf => set if error ;
;***********************************;
ReadSectorsLBA:
mov [LBA_Packet.block_cout], ax
mov [LBA_Packet.transfer_buffer], ebx
mov [LBA_Packet.lba_value], ecx
mov si, LBA_Packet
mov ah, 0x42 ; Read sectors function
int 0x13
ret
align 4
LBA_Packet:
.packet_size db 0x10 ; use_transfer_64 ? 10h : 18h
.reserved db 0x00 ; always zero
.block_cout dw 0x00 ; number of sectors to read
.transfer_buffer dd 0x00 ; address to load in ram
.lba_value dq 0x00 ; LBA addres value
Code: Select all
;****************************;
; Loads FAT table to FAT_SEG ;
;****************************;
LoadFAT:
; clear registers
xor ax, ax
xor ecx, ecx
xor ebx, ebx
xor dx, dx
; compute size of FAT and store in "ax"
mov ax, WORD [bpb_SectorsPerFAT] ; sectors used by FAT
; compute location of FAT and store in "ecx"
mov cx, WORD [bpb_ReservedSectors]
add ecx, 2048 ; temporary code for first partition
; read FAT into memory at FAT_SEG
mov dl, [bpb_DriveNumber]
mov bx, WORD FAT_SEG
call ReadSectorsLBA
ret
This is what I tried:
- Initialize the disk with int 13h/ah=0h
- Changing ram destination
- implementing this code outside of the function
I also tried to print the error code from the interrupt but the next line is never executed, is like it hangs forever in the interrupt handling.
Does the interrupt have some limitation on the sectors that it can read or is just some bug in my code?
It is not the minmal example of my code since it contains also the code of the kernel that sould be loaded by this bootloader but here you can find the repository with all the code. The bootloader part is in the boot directory. The readme suggest to run the dependencies.sh file but what it mostly does is creating the cross compiler for the kernel so it can be skipped. You can use the makefile in the boot direcoty to build the bootloader bins and the create_image.sh script with some adjustments.