Page 1 of 1

PIT doesn't work in Bochs

Posted: Mon Oct 22, 2012 12:53 pm
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.

Re: PIT doesn't work in Bochs

Posted: Tue Oct 23, 2012 7:10 am
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?

Re: PIT doesn't work in Bochs

Posted: Tue Oct 23, 2012 12:43 pm
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.

Re: PIT doesn't work in Bochs

Posted: Tue Oct 23, 2012 2:11 pm
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.

Re: PIT doesn't work in Bochs

Posted: Tue Oct 23, 2012 2:40 pm
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).

Re: PIT doesn't work in Bochs

Posted: Wed Oct 24, 2012 3:18 pm
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.

Re: PIT doesn't work in Bochs

Posted: Mon Oct 29, 2012 2:02 pm
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.