How to delay execution for a specified amount of milliseconds when in protected mode?
I have a C program that runs on bare x86 (without an OS) in protected mode. I need to delay the program's execution for a certain amount of time. Currently, I'm doing this:
for(p=0; p<1000000; ++p) asm("pause");
But this looks very very wrong (I do get a delay, but apparently, I have no real control over its duration: the length of 开发者_如何学编程the "pause" is undefined).
Now, I'm not really experienced with stuff at such low level, and I've been searching the net for solutions, but so far the only one that I found involved BIOS interrupts, which don't work in pmode (or so I was told).
So, how do I delay execution when in protected mode?
The typical way to implement delays is using the system timer, also called PIT on x86 (Programmable Interval Timer) to generate an interrupt. You would set up the system timer (hardware IRQ0) to raise an interrupt after a certain time, write the interrupt handler to set some register or flag on interrupt, and, when you need to delay the execution, loop on the register or flag until the interrupt handler sets it.
精彩评论