[SOLVED] Int 0x13, AH=0x42 works only once
Posted: Sat Jul 14, 2012 1:57 am
Any idea of why the following code, supposed to load the GPT header, then the partition table, then the BIOS Boot Partition doesn't work?
Stepping through bochs I see that only the first time the INT 0x13 is called for extended read works. The second time bochs outputs "int13_harddisk: function 42, error 01 !". AH is set to 0x0C.
I tought the problem was that in the first read I did read too many sectors at once... so I made the ReadSector function split up in "ecx" reads, but still that won't work.... Any help?
Thanks in advance.
Stepping through bochs I see that only the first time the INT 0x13 is called for extended read works. The second time bochs outputs "int13_harddisk: function 42, error 01 !". AH is set to 0x0C.
I tought the problem was that in the first read I did read too many sectors at once... so I made the ReadSector function split up in "ecx" reads, but still that won't work.... Any help?
Code: Select all
[BITS 16]
[ORG 0x7C00]
cli
xor ax, ax
mov ds, ax
mov ss, ax
jmp 0:Start
Start:
mov sp, 0x7C00
sti
mov si, DiskPacket
mov [DxBackup], dx
; INT13 Extensions Setup Check (save boot disk number)
mov ah, 0x41
mov bx, 0x55AA
int 0x13
jc PrintError
mov dx, [DxBackup]
; Read the GPT Header
mov ecx, 1
mov ebx, 0x200
mov eax, 1
call ReadSector
; Look for GPT Signature
cmp dword [0x200], 0x20494645
jne PrintError
cmp dword [0x204], 0x54524150
jne PrintError
; Read partition table LBA
mov eax, [0x248]
push eax
; Sectors to read = ((number of entries * size of entries) + 511) >> 9;
mov eax, [0x250]
mov ebx, [0x254]
mov [PartEntrySize], ebx
mov [PartEntryCount], eax
mul ebx
add eax, 511
shr eax, 9
mov ecx, eax
pop eax
mov ebx, 0x200
mov dx, [DxBackup]
call ReadSector
mov ebx, 0x200
mov ecx, [PartEntryCount]
CheckPartition:
cmp dword [ebx], 0x21686148
jne .Next
cmp dword [ebx + 4], 0x6e6f6449
jne .Next
cmp dword [ebx + 8], 0x65654e74
jne .Next
cmp dword [ebx + 12], 0x49464564
jne .Next
jmp .Found
.Next:
add ebx, [PartEntrySize]
loop CheckPartition
jmp PrintError
.Found:
mov dx, [DxBackup]
mov ebx, [ebx + 32]
push ebx
mov ecx, 1
mov eax, ebx
mov ebx, 0x200
call ReadSector
cmp dword [0x200], 0x6F4E6D49
jne PrintError
cmp dword [0x204], 0x49464574
jne PrintError
pop eax
inc eax
mov ecx, [0x208]
dec ecx
mov ebx, 0x400
mov dx, [DxBackup]
call ReadSector
mov dx, [DxBackup]
jmp 0x20C
ReadSector:
pusha
mov [DiskPacket], word 0x10
mov word [DiskPacket + 2], 1
mov [DiskPacket + 4], ebx
mov [DiskPacket + 8], eax
mov [DiskPacket + 12], dword 0
.ReadNext:
xor eax, eax
mov ah, 0x42
push ecx
int 0x13
jc PrintError
pop ecx
loop .Next
popa
ret
.Next:
inc dword [DiskPacket + 8]
add word [DiskPacket + 4], 0x200
cmp word [DiskPacket + 4], 0x200
jl .NextSeg
jmp .ReadNext
.NextSeg:
add word [DiskPacket + 6], 0x1000
jmp .ReadNext
PrintError:
mov si, ErrorMessage
call message
stop:
hlt
jmp stop
ErrorMessage DB "Error!", 0
GoodMessage DB "Good!", 10, 13, 0
message:
lodsb
cmp al, 0
je .done
mov bx, 1
mov ah, 0xE
int 0x10
jmp message
.done:
ret
DxBackup DW 0
PartEntrySize DD 0
PartEntryCount DD 0
ALIGN 4
DiskPacket:
DW 0 ; Size and reserved
DW 0 ; Blocks count
DD 0 ; Buffer
DQ 0 ; Starting LBA
times (446 - ($ - $$)) DB 0
; Partition table: 1 GPT partition
DD 0x00010000
DD 0xFFFFFEEE
DD 1
DD 0xFFFFFFFF
times (510 - ($ - $$)) DB 0
DW 0xAA55