1
votes

I have made a very basic boot loader based on MikeOS boot loader ( Link ). I'm using NASM and QEMU for assembling and testing. And I'm trying to enable protected mode for my OS. So, I started searching web for more details and to know more about BIOS interrupts. I came across wikipedia and read an article....

Many modern operating systems (such as Linux and newer versions of Windows) bypass the built-in BIOS interrupt communication system altogether, preferring to use their own software to control the attached hardware directly. The original reason for this was primarily that these operating systems run the processor in protected mode, whereas calling BIOS requires switching to real mode and back again, and switching to real mode is slow. However, there are also serious security reasons not to switch to real mode, and the BIOS code has limitations both in functionality and speed ( Source: wikipedia ( Link ) )

The article in wikipedia says that

.....primarily that these operating systems run the processor in protected mode, whereas calling BIOS requires switching to real mode and back again, and switching to real mode is slow......
( Source: wikipedia ( Link ) )

According to what I understood, it is not much advisable to use much BIOS interrupts for all procedures in protected mode, am I right ? If I'm right, then my boot loader also uses many BIOS interrupts to print characters on screen... Is it good or bad ? If it's bad, why ? and what changes do I need to make to create a print character procedure ?

As I want to make my OS for protected mode, I am confused whether I should use BIOS interrupts or not ? Currently I have made a boot loader only which prints string on the screen, currently I don't have any another functions in my bootloader which uses any BIOS interrupts. If it is not good to use BIOS interrupts for protected mode, what should I do for print string function when I load my kernel in protected mode ( when I make it :p ) ?

Also,

Many modern operating systems (such as Linux and newer versions of Windows) bypass the built-in BIOS interrupt communication system altogether, preferring to use their own software to control the attached hardware directly. ( Source: wikipedia ( Link ) )

How are those developers able to develop those software ? Are those softwares made in Assembly or any other language ? Does they require deep hardware-software knowledge ? If its possible to make those softwares in my OS then I am thinking to add those.... Is it advisable to do so, or should I use BIOS interrupts only ?

1
So compile it in your head and write NASM code that does those stores. i.e. treat it as pseudocode showing which memory you need to write. - Peter Cordes
It's pretty simple pseudocode; if you can read C syntax at all. But you could literally compile it with gcc -c -Os, and disassemble it into a NASM function with Agner Fog's objconv disassembler. agner.org/optimize/#objconv - Peter Cordes
Even in the MS-DOS days, when programs did run in real mode, many apps wrote directly to the video memory anyway, because using the BIOS was pretty slow even when not switching modes. And in the 286, used in the original PC/AT, there was no machine instruction available to leave protected mode. To get out of protected mode you would have to reset the processor (activate the reset pin) and start over. That's where "switching to real mode is slow" originated. When later processors got a better way, people had already learned how to get along without the BIOS. - Bo Persson
On a side note though. Back in the DOS days and the advent of 386 Memory Managers like EMM386, QEMM /386(Quarterdeck) etc. DOS was often running as a virtual VM8086 task and the memory manager had a VM8086 monitor in the background. - Michael Petch

1 Answers

4
votes

You can use BIOS interrupts in Real-Mode but you won't be able to do it after you've entered Protected Mode or Long Mode in the same way that you would have in Real Mode. It's actually for security as far as I am aware; the whole point of Protected Mode was to enforce more security and stability (also removing many limitations which were present in Real Mode), and Long Mode has its own set of benefits further than Protected Mode as well (since Long Mode is for 64-bit).

You have several options:

  1. Write a Kernel-Mode device driver to implement support for the functionality manually, instead of relying on the BIOS interrupt functionality.
  2. Implement support for Real Mode emulation via Virtual 8086 implementation. I believe early versions of Windows (really, really early versions) relied on this and apparently this is why some of the really old ones had some freezing bugs, but I cannot verify if this is indeed true nor if Microsoft still use a Virtual 8086 implementation for anything. Anyway, a Virtual 8086 implementation will allow you to perform BIOS interrupts despite your kernel being in Protected Mode because you'd have an emulation of Real Mode.
  3. Switch back from Protected Mode to Real Mode and back. There should be more information about this in some Intel documentation and there is some information on it online (e.g. OS Dev Wiki, try searching for it), but this can cause problems depending on how your Operating System's Kernel works. You'll need to be careful with it to say the least... it'll be easy to mess things up, and will likely be really tricky for you to implement in a stable manner given you've asked the question you have.

If I'm right, then my boot loader also uses many BIOS interrupts to print characters on screen... Is it good or bad ?

If you want to print characters to the screen after exiting Real Mode (e.g. entering Protected Mode or Long Mode), you can write to the video memory directly. Just so you know.

Going back to talking about BIOS interrupts, it is fine because you'll be in Real Mode at that stage, which is where you're allowed to perform BIOS interrupts. However, if you try to do it whilst in Protected Mode or Long Mode, it will not work (without Real Mode emulation or switching back to Real Mode temporarily).

The BIOS offers the interrupts for you to be able to rely on its internal functionality to help you get on your feet, so no, it is not bad to use BIOS interrupts whilst in Real Mode.

See the following links, please.

https://wiki.osdev.org/Real_Mode

https://wiki.osdev.org/Virtual_8086_Mode

https://en.wikipedia.org/wiki/Virtual_8086_mode

https://wiki.osdev.org/Protected_Mode