Reputation: 818
The x86 interrupt 0x1A seems to give the computer's clock time, but it can only give accurate time to within 55ms (AH=0). Is there any way to get smaller increments (and maybe a bit more "normal") than that, like maybe 1ms? I'm trying to make my own toy OS, so i can't use anything i can't write myself.
Upvotes: 5
Views: 506
Reputation: 25268
Since you're making your own OS, you don't have to keep the timer period. It is possible to reprogram the PIT to trigger INT 8 (IRQ 0) more often. See here.
On newer computers you can also make use of the High Precision Event Timer.
Upvotes: 3
Reputation: 29466
You can use the rdtsc
(read timestamp counter) instruction on x86 to get the 64-bit CPU timestamp into edx:eax
. The implementation of this instruction depends on your processor, but it either increments once per clock or at a constant rate. Because of this, the time resolution also varies, but it should be better than 1ms.
There are some caveats to using rdtsc
:
Since you're writing your own OS, you might not need to worry about some of these issues.
Upvotes: 6