diff options
| -rw-r--r-- | kernel/console.c | 38 | ||||
| -rw-r--r-- | kernel/console.h | 23 | ||||
| -rw-r--r-- | kernel/kernel.c | 134 |
3 files changed, 79 insertions, 116 deletions
diff --git a/kernel/console.c b/kernel/console.c index d5d4573..f17dbe3 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -1,11 +1,24 @@ -#include <stdint.h> - #include "console.h" static int posx=0; static int posy=0; -void print_nextline() +void scr_clear() +{ + int x,y; + + for(x=0;x<SCR_WIDTH;x++) + for(y=0;y<SCR_HEIGHT;y++) + { + print_char_col(x,y," ",SCR_BLACK); + + } + + posx=posy=0; + +} +//TODO +void scr_nextline() { int i,x; @@ -30,8 +43,9 @@ void print_nextline() } } -void print_hex(uint16_t val) +void scr_put_hex(uint16_t val) { + int i; print_char_col(posx,posy,'0',SCR_WHITE); @@ -43,34 +57,20 @@ void print_hex(uint16_t val) { print_single_hex((val&0xf000)>>12); val=val << 4; - } } -void print_string(char *str) +void scr_put_string(char *str) { - while(*str!=0) { print_char(posx++,posy,*(str++)); } } -void console_clear_screen() -{ - int x,y; - for(x=0;x<SCR_WIDTH;x++) - for(y=0;y<SCR_WIDTH;y++) - { - print_char_col(x,y," ",SCR_BLACK); - - } - posx=posy=0; - -} diff --git a/kernel/console.h b/kernel/console.h index b834289..a8b2b86 100644 --- a/kernel/console.h +++ b/kernel/console.h @@ -1,3 +1,8 @@ +#ifndef CONSOLE_H +#define CONSOLE_H + +#include <stdint.h> //needed for uint16_t + #define SCR_VIDEOMEM 0xb8000 #define SCR_WIDTH 80 @@ -13,17 +18,13 @@ #define SCR_RED 0x4 // TODO: more colors here... - # define SCR_WHITE 0xf //autoscroll -void print_nextline(); -void print_string(char *str); -void print_hex(uint16_t val); -void console_clear_screen(); - -//no autoscroll -void print_str(int x,int y,char *str); -void print_str_col(int x,int y,char *str, char col); -void print_char(int x, int y, char c); -void print_char_col(int x, int y, char c, char col); +void scr_clear(); +void scr_nextline(); +void scr_put_string(char *str); +void scr_put_hex(uint16_t val); +//void scr_put_int(uint16_t int); + +#endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 584b5c8..bdf1ec1 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,8 +1,19 @@ -#include <stdint.h> +#include <stdint.h> #include "kernel.h" // general kernel config #include "console.h" // this will allow us to write to screen +// garbage +int unhandled=0; + +char col=100; +char col2=0; + +int cursor=0; +char last_code=0; + +uint8_t kb_in; + //// interrupt stuff ///// // #define INT_MAX 255 @@ -28,23 +39,13 @@ static struct idt_desc } idtd; -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! + // todo also the other pic!// TODO __asm__("mov $0x20, %al"); __asm__("out %al, $0x20"); @@ -61,7 +62,7 @@ void int_kb_handler() __asm__("in $0x60, %al"); __asm__("mov %%al, %0"::"m" (kb_in)); - int0(kb_in); + int0(kb_in); //TODO!! __asm__("mov $0x20, %al"); __asm__("out %al, $0x20"); @@ -76,17 +77,10 @@ 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++) { -// 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); } } @@ -116,44 +110,15 @@ void int_install() __asm__("lidt %0"::"m" (idtd)); } - -void int_disable() +/* +void int_show() { - __asm__("cli"); -} - -void int_enable() -{ - __asm__("sti"); -} - -void kernel_main() -{ - - 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; @@ -167,64 +132,61 @@ void kernel_main() print_hex(*(ptr3+3+offset*4)); //addrHi print_nextline(); } +} +*/ +void int_disable() +{ + __asm__("cli"); +} - // - // 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,0x087c); +void int_enable() +{ + __asm__("sti"); +} +////////// KERNEL MAIN///// ///// +// +void kernel_main() +{ - //int_install_ir(33, 0b10001110, 0x8, 0x7c50); + // clear console + scr_clear(); + // hello message + scr_put_string(KERNEL_HELLO_MESSAGE); + scr_nextline(); + scr_nextline(); + + // init interrupt decriptor table + // install and enable! + int_init(0x08); int_install(); int_enable(); + scr_put_string("Interrupts Up and Running"); + scr_nextline(); - //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(); - } -*/ - + // kernel main loop while(1) { - // print_nextline(); // print_str_col(0,0,"ABC",col); -// print_str_col(1,SCR_HEIGHT,"(*)",col2++); + print_str_col(1,SCR_HEIGHT,"(*)",col2++); //int0(); } - print_hex(*(ptr3)); - print_nextline(); } + + +/// keyboard driver //// + void int0(uint8_t in) { int i=0; |
