IDT entry - where does the offset come from?

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
User avatar
BenjiWiebe
Posts: 20
Joined: Thu Feb 07, 2013 9:47 pm
Location: Durham, Kansas
Contact:

IDT entry - where does the offset come from?

Post 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.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

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

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
User avatar
BenjiWiebe
Posts: 20
Joined: Thu Feb 07, 2013 9:47 pm
Location: Durham, Kansas
Contact:

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

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
BenjiWiebe
Posts: 20
Joined: Thu Feb 07, 2013 9:47 pm
Location: Durham, Kansas
Contact:

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

Post 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.
Post Reply