int 0x13 causes function not to return

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
einspieler13
Posts: 2
Joined: Sat Mar 18, 2023 1:36 pm
Libera.chat IRC: 1565

int 0x13 causes function not to return

Post by einspieler13 »

Hello, I try to write an 16bit boot program but I encounter a weird problem. I have written an function that takes the drive, cylinder, head, segment, and an memory address, and writes from the segment into the specified address it's contents.
I call functions with returns and arguments like this: first push a value for the return, then push the arguments in reverse order and then the function gets called. And my function looks like this:

Code: Select all

; param 1 drive
; param 2 cylinder
; param 3 head
; param 4 sector
; param 5 buffer
; return error (error = 1)
bios_load_chs:
    mov bx, sp
    ; drive, param 1
    mov ax, WORD[ss:bx+2]
    mov dl, al
    ; cylinder, param 2 
    mov ax, WORD[ss:bx+4]
    mov ch, al
    ; head, param 3
    mov ax, WORD[ss:bx+6]
    mov dh, al
    ; sector, param 4
    mov ax, WORD[ss:bx+8]
    mov cl, al
    ; buffer, param 5 (write location is in es:bx)
    mov bx, WORD[ss:bx+10]
    mov ah, 2
    ; reading only one segment, explanation why: https://wiki.osdev.org/Disk_access_using_the_BIOS_(INT_13h)
    mov al, 1
    clc
    int 0x13
    mov bx, sp
    ; error handeling
    jnc BIOSLOADSHSNOERROR
    mov WORD[ss:bx+12], 1
    ret
BIOSLOADSHSNOERROR:
    mov WORD[ss:bx+12], 0
    ret
And I call it with:

Code: Select all

push 0 ; return
push 0x7f00 ; buffer
push 4 ; sector
push 0 ; head
push 0 ; cylinder
mov ah, 0
mov al, BYTE[DISKDIM + DISKDIM_DRIVE_OFFSET]
push ax ; drive
call bios_load_chs
pop ax ; arg 1
pop ax ; arg 2
pop ax ; arg 3
pop ax ; arg 4
pop ax ; arg 5

call print_num
pop ax ; return
The stack should look like this (the elements are btw. words):
|return|buffer|sector|head|cylinder|drive|call address| ---growing direction---->
(my stack segment is at 0x6fff and the stack/base pointer gets initialized at 0xffff)
How ever my function doesn't return. And even more interesting is, if I print a character before the "int 0x13" it gets printed, but if I try to print an character after the interrupt I get nothing.
alexfru
Member
Member
Posts: 1111
Joined: Tue Mar 04, 2014 5:27 am

Re: int 0x13 causes function not to return

Post by alexfru »

The read will overwrite memory at es:bx. Where does this pair of registers point? Is BIOS by any chance overwriting the stack or code of your program?
rdos
Member
Member
Posts: 3296
Joined: Wed Oct 01, 2008 1:55 pm

Re: int 0x13 causes function not to return

Post by rdos »

alexfru wrote:The read will overwrite memory at es:bx. Where does this pair of registers point? Is BIOS by any chance overwriting the stack or code of your program?
Or the interrupt vector table. :-)
einspieler13
Posts: 2
Joined: Sat Mar 18, 2023 1:36 pm
Libera.chat IRC: 1565

Re: int 0x13 causes function not to return

Post by einspieler13 »

yes, it did overwrite itself...
Thanks for the replies, I completely overlooked this, I am sorry for such an simple question it will not happen again (I hope). Next time I will use a label for the next free segment instead of "calculating" it.
Post Reply