Page 1 of 1

Calling to driver in Pmode

Posted: Mon Jun 24, 2002 7:58 am
by cobrab
In Real mode when I call the video driver I use the interrupt 10, 13 for disk access. And it?s posible to use other interrup for my drivers.

In Pmode How is the form to implemate a driver, how I comunicate the kernel and the driver?

How detect when a program request a service of the driver?

It's posible to use interrupts (not bios interrupts) for my disk driver, for example int 25 disk driver, int 26 video driver.


Thanks.

Re:Calling to driver in Pmode

Posted: Mon Jun 24, 2002 8:43 am
by crazybuddha
You're actually asking about a lot of things.

A software interrupt using INT is a way to patch code from someplace else into the currently executing code. When you specify a number for the INT, it is an index into a table containing the locations of the code to exectute -- called interrupt service routines. So when you write INT 0x10, this number is multiplied by 4 (because that is the size of each table entry) and the result gets you to byte 0x40 in the IVT (Interrupt Vector Table). Under pmode, it is the IDT (Interrupt Descriptor Table) and each entry is 8 bytes long.

A hardware interrupt does the same thing. A device called the Interrupt Controller is programmed with indexes into the IVT/IDT for each hardware device that will be issuing an interrupt.

The CPU itself uses the same scheme in response to certain conditions (such as trying to divide by zero), although these are referred to as "exceptions", not interrupts.

Now the actual code (interrupt service routines and drivers) to communicate with hardware is something different. There are "ports" associated with the device and these are accessed using the instructions IN and OUT. Alternately, a device can be "mapped" to a regular memory location. An example would be the video frame buffer, which is at 0xA0000. So if you write a value to this memory loction directly, it will be handled by the video controller and placed on the display for you to enjoy as a dot in the upper left corner.

Now all of this gets very, very messy because hardware which can be added to the system is not standardized. (even the system itself is often not standardized due to technological advances). This is the reason you need a driver for a particular card. It has a chip with registers that need to be programmed in unique ways and you access them through particular ports or memory map, which you have to find out.

Obviously, this is a big problem confronting a new OS -- "do I really have to write drivers for all the hardware my OS will support?" Yup.

For hardware devices that are common to all PC systems, the BIOS suffices to communcate with them. For reasons I don't know, BIOS operates in real-mode only, but there is a special "bridge" between protected mode and real mode -- called V86 -- that lets you drop down into a quasi-real mode in order to access the BIOS without suffering the evils of real mode.

As far as implementing system calls in standard libraries for programs on your OS, this is up to you. My feeling is that many OS developers want to be able to use pre-existing libraries, as well as run existing software. This is almost a separate issue involving POSIX compliance and so on.

I believe our friend, Tim, has a bit of experience in several of these areas, and has summarized his experience in a few articles. Perhaps someone will supply links.

Re:Calling to driver in Pmode

Posted: Mon Jun 24, 2002 3:41 pm
by Tim
I believe our friend, Tim, has a bit of experience in several of these areas, and has summarized his experience in a few articles. Perhaps someone will supply links.
Yep, the OS Journal is a good place for this kind of thing: http://www.osjournal.n3.net/. Crazybuddha is probably thinking in particular of the device interface article I wrote.