Add another wrapper: kos_sys_misc_load_file

This commit is contained in:
Ivan Baravy 2023-07-19 19:10:06 +01:00
parent 462f1c3075
commit 32e460b8f3
7 changed files with 118 additions and 3 deletions

67
shell.c
View File

@ -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 <filename> [-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 },

View File

@ -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;
}

0
test/t068/ref.log Normal file
View File

13
test/t068/run.us Normal file
View File

@ -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

1
test/t068/tags.txt Normal file
View File

@ -0,0 +1 @@
syscall: f68 f68s27

1
test/t068/timeout.txt Normal file
View File

@ -0,0 +1 @@
10s

37
umka.h
View File

@ -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__ (