Page 1 of 1

play with PIT, with lots of observations

Posted: Sat Oct 10, 2020 3:05 am
by ITchimp
Playing with various modes of PIT, channel 0, and 2... various modes...

first of all, 111 does not work as 011, at least in bochs
0 0 0 = Mode 0 (interrupt on terminal count)
0 0 1 = Mode 1 (hardware re-triggerable one-shot)
0 1 0 = Mode 2 (rate generator)
0 1 1 = Mode 3 (square wave generator)
1 0 0 = Mode 4 (software triggered strobe)
1 0 1 = Mode 5 (hardware triggered strobe)
1 1 0 = Mode 2 (rate generator, same as 010b)
1 1 1 = Mode 3 (square wave generator, same as 011b)
secondly, I am trying to use 000 (interrupt on terminal count, ie outb(0x43, 0x30)), my goal is that after the counter register reaches zero, (which is
when interrupt gets generated), I will just set the divisor to port 0x40, (hi lo configuration),

Code: Select all

              static void timer_callback(reg_t *r){
                tick++;
                task_switch();

                unsigned long  ddivisor = 1193100/50 ; // 50 is the frequency
                outb(0x40, (unsigned char) (divisor & 0xff));
                outb(0x40, (unsigned char) ((divisor >>8) 0xff));
               }
so my context switch code looks like


it worked for three context switch... but afterwards, context switch stopped working,

notice that I am on purpose trying not to use the square wave (011 mode 3)... can someone tell me why

Re: play with PIT, with lots of observations

Posted: Sat Oct 10, 2020 4:27 pm
by Octocontrabass
ITchimp wrote:first of all, 111 does not work as 011, at least in bochs
This appears to be a bug in Bochs. On real hardware, there is no difference.
ITchimp wrote:it worked for three context switch... but afterwards, context switch stopped working,
You're setting the timer after the context switch? What happens if you switch to a context that doesn't set the timer?

Re: play with PIT, with lots of observations

Posted: Sun Oct 11, 2020 1:47 am
by ITchimp
I am not setting the timer, I am just following the instruction and reset the reload registers,
(since the interrupt trigger when the reload register is decremented to zero) I just set it back up using
frequency division...

I just follow what I read from the osdev doc on PIT...

Re: play with PIT, with lots of observations

Posted: Sun Oct 11, 2020 12:41 pm
by Octocontrabass
Okay, but you're setting the reload register after the context switch.

What happens if the task you switch to doesn't set the reload register?

Re: play with PIT, with lots of observations

Posted: Tue Oct 13, 2020 12:24 am
by ITchimp
https://www.cs.usfca.edu/~cruse/cs630f08/lesson15.ppt
I don't believe this is a bug of bochs... here is the 8254 documentation.

Re: play with PIT, with lots of observations

Posted: Tue Oct 13, 2020 12:50 am
by Octocontrabass
That is not the 8254 documentation. This is. (And this is the 82C54 documentation, since Bochs is supposed to be emulating one of those.)

The timer mode settings are shown on page 6 of the 8254 datasheet and page 8 of the 82C54 datasheet.

Re: play with PIT, with lots of observations

Posted: Tue Oct 13, 2020 1:32 am
by ITchimp
Interesting docs...
I keep seeing the gate signal being able to affect the counting operation, but there is
no way to program it from 0x43...

x 1 1 indicates that it is a don't-care...

also only channel 0 generates irq, the other two channels (1, and 2), you can check their counting status byte using 0x61 (bit 4 and 5 )

Re: play with PIT, with lots of observations

Posted: Tue Oct 13, 2020 2:46 am
by Octocontrabass
ITchimp wrote:I keep seeing the gate signal being able to affect the counting operation, but there is
no way to program it from 0x43...
In an AT-compatible PC, the gate signals for channels 0 and 1 are hardwired. You can't change them. The gate signal for channel 2 can be programmed by writing port 0x61.