aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2016-07-16 15:59:46 +0200
committerAlex Auvolat <alex@adnab.me>2016-07-16 15:59:46 +0200
commit3d6a857b9186ef6304ea6cf04627c2b787169f29 (patch)
tree756179ce1e1838f75c57e3efec2a570d72051594 /src
parent59000174aa50ed6b2d24a71576d15e6a53c5be0c (diff)
downloadkogata-3d6a857b9186ef6304ea6cf04627c2b787169f29.tar.gz
kogata-3d6a857b9186ef6304ea6cf04627c2b787169f29.zip
Make way for libc implementation
Diffstat (limited to 'src')
-rw-r--r--src/bin/bam.lua2
-rw-r--r--src/common/include/proto/launch.h26
-rw-r--r--src/lib/include/assert.h3
-rw-r--r--src/lib/include/kogata/syscall.h92
-rw-r--r--src/lib/include/readline/history.h5
-rw-r--r--src/lib/include/readline/readline.h6
-rw-r--r--src/lib/include/setjmp.h2
-rw-r--r--src/lib/include/stdio.h11
-rw-r--r--src/lib/include/stdlib.h7
-rw-r--r--src/lib/libc/debug.c23
-rw-r--r--src/lib/libc/malloc.c6
-rw-r--r--src/lib/libc/readline.c49
-rw-r--r--src/lib/libc/start.c10
-rw-r--r--src/lib/libc/stdio.c57
-rw-r--r--src/lib/libc/stdlib.c6
-rw-r--r--src/lib/libc/syscall.c174
-rw-r--r--src/lib/libc/unistd.c2
-rw-r--r--src/lib/libkogata/draw.c12
-rw-r--r--src/lib/libkogata/keyboard.c6
-rw-r--r--src/lib/libkogata/mainloop.c6
-rw-r--r--src/lib/linker.ld (renamed from src/sysbin/linker.ld)2
-rw-r--r--src/sysbin/bam.lua2
-rw-r--r--src/sysbin/giosrv/main.c11
-rw-r--r--src/sysbin/init/main.c50
-rw-r--r--src/sysbin/login/main.c30
-rw-r--r--src/sysbin/shell/main.c29
-rw-r--r--src/sysbin/terminal/main.c18
27 files changed, 370 insertions, 277 deletions
diff --git a/src/bin/bam.lua b/src/bin/bam.lua
index 15cfb40..76b7b2a 100644
--- a/src/bin/bam.lua
+++ b/src/bin/bam.lua
@@ -1,6 +1,6 @@
local function bin_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/bin/" .. name .. ".map")
if name == 'lua' or name == 'luac' then
s.cc.includes:Add("src/lib/lua")
diff --git a/src/common/include/proto/launch.h b/src/common/include/proto/launch.h
new file mode 100644
index 0000000..3192f82
--- /dev/null
+++ b/src/common/include/proto/launch.h
@@ -0,0 +1,26 @@
+#pragma once
+
+// Standard file descriptor numbers
+// If these FDs are mapped when a process is launched, a specific role for them is assumed
+
+// {{ Automatically causes libc stdio initialization
+
+// tty_stdio : assume we have a terminal window for keyboard I/O
+#define STD_FD_TTY_STDIO 1
+
+// if stdin is mapped, we assume no terminal window
+#define STD_FD_STDIN 2
+#define STD_FD_STDOUT 3
+#define STD_FD_STDERR 4
+
+// }}
+
+
+#define STD_FD_GIP 5 // graphics initiation protocol, i.e. GUI window
+
+// For system services
+#define STD_FD_GIOSRV 10
+
+#define STD_FD_TTYSRV 11
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/assert.h b/src/lib/include/assert.h
index af02bb5..655d6f6 100644
--- a/src/lib/include/assert.h
+++ b/src/lib/include/assert.h
@@ -1,6 +1,5 @@
#pragma once
-// TODO
-
+#include <kogata/debug.h>
/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/kogata/syscall.h b/src/lib/include/kogata/syscall.h
index 378dda2..8ae5325 100644
--- a/src/lib/include/kogata/syscall.h
+++ b/src/lib/include/kogata/syscall.h
@@ -13,51 +13,51 @@
typedef void (*entry_t)(void*);
-void dbg_print(const char* str);
-void yield();
-void exit(int code);
-void usleep(int usecs);
-bool sys_new_thread(void* eip, void* esp);
-void exit_thread();
-
-bool mmap(void* addr, size_t size, int mode);
-bool mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode);
-bool mchmap(void* addr, int mode);
-bool munmap(void* addr);
-
-bool create(const char* name, int type);
-bool delete(const char* name);
-bool move(const char* oldname, const char* newname);
-bool stat(const char* name, stat_t *s);
-
-fd_t open(const char* name, int mode);
-void close(fd_t file);
-size_t read(fd_t file, size_t offset, size_t len, char *buf);
-size_t write(fd_t file, size_t offset, size_t len, const char* buf);
-bool readdir(fd_t file, size_t ent_no, dirent_t *d);
-bool stat_open(fd_t file, stat_t *s);
-int ioctl(fd_t file, int command, void* data);
-int fctl(fd_t file, int command, void* data);
-bool select(sel_fd_t* fds, size_t nfds, int timeout);
-
-fd_pair_t make_channel(bool blocking);
-fd_t make_shm(size_t size);
-bool gen_token(fd_t file, token_t *tok);
-fd_t use_token(token_t *tok);
-
-bool make_fs(const char* name, const char* driver, fd_t source, const char* options);
-bool fs_add_source(const char* fs, fd_t source, const char* options);
-bool fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_modes);
-void fs_remove(const char* name);
-
-pid_t new_proc();
-bool bind_fs(pid_t pid, const char* new_name, const char* fs);
-bool bind_subfs(pid_t pid, const char* new_name, const char* fs, const char* root, int ok_modes);
-bool bind_make_fs(pid_t pid, const char* name, const char* driver, fd_t source, const char* options);
-bool bind_fd(pid_t pid, fd_t new_fd, fd_t fd);
-bool proc_exec(pid_t pid, const char* file);
-bool proc_status(pid_t pid, proc_status_t *s);
-bool proc_kill(pid_t pid, proc_status_t *s);
-void proc_wait(pid_t pid, bool wait, proc_status_t *s);
+void sc_dbg_print(const char* str);
+void sc_yield();
+void sc_exit(int code);
+void sc_usleep(int usecs);
+bool sc_sys_new_thread(void* eip, void* esp);
+void sc_exit_thread();
+
+bool sc_mmap(void* addr, size_t size, int mode);
+bool sc_mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode);
+bool sc_mchmap(void* addr, int mode);
+bool sc_munmap(void* addr);
+
+bool sc_create(const char* name, int type);
+bool sc_delete(const char* name);
+bool sc_move(const char* oldname, const char* newname);
+bool sc_stat(const char* name, stat_t *s);
+
+fd_t sc_open(const char* name, int mode);
+void sc_close(fd_t file);
+size_t sc_read(fd_t file, size_t offset, size_t len, char *buf);
+size_t sc_write(fd_t file, size_t offset, size_t len, const char* buf);
+bool sc_readdir(fd_t file, size_t ent_no, dirent_t *d);
+bool sc_stat_open(fd_t file, stat_t *s);
+int sc_ioctl(fd_t file, int command, void* data);
+int sc_fctl(fd_t file, int command, void* data);
+bool sc_select(sel_fd_t* fds, size_t nfds, int timeout);
+
+fd_pair_t sc_make_channel(bool blocking);
+fd_t sc_make_shm(size_t size);
+bool sc_gen_token(fd_t file, token_t *tok);
+fd_t sc_use_token(token_t *tok);
+
+bool sc_make_fs(const char* name, const char* driver, fd_t source, const char* options);
+bool sc_fs_add_source(const char* fs, fd_t source, const char* options);
+bool sc_fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_modes);
+void sc_fs_remove(const char* name);
+
+pid_t sc_new_proc();
+bool sc_bind_fs(pid_t pid, const char* new_name, const char* fs);
+bool sc_bind_subfs(pid_t pid, const char* new_name, const char* fs, const char* root, int ok_modes);
+bool sc_bind_make_fs(pid_t pid, const char* name, const char* driver, fd_t source, const char* options);
+bool sc_bind_fd(pid_t pid, fd_t new_fd, fd_t fd);
+bool sc_proc_exec(pid_t pid, const char* file);
+bool sc_proc_status(pid_t pid, proc_status_t *s);
+bool sc_proc_kill(pid_t pid, proc_status_t *s);
+void sc_proc_wait(pid_t pid, bool wait, proc_status_t *s);
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/readline/history.h b/src/lib/include/readline/history.h
new file mode 100644
index 0000000..3b98ca2
--- /dev/null
+++ b/src/lib/include/readline/history.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "readline.h"
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/readline/readline.h b/src/lib/include/readline/readline.h
new file mode 100644
index 0000000..ae3e05c
--- /dev/null
+++ b/src/lib/include/readline/readline.h
@@ -0,0 +1,6 @@
+#pragma once
+
+char* readline(const char* prompt);
+void add_history(const char* line);
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/setjmp.h b/src/lib/include/setjmp.h
index 42df49e..46c3b5d 100644
--- a/src/lib/include/setjmp.h
+++ b/src/lib/include/setjmp.h
@@ -1,6 +1,6 @@
#pragma once
-// TODO
+#include <stdint.h>
struct _jmp_buf {
uint32_t stuff[10]; // 40 bytes
diff --git a/src/lib/include/stdio.h b/src/lib/include/stdio.h
index 3914a89..c6b636d 100644
--- a/src/lib/include/stdio.h
+++ b/src/lib/include/stdio.h
@@ -2,17 +2,16 @@
#include <stdarg.h>
-#include <kogata/syscall.h>
+#include <kogata/printf.h>
-extern fd_t stdio;
+#include <kogata/syscall.h>
-// CUSTOM!
-void getline(char* buf, size_t l);
+void setup_libc_stdio();
//TODO below
struct file_t {
- fd_t fd;
+ // TODO
};
typedef struct file_t FILE;
@@ -78,12 +77,10 @@ int rename(const char *old, const char *new);
int remove(const char *pathname);
-
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int dprintf(int fd, const char *format, ...);
int sprintf(char *str, const char *format, ...);
-int snprintf(char *str, size_t size, const char *format, ...);
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/include/stdlib.h b/src/lib/include/stdlib.h
index 53aef80..e451c52 100644
--- a/src/lib/include/stdlib.h
+++ b/src/lib/include/stdlib.h
@@ -1,10 +1,13 @@
#pragma once
#include <kogata/malloc.h>
+#include <kogata/syscall.h>
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 255
+#define exit sc_exit
+
int rand(void);
//int rand_r(unsigned int *seedp);
void srand(unsigned int seed);
@@ -14,8 +17,8 @@ void srand(unsigned int seed);
void abort() __attribute__((__noreturn__));
-double strtod(const char *nptr, const char **endptr);
-float strtof(const char *nptr, const char **endptr);
+double strtod(const char *nptr, char **endptr);
+float strtof(const char *nptr, char **endptr);
char *getenv(const char *name);
diff --git a/src/lib/libc/debug.c b/src/lib/libc/debug.c
index dc04fd3..f862fe6 100644
--- a/src/lib/libc/debug.c
+++ b/src/lib/libc/debug.c
@@ -1,7 +1,9 @@
#include <stdbool.h>
+#include <stdlib.h>
-#include <kogata/debug.h>
#include <kogata/syscall.h>
+#include <kogata/debug.h>
+#include <kogata/printf.h>
void sys_panic(const char* msg, const char* file, int line) {
dbg_printf("PANIC in user process\n %s\n at %s:%d\n", msg, file, line);
@@ -15,4 +17,23 @@ void sys_panic_assert(const char* assert, const char* file, int line) {
while(true);
}
+void dbg_print(const char* s) {
+ sc_dbg_print(s);
+}
+
+void dbg_printf(const char* fmt, ...) {
+ va_list ap;
+ char buffer[256];
+
+ va_start(ap, fmt);
+ vsnprintf(buffer, 256, fmt, ap);
+ va_end(ap);
+
+ dbg_print(buffer);
+}
+
+void yield() {
+ sc_yield();
+}
+
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/malloc.c b/src/lib/libc/malloc.c
index 2d43656..473404b 100644
--- a/src/lib/libc/malloc.c
+++ b/src/lib/libc/malloc.c
@@ -10,7 +10,7 @@ static void* heap_alloc_pages(size_t s) {
void* addr = region_alloc(s, "Heap");
if (addr == 0) return 0;
- bool map_ok = mmap(addr, s, FM_READ | FM_WRITE);
+ bool map_ok = sc_mmap(addr, s, FM_READ | FM_WRITE);
if (!map_ok) {
region_free(addr);
return 0;
@@ -20,7 +20,7 @@ static void* heap_alloc_pages(size_t s) {
}
static void heap_free_pages(void* addr) {
- munmap(addr);
+ sc_munmap(addr);
region_free(addr);
}
@@ -40,7 +40,7 @@ static slab_type_t slab_sizes[] = {
};
bool mmap_single_page(void* addr) {
- return mmap(addr, PAGE_SIZE, MM_READ | MM_WRITE);
+ return sc_mmap(addr, PAGE_SIZE, MM_READ | MM_WRITE);
}
void malloc_setup() {
diff --git a/src/lib/libc/readline.c b/src/lib/libc/readline.c
new file mode 100644
index 0000000..20c2007
--- /dev/null
+++ b/src/lib/libc/readline.c
@@ -0,0 +1,49 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <readline/readline.h>
+
+// ** READLINE
+
+#define READLINE_MAX_LEN 256
+
+typedef struct _rdln_hist {
+ int max;
+ int n;
+ char **str;
+} readline_history;
+
+readline_history stdio_history = {0, 0, 0};
+
+
+char *readline(const char* prompt) {
+ // readline_history *h = &stdio_history;
+
+ puts(prompt);
+
+ char* buf = malloc(READLINE_MAX_LEN);
+ if (buf == NULL) return NULL;
+
+ char* ret = fgets(buf, READLINE_MAX_LEN, stdin);
+ if (ret == NULL) {
+ free(buf);
+ return NULL;
+ }
+
+ int n = strlen(ret);
+ if (n > 0 && ret[n-1] == '\n') ret[n-1] = 0;
+
+ // TODO
+
+ return ret;
+}
+
+void add_history(const char* line) {
+ // readline_history *h = &stdio_history;
+
+ // TODO
+}
+
+
+/* vim: set sts=0 ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/start.c b/src/lib/libc/start.c
index 49a6ca1..185d90f 100644
--- a/src/lib/libc/start.c
+++ b/src/lib/libc/start.c
@@ -1,17 +1,21 @@
#include <kogata/syscall.h>
+#include <stdio.h>
+
void malloc_setup();
int main(int, char**);
-void __libkogata_start() {
+void __libc_start() {
malloc_setup();
- // TODO : more setup ?
+ setup_libc_stdio();
+
+ // TODO : more setup ? yes, for args, for env...
int ret = main(0, 0);
- exit(ret);
+ sc_exit(ret);
}
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/stdio.c b/src/lib/libc/stdio.c
index bd6c35b..8d4577e 100644
--- a/src/lib/libc/stdio.c
+++ b/src/lib/libc/stdio.c
@@ -1,52 +1,38 @@
#include <string.h>
#include <stdio.h>
+#include <proto/launch.h>
+
#include <kogata/syscall.h>
#include <kogata/printf.h>
+FILE *stdin = 0;
+FILE *stdout = 0;
+FILE *stderr = 0;
-fd_t stdio = 1;
+void setup_libc_stdio() {
+ fd_t tty_io = STD_FD_TTY_STDIO;
+ // fd_t tty_in = STD_FD_STDIN;
+ // fd_t tty_out = STD_FD_STDOUT;
+ // fd_t tty_err = STD_FD_STDERR;
-int getchar() {
- char chr;
- size_t sz = read(stdio, 0, 1, &chr);
- ASSERT(sz == 1);
- return chr;
+ // TODO
+ if (true) {
+ sc_fctl(tty_io, FC_SET_BLOCKING, 0);
+ }
}
+int getchar() {
+ return fgetc(stdin);
+}
+
int putchar(int c) {
- char chr = c;
- write(stdio, 0, 1, &chr);
- return 0; //TODO what?
+ return fputc(c, stdout);
}
int puts(const char* s) {
- // TODO return EOF on error
- return write(stdio, 0, strlen(s), s);
-}
-
-void getline(char* buf, size_t l) {
- size_t i = 0;
- while (true) {
- int c = getchar();
- if (c == '\n') {
- putchar('\n');
- buf[i] = 0;
- break;
- } else if (c == '\b') {
- if (i > 0) {
- i--;
- putchar('\b');
- }
- } else if (c >= ' ') {
- buf[i] = c;
- if (i < l-1) {
- i++;
- putchar(c);
- }
- }
- }
+ return fputs(s, stdout);
}
int printf(const char* fmt, ...) {
@@ -139,9 +125,6 @@ int fclose(FILE* f) {
return 0;
}
-FILE *stdin = 0;
-FILE *stdout = 0;
-FILE *stderr = 0;
void setbuf(FILE *stream, char *buf) {
// TODO
diff --git a/src/lib/libc/stdlib.c b/src/lib/libc/stdlib.c
index d8598dd..540d53c 100644
--- a/src/lib/libc/stdlib.c
+++ b/src/lib/libc/stdlib.c
@@ -15,10 +15,10 @@ void abort() {
PANIC("Aborted.");
}
-float strtof(const char *nptr, const char **endptr) {
+float strtof(const char *nptr, char **endptr) {
return (float)strtod(nptr, endptr);
}
-double strtod(const char *nptr, const char **endptr) {
+double strtod(const char *nptr, char **endptr) {
// TODO: better (inf, nan, ...)
const char* p = nptr;
@@ -57,7 +57,7 @@ double strtod(const char *nptr, const char **endptr) {
for (int i = 0; i < exp; i++) val /= 10;
}
}
- if (endptr != NULL) *endptr = p-1;
+ if (endptr != NULL) *endptr = (char*)(p-1);
return val * sign;
}
diff --git a/src/lib/libc/syscall.c b/src/lib/libc/syscall.c
index 61b3471..83708da 100644
--- a/src/lib/libc/syscall.c
+++ b/src/lib/libc/syscall.c
@@ -5,7 +5,7 @@
#include <string.h>
-static inline uint32_t call(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t ss, uint32_t dd) {
+static inline uint32_t sc_docall(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t ss, uint32_t dd) {
uint32_t ret;
asm volatile("int $0x40"
:"=a"(ret)
@@ -13,111 +13,101 @@ static inline uint32_t call(uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint
return ret;
}
-void dbg_print(const char* str) {
- call(SC_DBG_PRINT, (uint32_t)str, strlen(str), 0, 0, 0);
+void sc_dbg_print(const char* str) {
+ sc_docall(SC_DBG_PRINT, (uint32_t)str, strlen(str), 0, 0, 0);
}
-void dbg_printf(const char* fmt, ...) {
- va_list ap;
- char buffer[256];
- va_start(ap, fmt);
- vsnprintf(buffer, 256, fmt, ap);
- va_end(ap);
-
- dbg_print(buffer);
-}
-
-void yield() {
- call(SC_YIELD, 0, 0, 0, 0, 0);
+void sc_yield() {
+ sc_docall(SC_YIELD, 0, 0, 0, 0, 0);
}
-void exit(int code) {
- call(SC_EXIT, code, 0, 0, 0, 0);
+void sc_exit(int code) {
+ sc_docall(SC_EXIT, code, 0, 0, 0, 0);
}
-void usleep(int usecs) {
- call(SC_USLEEP, usecs, 0, 0, 0, 0);
+void sc_usleep(int usecs) {
+ sc_docall(SC_USLEEP, usecs, 0, 0, 0, 0);
}
-bool sys_new_thread(void* eip, void* esp) {
- return call(SC_NEW_THREAD, (uint32_t)eip, (uint32_t)esp, 0, 0, 0);
+bool sc_sys_new_thread(void* eip, void* esp) {
+ return sc_docall(SC_NEW_THREAD, (uint32_t)eip, (uint32_t)esp, 0, 0, 0);
}
-void exit_thread() {
- call(SC_EXIT_THREAD, 0, 0, 0, 0, 0);
+void sc_exit_thread() {
+ sc_docall(SC_EXIT_THREAD, 0, 0, 0, 0, 0);
}
-bool mmap(void* addr, size_t size, int mode) {
- return call(SC_MMAP, (uint32_t)addr, size, mode, 0, 0);
+bool sc_mmap(void* addr, size_t size, int mode) {
+ return sc_docall(SC_MMAP, (uint32_t)addr, size, mode, 0, 0);
}
-bool mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode) {
- return call(SC_MMAP_FILE, file, offset, (uint32_t)addr, size, mode);
+bool sc_mmap_file(fd_t file, size_t offset, void* addr, size_t size, int mode) {
+ return sc_docall(SC_MMAP_FILE, file, offset, (uint32_t)addr, size, mode);
}
-bool mchmap(void* addr, int mode) {
- return call(SC_MCHMAP, (uint32_t)addr, mode, 0, 0, 0);
+bool sc_mchmap(void* addr, int mode) {
+ return sc_docall(SC_MCHMAP, (uint32_t)addr, mode, 0, 0, 0);
}
-bool munmap(void* addr) {
- return call(SC_MUNMAP, (uint32_t)addr, 0, 0, 0, 0);
+bool sc_munmap(void* addr) {
+ return sc_docall(SC_MUNMAP, (uint32_t)addr, 0, 0, 0, 0);
}
-bool create(const char* name, int type) {
- return call(SC_CREATE, (uint32_t)name, strlen(name), type, 0, 0);
+bool sc_create(const char* name, int type) {
+ return sc_docall(SC_CREATE, (uint32_t)name, strlen(name), type, 0, 0);
}
-bool delete(const char* name) {
- return call(SC_CREATE, (uint32_t)name, strlen(name), 0, 0, 0);
+bool sc_delete(const char* name) {
+ return sc_docall(SC_CREATE, (uint32_t)name, strlen(name), 0, 0, 0);
}
-bool move(const char* oldname, const char* newname) {
- return call(SC_MOVE, (uint32_t)oldname, strlen(oldname), (uint32_t)newname, strlen(newname), 0);
+bool sc_move(const char* oldname, const char* newname) {
+ return sc_docall(SC_MOVE, (uint32_t)oldname, strlen(oldname), (uint32_t)newname, strlen(newname), 0);
}
-bool stat(const char* name, stat_t *s) {
- return call(SC_STAT, (uint32_t)name, strlen(name), (uint32_t)s, 0, 0);
+bool sc_stat(const char* name, stat_t *s) {
+ return sc_docall(SC_STAT, (uint32_t)name, strlen(name), (uint32_t)s, 0, 0);
}
-fd_t open(const char* name, int mode) {
- return call(SC_OPEN, (uint32_t)name, strlen(name), mode, 0, 0);
+fd_t sc_open(const char* name, int mode) {
+ return sc_docall(SC_OPEN, (uint32_t)name, strlen(name), mode, 0, 0);
}
-void close(fd_t file) {
- call(SC_CLOSE, file, 0, 0, 0, 0);
+void sc_close(fd_t file) {
+ sc_docall(SC_CLOSE, file, 0, 0, 0, 0);
}
-size_t read(fd_t file, size_t offset, size_t len, char *buf) {
- return call(SC_READ, file, offset, len, (uint32_t)buf, 0);
+size_t sc_read(fd_t file, size_t offset, size_t len, char *buf) {
+ return sc_docall(SC_READ, file, offset, len, (uint32_t)buf, 0);
}
-size_t write(fd_t file, size_t offset, size_t len, const char* buf) {
- return call(SC_WRITE, file, offset, len, (uint32_t)buf, 0);
+size_t sc_write(fd_t file, size_t offset, size_t len, const char* buf) {
+ return sc_docall(SC_WRITE, file, offset, len, (uint32_t)buf, 0);
}
-bool readdir(fd_t file, size_t ent_no, dirent_t *d) {
- return call(SC_READDIR, file, ent_no, (uint32_t)d, 0, 0);
+bool sc_readdir(fd_t file, size_t ent_no, dirent_t *d) {
+ return sc_docall(SC_READDIR, file, ent_no, (uint32_t)d, 0, 0);
}
-bool stat_open(fd_t file, stat_t *s) {
- return call(SC_STAT_OPEN, file, (uint32_t)s, 0, 0, 0);
+bool sc_stat_open(fd_t file, stat_t *s) {
+ return sc_docall(SC_STAT_OPEN, file, (uint32_t)s, 0, 0, 0);
}
-int ioctl(fd_t file, int command, void* data) {
- return call(SC_IOCTL, file, command, (uint32_t)data, 0, 0);
+int sc_ioctl(fd_t file, int command, void* data) {
+ return sc_docall(SC_IOCTL, file, command, (uint32_t)data, 0, 0);
}
-int fctl(fd_t file, int command, void *data) {
- return call(SC_FCTL, file, command, (uint32_t)data, 0, 0);
+int sc_fctl(fd_t file, int command, void *data) {
+ return sc_docall(SC_FCTL, file, command, (uint32_t)data, 0, 0);
}
-bool select(sel_fd_t* fds, size_t nfds, int timeout) {
- return call(SC_SELECT, (uint32_t)fds, nfds, timeout, 0, 0);
+bool sc_select(sel_fd_t* fds, size_t nfds, int timeout) {
+ return sc_docall(SC_SELECT, (uint32_t)fds, nfds, timeout, 0, 0);
}
-fd_pair_t make_channel(bool blocking) {
+fd_pair_t sc_make_channel(bool blocking) {
fd_pair_t ret;
- call(SC_MK_CHANNEL, blocking, (uint32_t)&ret, 0, 0, 0);
+ sc_docall(SC_MK_CHANNEL, blocking, (uint32_t)&ret, 0, 0, 0);
return ret;
}
-fd_t make_shm(size_t s) {
- return call(SC_MK_SHM, s, 0, 0, 0, 0);
+fd_t sc_make_shm(size_t s) {
+ return sc_docall(SC_MK_SHM, s, 0, 0, 0, 0);
}
-bool gen_token(fd_t file, token_t *tok) {
- return call(SC_GEN_TOKEN, file, (uint32_t)tok, 0, 0, 0);
+bool sc_gen_token(fd_t file, token_t *tok) {
+ return sc_docall(SC_GEN_TOKEN, file, (uint32_t)tok, 0, 0, 0);
}
-fd_t use_token(token_t *tok) {
- return call(SC_USE_TOKEN, (uint32_t)tok, 0, 0, 0, 0);
+fd_t sc_use_token(token_t *tok) {
+ return sc_docall(SC_USE_TOKEN, (uint32_t)tok, 0, 0, 0, 0);
}
-bool make_fs(const char* name, const char* driver, fd_t source, const char* options) {
+bool sc_make_fs(const char* name, const char* driver, fd_t source, const char* options) {
volatile sc_make_fs_args_t args = {
.driver = driver,
.driver_strlen = strlen(driver),
@@ -128,12 +118,12 @@ bool make_fs(const char* name, const char* driver, fd_t source, const char* opti
.opts_strlen = strlen(options),
.bind_to_pid = 0,
};
- return call(SC_MAKE_FS, (uint32_t)&args, 0, 0, 0, 0);
+ return sc_docall(SC_MAKE_FS, (uint32_t)&args, 0, 0, 0, 0);
}
-bool fs_add_source(const char* fs, fd_t source, const char* options) {
- return call(SC_FS_ADD_SRC, (uint32_t)fs, strlen(fs), source, (uint32_t)options, strlen(options));
+bool sc_fs_add_source(const char* fs, fd_t source, const char* options) {
+ return sc_docall(SC_FS_ADD_SRC, (uint32_t)fs, strlen(fs), source, (uint32_t)options, strlen(options));
}
-bool fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_modes) {
+bool sc_fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_modes) {
volatile sc_subfs_args_t args = {
.new_name = name,
.new_name_strlen = strlen(name),
@@ -144,19 +134,19 @@ bool fs_subfs(const char* name, const char* orig_fs, const char* root, int ok_mo
.ok_modes = ok_modes,
.bind_to_pid = 0
};
- return call(SC_SUBFS, (uint32_t)(&args), 0, 0, 0, 0);
+ return sc_docall(SC_SUBFS, (uint32_t)(&args), 0, 0, 0, 0);
}
-void fs_remove(const char* name) {
- call(SC_RM_FS, (uint32_t)name, strlen(name), 0, 0, 0);
+void sc_fs_remove(const char* name) {
+ sc_docall(SC_RM_FS, (uint32_t)name, strlen(name), 0, 0, 0);
}
-pid_t new_proc() {
- return call(SC_NEW_PROC, 0, 0, 0, 0, 0);
+pid_t sc_new_proc() {
+ return sc_docall(SC_NEW_PROC, 0, 0, 0, 0, 0);
}
-bool bind_fs(pid_t pid, const char* new_name, const char* fs) {
- return call(SC_BIND_FS, pid, (uint32_t)new_name, strlen(new_name), (uint32_t)fs, strlen(fs));
+bool sc_bind_fs(pid_t pid, const char* new_name, const char* fs) {
+ return sc_docall(SC_BIND_FS, pid, (uint32_t)new_name, strlen(new_name), (uint32_t)fs, strlen(fs));
}
-bool bind_subfs(pid_t pid, const char* new_name, const char* orig_fs, const char* root, int ok_modes) {
+bool sc_bind_subfs(pid_t pid, const char* new_name, const char* orig_fs, const char* root, int ok_modes) {
sc_subfs_args_t args = {
.new_name = new_name,
.new_name_strlen = strlen(new_name),
@@ -167,9 +157,9 @@ bool bind_subfs(pid_t pid, const char* new_name, const char* orig_fs, const char
.ok_modes = ok_modes,
.bind_to_pid = pid
};
- return call(SC_BIND_SUBFS, (uint32_t)&args, 0, 0, 0, 0);
+ return sc_docall(SC_BIND_SUBFS, (uint32_t)&args, 0, 0, 0, 0);
}
-bool bind_make_fs(pid_t pid, const char* name, const char* driver, fd_t source, const char* options) {
+bool sc_bind_make_fs(pid_t pid, const char* name, const char* driver, fd_t source, const char* options) {
sc_make_fs_args_t args = {
.driver = driver,
.driver_strlen = strlen(driver),
@@ -180,25 +170,23 @@ bool bind_make_fs(pid_t pid, const char* name, const char* driver, fd_t source,
.opts_strlen = strlen(options),
.bind_to_pid = pid,
};
- return call(SC_BIND_MAKE_FS, (uint32_t)&args, 0, 0, 0, 0);
+ return sc_docall(SC_BIND_MAKE_FS, (uint32_t)&args, 0, 0, 0, 0);
}
-bool bind_fd(pid_t pid, fd_t new_fd, fd_t fd) {
- return call(SC_BIND_FD, pid, new_fd, fd, 0, 0);
+bool sc_bind_fd(pid_t pid, fd_t new_fd, fd_t fd) {
+ return sc_docall(SC_BIND_FD, pid, new_fd, fd, 0, 0);
}
-bool proc_exec(pid_t pid, const char* file) {
- return call(SC_PROC_EXEC, pid, (uint32_t)file, strlen(file), 0, 0);
+bool sc_proc_exec(pid_t pid, const char* file) {
+ return sc_docall(SC_PROC_EXEC, pid, (uint32_t)file, strlen(file), 0, 0);
}
-bool proc_status(pid_t pid, proc_status_t *s) {
- return call(SC_PROC_STATUS, pid, (uint32_t)s, 0, 0, 0);
+bool sc_proc_status(pid_t pid, proc_status_t *s) {
+ return sc_docall(SC_PROC_STATUS, pid, (uint32_t)s, 0, 0, 0);
}
-bool proc_kill(pid_t pid, proc_status_t *s) {
- return call(SC_PROC_KILL, pid, (uint32_t)s, 0, 0, 0);
+bool sc_proc_kill(pid_t pid, proc_status_t *s) {
+ return sc_docall(SC_PROC_KILL, pid, (uint32_t)s, 0, 0, 0);
}
-void proc_wait(pid_t pid, bool block, proc_status_t *s) {
- call(SC_PROC_WAIT, pid, block, (uint32_t)s, 0, 0);
+void sc_proc_wait(pid_t pid, bool block, proc_status_t *s) {
+ sc_docall(SC_PROC_WAIT, pid, block, (uint32_t)s, 0, 0);
}
-
-
/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/lib/libc/unistd.c b/src/lib/libc/unistd.c
index 5ae1735..f5a7a3c 100644
--- a/src/lib/libc/unistd.c
+++ b/src/lib/libc/unistd.c
@@ -22,7 +22,7 @@ int chdir(const char* path) {
if (!pathncat(cwd_buf2, path, 256)) return -1;
stat_t st;
- if (!stat(cwd_buf2, &st)) return -1;
+ if (!sc_stat(cwd_buf2, &st)) return -1;
if (!(st.type & FT_DIR)) return -1;
strcpy(cwd_buf, cwd_buf2);
diff --git a/src/lib/libkogata/draw.c b/src/lib/libkogata/draw.c
index d988cb9..6aa3387 100644
--- a/src/lib/libkogata/draw.c
+++ b/src/lib/libkogata/draw.c
@@ -19,7 +19,7 @@ fb_t *g_fb_from_file(fd_t file, fb_info_t *geom) {
ret->data = (uint8_t*)region_alloc(geom->height * geom->pitch, "Framebuffer");
if (ret->data == 0) goto error;
- bool map_ok = mmap_file(file, 0, ret->data, geom->height * geom->pitch, MM_READ | MM_WRITE);
+ bool map_ok = sc_mmap_file(file, 0, ret->data, geom->height * geom->pitch, MM_READ | MM_WRITE);
if (!map_ok) goto error;
return ret;
@@ -43,7 +43,7 @@ fb_t *g_fb_from_mem(uint8_t* data, fb_info_t *geom) {
void g_delete_fb(fb_t *fb) {
if (fb->fd != 0) {
- munmap(fb->data);
+ sc_munmap(fb->data);
region_free(fb->data);
}
free(fb);
@@ -237,7 +237,7 @@ font_t *g_load_ascii_bitmap_font(fd_t f) {
ascii_bitmap_font_header h;
- size_t s = read(f, 0, sizeof(h), (char*)&h);
+ size_t s = sc_read(f, 0, sizeof(h), (char*)&h);
if (s != sizeof(h)) goto error;
if (h.magic != ASCII_BITMAP_FONT_MAGIC) goto error;
@@ -255,7 +255,7 @@ font_t *g_load_ascii_bitmap_font(fd_t f) {
font->ascii_bitmap.data = (uint8_t*)malloc(h.ch * h.nchars);
if (font->ascii_bitmap.data == 0) goto error;
- size_t rd = read(f, sizeof(h), h.ch * h.nchars, (char*)font->ascii_bitmap.data);
+ size_t rd = sc_read(f, sizeof(h), h.ch * h.nchars, (char*)font->ascii_bitmap.data);
if (rd != h.ch * h.nchars) goto error;
return font;
@@ -263,7 +263,7 @@ font_t *g_load_ascii_bitmap_font(fd_t f) {
error:
if (font && font->ascii_bitmap.data) free(font->ascii_bitmap.data);
if (font) free(font);
- close(f);
+ sc_close(f);
return 0;
}
@@ -271,7 +271,7 @@ font_t *g_load_font(const char* fontname) {
char buf[128];
snprintf(buf, 128, "sys:/fonts/%s.bf", fontname);
- fd_t f = open(buf, FM_READ);
+ fd_t f = sc_open(buf, FM_READ);
if (f != 0) return g_load_ascii_bitmap_font(f);
return 0;
diff --git a/src/lib/libkogata/keyboard.c b/src/lib/libkogata/keyboard.c
index e7fb08b..64569ed 100644
--- a/src/lib/libkogata/keyboard.c
+++ b/src/lib/libkogata/keyboard.c
@@ -57,14 +57,14 @@ bool load_keymap(keyboard_t *kb, const char* kmname) {
char buf[128];
snprintf(buf, 128, "sys:/keymaps/%s.km", kmname);
- fd_t f = open(buf, FM_READ);
+ fd_t f = sc_open(buf, FM_READ);
if (f == 0) {
dbg_printf("Failed to open keymap %s\n", buf);
return false;
}
keymap_t km;
- size_t rd = read(f, 0, sizeof(keymap_t), (char*)&km);
+ size_t rd = sc_read(f, 0, sizeof(keymap_t), (char*)&km);
bool ok = (rd == sizeof(keymap_t));
@@ -73,7 +73,7 @@ bool load_keymap(keyboard_t *kb, const char* kmname) {
kb->status = 0;
}
- close(f);
+ sc_close(f);
return ok;
}
diff --git a/src/lib/libkogata/mainloop.c b/src/lib/libkogata/mainloop.c
index bce1174..c1758a4 100644
--- a/src/lib/libkogata/mainloop.c
+++ b/src/lib/libkogata/mainloop.c
@@ -91,7 +91,7 @@ void mainloop_run() {
// ---- Do the select
/*dbg_printf("(mainloop) begin select\n");*/
- bool ok = select(sel_arg, nfds, -1);
+ bool ok = sc_select(sel_arg, nfds, -1);
if (!ok) {
dbg_printf("(mainloop) Failed to select.\n");
free(sel_arg);
@@ -107,7 +107,7 @@ void mainloop_run() {
fd->on_error(fd);
} else if ((sel_arg[i].got_flags & SEL_READ) && fd->rd_buf != 0) {
fd->rd_buf_filled +=
- read(fd->fd, 0, fd->rd_buf_expect_size - fd->rd_buf_filled, fd->rd_buf + fd->rd_buf_filled);
+ sc_read(fd->fd, 0, fd->rd_buf_expect_size - fd->rd_buf_filled, fd->rd_buf + fd->rd_buf_filled);
if (fd->rd_buf_filled == fd->rd_buf_expect_size) {
/*dbg_printf("(mainloop) finish read %d\n", fd->rd_buf_expect_size);*/
fd->rd_buf_filled = 0;
@@ -118,7 +118,7 @@ void mainloop_run() {
size_t remain_size = fd->wr_bufs[0].size - fd->wr_bufs[0].written;
void* write_ptr = fd->wr_bufs[0].buf + fd->wr_bufs[0].written;
- fd->wr_bufs[0].written += write(fd->fd, 0, remain_size, write_ptr);
+ fd->wr_bufs[0].written += sc_write(fd->fd, 0, remain_size, write_ptr);
if (fd->wr_bufs[0].written == fd->wr_bufs[0].size) {
/*dbg_printf("(mainloop) finish write %d\n", fd->wr_bufs[0].size);*/
diff --git a/src/sysbin/linker.ld b/src/lib/linker.ld
index 50bebbe..7495c6c 100644
--- a/src/sysbin/linker.ld
+++ b/src/lib/linker.ld
@@ -1,4 +1,4 @@
-ENTRY (__libkogata_start)
+ENTRY (__libc_start)
SECTIONS{
. = 0x100000;
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/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) {