changeset 113:d971d4288a5a

An attempt to get the standard library to work for both the system level stuff and the program level stuff
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sat, 11 Jun 2011 15:24:28 -0400
parents aec919038b60
children 4187043a3e3a
files .hgignore Makefile include/os/svcNums.h include/std.h include/svcCalls.h src/os/scall.c src/os/std.c src/prog/hello.c
diffstat 8 files changed, 41 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sat Jun 11 14:13:21 2011 -0400
+++ b/.hgignore	Sat Jun 11 15:24:28 2011 -0400
@@ -6,7 +6,7 @@
 ^dynamic$
 ^testFS$
 ^shell$
-^osTest$
+^hello$
 ^ls$
 ^loader\.bin$
 ^cscope\.out$
--- a/Makefile	Sat Jun 11 14:13:21 2011 -0400
+++ b/Makefile	Sat Jun 11 15:24:28 2011 -0400
@@ -15,7 +15,7 @@
 PROGBINS=hello ls
 
 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 arch/arch.a
-hello_OBJS=src/prog/hello.o
+hello_OBJS=src/prog/hello.o src/prog/std.o src/prog/string.o
 ls_OBJS=src/prog/ls.o
 
 sarpn_OBJS=src/sarpn.o src/std.o src/string.o src/prog/stack.o src/operations.o src/math.o arch/arch.a
@@ -33,7 +33,7 @@
 
 clean:
 	rm -f $(shell_OBJS)
-	rm -f $(osTest_OBJS)
+	rm -f $(hello_OBJS)
 	rm -f $(ls_OBJS)
 	rm -f $(sarpn_OBJS)
 	rm -f $(dynamic_OBJS)
@@ -67,9 +67,14 @@
 %.o: %.S
 	$(CC) $(CFLAGS) -c -o $@ $<
 
+src/prog/%.o: src/prog/%.c
+	$(CC) $(CFLAGS) -include include/system.h -c -o $@ $<
+src/os/%.o: src/os/%.c
+	$(CC) $(CFLAGS) -include include/system.h -c -o $@ $< -DOSLEVEL
 %.o: %.c
 	$(CC) $(CFLAGS) -include include/system.h -c -o $@ $<
 
+
 %.o: %.cpp
 	$(CXX) $(CXXFLAGS) -include include/system.h -c -o $@ $<
 
@@ -111,20 +116,7 @@
 # DO NOT DELETE
 
 src/dynamic.o: include/std.h include/die.h include/string.h include/stack.h
-src/ls.o: include/os/fsStructs.h include/svcCalls.h include/svc_prog.h
-src/ls.o: include/os/svcNums.h include/error.h
-src/operations.o: include/operations.h include/std.h include/die.h
-src/operations.o: include/stack.h include/string.h include/math.h
-src/osTest.o: include/svcCalls.h include/svc_prog.h include/os/svcNums.h
-src/osTest.o: include/error.h
 src/sarpn.o: include/std.h include/die.h include/string.h
 src/sarpn.o: include/operations.h include/stack.h
-src/shell.o: include/std.h include/die.h include/string.h include/stdio.h
-src/shell.o: include/error.h include/os/fs.h include/os/fsStructs.h
-src/shell.o: include/elf.h include/psw.h include/svc.h include/os/scall.h
-src/stack.o: include/stack.h include/std.h include/die.h
-src/std.o: include/std.h include/die.h include/string.h
-src/stdio.o: include/stdio.h include/std.h include/die.h include/string.h
-src/stdio.o: include/stdarg.h
 src/testFS.o: include/std.h include/die.h include/os/fs.h include/error.h
 src/testFS.o: include/os/fsStructs.h
--- a/include/os/svcNums.h	Sat Jun 11 14:13:21 2011 -0400
+++ b/include/os/svcNums.h	Sat Jun 11 15:24:28 2011 -0400
@@ -3,8 +3,7 @@
 
 #define SVC_EXIT 0
 #define SVC_PRINT 1
-#define SVC_FINFO 2
-
-#define SVC_MAX 2
+#define SVC_READ 2
+#define SVC_FINFO 3
 
 #endif //__SVCNUMS_H
--- a/include/std.h	Sat Jun 11 14:13:21 2011 -0400
+++ b/include/std.h	Sat Jun 11 15:24:28 2011 -0400
@@ -28,7 +28,7 @@
 
 
 //MALLOC CODE
-
+#ifdef OSLEVEL
 struct HEADER{
 	struct HEADER *next;
 	size_t size;
@@ -40,5 +40,6 @@
 void malloc_init(size_t memSize);
 void* malloc(size_t size);
 void free(void *ptr);
+#endif
 
 #endif
--- a/include/svcCalls.h	Sat Jun 11 14:13:21 2011 -0400
+++ b/include/svcCalls.h	Sat Jun 11 15:24:28 2011 -0400
@@ -15,6 +15,11 @@
 	return invoke_svc2(SVC_PRINT, buf, len);
 }
 
+static inline int readLine(char *buf, int len)
+{
+	return invoke_svc2(SVC_READ, buf, len);
+}
+
 static inline ErrCode finfo(u32 n, void* de)
 {
 	return invoke_svc2(SVC_FINFO, n, de);
--- a/src/os/scall.c	Sat Jun 11 14:13:21 2011 -0400
+++ b/src/os/scall.c	Sat Jun 11 15:24:28 2011 -0400
@@ -19,6 +19,9 @@
 		case SVC_PRINT: //print
 			registers[2] = putline((char*)a, (u32)b);
 			break;
+		case SVC_READ:
+			registers[2] = getline((char*)a, (u32)b);
+			break;
 		case SVC_FINFO:
 			registers[2] = getFInfo(a, (void*) b);
 			break;
--- a/src/os/std.c	Sat Jun 11 14:13:21 2011 -0400
+++ b/src/os/std.c	Sat Jun 11 15:24:28 2011 -0400
@@ -1,11 +1,16 @@
 #include <std.h>
 #include <string.h>
+#ifndef OSLEVEL
+#include <svcCalls.h>
+#endif
 
 void init_all(u64 __memsize)
 {
+#ifdef OSLEVEL
 	init_io_int();
 	init_console();
 	malloc_init(__memsize - HEAP_START);
+#endif
 }
 
 double abs(double num)
@@ -118,20 +123,31 @@
 	char *b = a;
 	while(*b && *++b);
 	do {
-		putline(a, (b - a > CON_LEN)?CON_LEN:(b - a)); //TODO supervisor call
+#ifdef OSLEVEL
+		putline(a, (b - a > CON_LEN)?CON_LEN:(b - a));
+#else //problem mode
+		printLine(a, (b - a > CON_LEN)?CON_LEN:(b - a));
+#endif
+		
 		a += CON_LEN;
 	} while(a < b);
 }
 
 char* sGet(char *a, unsigned int n)
 {
+#ifdef OSLEVEL
 	int length = getline(a, n); //TODO supervisor call
+#else //problem mode
+	int length = readLine(a, n); //TODO supervisor call
+#endif
+
 	a[(length < n)?length:n - 1] = '\0';
 	return a;
 }
 
 //DYNAMIC MEMORY
 
+#ifdef OSLEVEL //TODO NOT JUST OS
 static Header base;
 static Header *allocp = NULL; //the location of the last known free block
 
@@ -191,3 +207,5 @@
 		toFree->next = toFree->next->next;
 	}
 }
+
+#endif //OSLEVEL
--- a/src/prog/hello.c	Sat Jun 11 14:13:21 2011 -0400
+++ b/src/prog/hello.c	Sat Jun 11 15:24:28 2011 -0400
@@ -1,7 +1,8 @@
 #include <svcCalls.h>
+#include <std.h>
 
 void start()
 {
-	printLine("Hello world!\n", 13);
+	sPrint("Hello world!\n");
 	exit();
 }