From 32e460b8f3d150683a43637eacc30b7d22dc2039 Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Wed, 19 Jul 2023 19:10:06 +0100 Subject: [PATCH] Add another wrapper: kos_sys_misc_load_file --- shell.c | 67 ++++++++++++++++++++++++++++++++++++++++++- test/runtests.c | 2 +- test/t068/ref.log | 0 test/t068/run.us | 13 +++++++++ test/t068/tags.txt | 1 + test/t068/timeout.txt | 1 + umka.h | 37 +++++++++++++++++++++++- 7 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 test/t068/ref.log create mode 100644 test/t068/run.us create mode 100644 test/t068/tags.txt create mode 100644 test/t068/timeout.txt diff --git a/shell.c b/shell.c index d1016a6..bbdd126 100644 --- a/shell.c +++ b/shell.c @@ -2109,6 +2109,67 @@ cmd_button(struct shell_ctx *ctx, int argc, char **argv) { COVERAGE_OFF(); } +static void +cmd_kos_sys_misc_init_heap(struct shell_ctx *ctx, int argc, char **argv) { + (void)argv; + const char *usage = \ + "usage: kos_sys_misc_init_heap\n"; + if (argc != 1) { + fputs(usage, ctx->fout); + return; + } + + COVERAGE_ON(); + size_t heap_size = kos_sys_misc_init_heap(); + COVERAGE_OFF(); + fprintf(ctx->fout, "heap size = %u\n", heap_size); +} + +static void +cmd_kos_sys_misc_load_file(struct shell_ctx *ctx, int argc, char **argv) { + const char *usage = \ + "usage: kos_sys_misc_load_file [-h] [-p]\n" + " file file in kolibri fs, e.g. /sys/pew/blah\n" + " -h dump bytes in hex\n" + " -p print pointers\n"; + if (argc < 2) { + fputs(usage, ctx->fout); + return; + } + const char *fname = argv[1]; + int show_hash = 0; + int show_pointers = 0; + optparse_init(&ctx->opts, argv+1); + int opt; + while ((opt = optparse(&ctx->opts, "hp")) != -1) { + switch (opt) { + case 'h': + show_hash = 1; + break; + case 'p': + show_pointers = 1; + break; + default: + fputs(usage, ctx->fout); + return; + } + } + + COVERAGE_ON(); + struct sys_load_file_ret ret = kos_sys_misc_load_file(fname); + COVERAGE_OFF(); + if (show_pointers) { + fprintf(ctx->fout, "file data = %p\n", ret.fdata); + } else { + fprintf(ctx->fout, "file data = %s\n", ret.fdata ? "non-zero" : "0"); + } + if (show_hash) { + print_hash(ctx, ret.fdata, ret.fsize); + } + fprintf(ctx->fout, "file size = %u\n", ret.fsize); + shell_var_add_ptr(ctx, ret.fdata); +} + static void cmd_load_cursor_from_file(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ @@ -4077,7 +4138,8 @@ cmd_bg_unmap(struct shell_ctx *ctx, int argc, char **argv) { fprintf(ctx->fout, "status = %d\n", status); } -static void cmd_help(struct shell_ctx *ctx, int argc, char **argv); +static void +cmd_help(struct shell_ctx *ctx, int argc, char **argv); func_table_t cmd_cmds[] = { { "send_scancode", cmd_send_scancode }, @@ -4135,6 +4197,9 @@ func_table_t cmd_cmds[] = { { "get_window_colors", cmd_get_window_colors }, { "help", cmd_help }, { "i40", cmd_i40 }, + // f68 + { "kos_sys_misc_init_heap", cmd_kos_sys_misc_init_heap }, // 11 + { "kos_sys_misc_load_file", cmd_kos_sys_misc_load_file }, // 27 { "load_cursor_from_file", cmd_load_cursor_from_file }, { "load_cursor_from_mem", cmd_load_cursor_from_mem }, { "load_dll", cmd_load_dll }, diff --git a/test/runtests.c b/test/runtests.c index df73c9b..f53c457 100644 --- a/test/runtests.c +++ b/test/runtests.c @@ -213,7 +213,7 @@ run_test(const void *arg) { unsigned tout = get_test_timeout(test_name); if(!CreateProcessA(NULL, "../umka_shell -ri run.us -o out.log", NULL, - NULL, FALSE, 0, NULL, test_name, &si, &pi)) { + NULL, FALSE, 0, NULL, test_name, &si, &pi)) { fprintf(stderr, "CreateProcess failed: %lu\n", GetLastError()); return (void *)-1; } diff --git a/test/t068/ref.log b/test/t068/ref.log new file mode 100644 index 0000000..e69de29 diff --git a/test/t068/run.us b/test/t068/run.us new file mode 100644 index 0000000..4c048e7 --- /dev/null +++ b/test/t068/run.us @@ -0,0 +1,13 @@ +umka_boot +ramdisk_init ../img/kolibri.raw + +kos_sys_misc_init_heap +kos_sys_misc_load_file /sys/fill.cur +#kos_sys_misc_load_file /sys/fill.cur -h +#kos_sys_misc_load_file /sys/fill.cur -h + +#kos_sys_misc_load_file /sys/spray.cur +#kos_sys_misc_load_file /sys/spray.cur -h +#kos_sys_misc_load_file /sys/spray.cur -h + +disk_del rd diff --git a/test/t068/tags.txt b/test/t068/tags.txt new file mode 100644 index 0000000..c12979b --- /dev/null +++ b/test/t068/tags.txt @@ -0,0 +1 @@ +syscall: f68 f68s27 diff --git a/test/t068/timeout.txt b/test/t068/timeout.txt new file mode 100644 index 0000000..39e1887 --- /dev/null +++ b/test/t068/timeout.txt @@ -0,0 +1 @@ +10s diff --git a/umka.h b/umka.h index 7e52df1..1e42863 100644 --- a/umka.h +++ b/umka.h @@ -1895,7 +1895,7 @@ umka_sys_move_window(size_t x, size_t y, ssize_t xsize, ssize_t ysize) { : "memory"); } -static inline void* +static inline void * umka_sys_load_dll(const char *fname) { void *table; __asm__ __inline__ __volatile__ ( @@ -1908,6 +1908,41 @@ umka_sys_load_dll(const char *fname) { return table; } +struct sys_load_file_ret { + void *fdata; + size_t fsize; +}; + +static inline size_t +kos_sys_misc_init_heap(void) { + size_t heap_size; + + __asm__ __inline__ __volatile__ ( + "call i40" + : "=a"(heap_size) + : "a"(68), + "b"(11) + : "memory"); + + return heap_size; +} + +static inline struct sys_load_file_ret +kos_sys_misc_load_file(const char *fname) { + struct sys_load_file_ret ret; + + __asm__ __inline__ __volatile__ ( + "call i40" + : "=a"(ret.fdata), + "=d"(ret.fsize) + : "a"(68), + "b"(27), + "c"(fname) + : "memory"); + + return ret; +} + static inline void umka_sys_lfn(void *f7080sXarg, f7080ret_t *r, f70or80_t f70or80) { __asm__ __inline__ __volatile__ (