8253 runs too fast

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
miaowei
Member
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

8253 runs too fast

Post 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.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: 8253 runs too fast

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
miaowei
Member
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

Re: 8253 runs too fast

Post 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.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: 8253 runs too fast

Post by Techel »

Somewhere in the bochs config file you can set it to realtime.
miaowei
Member
Member
Posts: 84
Joined: Wed Dec 18, 2013 9:10 am

Re: 8253 runs too fast

Post 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!
Post Reply