Entering Pmode - Keyboard controller needed ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
modshah

Entering Pmode - Keyboard controller needed ?

Post by modshah »

Hi everybody,

I have been reading osdev tuts all over the net. One methodology says to directly load the gdt, set bit 0 of cr0 and then jump to a 32bit code. Another method says to play around with a keyboard controller. Can someone help me with this ? Honestly I don't see any connection between a keyboard controller and Pmode.

Please Help.
Jamethiel

RE:Entering Pmode - Keyboard controller needed ?

Post by Jamethiel »

I see two connections between a keyboard controller and PMode.

Back in the days of old, when the 286 ruled the earth, there was no way to leave PMode short of resetting the CPU. Intel's engineers didn't see any reason for someone to -want- to leave PMode, so they didn't put that functionality in.

Of course, this wasn't acceptable for personal computer applications, because they needed to be able to return to real mode for a variety of reasons.

So IBM's engineers came up with a trick. They wired one of the unused pins on the keyboard controller to the CPU reset line so that the CPU could be reset on command.

The problem with this was that when the CPU was reset, control ended up at the BIOS, which doesn't really help all that much. So they added another trick involving reserved memory locations, some of the CMOS clock chip memory, and so on. This allowed the BIOS to check to see if this was a programmed reboot, and jump to a program-specified address if it was.

Of course, these days we have a much faster method for rebooting even a 286 than going through the keyboard controller (although you still need to set up the special junk for regaining controll after the reboot). We just triple-fault the CPU.

Anyway, all this only applies for a 286, -leaving- PMode, when you don't know about the Triple-Fault trick.

The -other- connection was also forged in the days of the 286, but still applies even today. And that is the A20 line gate. You don't strictly need to enable the A20 line to enter PMode, but you do if you want to access any memory above the 1 megabyte line.

The A20 line gate was used for compatability with all the Real Mode software that tried to access the interrupt vector table and other such low-memory variables by messing with the 64k high memory area (which, on the 8086, worked, but on the 286 accessed the 64k of memory starting at the 1 megabyte line).

IBM's engineers added the A20 line gate to disable the A20 address line, forcing all memory accesses above 1 megabyte to be reflected down to the first megabyte of address space.

I hope that these bits of PC history are in some way helpful.

--Jamethiel
modshah

RE:Entering Pmode - Keyboard controller needed ?

Post by modshah »

Thank you Jamethiel for the detailed description. Could you please explain triple-fault. One more thing - So I have to play around with keyboard controller to get more than 1Mb memory ?

--modshah
Jamethiel

RE:Entering Pmode - Keyboard controller needed ?

Post by Jamethiel »

A double-fault is when an interrupt or exception occurs and an exception occurs while trying to handle it. In this case, the double-fault exception is raised.

If an exception occurs while trying to handle a double-fault exception, the CPU halts, and some hardware on the motherboard detects this and resets it. This is called "triple-fault".

Some, but by no means all, motherboards provide something called a "fast A20 gate". If your motherboard supplies this and you know how to use it (I don't), then you won't have to mess with the controller to access the upper memory areas.
Post Reply