OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Nov 25, 2020 9:51 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: play with PIT, with lots of observations
PostPosted: Sat Oct 10, 2020 3:05 am 
Offline
Member
Member

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

Quote:
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:
              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


Top
 Profile  
 
 Post subject: Re: play with PIT, with lots of observations
PostPosted: Sat Oct 10, 2020 4:27 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 2480
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?


Top
 Profile  
 
 Post subject: Re: play with PIT, with lots of observations
PostPosted: Sun Oct 11, 2020 1:47 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: play with PIT, with lots of observations
PostPosted: Sun Oct 11, 2020 12:41 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 2480
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?


Top
 Profile  
 
 Post subject: Re: play with PIT, with lots of observations
PostPosted: Tue Oct 13, 2020 12:24 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 113
https://www.cs.usfca.edu/~cruse/cs630f08/lesson15.ppt
I don't believe this is a bug of bochs... here is the 8254 documentation.


Top
 Profile  
 
 Post subject: Re: play with PIT, with lots of observations
PostPosted: Tue Oct 13, 2020 12:50 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 2480
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.


Top
 Profile  
 
 Post subject: Re: play with PIT, with lots of observations
PostPosted: Tue Oct 13, 2020 1:32 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 113
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 )


Top
 Profile  
 
 Post subject: Re: play with PIT, with lots of observations
PostPosted: Tue Oct 13, 2020 2:46 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 2480
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group