Page 3 of 5
Re:Loading IDT
Posted: Fri Sep 16, 2005 7:10 am
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?!?!)
Re:Loading IDT
Posted: Fri Sep 16, 2005 7:25 am
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
Re:Loading IDT
Posted: Sat Sep 24, 2005 4:05 am
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)
Re:Loading IDT
Posted: Sat Sep 24, 2005 4:33 am
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).
Re:Loading IDT
Posted: Sat Sep 24, 2005 6:28 am
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.
Re:Loading IDT
Posted: Sun Sep 25, 2005 7:10 am
by OSMAN
Please answer the message ^ above ^ ; otherways I'm stuck in OS-dev.!
Re:Loading IDT
Posted: Sun Sep 25, 2005 8:13 am
by 0Scoder
One question:
Excuse me if I missed something, but: why don't you code the idt in c?
Re:Loading IDT
Posted: Sun Sep 25, 2005 11:01 am
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?)
Re:Loading IDT
Posted: Mon Sep 26, 2005 6:02 am
by OSMAN
So, will you help me?
Re:Loading IDT
Posted: Mon Sep 26, 2005 7:05 am
by bubach
Why "-$$"?
Why not hardcoding it (you can still change it at runtime later)?
Re:Loading IDT
Posted: Mon Sep 26, 2005 7:53 am
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)
Re:Loading IDT
Posted: Mon Sep 26, 2005 8:06 am
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.
Re:Loading IDT
Posted: Mon Sep 26, 2005 9:04 am
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?
Re:Loading IDT
Posted: Mon Sep 26, 2005 9:23 am
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!
Re:Loading IDT
Posted: Mon Sep 26, 2005 10:52 am
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!?!!!!!!