program gets stuck when executing int 13h

53 Views Asked by At

I'm trying to make a simple OS so I wrote a small bootloader that will load the kernel, but when I try to run the program in bochs (or qemu) it get stuck on the int 13h instruction.

main.asm

org 0x7c00
bits 16

start:
    ; setup data segments
    mov ax, 0
    mov bx, 0x7000
    mov ds, ax
    mov es, ax
    

    ; setup stack
    mov ss, bx
    mov sp, ax
    
    ; some bioses might start us in 07c0:0000 instead of 0000:7c00, so we fix this
    push es
    push word .after
    retf

.after:
    mov [BOOT_DRIVE], dl
    call load_kernel
    jmp $                        ; this is temporary, it will be changed to a jmp to the kernel.

load_kernel:
    ; loads the kernel from memory
    push bx
    push dx

    mov bx, [KERNEL_OFFSET]
    mov dh, 1
    mov dl, [BOOT_DRIVE]
    call disk_load

    pop dx
    pop bx
    ret

disk_load:
    push ax
    push bx
    push cx
    push dx
    push di

    mov ah, 02h     ; mode, 2=read from disk
    mov al, dh      ; num of sectors to read
    mov cl, 02h     ; start from sector

    mov ch, 0x00    ; cylinder num
    mov dh, 0x00    ; head num

    mov di, 3       ; retry count

.loop:
    pusha
    stc             ; set carry

    int 0x013     <------ get stuck here
    jnc .done

    ; read failed
.fail:
    popa
    call disk_reset

    dec di
    test di, di
    jnz .loop
    jmp floppy_error

.done:
    popa

    pop di
    pop dx
    pop cx
    pop bx
    pop ax
    ret


KERNEL_OFFSET equ 0x2000    ; where to load the kernel

Makefile (how I create the image):

    dd if=/dev/zero of=$@ bs=512 count=2880
    dd if=$(BUILD_DIR)/main.bin of=$@ conv=notrunc bs=512 count=1 seek=0
    dd if=$(BUILD_DIR)/kernel_entry.bin of=$@ conv=notrunc bs=512 count=1 seek=1

So my question is why it gets stuck and how to fix it, and I didn't really understand to what I should set the stack.

0

There are 0 best solutions below