play with PIT, with lots of observations

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
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

play with PIT, with lots of observations

Post 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
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: play with PIT, with lots of observations

Post 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?
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

Re: play with PIT, with lots of observations

Post 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...
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: play with PIT, with lots of observations

Post 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?
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

Re: play with PIT, with lots of observations

Post 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.
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: play with PIT, with lots of observations

Post 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.
ITchimp
Member
Member
Posts: 134
Joined: Sat Aug 18, 2018 8:44 pm

Re: play with PIT, with lots of observations

Post 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 )
Octocontrabass
Member
Member
Posts: 5572
Joined: Mon Mar 25, 2013 7:01 pm

Re: play with PIT, with lots of observations

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