From 9c8cfc2e52b0446f7cab14325028075760869b45 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Wed, 26 Nov 2014 17:42:33 +0100 Subject: further cleanup --- Makefile | 2 +- kernel/kernel.c | 27 ++++++++------------------- kernel/keyboard.c | 12 +++--------- kernel/keyboard.h | 1 - kernel/mem.c | 41 +++++++++++++++++++++++++++-------------- kernel/mem.h | 2 +- kernel/spinlock.c | 20 ++++++++++---------- kernel/spinlock.h | 9 ++++++--- kernel/timer.c | 4 +--- kernel/timer.h | 2 +- lib/buffer/ringbuffer.c | 46 ++++++++-------------------------------------- lib/logger/log.c | 20 ++++++++++---------- video/vesa.c | 2 ++ 13 files changed, 78 insertions(+), 110 deletions(-) diff --git a/Makefile b/Makefile index 95be7eb..57d01fa 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ CFLAGS+=-std=gnu11 CFLAGS+=-I. CFLAGS+=-I/home/miguel/temp/fool-os-stuff/newlib-2.1.0/newlib/libc/include #CFLAGS+=-lgcc -#CFLAGS+=-Werror-implicit-function-declaration +CFLAGS+=-Werror-implicit-function-declaration #CFLAGS+=-fno-zero-initialized-in-bss #CFLAGS+= -O4 #CFLAGS+=-fdata-sections -ffunction-sections diff --git a/kernel/kernel.c b/kernel/kernel.c index 0c14e56..ecb42eb 100644 --- a/kernel/kernel.c +++ b/kernel/kernel.c @@ -29,7 +29,6 @@ #include #include - // CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate // with sys.c // http://wiki.osdev.org/Stack_Smashing_Protector @@ -47,10 +46,16 @@ void __stack_chk_fail(void) { panic(FOOLOS_MODULE_NAME,"Stack smashing detected"); } +// // mp informs us if this if this is the main processor void kernel_main(uint32_t initial_stack, int mp) { + // + // Configuring the PIT timer. + // + timer_init(); + // // Memory Init // @@ -62,11 +67,6 @@ void kernel_main(uint32_t initial_stack, int mp) // mem_init(0xa001,*((uint16_t *)(0xa000))); - // - // Configuring the PIT timer. - // - timer_init(); - // // Activate Virtual Memory (paging) // @@ -84,19 +84,14 @@ void kernel_main(uint32_t initial_stack, int mp) // // Setup PIC (interrupts) - // + // TODO: log! pic_setup(); - - // mouse and kb driver init (before interrupts) - // mouse_init(); - keyboard_init(); - - // // Setup Interrupts (code segment: 0x08) // int_init(0x08); + // // Gather Info about other processors. (APs) @@ -112,12 +107,6 @@ void kernel_main(uint32_t initial_stack, int mp) panic(FOOLOS_MODULE_NAME,"ACPI and MP search failed! I do not want to continue!"); */ - // init spinlocks - init_spinlocks(); - - - // ringbuffer for stdin! - ringbuffer_init(); // load and run foolshell // we will come back into the kernel only on interrupts... diff --git a/kernel/keyboard.c b/kernel/keyboard.c index 074c495..32f28f0 100644 --- a/kernel/keyboard.c +++ b/kernel/keyboard.c @@ -11,15 +11,9 @@ /// keyboard driver //// // http://www.computer-engineering.org/ps2keyboard/scancodes1.html -static bool shift_l; -static bool shift_r; -static bool capslock; - -void keyboard_init() -{ - shift_l=shift_r=capslock=false; //!! -} - +static bool shift_l=false; +static bool shift_r=false; +static bool capslock=false; void keyboard_handle(uint8_t in) { diff --git a/kernel/keyboard.h b/kernel/keyboard.h index 0b3bf28..8b13789 100644 --- a/kernel/keyboard.h +++ b/kernel/keyboard.h @@ -1,2 +1 @@ -void keyboard_init(); diff --git a/kernel/mem.c b/kernel/mem.c index b2ab6ad..cf0c673 100644 --- a/kernel/mem.c +++ b/kernel/mem.c @@ -1,7 +1,8 @@ #define FOOLOS_MODULE_NAME "mem" +#include + #include "config.h" -#include "lib/int/stdint.h" #include "lib/logger/log.h" // logger facilities //! 8 blocks per byte @@ -13,12 +14,20 @@ //! block alignment ??? TODO: what is this!? #define PMMNGR_BLOCK_ALIGN PMMNGR_BLOCK_SIZE + //memory map bit array. Each bit represents a 4KB memory block static uint32_t *_mmngr_memory_map; - static uint32_t mem_free_blocks; static uint32_t mem_array_size; +char *memmap_type_to_string[]= + { + "Usable", + "Reserved", + "ACPI reclaimable", + "ACPI NVS", + "Bad Memory" + }; // bit funcs! void mmap_set(int bit) { @@ -34,10 +43,13 @@ int mmap_test(int bit) { return _mmngr_memory_map[bit / 32] & (1 << (bit % 32)); } +// +// By default, Set all of memory is in use void pmmngr_init () { - // By default, all of memory is in use + mem_free_blocks=0; + for(int i=0;i + +typedef uint8_t spinlock; + +volatile void lock_spin(spinlock); +void lock_release(spinlock); #endif diff --git a/kernel/timer.c b/kernel/timer.c index 956195b..676be48 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -33,11 +33,9 @@ #define FOOLOS_MODULE_NAME "timer" #include "timer.h" -#include "x86.h" -#include "../lib/logger/log.h" // logger facilities +#include "lib/logger/log.h" // logger facilities -//static volatile static uint64_t task_system_clock=0; void timer_init() diff --git a/kernel/timer.h b/kernel/timer.h index 3b9ecdf..57ea21e 100644 --- a/kernel/timer.h +++ b/kernel/timer.h @@ -1,4 +1,4 @@ -#include "lib/int/stdint.h" +#include void timer_init(); void timer_tick(); diff --git a/lib/buffer/ringbuffer.c b/lib/buffer/ringbuffer.c index 9e3adaf..dcf7bc2 100644 --- a/lib/buffer/ringbuffer.c +++ b/lib/buffer/ringbuffer.c @@ -3,45 +3,37 @@ // todo: syncing access to buffer. #define FOOLOS_MODULE_NAME "ringbuffer" + #include "lib/bool/bool.h" #include "lib/logger/log.h" #include "kernel/spinlock.h" -static volatile int front; -static volatile int back; -static volatile int size; - #define RINGBUFFER_SIZE 10 +static volatile int size=RINGBUFFER_SIZE; +static volatile int front=RINGBUFFER_SIZE-1; +static volatile int back=RINGBUFFER_SIZE-1; static volatile char buf[RINGBUFFER_SIZE]; -bool ringbuffer_selftest(); - -void ringbuffer_init() -{ - size=RINGBUFFER_SIZE; - front=size-1; - back=size-1; - -// ringbuffer_selftest(); -// while(1); -} - bool ringbuffer_put(char c) { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put wants lock)"); lock_spin(3); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by put)"); + if((back-1+size)%size==front) { lock_release(3); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put)"); return false; } + buf[back]=c; log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"put %d %d (%c)", back, front,c); back--; back+=size; back%=size; + lock_release(3); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"unlocked by put)"); @@ -51,7 +43,6 @@ bool ringbuffer_put(char c) bool ringbuffer_get(char *c) { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"get wants lock)"); lock_spin(3); log(FOOLOS_MODULE_NAME,FOOLOS_LOG_FINE,"locked by get)"); @@ -74,24 +65,3 @@ bool ringbuffer_get(char *c) return true; } - -bool ringbuffer_selftest() -{ - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"ringbuffer selftest"); - char c; - - ringbuffer_put('a'); - ringbuffer_put('b'); - ringbuffer_put('c'); - ringbuffer_put('d'); - ringbuffer_put('e'); - - ringbuffer_get(&c); - ringbuffer_get(&c); - ringbuffer_get(&c); - ringbuffer_get(&c); - ringbuffer_get(&c); - ringbuffer_get(&c); - ringbuffer_get(&c); - -} diff --git a/lib/logger/log.c b/lib/logger/log.c index 703658a..d58d2d6 100644 --- a/lib/logger/log.c +++ b/lib/logger/log.c @@ -14,23 +14,16 @@ 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 + #ifdef FOOLOS_LOG_OFF return; -#endif + #endif if(log_levelphysbase=buffer; } +*/ -- cgit v1.2.3