diff options
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/console.c | 68 | ||||
| -rw-r--r-- | kernel/console.h | 27 | ||||
| -rw-r--r-- | kernel/kernel.c | 151 |
3 files changed, 185 insertions, 61 deletions
diff --git a/kernel/console.c b/kernel/console.c new file mode 100644 index 0000000..9381eed --- /dev/null +++ b/kernel/console.c @@ -0,0 +1,68 @@ +#include <stdint.h> + +#include "console.h" + +static int posx=0; +static int posy=0; + +void print_nextline() +{ + posx=0; + posy++; + if(posy>SCR_HEIGHT-2)posy=0; +} + +void print_hex(uint16_t val) +{ + int i; + + print_char_col(posx,posy,'0',SCR_WHITE); + posx++; + print_char_col(posx,posy,'x',SCR_WHITE); + posx++; + + for(i=0;i<4;i++) + { + print_single_hex((val&0xf000)>>12); + val=val << 4; + + + } + +} + +void print_single_hex(int i) +{ + if(i<10)print_char_col(posx,posy,'0'+i,SCR_GREEN); + else if(i<16)print_char_col(posx,posy,'A'+i-10,SCR_GREEN); + posx++; + +} + + +void print_str(int x,int y,char *str) +{ + print_str_col(x,y,str,SCR_WHITE); +} + +void print_char(int x, int y, char c) +{ + print_char_col(x,y,c,SCR_WHITE); +} + +void print_str_col(int x,int y,char *str, char col) +{ + + while(*str!=0) + { + print_char_col(x++,y,*(str++),col); + } + +} + +void print_char_col(int x, int y, char c, char col) +{ + char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_WIDTH)*2; + video_mem[0]=c; + video_mem[1]=col; +} diff --git a/kernel/console.h b/kernel/console.h new file mode 100644 index 0000000..e304773 --- /dev/null +++ b/kernel/console.h @@ -0,0 +1,27 @@ +#define SCR_VIDEOMEM 0xb8000 + +#define SCR_WIDTH 80 +#define SCR_HEIGHT 23 + +#define SCR_CTRL 0x3D4 +#define SCR_DATA 0x3D5 + +#define SCR_BLACK 0x0 +#define SCR_BLUE 0x1 +#define SCR_GREEN 0x2 +#define SCR_CYAN 0x3 +#define SCR_RED 0x4 + +// TODO: more colors here... + +# define SCR_WHITE 0xf + +//autoscroll +void print_nextline(); +void print_hex(uint16_t val); + +//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); diff --git a/kernel/kernel.c b/kernel/kernel.c index 05d04cc..c8b21cf 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -1,95 +1,125 @@ -#define SCR_WIDTH 80 -#define SCR_HEIGHT 23 +#include <stdint.h> -#define SCR_CTRL 0x3D4 -#define SCR_DATA 0x3D5 +#include "console.h" // this will allow us to write to screen -#define SCR_BLACK 0x0 -#define SCR_BLUE 0x1 -#define SCR_GREEN 0x2 -#define SCR_CYAN 0x3 -#define SCR_RED 0x4 -// todo... -# define SCR_WHITE 0xf +//// interrupt stuff ///// +// +#define INT_MAX 255 +// interrupt descriptor table +static struct int_desc +{ + uint16_t addrLo; + uint16_t sel; + uint8_t zeros; + uint8_t flags; + uint16_t addrHi; + +} idt[INT_MAX]; -void print_char(int x, int y, char c, char col) +// interrupt descriptor table descriptor +static struct idt_desc { - char* video_mem=(char *)0xb8000+(x+y*SCR_WIDTH)*2; - video_mem[0]=c; - video_mem[1]=col; + uint16_t size; + uint32_t base; + +} idtd; + +volatile char col=100; +char col2=0; + +int cursor=0; +char last_code=0; + + +volatile void int_def_handler() +{ + __asm__("pusha"); + + col++; + print_str(5,5,"Interrupted"); + + __asm__("popa"); + __asm__("iret"); + } -float func(float x,float y) +void int_init(uint16_t sel) { - return x*x*y; + 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); + } + + int_install_ir(0, 0, 0, 0); + } -void clear_screen() +void int_install_ir(int irq, uint16_t flags, uint16_t sel, void *addr) { - int x=0; - int y=0; - for(x=0;x<SCR_WIDTH;x++) - for(y=2;y<SCR_HEIGHT;y++) - print_char(x,y,'R',SCR_BLACK); + uint64_t base=(uint64_t)&(*addr); +// uint32_t base=addr; + + idt[irq].addrLo = base & 0xffff; + idt[irq].addrHi = (base >> 16) & 0xffff; + idt[irq].zeros=0; + idt[irq].flags=flags; + idt[irq].sel=sel; + } -void sleep(int i) + +void int_install() { - int x; + __asm__("lidt %0"::"m" (idtd)); - for(x=0;x<i;x++) - { - __asm__("nop"); +} - } +void int_disable() +{ + __asm__("cli"); +} + +void int_enable() +{ + __asm__("sti"); } void kernel_main() { + char str[]="ABC"; - int col=0; - - while(1) - { + int_init(0x08); // offset in GDT (CODE_SEG) + int_install(); + int_enable(); - print_char(0,0,'*',col++%0xf); - int0(); - - } - -} + print_str(0,0,"Interrupts Enabled"); -void kernel_main_joke() -{ - - float time=0; - int col=0; - int x; while(1) { - time++; - print_char(0,0,'R',col++%0xf); - for(x=0;x<SCR_WIDTH;x++) - { - print_char(x,(2+(int)func((float)x,0.002*(time/100)))%(SCR_HEIGHT-2),'R',SCR_BLUE); - } - if(time>300)time=0; - - } + print_str_col(0,0,str,col); + print_str_col(0,2,str,col2++); -} + int0(); + } -int cursor=0; -char last_code=0; + +} void int0() { int i=0; + char* int_count=(char *)0x7c00+3; char make_codes[]={ 0x1e, // A @@ -149,15 +179,14 @@ void int0() 0xac, // Z }; - char* int_count=(char *)0x7c00+3; - + print_str(6,6,*int_count); if(last_code==*int_count)return; for(i=0;i<26;i++) { if(make_codes[i]==*int_count) { - print_char(cursor,10,'A'+i,0xf); + print_char_col(cursor,10,'A'+i,0xf); } } @@ -165,7 +194,7 @@ void int0() { if(break_codes[i]==*int_count) { - print_char(cursor++,10,'a'+i,0xf); + print_char_col(cursor++,10,'a'+i,SCR_RED); } } |
