Page 2 of 2
Re: keyboard problem(interrupts are working, keyboard is not
Posted: Sat May 14, 2011 8:24 pm
by pk44
I think that it must be something in my C code, because i have tried calling my kmain from various different assembly files and booting in both qemu and virtualbox, also removing or adding sti or cli to my assembly loader and it is always the same.
Re: keyboard problem(interrupts are working, keyboard is not
Posted: Sun May 15, 2011 1:19 am
by xenos
If an interrupt causes a GPF, there's probably something wrong with your IDT. Have you checked whether your IDT entries are correct?
Re: keyboard problem(interrupts are working, keyboard is not
Posted: Sun May 15, 2011 3:13 pm
by pk44
If there is anything wrong with it, I sure don't see it...My interrupt and IDt structs look like this
Code: Select all
/* structure for an interrupt */
typedef struct
{
word low_offset; // low nibble of offset to handler of interrupt
word selector; // GDT selector used
word settings; // settings for int
word high_offset; // high nibble to handler code
} __attribute__ ((packed)) x86_interrupt;
/* structure for the IDTR */
typedef struct
{
word limit; // limit or Size of IDT
x86_interrupt *base; // a pointer to the base of the IDT
} __attribute__ ((packed)) idtr;
first, I turn off interrupts, then I re-map the pic( you have already seen that functions), then i mask IRQs, then i load make all of my descriptors with the addint function, then I load my IDT with this:
Code: Select all
idtr IDTR;
x86_interrupt IDT
void loadIDTR()
{
IDTR.limit = 256*(sizeof(x86_interrupt)-1);
IDTR.base = IDT;
idtr *IDTRptr = &IDTR;
/* load IDTR with lidt */
asm volatile("LIDT (%0) ": :"p" (IDTRptr));
}
then I unmask IRQs and turn on interrupts and thine erything should be fine, but the cli in my loader is run so I think that it stops the interrupts from the keyboard, or when I remove some strange error in my IDT gets a gpf. Thanks for your help, should i use lidt in my asm loader after i call the kernel and then turn interrupts on, do you think? maybe that would change something, but i don't know much of the effects of inline assembly...
Re: keyboard problem(interrupts are working, keyboard is not
Posted: Mon May 16, 2011 12:18 pm
by xenos
should probably be
Code: Select all
IDTR.limit = 256*(sizeof(x86_interrupt)-1);
should probably be
Code: Select all
IDTR.limit = 256*sizeof(x86_interrupt);
(See Vol. 2A of the Intel manuals, LGDT / LIDT instruction.)
I am not 100% sure about the LGDT instruction in inline assembly (it is rarely used, and I load the IDT in a separate asm file).
Re: keyboard problem(interrupts are working, keyboard is not
Posted: Mon May 16, 2011 1:30 pm
by pk44
I fixed it. It works now, but its not really the same IDT...I completely re-did my kernel (it wasn't very far along anyway) using Bran's kernel development tutorial on osdever.net as a reference and the keyboard works now. Thanks alot for all of your help! I will change those lines anyway and see if it works but it is fine now with my new kernel. Now on to the next part of operating system development... thanks again
Re: keyboard problem(interrupts are working, keyboard is not
Posted: Tue May 17, 2011 12:08 am
by xenos
berkus wrote:, since limit is one less than the size.
I remember that we had
this discussion a while ago. It seems that the Intel and AMD manuals are a bit insonsistent whether limit = size or limit = size - 1. But you're probably right, I just checked the output of sidt on my Core i7 and I get limit = 4095.