OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 10:50 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: [Solved] BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 9:04 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 91
I have a small "kernel" that is loaded in using my own Boot loader. The Boot loader loads the entire kernel(written in C) and sets the CPU to 32-bit and jumps to the kernel. And the kernel is loaded correctly. For accessing disk drive, I have a set of subroutines in assembly that switches the CPU back to real mode, runs a BIOS I/O interrupt, switches back to 32-bit mode, get the stack back, and return back to C code.The Code snippet that I've posted below runs on emulators and my laptop with Insyde BIOS, but when tried to run on my old hardware, it freezes right at int 0x13.
Code:
.
.
   mov ah, 0x02                             
   mov al, [0x7a00]                     ;1
   mov cl, [0x7a01]                     ;1
   mov dh, [0x7a02]                    ;31
   mov dl, [drivedata]                   ;sets by bios
   mov ch, [0x7a03]                    ;0
   mov bx, [0x7a06]                    ;0
   mov es, bx
   mov bx, [0x7a04]                    ;0x7000
   int 0x13
   jnc diskreadnoerr
.
.


I have been using the same code snippet to run multiple filesystem based functions like list files, create new one, save to a file, read from a file etc. on both emulators and my real hardware. It worked with no problems, but when I tried to do the same on my old pc, it freezes.
And yes, I tested using debug-prints and found that the CPU executes successfully upto int 0x13, then it doesn't come out. Doesn't go to error routine either. It stucks somewhere inside that routine.
I also tested by directly giving the arguments instead of reding it from memory, but still it didn't work. I have no idea why this is happening.

This is how I jumps back to real mode..
Code:
.
.
   lgdt [gdt_desc_16]
   jmp 0x8:$+7
   mov eax, cr0
   and al, 0xfe
   mov cr0, eax
   jmp 0x0:bit_16_start
[bits 16]
bit_16_start:
   mov ax, 0
   mov ds, ax
   mov ss, ax
   mov fs, ax
   mov es, ax
   mov gs, ax
   mov ax, 0x7900
   mov sp, ax
   mov bp, ax
.
.


Don't know if this is needed, but here is the 16-bit protected mode gdt I used:
Code:
null_16:                  ;NULL gdt
   dd 0x0
   dd 0x0
   
gdt_code_16:               ;code segment descriptor
   dw 0xffff            
   dw 0x0               
   db 0x0               
   db 10011010b
   db 00001111b
   db 0x0
gdt_data_16:               ;Data segment Descriptor
   dw 0xffff
   dw 0x0
   db 0x0
   db 10010010b ; 1 st flags , type flags
   db 00001111b ; 2 nd flags , Limit ( bits 16 -19)
   db 0x0


EDIT: I found something. I am more confused now.

I can actually call some BIOS routines! I used 10h to reset video mode and used my own 16-bit subroutine to that prints strings using 10h and it all worked! Right until int 0x13!
Then I tried to reset disk using int 13h. But no even that didn't happen.
my modified code:
Code:
[bits 16]
   mov dl, 0x80
   mov ah, 0
   ;int 0x13                                                   ;doesn't work!
   mov al, 3
   mov ah, 0
   int 0x10                                                    ; works!
   mov bx, checkdata
   call print_bx                                              ;also works!
   mov al, [0x7a00]
   mov cl, [0x7a01]
   mov dh, [0x7a02]
   mov dl, [drivedata]
   mov ch, [0x7a03]
   mov bx, [0x7a06]
   mov es, bx
   mov bx, [0x7a04]
   mov ah, 0x02
   int 0x13                                                     ;doesn't work!


If real mode has problem, how am I able to call a function from the boot loader to print a string but not even reset the disk system?!

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Last edited by pranavappu007 on Tue Jul 07, 2020 11:02 pm, edited 3 times in total.

Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 9:46 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
You know, it's much easier to write a protected mode disk driver than to mess about switching back to real mode and using BIOS calls. And it's going to be a whole lot more efficient.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 9:50 am 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
First, I agree with iansjack. It is a bit easier and you will have to do it eventually anyway.

My first few impressions of your situation is that you might be reading too many sectors at a time. 0x7F is the limit.
Also, your buffer should not cross a 64k boundary. i.e.: You can't read sectors to a buffer where one or more of the sectors will cross into the next 64k aligned block of memory.

Ben
- http://www.fysnet.net/osdesign_book_series.htm


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:15 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 91
BenLunt wrote:
First, I agree with iansjack. It is a bit easier and you will have to do it eventually anyway.

My first few impressions of your situation is that you might be reading too many sectors at a time.


This piece of code will only read 1 sector, as I only need a small table I stored inside it.

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:17 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 91
iansjack wrote:
You know, it's much easier to write a protected mode disk driver than to mess about switching back to real mode and using BIOS calls. And it's going to be a whole lot more efficient.

I didn't know that at the time I wrote the function. But as I now have a somewhat working setup that I can even use later for things like video services, I like to continue with it unless I have no other option.

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:17 am 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
What do you do after the int 0x13 if carry flag is set? Simply retry?

EDIT: I recommend, though it probably doesn't cause the problem:

Code:
bit_16_start:
   mov ax, 0
   mov ds, ax
   mov fs, ax
   mov es, ax
   mov gs, ax
   mov ss, ax
   mov sp, 0x7900
   mov bp, 0x7900


Last edited by PeterX on Mon Jul 06, 2020 10:22 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:20 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 91
PeterX wrote:
What do you do after the int 0x13 if carry flag is set? Simply retry?


print a red 'X' and hangs. And the red X does print on my laptop if actual disk error occurs.

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:25 am 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
pranavappu007 wrote:
PeterX wrote:
What do you do after the int 0x13 if carry flag is set? Simply retry?


print a red 'X' and hangs. And the red X does print on my laptop if actual disk error occurs.

May I ask about details of your "old system"? Maybe that's the reason?


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:30 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 91
PeterX wrote:
May I ask about details of your "old system"? Maybe that's the reason?

My new system is a laptop with Insyde BIOS and I regularly update the BIOS whenever a new version is it, so it is the latest supported version. The laptop is an HP Notebook 15 bs658tx.
My old system is a socket 775 build that features pentium E5700 with an Asus P5KPL-AM/PS Motherboard. It had one update available and I did that, but don't know the version.
Update: It also doesn't work on an i5 4th gen system with GIGABYTE motherboard.. :cry:

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:41 am 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
I must admit I can't find an error in your code. I personally suspect a broken BIOS.

Or you did something in pmode that leads to unreal mode or such weirdness.

Maybe the number of heads is below 32 on your old system? So head=31 would exceed the disk's limits.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:47 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Your choice is something of a dead-end street. More and more computers nowadays support UEFI only, with no BIOS emulation.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:49 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 91
PeterX wrote:
Maybe the number of heads is below 32 on your old system? So head=31 would exceed the disk's limits.

no, as my actual kernel resides in 32,34. It loads so no broken BIOS too.
PeterX wrote:
Or you did something in pmode that leads to unreal mode or such weirdness.

I suspect - no I know this is the problem... Would you give me an insight of what kind of action might have an effect at this?
If you need more info, I use memory at 0x18000(stack),0x20000(for an "Interpreter"),0x50000 for a text editor and 0x70000 for file load and save function.
Also uses location in the code, and a real mode stack at 0x7900
My OS is around 32KB and is loaded at 0x7e00 right besides the boot loader, as actually both of them is one big program.

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 10:50 am 
Offline
Member
Member

Joined: Mon Apr 20, 2020 11:02 am
Posts: 91
iansjack wrote:
Your choice is something of a dead-end street. More and more computers nowadays support UEFI only, with no BIOS emulation.

Doesn't matter as I am not writing a commercial OS, I just need to learn. UEFI and BIOS are both good to learn :wink:

_________________
A beginner developer/student. Likes to know stuff. Don't have an OS to put here.


Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 11:30 am 
Offline
Member
Member

Joined: Fri Nov 22, 2019 5:46 am
Posts: 590
Replace
Code:
jmp 0x8:$+7


with
Code:
jmp 0x8:$+5


That's important, or else you skip over part of the to-real-mode instructions


Last edited by PeterX on Mon Jul 06, 2020 11:43 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: BIOS I/O function causing older systems to freeze
PostPosted: Mon Jul 06, 2020 11:39 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
pranavappu007 wrote:
I just need to learn.
That's why I suggested writing a protected-mode disk driver rather than relying upon the crutch of the BIOS.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 32 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 224 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