Mercurial > sos > sos
view src/os/scall.c @ 117:32560561ccea
First attempt at program level dynamic memory
Created a new "class" memStack. It is essentially the same as the other stack in the program...
TODO: find a C way to combine these if possible
Moved the dynamic test program to be a part of the new system, it seems to work...
The general idea here is that if there is no dynamic memory in the system,
it asks the os to allocate a part of its heap for the program's usage. The os
gives the program a chunk, 4kb alligned, which it can use as part of its heap.
Additionally, the address of the chunk is tracked by the os in a stack. When the
program exits, the os will free all the memory in the stack and go back to the main
program.
author | Jonathan Pevarnek <pevarnj@gmail.com> |
---|---|
date | Thu, 16 Jun 2011 11:24:39 -0400 |
parents | 4473e746fe5a |
children | 73deaa825710 |
line wrap: on
line source
#include <os/scall.h> #include <os/svcNums.h> #include <os/fs.h> #include <os/svc.h> #include <os/heap.h> #include <memStack.h> /* #include <stdio.h> #include <string.h> */ MemStack *ms = NULL; u64 svc_handler(u64 callCode, u64 a, u64 b, u64 c, u64 d) { Psw psw; u64 registers[16]; void* point; savecontext(&psw, registers); switch(callCode) { case SVC_EXIT: if(ms) msDestroyFN(ms, freeHeap); //dynamic memory was used, kill it setcontext(&shellPsw, shellRegisters); break; case SVC_PRINT: //print registers[2] = putline((char*)a, (u32)b); break; case SVC_READ: registers[2] = getline((char*)a, (u32)b); break; case SVC_FINFO: registers[2] = getFInfo(a, (void*) b); break; case SVC_GETHEAP: point = allocHeap(a, (void*)b); if(!ms) ms = msInit(); msPush(ms, point); registers[2] = (u64)point; break; default: registers[2] = -1; //TODO HACK break; } setcontext(&psw, registers); return -1; //the code should never get here }