diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | kernel/kernel.c | 27 | ||||
| -rw-r--r-- | kernel/keyboard.c | 12 | ||||
| -rw-r--r-- | kernel/keyboard.h | 1 | ||||
| -rw-r--r-- | kernel/mem.c | 41 | ||||
| -rw-r--r-- | kernel/mem.h | 2 | ||||
| -rw-r--r-- | kernel/spinlock.c | 20 | ||||
| -rw-r--r-- | kernel/spinlock.h | 9 | ||||
| -rw-r--r-- | kernel/timer.c | 4 | ||||
| -rw-r--r-- | kernel/timer.h | 2 | ||||
| -rw-r--r-- | lib/buffer/ringbuffer.c | 46 | ||||
| -rw-r--r-- | lib/logger/log.c | 20 | ||||
| -rw-r--r-- | video/vesa.c | 2 |
13 files changed, 78 insertions, 110 deletions
@@ -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 <stdint.h> #include <stdlib.h> - // CODE FOR Stack Smashing Protector, TODO: MOVE / and do not duplicate // with sys.c // http://wiki.osdev.org/Stack_Smashing_Protector @@ -47,11 +46,17 @@ 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 // // after this is set up we will be able to allocate and deallocate @@ -63,11 +68,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) // vmem_init(); @@ -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 <stdint.h> + #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<mem_array_size;i++) { _mmngr_memory_map[i]=0xffffffff; @@ -57,6 +69,7 @@ int mmap_first_free () return -1; } +/* //find the first free consecutive x bits int mmap_first_free_s (uint32_t x) { @@ -73,6 +86,7 @@ int mmap_first_free_s (uint32_t x) return -1; } +*/ void pmmngr_init_region (uint32_t base, uint32_t size) { @@ -96,7 +110,6 @@ void pmmngr_deinit_region (uint32_t base, uint32_t size) mmap_set (align++); mem_free_blocks--; } - } void* pmmngr_alloc_block () @@ -116,6 +129,7 @@ void* pmmngr_alloc_block () return (void*)addr; } +/* void* pmmngr_alloc_blocks (uint32_t size) { @@ -138,6 +152,7 @@ void* pmmngr_alloc_blocks (uint32_t size) return (void*)addr; } +*/ void pmmngr_free_block (void* p) { @@ -151,17 +166,14 @@ void pmmngr_free_block (void* p) } } + void mem_init(uint16_t *memmap,uint16_t entries) { - - // init free blocks counter - mem_free_blocks=0; + // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"the memory map contains %d entries.",entries); // count available mem uint32_t total_mem=0, highest_end=0, high_end_low=0,last_end=0; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"the memory map contains %d entries.",entries); - // preserve pointer uint16_t save=memmap; @@ -173,10 +185,11 @@ void mem_init(uint16_t *memmap,uint16_t entries) +(((uint32_t)memmap[5])<<16)+memmap[4]; #ifdef MEM_PRINT_MEMORYMAP - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"type: %02d / range: 0x%08x - 0x%08x", - memmap[8],low_end,high_end); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"range: 0x%08x - 0x%08x (%s)", + low_end,high_end,memmap_type_to_string[memmap[8]-1]); #endif + //reclaimable OR usable if(memmap[8]==1||memmap[8]==3) { total_mem+=memmap[4]+(memmap[5]<<16); @@ -201,7 +214,6 @@ void mem_init(uint16_t *memmap,uint16_t entries) int blocks=highest_end/4096+1; mem_array_size=blocks/32+1; - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Highest end area: 0x%08X - 0x%08X",high_end_low,highest_end); if(highest_end-high_end_low<mem_array_size*4) { @@ -223,8 +235,9 @@ void mem_init(uint16_t *memmap,uint16_t entries) memmap+=12; } - // here is somewhere our kernel stuff ;) // TODO!! better. - pmmngr_deinit_region(0x0,0x600000); + // here is somewhere our kernel stuff. + // reserve 4Mb (0x100000-0x500000) for kernel and ext2 img + pmmngr_deinit_region(0x0,0x500000); // and here is the memory map that we JUST created! pmmngr_deinit_region(_mmngr_memory_map,mem_array_size*4); diff --git a/kernel/mem.h b/kernel/mem.h index 1624a06..d574fec 100644 --- a/kernel/mem.h +++ b/kernel/mem.h @@ -1,6 +1,6 @@ #include "lib/int/stdint.h" void* pmmngr_alloc_block (); -void* pmmngr_alloc_blocks (uint32_t size); +//void* pmmngr_alloc_blocks (uint32_t size); void pmmngr_free_block (void* p); void mem_init(uint16_t *memmap,uint16_t entries); diff --git a/kernel/spinlock.c b/kernel/spinlock.c index 33ed178..2c6d161 100644 --- a/kernel/spinlock.c +++ b/kernel/spinlock.c @@ -1,23 +1,23 @@ #define FOOLOS_MODULE_NAME "spinlock" #include "lib/logger/log.h" -#include "lib/int/stdint.h" -#include "x86.h" +#include "spinlock.h" // https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html +#define NUMBER_SPINLOCKS 16 -typedef uint8_t spinlock; -volatile spinlock spinlocks[16]; +spinlock spinlocks[NUMBER_SPINLOCKS]; - -void init_spinlocks() +void check_spinlocks() { - log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Initializing spinlocks at 0x%08X ",spinlocks); - for(int i=0;i<16;i++)spinlocks[i]=0; + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Spinlocks at 0x%08X ",spinlocks); + for(int i=0;i<NUMBER_SPINLOCKS;i++) + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"%d",spinlocks[i]); } -volatile void lock_spin(int i) + +void lock_spin(spinlock i) { spinlock *addr=spinlocks+i; @@ -26,7 +26,7 @@ volatile void lock_spin(int i) while(x86_xchg(addr,1)); } -void lock_release(int i) +void lock_release(spinlock i) { // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"unlocking %d",i); diff --git a/kernel/spinlock.h b/kernel/spinlock.h index 7080490..43cd82f 100644 --- a/kernel/spinlock.h +++ b/kernel/spinlock.h @@ -1,8 +1,11 @@ #ifndef SPINLOCK_H #define SPINLOCK_H -void init_spinlocks(); -volatile void lock_spin(int i); -void lock_release(int i); +#include <stdint.h> + +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 <stdint.h> 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_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]; @@ -39,7 +32,7 @@ void log(char *module_name, int log_level, char *format_string, ...) uint32_t s=t/25; uint32_t ms=t*1000/25-1000*s; - tfp_sprintf(buf_time,"[%3d.%05d] ",s,ms); + tfp_sprintf(buf_time,"[%3d.%05d]",s,ms); va_list va; va_start(va,format_string); @@ -71,6 +64,13 @@ void panic(char *module_name, char *message) void log_log() { + #ifdef FOOLOS_LOG_OFF + return; + #endif + + char buf_log[256]; + tfp_sprintf(buf_log,"[ 0.00000] log: buffer state: first=%d, last=%d, buf_size=%d\n",first,last,LOG_BUF_SIZE); + console_put_str(buf_log); for(int i=first;i!=last;i++) { console_put_char(buffer[i]); diff --git a/video/vesa.c b/video/vesa.c index 0859f19..416a893 100644 --- a/video/vesa.c +++ b/video/vesa.c @@ -231,6 +231,7 @@ void vesa_render() vesa_switch_buffers(); } +/* void vesa_init_doublebuff() { boxx=300; @@ -243,6 +244,7 @@ void vesa_init_doublebuff() VbeModeInfoBlock->physbase=buffer; } +*/ |
