Page 1 of 1

RTC interruption

Posted: Mon Oct 09, 2017 8:19 pm
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
*/ 

Re: RTC interruption

Posted: Mon Oct 09, 2017 11:41 pm
by iansjack
No "RTI" instruction?

Re: RTC interruption

Posted: Tue Oct 10, 2017 9:59 am
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.

Re: RTC interruption

Posted: Tue Oct 10, 2017 6:21 pm
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

Re: RTC interruption

Posted: Tue Oct 10, 2017 6:38 pm
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

Re: RTC interruption

Posted: Wed Oct 11, 2017 5:51 am
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 :( .

Re: RTC interruption

Posted: Wed Oct 11, 2017 12:23 pm
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.