Page 1 of 1

BIOS usage in modern OS

Posted: Wed Nov 19, 2008 5:56 am
by osnewbie
Hi my question is about BIOS staff.

I am new to OS development. I know that BIOS can be accessed in real mode. It seems BIOS calls make it easy to access surrounding peripherals like disk and vga.

Now, without BIOS calls how hardware access is done? I tried to search the forum with keywords bios, protected mode etc. but couldnt get any result since they are very common keywords.

What methods are used to access hardware peripherals in the system in protected mode? Please direct me to source of information.

Re: BIOS usage in modern OS

Posted: Wed Nov 19, 2008 6:23 am
by AJ
Hi,
osnewbie wrote:I know that BIOS can be accessed in real mode. It seems BIOS calls make it easy to access surrounding peripherals like disk and vga.
You're right, the BIOS makes it easy, but you need to be careful here. You don't know what the BIOS codes does and what state it could leave everything in. You may also find that some functions need manufacturer specific bug workarounds.
Now, without BIOS calls how hardware access is done?
Generally one of two methods. The first is port IO (IN and OUT instructions) and the second is memory mapped IO. Here's the caveat: not all devices (even of the same class like video cards) use the same ports and registers - even if they are from the same manufacturer. You therefore need a different driver for each piece of hardware.

Just as an example (with no specific factual basis), take a (no-VESA SVGA) video card. It may have a two-port range. The first port could be an address selector and the second a command/data port. To switch video modes, you may have to use the address selector to select the command port function and then write a specific number to the command port to perform the video mode select.

Once you have done that, the video card may support a memory-mapped linear frame buffer (LFB) representing the actual pixel data. You wouldn't need any other port accesses, but simply update the LFB to draw to the display device.

Actually, most current video cards seem to support VESA (2.0). Using this, you would perhaps select a display mode at boot time (with a BIOS call) and then just write to the LFB once you have entered PMode.
What methods are used to access hardware peripherals in the system in protected mode? Please direct me to source of information.
For a very simple example of COM port access via port IO, see --> Serial Ports <-- on our very own wiki. For an example of memory IO, see --> Drawing in Protected Mode.

Beyond this, I'm afraid it's a case of reading datasheets and creating your own drivers.

Note that you can use PMode <-> RMode switching or v86 for using BIOS calls, but the second method is generally not recommended for disk IO (cf. Windows 95!). PMode <-> RMode switching also needs to be done very carefully and can get messy. If you go to long mode, you will need drivers (there's no v86 mode).

Cheers,
Adam