GPF being caused by keyboard

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.
Post Reply
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

GPF being caused by keyboard

Post 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
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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:

Code: Select all

sti 
add $8, %esp  ;< HERE
iret 
You may not think it makes a difference, but it does.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.
User avatar
salil_bhagurkar
Member
Member
Posts: 261
Joined: Mon Feb 19, 2007 10:40 am
Location: India

Post by salil_bhagurkar »

Pyrofan... In the first place why are doing:

Code: Select all

add $8, %esp
Your stack is restored to the original position when you are popping registers... You are corrupting the stack... :shock:
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post 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);
		}
	}
}
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post 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
Author of COBOS
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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.

:roll:

JamesM
User avatar
Alboin
Member
Member
Posts: 1466
Joined: Thu Jan 04, 2007 3:29 pm
Location: Noricum and Pannonia

Post 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. :P

Simplify, simplify, simplify.
C8H10N4O2 | #446691 | Trust the nodes.
Post Reply