about hardware drivers in protected mode
Recently, I'm trying to write a simple OS. This is a big project.
when I'm writing my code, I'm wondering how modern OS contact hardware under protected mode In real mode, we can just call the bios interrupt to accomplish this job. But I'm wondering how to accomplish this goal in protected mode.(Is it using in and out instru开发者_高级运维ction??) I traced some of the linux source code, but still can't find the appropriate code.I know it is a basic question to many people, plz help me, tks.
and sorry about my poor English.In protected mode, the CPU can run in either kernel mode or user mode. In kernel mode, you can always access the hardware. Calling BIOS interrupt is one old method, but a modern OS normally has its own device drivers for the hardware and does not call BIOS too often. If you know the hardware datasheet, you can use in
, and out
to access the hardware directly. Also, for modern PCI and PCI Express devices, they supported memory mapped IO (X86 CPU also supports this), and it means you can use mov
to access the hardware.
For x86, the CPU also allows the user level program to access the hardware using in and out instructions. You can find it on Intel CPU manual. Just set DPL, CPL? (I forgot the correct name).
I guess you'd better read some book about device drivers, such as Linux Device Drivers, 3rd edition. http://lwn.net/Kernel/LDD3/
精彩评论