changeset 155:9ad854e6d994

Move the definition of the page size to the same location as everything else memory related
author Jonathan Pevarnek <pevarnj@gmail.com>
date Fri, 04 Nov 2011 15:30:17 -0400
parents 0d0ce48aa55d
children 2cf6fb157764
files include/os/heap.h include/os/memLayout.h src/os/heap.c
diffstat 3 files changed, 9 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/include/os/heap.h	Fri Nov 04 14:29:16 2011 -0400
+++ b/include/os/heap.h	Fri Nov 04 15:30:17 2011 -0400
@@ -4,8 +4,6 @@
 #include <memHead.h>
 #include <os/storageKeys.h>
 
-#define PageSize 0x1000
-
 void heap_init(size_t memSize);
 void* allocHeap(size_t size, size_t *ammt);
 void freeHeap(void *ptr);
--- a/include/os/memLayout.h	Fri Nov 04 14:29:16 2011 -0400
+++ b/include/os/memLayout.h	Fri Nov 04 15:30:17 2011 -0400
@@ -50,5 +50,7 @@
 
 //the size of a filesystem block
 #define BLOCKSIZE 0x1000
+//the size of a memory page
+#define PAGESIZE 0x1000
 
 #endif //__MEMLAYOUT_H
--- a/src/os/heap.c	Fri Nov 04 14:29:16 2011 -0400
+++ b/src/os/heap.c	Fri Nov 04 15:30:17 2011 -0400
@@ -3,8 +3,6 @@
 #include <os/storageKeys.h>
 #include <os/memLayout.h>
 
-//TODO break if PageSize%BLOCKSIZE != 0
-
 static Header base;
 static Header *allocp = NULL;
 
@@ -14,13 +12,13 @@
 	allocp->size = 0;
 	allocp->next = (void*)HEAP_START;
 	allocp->next->next = &base;
-	allocp->next->size = (memSize - HEAP_START)/PageSize;
+	allocp->next->size = (memSize - HEAP_START)/PAGESIZE;
 }
 
 //sets ammt to the amount of space that was allocated
 void* allocHeap(size_t size, size_t *ammt)
 { 
-	size_t nUnits = ((size + sizeof(Header)) + PageSize - 1)/PageSize;
+	size_t nUnits = ((size + sizeof(Header)) + PAGESIZE - 1)/PAGESIZE;
 	Header *prev = allocp;
 	Header *cur, *temp;
 	for(cur = prev->next;; prev = cur, cur = cur->next) {
@@ -28,16 +26,16 @@
 			if(cur->size == nUnits) {
 				prev->next = cur->next;
 			} else {
-				temp = cur + nUnits*PageSize/sizeof(Header);
+				temp = cur + nUnits*PAGESIZE/sizeof(Header);
 				temp->size = cur->size - nUnits;
 				temp->next = cur->next;
 				prev->next = temp;
 				cur->size = nUnits;
 			}
-			*ammt = cur->size*PageSize - sizeof(Header);
+			*ammt = cur->size*PAGESIZE - sizeof(Header);
 			allocp = prev;
 			intptr_t ptr;
-			for(ptr = (intptr_t)cur; (ptr - (intptr_t)cur) < nUnits*PageSize; ptr += BLOCKSIZE) {
+			for(ptr = (intptr_t)cur; (ptr - (intptr_t)cur) < nUnits*PAGESIZE; ptr += BLOCKSIZE) {
 				setStorageKey(ptr, PROGSK, 1); //TODO only do this if being called by the program (how?)
 			}
 			return (void*)(cur + 1);
@@ -51,7 +49,7 @@
 {
 	Header *toFree = (Header *)ptr - 1;
 	intptr_t skLoc;
-	for(skLoc = (intptr_t)toFree; (skLoc - (intptr_t)toFree) < toFree->size*PageSize; skLoc += BLOCKSIZE) {
+	for(skLoc = (intptr_t)toFree; (skLoc - (intptr_t)toFree) < toFree->size*PAGESIZE; skLoc += BLOCKSIZE) {
 		setStorageKey(skLoc, 0, 1);
 	}
 	Header *scan;
@@ -64,7 +62,7 @@
 		scan->next = toFree->next;
 		toFree = scan;
 	}
-	if(toFree + (toFree->size*PageSize)/sizeof(Header) == toFree->next) {
+	if(toFree + (toFree->size*PAGESIZE)/sizeof(Header) == toFree->next) {
 		toFree->size += toFree->next->size;
 		toFree->next = toFree->next->next;
 	}