Some IDT Code...in C
Re:Some IDT Code...in C
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! :'(
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
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?
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
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
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?
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
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
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
i find its easier+cleaner to enter ints via an asm stub, rather than inline asm asm stackframe removale/iretUnexpected 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?
(what happens if you compile without stackframes! your code bombs)
-- Stu --
Re:Some IDT Code...in C
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?
How do I make my stack bigger?
Re:Some IDT Code...in C
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.
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
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
Hope this helps
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Some IDT Code...in C
Sorry, but you enfringed golden rule #1 of interrupts programming: SAVE and RESTORE everything that might be modified.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?
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
Could Somebody PLEASE, PLEASE explain to me, WHAT IS AN IDT! and What does it do??
;D
;D