summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/lib/tce/syscall.c4
-rw-r--r--src/user/test/main.c67
2 files changed, 45 insertions, 26 deletions
diff --git a/src/user/lib/tce/syscall.c b/src/user/lib/tce/syscall.c
index 4e81475..3e8d75e 100644
--- a/src/user/lib/tce/syscall.c
+++ b/src/user/lib/tce/syscall.c
@@ -44,8 +44,8 @@ void thread_start(void *data) {
mutex_lock(&_stack_freeing_mutex);
if (_stack_to_free != 0) free(_stack_to_free);
_stack_to_free = tsd->stack;
- asm volatile("movl %0, (_stack_freeing_mutex); int $64;" ::
- "a"(SC_THREAD_EXIT), "r"(MUTEX_UNLOCKED));
+ asm volatile("movl %%ebx, (_stack_freeing_mutex); int $64;" ::
+ "a"(SC_THREAD_EXIT), "b"(MUTEX_UNLOCKED));
}
void thread_new(void (*entry)(void*), void *data) {
struct thread_start_data *tsd = malloc(sizeof(struct thread_start_data));
diff --git a/src/user/test/main.c b/src/user/test/main.c
index e7a6b4f..c98a619 100644
--- a/src/user/test/main.c
+++ b/src/user/test/main.c
@@ -41,24 +41,31 @@ void list_dir(FILE f, int lv) {
file_info info;
while ((r = read(f, i, 256, buf)) > 0) {
+ if (strcmp(buf, ".") == 0 || strcmp(buf, "..") == 0) {
+ i++;
+ continue;
+ }
for (k = 0; k < lv; k++) printk(" ");
- printk(buf); printk("\t\t");
-
+ printk(buf);
stat_relative(f, buf, &info);
- printk_hex(info.type);
+ if (info.type & FT_DIR) printk("/");
+ printk(" \t");
+
+ if (info.type & FT_FILE) printk("file ");
+ if (info.type & FT_DIR) printk("dir ");
+ if (info.type & FT_SYMLINK) printk("symlink ");
+ if (info.type & FT_DEV) printk("dev ");
+ if (info.type & FT_TERMINAL) printk("term ");
+
if (info.type & FT_DIR) {
- printk("\t");
- if (strcmp(buf, ".") != 0 && strcmp(buf, "..") != 0) {
- FILE ff = open_relative(f, buf, 0);
- if (ff <= 0) {
- printk("error: "); printk_int(ff); printk("\n");
- } else {
- printk("fd: "); printk_int(ff); printk("\n");
- list_dir(ff, lv+1);
- close(ff);
- }
+ printk(" \t");
+ FILE ff = open_relative(f, buf, 0);
+ if (ff <= 0) {
+ printk("error: "); printk_int(ff); printk("\n");
} else {
- printk("\n");
+ printk("fd: "); printk_int(ff); printk("\n");
+ list_dir(ff, lv+1);
+ close(ff);
}
} else {
printk("\n");
@@ -67,6 +74,10 @@ void list_dir(FILE f, int lv) {
}
}
+void fprint(FILE f, char *s) {
+ write(f, 0, strlen(s), s);
+}
+
int main() {
printk("(test app) malloc(42) = ");
printk_hex((uint32_t)malloc(42));
@@ -93,27 +104,35 @@ int main() {
close(f);
}
- printk(" -> YOUR SHELL IS STARTING UP, SIR.\n");
f = open("/.ui/klog", 0);
if (f <= 0) {
printk(" -> Error #"); printk_int(f); printk(" - too bad. Exiting.\n");
} else {
- char *s = "Hello, writing from your opened file!\n";
- write(f, 0, strlen(s), s);
+ fprint(f, " -> Now reading && writing from/to virtual terminal '/.ui/klog'\n");
while (1) {
- char *s = " > ";
- write(f, 0, strlen(s), s);
+ fprint(f, " > ");
char buffer[256];
int l = read(f, 0, 255, buffer);
buffer[l] = 0;
if (buffer[l-1] == '\n') {
- char *s = "You said: ";
- write(f, 0, strlen(s), s);
- write(f, 0, l, buffer);
+ buffer[l-1] = 0; l--;
+
+ if (strcmp(buffer, "about") == 0) {
+ fprint(f, "Trivial/Computing Environment v0.1.0 - useless shell, first ediiton.\n");
+ } 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");
+ break;
+ } else if (strcmp(buffer, "gotosleep") == 0) {
+ while (1) thread_sleep(1000);
+ } else {
+ fprint(f, "Unknown command. ");
+ fprint(f, buffer);
+ }
} else {
- char *s = "oops\n";
- write(f, 0, strlen(s), s);
+ fprint(f, " - - - oops\n");
}
}
}