Page 1 of 1
GPF being caused by keyboard
Posted: Wed Jul 25, 2007 10:07 pm
by Pyrofan1
here is my main.c
Code: Select all
#include "kernel/kernel.h"
void _main(void* mbd,unsigned int magic)
{
int a=10;
int b=34;
clrscr(BLACK,BLACK);
gdt_install();
idt_install();
set_color(WHITE,BLACK);
set_echo(1);
Printf("Hello world\n");
for(;;);
}
here is the code that calls the irq function
Code: Select all
irq_common:
cli
pusha
mov %ds, %ax
push %ax
mov %es, %ax
push %ax
mov %fs, %ax
push %ax
mov %gs, %ax
push %ax
mov %cr0, %eax
push %eax
mov %cr3, %eax
push %eax
push %esp
call irq_handler
pop %eax
pop %eax
pop %eax
pop %ax
mov %ax, %gs
pop %ax
mov %ax, %fs
pop %ax
mov %ax, %es
pop %ax
mov %ax, %ds
popa
sti
add $8, %esp
iret
and here is my irq_handler
Code: Select all
void irq_handler(struct REGS *r)
{
if(r->int_no==0)
{
timer_handler();
}
else
if(r->int_no==1)
{
keyboard_handler();
}
if (r->int_no >= 40)
{
outportb(0xA0, 0x20);
}
outportb(0x20, 0x20);
}
when i run my kernel i get "Hello world" and when i press a key i get this
http://s176.photobucket.com/albums/w199 ... 0_2144.jpg
Posted: Wed Jul 25, 2007 10:34 pm
by Dex
It may not be your problem, but you should not use cli or sti in your IRQ code, as this is already done, thats why you have "iret".
What happens if you get a irq here:
You may not think it makes a difference, but it does.
Posted: Thu Jul 26, 2007 2:58 am
by JamesM
Have you remapped the PIC correctly?
It looks like you're following bran's tutorial, so double check the byte values are what they should be - It seems like an IRQ is being rerouted to ISR 13.
Posted: Thu Jul 26, 2007 12:06 pm
by salil_bhagurkar
Pyrofan... In the first place why are doing:
Your stack is restored to the original position when you are popping registers... You are corrupting the stack...
![Shocked :shock:](./images/smilies/icon_eek.gif)
Posted: Thu Jul 26, 2007 12:31 pm
by Pyrofan1
okay i found out i wasn't adding my keyboard function to the idt. but now my keyboard function doesn't work.
Code: Select all
void keyboard_handler(void)
{
unsigned char scancode=inportb(0x60);
unsigned char last_key;
if(scancode&0x80){}
else
{
last_key=kbdus[scancode];
if(last_key==KEY_CAPS)
{
if(caps)
{
~caps;
while(1)
{
if((inportb(0x64)&2)==0) break;
}
outportb(0x60,0xED);
outportb(0x60,0x00);
}
else
{
~caps;
while(1)
{
if((inportb(0x64)&2)==0) break;
}
outportb(0x60,0xED);
outportb(0x60,0x04);
}
}
else
if(last_key==KEY_LSHIFT||last_key==KEY_RSHIFT)
{
~shift;
}
else
if(last_key==KEY_ALT)
{
~alt;
}
else
if(last_key==KEY_CTRL)
{
~ctrl;
}
if(last_key!=KEY_CAPS && last_key!=KEY_ALT && last_key!=KEY_CTRL && last_key!=KEY_RSHIFT && last_key!=KEY_LSHIFT)
{
if(shift)
{
switch(last_key)
{
case '1':
last_key='!';
break;
case '2':
last_key='@';
break;
case '3':
last_key='#';
break;
case '4':
last_key='$';
break;
case '5':
last_key='%';
break;
case '6':
last_key='^';
break;
case '7':
last_key='&';
break;
case '8':
last_key='*';
break;
case '9':
last_key='(';
break;
case '0':
last_key=')';
break;
case '\'':
last_key='"';
break;
case ',':
last_key='<';
break;
case '.':
last_key='>';
break;
case '/':
last_key='?';
break;
case '=':
last_key='+';
break;
case '\\':
last_key='|';
break;
case '-':
last_key='_';
break;
case ';':
last_key=':';
break;
case '[':
last_key='{';
break;
case ']':
last_key='}';
break;
default:
break;
}
}
else
{
if(caps||shift)
{
last_key+=('A'-'a');
}
}
if(echo) putchar(last_key);
}
}
}
Posted: Thu Jul 26, 2007 2:25 pm
by os64dev
is it me or do more people have the general feeling that nobody wants to investigate or debug anny more. more i see message in the general idea of it doesnt work help, btw here is my code and fix it. Like pyrofan here it took him two hours to give up. well get use to these issues, they are very commonin os devving. ok end of rant
Posted: Thu Jul 26, 2007 2:35 pm
by JamesM
* JamesM nods head and looks distinctly impressed by os64dev's self-control, pointing to his own replies/flames/trolls/death threats to Compdever in the other thread.
JamesM
Posted: Thu Jul 26, 2007 4:02 pm
by Alboin
os64dev wrote:is it me or do more people have the general feeling that nobody wants to investigate or debug anny more. more i see message in the general idea of it doesnt work help, btw here is my code and fix it. Like pyrofan here it took him two hours to give up. well get use to these issues, they are very commonin os devving. ok end of rant
That reminds me: I recently spent two weeks trying to find this bug in some hashes of mine. I eventually rewrote it in a day using 1/2 as many pointers.
Simplify, simplify, simplify.