int 13h ah 42h start sector
Posted: Mon Oct 18, 2021 8:34 am
I'm trying to read from disk using int 13h ah 42h and it works fine only if I read the whole kernel in one call.
When reading in chunks it seems like only first call is having effect.
And I guess it works only when source sector in disk address packet is equal to 1.
I tried debugging it in bochs and it showed me that every read except first does not change the memory.
I'm interested to know why this happens.
Here's the boot code:
When reading in chunks it seems like only first call is having effect.
And I guess it works only when source sector in disk address packet is equal to 1.
I tried debugging it in bochs and it showed me that every read except first does not change the memory.
I'm interested to know why this happens.
Here's the boot code:
Code: Select all
kernel_offset equ 0x7E00 ; The same one we used when linking the kernel
port_com1 equ 0x3f8
[bits 16]
org 0x7c00
e_read equ 0
sectors_per_iteration equ 1
boot_main_16:
mov [boot_disk_id], dl
mov ax, 0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov sp, 0x7c00 ; free memory from 0x500 to 0x7c00
mov bp, sp
mov si, 0
mov ds, si
mov si, disk_address_packet
mov ah, 0x42
mov dl, [boot_disk_id]
mov bx, kernel_size_in_sectors ; remaining sectors count
.read_next:
cmp bx, sectors_per_iteration
jg .more_remaining
mov word [disk_address_packet.sectors_to_transfer], bx
jmp .update_remaining_sector_count
.more_remaining:
mov word [disk_address_packet.sectors_to_transfer], sectors_per_iteration
.update_remaining_sector_count:
sub bx, word [disk_address_packet.sectors_to_transfer]
mov di, 3 ; try count
.retry_read:
stc
int 0x13
jnc .read_success
.read_error:
dec di
test di, di
jnz .retry_read
jmp shutdown
.read_success:
test bx, bx
jz .read_done
add dword [disk_address_packet.destination_segment], sectors_per_iteration*512/16
add dword [disk_address_packet.source_sector], sectors_per_iteration
jmp .read_next
.read_done:
call kernel_offset
call shutdown
shutdown:
mov dx, 0x604
mov ax, 0x2000
out dx, ax
cli
hlt
jmp shutdown
boot_disk_id: db 0
disk_address_packet:
.size: db 16
.reserved: db 0
.sectors_to_transfer: dw 1
.destination_offset: dw 0
.destination_segment: dw kernel_offset/16
.source_sector: dq 1
times 510-($-$$) db 0
dw 0xaa55
kernel_size_in_sectors equ 63