diff options
Diffstat (limited to 'kernel')
| -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 |
9 files changed, 57 insertions, 61 deletions
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(); |
