keyboard problem(interrupts are working, keyboard is not)

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.
pk44
Posts: 12
Joined: Wed May 11, 2011 12:10 pm

Re: keyboard problem(interrupts are working, keyboard is not

Post 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.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: keyboard problem(interrupts are working, keyboard is not

Post 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?
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
pk44
Posts: 12
Joined: Wed May 11, 2011 12:10 pm

Re: keyboard problem(interrupts are working, keyboard is not

Post 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...
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: keyboard problem(interrupts are working, keyboard is not

Post by xenos »

Code: Select all

x86_interrupt IDT
should probably be

Code: Select all

x86_interrupt IDT[256];

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).
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
pk44
Posts: 12
Joined: Wed May 11, 2011 12:10 pm

Re: keyboard problem(interrupts are working, keyboard is not

Post 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
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: keyboard problem(interrupts are working, keyboard is not

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply