ISR correct?

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
Whatever5k

ISR correct?

Post by Whatever5k »

I'm wondering if following ISR is correct:

This is just the code that sets up the ISR:

Code: Select all

[BITS 32]???; Protected Mode
[global setup_handlers]???; called by an extern function
[extern idt]

setup_handlers:
???; ok, let's just do it...
???; set up different interrupt handlers
???; all ISRs are defined in kernel/ints.asm
???; interrupts are still disabled (good)
???
???; IRQ1 (keyboard)
???extern int_irq1

???push ebx???; save
???push edx???; registers
???
???mov ebx, 0x21???; the interrupt number
???shl ebx, 3???; need to multiply by 8
???mov edx, [idt]???; address of IDT to edx
???mov [edx + ebx], dword int_irq1???; interrupt service routine

???pop edx???; restore
???pop ebx???; registers

???ret
And this is the actual ISR:

Code: Select all

[BITS 32]
[global int_irq1]
int_irq1:
   iret   ; do nothing yet
I'm specially wondering, if the instructions

Code: Select all

mov edx, [idt]???; address of IDT to edx
???mov [edx + ebx], dword int_irq1???; interrupt service routine
are correct. I think they are, but I need to be sure ;)
PlayOS

Re:ISR correct?

Post by PlayOS »

Whatever5k wrote:I'm specially wondering, if the instructions

mov edx, [idt]???; address of IDT to edx
???mov [edx + ebx], dword int_irq1???; interrupt service routine

are correct. I think they are, but I need to be sure ;)
OK, the code looks good but a IDT entry is 8 bytes long, this means that all you are putting in the entry is the handler address, which is only half of the entry. Also, the handler address is spread out in two places. This is what an entry looks like:

0:1 - Loword of the Handler Address
2:3 - GDT Descriptor to use for the Handler
4:5 - Attributes
6:7 - Hiword of the Handler Address

Hope this helps. :)
Whatever5k

Re:ISR correct?

Post by Whatever5k »

Yeah, I managed it...
But now, I have another problem: I want to create a function, that is called from a C function. This function sets up a new Interrupt Handler for a secified interrupt...
Look at the code:

Code: Select all

[BITS 32]???; protected mode
[global changeISR]
[extern idt]

; function is called like this for example:
; changeISR(0x21, (void*) int_irq1)
changeISR:
???push ebx
???push edx
???push eax
???push ebp

???mov ebp, esp
            mov ebx, [ss:ebp + 20]???; interrupt number
???mov eax, [ss:ebp + 24]???; interrupt handler
???mov edx, idt???; idt location

???shl ebx, 3???; need to multiply by 8
???mov [edx + ebx], ax???; low offset
???shr eax, 16
???mov [edx + ebx + 6], ax???; high offset

???pop ebp
???pop eax
???pop edx
???pop ebx??????
???
???ret
And this is my C code:

Code: Select all

void changeISR(unsigned int, void *);
void int_irq1(void);

void do_it(void)
{
   remap_pics(0x20, 0x28);
???printk("PICs remapped: IRQs starting at interrupt 0x20\n");
???
???printk("Changing ISR for IRQ1\n");
???changeISR(0x21, (void*) int_irq1);
???printk("Enabling IRQ1\n");
???enable_irq(1);
???asm("sti");
???printk("Interrupts enabled\n");
}
The int_irq1 prints the message "IRQ1" on the screen...
When I link this and run bochs, there's no error message, but there's no "IRQ1" message printed if I press a key...
What is wrong?
Whatever5k

Re:ISR correct?

Post by Whatever5k »

Oh my god, it's terrible...
When I compile and link this and run bochs with GRUB, it sometimes work but sometimes not...
This is impossible!!!
I think it's GRUB who is wrong...because I overwrote GRUB once, and now had to install GRUB again...but I cannot really manage it..
I've copied stage1 and stage2 to /dev/floppy, but I think I have to do more...
HElp!
Whatever5k

Re:ISR correct?

Post by Whatever5k »

No, I have installed GRUB correctly now...but still, sometimes it works, sometimes not...
What the hell is wrong?
Post Reply