-1

I write a 16bit operating system and currently I work on the disk reading. And the problem is the BIOS function ah = 2, int 0x13 raises an carry flag and reads 0 segments on the second read. After the faulty read ax is set to 0x2000, so 0 segments were read and it doesn't tell if the BIOS function isn't supported or something. My Image/disk has 2 heads and 36 Sectors per track (tells me a BIOS function). Is there a way to fix this?

If needed the function code:

param_loadlba_sectors: db 1
param_loadlba: dw 0
param_loadlbabuffer: dw 0
load_with_lba:
    ;
    ;   Convert lba to chs
    ;
    pusha
    mov ax, [param_loadlba]
    div BYTE[self_sectperside]
    ; temp, sector = lba / sect per side, lba % sect per side + 1
    mov BYTE[LODAWITHLBATEMP], al
    inc ah
    mov BYTE[LOADWITLBASECTOR], ah

    mov ah, 0
    mov al, BYTE[LODAWITHLBATEMP]
    div BYTE[self_heads]
    ; cylinder, head = temp / heads, temp % heads
    mov BYTE[LOADWITHLBACYLINDER], al
    mov BYTE[LOADWITHLBAHEAD], ah
    ;
    ;   Load
    ;
    ; drive
    mov dl, [start_drive]
    ; cylinder
    mov cl, BYTE[LOADWITHLBACYLINDER]
    ; diskside
    mov dh, BYTE[LOADWITHLBAHEAD]
    ; sector
    mov cl, [LOADWITLBASECTOR]
    ; number of sectors
    mov al, BYTE[param_loadlba_sectors]
    ; es = 0
    mov bx, 0
    mov es, bx
    ; bx = *param_loadlbabuffer
    mov bx, WORD[param_loadlbabuffer]
    mov ah, 0x2
    clc
    int 0x13
    ; check if error
    jnc NOERROR
    mov BYTE[error], FILEERROR
    NOERROR:
    mov BYTE[param_loadlba_sectors], 1
    popa
    ret
LODAWITHLBATEMP: db 0
LOADWITLBASECTOR: db 0
LOADWITHLBAHEAD: db 0
LOADWITHLBACYLINDER: db 0

After the faulty call I checked the state of 'local variables' and it calculated that the cylinder 0, head 0 and sector 4 was read (The labels at the bottom).

If it's important I load on the first call some code into the address 0x500 and jump to it (I verified the code there is executed) even if I read the function call a second time before the jump it raises the carry flag.

I use qemu and nasm.

3
  • Show your full code and build + run commands.
    – ecm
    Mar 17 at 14:22
  • 1
    You aren't writing ch
    – ecm
    Mar 17 at 14:23
  • 1
    Put the answer in your answer, not in the question, but I'll leave that for you to edit both of those to move that part of the "question" where it belongs. I edited the word "solved" out of the title; if you want to mark it solved, accept your own self-answer using the checkmark. Mar 18 at 0:54

1 Answer 1

0

Solution: After investigating I found out that the drive given as input was the wrong one. The memory cell containing it was overwritten by another function. To anyone in the future having the same problem check ALL inputs, even when they seem to be guaranteed right. I think writing as parameter a value to a specific address in a function should be avoided because, if the function is relocated the value gets lost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.