Page 1 of 1

ISR correct?

Posted: Thu Sep 26, 2002 8:05 am
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 ;)

Re:ISR correct?

Posted: Fri Sep 27, 2002 4:42 am
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. :)

Re:ISR correct?

Posted: Fri Sep 27, 2002 5:55 am
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?

Re:ISR correct?

Posted: Fri Sep 27, 2002 6:54 am
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!

Re:ISR correct?

Posted: Fri Sep 27, 2002 7:01 am
by Whatever5k
No, I have installed GRUB correctly now...but still, sometimes it works, sometimes not...
What the hell is wrong?