diff options
Diffstat (limited to 'kernel/kernel.c')
| -rw-r--r-- | kernel/kernel.c | 188 |
1 files changed, 145 insertions, 43 deletions
diff --git a/kernel/kernel.c b/kernel/kernel.c index 6719cdc..584b5c8 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,11 +1,12 @@ #include <stdint.h> +#include "kernel.h" // general kernel config #include "console.h" // this will allow us to write to screen //// interrupt stuff ///// // #define INT_MAX 255 - +// // interrupt descriptor table static struct int_desc @@ -18,31 +19,55 @@ static struct int_desc } idt[INT_MAX]; -static struct int_desc *idt_old=0x1000; - // interrupt descriptor table descriptor static struct idt_desc { uint16_t size; - uint32_t base; + uint16_t baseLo; + uint16_t baseHi; } idtd; -volatile char col=100; +int unhandled=0; + +char col=100; char col2=0; int cursor=0; char last_code=0; +uint8_t kb_in; + +void int_def_handler() +{ + __asm__("pusha"); + + unhandled++; + + // todo also the other pic! + __asm__("mov $0x20, %al"); + __asm__("out %al, $0x20"); + + __asm__("popa"); + __asm__("leave"); + __asm__("iret"); + +} -volatile void int_def_handler() +void int_kb_handler() { __asm__("pusha"); - col++; - print_str(5,5,"Interrupted"); + __asm__("in $0x60, %al"); + __asm__("mov %%al, %0"::"m" (kb_in)); + + int0(kb_in); + + __asm__("mov $0x20, %al"); + __asm__("out %al, $0x20"); __asm__("popa"); + __asm__("leave"); __asm__("iret"); } @@ -51,40 +76,43 @@ void int_init(uint16_t sel) { int i; + /* idtd.size=sizeof(struct int_desc)*INT_MAX-1; // why the -1 ?? idtd.base=(uint32_t)&idt[0]; + */ for(i=0; i<INT_MAX; i++) { - int_install_ir(i, 0b10001110, sel, &int_def_handler); -// int_install_ir(i, 0b10001110, sel, 0x7c50); +// if(i==0)int_install_ir(i, 0, 0,0); + if(i==33)int_install_ir(i, 0b10001110, sel,&int_kb_handler); + else int_install_ir(i, 0b10001110, sel,&int_def_handler); + //if(i==0)int_install_ir(i, 0, 0,0); } - int_install_ir(0, 0, 0, 0); - } void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr) { uint64_t base=(uint64_t)&(*addr); -// uint32_t base=addr; - idt_old[irq].addrLo = base & 0xffff; - idt_old[irq].addrHi = (base >> 16) & 0xffff; - - idt_old[irq].addrLo = 0x087c; - idt_old[irq].addrHi = 0x0; - - idt_old[irq].zeros=0; - idt_old[irq].flags=flags; - idt_old[irq].sel=sel; + idt[irq].addrLo = base & 0xffff; + idt[irq].addrHi = (base >> 16) & 0xffff; + idt[irq].addrHi = 0x0; + idt[irq].zeros=0; + idt[irq].flags=flags; + idt[irq].sel=sel; } void int_install() { + + idtd.size=8*34; + idtd.baseHi=0x0000; + idtd.baseLo=&idt[0]; + __asm__("lidt %0"::"m" (idtd)); } @@ -101,35 +129,109 @@ void int_enable() void kernel_main() { - char str[]="ABC"; + + console_clear_screen(); + + // + print_string(KERNEL_HELLO_MESSAGE); + print_nextline(); + print_nextline(); + // + + // address of our initial idt (set up by bootloader) + //uint16_t *ptr3=0x1000; + uint16_t *ptr3=&idt[0]; + //uint16_t *ptr3=0x2040; + + // debugging idt: + // int_install_ir(34,0x0,0xaabb,0x1234); + //int_install_ir(33,0b1000110,0x8,&int_def_handler); + + + print_string("idt located: "); + print_hex(ptr3); + print_nextline(); + + // init idt; + int_init(0x08); + + // first two bytes as chars + int offset; + for(offset=32;offset<40;offset++) + { + print_hex(offset-32); //irq + print_string(" -> "); + print_hex(*(ptr3+offset*4)); //addrLo + print_hex(*(ptr3+1+offset*4)); //sel + print_hex(*(ptr3+2+offset*4)); //zeros & flags + print_hex(*(ptr3+3+offset*4)); //addrHi + print_nextline(); + } + + + // + // print_nextline(); + // print_nextline(); + +// print_hex(*ptr2); + + // print_nextline(); + // print_nextline(); // int_init(0x08); // offset in GDT (CODE_SEG) - int_install_ir(33,0b1000110,0x8,&int_def_handler); - int_install_ir(33,0b1000110,0x8,0x087c); - // int_install(); - // int_enable(); + // int_install_ir(33,0b1000110,0x8,0x087c); + - print_str(0,0,"Interrupts Enabled"); + //int_install_ir(33, 0b10001110, 0x8, 0x7c50); + int_install(); + int_enable(); + + + //print_str(0,0,"Interrupts Enabled"); + // + /* + int irq=32; + for (irq=32;irq<32+16;irq++) + { + print_string("irq:"); + print_hex(irq); + + print_string(" -> "); + print_hex(idt_old[irq].addrLo); + print_string(" "); + print_hex(idt_old[irq].addrHi); + print_string(" "); + print_hex(idt_old[irq].sel); + print_nextline(); + } +*/ while(1) { - print_str_col(0,0,str,col); - print_str_col(0,2,str,col2++); - int0(); + +// print_nextline(); + +// print_str_col(0,0,"ABC",col); +// print_str_col(1,SCR_HEIGHT,"(*)",col2++); + + //int0(); } + print_hex(*(ptr3)); + print_nextline(); } -void int0() +void int0(uint8_t in) { int i=0; - char* int_count=(char *)0x7c00+3; + // + //print_hex(int_count); - char make_codes[]={ + uint8_t make_codes[]={ 0x1e, // A 0x30, // B 0x2e, // C @@ -158,7 +260,7 @@ void int0() 0x2c, // Z }; - char break_codes[]={ + uint8_t break_codes[]={ 0x9e, // A 0xb0, // B 0xae, // C @@ -187,24 +289,24 @@ void int0() 0xac, // Z }; - print_str(6,6,*int_count); - if(last_code==*int_count)return; + //if(last_code==*int_count)return; for(i=0;i<26;i++) { - if(make_codes[i]==*int_count) + if(make_codes[i]==in) { - print_char_col(cursor,10,'A'+i,0xf); + print_char_col(cursor,20,'A'+i,0xf); } } - + for(i=0;i<26;i++) { - if(break_codes[i]==*int_count) + if(break_codes[i]==in) { - print_char_col(cursor++,10,'a'+i,SCR_RED); + print_char_col(cursor++,20,'a'+i,SCR_RED); } } - last_code=*int_count; + last_code=in; + } |
