OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Feb 24, 2018 8:04 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: IRQs cause exceptions?
PostPosted: Fri Dec 22, 2017 11:14 pm 
Offline

Joined: Thu May 25, 2017 10:41 pm
Posts: 16
Once I enable interrupts with sti, I get an exception.
Before I enable IRQs, I first remap the PIC to offsets 0x20 on master and 0x28 on slave; here is the remapping code:

Code:
void irq_remap() {
   outb(0x20, 0x11);
   outb(0xA0, 0x11);
   outb(0x21, 0x20);
   outb(0xA1, 0x28);
   outb(0x21, 0x04);
   outb(0xA1, 0x02);
   outb(0x21, 0x01);
   outb(0xA1, 0x01);
   outb(0x21, 0x0);
   outb(0xA1, 0x0);
}


And this is my IRQ-installing code:
Code:
void install_irqs() {
   irq_remap();
   set_idt_gate(32, (unsigned)irq0, 0x08, 0x8E);
   set_idt_gate(33, (unsigned)irq1, 0x08, 0x8E);
   set_idt_gate(34, (unsigned)irq2, 0x08, 0x8E);
   set_idt_gate(35, (unsigned)irq3, 0x08, 0x8E);
   set_idt_gate(36, (unsigned)irq4, 0x08, 0x8E);
   set_idt_gate(37, (unsigned)irq5, 0x08, 0x8E);
   set_idt_gate(38, (unsigned)irq6, 0x08, 0x8E);
   set_idt_gate(39, (unsigned)irq7, 0x08, 0x8E);
   set_idt_gate(40, (unsigned)irq8, 0x08, 0x8E);
   set_idt_gate(41, (unsigned)irq9, 0x08, 0x8E);
   set_idt_gate(42, (unsigned)irq10, 0x08, 0x8E);
   set_idt_gate(43, (unsigned)irq11, 0x08, 0x8E);
   set_idt_gate(44, (unsigned)irq12, 0x08, 0x8E);
   set_idt_gate(45, (unsigned)irq13, 0x08, 0x8E);
   set_idt_gate(46, (unsigned)irq14, 0x08, 0x8E);
   set_idt_gate(47, (unsigned)irq15, 0x08, 0x8E);
}


Here is IRQ 0 in assembly:

Code:
irq0:
   cli
   push 0
   push 32
   jmp stub


This jumps to an assembly stub common to each IRQ:

Code:
stub:
   pushad
   mov eax, esp
   push eax
   mov eax, handle_irq
   call eax
   pop eax
   popad
   add esp, 8
   iret


Which then calls this C handler:

Code:
void handle_irq(struct regs *r) {
   void (*handler)(struct regs *r);
   handler = irq_routines[r->int_no - 32];
   if(handler) {
      handler(r);
   }
   if(r->int_no >= 40) {
      outb(0xA0, 0x20);
   }
   outb(0x20, 0x20);
}


I am somewhat suspicious that the issue is in my register frame, so here it is:

Code:
struct regs {   
   dword errcode, int_no, ebp, esp, ebx, edx, ecx, eax, esi, edi;
};


Does anyone know what may be the issue?
Thanks


Top
 Profile  
 
 Post subject: Re: IRQs cause exceptions?
PostPosted: Fri Dec 22, 2017 11:22 pm 
Offline

Joined: Thu May 25, 2017 10:41 pm
Posts: 16
Never mind. Really was a problem with my regs structure; forgot that the CPU pushes some things as well (plus my order was reversed)
Here it is:
Code:
struct regs {   
   dword edi, esi, ebp, esp, ebx, edx, ecx, eax, int_no, errcode, eip, cs, eflags, esp2, ss;
};


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google Feedfetcher and 4 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