Page 1 of 1

IRQs and how they work?

Posted: Sun Apr 13, 2003 10:15 am
by Thunder
Hello!
I have read about ISRs IRQs and software interrupts, but one thing worries "How works IRQs and how setup them"?
Bye

Re:IRQs and how they work?

Posted: Sun Apr 13, 2003 10:59 am
by Unexpected
If you are in PMode, first you must create Interrupt Description Table(IDT). In this table is writed where interrupts handlers is. Then you need initialize the PIC to enable interrupts.
It works like:
When comes a hardware call (for ex. you press a keyboard button), then CPU "jumps" to IRQ1 handler(hanler address located in IDT).

P.S. - sorry for my poor English :'(

Re:IRQs and how they work?

Posted: Sun Apr 13, 2003 1:01 pm
by Thunder
then I must to create ISR for keyboard? I'm wrong?
If keyboard is IRQ2 then the ISR2 should handle with keyboard? How about exeptions?

Re:IRQs and how they work?

Posted: Sun Apr 13, 2003 2:01 pm
by Unexpected
IRQ - interrupt, ISR - exeption
And keyboard uses IRQ1 not 2(see http://osdev.neopages.net/tutorials/irqs.php).
So you must create in IDT table 32 entrys for exeptions plus interrupts. Keyboard interrupt is 34(33 - Timer).
Full IDT size is 255 entries.
:)

Re:IRQs and how they work?

Posted: Sun Apr 13, 2003 2:21 pm
by Thunder
Aciu tau dar karta :) :D

Re:IRQs and how they work?

Posted: Sun Apr 13, 2003 2:34 pm
by Thunder
So here is a part of my GDT:
codesel equ $-gdt
dw 0FFFFh
dw 0
db 0
db 9Ah
db 0CFh
db 0

DW ISR0
DW 0x08 ;code selector ???????????
DB 0x00
DB 0x8E
DW 0x00


what should be in dw 0x08?
Thanks

Re:IRQs and how they work?

Posted: Sun Apr 13, 2003 4:58 pm
by Unexpected
I dont understand your question but..
Here is example GDT:

Code: Select all

GDT
   DD 0
   DD 0
; CodeSel
   DW 0FFFFh
   DW 0
   DB 0
   DB 10011010b
   DB 0CFh
   DB 0
; DataSel
   DW 0FFFFh
   DW 0
   DB 0
   DB 10010010b
   DB 0CFh
   DB 0
GDT_End
Here is example of IDT entry:

Code: Select all

IDT_0:
   DW EXN_0
   DW CodeSel
   DB 0x00
   DB 0x8e
   DW 0x0000
CodeSel must be 0x08, because NULL entry is 8bytes long(two DD). DataSel must be 0x10 because NULL entry + CodeSel = 8 + 8 = 0x10(in hex)

Ner uz ka ;)

Re:IRQs and how they work?

Posted: Mon Apr 14, 2003 4:04 am
by Thunder
OK Thanks

Re:IRQs and how they work?

Posted: Mon Apr 14, 2003 4:17 am
by Thunder
Hey, but when I'm trying to create IDT:
DW ISR0
DW 0x08 ;code selector but should it be 0x0800
DB 0x00
DB 0x8E
DW 0x0000

The NASM says that: (.text+0x5a):" relocation truncated to fit: 16 text" this is DW ISR0, but when I write "DD ISR0" I get no errors, and when I put command "sti" computer just restarts.Whats wrong?
;Here is my part of ISR0:
ISR0:
pusha
push gs
push fs
push es
push ds

[extern _isr_0]
call _isr_0
pop ds
pop es
pop fs
pop gs
popa
iret

Re:IRQs and how they work?

Posted: Tue Apr 15, 2003 8:45 am
by Pype.Clicker
what is wrong is that the linker will have to make a 32-bit address fit a 16-bits location. This has been replied about 10 times on this forum... check out archives if it doesn't speak by itself...