Mercurial > sos > sos
changeset 150:e72f984619c7
Consolidated a lot of the defines which relate to the memory layout
There is a new file (include/os/memLayout.h) which now includes just
about all the #defines
author | Jonathan Pevarnek <pevarnj@gmail.com> |
---|---|
date | Wed, 02 Nov 2011 09:55:09 -0400 |
parents | eb69d1caa83b |
children | b18d52f11ade |
files | arch/progint.S include/os/heap.h include/os/memLayout.h include/os/progint.h include/os/storageKeys.h src/os/heap.c src/os/shell.c src/os/storageKeys.c |
diffstat | 8 files changed, 68 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/arch/progint.S Sun Oct 30 00:24:35 2011 -0400 +++ b/arch/progint.S Wed Nov 02 09:55:09 2011 -0400 @@ -1,4 +1,5 @@ #include <os/progint.h> +#include <os/memLayout.h> .text .align 4 @@ -7,7 +8,7 @@ PROGINT: stmg %r0,%r15,PROGINT_REG_LOC #save current registers -# llilf %r15,PROGINT_STACK +# llilf %r15,PROGINT_STACK_START lhi %r15,PROGINT_STACK_SHIFT sla %r15,PROGINT_STACK_SHIFT_OFFSET(%r0)
--- a/include/os/heap.h Sun Oct 30 00:24:35 2011 -0400 +++ b/include/os/heap.h Wed Nov 02 09:55:09 2011 -0400 @@ -4,7 +4,7 @@ #include <memHead.h> #include <os/storageKeys.h> -#define PageSize 4096 +#define PageSize 0x1000 void heap_init(size_t memSize); void* allocHeap(size_t size, size_t *ammt);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/os/memLayout.h Wed Nov 02 09:55:09 2011 -0400 @@ -0,0 +1,54 @@ +#ifndef __MEMLAYOUT_H +#define __MEMLAYOUT_H + +/* + * The following diagram was originally made by Holly and Jeff + + +----------+ + | | + | free | + | | + +----------+ + | | + 4MB +----------+ at 4MB, growing upward, is the program data/text + | | | growing downward, is the program stack. + | V | + 3.5MB +----------+ at 3.5MB, growing downward, is the program's in-kernel stack + | | | + | V | + +----------+ at 3MB, growing downward, is the program interrupt stack + | | | + | V | + +----------| ~2.5MB + | | + | free | + | | + +----------+ + | | + 1MB +----------+ at 1MB, growing upward, is the shell data/text + | | | growing downward, is the shell stack. + | V | + 512KB +----------+ + | | + | free | + | | + 8KB +----------+ + |XXXXXXXXXX| The first 8KB are reserved. + 0 +----------+ +*/ + +#define STACK_SIZE 0x80000 +#define PROGRAM_STACK_START 0x400000 +#define PROGRAM_TEXT_START 0x400000 +#define KERNEL_STACK_START 0x380000 +#define PROGINT_STACK_START 0x300000 +#define SHELL_STACK_START 0x100000 +#define SHELL_TEXT_START 0x100000 + +//how much room to have between the stack start and the actual start of data +#define STACK_SPACING 160 + +//the size of a filesystem block +#define BLOCKSIZE 0x1000 + +#endif //__MEMLAYOUT_H
--- a/include/os/progint.h Sun Oct 30 00:24:35 2011 -0400 +++ b/include/os/progint.h Wed Nov 02 09:55:09 2011 -0400 @@ -6,7 +6,6 @@ #define PROGINT_PSW_OLD 0x150 #define PROGINT_PSW_NEW 0x1D0 -#define PROGINT_STACK 0x300000 #define PROGINT_STACK_SHIFT 0x30 #define PROGINT_STACK_SHIFT_OFFSET 16
--- a/include/os/storageKeys.h Sun Oct 30 00:24:35 2011 -0400 +++ b/include/os/storageKeys.h Wed Nov 02 09:55:09 2011 -0400 @@ -1,7 +1,6 @@ #ifndef __STORAGEKEYS_H #define __STORAGEKEYS_H -#define BLOCKSIZE 0x1000 #define PROGSK 0xC void setStorageKey(intptr_t blockPtr, u8 key, u8 fBit);
--- a/src/os/heap.c Sun Oct 30 00:24:35 2011 -0400 +++ b/src/os/heap.c Wed Nov 02 09:55:09 2011 -0400 @@ -1,6 +1,7 @@ #include <os/heap.h> #include <memHead.h> #include <os/storageKeys.h> +#include <os/memLayout.h> static Header base; static Header *allocp = NULL; @@ -34,8 +35,8 @@ } allocp = prev; intptr_t ptr; - for(ptr = (intptr_t)cur; (ptr - (intptr_t)cur)/PageSize < nUnits; ptr += PageSize) { - setStorageKey(ptr, PROGSK, 1); + for(ptr = (intptr_t)cur; (ptr - (intptr_t)cur)/BLOCKSIZE < nUnits; ptr += PageSize) { + setStorageKey(ptr, PROGSK, 1); //TODO only do this if being called by the program (how?) } return (void*)(cur + 1); } else if(cur == allocp) { //We went back to the start...
--- a/src/os/shell.c Sun Oct 30 00:24:35 2011 -0400 +++ b/src/os/shell.c Wed Nov 02 09:55:09 2011 -0400 @@ -10,10 +10,7 @@ #include <os/scall.h> #include <os/pcb.h> #include <os/storageKeys.h> - -#define PROGRAM_STACK_START 0x400000 -#define KERNEL_STACK_START 0x380000 -#define STACK_SPACING 160 +#include <os/memLayout.h> #define MAX_INPUT_LENGTH 128 //128 characters maximum input #define MAX_ARGS 10 //no more than ten arguments, including the program name
--- a/src/os/storageKeys.c Sun Oct 30 00:24:35 2011 -0400 +++ b/src/os/storageKeys.c Wed Nov 02 09:55:09 2011 -0400 @@ -1,4 +1,5 @@ #include <os/storageKeys.h> +#include <os/memLayout.h> #include <string.h> static struct { @@ -12,7 +13,8 @@ _zero3:1; } StorageKey; -void setStorageKey(intptr_t blockPtr, u8 key, u8 fBit) { +void setStorageKey(intptr_t blockPtr, u8 key, u8 fBit) +{ StorageKey.key = key; StorageKey.f = fBit; asm volatile( @@ -23,12 +25,14 @@ ); } -void init_storage_keys(u64 memsize) { +void init_storage_keys(u64 memsize) +{ memset(&StorageKey, 0, sizeof(StorageKey)); intptr_t ptr = 0x0; u8 key; for(ptr = 0x0; ptr < memsize; ptr += BLOCKSIZE) { - if(ptr >= 0x380000 && ptr < 0x410000) { //is in the range the program should be accessing + if(ptr >= PROGRAM_STACK_START - STACK_SIZE && ptr < PROGRAM_TEXT_START + 0x10000) { + //is in the range the program should be accessing key = PROGSK; } else { key = 0;