diff options
author | Benji Dial <benji6283@gmail.com> | 2020-09-13 17:12:29 -0400 |
---|---|---|
committer | Benji Dial <benji6283@gmail.com> | 2020-09-13 17:12:29 -0400 |
commit | 5481848e27fdd4fc859def9841a0283665531a46 (patch) | |
tree | 990a8df008214d85141a3bd10bd96898e64b0c37 /src/user | |
parent | 1e4a254674f668839e5de273916024c16814b045 (diff) | |
download | portland-os-5481848e27fdd4fc859def9841a0283665531a46.tar.gz |
fixed some paging bugs, added fault handlers and new programs
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/dumphex/dumphex.c | 29 | ||||
-rw-r--r-- | src/user/dumptext/dumptext.c | 15 | ||||
-rw-r--r-- | src/user/hello/hello.asm | 14 | ||||
-rw-r--r-- | src/user/highway/highway.c | 7 | ||||
-rw-r--r-- | src/user/include/knob/format.h | 2 | ||||
-rw-r--r-- | src/user/init/init.c | 15 | ||||
-rw-r--r-- | src/user/knob/entry.asm | 1 | ||||
-rw-r--r-- | src/user/knob/format.c | 14 | ||||
-rw-r--r-- | src/user/knob/user.c | 14 |
9 files changed, 98 insertions, 13 deletions
diff --git a/src/user/dumphex/dumphex.c b/src/user/dumphex/dumphex.c new file mode 100644 index 0000000..4c63a06 --- /dev/null +++ b/src/user/dumphex/dumphex.c @@ -0,0 +1,29 @@ +#include <knob/file.h> +#include <knob/user.h> +#include <knob/format.h> + +void main(const char *path) { + struct file *f = open_file(path); + if (!f) { + tell_user_sz("Couldn't open file.\n"); + return; + } + char buf[] = { ' ', '\0', '\0', '\0' }; + uint8_t v; + uint32_t a = 0; + while (read_from_file(f, 1, &v)) { + if (!(a & 0xf)) { + char buf2[] = {'0', 'x', '\0', '\0', '\0', '\0', + '\0', '\0', '\0', '\0', '\0' }; + itosz_h32(a, buf2 + 2); + tell_user_sz(buf2); + tell_user_sz(" |"); + } + itosz_h8(v, buf + 1); + tell_user_sz(buf); + if (!(++a & 0xf)) + tell_user_sz("\n"); + } + tell_user_sz("\n"); + close_file(f); +}
\ No newline at end of file diff --git a/src/user/dumptext/dumptext.c b/src/user/dumptext/dumptext.c new file mode 100644 index 0000000..b10375c --- /dev/null +++ b/src/user/dumptext/dumptext.c @@ -0,0 +1,15 @@ +#include <knob/file.h> +#include <knob/user.h> + +void main(const char *path) { + struct file *f = open_file(path); + if (!f) { + tell_user_sz("Couldn't open file.\n"); + return; + } + char buf[] = { '\0', '\0' }; + while (read_from_file(f, 1, buf)) + tell_user_sz(buf); + tell_user_sz("\n"); + close_file(f); +}
\ No newline at end of file diff --git a/src/user/hello/hello.asm b/src/user/hello/hello.asm new file mode 100644 index 0000000..65d32be --- /dev/null +++ b/src/user/hello/hello.asm @@ -0,0 +1,14 @@ +bits 32 + +global _entry + +section .text +_entry: + mov eax, 0x5 + mov ebx, hello + int 0x30 + + int 0x38 + +section .data +hello db "Hello, world!", 0x0a, 0
\ No newline at end of file diff --git a/src/user/highway/highway.c b/src/user/highway/highway.c index effc131..8dc0080 100644 --- a/src/user/highway/highway.c +++ b/src/user/highway/highway.c @@ -6,8 +6,13 @@ //TODO: have an active disk and/or directory void main() { - char path_buf[1024 + 4] = "BIN/"; + char path_buf[1024 + 4] = "bin/"; char *const line_buf = path_buf + 4; + + tell_user_sz("Highway, Portland Command Shell, started.\n" + "Type \"exit\" to quit.\n"); + yield_task(); + while (1) { tell_user_sz("> "); ask_user_line_sz(line_buf, 1023); diff --git a/src/user/include/knob/format.h b/src/user/include/knob/format.h index 6c4aa5d..89402c0 100644 --- a/src/user/include/knob/format.h +++ b/src/user/include/knob/format.h @@ -6,5 +6,7 @@ bool try_sntoi(const char *s, uint32_t n, uint32_t *out); void itosz(uint32_t i, char *out); +void itosz_h8(uint8_t i, char *out); +void itosz_h32(uint32_t i, char *out); #endif
\ No newline at end of file diff --git a/src/user/init/init.c b/src/user/init/init.c index 64c534e..390b731 100644 --- a/src/user/init/init.c +++ b/src/user/init/init.c @@ -3,25 +3,28 @@ #include <knob/task.h> void start(const char *cmd) { + tell_user_sz("[init] Starting "); tell_user_sz(cmd); tell_user_sz(": "); tell_user_sz( try_run_command(cmd) - ? "success\n" - : "failed\n" + ? "Succeded.\n" + : "Failed.\n" ); + tell_user_sz("[init] Yielding.\n"); + yield_task(); } -#define STARTUP_FILE_PATH "SYS/STARTUP.RC" +#define STARTUP_FILE_PATH "sys/startup.rc" void main() { struct file *f = open_file(STARTUP_FILE_PATH); if (!f) { - tell_user_sz("Could not open " STARTUP_FILE_PATH "\n"); + tell_user_sz("Could not open " STARTUP_FILE_PATH ".\n"); return; } - tell_user_sz("[init] Reading from " STARTUP_FILE_PATH ":\n"); + tell_user_sz("[init] Reading from " STARTUP_FILE_PATH ".\n"); char buf[1024]; char *bufp = buf; @@ -43,5 +46,5 @@ void main() { close_file(f); - tell_user_sz("[init] Done.\n"); + tell_user_sz("[init] Done starting programs.\n"); } diff --git a/src/user/knob/entry.asm b/src/user/knob/entry.asm index 18faf7f..acf6f5f 100644 --- a/src/user/knob/entry.asm +++ b/src/user/knob/entry.asm @@ -12,7 +12,6 @@ _entry: mov esp, stack push edx - ;TODO: heap stuff? ;TODO: determine current_disk ;any further needed initialization diff --git a/src/user/knob/format.c b/src/user/knob/format.c index 087f6fd..645fb73 100644 --- a/src/user/knob/format.c +++ b/src/user/knob/format.c @@ -28,4 +28,18 @@ void itosz(uint32_t i, char *out) { } } *out = '\0'; +} + +const char *const hex_digits = "0123456789abcdef"; + +void itosz_h8(uint8_t i, char *out) { + out[0] = hex_digits[i >> 4]; + out[1] = hex_digits[i & 0xf]; + out[2] = '\0'; +} + +void itosz_h32(uint32_t i, char *out) { + for (uint8_t digit = 0; digit < 8; ++digit) + out[digit] = hex_digits[(i >> (28 - digit * 4)) & 0xf]; + out[8] = '\0'; }
\ No newline at end of file diff --git a/src/user/knob/user.c b/src/user/knob/user.c index 4ef3321..c84977c 100644 --- a/src/user/knob/user.c +++ b/src/user/knob/user.c @@ -165,16 +165,20 @@ uint32_t ask_user_line_sz(char *sz, uint32_t max_length) { goto replace; if (key & 0x80) goto replace;//TODO + if (key == '\b') { + if (i) { + --i; + _log_string("\b"); + } + goto replace; + } log_buf[0] = key; _log_string(log_buf); - if (key == '\b') - i -= i ? 2 : 1; - else if (key == '\n') + if (key == '\n') break; - else - sz[i] = key; + sz[i] = key; } sz[i] = '\0'; |