changeset 145:03be5ed1f609

Use a better method to end a program when an exception occurs
author Jonathan Pevarnek <pevarnj@gmail.com>
date Thu, 22 Sep 2011 16:26:20 -0400
parents cf569b2ab76c
children df5e47ce93b6
files include/os/scall.h src/os/except.c src/os/scall.c
diffstat 3 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/include/os/scall.h	Thu Sep 22 16:12:27 2011 -0400
+++ b/include/os/scall.h	Thu Sep 22 16:26:20 2011 -0400
@@ -6,6 +6,7 @@
 
 PCB shellPCB;
 
+void end_program();
 u64 svc_handler(u64 callCode, u64 a, u64 b, u64 c, u64 d);
 
 #endif //__SCALL_H
--- a/src/os/except.c	Thu Sep 22 16:12:27 2011 -0400
+++ b/src/os/except.c	Thu Sep 22 16:26:20 2011 -0400
@@ -3,7 +3,7 @@
 #include <std.h>
 #include <string.h>
 #include <stdio.h>
-#include <prog/svcCalls.h>
+#include <os/scall.h>
 
 extern void PROGINT(void);
 
@@ -31,7 +31,7 @@
 	sPrint(buffer);
 
 	if(oldPsw->p) { //was running in the program mode, switch back to shell
-		exit(); //not sure if this is the best way to do it...
+		end_program();
 	}
 	
 	//kill the machine
--- a/src/os/scall.c	Thu Sep 22 16:12:27 2011 -0400
+++ b/src/os/scall.c	Thu Sep 22 16:26:20 2011 -0400
@@ -4,13 +4,18 @@
 #include <os/svc.h>
 #include <os/heap.h>
 #include <memStack.h>
-/*
-#include <stdio.h>
-#include <string.h>
-*/
 
 MemStack *ms = NULL;
 
+void end_program()
+{
+	if(ms) {
+		msDestroy(ms, freeHeap);
+		ms = NULL;
+	}
+	setcontext_pcb(&shellPCB);
+}
+
 u64 svc_handler(u64 callCode, u64 a, u64 b, u64 c, u64 d)
 {
 	PCB pcb;
@@ -18,11 +23,7 @@
 	savecontext_pcb(&pcb);
 	switch(callCode) {
 		case SVC_EXIT:
-			if(ms) {
-				msDestroy(ms, freeHeap); //dynamic memory was used, kill it
-				ms = NULL;
-			}
-			setcontext_pcb(&shellPCB);
+			end_program();
 			break;
 		case SVC_PRINT: //print
 			pcb.registers[2] = putline((char*)a, (u32)b);