Page 1 of 1

my idt is epic failure

Posted: Sat Mar 05, 2011 11:45 pm
by anonlalo
hi, new to this forum first post :) been reading the wiki and stuff for a while... worked through a bunch of tutorials... I am having trouble at the point of IDT...

I am lost on IDT... it loads correctly, but I am quite sure I'm doing something wrong. my assembler is nasm.

here is my idt.s

Code: Select all

bits 32

global installIDT
extern puts

installIDT:
pusha
lidt [idtr]
popa
ret

startidt:
     dd isr0, 00000000000010001000111000000000b, 0
     dd isr1, 00000000000010001000111000000000b, 0
     < etc, ...>

IDT_END:
idtr:
     dw startidt -IDT_END - 1
     dd startidt

isr0:
pusha
     ;handle interrupt here
popa
sti
iret

isr1:
pusha
     ;handle interrupt here
popa
sti
iret
first i tried this for idt entry:

Code: Select all

dw 0xffff
dw 0x08
db 0
db 10001110b
dw isr0
but it gave me turnication error, which i through process of elimination determined was coming from "dw isr0"

then I tried this line which I found on the forums:

Code: Select all

dw isr0, 8, 1000111000000000b, 0
it gave same error relocation turnicated to fit: r_386_16 against '.text.'

everything assembles and links fine, but when I call an int it crashes...
I have not set the stack in my os, but I booted with grub and the tutorial i looked at also did not set the stack after using grub, so i'm not sure if this is a problem.
I have read the wiki, I have re-read the entire chapter on interupts in the intel manuals, i have searched the forums for "lidt" since "idt assembly" is too common a search string and gives me that error. been trying at this for a good 8 hours can't figure it out.

Re: my idt is epic failure

Posted: Sun Mar 06, 2011 1:15 am
by a5498828
startidt -IDT_END - 1
wtf
sti
iret
iret will load flags from stack

dd isr1, 00000000000010001000111000000000b, 0
please... have you read osdev wiki?
use dw instead of binary because its unreadable.

Re: my idt is epic failure

Posted: Sun Mar 06, 2011 5:06 am
by Chandra
Hi,

there are lots of IDT related stuffs available in the wiki. You may want to have a look at them. There's also an example in the FAQ section which fits best in your case. Thank you.

Re: my idt is epic failure

Posted: Sun Mar 06, 2011 1:49 pm
by anonlalo
hey thanks for your quick responses guys:)

I had read the idt stuff in the wiki and every other bit i could find on it elsewhere, but I did not check the FAQ. After first trying a variation of what the FAQ had, and then exactly what it had...

I went and checked my GDT, i had a typo in the access flags:)

I had considered that using mov with shifts would be good, but I knew i couldn't use them in the IDT itself, and I had a passing thought of editing them in memory with a function, but i had dismissed it as inefficient without even considering the insignificance of a few ms at boot-time.

and as to binary being less readable - i find it pretty easy when I know how the data is divided up and i have a binary calculator.. easier than a bunch of shl and shr which have always required alot of thinking and careful planning for me to work with, perhaps it's just my weakness.

anyways thanks again guys I will go back and try my version see if it works with the gdt fixed.

Re: my idt is epic failure

Posted: Sun Mar 06, 2011 2:08 pm
by Combuster
The linker complains about the fact that you are loading a 16-bit field with a 32-bit address, which obviously does not fit. You will need to split the IDT addresses manually in code since the ELF file format can not do it for you.