IDT code:
Code: Select all
struct gate_descriptor idt[255];
struct descriptor_table_pointer idt_pointer;
void init_idt()
{
int count;
idt_pointer.limit=(256*sizeof(struct gate_descriptor))-1; /*the size of the idt*/
idt_pointer.base=(unsigned int)&idt; /*actuall pointer to the idt*/
for(count=0; count<255; count++) /*Clear the idt*/
free_int(count);
asm volatile("lidt %0\n\t" :: "m" (idt_pointer)); /*load the idt*/
return;
}
void alloc_int(unsigned char int_no, unsigned long offset, unsigned char dpl)
{
idt[int_no].offset_high=((offset>>16) & 0xFFFF);
idt[int_no].attributes=0x8E;
idt[int_no].unused=0;
idt[int_no].selector=0x08;
idt[int_no].offset_low=(offset & 0xFFFF);
}
void free_int(unsigned char int_no)
{
idt[int_no].offset_high=0;
idt[int_no].attributes=0;
idt[int_no].unused=0;
idt[int_no].selector=0;
idt[int_no].offset_low=0;
}
Code: Select all
/*Init function:*/
void keyboard_init()
{
alloc_int(_IRQ_0+1,(unsigned long int)&keyboard_handler,IDT_RING0);
enable_irq(1);
}
Code: Select all
void init_paging()
{
unsigned long *page_directory = (unsigned long*) alloc_page(1);
unsigned long *page_table = (unsigned long*) alloc_page(1);
unsigned long *page_table_2 = (unsigned long*) alloc_page(1);
unsigned long address=0; //holds the physical address of a page
unsigned int counter;
unsigned long temp;
/*Mark all page directories as empty:*/
for(counter=0; counter<1024; counter++)
{
page_directory[counter] = 0 | 2; //supervisor, writeable, not present
}
/*Fill up our first page table (lower 4mb):*/
for(counter=0; counter<1024; counter++)
{
page_table[counter] = address | 3; //supervisor, writeable, present
address = address + 4096; //4096 bytes - one page
};
/*Fill up our second page table (lower 4mb):*/
for(counter=0; counter<1024; counter++)
{
page_table_2[counter] = 0 | 2; //supervisor, writeable, not present
};
page_table_2[0]=(int)page_table; /*Map in lower page table*/
page_table_2[0]=page_table_2[0] | 3;
page_table_2[1022]=(int)page_directory; /*Map in page directory*/
page_table_2[1022]=page_table_2[1022] | 3;
page_table_2[1023]=(int)page_table_2; /*Map in self*/
page_table_2[1023]=page_table_2[1023] | 3;
/*Add the pages to the page directory:*/
page_directory[0]=(int)page_table; /*attribute set to: supervisor level, read/write, present(011 in binary)*/
page_directory[0]=page_directory[0] | 3;
page_directory[1023]=(int)page_table_2; /*attribute set to: supervisor level, read/write, present(011 in binary)*/
page_directory[1023]=page_directory[0] | 3;
/*Enable paging:*/
temp=(unsigned long)page_directory;
write_cr3(temp);
get_cr0(temp);
write_cr0((temp | 0x80000000));
}
Code: Select all
00006983000d[KBD ] keyboard: writing translated 20
00006983000d[KBD ] service_keyboard: key in internal buffer waiting
00006983250d[PIC ] IRQ line 1 now high
00006983250d[PIC ] signalling IRQ(1)
00006983250d[CPU ] interrupt(): vector = 129, INT = 0, EXT = 1
00006983250d[CPU ] exception(0e h)
00006983250d[CPU ] interrupt(): vector = 14, INT = 0, EXT = 1
00006983250d[CPU ] exception(0e h)
00006983250d[CPU ] interrupt(): vector = 8, INT = 0, EXT = 1
00006983250d[CPU ] exception(0e h)
00011669250p[CPU ] >>PANIC<< exception(): 3rd (14) exception with no resolution
OScoder
