Page 1 of 1

IDT entry - where does the offset come from?

Posted: Tue Feb 12, 2013 7:42 pm
by BenjiWiebe
I have an IDT entry filled out, except for the two offset values. Where do they come from?

Code: Select all

global LoadIDT
IDTstart:
        dw                      ; offset, first half  ???????
        dw      0x8             ; selector
        db      0               ; unused, set to zero
        db      0x8E            ; type and attributes
        dw                      ; offset, last half ???????
IDTend:

toc:
        dw IDTend - IDTstart - 1        ; limit (Size of IDT)
        dd IDTstart                     ; base of IDT

LoadIDT:
        cli
        lidt [toc]
        ret

handler:
        cli
        hlt
        iret
I want handler to be the code that gets ran when number / 0 occurs.

Any help would be appreciated.

Re: IDT entry - where does the offset come from?

Posted: Tue Feb 12, 2013 10:58 pm
by thepowersgang
May I suggest reading the lovely tutorials on the wiki?
To quickly answer your question (that could be answered with either the wiki, or the CPU's manuals - an indispensable resource) the offset is usually the address of the handler for that interrupt vector.

Re: IDT entry - where does the offset come from?

Posted: Wed Feb 13, 2013 7:36 am
by BenjiWiebe
thepowersgang wrote:May I suggest reading the lovely tutorials on the wiki?
To quickly answer your question (that could be answered with either the wiki, or the CPU's manuals - an indispensable resource) the offset is usually the address of the handler for that interrupt vector.
I have read the tutorial, and I have looked for example code, but 99% of example code is in C, not assembly.

Code: Select all

global LoadIDT
IDTstart:
fo:     resw    1               ; offset, first half
        dw      0x8             ; selector
        db      0               ; unused, set to zero
        db      0x8E            ; type and attributes
lo:     resw    1               ; offset, last half
IDTend:

toc:
        dw IDTend - IDTstart - 1        ; limit (Size of IDT)
        dd IDTstart                     ; base of IDT

LoadIDT:
        cli
        push ax
        mov ax, [handler]
        and ax, 0xFFFF0000
        ror ax, 16
        mov [fo], ax
        mov ax, [handler]
        and ax, 0x0000FFFF
        mov [lo], ax
        pop ax
        lidt [toc]
        ret

handler:
        cli
        hlt
        iret
This is how I am currently trying to do it.

Go ahead, criticize this code. The code is in need of criticism.

Re: IDT entry - where does the offset come from?

Posted: Wed Feb 13, 2013 7:39 am
by Combuster
I don't think this is even close to what you want...

Code: Select all

mov ax, [handler]     ; ax = first >>two bytes<< of "cli; hlt; iret"
and ax, 0xFFFF0000    ; ax = 0
ror ax, 16            ; ax = ax
(hint: learn to use a debugger. It makes errors such as these immediately obvious)

Re: IDT entry - where does the offset come from?

Posted: Wed Feb 13, 2013 8:11 am
by BenjiWiebe
Combuster wrote:I don't think this is even close to what you want...

Code: Select all

mov ax, [handler]     ; ax = first >>two bytes<< of "cli; hlt; iret"
and ax, 0xFFFF0000    ; ax = 0
ror ax, 16            ; ax = ax
(hint: learn to use a debugger. It makes errors such as these immediately obvious)
#-o thanks!!

not sure what i was thinking... oh yeah, i wasn't thinking.