restart when keyboard interrupt occurs
restart when keyboard interrupt occurs
hello friend..
I am new to this forum and ofcourse new in OS developing. I am designing my OS in C.
I have read tutorials about IDT ,PIC and know how to initialize all interrupt stuffs. I am setting all 256 interrupts to a default int_handler() function which do nothing but just prints a message "AN INTERRUPT OCCURS" and then the system is hanged. After setting all interrupts I am enabling keyboard.
But now the problem comes.. whenever i press any key on my keyboard the system gets restarted. I am using BOCHS as an emulator. it gives following error message whenever the key is pressed.
00242790000e[CPU ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00242794049i[BIOS ] rombios.c,v 1.103 2003/12/18 16:48:19 vruppert Exp $
00243120041i[KBD ] reset-disable command received
Please help me as I am a newbee. Any simple OSes in C will be welcomed. Sorry 4 my english as I am an Indian.
I am new to this forum and ofcourse new in OS developing. I am designing my OS in C.
I have read tutorials about IDT ,PIC and know how to initialize all interrupt stuffs. I am setting all 256 interrupts to a default int_handler() function which do nothing but just prints a message "AN INTERRUPT OCCURS" and then the system is hanged. After setting all interrupts I am enabling keyboard.
But now the problem comes.. whenever i press any key on my keyboard the system gets restarted. I am using BOCHS as an emulator. it gives following error message whenever the key is pressed.
00242790000e[CPU ] exception(): 3rd (14) exception with no resolution, shutdown status is 00h, resetting
00242794049i[BIOS ] rombios.c,v 1.103 2003/12/18 16:48:19 vruppert Exp $
00243120041i[KBD ] reset-disable command received
Please help me as I am a newbee. Any simple OSes in C will be welcomed. Sorry 4 my english as I am an Indian.
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:restart when keyboard interrupt occurs
this message, that bochs spills out means basically, that the cpu canna reach your code, simply put. It just doesn't know the location of the IDT.
the number of the exception (14) tells us that the cpu has triple faulted due to a page fault exception - in your case that's been one too much and the poor cpu thought only of pfau- toomusch hassles, letz get out of here!
this can have a lot of causes.
here are some possibilities:
1. you by any chance have enabled paging. this happens if you make a bitwise or of 0x80000000 with the contents of cr0 ere you write it back. If you have not provided valid page directory/page tables, it will triple fault.
2. you have set too narrow a limit in your code & data segments - if you are using segmentation albeit i think it will trigger a GPF in such a case.
Very important: you only need to assign handlers to the first 32 positions PLUs the 16 slots for hardware irqs - plus some indices for software interrupts in your idt. It saves place as you don't need to keep the space for a full fledged idt in your precious memory.
HtH & ccw.
*sets off to continue with ext2-writing-access implementation*
the number of the exception (14) tells us that the cpu has triple faulted due to a page fault exception - in your case that's been one too much and the poor cpu thought only of pfau- toomusch hassles, letz get out of here!
this can have a lot of causes.
here are some possibilities:
1. you by any chance have enabled paging. this happens if you make a bitwise or of 0x80000000 with the contents of cr0 ere you write it back. If you have not provided valid page directory/page tables, it will triple fault.
2. you have set too narrow a limit in your code & data segments - if you are using segmentation albeit i think it will trigger a GPF in such a case.
Very important: you only need to assign handlers to the first 32 positions PLUs the 16 slots for hardware irqs - plus some indices for software interrupts in your idt. It saves place as you don't need to keep the space for a full fledged idt in your precious memory.
HtH & ccw.
*sets off to continue with ext2-writing-access implementation*
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:restart when keyboard interrupt occurs
As long as others understand you it should beno problem.viral wrote: Sorry 4 my english as I am an Indian.
Anyway from which part of India are you?
Only Human
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:restart when keyboard interrupt occurs
If i may suggest, we collected howto informations about such problems at http://www.osdev.org/osfaq2/index.php/TroubleShooting ...
In this case, it sounds like your interrupt table is not properly set up and when the CPU tries to access it, it generates an exception ...
You may like to re-run the experiment in a debugger-enabled BOCHS and ask for a dump_cpu or something alike after the crash occur.
In this case, it sounds like your interrupt table is not properly set up and when the CPU tries to access it, it generates an exception ...
You may like to re-run the experiment in a debugger-enabled BOCHS and ask for a dump_cpu or something alike after the crash occur.
Re:restart when keyboard interrupt occurs
You can also try it step-by-step with bochs' debugger, if you compiled it.
It's very useful, as it provides information about the IDTR and any IDT entry.
You can also set a breakpoint at the entry of your IRQ handler and try step-by-step until you reach the faulty instruction
It's very useful, as it provides information about the IDTR and any IDT entry.
You can also set a breakpoint at the entry of your IRQ handler and try step-by-step until you reach the faulty instruction
Re:restart when keyboard interrupt occurs
hi friends...
Thanks for the reply... I am really a very little bee so I am not getting what you r trying to tell.
I am initializing IDT by calling a function setIDT() which is as follows:
I guess the problem is in lidt instruction. It is not loading the actual address of IDT.
Thanks for the reply... I am really a very little bee so I am not getting what you r trying to tell.
I am initializing IDT by calling a function setIDT() which is as follows:
Code: Select all
void setIDT()
{
int i =32;
int selector = 0;
disable(); // cli (disable interrupt)
asm volatile("movw %%cs,% :"=g"(selector));//Obtain
// Code Selector
selector_code = selector;
init_pics(0x20, 0x28); // initialize PIC
set_exceptions(); //set all exceptions
for (i=32;i<255;i++) //Fill IDT with default entries.
{
set_vector(i,default_handler,
INT_GATE|BITS_32|PRESENT|RING_3);
}
idt_desc.size=(255*8)-1;
idt_desc.offset=(unsigned long)idt;
asm("lidt %0" : "=m" (idt_desc)); //Load IDT.
} //end of function
Re:restart when keyboard interrupt occurs
Why is the input to LIDT in the list of output registers? That looks bad, not sure whether it matters. For these opcodes, take the book by the hand and look at the exact byte-wise way to encode it, and see whether your assembly (upon disassembling) matches it.viral wrote: asm("lidt %0" : "=m" (idt_desc)); //Load IDT.
I guess the problem is in lidt instruction. It is not loading the actual address of IDT.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:restart when keyboard interrupt occurs
LIDT through inline GCC assembly is especially tricky. I suggest you write that as a separate ASM function or that you check out our http://www.osdev.org/osfaq2/index.php/S ... eFunctions on the FAQ
Re:restart when keyboard interrupt occurs
Your struct is not correct which is why it isn't loading correctly (As well as the faulty ASM line).
You need to use lowbase and highbase because the bit layout on the x86 is high,low and the IDTR wants it as low,high. You also need to make sure the struct is packed otherwise it'll take up 12 bytes instead of 6 (GCC may 32bit align the elements).
Code: Select all
struct IDTSizeDescriptor
{
unsigned short limit; //How long is IDT
unsigned short lowbase; //Low of Where Table starts
unsigned short highbase; //High of where Table starts
} __attribute__((__packed__));
IDTSizeDescriptor sz;
sz.limit = (255*8)-1;
sz.lowbase = (unsigned int)idt & 0xFFFF;
sz.highbase = ((unsigned int)idt & 0xFFFF0000) >> 16;
__asm__ ("lidt (%%eax)" : : "a"(&sz));
Re:restart when keyboard interrupt occurs
Thanks for this valuable reply. I am now trying to follow this instructions