1

I have an issue with bochs reading my floppy drive. After reading a few sectors (1 - 10) bochs exits with the following error:

[BIOS ] int13_diskette: ctrl not ready.

The error occurs while executing interrupt 13h, but the parameters given to the interrupt seem to be fine:

AX: 0x0201 
BX: 0x0900
CX: 0x0004
DX: 0x0100
ES: 0x0000

Here is the floppy disk reading part:

; input: 
;   dl -> device
;   es:bx -> Buffer to read to
;   ax -> Start sector
;   cx -> Number of sectors
;
; output:
;   carry -> On error

fat_read_device:
    mov di, FAT_READ_RETRIES ; retries for error -> 5

    .try_load:
        push ax
        push bx
        push cx

        push bx
        mov bl, dl ; remember device
        mov dx, ax

        int 0xe2 ; Convert lba to chs -> Writing to cl, ch and dh

        mov dl, bl
        pop bx

        mov ah, 0x02 ; Read device es:bx
        mov al, 0x01 ; Number of sectors to read
        ;xchg bx, bx
        int 0x13
        jnc .done ; test if succeeded

        xor ax, ax ; Reset disk
        int 0x13
        dec di ; decrement error counter
        pop cx
        pop bx
        pop ax
        jnz .try_load ; attempt to read again

        stc
        ret

    .done:
        int 0xcf ; Feedback disk operation -> Print a "."

        pop cx
        pop bx
        pop ax
        add bx, word [bpbBytesPerSector] ; next sector
        inc ax ; read next sector
        loop fat_read_device ; repeat until cx sectors are read
        ret

I'm also reprogramming PIT 0 (programmable interval timer) to be 1000hz rather than 18.2hz using this code:

TIMER_DIVISOR EQU 1193

timer_init:
    cli

    mov al, 36h ; PIT channel 0
    out 43h, al ; select channel

    mov ax, TIMER_DIVISOR
    out 40h, al ;send low byte
    mov al, ah
    out 40h, al ;send high byte

    sti

    mov word [cs:timer_tick_count], 0

    ret

I do only get this error with bochs in debug mode. If I start the system in non debug mode, it works fine.

Has anyone had the same issue or does anyone have an idea what I am doing wrong?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Erukaron
  • 39
  • 5
  • Can you show us a complete list of ALL the register values (including all the segment registers). Basically the full output of `REG` and `SREG` in BOCHS just before the `int 13h` that fails. Usually this kind of error is due to some kind of memory corruption. Like loading the code on top of the stack. I don't seen an obvious bug in the code shown. It doesn't cross a DMA boundary etc and the CHS value seems to be within norms for a 1.4MB disk image. – Michael Petch Oct 18 '20 at 00:03
  • 3
    Your problem is likely not a result of the things you are showing here. For example I now know you modify the PIT timer 0 which the BIOS / Int 13h may use for timings. I wouldn't modify that, it may be causing issues with the BIOS bochs is using. – Michael Petch Oct 18 '20 at 00:32
  • 1
    As Michael Petch said the problem was caused by reprogramming the PIT, if i leave it untouched, everything works as it should. The floppy interrupt uses the PIT in its default state (ca. 18 Hz) to calculate the time needed waiting for the drive. Because of the frequency increase of the PIT (i set it to 1000Hz) interrupt 13h failed. Two possible solutions are: not reprogramming the PIT, or writing to the floppy disk controller directly and handle timing yourself. – Erukaron Oct 18 '20 at 08:57
  • I've downvoted your question because you have omitted the critical details needed to answer it. Michael Petch made a lucky guess, but in general, you should always provide a [mcve]. – fuz Oct 18 '20 at 09:05
  • 2
    @fuz : Not a lucky guess ;-). I had become aware of PIT 0 being set on another forum that this was cross posted to. – Michael Petch Oct 18 '20 at 09:15
  • 1
    Thanks for adding the PIT 0 detail. However, that doesn't make your code a [mcve] as it still cannot be independently assembled and executed to reproduce your issue. For your next question, please provide such a [mcve]. – fuz Oct 18 '20 at 09:35

0 Answers0