int 0x13 causes function not to return
Posted: Mon Mar 20, 2023 12:08 pm
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:
And I call it with:
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.
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
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
|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.