diff options
| -rw-r--r-- | Makefile | 3 | ||||
| -rw-r--r-- | boot/stage2.asm | 2 | ||||
| -rw-r--r-- | kernel/config.h | 1 | ||||
| -rw-r--r-- | kernel/console.c | 158 | ||||
| -rw-r--r-- | kernel/console.h | 38 | ||||
| -rw-r--r-- | kernel/kernel.c | 10 | ||||
| -rw-r--r-- | kernel/keyboard.c | 5 | ||||
| -rw-r--r-- | kernel/spinlock.h | 5 | ||||
| -rw-r--r-- | kernel/syscalls.c | 5 | ||||
| -rw-r--r-- | lib/logger/log.c | 17 | ||||
| -rw-r--r-- | video/console.c | 156 | ||||
| -rw-r--r-- | video/console.h | 43 | ||||
| -rw-r--r-- | video/vesa.c (renamed from kernel/vesa.c) | 4 | ||||
| -rw-r--r-- | video/vesa.h (renamed from kernel/vesa.h) | 0 |
14 files changed, 239 insertions, 208 deletions
@@ -25,7 +25,7 @@ CFLAGS+=-std=gnu11 CFLAGS+= -I. #CFLAGS+=-lgcc -#CFLAGS+= -w -Wimplicit-function-declaration -Werror-implicit-function-declaration +CFLAGS+=-Werror-implicit-function-declaration #CFLAGS+= -O4 #CFLAGS+=-fdata-sections -ffunction-sections #CFLAGS+= -Werror @@ -35,6 +35,7 @@ CFLAGS+= -I. #kernel sources (asm and c) SOURCES=$(wildcard ./kernel/*.c) +SOURCES+=$(wildcard ./video/*.c) SOURCES+=$(wildcard ./lib/*/*.c) SOURCES+=$(wildcard ./fs/*.c) diff --git a/boot/stage2.asm b/boot/stage2.asm index 517e481..215cb18 100644 --- a/boot/stage2.asm +++ b/boot/stage2.asm @@ -144,7 +144,7 @@ kernel_load: mov ax,[KERNEL_CHUNK] cmp ax,0x5 jne skip_vesa_init - call VesaSetup + ; call VesaSetup skip_vesa_init: call switch_to_pm diff --git a/kernel/config.h b/kernel/config.h index 0f62abb..da8272d 100644 --- a/kernel/config.h +++ b/kernel/config.h @@ -7,4 +7,5 @@ //#define FOOLOS_COMPILE_FLOPPY // compile floppy drivers #define FOOLOS_CONSOLE_AUTOBREAK // add newline automatically at end of line //#define FOOLOS_LOG_OFF // do not log anything +#define FOOLOS_CONSOLE diff --git a/kernel/console.c b/kernel/console.c index e06da45..b6866a7 100644 --- a/kernel/console.c +++ b/kernel/console.c @@ -1,155 +1,5 @@ -#include "console.h" +#include "video/console.h" -//#define FOOLOS_CONSOLE - -static int posx=0; -static int posy=0; - -// helper_funcs - -void print_char_col(int x, int y, char c, char col) -{ -#ifdef FOOLOS_CONSOLE - char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2; - video_mem[0]=c; - video_mem[1]=col; -#endif -} - -void print_char(int x, int y, char c) -{ - print_char_col(x,y,c,SCR_WHITE); -} - -void print_single_num(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++; - if(posx>=SCR_WIDTH)scr_nextline(); - -} - -void print_str_col(int x,int y,char *str, char col) -{ - - while(*str!=0) - { - print_char_col(x++,y,*(str++),col); - } - -} - -void print_str(int x,int y,char *str) -{ - print_str_col(x,y,str,SCR_WHITE); -} - - -// -// -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_BLUE); - - } - - posx=posy=0; - -} - -void scr_put_string_nl(char *str) -{ - scr_put_string(str); - scr_nextline(); -} - -void scr_nextline() -{ -#ifdef FOOLOS_CONSOLE - int i,x; - - posx=0; - posy++; - - if(posy>SCR_HEIGHT-2) - { - for(i=1;i<SCR_HEIGHT-1;i++) - { - - for(x=0;x<SCR_WIDTH;x++) - { - char* video_mem=(char *)SCR_VIDEOMEM+((x)+(i-1)*SCR_REAL_WIDTH)*2; - char* video_mem2=(char *)SCR_VIDEOMEM+((x)+i*SCR_REAL_WIDTH)*2; - *video_mem=*video_mem2; - *(video_mem+1)=*(video_mem2+1); - //clear last line - if(i==SCR_HEIGHT-2) - { - print_char_col(x,i,'@',SCR_LBLUE); - - - } - } - } - - posy--; - } -#endif -} - -void scr_put_char(char ch,char col) -{ - - print_char_col(posx,posy,ch,SCR_WHITE); - posx++; - if(posx>=SCR_WIDTH)scr_nextline(); -} - - -void scr_put_hex(uint16_t val) -{ - - int i; - - scr_put_string("0x"); - - for(i=0;i<4;i++) - { - print_single_num((val&0xf000)>>12); - val=val << 4; - - } - -} - - -void scr_put_hex32(uint32_t val) -{ - scr_put_string("["); - scr_put_hex(val>>16); - scr_put_string(","); - scr_put_hex(val&0xffff); - scr_put_string("]"); -} - -void scr_put_string(char *str) -{ - while(*str!=0) - { - scr_put_char(*(str++),SCR_WHITE); - } -} - -void scr_backspace() -{ - if(posx==0)return; - print_char_col(posx-1,posy,'@',SCR_LGREEN); - posx--; - -} +void console_init(){scr_clear();} +void console_put_char(char c){scr_put_char(c,SCR_RED);} +void console_put_str(char *s){scr_put_string(s);} diff --git a/kernel/console.h b/kernel/console.h index d3b9b58..93008ab 100644 --- a/kernel/console.h +++ b/kernel/console.h @@ -1,42 +1,10 @@ #ifndef CONSOLE_H #define CONSOLE_H -#include "lib/int/stdint.h" -#define SCR_VIDEOMEM 0xb8000 +void console_init(); +void console_put_char(char); +void console_put_str(char *); -#define SCR_REAL_WIDTH 80 - -#define SCR_WIDTH 70 -#define SCR_HEIGHT 23 - -#define SCR_CTRL 0x3D4 -#define SCR_DATA 0x3D5 - -// colors -#define SCR_BLACK 0x0 -#define SCR_BLUE 0x1 -#define SCR_GREEN 0x2 -#define SCR_CYAN 0x3 -#define SCR_RED 0x4 -#define SCR_VIOLET 0x5 -#define SCR_BROWN 0x6 -#define SCR_GRAY1 0x7 -#define SCR_GRAY2 0x8 -#define SCR_LBLUE 0x9 -#define SCR_LGREEN 0xa -#define SCR_LCYAN 0xb -#define SCR_LRED 0xc -#define SCR_PINK 0xd -#define SCR_YELLOW 0xe -#define SCR_WHITE 0xf - -//autoscroll -void scr_clear(); -void scr_nextline(); -void scr_backspace(); -void scr_put_string(char *str); -void scr_put_string_nl(char *str); -void scr_put_hex(uint16_t val); #endif diff --git a/kernel/kernel.c b/kernel/kernel.c index 45fc68c..29159f5 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -13,20 +13,22 @@ #include "spinlock.h" #include "syscalls.h" #include "mem.h" -#include "vesa.h" #include "interrupts.h" #include "acpi.h" #include "mp.h" #include "keyboard.h" +#include "console.h" #include "fs/fs.h" #include "fs/ext2.h" + #ifdef FOOLOS_COMPILE_FLOPPY #include "floppy.h" #endif + // some multiprocessor shit that should move away TODO uint32_t c1,c2,c3; volatile uint8_t proc; @@ -87,6 +89,8 @@ void kernel_main(uint32_t initial_stack, int mp) // log_init(); + console_init(); + // // We want to get output to the screen as fast as possible! // @@ -106,7 +110,9 @@ void kernel_main(uint32_t initial_stack, int mp) // this function returns the physical base address of // our video memory // - uint32_t vesa_physbase=vesa_init(0x9300,0x9400,0x168000+512);//0x80000+0x200); + + + //uint32_t vesa_physbase=vesa_init(0x9300,0x9400,0x168000+512);//0x80000+0x200); // self-log message of logger :P log_log(); diff --git a/kernel/keyboard.c b/kernel/keyboard.c index 0e31e67..49c2fa0 100644 --- a/kernel/keyboard.c +++ b/kernel/keyboard.c @@ -1,8 +1,8 @@ #define FOOLOS_MODULE_NAME "keyboard" #include "kernel.h" -#include "x86.h" #include "console.h" +#include "x86.h" #include "lib/buffer/ringbuffer.h" #include "lib/logger/log.h" // logger facilities @@ -201,7 +201,8 @@ void keyboard_handle(uint8_t in) if(match) { - PutConsoleChar(ascii,0b1111100000011111); +// PutConsoleChar(ascii,0b1111100000011111); + console_put_char(ascii); if(!ringbuffer_put(ascii)) log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ringbuffer full.."); diff --git a/kernel/spinlock.h b/kernel/spinlock.h index 4c39dfe..7080490 100644 --- a/kernel/spinlock.h +++ b/kernel/spinlock.h @@ -1,3 +1,8 @@ +#ifndef SPINLOCK_H +#define SPINLOCK_H + void init_spinlocks(); volatile void lock_spin(int i); void lock_release(int i); + +#endif diff --git a/kernel/syscalls.c b/kernel/syscalls.c index 267c96f..b5a581d 100644 --- a/kernel/syscalls.c +++ b/kernel/syscalls.c @@ -4,6 +4,8 @@ #include "lib/bool/bool.h" #include "fs/fs.h" #include "fs/ext2.h" +#include "kernel/console.h" + // int syscall_write(int file, char *buf, int len) @@ -11,7 +13,8 @@ int syscall_write(int file, char *buf, int len) // ALL output to stdout for(int i=0;i<len;i++) { - PutConsoleChar(buf[i],0b1111111111000000); + //PutConsoleChar(buf[i],0b1111111111000000); + console_put_char(buf[i]); } return len; } diff --git a/lib/logger/log.c b/lib/logger/log.c index 7bc1d82..f2b9834 100644 --- a/lib/logger/log.c +++ b/lib/logger/log.c @@ -4,6 +4,7 @@ #include <stdarg.h> #include "log.h" +#include "kernel/console.h" #include "lib/printf/printf.h" #include "kernel/config.h" #include "lib/int/stdint.h" @@ -15,8 +16,6 @@ static char buffer[BUF_SIZE]; static int first; static int last; -void PutConsole(char *str, int color); - void log(char *module_name, int log_level, char *format_string, ...) { #ifdef FOOLOS_LOG_OFF @@ -41,13 +40,8 @@ void log(char *module_name, int log_level, char *format_string, ...) tfp_vsprintf(buf_info,format_string,va); va_end(va); - PutConsole(buf_time,0b0111101111101111); - PutConsole(module_name,0b1111100000000000); - PutConsole(": ",0b0000011111100000); - PutConsole(buf_info, 0b0111101111111111); - PutConsoleNL(); - tfp_sprintf(buf_log,"%s %s: %s\n",buf_time,module_name,buf_info); + console_put_str(buf_log); for(int i=0;buf_log[i]!=0;i++) { @@ -60,12 +54,17 @@ void log(char *module_name, int log_level, char *format_string, ...) } -void panic(char *module_name, char *format_string) +void panic(char *module_name, char *message) { + char buf_log[256]; + /* PutConsole("!! KERNEL PANIC !! ",0b1111100000000000); PutConsole(module_name,0b1111100000000000); PutConsole(" : ",0b0000011111100000); PutConsole(format_string,0b1111100000000000); + */ + tfp_sprintf(buf_log,"KERNEL PANIC !! %s: %s\n",module_name,message); + console_put_str(buf_log); while(1); // halt } diff --git a/video/console.c b/video/console.c new file mode 100644 index 0000000..c89424b --- /dev/null +++ b/video/console.c @@ -0,0 +1,156 @@ +#include "console.h" +#include "kernel/config.h" + +//#define FOOLOS_CONSOLE + +static int posx=0; +static int posy=0; + +// helper_funcs + +void print_char_col(int x, int y, char c, char col) +{ +#ifdef FOOLOS_CONSOLE + char* video_mem=(char *)SCR_VIDEOMEM+(x+y*SCR_REAL_WIDTH)*2; + video_mem[0]=c; + video_mem[1]=col; +#endif +} + +void print_char(int x, int y, char c) +{ + print_char_col(x,y,c,SCR_WHITE); +} + +void print_single_num(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++; + if(posx>=SCR_WIDTH)scr_nextline(); + +} + +void print_str_col(int x,int y,char *str, char col) +{ + + while(*str!=0) + { + print_char_col(x++,y,*(str++),col); + } + +} + +void print_str(int x,int y,char *str) +{ + print_str_col(x,y,str,SCR_WHITE); +} + + +// +// +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_BLUE); + + } + + posx=posy=0; + +} + +void scr_put_string_nl(char *str) +{ + scr_put_string(str); + scr_nextline(); +} + +void scr_nextline() +{ +#ifdef FOOLOS_CONSOLE + int i,x; + + posx=0; + posy++; + + if(posy>SCR_HEIGHT-2) + { + for(i=1;i<SCR_HEIGHT-1;i++) + { + + for(x=0;x<SCR_WIDTH;x++) + { + char* video_mem=(char *)SCR_VIDEOMEM+((x)+(i-1)*SCR_REAL_WIDTH)*2; + char* video_mem2=(char *)SCR_VIDEOMEM+((x)+i*SCR_REAL_WIDTH)*2; + *video_mem=*video_mem2; + *(video_mem+1)=*(video_mem2+1); + //clear last line + if(i==SCR_HEIGHT-2) + { + print_char_col(x,i,'@',SCR_LBLUE); + + + } + } + } + + posy--; + } +#endif +} + +void scr_put_char(char ch,char col) +{ + + print_char_col(posx,posy,ch,SCR_WHITE); + posx++; + if(posx>=SCR_WIDTH)scr_nextline(); +} + + +void scr_put_hex(uint16_t val) +{ + + int i; + + scr_put_string("0x"); + + for(i=0;i<4;i++) + { + print_single_num((val&0xf000)>>12); + val=val << 4; + + } + +} + + +void scr_put_hex32(uint32_t val) +{ + scr_put_string("["); + scr_put_hex(val>>16); + scr_put_string(","); + scr_put_hex(val&0xffff); + scr_put_string("]"); +} + +void scr_put_string(char *str) +{ + while(*str!=0) + { + scr_put_char(*(str++),SCR_WHITE); + } +} + +void scr_backspace() +{ + if(posx==0)return; + print_char_col(posx-1,posy,'@',SCR_LGREEN); + posx--; + +} diff --git a/video/console.h b/video/console.h new file mode 100644 index 0000000..22184fb --- /dev/null +++ b/video/console.h @@ -0,0 +1,43 @@ +#ifndef CONSOLEINT_H +#define CONSOLEINT_H + +#include "lib/int/stdint.h" + +#define SCR_VIDEOMEM 0xb8000 + +#define SCR_REAL_WIDTH 80 + +#define SCR_WIDTH 70 +#define SCR_HEIGHT 23 + +#define SCR_CTRL 0x3D4 +#define SCR_DATA 0x3D5 + +// colors +#define SCR_BLACK 0x0 +#define SCR_BLUE 0x1 +#define SCR_GREEN 0x2 +#define SCR_CYAN 0x3 +#define SCR_RED 0x4 +#define SCR_VIOLET 0x5 +#define SCR_BROWN 0x6 +#define SCR_GRAY1 0x7 +#define SCR_GRAY2 0x8 +#define SCR_LBLUE 0x9 +#define SCR_LGREEN 0xa +#define SCR_LCYAN 0xb +#define SCR_LRED 0xc +#define SCR_PINK 0xd +#define SCR_YELLOW 0xe +#define SCR_WHITE 0xf + +//autoscroll +void scr_clear(); +void scr_nextline(); +void scr_backspace(); +void scr_put_char(char ch,char col); +void scr_put_string(char *str); +void scr_put_string_nl(char *str); +void scr_put_hex(uint16_t val); + +#endif diff --git a/kernel/vesa.c b/video/vesa.c index be17623..2addea7 100644 --- a/kernel/vesa.c +++ b/video/vesa.c @@ -1,8 +1,6 @@ //http://wiki.osdev.org/GUI #include <stdarg.h> -#include "kernel.h" -#include "config.h" -#include "mem.h" +#include "kernel/mem.h" #include "vesa.h" #include "lib/logger/log.h" // logger facilities diff --git a/kernel/vesa.h b/video/vesa.h index 89cb680..89cb680 100644 --- a/kernel/vesa.h +++ b/video/vesa.h |
