OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Jun 26, 2022 12:23 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Brendan's BIOS Wrapper (experimental!)
PostPosted: Thu Mar 28, 2013 8:34 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

This code allows software to use the BIOS from protected mode.

WARNING: This is just an experimental prototype hack, and wasn't written as 100% bullet-proof code.

It switches to protected mode and installs its own IDT. When any interrupt occurs in protected mode, it switches back to real mode and executes the relevant BIOS interrupt handler, then switches back to protected mode and returns to protected mode.

I also made it so that it knows the difference between an exception and a software interrupt or IRQ. If an exception occurs it just locks up instead of executing the BIOS's interrupt handler (I was going to add some "blue screen of death" crash dump code to it but I was lazy).

There's also some extremely bad floppy disk boot code that I slapped together for testing. You'd want to use NASM to assemble it (but YASM would probably work too).

Source code is in the attachment. The copyright is "public domain" - do whatever you want with it.


Cheers,

Brendan


Attachments:
bbw.tar.gz [5.2 KiB]
Downloaded 198 times

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Top
 Profile  
 
 Post subject: Re: Brendan's BIOS Wrapper (experimental!)
PostPosted: Sat Mar 30, 2013 8:59 am 
Offline
Member
Member

Joined: Thu Jul 05, 2012 5:12 am
Posts: 923
Location: Finland
If I were to start writing a boot loader now, I would think about using this idea. I could write almost everything being 32-bit code written in C. However, maybe the end result would be more entangled because inline assembly would be needed anyway to do several things. In addition, this mechanism itself would constitute almost a half of the boot code in my case. Anyway, a good prototype for introducing the idea.

_________________
Undefined behavior since 2012


Top
 Profile  
 
 Post subject: Re: Brendan's BIOS Wrapper (experimental!)
PostPosted: Sat Mar 30, 2013 5:48 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

Antti wrote:
If I were to start writing a boot loader now, I would think about using this idea. I could write almost everything being 32-bit code written in C. However, maybe the end result would be more entangled because inline assembly would be needed anyway to do several things. In addition, this mechanism itself would constitute almost a half of the boot code in my case. Anyway, a good prototype for introducing the idea.


Boot code is the reason I was playing around with the idea.

My boot code uses protected mode and paging (and is probably more complex than some people's OSs ;) ). For older versions I disabled IRQs while running in protected mode; which meant that the BIOS could lose IRQs. To work around that I peppered the code with "do nothing" calls (switch to real mode, enable IRQs and execute a few NOP instructions; just to give the BIOS a chance to handle any IRQs before it's too late). It's not pretty. For me, the BIOS wrapper would make things a lot cleaner (getting rid of the need for those "do nothing" calls all over the place, and also avoiding wrappers around individual BIOS functions) and I do intend to use this idea in my next "stage 2".

For the prototype itself there's still a few things missing. Mainly, if a BIOS function uses a segment register (e.g. ES for BIOS functions that read/write sectors) then the segment register has to be 0x0000 (it'd be easy to fix, it's just that I haven't yet). It'd also be nice to implement the "BSOD on exception" code, and maybe catch exceptions that occur while the CPU is in real mode (in case the BIOS crashes), to make it a little easier to debug the boot code on real hardware if things go wrong.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


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

All times are UTC - 6 hours


Who is online

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