diff options
Diffstat (limited to 'src/init')
-rw-r--r-- | src/init/main.c | 10 | ||||
-rw-r--r-- | src/init/shell.c | 8 | ||||
-rw-r--r-- | src/init/stdlib.c | 3 | ||||
-rw-r--r-- | src/init/stdlib.h | 5 |
4 files changed, 11 insertions, 15 deletions
diff --git a/src/init/main.c b/src/init/main.c index 35d22a1..f726f31 100644 --- a/src/init/main.c +++ b/src/init/main.c @@ -11,8 +11,6 @@ extern char _bss_start; // provided by the linker extern char _bss_end; extern char _initrd; -int tty_fd; - void read_file(const char *path, size_t len); void fs_test(void); void test_await(void); @@ -22,8 +20,8 @@ int main(void) { // allocate bss _syscall_memflag(&_bss_start, &_bss_end - &_bss_start, MEMFLAG_PRESENT); - tty_fd = _syscall_open("/tty", sizeof("/tty") - 1); - if (tty_fd < 0) + __tty_fd = _syscall_open("/tty", sizeof("/tty") - 1); + if (__tty_fd < 0) _syscall_exit(1); fs_test(); @@ -38,7 +36,7 @@ void read_file(const char *path, size_t len) { static char buf[64]; int buf_len = 64; - _syscall_write(tty_fd, path, len, 0); + _syscall_write(__tty_fd, path, len, 0); printf(": "); if (fd < 0) { printf("couldn't open.\n"); @@ -46,7 +44,7 @@ void read_file(const char *path, size_t len) { } buf_len = _syscall_read(fd, buf, buf_len, 0); - _syscall_write(tty_fd, buf, buf_len, 0); + _syscall_write(__tty_fd, buf, buf_len, 0); _syscall_close(fd); } diff --git a/src/init/shell.c b/src/init/shell.c index 12ec5f6..6002156 100644 --- a/src/init/shell.c +++ b/src/init/shell.c @@ -4,8 +4,6 @@ #define PROMPT "$ " -static int tty_fd = 0; // TODO put in stdlib - static char *split(char *base) { while (*base) { if (*base == ' ' || *base == '\t') { @@ -20,7 +18,7 @@ static char *split(char *base) { static int readline(char *buf, size_t max) { char c; size_t pos = 0; - while (_syscall_read(tty_fd, &c, 1, 0)) { + while (_syscall_read(__tty_fd, &c, 1, 0)) { switch (c) { case '\b': case 0x7f: @@ -36,7 +34,7 @@ static int readline(char *buf, size_t max) { return pos; default: if (pos < max) { - _syscall_write(tty_fd, &c, 1, 0); + _syscall_write(__tty_fd, &c, 1, 0); buf[pos] = c; pos++; } @@ -56,7 +54,7 @@ static void cmd_cat(const char *args) { } len = _syscall_read(fd, buf, len, 0); - _syscall_write(tty_fd, buf, len, 0); + _syscall_write(__tty_fd, buf, len, 0); _syscall_close(fd); } diff --git a/src/init/stdlib.c b/src/init/stdlib.c index 3714324..5c6f45f 100644 --- a/src/init/stdlib.c +++ b/src/init/stdlib.c @@ -2,6 +2,9 @@ #include <shared/syscalls.h> #include <stdarg.h> +int __tty_fd; + + int memcmp(const void *s1, const void *s2, size_t n) { const unsigned char *c1 = s1, *c2 = s2; for (size_t i = 0; i < n; i++) { diff --git a/src/init/stdlib.h b/src/init/stdlib.h index a3a8b64..8b71adf 100644 --- a/src/init/stdlib.h +++ b/src/init/stdlib.h @@ -1,12 +1,9 @@ #pragma once #include <stddef.h> -// TODO since this is shared with the kernel, maybe i could turn this into an -// stb-style header file +extern int __tty_fd; int memcmp(const void *s1, const void *s2, size_t n); - int strcmp(const char *s1, const char *s2); size_t strlen(const char *s); - int printf(const char *fmt, ...); |