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.
petrusss
Post
by petrusss » Fri Dec 19, 2003 6:36 am
Hi!
I'm having problems with my OS, I'm trying to fix hardware interrupts but I can't make it work...
Software interrupts work perfectly.
When I try to unmask the keyboard, I get a General Protection Fault.
This is my unmasking code:
Code: Select all
void unmaskIRQ(unsigned char irq) {
if(irq==ALL) {
outb(MASTERDATA,0x00);
outb(SLAVEDATA,0x00);
}
else {
irq = irq & (1<<irq);
if(irq < 8)
outb(MASTERDATA, irq&0xFF);
else
outb(SLAVEDATA, irq>>8);
}
}
petrusss
Post
by petrusss » Fri Dec 19, 2003 6:38 am
And here's the main code:
Code: Select all
extern void kbdHandler_stub();
extern void print_version_stub();
void kbdHandler();
void print_version();
void kstart() {
INTS(false);
remapPIC(0x20,0x28);
maskIRQ(ALL);
LoadExceptions();
AddInt(KEYBOARD, kbdHandler_stub, 0);
AddInt(21, print_version_stub, 0);
loadIDTR();
unmaskIRQ(KEYBOARD);
INTS(true);
kclearScreen();
kprintf("Welcome!");
asm("int $1");
return;
}
void print_version() {
kprintf("\n======================\n");
kprintf("PeOS version 0.0000001\n");
kprintf("======================\n");
}
void kbdHandler() {
kprintf("Key pressed!");
// char scancode = inb(0x60);
//sendEOI();
//outb(0x21, EOI);
}
I've tried to put the call to unmaskIRQ elsewhere in the code, but I still get GPF.
Pype.Clicker
Member
Posts: 5964 Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:
Post
by Pype.Clicker » Fri Dec 19, 2003 8:43 am
petrusss wrote:
This is my unmasking code:
Code: Select all
void unmaskIRQ(unsigned char irq) {
if(irq==ALL) {
outb(MASTERDATA,0x00);
outb(SLAVEDATA,0x00);
}
else {
irq = irq & (1<<irq);
if(irq < 8)
outb(MASTERDATA, irq&0xFF);
else
outb(SLAVEDATA, irq>>8);
}
}
There are things that looks weird in the "irq = irq & (1<<irq)" command. I would rather have expected something like
Code: Select all
irqmask = inb(MASTERDATA);
irqmask &= (1<<irq);
outb(MASTERDATA,irqmask);
so that only the bit from "irq" number is toggled, and other are left unchanged.
There are chances that your code also enable IRQ0, which has no handler so far and thus will trigger GPF every 1/18.2 sec.
petrusss
Post
by petrusss » Fri Dec 19, 2003 10:15 am
Thanks, I don't get GPF now
But I still don't get keypresses
Pype.Clicker
Member
Posts: 5964 Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:
Post
by Pype.Clicker » Fri Dec 19, 2003 10:25 am
where do "kstart()" returns to ? if it's a 'cli; hlt" loop, you're unlikely to get any keypress at all ...
Did you sent an end-of-interrupt signal to the PIC in your handler?
Did you read the byte from the keyboard controller ?
both these stuff are mandatory to get more IRQ1 ?
And what's that "int $1" stuff ??
petrusss
Post
by petrusss » Fri Dec 19, 2003 10:36 am
Hahah!
Of course... :]
When I press a key, I start getting alot of GPF's =|
I'll experiment a bit.
petrusss
Post
by petrusss » Fri Dec 19, 2003 11:43 am
OK, I can't make it not crash.
I get some GPF's (~100), and then it crashes.
This is what I get from bochs:
00083325742i[CPU ] read_virtual_checks(): write beyond limit
00083325790p[CPU ] >>PANIC<< fetch_raw_descriptor: LDTR.valid=0
A keypress starts that GPF loop =|
Pype.Clicker
Member
Posts: 5964 Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:
Post
by Pype.Clicker » Mon Dec 22, 2003 12:52 pm
it is likely that you have something wrong in your ISR stub, which makes a bad segment selector being popped, which triggers a GPF, etc.