diff options
Diffstat (limited to 'src/sysbin')
-rw-r--r-- | src/sysbin/bam.lua | 2 | ||||
-rw-r--r-- | src/sysbin/giosrv/main.c | 11 | ||||
-rw-r--r-- | src/sysbin/init/main.c | 50 | ||||
-rw-r--r-- | src/sysbin/linker.ld | 33 | ||||
-rw-r--r-- | src/sysbin/login/main.c | 30 | ||||
-rw-r--r-- | src/sysbin/shell/main.c | 29 | ||||
-rw-r--r-- | src/sysbin/terminal/main.c | 18 |
7 files changed, 76 insertions, 97 deletions
diff --git a/src/sysbin/bam.lua b/src/sysbin/bam.lua index d9d5846..8628bf1 100644 --- a/src/sysbin/bam.lua +++ b/src/sysbin/bam.lua @@ -1,6 +1,6 @@ local function sysbin_settings(name) local s = TableDeepCopy(user_settings) - s.link.flags:Add("-T src/sysbin/linker.ld", + s.link.flags:Add("-T src/lib/linker.ld", "-Xlinker -Map=build/sysbin/" .. name .. ".map") return s end diff --git a/src/sysbin/giosrv/main.c b/src/sysbin/giosrv/main.c index 37f0f3c..b8e0095 100644 --- a/src/sysbin/giosrv/main.c +++ b/src/sysbin/giosrv/main.c @@ -6,6 +6,7 @@ #include <kogata/debug.h> #include <kogata/region_alloc.h> +#include <proto/launch.h> #include <proto/keyboard.h> #include <kogata/gip.h> @@ -62,7 +63,7 @@ int main(int argc, char **argv) { dbg_print("[giosrv] Starting up.\n"); // ---- Keyboard setup - kbd.fd = open("io:/input/pckbd", FM_READ); + kbd.fd = sc_open("io:/input/pckbd", FM_READ); if (kbd.fd == 0) PANIC("Could not open keyboard"); mainloop_fd_t kh; @@ -75,10 +76,10 @@ int main(int argc, char **argv) { mainloop_add_fd(&kh); // ---- VESA setup - srv.fd = open("io:/display/vesa", FM_IOCTL | FM_READ | FM_WRITE | FM_MMAP); + srv.fd = sc_open("io:/display/vesa", FM_IOCTL | FM_READ | FM_WRITE | FM_MMAP); if (srv.fd == 0) PANIC("Could not open fbdev"); - int r = ioctl(srv.fd, IOCTL_FB_GET_INFO, &srv.mode); + int r = sc_ioctl(srv.fd, IOCTL_FB_GET_INFO, &srv.mode); ASSERT(r == 1); dbg_printf("[giosrv] Running on FB %dx%d\n", srv.mode.width, srv.mode.height); @@ -86,7 +87,7 @@ int main(int argc, char **argv) { gipsrv = new_gip_handler(&giosrv_cb, &srv); ASSERT(gipsrv != 0); - gipsrv->mainloop_item.fd = 1; + gipsrv->mainloop_item.fd = STD_FD_GIOSRV; mainloop_add_fd(&gipsrv->mainloop_item); // ---- Enter main loop @@ -105,7 +106,7 @@ void send_buffer_info(gip_handler_t *h, giosrv_t *s) { gip_buffer_info_msg msg_data; msg_data.geom = s->mode; - if (!gen_token(s->fd, &msg_data.tok)) { + if (!sc_gen_token(s->fd, &msg_data.tok)) { dbg_printf("[giosrv] Could not generate token for buffer_info_msg.\n"); } else { dbg_printf("[giosrv] Generated token: %x %x\n", diff --git a/src/sysbin/init/main.c b/src/sysbin/init/main.c index da51223..ce09f37 100644 --- a/src/sysbin/init/main.c +++ b/src/sysbin/init/main.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdlib.h> +#include <proto/launch.h> + #include <kogata/syscall.h> #include <kogata/debug.h> #include <kogata/printf.h> @@ -51,25 +53,25 @@ btree_t *parse_cmdline(const char* x) { btree_t* read_cmdline() { char cmdline_buf[256]; - fd_t f = open("io:/cmdline", FM_READ); + fd_t f = sc_open("io:/cmdline", FM_READ); if (f == 0) return 0; - size_t len = read(f, 0, 255, cmdline_buf); + size_t len = sc_read(f, 0, 255, cmdline_buf); cmdline_buf[len] = 0; - close(f); + sc_close(f); return parse_cmdline(cmdline_buf); } void setup_sys() { - fd_t sysdir_cfg = open("config:/sysdir", FM_READ); + fd_t sysdir_cfg = sc_open("config:/sysdir", FM_READ); if (sysdir_cfg == 0) PANIC("[init] Could not read config:/sysdir"); char buf[256]; - size_t l = read(sysdir_cfg, 0, 255, buf); + size_t l = sc_read(sysdir_cfg, 0, 255, buf); buf[l] = 0; - close(sysdir_cfg); + sc_close(sysdir_cfg); char* eol = strchr(buf, '\n'); if (eol) *eol = 0; @@ -79,10 +81,10 @@ void setup_sys() { char* sep = strchr(buf, ':'); if (sep == 0) { - ok = fs_subfs("sys", "root", buf, FM_READ | FM_MMAP | FM_READDIR); + ok = sc_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 | FM_READDIR); + ok = sc_fs_subfs("sys", buf, sep +1, FM_READ | FM_MMAP | FM_READDIR); } if (!ok) PANIC("[init] Could not bind root:/sys to sys:/"); @@ -91,7 +93,7 @@ void setup_sys() { void launch_giosrv() { if (giosrv_pid != 0) return; - giosrv_pid = new_proc(); + giosrv_pid = sc_new_proc(); if (giosrv_pid == 0) { PANIC("[init] Could not create process for giosrv"); } @@ -100,19 +102,19 @@ void launch_giosrv() { bool ok; - ok = bind_fs(giosrv_pid, "io", "io"); + ok = sc_bind_fs(giosrv_pid, "io", "io"); if (!ok) PANIC("[init] Could not bind io:/ to giosrv"); - ok = bind_fs(giosrv_pid, "sys", "sys"); + ok = sc_bind_fs(giosrv_pid, "sys", "sys"); if (!ok) PANIC("[init] Could not bind sys:/ to giosrv"); - ok = bind_fs(giosrv_pid, "config", "config"); + ok = sc_bind_fs(giosrv_pid, "config", "config"); if (!ok) PANIC("[init] Could not bind config:/ to giosrv"); - ok = bind_fd(giosrv_pid, 1, root_gip_chan.a); + ok = sc_bind_fd(giosrv_pid, STD_FD_GIOSRV, root_gip_chan.a); if (!ok) PANIC("[init] Could not bind root GIP channel FD to giosrv"); - ok = proc_exec(giosrv_pid, "sys:/bin/giosrv.bin"); + ok = sc_proc_exec(giosrv_pid, "sys:/bin/giosrv.bin"); if (!ok) PANIC("[init] Could not run giosrv.bin"); dbg_printf("[init] giosrv started.\n"); @@ -121,7 +123,7 @@ void launch_giosrv() { void launch_login() { if (login_pid != 0) return; - login_pid = new_proc(); + login_pid = sc_new_proc(); if (login_pid == 0) { PANIC("[init] Could not create process for login"); } @@ -130,19 +132,19 @@ void launch_login() { bool ok; - ok = bind_fs(login_pid, "root", "root"); + ok = sc_bind_fs(login_pid, "root", "root"); if (!ok) PANIC("[init] Could not bind root:/ to login"); - ok = bind_fs(login_pid, "sys", "sys"); + ok = sc_bind_fs(login_pid, "sys", "sys"); if (!ok) PANIC("[init] Could not bind sys:/ to login"); - ok = bind_fs(login_pid, "config", "config"); + ok = sc_bind_fs(login_pid, "config", "config"); if (!ok) PANIC("[init] Could not bind config:/ to login"); - ok = bind_fd(login_pid, 1, root_gip_chan.b); + ok = sc_bind_fd(login_pid, STD_FD_GIP, root_gip_chan.b); if (!ok) PANIC("[init] Could not bind root GIP channel FD to login"); - ok = proc_exec(login_pid, "sys:/bin/login.bin"); + ok = sc_proc_exec(login_pid, "sys:/bin/login.bin"); if (!ok) PANIC("[init] Could not run login.bin"); dbg_printf("[init] login started.\n"); @@ -165,7 +167,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 | FM_READDIR); + bool ok = sc_fs_subfs("config", "root", buf, FM_READ | FM_WRITE | FM_MMAP | FM_READDIR); if (!ok) PANIC("[init] Could not setup config:"); } @@ -173,7 +175,7 @@ int main(int argc, char **argv) { setup_sys(); // Setup GIP channel for communication between giosrv and login - root_gip_chan = make_channel(false); + root_gip_chan = sc_make_channel(false); if (root_gip_chan.a == 0 || root_gip_chan.b == 0) { PANIC("[init] Could not create root GIP channel."); } @@ -185,7 +187,7 @@ int main(int argc, char **argv) { // Make sure no one dies while(true) { proc_status_t s; - proc_wait(0, false, &s); + sc_proc_wait(0, false, &s); if (s.pid != 0) { if (s.pid == giosrv_pid) { giosrv_pid = 0; @@ -201,7 +203,7 @@ int main(int argc, char **argv) { ASSERT(false); } } - usleep(1000000); + sc_usleep(1000000); } return 0; diff --git a/src/sysbin/linker.ld b/src/sysbin/linker.ld deleted file mode 100644 index 50bebbe..0000000 --- a/src/sysbin/linker.ld +++ /dev/null @@ -1,33 +0,0 @@ -ENTRY (__libkogata_start) - -SECTIONS{ - . = 0x100000; - - .text : { - *(.text) - } - - .rodata ALIGN (0x1000) :{ - *(.rodata) - } - - .data ALIGN (0x1000) : { - start_ctors = .; - *(.ctor*) - end_ctors = .; - start_dtors = .; - *(.dtor*) - end_dtors = .; - *(.data) - *(.locks) - } - - .bss : { - sbss = .; - *(COMMON) - *(.bss) - ebss = .; - } - - end = .; _end = .; __end = .; -} diff --git a/src/sysbin/login/main.c b/src/sysbin/login/main.c index c9d2455..c4cd260 100644 --- a/src/sysbin/login/main.c +++ b/src/sysbin/login/main.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdlib.h> +#include <proto/launch.h> + #include <kogata/debug.h> #include <kogata/syscall.h> @@ -8,42 +10,42 @@ int main(int argc, char **argv) { dbg_print("[login] Starting up.\n"); // communication channel between terminal && shell - fd_pair_t tc = make_channel(false); + fd_pair_t tc = sc_make_channel(false); // just launch a terminal - pid_t term_pid = new_proc(); + pid_t term_pid = sc_new_proc(); if (term_pid == 0) { PANIC("[login] Could not launch terminal"); } bool ok; - ok = bind_fs(term_pid, "sys", "sys") - && bind_fs(term_pid, "config", "config") - && bind_fd(term_pid, 1, 1) - && bind_fd(term_pid, 2, tc.a); + ok = sc_bind_fs(term_pid, "sys", "sys") + && sc_bind_fs(term_pid, "config", "config") + && sc_bind_fd(term_pid, STD_FD_GIP, STD_FD_GIP) + && sc_bind_fd(term_pid, STD_FD_TTYSRV, tc.a); if (!ok) PANIC("[login] Could not bind to terminal process."); - ok = proc_exec(term_pid, "sys:/bin/terminal.bin"); + ok = sc_proc_exec(term_pid, "sys:/bin/terminal.bin"); if (!ok) PANIC("[login] Could not run terminal.bin"); // and launch the shell - pid_t shell_pid = new_proc(); + pid_t shell_pid = sc_new_proc(); if (shell_pid == 0) { PANIC("[login] Could not launch shell"); } - ok = bind_fs(shell_pid, "root", "root") - && bind_fs(shell_pid, "sys", "sys") - && bind_fs(shell_pid, "config", "config") - && bind_fd(shell_pid, 1, tc.b); + ok = sc_bind_fs(shell_pid, "root", "root") + && sc_bind_fs(shell_pid, "sys", "sys") + && sc_bind_fs(shell_pid, "config", "config") + && sc_bind_fd(shell_pid, STD_FD_TTY_STDIO, tc.b); if (!ok) PANIC("[login] Could not bind to shell process."); - ok = proc_exec(shell_pid, "sys:/bin/shell.bin"); + ok = sc_proc_exec(shell_pid, "sys:/bin/shell.bin"); if (!ok) PANIC("[login] Could not run shell.bin"); proc_status_t s; - proc_wait(0, true, &s); + sc_proc_wait(0, true, &s); return 0; } diff --git a/src/sysbin/shell/main.c b/src/sysbin/shell/main.c index 81ecdfa..e27b4e9 100644 --- a/src/sysbin/shell/main.c +++ b/src/sysbin/shell/main.c @@ -4,38 +4,40 @@ #include <stdio.h> #include <unistd.h> +#include <readline/readline.h> + #include <kogata/debug.h> #include <kogata/syscall.h> void ls(char* dir) { - fd_t f = open(dir, FM_READDIR); + fd_t f = sc_open(dir, FM_READDIR); if (f) { dirent_t i; int ent_no = 0; - while (readdir(f, ent_no++, &i)) { + while (sc_readdir(f, ent_no++, &i)) { if (i.st.type & FT_DIR) printf("%s/\n", i.name); else printf("%s\n", i.name); } - close(f); + sc_close(f); } else { printf("Could not open directory '%s'\n", dir); } } void cat(char* file) { - fd_t f = open(file, FM_READ); + fd_t f = sc_open(file, FM_READ); if (f) { char buf[129]; size_t p = 0; while (true) { - size_t r = read(f, p, 128, buf); + size_t r = sc_read(f, p, 128, buf); p += r; - write(stdio, 0, r, buf); + fwrite(buf, r, 1, stdout); if (r < 128) break; } - close(f); + sc_close(f); } else { printf("Could not open file '%s'\n", file); } @@ -44,17 +46,18 @@ void cat(char* file) { int main(int argc, char **argv) { dbg_printf("[shell] Starting\n"); - fctl(stdio, FC_SET_BLOCKING, 0); - puts("Kogata shell.\n"); chdir("sys:"); while(true) { - char buf[256]; - printf("\n\e[36m%s>\e[33m ", getcwd(buf, 256)); + char prompt[256]; + char cwdbuf[256]; + snprintf(prompt, 256, "\n\e[36m%s>\e[33m ", getcwd(cwdbuf, 256)); - getline(buf, 256); + char *buf = readline(prompt); + if (buf == NULL) continue; + add_history(buf); printf("\e[39m"); if (!strncmp(buf, "cd ", 3)) { @@ -82,6 +85,8 @@ int main(int argc, char **argv) { } else { printf("No such command.\n"); } + + free(buf); } printf("Bye.\n"); diff --git a/src/sysbin/terminal/main.c b/src/sysbin/terminal/main.c index fe2376f..d6d0fe4 100644 --- a/src/sysbin/terminal/main.c +++ b/src/sysbin/terminal/main.c @@ -1,6 +1,8 @@ #include <string.h> #include <stdlib.h> +#include <proto/launch.h> + #include <kogata/region_alloc.h> #include <kogata/debug.h> @@ -107,11 +109,11 @@ int main(int argc, char **argv) { gip_handler_t *h = new_gip_handler(&term_gip_cb, &term); ASSERT(h != 0); - h->mainloop_item.fd = 1; + h->mainloop_item.fd = STD_FD_GIP; mainloop_add_fd(&h->mainloop_item); // setup communication with app - term.app.fd = 2; + term.app.fd = STD_FD_TTYSRV; term.app.on_error = term_app_on_error; term.app.data = &term; mainloop_expect(&term.app, &term.rd_c_buf, 1, term_on_rd_c); @@ -262,9 +264,6 @@ void term_putc(term_t *t, int c) { } else if (c == '\b') { if (nc > 0) { nc--; - } else { - nl--; - nc = t->w - 1; } term_put_at(t, nl, nc, ' '); } else if (c == '\t') { @@ -307,11 +306,11 @@ void gip_buffer_info(gip_handler_t *s, gip_msg_header *p, gip_buffer_info_msg *m c->fb = 0; } if (c->fd != 0) { - close(c->fd); + sc_close(c->fd); c->fd = 0; } - c->fd = use_token(&m->tok); + c->fd = sc_use_token(&m->tok); if (c->fd != 0) { memcpy(&c->mode, &m->geom, sizeof(fb_info_t)); @@ -361,7 +360,10 @@ void gip_key_down(gip_handler_t *s, gip_msg_header *p) { if (k.key == KBD_CODE_TAB) c->wr_c_buf = '\t'; if (k.key == KBD_CODE_BKSP) c->wr_c_buf = '\b'; } - mainloop_nonblocking_write(&c->app, &c->wr_c_buf, 1, false); + if (c->wr_c_buf != 0) { + term_putc(c, c->wr_c_buf); + mainloop_nonblocking_write(&c->app, &c->wr_c_buf, 1, false); + } } void gip_key_up(gip_handler_t *s, gip_msg_header *p) { |