RTC interruption

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
pedrodemargomes
Posts: 6
Joined: Wed Aug 30, 2017 9:04 pm
Libera.chat IRC: pedroOS

RTC interruption

Post by pedrodemargomes »

I am trying to set rtc interruptions, but it is not working(triple fault).
I have already setted PIC1 and PIC2 and their interruption masks.

This is the code that sets the rtc interruptions:

Code: Select all

/*          Ports
*        PIC1   PIC2
*Command 0x20   0xA0
*Data    0x21   0xA1
*/


asm volatile ( "cli" ); 
 
uint8_t rate = 0x05;
outb(0x70, 0x8B);
char prev = inb(0x71);
outb(0x70, 0x8B);
outb(0x71, prev | 0x40);

outb(0x70, 0x8A);
prev = inb(0x71);
outb(0x70, 0x8A);
outb(0x71, (prev & 0xF0) | rate );
outb(0x70, 0x0C);
inb(0x71);
 
// PIC 2
/* 0xFE is 11111110 - enables IRQ0 (rtc)*/
uint8_t prevIrq = inb(0xA1);
outb(0xA1 , 0xFE & prevIrq );
     
// PIC 1
/* 0xFB is 11111011 - enables IRQ2 (rtc)*/
prevIrq = inb(0x21);    
outb(0x21 , 0xFB & prevIrq );     

asm volatile ( "sti" ); 
This is the rtc interruption handler:

Code: Select all

/*          Ports
*        PIC1   PIC2
*Command 0x20   0xA0
*Data    0x21   0xA1
*/

outb(0xA1, 0x20);
outb(0x20, 0x20);
/* 
do something
*/ 
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: RTC interruption

Post by iansjack »

No "RTI" instruction?
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: RTC interruption

Post by Octocontrabass »

pedrodemargomes wrote:I am trying to set rtc interruptions, but it is not working(triple fault).
Have you figured out where in your code the triple fault occurs?
pedrodemargomes wrote:

Code: Select all

outb(0xA1, 0x20);
I don't think this line of code does what you want.
pedrodemargomes
Posts: 6
Joined: Wed Aug 30, 2017 9:04 pm
Libera.chat IRC: pedroOS

Re: RTC interruption

Post by pedrodemargomes »

Octocontrabass wrote:
pedrodemargomes wrote:I am trying to set rtc interruptions, but it is not working(triple fault).
Have you figured out where in your code the triple fault occurs?
Yes, it occurs at the first rtc interruption.
Octocontrabass wrote:

Code: Select all

outb(0xA1, 0x20);
I don't think this line of code does what you want.
It supossed to be 0xA0, i fixed that :D .
But the problem is that the program does not get there, it fails before that.

I will let my git repository here:
https://gitlab.com/pedrodemargomes/BootTeste_OS
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: RTC interruption

Post by Brendan »

Hi,
pedrodemargomes wrote:I am trying to set rtc interruptions, but it is not working(triple fault).
In that case it's probably a problem with your GDT, IDT or stack (and not a problem with any of the code you posted). You should be able to get some information about what caused the triple fault from an emulator's logs (e.g. if the first exception was a general protection fault or page fault, etc).
pedrodemargomes wrote:I will let my git repository here:
https://gitlab.com/pedrodemargomes/BootTeste_OS
I couldn't find any source code there.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
pedrodemargomes
Posts: 6
Joined: Wed Aug 30, 2017 9:04 pm
Libera.chat IRC: pedroOS

Re: RTC interruption

Post by pedrodemargomes »

Brendan wrote:Hi,
pedrodemargomes wrote:I am trying to set rtc interruptions, but it is not working(triple fault).
In that case it's probably a problem with your GDT, IDT or stack (and not a problem with any of the code you posted). You should be able to get some information about what caused the triple fault from an emulator's logs (e.g. if the first exception was a general protection fault or page fault, etc).
pedrodemargomes wrote:I will let my git repository here:
https://gitlab.com/pedrodemargomes/BootTeste_OS
I couldn't find any source code there.


Cheers,

Brendan
Sorry, i forgot to change the permissions :D, now it is right.
I could not find any usefull information in the log files about the the faults :( .
MichaelPetch
Member
Member
Posts: 799
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: RTC interruption

Post by MichaelPetch »

Where in your code do you set up the IDT entry for your RTC Interrupt handler? I see you set up an entry for the keyboard at IDT[0x21] to handle IRQ1. To handle IRQ8 (RTC) you would need an IDT entry at IDT[0x28] with the way you set up the PICs and then point it at your rtc_handler function.
Post Reply