diff options
Diffstat (limited to 'src/user')
-rw-r--r-- | src/user/hello/hello.c | 5 | ||||
-rw-r--r-- | src/user/highway/highway.c | 21 | ||||
-rw-r--r-- | src/user/include/knob/block.h | 7 | ||||
-rw-r--r-- | src/user/include/knob/user.h | 3 | ||||
-rw-r--r-- | src/user/include/pland/syscall.h | 6 | ||||
-rw-r--r-- | src/user/init/init.c | 24 | ||||
-rw-r--r-- | src/user/knob/block.c | 17 | ||||
-rw-r--r-- | src/user/knob/entry.asm | 1 | ||||
-rw-r--r-- | src/user/knob/quit.c | 25 | ||||
-rw-r--r-- | src/user/knob/task.c | 16 | ||||
-rw-r--r-- | src/user/knob/user.c | 116 |
11 files changed, 169 insertions, 72 deletions
diff --git a/src/user/hello/hello.c b/src/user/hello/hello.c deleted file mode 100644 index 00d33b5..0000000 --- a/src/user/hello/hello.c +++ /dev/null @@ -1,5 +0,0 @@ -#include <knob/user.h> - -void main() { - tell_user_sz("Hello, world!\n"); -}
\ No newline at end of file diff --git a/src/user/highway/highway.c b/src/user/highway/highway.c new file mode 100644 index 0000000..effc131 --- /dev/null +++ b/src/user/highway/highway.c @@ -0,0 +1,21 @@ +#include <knob/user.h> +#include <knob/task.h> +#include <knob/block.h> + +//TODO: load a user environment file containing a PATH-like setting. +//TODO: have an active disk and/or directory + +void main() { + char path_buf[1024 + 4] = "BIN/"; + char *const line_buf = path_buf + 4; + while (1) { + tell_user_sz("> "); + ask_user_line_sz(line_buf, 1023); + if (blockequ(line_buf, "exit", 5)) + return; + if (try_run_command(path_buf)) + yield_task(); + else + tell_user_sz("An error occured trying to run that command.\n"); + } +}
\ No newline at end of file diff --git a/src/user/include/knob/block.h b/src/user/include/knob/block.h new file mode 100644 index 0000000..2aa2b36 --- /dev/null +++ b/src/user/include/knob/block.h @@ -0,0 +1,7 @@ +#ifndef KNOB_BLOCK_H +#define KNOB_BLOCK_H + +void blockcpy(void *to, const void *from, uint32_t size); +bool blockequ(void *a, void *b, uint32_t size) __attribute__ ((__pure__)); + +#endif
\ No newline at end of file diff --git a/src/user/include/knob/user.h b/src/user/include/knob/user.h index c4ec7db..45caab4 100644 --- a/src/user/include/knob/user.h +++ b/src/user/include/knob/user.h @@ -6,7 +6,8 @@ void tell_user_sz(const char *sz); void tell_user_n(uint32_t n); -//return value and max_length both include null terminator +//return value and max_length don't include null terminator +//returns the real length of the string uint32_t ask_user_line_sz(char *sz, uint32_t max_length); #endif
\ No newline at end of file diff --git a/src/user/include/pland/syscall.h b/src/user/include/pland/syscall.h index 298fc51..c597e2b 100644 --- a/src/user/include/pland/syscall.h +++ b/src/user/include/pland/syscall.h @@ -97,7 +97,7 @@ static inline uint32_t _sc5(enum _scn eax, uint32_t ebx, uint32_t ecx, uint32_t static inline void _yield_task() { asm ( "int $0x39" - ); + : : : "eax"); } __attribute__ ((noreturn)) @@ -124,8 +124,8 @@ static inline uint32_t _file_size(_file_handle_t handle) { return _sc1(_SCN_FILE_SIZE, handle); } -static inline bool _start_task(_drive_number_t drive_number, const char *path) { - return (bool)_sc2(_SCN_START_TASK, drive_number, (uint32_t)path); +static inline bool _start_task(_drive_number_t drive_number, const char *path, const char *pass) { + return (bool)_sc3(_SCN_START_TASK, drive_number, (uint32_t)path, (uint32_t)pass); } static inline void _log_string(const char *sz) { diff --git a/src/user/init/init.c b/src/user/init/init.c index b8536be..64c534e 100644 --- a/src/user/init/init.c +++ b/src/user/init/init.c @@ -2,13 +2,27 @@ #include <knob/file.h> #include <knob/task.h> +void start(const char *cmd) { + tell_user_sz(cmd); + tell_user_sz(": "); + tell_user_sz( + try_run_command(cmd) + ? "success\n" + : "failed\n" + ); +} + +#define STARTUP_FILE_PATH "SYS/STARTUP.RC" + void main() { - struct file *f = open_file("SYS/STARTUP.RC"); + struct file *f = open_file(STARTUP_FILE_PATH); if (!f) { - tell_user_sz("Could not open SYS/STARTUP.RC\n"); + tell_user_sz("Could not open " STARTUP_FILE_PATH "\n"); return; } + tell_user_sz("[init] Reading from " STARTUP_FILE_PATH ":\n"); + char buf[1024]; char *bufp = buf; while (read_from_file(f, 1, bufp)) { @@ -16,7 +30,7 @@ void main() { if (bufp == buf) continue; *bufp = '\0'; - try_run_command(buf); + start(buf); bufp = buf; } else @@ -24,8 +38,10 @@ void main() { } if (bufp != buf) { *bufp = '\0'; - try_run_command(buf); + start(buf); } close_file(f); + + tell_user_sz("[init] Done.\n"); } diff --git a/src/user/knob/block.c b/src/user/knob/block.c new file mode 100644 index 0000000..e890fa1 --- /dev/null +++ b/src/user/knob/block.c @@ -0,0 +1,17 @@ +#include <stdint.h> +#include <stdbool.h> + +//unsophisticated, should copy by dwords where available +void blockcpy(void *to, const void *from, uint32_t size) { + for (uint32_t i = 0; i < size; ++i) + *(uint8_t *)(to++) = *(const uint8_t *)(from++); +} + +//unsophisticated, should check by dwords wheere available +__attribute__ ((__pure__)) +bool blockequ(void *a, void *b, uint32_t size) { + for (uint32_t i = 0; i < size; ++i) + if (*(uint8_t *)(a++) != *(uint8_t *)(b++)) + return false; + return true; +}
\ No newline at end of file diff --git a/src/user/knob/entry.asm b/src/user/knob/entry.asm index ae024c4..18faf7f 100644 --- a/src/user/knob/entry.asm +++ b/src/user/knob/entry.asm @@ -10,6 +10,7 @@ extern current_disk section .text _entry: mov esp, stack + push edx ;TODO: heap stuff? ;TODO: determine current_disk diff --git a/src/user/knob/quit.c b/src/user/knob/quit.c index a2ef5aa..7c20bdd 100644 --- a/src/user/knob/quit.c +++ b/src/user/knob/quit.c @@ -1,29 +1,6 @@ #include <pland/syscall.h> -#include <knob/heap.h> - -struct quit_list_node { - struct quit_list_node *prev; - void (*f)(); -}; - -static struct quit_list_node head = { - .f = &_exit_task -}; - -static struct quit_list_node *last = &head; - -void on_quit(void (*run_f)()) { - struct quit_list_node *new = get_block(sizeof(struct quit_list_node)); - new->prev = last; - new->f = run_f; - last = new; -} __attribute__ ((noreturn)) void quit() { - struct quit_list_node *node = last; - while (1) { - node->f(); - node = node->prev; - } + _exit_task(); }
\ No newline at end of file diff --git a/src/user/knob/task.c b/src/user/knob/task.c index aa18eab..598bee2 100644 --- a/src/user/knob/task.c +++ b/src/user/knob/task.c @@ -1,11 +1,25 @@ #include <stdbool.h> #include <pland/syscall.h> #include <knob/file.h> +#include <knob/heap.h> +#include <knob/block.h> bool try_run_command(const char *path) { uint8_t dn; path = remove_prefix(path, &dn); - return _start_task(dn, path); + + for (const char *ptr = path; *ptr; ++ptr) + if (*ptr == ' ') { + char *new_path = get_block(ptr - path + 1); + blockcpy(new_path, path, ptr - path); + new_path[ptr - path] = '\0'; + + bool succeded = _start_task(dn, new_path, ptr + 1); + free_block(new_path); + return succeded; + } + + return _start_task(dn, path, ""); } void yield_task() { diff --git a/src/user/knob/user.c b/src/user/knob/user.c index fb39851..4ef3321 100644 --- a/src/user/knob/user.c +++ b/src/user/knob/user.c @@ -19,9 +19,25 @@ static const uint8_t caps_and_shift[] = { 0x7e, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, - 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x00 - - //TODO: higher + 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t caps_no_shift[] = { @@ -41,9 +57,25 @@ static const uint8_t caps_no_shift[] = { 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x00 - - //TODO: higher + 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static const uint8_t shifted[] = { @@ -63,28 +95,39 @@ static const uint8_t shifted[] = { 0x7e, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, - 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x00 - - //TODO: higher + 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; static char get_key_char() { _key_code_t key; while (!(key = _get_key())) _yield_task(); - return (char)( - (key & (_KEY_ALT | _KEY_CTRL | _KEY_META)) - ? 0 - : (key & _KEY_CAPS) - ? (key & _KEY_SHIFT) - ? caps_and_shift[key & 0xff] - : caps_no_shift[key & 0xff] - : (key & _KEY_SHIFT) - ? shifted[key & 0xff] - : (key & 0x80) - ? 0 - : (key & 0x7f) - ); + return + key & _KEY_CAPS + ? key & _KEY_SHIFT + ? caps_and_shift[key & 0xff] + : caps_no_shift[key & 0xff] + : key & _KEY_SHIFT + ? shifted[key & 0xff] + : key & 0xff; } void tell_user_sz(const char *sz) { @@ -115,18 +158,23 @@ uint32_t ask_user_line_sz(char *sz, uint32_t max_length) { uint32_t i; for (i = 0; i != max_length; ++i) { - char key = get_key_char(); - if (key) { - log_buf[0] = key; - _log_string(log_buf); - - if (key == '\b') - i -= i ? 2 : 1; - else if (key == '\n') - break; - else - sz[i] = key; - } + char key; + replace: + key = get_key_char(); + if (!key) + goto replace; + if (key & 0x80) + goto replace;//TODO + + log_buf[0] = key; + _log_string(log_buf); + + if (key == '\b') + i -= i ? 2 : 1; + else if (key == '\n') + break; + else + sz[i] = key; } sz[i] = '\0'; |