Page 1 of 3

PIC, IRQs and IDT?

Posted: Sun Sep 12, 2004 6:39 am
by bubach
I have read a couple of PIC tuts, and it seems like some of them saves the state of the PICs before remapping them. then they restore the state.
Should i do this? What diffrens does it do?
It works fine for me, and i don?t do it at the moment..

/ Christoffer

Re:Save state of PICs?

Posted: Sun Sep 12, 2004 6:53 am
by DennisCGc
AFAIK you only should do that if you're going to switch to realmode in your OS... (also the BIOS will expect, if you're going to use it though, that the IRQs are placed at the interrupts where it's placed at bootup...)
Anyway, I'm not doing it either, because I really don't think it's neccesary....

Re:Save state of PICs?

Posted: Sun Sep 12, 2004 7:34 am
by bubach
Ok. Then i wont do it until someone tells me to. ;)

Re:PIC, IRQs and IDT?

Posted: Mon Sep 13, 2004 1:19 am
by bubach
Hmm. it seemed to work until i did a division with zero on purpose. then it crashed.

i used this tutorial:
http://www.osdever.net/tutorials/interr ... ?the_id=39

and as i am writing my os in asm, my source looks almost exact like it.

i think that the problem lies in my idt, that prob. don?t point to the right place.. :-)

how do i find out the correct offset to my interrupt rutines and put it into the code that might look like this:
code from the tut.

Code: Select all

start_of_idt:
;first entry
dw 0x0000   ; <-- if i am correct, this would be one of the
                 ;       offset parts?
dw 0x10      ; <-- and this would be the gdt segment?
dw 0x8E00   ; <-- hmm, misc info, and enabled bit?
dw 0x20      ; <-- second part off offset?
;second entry
dw 0x0000
dw 0x10
dw 0x8E00
dw 0x30
;third entry
dw 0x0000
dw 0x10
dw 0x8E00
dw 0x10
end_of_idt:
maybe someone have another tutorial link?

Re:PIC, IRQs and IDT?

Posted: Mon Sep 13, 2004 2:27 am
by Brendan
Hi,

I can think of a few ways of getting the offsets into the IDT (or GDT). At assembly time you could:

Code: Select all

dw (theOffset - CODESTART + ORGADDRESS) & 0xFFFF
dw 0x10
dw 0x8E00
dw (theOffset - CODESTART + ORGADDRESS) >> 16
Unfortunately NASM won't let you do "dw theOffset & 0xFFFF" because "theOffset" is a label not a normal number, so you have to add the extra stuff which would need to be defined beforehand. For e.g. at the start of your code put something like:

Code: Select all

%define ORGADDRESS 0x12345678
       org ORGADDRESS
       bits 32
CODESTART:
This should work because subtracting a label from a label leaves a normal number, and ORGADDRESS is also a normal number, so the shift (or and) isn't working on label anymore :)


Alternatively you could do it at run time:

Code: Select all

; eax   Offset for interrupt handler
; bl   Interrupt type (0x8F = trap gate, 0x8E = interrupt gate)
; edx   Address of IDT entry

makeIDTentry:
   push eax
   mov [edx],ax
   mov word [edx+2],SELECTORkernelCode
   shr eax,16
   mov byte [edx+4],0x00
   mov byte [edx+5],bl
   mov [edx+6],ax
   pop eax
   ret
Cheers,

Brendan

Re:PIC, IRQs and IDT?

Posted: Mon Sep 13, 2004 4:59 am
by bubach
So how do i get "theOffset"?
I take the label at my isr, like "isr01"?
do i need to do something with it or could it look like this:

Code: Select all

%define ORGADDRESS 0x100000
       org ORGADDRESS
       bits 32
CODESTART:
and:

Code: Select all

dw (isr01 - CODESTART + ORGADDRESS) & 0xFFFF
dw 0x10
dw 0x8E00
dw (isr01 - CODESTART + ORGADDRESS) >> 16
is that it?

/ Christoffer

Re:PIC, IRQs and IDT?

Posted: Mon Sep 13, 2004 8:40 am
by Brendan
Hi,
bubach wrote: I take the label at my isr, like "isr01"?

is that it?
I could say "yes - it'd work", but what if I'm wrong? Stranger things have happened....

There's really only one way to know for sure - assemble it, then disassemble it :-)


Cheers,

Brendan

Re:PIC, IRQs and IDT?

Posted: Mon Sep 13, 2004 10:02 am
by bubach
Ok, so it didn?t work. or i may have some other problem, becasue i keep getting these "bogus memory"- fault, and bochs dies.
bogus memory.. hm.. i guess that i jumped to some **** place that does not exists?
is this really idt related?

/ Christoffer

Re:PIC, IRQs and IDT?

Posted: Tue Sep 14, 2004 5:04 am
by bubach
Can somebody take a quick look at this source and tell me what i did wrong and where to find info to fix it.

from the kernel:

Code: Select all

     ; Remap PICs.
     ;--------------
          mov     cl, 0x20                            ; PIC 1.
          mov     ch, 0x28                            ; PIC 2.
          call    remap_pics                          ; Remap the PICs.
          call    disable_irqs                        ; Disable IRQs for now.

          mov     dl, 0x0A                            ; row, 00h -> 18h (0 -> 24)
          mov     dh, 0x01                            ; col, 00h -> 4Fh (0 -> 79)
          call    setcursorxy                         ; move it

          mov     esi, pic_irq
          mov     al, 0x07                            ; "White".
          call    print

          mov     dl, 0x0A                            ; row, 00h -> 18h (0 -> 24)
          mov     dh, 0x35                            ; col, 00h -> 4Fh (0 -> 79)
          call    setcursorxy                         ; move it

          mov     esi, pic_irq_ok
          mov     al, 0x02                            ; Green.
          call    print


     ; Setup IDT.
     ;--------------
          lidt    [cs:idt_pointer]
          sti                                         ; Interrupts back..

          mov     dl, 0x0B                            ; row, 00h -> 18h (0 -> 24)
          mov     dh, 0x01                            ; col, 00h -> 4Fh (0 -> 79)
          call    setcursorxy                         ; move it

          mov     esi, idt
          mov     al, 0x07                            ; "White".
          call    print

          mov     dl, 0x0B                            ; row, 00h -> 18h (0 -> 24)
          mov     dh, 0x35                            ; col, 00h -> 4Fh (0 -> 79)
          call    setcursorxy                         ; move it

          mov     esi, idt_ok
          mov     al, 0x02                            ; Green.
          call    print
I have added my own interrupt nr 32 and tried to call it, but i always get a "bogus memory" or "(3) exception, nr 11"-error. :'(

I have attached my idt.in, isr.inc and pic.inc files in three_in_one.asm.txt

I know that it is mutch to ask for u to read all that, but i would be VERY thankful. Probably i have done something really stupid.

/ Christoffer

Re:PIC, IRQs and IDT?

Posted: Tue Sep 14, 2004 11:32 am
by ASHLEY4
Search in the old post ( to when people on this site new asm) under "ASHLEY4" IDT" and you will find my code with all the answers to your ?.

\\\\||////
(@@)
ASHLEY4.

Re:PIC, IRQs and IDT?

Posted: Wed Sep 15, 2004 1:06 am
by bubach
I hate this forums search function.
The site admins should rip phpBB?s search function.

I have tried but i can?t find your thread.
The search function even tells me that u haven?t starded ANY post. Gives me "end of result" when i serach for any thread started by ASHLEY4.
*starts looking throw the pages manually*

/ Christoffer

Re:PIC, IRQs and IDT?

Posted: Wed Sep 15, 2004 1:55 am
by bubach
Can?t find anything usefull. :'(

Re:PIC, IRQs and IDT?

Posted: Wed Sep 15, 2004 2:50 am
by ASHLEY4
Try this:
http://www.mega-tokyo.com/forum/index.p ... 53;start=0

You after look under guest's, i left this forum.

\\\\||////
(@@)
ASHLEY4.

Re:PIC, IRQs and IDT?

Posted: Wed Sep 15, 2004 5:53 am
by bubach
belive me, i didn?t look for only members. i looked for everybody named ashley4.
This forums search function sucks!
why did you leave this forum?

do u have a homepage or something? it would be nice if i could look at all the code, becasue some things seems to be missing in the thread you link to. for example what is 'sys_interrupt'? a label to the start of your isr?s?

thanks for the help!

/ Christoffer

Re:PIC, IRQs and IDT?

Posted: Wed Sep 15, 2004 8:54 am
by ASHLEY4
Give me untill tonight and i will send you a small demo that set up A20,GDT,IDT,remap pic etc and goes to pmode,with code (fasm, may compile with nasm ?).

\\\\||////
(@@)
ASHLEY4.