Page 5 of 9
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 3:56 pm
by Slasher
seems people don't understand the code i posted.
descriptor_reg idt,gdt;
defines the 6 bytes location needed to store info about where you want to put your idt and gdt descriptors.
this is the 6 bytes needed for the LIDT and LGDT instructions.
so basically, idt.base is the base (just like in the intel manual) and idt.limit is the limit(i.e number of descriptors*8 - 1 cause we start counting from 0)
in memory this looks like
limit base
L L L L B B B B B B B B
don't know how to explain any better. if you need help best to post code, can't work in the DARK! :'(
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 4:28 pm
by Unexpected
Code Slasher, your code is good... but without pointer is easer to understand... I think
I correct the IDT and handlers. Now my keyboard handler works and it looks like this:
void KBD_Handler()
{
Print("KBD Test");
outportb(0x20, 0x20);
asm("MOV %ebp,%esp");
asm("POP %ebp");
asm("IRET");
}
Is it all correct?
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 4:36 pm
by jrfritz
Unexpected...PLEASE post your code for me to see!!!
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 4:46 pm
by jrfritz
I must have did something wrong to Code Slasher's code...so i'd like to see yours because mine still does a exception 8. :-\
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 4:47 pm
by Slasher
looks fine to me.
Tom, if you are processing an Interrupt you have to acknowledge it to the pic by sending
0x20 to 0x20 and 0xA0 ie
mov al,0x20
out 0x20,al
out 0xa0,al
i hope you placed this in your code?
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 4:52 pm
by jrfritz
OPPS!
Where do the ints start at? What number in hex?
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 4:53 pm
by jrfritz
Hey...wait a second...I only set up 31 ints only for exceptions! There's not a IRQ being called!
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 4:58 pm
by jrfritz
Ok ints start at 0x20...I only have up to 0x31 set up...so that's not the problem.
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 5:13 pm
by Slasher
have you reprogrammed the PIC?
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 5:50 pm
by jrfritz
No... :-[ i'll reprogram it now.
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 5:54 pm
by df
Unexpected wrote:
I correct the IDT and handlers. Now my keyboard handler works and it looks like this:
void KBD_Handler()
{
Print("KBD Test");
outportb(0x20, 0x20);
asm("MOV %ebp,%esp");
asm("POP %ebp");
asm("IRET");
}
Is it all correct?
i find its easier+cleaner to enter ints via an asm stub, rather than inline asm asm stackframe removale/iret
(what happens if you compile without stackframes! your code bombs)
Re:Some IDT Code...in C
Posted: Tue Dec 17, 2002 6:36 pm
by jrfritz
Well...remaping the pic workd and my IDT works except for one thing...I get a excep13 complaning about a too small stack...my stack and GDT is 0xFFFF ( stack ) and GDT is 0x0FFFF...
How do I make my stack bigger?
Re:Some IDT Code...in C
Posted: Wed Dec 18, 2002 12:52 am
by beyondsociety
Tom
Remember that your stack in protected mode is still a 16-bit stack and not a 32 bit one. Does this ring a bell.
Code: Select all
mov ax,0x10
mov ss,ax
mov esp,0xFFFF
NASM assumes that, since you are using esp, you are assigning to it a 32-Bit number. If you use a value like 0xFFFF, it will padd it out with zeros to make 0x0000FFFF. In the case of the example above, this means that the stack pointer is initialised very low (for a 32-Bit stack), and would almost certainly be below the segment limit (unless you have a 4Gb stack), which would cause a stack fault.
Hope this helps
Re:Some IDT Code...in C
Posted: Wed Dec 18, 2002 1:12 am
by Pype.Clicker
Unexpected wrote:
Code Slasher, your code is good... but without pointer is easer to understand... I think
I correct the IDT and handlers. Now my keyboard handler works and it looks like this:
void KBD_Handler()
{
Print("KBD Test");
outportb(0x20, 0x20);
asm("MOV %ebp,%esp");
asm("POP %ebp");
asm("IRET");
}
Is it all correct?
Sorry, but you enfringed golden rule #1 of interrupts programming: SAVE and RESTORE everything that might be modified.
including machine registers (eax, ecx ...) that you absolutely don't protect ... the CPU is likely to crash if some registers can be modified at random times.
So, i know this is about writing a IDT in pure C, but now you have to face the truth: IDT setup is feasible in pure C (if you just do an asm(lidt)), but interrupt handlers MUST be written in ASM... Look at your own code, forcing pops from the stack frame, do you think it still looks like C ?
maybe you could try the "interrupt" modifier for your code (though i dunno if it's 4|\|51 or if it's something Borland&MS added to C...
However, i beleive that a good ASM stub is the better way to go. Look at
this code if you need some reference ... that's something that works.
df's code works for exception because he does nothing but halting the processor. If he have tried to return from his exception, he was likely to get another one ...
Re:Some IDT Code...in C
Posted: Wed Dec 18, 2002 7:28 am
by Berserk
Could Somebody PLEASE, PLEASE explain to me, WHAT IS AN IDT! and What does it do??
;D