changeset 123:2a35ea7e123b

Moved the psw and registers into a program control block structure
author Jonathan Pevarnek <pevarnj@gmail.com>
date Thu, 23 Jun 2011 10:05:55 -0400
parents 22990a9ff28c
children 56447a5e2d2f
files include/os/pcb.h include/os/scall.h src/os/scall.c src/os/shell.c
diffstat 4 files changed, 48 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/os/pcb.h	Thu Jun 23 10:05:55 2011 -0400
@@ -0,0 +1,27 @@
+#ifndef __PCB_H
+#define __PCB_H
+
+#include <os/psw.h>
+#include <os/svc.h>
+
+typedef struct {
+	u64 registers[16];
+	Psw psw;
+} PCB;
+
+static inline void setcontext_pcb(PCB *pcb)
+{
+	setcontext(&(pcb->psw), pcb->registers);
+}
+
+static inline void savecontext_pcb(PCB *pcb)
+{
+	savecontext(&(pcb->psw), pcb->registers);
+}
+
+static inline void swapcontext_pcb(PCB *old, PCB *new)
+{
+	swapcontext(&(old->psw), old->registers, &(new->psw), new->registers);
+}
+
+#endif
--- a/include/os/scall.h	Sat Jun 18 20:54:59 2011 -0400
+++ b/include/os/scall.h	Thu Jun 23 10:05:55 2011 -0400
@@ -2,9 +2,9 @@
 #define __SCALL_H
 
 #include <os/psw.h>
+#include <os/pcb.h>
 
-Psw shellPsw; //XXX No idea if this is correct XXX
-u64 shellRegisters[16];
+PCB shellPCB;
 
 u64 svc_handler(u64 callCode, u64 a, u64 b, u64 c, u64 d);
 
--- a/src/os/scall.c	Sat Jun 18 20:54:59 2011 -0400
+++ b/src/os/scall.c	Thu Jun 23 10:05:55 2011 -0400
@@ -13,37 +13,36 @@
 
 u64 svc_handler(u64 callCode, u64 a, u64 b, u64 c, u64 d)
 {
-	Psw psw;
-	u64 registers[16];
+	PCB pcb;
 	void* point;
-	savecontext(&psw, registers);
+	savecontext_pcb(&pcb);
 	switch(callCode) {
 		case SVC_EXIT:
 			if(ms) {
 				msDestroy(ms, freeHeap); //dynamic memory was used, kill it
 				ms = NULL;
 			}
-			setcontext(&shellPsw, shellRegisters);
+			setcontext_pcb(&shellPCB);
 			break;
 		case SVC_PRINT: //print
-			registers[2] = putline((char*)a, (u32)b);
+			pcb.registers[2] = putline((char*)a, (u32)b);
 			break;
 		case SVC_READ:
-			registers[2] = getline((char*)a, (u32)b);
+			pcb.registers[2] = getline((char*)a, (u32)b);
 			break;
 		case SVC_FINFO:
-			registers[2] = getFInfo(a, (void*) b);
+			pcb.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;
+			pcb.registers[2] = (u64)point;
 			break;
 		default:
-			registers[2] = -1; //TODO HACK
+			pcb.registers[2] = -1; //TODO HACK
 			break;
 	}
-	setcontext(&psw, registers);
+	setcontext_pcb(&pcb);
 	return -1; //the code should never get here
 }
--- a/src/os/shell.c	Sat Jun 18 20:54:59 2011 -0400
+++ b/src/os/shell.c	Thu Jun 23 10:05:55 2011 -0400
@@ -8,13 +8,14 @@
 #include <os/psw.h>
 #include <os/svc.h>
 #include <os/scall.h>
+#include <os/pcb.h>
 
 #define PROGRAM_STACK_START 0x400000 - 160 //this is correct, ignore the documentation
 #define KERNEL_STACK_START 0x380000 - 160 //this is correct, ignore the documentation
 
 void start(u64 __memsize)
 {
-	char buffer[1024];
+	char buffer[128];
 	ErrCode err;
 	init_all(__memsize);
 	if(isError(init_fs(0x100, __memsize))) die();
@@ -50,34 +51,20 @@
 					void *toLoc = (void*)pHdr->p_vaddr;
 					memcpy(toLoc, fromLoc, pHdr->p_filesz);
 					size_t diff = pHdr->p_memsz - pHdr->p_filesz;
-					/*
-					sprintf(buffer, "file: %x, mem: %x, toLoc: %x\n", pHdr->p_filesz, pHdr->p_memsz, toLoc);
-					sPrint(buffer);
-					*/
 					if(diff) memset(toLoc + pHdr->p_filesz, 0, diff);
 				}
 			}
 
-			Psw psw;
-			u64 registers[16];
-			memset(&psw, 0, sizeof(psw));
-			memset(registers, 0, sizeof(registers));
-			registers[15] = PROGRAM_STACK_START;
-			psw.p = 1;
-			psw.ea = 1;
-			psw.ba = 1;
-			psw.ptr = eHdr->e_entry;
-			/*
-			sprintf(buffer, "Going to memory address %x\n", eHdr->e_entry);
-			sPrint(buffer);
-			*/
-			swapcontext(&shellPsw, shellRegisters, &psw, registers);
+			PCB pcb;
+			memset(&pcb, 0, sizeof(pcb));
+			pcb.registers[15] = PROGRAM_STACK_START;
+			pcb.psw.p = 1;
+			pcb.psw.ea = 1;
+			pcb.psw.ba = 1;
+			pcb.psw.ptr = eHdr->e_entry;
+			swapcontext_pcb(&shellPCB, &pcb);
 		loopCont:
 			free(data);
 		}
 	}
-
-//END:
-	sPrint("DONE\n");
-	die();
 }