OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:09 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: int 0x13 causes function not to return
PostPosted: Mon Mar 20, 2023 12:08 pm 
Offline

Joined: Sat Mar 18, 2023 1:36 pm
Posts: 2
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:
; 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:
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.


Top
 Profile  
 
 Post subject: Re: int 0x13 causes function not to return
PostPosted: Tue Mar 21, 2023 10:28 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
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?


Top
 Profile  
 
 Post subject: Re: int 0x13 causes function not to return
PostPosted: Wed Mar 22, 2023 1:24 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3191
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. :-)


Top
 Profile  
 
 Post subject: Re: int 0x13 causes function not to return
PostPosted: Wed Mar 22, 2023 4:13 am 
Offline

Joined: Sat Mar 18, 2023 1:36 pm
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 60 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group