diff options
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | kernel/config.h | 3 | ||||
| -rw-r--r-- | kernel/kernel.c | 26 | ||||
| -rw-r--r-- | kernel/task.c | 5 | ||||
| -rw-r--r-- | kernel/time.h | 3 | ||||
| -rw-r--r-- | kernel/timer.c | 20 | ||||
| -rw-r--r-- | kernel/timer.h | 4 | ||||
| -rw-r--r-- | kernel/x86.c | 5 | ||||
| -rw-r--r-- | lib/logger/log.c | 44 | ||||
| -rw-r--r-- | lib/logger/log.h | 3 | ||||
| -rw-r--r-- | video/console.c | 11 | ||||
| -rw-r--r-- | video/console.h | 4 |
12 files changed, 65 insertions, 64 deletions
@@ -38,6 +38,7 @@ CFLAGS+=-std=gnu11 CFLAGS+= -I. #CFLAGS+=-lgcc CFLAGS+=-Werror-implicit-function-declaration +#CFLAGS+=-fno-zero-initialized-in-bss #CFLAGS+= -O4 #CFLAGS+=-fdata-sections -ffunction-sections #CFLAGS+= -Werror diff --git a/kernel/config.h b/kernel/config.h index 14a6eee..05c4bcb 100644 --- a/kernel/config.h +++ b/kernel/config.h @@ -6,7 +6,8 @@ //#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_LOG_OFF // do not log anything #define FOOLOS_CONSOLE // otherwise VESA will be used! #define MEM_PRINT_MEMORYMAP +#define LOG_BUF_SIZE 4069 diff --git a/kernel/kernel.c b/kernel/kernel.c index 5628e84..b45703a 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -8,7 +8,6 @@ #include "lib/buffer/ringbuffer.h" #include "smp.h" -#include "time.h" #include "timer.h" #include "spinlock.h" #include "syscalls.h" @@ -80,22 +79,22 @@ void kernel_main(uint32_t initial_stack, int mp) /////////////////// BULLSHIT ABOVE THIS LINE: TODO: CLEANUP // - // init system log ringbugger - // - log_init(); + // Print initial address of the esp stack pointer + // + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack); - // - // The System Time // - task_system_clock=0; - + // Configuring the PIT timer. + // + timer_init(); + // // Memory Init // // after this is set up we will be able to allocate and deallocate // blocks of physical memory :) // - // we know that here, the bootloader placed the mamory map and + // we know that here, the bootloader placed the memory map and // the number of entries. // mem_init(0x7c00+1,*((uint16_t *)(0x7c00))); @@ -109,20 +108,11 @@ void kernel_main(uint32_t initial_stack, int mp) log_log(); // - // Print initial address of the esp stack pointer - // - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"initial esp: 0x%08X",initial_stack); - - // // Setup PIC // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"setting up PIC."); pic_setup(); - // - // Configuring the PIT timer. - // - timer_init(); // mouse and kb driver init (before interrupts) // mouse_init(); diff --git a/kernel/task.c b/kernel/task.c index 29ccaa4..6d571cb 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -5,6 +5,7 @@ #include "lib/logger/log.h" // logger facilities #include "lib/int/stdint.h" #include "mem.h" +#include "timer.h" #include "syscalls.h" #include "fs/fs.h" @@ -12,7 +13,6 @@ #define FOOLOS_MODULE_NAME "task" int started; -uint64_t task_system_clock; static uint32_t c1,c2,c3; @@ -99,8 +99,7 @@ void task_create(int pid,void(*thread)()) uint32_t task_switch_next(uint32_t oldesp) { - task_system_clock++; - + timer_tick(); if(started!=0xabcde) return oldesp; if(CurrentTask!=-1)Threads[CurrentTask].esp0=oldesp; diff --git a/kernel/time.h b/kernel/time.h deleted file mode 100644 index 1c581c1..0000000 --- a/kernel/time.h +++ /dev/null @@ -1,3 +0,0 @@ -#include "lib/int/stdint.h" -volatile uint64_t task_system_clock; // from task.c - diff --git a/kernel/timer.c b/kernel/timer.c index da9e6bd..956195b 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -30,12 +30,15 @@ */ -#include "kernel.h" +#define FOOLOS_MODULE_NAME "timer" + +#include "timer.h" #include "x86.h" #include "../lib/logger/log.h" // logger facilities -#define FOOLOS_MODULE_NAME "timer" +//static volatile +static uint64_t task_system_clock=0; void timer_init() { @@ -43,7 +46,7 @@ void timer_init() // http://en.wikipedia.org/wiki/Intel_8253#Control_Word_Register // http://www.brokenthorn.com/Resources/OSDevPit.html // int0 will be triggered ~25 times a second. - + __asm__("pusha"); __asm__("mov %0, %%dx"::"X" (1193180 / 25)); @@ -60,4 +63,15 @@ void timer_init() __asm__("popa"); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Configured PIT Channel 0 : Mode 2 : 1/25 s."); + +} + +void timer_tick() +{ + task_system_clock++; +} + +uint64_t timer_get_ticks() +{ + return task_system_clock; } diff --git a/kernel/timer.h b/kernel/timer.h index 4859925..3b9ecdf 100644 --- a/kernel/timer.h +++ b/kernel/timer.h @@ -1 +1,5 @@ +#include "lib/int/stdint.h" + void timer_init(); +void timer_tick(); +uint64_t timer_get_ticks(); diff --git a/kernel/x86.c b/kernel/x86.c index 15236a3..725c50d 100644 --- a/kernel/x86.c +++ b/kernel/x86.c @@ -1,6 +1,7 @@ #define FOOLOS_MODULE_NAME "x86" #include "x86.h" +#include "timer.h" #include "lib/int/stdint.h" #include "lib/logger/log.h" @@ -8,11 +9,9 @@ // suffix (b, w, l, q for byte, word, dword, and qword). // -extern volatile uint64_t task_system_clock; // from task.c - void sleep(int i) { - volatile uint64_t clock=task_system_clock; + volatile uint64_t clock=timer_get_ticks(); // while(clock+i>task_system_clock) // { diff --git a/lib/logger/log.c b/lib/logger/log.c index a9b2165..703658a 100644 --- a/lib/logger/log.c +++ b/lib/logger/log.c @@ -1,39 +1,45 @@ #define FOOLOS_MODULE_NAME "log" -#include "lib/logger/log.h" #include <stdarg.h> #include "log.h" +#include "kernel/config.h" #include "kernel/console.h" #include "lib/printf/printf.h" -#include "kernel/config.h" #include "lib/int/stdint.h" -#include "kernel/time.h" +#include "lib/bool/bool.h" +#include "kernel/timer.h" -#define BUF_SIZE 4069 -static char buffer[BUF_SIZE]; -static int first; -static int last; +static char buffer[LOG_BUF_SIZE]; +static int first=0; +static int last=0; +static bool init=false; void log(char *module_name, int log_level, char *format_string, ...) { + #ifdef FOOLOS_LOG_OFF return; #endif - if(log_level<FOOLOS_LOG_INFO)return; + if(!init) + { + init=true; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"buffer: 0x%08X, first=%08X, last=%08X",buffer,&first,&last); + } + char buf_info[256]; char buf_log[256]; char buf_time[20]; - uint32_t t=task_system_clock; + uint32_t t=timer_get_ticks(); uint32_t s=t/25; uint32_t ms=t*1000/25-1000*s; - tfp_sprintf(buf_time,"[%6d.%05d] ",s,ms); + tfp_sprintf(buf_time,"[%3d.%05d] ",s,ms); va_list va; va_start(va,format_string); @@ -46,9 +52,9 @@ void log(char *module_name, int log_level, char *format_string, ...) for(int i=0;buf_log[i]!=0;i++) { buffer[last]=buf_log[i]; - last=(last+1)%BUF_SIZE; - if(first<last)if(last-first>=BUF_SIZE)first=(first+1)%BUF_SIZE; - if(last>first)if(BUF_SIZE-last+first>=BUF_SIZE)first=(first+1)%BUF_SIZE; + last=(last+1)%LOG_BUF_SIZE; + if(first<last)if(last-first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; + if(last>first)if(LOG_BUF_SIZE-last+first>=LOG_BUF_SIZE)first=(first+1)%LOG_BUF_SIZE; } @@ -57,23 +63,11 @@ void log(char *module_name, int log_level, 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 } -void log_init() -{ - first=last=0; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"init buffer at: 0x%08X, first=%08X, last=%08X",buffer,&first,&last); -} void log_log() { diff --git a/lib/logger/log.h b/lib/logger/log.h index 1159d94..bbe4c64 100644 --- a/lib/logger/log.h +++ b/lib/logger/log.h @@ -1,5 +1,5 @@ #ifndef FOOLOS_LOG_H -#define FOOLOS_LOGL_H +#define FOOLOS_LOG_H #define FOOLOS_LOG_INFO 3 #define FOOLOS_LOG_DEBUG 2 @@ -7,7 +7,6 @@ void log(char *module_name, int prio, char *format_string, ...); void panic(char *module_name, char *format_string); -void log_init(); void log_log(); #endif diff --git a/video/console.c b/video/console.c index e23a2c8..ae5d720 100644 --- a/video/console.c +++ b/video/console.c @@ -53,10 +53,12 @@ void scr_clear() { int x,y; - for(x=0;x<SCR_WIDTH;x++) + for(x=0;x<SCR_WIDTH+1;x++) for(y=0;y<SCR_HEIGHT;y++) { - print_char_col(x,y,'@',SCR_BLUE); + if(x==SCR_WIDTH)print_char_col(x,y,'|',SCR_BLUE); + else print_char_col(x,y,' ',SCR_BLUE); + } @@ -83,7 +85,7 @@ void scr_nextline() for(i=1;i<SCR_HEIGHT-1;i++) { - for(x=0;x<SCR_WIDTH;x++) + for(x=0;x<SCR_WIDTH+1;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; @@ -92,7 +94,8 @@ void scr_nextline() //clear last line if(i==SCR_HEIGHT-2) { - print_char_col(x,i,'@',SCR_LBLUE); + if(x==SCR_WIDTH)print_char_col(x,i,'|',SCR_BLUE); + else print_char_col(x,i,' ',SCR_BLUE); } diff --git a/video/console.h b/video/console.h index 22184fb..e8939e7 100644 --- a/video/console.h +++ b/video/console.h @@ -7,8 +7,8 @@ #define SCR_REAL_WIDTH 80 -#define SCR_WIDTH 70 -#define SCR_HEIGHT 23 +#define SCR_WIDTH 78 +#define SCR_HEIGHT 24 #define SCR_CTRL 0x3D4 #define SCR_DATA 0x3D5 |
