diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-13 16:16:43 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-13 16:16:43 +0100 |
commit | 5bc7fcc00507bbc5ff5bf957a1589209f8495534 (patch) | |
tree | f18969c395f6e74e0f299948e376abbe74577f68 | |
parent | 41a4f5309ef298da764bf1dca1254e734a4417f0 (diff) | |
download | kogata-5bc7fcc00507bbc5ff5bf957a1589209f8495534.tar.gz kogata-5bc7fcc00507bbc5ff5bf957a1589209f8495534.zip |
Shell begins to be usefull.
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | res/fonts/Makefile | 2 | ||||
-rw-r--r-- | res/fonts/pcvga.c | 2 | ||||
-rw-r--r-- | res/keymaps/Makefile | 2 | ||||
-rw-r--r-- | res/keymaps/fr.c | 2 | ||||
-rw-r--r-- | src/kernel/config.h | 2 | ||||
-rw-r--r-- | src/kernel/fs/iso9660.c | 2 | ||||
-rw-r--r-- | src/kernel/user/process.c | 4 | ||||
-rw-r--r-- | src/lib/include/unistd.h | 10 | ||||
-rw-r--r-- | src/lib/libkogata/Makefile | 2 | ||||
-rw-r--r-- | src/lib/libkogata/unistd.c | 67 | ||||
-rw-r--r-- | src/sysbin/init/main.c | 6 | ||||
-rw-r--r-- | src/sysbin/shell/main.c | 42 | ||||
-rw-r--r-- | src/sysbin/terminal/main.c | 14 |
14 files changed, 136 insertions, 23 deletions
@@ -26,7 +26,7 @@ mrproper: run_tests: rebuild src/tests/run_tests.sh -cdrom.iso: all +cdrom.iso: all make_cdrom.sh ./make_cdrom.sh run_qemu: cdrom.iso diff --git a/res/fonts/Makefile b/res/fonts/Makefile index 9a2a6b3..758bbcf 100644 --- a/res/fonts/Makefile +++ b/res/fonts/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-I../../src/lib/include -std=c11 +CFLAGS=-I../../src/lib/include/proto -std=c11 AS=nasm ASFLAGS=-fbin diff --git a/res/fonts/pcvga.c b/res/fonts/pcvga.c index b646eb8..b520171 100644 --- a/res/fonts/pcvga.c +++ b/res/fonts/pcvga.c @@ -1,6 +1,6 @@ #include <stdio.h> -#include <proto/font_file.h> +#include <font_file.h> char font_data[256][16] = { /* 0x00 */ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, diff --git a/res/keymaps/Makefile b/res/keymaps/Makefile index 3e7a755..147a60d 100644 --- a/res/keymaps/Makefile +++ b/res/keymaps/Makefile @@ -1,5 +1,5 @@ CC=gcc -CFLAGS=-I../../src/lib/include -std=c11 +CFLAGS=-I../../src/lib/include/proto -std=c11 all: fr.km diff --git a/res/keymaps/fr.c b/res/keymaps/fr.c index 04f086e..f3139eb 100644 --- a/res/keymaps/fr.c +++ b/res/keymaps/fr.c @@ -1,6 +1,6 @@ #include <stdio.h> -#include <proto/keymap_file.h> +#include <keymap_file.h> keymap_t fr_keymap = { { // normal diff --git a/src/kernel/config.h b/src/kernel/config.h index e7b9591..f50a4ff 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -24,6 +24,6 @@ // Comment to disable either form of debug log output #define DBGLOG_TO_SERIAL -#define DBGLOG_TO_SCREEN +//#define DBGLOG_TO_SCREEN /* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/kernel/fs/iso9660.c b/src/kernel/fs/iso9660.c index 4de6f2b..6c67823 100644 --- a/src/kernel/fs/iso9660.c +++ b/src/kernel/fs/iso9660.c @@ -315,7 +315,7 @@ bool iso9660_dir_readdir(fs_handle_t *h, size_t ent_no, dirent_t *d) { if (!(dr->flags & ISO9660_DR_FLAG_DIR) && name[len] != ';') continue; if (name[len-1] == '.') len--; // file with no extension - if (idx == ent_no) { + if (idx - 2 == ent_no) { // Found the node we are interested in if (len >= DIR_MAX) len = DIR_MAX - 1; memcpy(d->name, name, len); diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c index 52f1031..00a7e44 100644 --- a/src/kernel/user/process.c +++ b/src/kernel/user/process.c @@ -244,7 +244,7 @@ void process_exit(process_t *p, int status, int exit_code) { // notify parent process_t *par = p->parent; if (par->status == PS_RUNNING) { - resume_on(par->children); + resume_on(&par->children); resume_on(p); } @@ -408,7 +408,7 @@ void process_wait_any_child(process_t *par, proc_status_t *st, bool wait) { { int st = enter_critical(CL_NOSWITCH); mutex_unlock(&par->lock); - wait_ok = wait_on(par); + wait_ok = wait_on(&par->children); exit_critical(st); } diff --git a/src/lib/include/unistd.h b/src/lib/include/unistd.h new file mode 100644 index 0000000..5080d6c --- /dev/null +++ b/src/lib/include/unistd.h @@ -0,0 +1,10 @@ +#pragma once +#include <stddef.h> + +int chdir(const char* path); + +char* getcwd(char* buf, size_t buf_len); + +char* pathncat(char* buf, const char* add, size_t buf_len); // path simplification + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/lib/libkogata/Makefile b/src/lib/libkogata/Makefile index 20c6dee..95de086 100644 --- a/src/lib/libkogata/Makefile +++ b/src/lib/libkogata/Makefile @@ -1,6 +1,6 @@ OBJ = start.o malloc.o debug.o syscall.o user_region.o \ mainloop.o gip.o draw.o keyboard.o \ - stdio.o + stdio.o unistd.o LIB = ../../common/libkogata/libkogata.lib ../../common/libalgo/libalgo.lib ../../common/libc/libc.lib diff --git a/src/lib/libkogata/unistd.c b/src/lib/libkogata/unistd.c new file mode 100644 index 0000000..80a32e4 --- /dev/null +++ b/src/lib/libkogata/unistd.c @@ -0,0 +1,67 @@ +#include <string.h> + +#include <syscall.h> + +#include <unistd.h> + + +char cwd_buf[256]; + +char* getcwd(char* buf, size_t buf_len) { + if (buf_len > strlen(cwd_buf)) { + strcpy(buf, cwd_buf); + return buf; + } else { + return 0; + } +} + +int chdir(const char* path) { + char cwd_buf2[256]; + strcpy(cwd_buf2, cwd_buf); + + if (!pathncat(cwd_buf2, path, 256)) return -1; + + stat_t st; + if (!stat(cwd_buf2, &st)) return -1; + if (!st.type & FT_DIR) return -1; + + strcpy(cwd_buf, cwd_buf2); + return 0; +} + +char* pathncat(char* buf, const char* add, size_t buf_len) { + if (strchr(add, ':')) { + if (strlen(add) < buf_len) { + strcpy(buf, add); + return buf; + } else { + return 0; + } + } else { + char* sep_init = strchr(buf, ':'); + if (add[0] == '/') { + if (strlen(add) + (sep_init + 1 - buf) < buf_len) { + strcpy(sep_init + 1, add); + return buf; + } else { + return 0; + } + } else { + //TODO: simplify '..' + char* end = buf + strlen(buf) - 1; + if (*end != '/') end++; + if (end + 1 - buf + strlen(add) < buf_len) { + *end = '/'; + strcpy(end + 1, add); + return buf; + } else { + return 0; + } + } + return 0; + } +} + + +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/sysbin/init/main.c b/src/sysbin/init/main.c index d7f3f36..6ac003b 100644 --- a/src/sysbin/init/main.c +++ b/src/sysbin/init/main.c @@ -80,10 +80,10 @@ void setup_sys() { char* sep = strchr(buf, ':'); if (sep == 0) { - ok = fs_subfs("sys", "root", buf, FM_READ | FM_MMAP); + ok = fs_subfs("sys", "root", buf, FM_READ | FM_MMAP | FM_READDIR); } else { *sep = 0; - ok = fs_subfs("sys", buf, sep +1, FM_READ | FM_MMAP); + ok = fs_subfs("sys", buf, sep +1, FM_READ | FM_MMAP | FM_READDIR); } if (!ok) PANIC("[init] Could not bind root:/sys to sys:/"); @@ -166,7 +166,7 @@ int main(int argc, char **argv) { char buf[50]; snprintf(buf, 50, "/config/%s", config); - bool ok = fs_subfs("config", "root", buf, FM_READ | FM_WRITE | FM_MMAP); + bool ok = fs_subfs("config", "root", buf, FM_READ | FM_WRITE | FM_MMAP | FM_READDIR); if (!ok) PANIC("[init] Could not setup config:"); } diff --git a/src/sysbin/shell/main.c b/src/sysbin/shell/main.c index 54cec06..1929025 100644 --- a/src/sysbin/shell/main.c +++ b/src/sysbin/shell/main.c @@ -4,22 +4,58 @@ #include <debug.h> #include <stdio.h> +#include <unistd.h> #include <syscall.h> +void ls(char* dir) { + fd_t f = open(dir, FM_READDIR); + if (f) { + dirent_t i; + int ent_no = 0; + while (readdir(f, ent_no++, &i)) { + printf("%s\n", i.name); + } + close(f); + } else { + printf("Could not open directory '%s'\n", dir); + } +} + int main(int argc, char **argv) { dbg_printf("[shell] Starting\n"); /*fctl(stdio, FC_SET_BLOCKING, 0);*/ - puts("Hello, world!\n"); + puts("Kogata shell.\n"); + + chdir("sys:"); while(true) { - puts("> "); char buf[256]; + printf("\n%s> ", getcwd(buf, 256)); + getline(buf, 256); - printf("You said: '%s'. I don't understand a word of that.\n\n", buf); + if (!strncmp(buf, "cd ", 3)) { + chdir(buf + 3); + } else if (!strcmp(buf, "ls")) { + if (getcwd(buf, 256)) { + ls(buf); + } + } else if (!strncmp(buf, "ls ", 3)) { + char buf2[256]; + if (getcwd(buf2, 256)) { + if (pathncat(buf2, buf + 3, 256)) { + ls(buf2); + } + } + } else if (!strcmp(buf, "exit")) { + break; + } else { + printf("No such command.\n"); + } } + printf("Bye.\n"); return 0; } diff --git a/src/sysbin/terminal/main.c b/src/sysbin/terminal/main.c index 133736b..1174305 100644 --- a/src/sysbin/terminal/main.c +++ b/src/sysbin/terminal/main.c @@ -231,13 +231,7 @@ void c_buffer_info(gip_handler_t *s, gip_msg_header *p, gip_buffer_info_msg *m) void c_key_down(gip_handler_t *s, gip_msg_header *p) { term_t *c = (term_t*)s->data; - keyboard_press(c->kb, p->arg); -} - -void c_key_up(gip_handler_t *s, gip_msg_header *p) { - term_t *c = (term_t*)s->data; - - key_t k = keyboard_release(c->kb, p->arg); + key_t k = keyboard_press(c->kb, p->arg); c->wr_c_buf = 0; if (k.flags & KBD_CHAR) { @@ -250,6 +244,12 @@ void c_key_up(gip_handler_t *s, gip_msg_header *p) { mainloop_nonblocking_write(&c->app, &c->wr_c_buf, 1, false); } +void c_key_up(gip_handler_t *s, gip_msg_header *p) { + term_t *c = (term_t*)s->data; + + keyboard_release(c->kb, p->arg); +} + void c_unknown_msg(gip_handler_t *s, gip_msg_header *p) { // TODO } |