PIT doesn't work in Bochs

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
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

PIT doesn't work in Bochs

Post by ateno3 »

I am trying that PIT of Bochs works, but I am tired of try it :cry:
I have already programmed the driver which handles it, but it doesn't work in Bochs, but it works in Virtual Box.
This is my tiny-driver:

Code: Select all

u32 ticks;
	
	void PIT_SendCommand(u8 com){
		outb(com, PIT_COMMAND);
	}
	
	void PIT_Init(){
		DEBUG(true, "\nInitializing PIT... ");
		u16 count=(u16)(1193182L / 100); // Frequency = 100
		PIT_SendCommand(PIT_16BITS | PIT_MODE3 | PIT_2BYTES | PIT_CHAN_0); // 0x36
		outb((u8) count & 0xFF, PIT_CHAN_0);
		outb((u8) (count >> 8) & 0xFF, PIT_CHAN_0);
		IRQ_Disable(0x00);
		DEBUG(true, "[OK]\n");
	}
	
	void PIT_IRQ(){
		ticks++;
		DEBUG(true, "\n[IRQ0: Ticks = %d]\n", ticks);
		UpdateTimers();
		outb(0x20, 0x20);
	}
If someone could help me, I would be thankful. :)

PD: I don't know, but I think my English is bad, if someone didn't understand something, ask me, please.

PD: As you can see, in the code I disable the IRQ0, but later I re-enable it.
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: PIT doesn't work in Bochs

Post by JAAman »

"it doesn't work" doesn't mean anything...

what is it that does (or doesn't) happen

details are important to solving anything


if by "doesn't work" you mean the timing is wrong, thats quite normal for bochs -- because of the way bochs works, the timer does not fire in sync with real time, and instead fires in sync with what is happening in the simulator

if you mean something else, then we need more information to help... at least start with what it is that is going wrong: is it never firing? is it firing once and never again? is it firing an exception?
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

Re: PIT doesn't work in Bochs

Post by ateno3 »

JAAman wrote:"it doesn't work" doesn't mean anything...

what is it that does (or doesn't) happen

details are important to solving anything


if by "doesn't work" you mean the timing is wrong, thats quite normal for bochs -- because of the way bochs works, the timer does not fire in sync with real time, and instead fires in sync with what is happening in the simulator

if you mean something else, then we need more information to help... at least start with what it is that is going wrong: is it never firing? is it firing once and never again? is it firing an exception?
I am sorry, you are right.
The problem is IRQ0 doesn't fire.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: PIT doesn't work in Bochs

Post by bluemoon »

ateno3 wrote:The problem is IRQ0 doesn't fire.
What is this function doing?

Code: Select all

IRQ_Disable(0x00);
By the way, the PIT initialization seems good (the 3 out), so it may be the problem of PIC/APIC code.
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

Re: PIT doesn't work in Bochs

Post by ateno3 »

bluemoon wrote:
ateno3 wrote:The problem is IRQ0 doesn't fire.
What is this function doing?

Code: Select all

IRQ_Disable(0x00);
By the way, the PIT initialization seems good (the 3 out), so it may be the problem of PIC/APIC code.
I don't think so, because I can receive another IRQs, like the IRQ1 (from the keyboard).
ateno3
Member
Member
Posts: 25
Joined: Sun Oct 02, 2011 3:36 am
Location: Spain

Re: PIT doesn't work in Bochs

Post by ateno3 »

I have tried it again, and I have two surprises, one is bad and the another, good.
The good is IRQ0 is called, but only for one time and any more.
halofreak1990
Member
Member
Posts: 41
Joined: Thu Aug 09, 2012 5:10 am

Re: PIT doesn't work in Bochs

Post by halofreak1990 »

ateno3 wrote:I have tried it again, and I have two surprises, one is bad and the another, good.
The good is IRQ0 is called, but only for one time and any more.
This means that, after recieving the IRQ, you are not properly unmasking it in the PIC/APIC register(s).

I had the same thing happen to me on the XBOX, where the PICs don't work with global unmasking. I had to unmask the channels individually.
On the upside, all PICs, even on the PC, support this, so it doesn't introduce incompatibilities.
<PixelToast> but i cant mouse

Porting is good if you want to port, not if you want maximum quality. -- sortie
Post Reply