Loading IDT

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.
OSMAN

Re:Loading IDT

Post by OSMAN »

Thanks for reply.

You don't sound rude. I know I don't know asm very well yet. But I will learn it. I don't belive that one guy in the forum who told he had learned asm basics in 4 hours.

But could you still tell me what is SELECTORkernelCode for I could use the function? (I think I understand the rest of it in some way?!?!)
JoeKayzA

Re:Loading IDT

Post by JoeKayzA »

I don't want to interfere here, but I *guess* it is a constant that contains the selector of the code segment which contains the kernel code. From looking at the code, this seems to make sense. ;)

cheers Joe
OSMAN

Re:Loading IDT

Post by OSMAN »

Hi again!

When I have this in data section:
;;;;;;;;;;;;;;;;;;;;;;;;
idt_start:
dw 0x0000 ; <--<
dw 0x08
dw 0x8E00
dw 0x20 ; <--<
...and so on for all of the slots...
idt_end:
;;;;;;;;;;;;;;;;;;;;;;;;
..., how can I point to the "arrow places" from the asm code? I tried :
mov word [idt_start+1], eax
and
mov word [idt_start+4], eax
but I guess it doesn't work!?

(idt_start and -_end are global symbols)
AR

Re:Loading IDT

Post by AR »

Code: Select all

; 1:
mov ax, [idt_start]

; 2:
mov ax, [idt_start+6]
AL/AH = 1byte, AX=2bytes, EAX=4bytes [and RAX=8bytes]

A word (DW) is 2 bytes so idt_start + 2*(entry-1).
OSMAN

Re:Loading IDT

Post by OSMAN »

Thanks.

I wrote this by myself :)

mov ax, isr0-$$ & 0xFFFF
mov [start_of_idt],ax
mov ax, (isr0-$$ >> 16) & 0xFFFF
mov [start_of_idt+6],ax

I meant it to fill the first slot of the empty IDT with isr #0 (, which exists of course), but it crashes my kernel! Why?
(I call it before "sti" and "call main")

Please tell me the correct version of this.
OSMAN

Re:Loading IDT

Post by OSMAN »

Please answer the message ^ above ^ ; otherways I'm stuck in OS-dev.!
0Scoder
Member
Member
Posts: 53
Joined: Sat Nov 11, 2006 8:02 am

Re:Loading IDT

Post by 0Scoder »

One question:
Excuse me if I missed something, but: why don't you code the idt in c?
OSMAN

Re:Loading IDT

Post by OSMAN »

Because I think I can get it more clear in asm; like if I'll want to port my os to a new arch some day I can just rewrite the asm.

I want to do everything like IDT, GDT and so-on in asm-file. C files can then contain everything related with the real work; asm for initialization and the base.

So, could you help me with my problem?!

(Sorry, the code above won't crash my kernel: it just does nothing. What's wrong with it?)
OSMAN

Re:Loading IDT

Post by OSMAN »

So, will you help me?
User avatar
bubach
Member
Member
Posts: 1223
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

Re:Loading IDT

Post by bubach »

Why "-$$"?
Why not hardcoding it (you can still change it at runtime later)?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
OSMAN

Re:Loading IDT

Post by OSMAN »

If I leave "-$$" off it will give me syntax error, something like "operator may only be applied to scalar values"

Is isr0-$$ a pointer to isr0 label?

Please tell me why this code doesn't work:

Code: Select all

mov ax, isr0-$$ & 0xFFFF
mov [start_of_idt],ax
mov ax, (isr0-$$ >> 16) & 0xFFFF
mov [start_of_idt+6],ax
(That code was supposed to fill slot#0 of IDT with isr0's address)

Before that code I do LIDT. After it I call main. And after calling main I have:

Code: Select all

global isr0
isr0:
 pusha
 push gs
 push fs
 push es
 push ds
 extern interrupt_service_routine0
 call interrupt_service_routine0
 pop ds
 pop es
 pop fs
 pop gs
 popa
iret
And in C I have:

Code: Select all

void interrupt_service_routine0(void)
{
 stdprint( "Interrupt 0 called" );
 byte_out_port( 0x20, 0x20 );
}


But interrupt_service_routine0 never gets called! Why?
(if I do STI before calling main: kernel crashes)
(if I do asm("sti"); nothing happens)
AR

Re:Loading IDT

Post by AR »

If you have only implemented ISR0, ISR0=Divide by Zero Exception, any other interrupt (ie. the periodic PIT hardware interrupt) will fail which will double fault which isn't handled either which will triple fault and reboot.
OSMAN

Re:Loading IDT

Post by OSMAN »

If you have only implemented ISR0...
No, I have not.

As I told you, there was something wrong with my code, and I'd like that if you made an exception and told me what's wrong with it.

I tried to divide n/0 in main but nothing happened. Did you mean I have to implement some other interrupts to get any of them working?
0Scoder
Member
Member
Posts: 53
Joined: Sat Nov 11, 2006 8:02 am

Re:Loading IDT

Post by 0Scoder »

BTW do you mean IRQ0 instead interrupt 0? Because if you are expecting to catch the timer interrupt that is called periodically, you need to set up the PIC. First you need to re-map the IRQ (hardware) interupts so that they don't conflict with various protected mode stuffs. Then you also need to unmask the IRQ's you want to use. There is a tutorial about this on bonafide I believe.

Also, I generally find c more portable, as with a change in instruction sets you only have to get a compiler for that architechture, whereas with asm you might end up replacing all the instructions manually!
OSMAN

Re:Loading IDT

Post by OSMAN »

Perhaps you're right with that portable-code thing! I mean the interrupt 0 which is described at the first entry of IDT. I will do it in C later, but could you now PLEASE give me what I've asked for in 6 mails already!?!!!!!!
Post Reply