summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/lib/include/tce/syscall.h3
-rw-r--r--src/user/lib/tce/syscall.c10
-rw-r--r--src/user/test/main.c44
3 files changed, 43 insertions, 14 deletions
diff --git a/src/user/lib/include/tce/syscall.h b/src/user/lib/include/tce/syscall.h
index 028b544..1811422 100644
--- a/src/user/lib/include/tce/syscall.h
+++ b/src/user/lib/include/tce/syscall.h
@@ -19,6 +19,9 @@ int proc_priv();
void* sbrk(size_t size);
void brk(void* ptr);
+int run(char* file, char** args);
+int waitpid(int pid);
+
FILE open(char* filename, int mode);
FILE open_relative(FILE root, char* filename, int mode);
int stat(char* filename, file_info *info);
diff --git a/src/user/lib/tce/syscall.c b/src/user/lib/tce/syscall.c
index 3e8d75e..bc8bfd8 100644
--- a/src/user/lib/tce/syscall.c
+++ b/src/user/lib/tce/syscall.c
@@ -73,6 +73,16 @@ void brk(void* ptr) {
return call (SC_BRK, ptr, 0, 0, 0, 0);
}
+// ********** proc
+
+int run(char* filename, char** args) {
+ return call(SC_RUN, (unsigned)filename, (unsigned)args, 0, 0, 0);
+}
+
+int waitpid(int p) {
+ return call(SC_WAITPID, p, 0, 0, 0, 0);
+}
+
// ********** file
FILE open(char* filename, int mode) {
diff --git a/src/user/test/main.c b/src/user/test/main.c
index 81753bd..eb289ca 100644
--- a/src/user/test/main.c
+++ b/src/user/test/main.c
@@ -74,6 +74,19 @@ void list_dir(FILE f, int lv) {
}
}
+void list_root() {
+ FILE f = open("/", 0);
+ if (f <= 0) {
+ printk(" -> Could not open '/', error #");
+ printk_int(f);
+ printk("...\n");
+ } else {
+ printk("Now enumerating '/' (fd "); printk_int(f); printk(") :\n");
+ list_dir(f, 1);
+ close(f);
+ }
+}
+
void fprint(FILE f, char *s) {
write(f, 0, strlen(s), s);
}
@@ -102,19 +115,9 @@ int main(char** args) {
if (threads == 0) break;
}
printk("\n -> Ok, let's try something else.\n");
+ list_root();
- FILE f = open("/", 0);
- if (f <= 0) {
- printk(" -> Could not open '/', error #");
- printk_int(f);
- printk("...\n");
- } else {
- printk("Now enumerating '/' (fd "); printk_int(f); printk(") :\n");
- list_dir(f, 1);
- close(f);
- }
-
- f = open("/.ui/klog", 0);
+ FILE f = open("/.ui/klog", 0);
if (f <= 0) {
printk(" -> Error #"); printk_int(f); printk(" - too bad. Exiting.\n");
} else {
@@ -133,13 +136,26 @@ int main(char** args) {
} else if (strcmp(buffer, "help") == 0) {
fprint(f, "Available commands: about, help, exit.\n");
} else if (strcmp(buffer, "exit") == 0) {
- fprint(f, "Exiting the shell. I think the system is pretty likely to panic.\n");
+ fprint(f, "Exiting the shell. See you later!\n");
break;
} else if (strcmp(buffer, "gotosleep") == 0) {
while (1) thread_sleep(1000);
+ } else if (strcmp(buffer, "spawn") == 0) {
+ char *args[] = {"hello", "world", 0};
+ int pid = run("/somewhere/bin/test", args);
+ if (pid < 0) {
+ printk("Error "); printk_int(pid); printk("\n");
+ } else {
+ printk("Launched, pid="); printk_int(pid); printk("\n");
+ int ret = waitpid(pid);
+ printk("Exited, ret="); printk_int(ret); printk("\n");
+ }
+ } else if (strcmp(buffer, "root") == 0) {
+ list_root();
} else {
- fprint(f, "Unknown command. ");
+ fprint(f, "Unknown command : ");
fprint(f, buffer);
+ fprint(f, "\n");
}
} else {
fprint(f, " - - - oops\n");