Page 1 of 1

8253 runs too fast

Posted: Fri May 01, 2015 9:08 am
by miaowei
here is my code, running under 32bit, protect mode.

Code: Select all

	
init8253:
         mov al,0x34
	out 0x43,al

	mov ax,[esp+4]
	out 0x40,al
	mov al,ah
	out 0x40,al
I call this function using:
push 65535
call init8253

I printf a character 'h' to 80x24 screen every time clock interrrupt occure,I am sure my IRQ handler works right. But the 'h' was always printed at a fast very speed,at least one full line each second.That means,at least 80 clock interrupts each second. But it's initialized wih 65535. It should be 18Hz.

And, when i push a smaller argument instead of 65535, it printed more quickly.

Thus, I can not find out the answer,it seems that the 8253 just runs faster than it should. I have noticed it for a long time and i don't want to tolerate it any more.

Re: 8253 runs too fast

Posted: Fri May 01, 2015 9:33 am
by xenos
Are you running your code on real hardware or in an emulator? Emulators may be running the 8253 at higher or lower speed than in real time.

Re: 8253 runs too fast

Posted: Fri May 01, 2015 10:35 am
by miaowei
XenOS wrote:Are you running your code on real hardware or in an emulator?
In bochs.
I will give a try on real machine.
But the difference seems too big. I mean, it's a little unacceptable.

Re: 8253 runs too fast

Posted: Fri May 01, 2015 10:47 am
by Techel
Somewhere in the bochs config file you can set it to realtime.

Re: 8253 runs too fast

Posted: Fri May 01, 2015 6:09 pm
by miaowei
Roflo wrote:Somewhere in the bochs config file you can set it to realtime.
OK, it works OK now.
I uncomment the following line in .bochsrc: clock:sync=realtime,time0=938581955
the bochs writer explains:
This defines the method how to synchronize the Bochs internal time with realtime. With the value 'none' the Bochs time relies on the IPS value and no host time synchronization is used.
............the 'realtime' method sacrifices reproducibility to preserve performance and host-time correlation.
However, since it sacrifices reproducibility, I may should choose another config option:
clock: sync=slowdown, time0=315529200

Really good!