diff options
| author | Miguel <m.i@gmx.at> | 2018-08-17 18:17:21 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-08-17 18:17:21 +0200 |
| commit | 340f513e9a41dd5815e79cffe54c3f631407f4e1 (patch) | |
| tree | 08ee2757e891513467cc6fb06f94efb58adc618e | |
| parent | 51d4dd040a291b62c648ff6cc0d7e0058cf4056f (diff) | |
cleaning up in progress
| -rw-r--r-- | asm/NOTES | 2 | ||||
| -rw-r--r-- | kernel/kmalloc.c | 41 | ||||
| -rw-r--r-- | kernel/kmalloc.h | 16 | ||||
| -rw-r--r-- | kernel/usermode.c | 53 |
4 files changed, 47 insertions, 65 deletions
diff --git a/asm/NOTES b/asm/NOTES deleted file mode 100644 index d5df67a..0000000 --- a/asm/NOTES +++ /dev/null @@ -1,2 +0,0 @@ -files in this directory should not depend on any other files. -This is not supported by the build-system by now. diff --git a/kernel/kmalloc.c b/kernel/kmalloc.c index d235f55..e3b0863 100644 --- a/kernel/kmalloc.c +++ b/kernel/kmalloc.c @@ -1,36 +1,43 @@ #define FOOLOS_MODULE_NAME "kmalloc" #include "kmalloc.h" -#include <stddef.h> + #include "lib/logger/log.h" -#define MEM_SIZE 1024*1024*8 +// 8MB for in kernel-memory +#define MEM_SIZE 1024*1024*8 + +static uint8_t data[MEM_SIZE]; // bytes -static uint8_t data[MEM_SIZE]; //8MB kernel memory managed by kmalloc -static uint32_t next; -static uint32_t first; -static uint8_t init=0; +static uint32_t next; +static uint32_t first; +static uint8_t init=0; -void kmallocinit() +// will be initialized on first call to kballoc() // +static void kmallocinit() { next=&(data[0]); first=next; - if(next%4096) //align (TODO: check how to tell gcc to do that) + //TODO: optionally tell gcc to align this itself. + if(next%4096) { - next+=4096; - next/=4096; - next*=4096; + next+=4096; + next/=4096; + next*=4096; } + // -// log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kmalloc_init: 0x%08X",next); + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"kmalloc_init: 0x%08X",next); init=1; } -// kernel block memory allocation +// kernel block memory allocation // uint32_t kballoc(uint32_t size) { size*=4096; + if(!init)kmallocinit(); + uint32_t old=next; next+=size; @@ -38,14 +45,14 @@ uint32_t kballoc(uint32_t size) { panic(FOOLOS_MODULE_NAME,"kballoc ran out of memory! maybe increase MEM_SIZE in kmalloc.c?"); } - // log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"(%d) : 0x%08X (~%dKB left)",size,old,(MEM_SIZE-next+first)/1024); - + + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"(%d) : 0x%08X (~%dKB left)",size,old,(MEM_SIZE-next+first)/1024); return old; } -//TODO! +//TODO: allow freeing memory!! uint32_t kbfree(uint32_t pos) { - + panic(FOOLOS_MODULE_NAME,"kbfree NOT IMPLEMENTED YET"); } diff --git a/kernel/kmalloc.h b/kernel/kmalloc.h index 2f89f8a..2faecb8 100644 --- a/kernel/kmalloc.h +++ b/kernel/kmalloc.h @@ -1,2 +1,16 @@ #include <stdint.h> -uint32_t kballoc(uint32_t size); + +/* + * Kernel Block Memory Allocation + * + * The kernel reserves some memory for internal operation, since malloc + * is not available. + * + * Last Revision: 17 AUG 2018 + */ + +// Allocate size*4096 bytes and returns a 32-bit pointer +uint32_t kballoc (uint32_t size); + +// Free memory allocated before by supplying the address (TODO) +uint32_t kbfree (uint32_t addr); diff --git a/kernel/usermode.c b/kernel/usermode.c index eb19cdf..db4ac9f 100644 --- a/kernel/usermode.c +++ b/kernel/usermode.c @@ -1,64 +1,27 @@ -#include "usermode.h" #define FOOLOS_MODULE_NAME "usermode" -#include "lib/logger/log.h" -#include "syscalls.h" -#include <stddef.h> - -tss_struct sys_tss; //Define the TSS as a global structure - -// generic syscall interface! -/* -int syscall(int call, int p1, int p2, int p3) -{ - int ebx; // will hold return value; - - asm("pusha"); - - // select syscall - asm("mov %0, %%eax"::"m"(call)); - - // pass params - asm("mov %0,%%edx"::"m"(p1)); - asm("mov %0,%%ecx"::"m"(p2)); - asm("mov %0,%%ebx"::"m"(p3)); - - // interrrupt - asm("int $0x80"); +#include "usermode.h" - // get return value - asm("mov %%ebx, %0": "=b" (ebx)); +#include "syscalls.h" +#include "kmalloc.h" - asm("popa"); +#include "lib/logger/log.h" - return ebx; -} -*/ +#include <stddef.h> -/* -int write(int file, char *ptr, int len) -{ - return syscall(SYSCALL_WRITE,file,ptr,len); -} -*/ -/* -int execve(char *name, char **argv, char **env) -{ - return syscall(SYSCALL_EXECVE,name,argv,env); -} -*/ +//https://wiki.osdev.org/Task_State_Segment +tss_struct sys_tss; //Define the TSS as a global structure void install_tss(int cpu_no){ // now fill each value // set values necessary - sys_tss.ss0 = 0x10; //kernel data + sys_tss.ss0 = 0x10; //kernel data sys_tss.esp0 = kballoc(4); // now set the IO bitmap (not necessary, so set above limit) // sys_tss.iomap = ( unsigned short ) sizeof( tss_struct ); } - void switch_to_user_mode() { asm_usermode(); |
