changeset 149:eb69d1caa83b

First try with storage keys
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sun, 30 Oct 2011 00:24:35 -0400
parents 21a0692ee656
children e72f984619c7
files Makefile include/os/heap.h include/os/storageKeys.h src/os/heap.c src/os/shell.c src/os/std.c src/os/storageKeys.c
diffstat 7 files changed, 59 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Oct 03 17:56:15 2011 -0400
+++ b/Makefile	Sun Oct 30 00:24:35 2011 -0400
@@ -14,7 +14,9 @@
 OSBINS=shell
 PROGBINS=hello ls echo dynamic rpn broken
 
-shell_OBJS=src/os/shell.o src/os/std.o src/os/fs.o src/os/string.o src/os/stdio.o src/os/scall.o src/os/heap.o src/os/memStack.o src/os/except.o arch/arch.a
+shell_OBJS=src/os/shell.o src/os/std.o src/os/fs.o src/os/string.o \
+					 src/os/stdio.o src/os/scall.o src/os/heap.o src/os/memStack.o \
+					 src/os/except.o src/os/storageKeys.o arch/arch.a
 hello_OBJS=src/prog/hello.o src/prog/std.o src/prog/string.o
 ls_OBJS=src/prog/ls.o
 echo_OBJS=src/prog/echo.o src/prog/std.o src/prog/string.o
--- a/include/os/heap.h	Mon Oct 03 17:56:15 2011 -0400
+++ b/include/os/heap.h	Sun Oct 30 00:24:35 2011 -0400
@@ -2,6 +2,7 @@
 #define __HEAP_H
 
 #include <memHead.h>
+#include <os/storageKeys.h>
 
 #define PageSize 4096
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/os/storageKeys.h	Sun Oct 30 00:24:35 2011 -0400
@@ -0,0 +1,9 @@
+#ifndef __STORAGEKEYS_H
+#define __STORAGEKEYS_H
+
+#define BLOCKSIZE 0x1000
+#define PROGSK 0xC
+
+void setStorageKey(intptr_t blockPtr, u8 key, u8 fBit);
+
+#endif
--- a/src/os/heap.c	Mon Oct 03 17:56:15 2011 -0400
+++ b/src/os/heap.c	Sun Oct 30 00:24:35 2011 -0400
@@ -1,5 +1,6 @@
 #include <os/heap.h>
 #include <memHead.h>
+#include <os/storageKeys.h>
 
 static Header base;
 static Header *allocp = NULL;
@@ -32,6 +33,10 @@
 				*ammt = cur->size*PageSize - sizeof(Header);
 			}
 			allocp = prev;
+			intptr_t ptr;
+			for(ptr = (intptr_t)cur; (ptr - (intptr_t)cur)/PageSize < nUnits; ptr += PageSize) {
+				setStorageKey(ptr, PROGSK, 1);
+			}
 			return (void*)(cur + 1);
 		} else if(cur == allocp) { //We went back to the start...
 			return NULL;
--- a/src/os/shell.c	Mon Oct 03 17:56:15 2011 -0400
+++ b/src/os/shell.c	Sun Oct 30 00:24:35 2011 -0400
@@ -9,6 +9,7 @@
 #include <os/svc.h>
 #include <os/scall.h>
 #include <os/pcb.h>
+#include <os/storageKeys.h>
 
 #define PROGRAM_STACK_START 0x400000
 #define KERNEL_STACK_START 0x380000
@@ -95,6 +96,7 @@
 			pcb.psw.p = 1;
 			pcb.psw.ea = 1;
 			pcb.psw.ba = 1;
+			pcb.psw.key = PROGSK;
 			pcb.psw.ptr = eHdr->e_entry;
 
 			swapcontext_pcb(&shellPCB, &pcb);
--- a/src/os/std.c	Mon Oct 03 17:56:15 2011 -0400
+++ b/src/os/std.c	Sun Oct 30 00:24:35 2011 -0400
@@ -15,6 +15,7 @@
 	init_console();
 	init_prog_int();
 	heap_init(__memsize);
+	init_storage_keys(__memsize);
 #endif
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/os/storageKeys.c	Sun Oct 30 00:24:35 2011 -0400
@@ -0,0 +1,38 @@
+#include <os/storageKeys.h>
+#include <string.h>
+
+static struct {
+	u32 _zero0;
+	u16 _zero1;
+	u8 _zero2;
+	u8 key:4,
+		 f:1, //true if storage key applies for reading also
+		 r:1,
+		 c:1,
+		 _zero3:1;
+} StorageKey;
+
+void setStorageKey(intptr_t blockPtr, u8 key, u8 fBit) {
+	StorageKey.key = key;
+	StorageKey.f = fBit;
+	asm volatile(
+			"sske %0,%1\n"
+			: /* no output */
+			: "d" (StorageKey),
+			  "a" (blockPtr)
+	);
+}
+
+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
+			key = PROGSK;
+		} else {
+			key = 0;
+		}
+		setStorageKey(ptr, key, 1);
+	}
+}