changeset 106:6243450db431

It works! Also, fixed up many a return value. So, I had the wrong number for the offset from the start of the program stack. It was 8, should be 160 Return values have been fixed to far less hackish alternatives sprintf now gives a hex value if %x is used (TODO: less code duplication)
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sun, 05 Jun 2011 15:31:51 -0400
parents fb73c5728eaf
children a57cb2d58b2a
files include/svcCalls.h src/os/scall.c src/osTest.c src/shell.c src/stdio.c
diffstat 5 files changed, 25 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/include/svcCalls.h	Sat Jun 04 23:20:53 2011 -0400
+++ b/include/svcCalls.h	Sun Jun 05 15:31:51 2011 -0400
@@ -3,16 +3,14 @@
 
 #include <svc_prog.h>
 
-static inline int exit()
+static inline void exit()
 {
 	invoke_svc0(0);
-	return 0; //TODO HACK
 }
 
 static inline int printLine(char *buf, int len)
 {
-	invoke_svc2(1, buf, len);
-	return 0; //TODO HACK
+	return invoke_svc2(1, buf, len);
 }
 
 
--- a/src/os/scall.c	Sat Jun 04 23:20:53 2011 -0400
+++ b/src/os/scall.c	Sun Jun 05 15:31:51 2011 -0400
@@ -10,12 +10,11 @@
 	switch(callCode) {
 		case 0: //exit
 			setcontext(&shellPsw, shellRegisters);
-			break; //to the best of my knowledge, this is not needed.
-			       //If this is wrong, my understanding of what I am doing is non-existent
+			break;
 		case 1: //print
-			putline((char*)a, (u32)b);
+			registers[2] = putline((char*)a, (u32)b);
 			break;
 	}
 	setcontext(&psw, registers);
-	return 0; //TODO HACK ???
+	return -1; //the code should never get here
 }
--- a/src/osTest.c	Sat Jun 04 23:20:53 2011 -0400
+++ b/src/osTest.c	Sun Jun 05 15:31:51 2011 -0400
@@ -2,7 +2,9 @@
 
 void start()
 {
+	printLine("Hello world!  This is a longer message, it is longer...\n", 56);
 	printLine("Hello world!\n", 13);
+	printLine("TEST\n", 5);
 	exit();
 	for(;;)
 		;
--- a/src/shell.c	Sat Jun 04 23:20:53 2011 -0400
+++ b/src/shell.c	Sun Jun 05 15:31:51 2011 -0400
@@ -9,7 +9,7 @@
 #include <svc.h>
 #include <os/scall.h>
 
-#define KERNEL_STACK_START 0x400000 - 8
+#define KERNEL_STACK_START 0x400000 - 160 //this is correctt, ignore the documentation
 
 void start(u64 __memsize)
 {
@@ -46,6 +46,10 @@
 					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);
 				}
 			}
@@ -59,6 +63,10 @@
 			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);
 		loopCont:
 			free(data);
--- a/src/stdio.c	Sat Jun 04 23:20:53 2011 -0400
+++ b/src/stdio.c	Sun Jun 05 15:31:51 2011 -0400
@@ -16,6 +16,15 @@
 				case '%':
 					*str++ = '%';
 					break;
+				case 'x':
+					{
+						char buffer[32];
+						long long num = va_arg(ap, long long);
+						itoa(num, buffer, 16);
+						memcpy(str, buffer, strlen(buffer));
+						str += strlen(buffer);
+					}
+					break;
 				case 'i':
 					{
 						char buffer[32];