From e03ae18548c722f0f9d1405aec794c743b22b00e Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Mon, 30 Jan 2023 06:24:23 +0000 Subject: [PATCH] Support different framebuffer formats, add tests --- README | 10 +- linux/thread.c | 2 +- makefile | 12 +- shell.c | 945 +++++++++++---------- shell.h | 4 +- test/065_#board_all.ref.log | 15 + test/065_#board_all.t | 11 + test/066_#f01_#draw_#draw16bit_all.ref.log | 117 +++ test/066_#f01_#draw_#draw16bit_all.ref.png | Bin 0 -> 2078 bytes test/066_#f01_#draw_#draw16bit_all.t | 53 ++ test/067_#f01_#draw_#draw24bit_all.ref.log | 117 +++ test/067_#f01_#draw_#draw24bit_all.ref.png | Bin 0 -> 2324 bytes test/067_#f01_#draw_#draw24bit_all.t | 53 ++ umka.asm | 19 +- umka.h | 34 +- umka_fuse.c | 2 +- umka_gen_devices_dat.c | 2 +- umka_monitor.c | 156 ---- umka_os.c | 171 ++-- umka_os.h | 14 - umka_os.us | 1 + umka_shell.c | 33 +- util.c | 54 +- util.h | 8 +- 24 files changed, 1128 insertions(+), 705 deletions(-) create mode 100644 test/065_#board_all.ref.log create mode 100644 test/065_#board_all.t create mode 100644 test/066_#f01_#draw_#draw16bit_all.ref.log create mode 100644 test/066_#f01_#draw_#draw16bit_all.ref.png create mode 100644 test/066_#f01_#draw_#draw16bit_all.t create mode 100644 test/067_#f01_#draw_#draw24bit_all.ref.log create mode 100644 test/067_#f01_#draw_#draw24bit_all.ref.png create mode 100644 test/067_#f01_#draw_#draw24bit_all.t delete mode 100644 umka_monitor.c diff --git a/README b/README index 5425016..74bccd9 100644 --- a/README +++ b/README @@ -103,12 +103,6 @@ Testing Troubleshooting --------------- -# umka_monitor - -Allow reading process_vm_readv syscall. - - # sysctl -w kernel.yama.ptrace_scope=0 - # umka_os To create tap devices. @@ -119,6 +113,10 @@ To load apps at 0 address. # sysctl -w vm.mmap_min_addr=0 +Allow reading process_vm_readv syscall. + + # sysctl -w kernel.yama.ptrace_scope=0 + Links & Acknowledgements ------------------------ diff --git a/linux/thread.c b/linux/thread.c index 3f19f0c..6d84b5f 100644 --- a/linux/thread.c +++ b/linux/thread.c @@ -16,7 +16,7 @@ sigset_t mask; void reset_procmask(void) { sigemptyset (&mask); - sigaddset (&mask, SIGPROF); + sigaddset (&mask, SIGALRM); sigprocmask(SIG_UNBLOCK, &mask, NULL); } diff --git a/makefile b/makefile index a08a151..fbc61a6 100644 --- a/makefile +++ b/makefile @@ -69,10 +69,7 @@ umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o vdisk/raw.o \ umka_os: umka_os.o umka.o shell.o lodepng.o vdisk.o vdisk/raw.o vdisk/qcow2.o \ vdisk/miniz/miniz.a vnet.o trace.o trace_lbr.o $(HOST)/pci.o \ $(HOST)/thread.o io.o $(HOST)/io_async.o util.o bestline32.o optparse32.o - $(CC) $(LDFLAGS_32) `sdl2-config --libs` -lpthread $^ -o $@ -T umka.ld - -#umka_monitor: umka_monitor.o optparse.o bestline.o -# $(CC) $(LDFLAGS) `sdl2-config --libs` $^ -o $@ + $(CC) $(LDFLAGS_32) `sdl2-config --libs` $^ -o $@ -T umka.ld umka_gen_devices_dat: umka_gen_devices_dat.o umka.o $(HOST)/pci.o \ $(HOST)/thread.o util.o @@ -100,10 +97,10 @@ lodepng.o: lodepng.c lodepng.h $(CC) $(CFLAGS_32) -c $< bestline32.o: bestline.c bestline.h - $(CC) $(CFLAGS_32) -U_POSIX_C_SOURCE -Wno-logical-op -Wno-switch-enum -c $< -o $@ + $(CC) $(CFLAGS_32) -Wno-logical-op -Wno-switch-enum -c $< -o $@ bestline.o: bestline.c bestline.h - $(CC) $(CFLAGS) -U_POSIX_C_SOURCE -Wno-logical-op -Wno-switch-enum -c $< -o $@ + $(CC) $(CFLAGS) -Wno-logical-op -Wno-switch-enum -c $< -o $@ optparse32.o: optparse.c optparse.h $(CC) $(CFLAGS_32) -c $< -o $@ @@ -174,9 +171,6 @@ umka_fuse.o: umka_fuse.c umka.h umka_os.o: umka_os.c umka.h umka_os.h $(CC) $(CFLAGS_32) `sdl2-config --cflags` -c $< -#umka_monitor.o: umka_monitor.c umka_os.h -# $(CC) $(CFLAGS) `sdl2-config --cflags` -c $< -D_GNU_SOURCE - umka_gen_devices_dat.o: umka_gen_devices_dat.c umka.h $(CC) $(CFLAGS_32) -c $< diff --git a/shell.c b/shell.c index 66d20d9..023dba4 100644 --- a/shell.c +++ b/shell.c @@ -37,6 +37,8 @@ #include "optparse.h" #include "bestline.h" +char *bestlineFile(const char *prompt, FILE *fin, FILE *fout); + #define MAX_COMMAND_ARGS 42 #define PRINT_BYTES_PER_LINE 32 #define MAX_DIRENTS_TO_READ 100 @@ -105,13 +107,14 @@ convert_f70_file_attr(uint32_t attr, char s[KF_ATTR_CNT+1]) { } static void -print_f70_status(f7080ret_t *r, int use_ebx) { - printf("status = %d %s", r->status, get_f70_status_name(r->status)); +print_f70_status(struct shell_ctx *ctx, f7080ret_t *r, int use_ebx) { + fprintf(ctx->fout, "status = %d %s", r->status, + get_f70_status_name(r->status)); if (use_ebx && (r->status == ERROR_SUCCESS || r->status == ERROR_END_OF_FILE)) { - printf(", count = %d", r->count); + fprintf(ctx->fout, ", count = %d", r->count); } - putchar('\n'); + fprintf(ctx->fout, "\n"); } static bool @@ -123,25 +126,25 @@ parse_uintmax(const char *str, uintmax_t *res) { } static bool -parse_uint32(const char *str, uint32_t *res) { +parse_uint32(struct shell_ctx *ctx, const char *str, uint32_t *res) { uintmax_t x; if (parse_uintmax(str, &x) && x <= UINT32_MAX) { *res = (uint32_t)x; return true; } else { - printf("invalid number: %s\n", str); + fprintf(ctx->fout, "invalid number: %s\n", str); return false; } } static bool -parse_uint64(const char *str, uint64_t *res) { +parse_uint64(struct shell_ctx *ctx, const char *str, uint64_t *res) { uintmax_t x; if (parse_uintmax(str, &x) && x <= UINT64_MAX) { *res = x; return true; } else { - printf("invalid number: %s\n", str); + fprintf(ctx->fout, "invalid number: %s\n", str); return false; } } @@ -275,24 +278,24 @@ shell_var_add_ptr(struct shell_ctx *ctx, void *value) { } static void -print_bytes(uint8_t *x, size_t len) { +print_bytes(struct shell_ctx *ctx, uint8_t *x, size_t len) { for (size_t i = 0; i < len; i++) { if (i % PRINT_BYTES_PER_LINE == 0 && i != 0) { - putchar('\n'); + fprintf(ctx->fout, "\n"); } - printf("%2.2x", x[i]); + fprintf(ctx->fout, "%2.2x", x[i]); } - putchar('\n'); + fprintf(ctx->fout, "\n"); } static void -print_hash(uint8_t *x, size_t len) { +print_hash(struct shell_ctx *ctx, uint8_t *x, size_t len) { hash_context hash; hash_oneshot(&hash, x, len); for (size_t i = 0; i < HASH_SIZE; i++) { - printf("%2.2x", hash.hash[i]); + fprintf(ctx->fout, "%2.2x", hash.hash[i]); } - putchar('\n'); + fprintf(ctx->fout, "\n"); } void *host_load_file(const char *fname) { @@ -331,7 +334,7 @@ prompt(struct shell_ctx *ctx) { last_dir = get_last_dir(cur_dir); cur_dir_changed = false; } - printf("%s> ", last_dir); + fprintf(ctx->fout, "%s> ", last_dir); fflush(stdout); } @@ -367,12 +370,12 @@ cmd_var(struct shell_ctx *ctx, int argc, char **argv) { "usage: var <$name>\n" " $name variable name, must start with $ sign"; if (argc != 2) { - puts(usage); + fputs(usage, ctx->fout); return; } bool status = shell_var_name(ctx, argv[1]); if (!status) { - printf("fail\n"); + fprintf(ctx->fout, "fail\n"); } } @@ -383,7 +386,7 @@ cmd_send_scancode(struct shell_ctx *ctx, int argc, char **argv) { "usage: send_scancode ...\n" " code dec or hex number"; if (argc < 2) { - puts(usage); + fputs(usage, ctx->fout); return; } argc -= 1; @@ -397,8 +400,8 @@ cmd_send_scancode(struct shell_ctx *ctx, int argc, char **argv) { argc--; argv++; } else { - printf("not an integer: %s\n", argv[0]); - puts(usage); + fprintf(ctx->fout, "not an integer: %s\n", argv[0]); + fputs(usage, ctx->fout); return; } } @@ -409,9 +412,9 @@ cmd_umka_boot(struct shell_ctx *ctx, int argc, char **argv) { (void)ctx; (void)argv; const char *usage = \ - "usage: umka_boot"; + "usage: umka_boot\n"; if (argc != 1) { - puts(usage); + fputs(usage, ctx->fout); return; } @@ -422,18 +425,19 @@ cmd_umka_boot(struct shell_ctx *ctx, int argc, char **argv) { static void cmd_umka_set_boot_params(struct shell_ctx *ctx, int argc, char **argv) { - (void)ctx; const char *usage = \ "usage: umka_set_boot_params [--x_res ] [--y_res ]\n" " --x_res screen width\n" - " --y_res screen height"; + " --y_res screen height\n" + " --bpp screen bits per pixel\n" + " --pitch screen line length in bytes\n"; argc -= 1; argv += 1; while (argc) { if (!strcmp(argv[0], "--x_res") && argc > 1) { kos_boot.x_res = strtoul(argv[1], NULL, 0); - kos_boot.pitch = kos_boot.x_res * 4; // assume 32bpp + kos_boot.pitch = kos_boot.x_res * kos_boot.bpp/8; argc -= 2; argv += 2; continue; @@ -442,9 +446,20 @@ cmd_umka_set_boot_params(struct shell_ctx *ctx, int argc, char **argv) { argc -= 2; argv += 2; continue; + } else if (!strcmp(argv[0], "--bpp") && argc > 1) { + kos_boot.bpp = strtoul(argv[1], NULL, 0); + kos_boot.pitch = kos_boot.x_res * kos_boot.bpp/8; + argc -= 2; + argv += 2; + continue; + } else if (!strcmp(argv[0], "--pitch") && argc > 1) { + kos_boot.pitch = strtoul(argv[1], NULL, 0); + argc -= 2; + argv += 2; + continue; } else { - printf("bad option: %s\n", argv[0]); - puts(usage); + fprintf(ctx->fout, "bad option: %s\n", argv[0]); + fputs(usage, ctx->fout); return; } } @@ -457,7 +472,7 @@ cmd_i40(struct shell_ctx *ctx, int argc, char **argv) { "usage: i40 [ebx [ecx [edx [esi [edi [ebp]]]]]]...\n" " see '/kernel/docs/sysfuncs.txt' for details"; if (argc < 2 || argc > 8) { - puts(usage); + fputs(usage, ctx->fout); return; } pushad_t regs = {0, 0, 0, 0, 0, 0, 0, 0}; @@ -471,7 +486,7 @@ cmd_i40(struct shell_ctx *ctx, int argc, char **argv) { COVERAGE_ON(); umka_i40(®s); COVERAGE_OFF(); - printf("eax = %8.8x %" PRIu32 " %" PRIi32 "\n" + fprintf(ctx->fout, "eax = %8.8x %" PRIu32 " %" PRIi32 "\n" "ebx = %8.8x %" PRIu32 " %" PRIi32 "\n", regs.eax, regs.eax, (int32_t)regs.eax, regs.ebx, regs.ebx, (int32_t)regs.ebx); @@ -523,13 +538,13 @@ bytes_to_kmgtpe(uint64_t *bytes, const char **kmg) { } static void -disk_list_partitions(disk_t *d) { +disk_list_partitions(struct shell_ctx *ctx, disk_t *d) { uint64_t kmgtpe_count = d->media_info.sector_size * d->media_info.capacity; const char *kmgtpe = NULL; bytes_to_kmgtpe(&kmgtpe_count, &kmgtpe); - printf("/%s: sector_size=%u, capacity=%" PRIu64 " (%" PRIu64 " %s), " - "num_partitions=%u\n", d->name, d->media_info.sector_size, - d->media_info.capacity, kmgtpe_count, kmgtpe, d->num_partitions); + fprintf(ctx->fout, "/%s: sector_size=%u, capacity=%" PRIu64 " (%" PRIu64 + " %s), num_partitions=%u\n", d->name, d->media_info.sector_size, + d->media_info.capacity, kmgtpe_count, kmgtpe, d->num_partitions); for (size_t i = 0; i < d->num_partitions; i++) { partition_t *p = d->partitions[i]; const char *fsname; @@ -548,12 +563,12 @@ disk_list_partitions(disk_t *d) { } kmgtpe_count = d->media_info.sector_size * p->first_sector; bytes_to_kmgtpe(&kmgtpe_count, &kmgtpe); - printf("/%s/%d: fs=%s, start=%" PRIu64 " (%" PRIu64 " %s)", - d->name, i+1, fsname, p->first_sector, kmgtpe_count, kmgtpe); + fprintf(ctx->fout, "/%s/%d: fs=%s, start=%" PRIu64 " (%" PRIu64 " %s)", + d->name, i+1, fsname, p->first_sector, kmgtpe_count, kmgtpe); kmgtpe_count = d->media_info.sector_size * p->length; bytes_to_kmgtpe(&kmgtpe_count, &kmgtpe); - printf(", length=%" PRIu64 " (%" PRIu64 " %s)\n", - p->length, kmgtpe_count, kmgtpe); + fprintf(ctx->fout, ", length=%" PRIu64 " (%" PRIu64 " %s)\n", + p->length, kmgtpe_count, kmgtpe); } } @@ -564,19 +579,19 @@ cmd_ramdisk_init(struct shell_ctx *ctx, int argc, char **argv) { "usage: ramdisk_init \n" " absolute or relative path"; if (argc != 2) { - puts(usage); + fputs(usage, ctx->fout); return; } const char *fname = argv[1]; FILE *f = fopen(fname, "rb"); if (!f) { - printf("[!] can't open file '%s': %s\n", fname, strerror(errno)); + fprintf(ctx->fout, "[!] can't open file '%s': %s\n", fname, strerror(errno)); return; } fseek(f, 0, SEEK_END); size_t fsize = ftell(f); if (fsize > 2880*512) { - printf("[!] file '%s' is too big, max size is 1474560 bytes\n", fname); + fprintf(ctx->fout, "[!] file '%s' is too big, max size is 1474560 bytes\n", fname); return; } rewind(f); @@ -585,7 +600,7 @@ cmd_ramdisk_init(struct shell_ctx *ctx, int argc, char **argv) { COVERAGE_ON(); void *ramdisk = kos_ramdisk_init(); COVERAGE_OFF(); - disk_list_partitions(ramdisk); + disk_list_partitions(ctx, ramdisk); } static void @@ -597,7 +612,7 @@ cmd_disk_add(struct shell_ctx *ctx, int argc, char **argv) { " disk name, e.g. hd0 or rd\n" " -c cache size size of disk cache in bytes"; if (argc < 3) { - puts(usage); + fputs(usage, ctx->fout); return; } size_t cache_size = 0; @@ -613,7 +628,7 @@ cmd_disk_add(struct shell_ctx *ctx, int argc, char **argv) { adjust_cache_size = 1; break; default: - puts(usage); + fputs(usage, ctx->fout); return; } } @@ -628,16 +643,16 @@ cmd_disk_add(struct shell_ctx *ctx, int argc, char **argv) { COVERAGE_ON(); disk_media_changed(disk, 1); COVERAGE_OFF(); - disk_list_partitions(disk); + disk_list_partitions(ctx, disk); return; } } - printf("umka: can't add file '%s' as disk '%s'\n", file_name, disk_name); + fprintf(ctx->fout, "umka: can't add file '%s' as disk '%s'\n", file_name, disk_name); return; } static void -disk_del_by_name(const char *name) { +disk_del_by_name(struct shell_ctx *ctx, const char *name) { for(disk_t *d = disk_list.next; d != &disk_list; d = d->next) { if (!strcmp(d->name, name)) { COVERAGE_ON(); @@ -646,7 +661,7 @@ disk_del_by_name(const char *name) { return; } } - printf("umka: can't find disk '%s'\n", name); + fprintf(ctx->fout, "umka: can't find disk '%s'\n", name); } static void @@ -656,11 +671,11 @@ cmd_disk_del(struct shell_ctx *ctx, int argc, char **argv) { "usage: disk_del \n" " name disk name, i.e. rd or hd0"; if (argc != 2) { - puts(usage); + fputs(usage, ctx->fout); return; } const char *name = argv[1]; - disk_del_by_name(name); + disk_del_by_name(ctx, name); return; } @@ -670,7 +685,7 @@ cmd_pwd(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: pwd"; if (argc != 1) { - puts(usage); + fputs(usage, ctx->fout); return; } (void)argv; @@ -679,7 +694,7 @@ cmd_pwd(struct shell_ctx *ctx, int argc, char **argv) { COVERAGE_ON(); umka_sys_get_cwd(cur_dir, PATH_MAX); COVERAGE_OFF(); - printf("%s%s%s\n", quote, cur_dir, quote); + fprintf(ctx->fout, "%s%s%s\n", quote, cur_dir, quote); } static void @@ -692,7 +707,7 @@ cmd_set_pixel(struct shell_ctx *ctx, int argc, char **argv) { " color argb in hex\n" " -i inverted color"; if (argc < 4) { - puts(usage); + fputs(usage, ctx->fout); return; } size_t x = strtoul(argv[1], NULL, 0); @@ -722,7 +737,7 @@ cmd_write_text(struct shell_ctx *ctx, int argc, char **argv) { " length length of the string if it is non-asciiz\n" " bg_color_or_buf argb or pointer"; if (argc != 12) { - puts(usage); + fputs(usage, ctx->fout); return; } size_t x = strtoul(argv[1], NULL, 0); @@ -750,10 +765,10 @@ cmd_get_key(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: get_key"; if (argc > 1) { - puts(usage); + fputs(usage, ctx->fout); return; } - printf("0x%8.8" PRIx32 "\n", umka_get_key()); + fprintf(ctx->fout, "0x%8.8" PRIx32 "\n", umka_get_key()); } static void @@ -763,7 +778,7 @@ cmd_dump_key_buff(struct shell_ctx *ctx, int argc, char **argv) { "usage: dump_key_buff [count]\n" " count how many items to dump (all by default)"; if (argc > 2) { - puts(usage); + fputs(usage, ctx->fout); return; } int count = INT_MAX; @@ -771,7 +786,7 @@ cmd_dump_key_buff(struct shell_ctx *ctx, int argc, char **argv) { count = strtol(argv[1], NULL, 0); } for (int i = 0; i < count && i < kos_key_count; i++) { - printf("%3i 0x%2.2x 0x%2.2x\n", i, kos_key_buff[i], + fprintf(ctx->fout, "%3i 0x%2.2x 0x%2.2x\n", i, kos_key_buff[i], kos_key_buff[120+2+i]); } } @@ -783,7 +798,7 @@ cmd_dump_win_stack(struct shell_ctx *ctx, int argc, char **argv) { "usage: dump_win_stack [count]\n" " count how many items to dump"; if (argc > 2) { - puts(usage); + fputs(usage, ctx->fout); return; } int depth = 5; @@ -791,7 +806,7 @@ cmd_dump_win_stack(struct shell_ctx *ctx, int argc, char **argv) { depth = strtol(argv[1], NULL, 0); } for (int i = 0; i < depth; i++) { - printf("%3i: %3u\n", i, kos_win_stack[i]); + fprintf(ctx->fout, "%3i: %3u\n", i, kos_win_stack[i]); } } @@ -802,7 +817,7 @@ cmd_dump_win_pos(struct shell_ctx *ctx, int argc, char **argv) { "usage: dump_win_pos [count]\n" " count how many items to dump"; if (argc < 1) { - puts(usage); + fputs(usage, ctx->fout); return; } int depth = 5; @@ -810,7 +825,7 @@ cmd_dump_win_pos(struct shell_ctx *ctx, int argc, char **argv) { depth = strtol(argv[1], NULL, 0); } for (int i = 0; i < depth; i++) { - printf("%3i: %3u\n", i, kos_win_pos[i]); + fprintf(ctx->fout, "%3i: %3u\n", i, kos_win_pos[i]); } } @@ -822,14 +837,15 @@ cmd_dump_win_map(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: dump_win_map"; if (argc < 0) { - puts(usage); + fputs(usage, ctx->fout); return; } for (size_t y = 0; y < kos_display.height; y++) { for (size_t x = 0; x < kos_display.width; x++) { - putchar(kos_display.win_map[y * kos_display.width + x] + '0'); + fprintf(ctx->fout, "%c", + kos_display.win_map[y * kos_display.width + x] + '0'); } - putchar('\n'); + fprintf(ctx->fout, "\n"); } } @@ -841,7 +857,7 @@ cmd_dump_appdata(struct shell_ctx *ctx, int argc, char **argv) { " index index into appdata array to dump\n" " -p print fields that are pointers"; if (argc < 2) { - puts(usage); + fputs(usage, ctx->fout); return; } int show_pointers = 0; @@ -850,49 +866,49 @@ cmd_dump_appdata(struct shell_ctx *ctx, int argc, char **argv) { show_pointers = 1; } appdata_t *a = kos_slot_base + idx; - printf("app_name: %s\n", a->app_name); + fprintf(ctx->fout, "app_name: %s\n", a->app_name); if (show_pointers) { - printf("process: %p\n", (void*)a->process); - printf("fpu_state: %p\n", (void*)a->fpu_state); - printf("exc_handler: %p\n", (void*)a->exc_handler); + fprintf(ctx->fout, "process: %p\n", (void*)a->process); + fprintf(ctx->fout, "fpu_state: %p\n", (void*)a->fpu_state); + fprintf(ctx->fout, "exc_handler: %p\n", (void*)a->exc_handler); } - printf("except_mask: %" PRIx32 "\n", a->except_mask); + fprintf(ctx->fout, "except_mask: %" PRIx32 "\n", a->except_mask); if (show_pointers) { - printf("pl0_stack: %p\n", (void*)a->pl0_stack); - printf("cursor: %p\n", (void*)a->cursor); - printf("fd_ev: %p\n", (void*)a->fd_ev); - printf("bk_ev: %p\n", (void*)a->bk_ev); - printf("fd_obj: %p\n", (void*)a->fd_obj); - printf("bk_obj: %p\n", (void*)a->bk_obj); - printf("saved_esp: %p\n", (void*)a->saved_esp); + fprintf(ctx->fout, "pl0_stack: %p\n", (void*)a->pl0_stack); + fprintf(ctx->fout, "cursor: %p\n", (void*)a->cursor); + fprintf(ctx->fout, "fd_ev: %p\n", (void*)a->fd_ev); + fprintf(ctx->fout, "bk_ev: %p\n", (void*)a->bk_ev); + fprintf(ctx->fout, "fd_obj: %p\n", (void*)a->fd_obj); + fprintf(ctx->fout, "bk_obj: %p\n", (void*)a->bk_obj); + fprintf(ctx->fout, "saved_esp: %p\n", (void*)a->saved_esp); } - printf("dbg_state: %u\n", a->dbg_state); - printf("cur_dir: %s\n", a->cur_dir); - printf("draw_bgr_x: %u\n", a->draw_bgr_x); - printf("draw_bgr_y: %u\n", a->draw_bgr_y); - printf("event_mask: %" PRIx32 "\n", a->event_mask); - printf("tid: %" PRId32 "\n", a->tid); - printf("state: 0x%" PRIx8 "\n", a->state); - printf("wnd_number: %" PRIu8 "\n", a->wnd_number); - printf("terminate_protection: %u\n", a->terminate_protection); - printf("keyboard_mode: %u\n", a->keyboard_mode); - printf("captionEncoding: %u\n", a->captionEncoding); - printf("exec_params: %s\n", a->exec_params); - printf("wnd_caption: %s\n", a->wnd_caption); - printf("wnd_clientbox (ltwh): %u %u %u %u\n", a->wnd_clientbox.left, + fprintf(ctx->fout, "dbg_state: %u\n", a->dbg_state); + fprintf(ctx->fout, "cur_dir: %s\n", a->cur_dir); + fprintf(ctx->fout, "draw_bgr_x: %u\n", a->draw_bgr_x); + fprintf(ctx->fout, "draw_bgr_y: %u\n", a->draw_bgr_y); + fprintf(ctx->fout, "event_mask: %" PRIx32 "\n", a->event_mask); + fprintf(ctx->fout, "tid: %" PRId32 "\n", a->tid); + fprintf(ctx->fout, "state: 0x%" PRIx8 "\n", a->state); + fprintf(ctx->fout, "wnd_number: %" PRIu8 "\n", a->wnd_number); + fprintf(ctx->fout, "terminate_protection: %u\n", a->terminate_protection); + fprintf(ctx->fout, "keyboard_mode: %u\n", a->keyboard_mode); + fprintf(ctx->fout, "captionEncoding: %u\n", a->captionEncoding); + fprintf(ctx->fout, "exec_params: %s\n", a->exec_params); + fprintf(ctx->fout, "wnd_caption: %s\n", a->wnd_caption); + fprintf(ctx->fout, "wnd_clientbox (ltwh): %u %u %u %u\n", a->wnd_clientbox.left, a->wnd_clientbox.top, a->wnd_clientbox.width, a->wnd_clientbox.height); - printf("priority: %u\n", a->priority); + fprintf(ctx->fout, "priority: %u\n", a->priority); - printf("in_schedule: prev"); + fprintf(ctx->fout, "in_schedule: prev"); if (show_pointers) { - printf(" %p", (void*)a->in_schedule.prev); + fprintf(ctx->fout, " %p", (void*)a->in_schedule.prev); } - printf(" (%u), next", (appdata_t*)a->in_schedule.prev - kos_slot_base); + fprintf(ctx->fout, " (%u), next", (appdata_t*)a->in_schedule.prev - kos_slot_base); if (show_pointers) { - printf(" %p", (void*)a->in_schedule.next); + fprintf(ctx->fout, " %p", (void*)a->in_schedule.next); } - printf(" (%u)\n", (appdata_t*)a->in_schedule.next - kos_slot_base); + fprintf(ctx->fout, " (%u)\n", (appdata_t*)a->in_schedule.next - kos_slot_base); } static void @@ -902,7 +918,7 @@ cmd_switch_to_thread(struct shell_ctx *ctx, int argc, char **argv) { "usage: switch_to_thread \n" " thread id to switch to"; if (argc != 2) { - puts(usage); + fputs(usage, ctx->fout); return; } uint8_t tid = strtoul(argv[1], NULL, 0); @@ -917,23 +933,23 @@ cmd_get(struct shell_ctx *ctx, int argc, char **argv) { "usage: get \n" " variable to get"; if (argc != 2) { - puts(usage); + fputs(usage, ctx->fout); return; } const char *var = argv[1]; if (!strcmp(var, "redraw_background")) { - printf("%i\n", kos_redraw_background); + fprintf(ctx->fout, "%i\n", kos_redraw_background); } else if (!strcmp(var, "key_count")) { - printf("%i\n", kos_key_count); + fprintf(ctx->fout, "%i\n", kos_key_count); } else if (!strcmp(var, "syslang")) { - printf("%i\n", kos_syslang); + fprintf(ctx->fout, "%i\n", kos_syslang); } else if (!strcmp(var, "keyboard")) { - printf("%i\n", kos_keyboard); + fprintf(ctx->fout, "%i\n", kos_keyboard); } else if (!strcmp(var, "keyboard_mode")) { - printf("%i\n", kos_keyboard_mode); + fprintf(ctx->fout, "%i\n", kos_keyboard_mode); } else { - printf("no such variable: %s\n", var); - puts(usage); + fprintf(ctx->fout, "no such variable: %s\n", var); + fputs(usage, ctx->fout); return; } } @@ -946,7 +962,7 @@ cmd_set(struct shell_ctx *ctx, int argc, char **argv) { " variable to set\n" " decimal or hex value"; if (argc != 3) { - puts(usage); + fputs(usage, ctx->fout); return; } const char *var = argv[1]; @@ -954,7 +970,7 @@ cmd_set(struct shell_ctx *ctx, int argc, char **argv) { char *endptr; ssize_t value = strtol(val_str, &endptr, 0); if (*endptr != '\0') { - printf("integer required: %s\n", val_str); + fprintf(ctx->fout, "integer required: %s\n", val_str); return; } if (!strcmp(var, "redraw_background")) { @@ -966,8 +982,8 @@ cmd_set(struct shell_ctx *ctx, int argc, char **argv) { } else if (!strcmp(var, "keyboard_mode")) { kos_keyboard_mode = value; } else { - printf("bad option: %s\n", argv[1]); - puts(usage); + fprintf(ctx->fout, "bad option: %s\n", argv[1]); + fputs(usage, ctx->fout); return; } } @@ -980,11 +996,11 @@ cmd_new_sys_thread(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: new_sys_thread"; if (!argc) { - puts(usage); + fputs(usage, ctx->fout); return; } size_t tid = umka_new_sys_threads(0, NULL, NULL); - printf("tid: %u\n", tid); + fprintf(ctx->fout, "tid: %u\n", tid); } static void @@ -1001,7 +1017,7 @@ cmd_mouse_move(struct shell_ctx *ctx, int argc, char **argv) { " -h scroll horizontally\n" " -v scroll vertically"; if (!argc) { - puts(usage); + fputs(usage, ctx->fout); return; } int lbheld = 0, mbheld = 0, rbheld = 0, xabs = 0, yabs = 0; @@ -1031,7 +1047,7 @@ cmd_mouse_move(struct shell_ctx *ctx, int argc, char **argv) { xmoving = -strtol(optarg, NULL, 0); break; default: - puts(usage); + fputs(usage, ctx->fout); return; } break; @@ -1047,26 +1063,26 @@ cmd_mouse_move(struct shell_ctx *ctx, int argc, char **argv) { ymoving = -strtol(optarg, NULL, 0); break; default: - puts(usage); + fputs(usage, ctx->fout); return; } break; case 'h': if ((optarg[0] != '+') && (optarg[0] != '-')) { - puts(usage); + fputs(usage, ctx->fout); return; } hscroll = strtol(optarg, NULL, 0); break; case 'v': if ((optarg[0] != '+') && (optarg[0] != '-')) { - puts(usage); + fputs(usage, ctx->fout); return; } vscroll = strtol(optarg, NULL, 0); break; default: - puts(usage); + fputs(usage, ctx->fout); return; } } @@ -1082,7 +1098,7 @@ cmd_process_info(struct shell_ctx *ctx, int argc, char **argv) { "usage: process_info \n" " pid process id to dump, -1 for self"; if (argc != 2) { - puts(usage); + fputs(usage, ctx->fout); return; } process_information_t info; @@ -1091,20 +1107,20 @@ cmd_process_info(struct shell_ctx *ctx, int argc, char **argv) { COVERAGE_ON(); umka_sys_process_info(pid, &info); COVERAGE_OFF(); - printf("cpu_usage: %u\n", info.cpu_usage); - printf("window_stack_position: %u\n", info.window_stack_position); - printf("window_stack_value: %u\n", info.window_stack_value); - printf("process_name: %s\n", info.process_name); - printf("memory_start: 0x%.8" PRIx32 "\n", info.memory_start); - printf("used_memory: %u (0x%x)\n", info.used_memory, + fprintf(ctx->fout, "cpu_usage: %u\n", info.cpu_usage); + fprintf(ctx->fout, "window_stack_position: %u\n", info.window_stack_position); + fprintf(ctx->fout, "window_stack_value: %u\n", info.window_stack_value); + fprintf(ctx->fout, "process_name: %s\n", info.process_name); + fprintf(ctx->fout, "memory_start: 0x%.8" PRIx32 "\n", info.memory_start); + fprintf(ctx->fout, "used_memory: %u (0x%x)\n", info.used_memory, info.used_memory); - printf("pid: %u\n", info.pid); - printf("box: %u %u %u %u\n", info.box.left, info.box.top, + fprintf(ctx->fout, "pid: %u\n", info.pid); + fprintf(ctx->fout, "box: %u %u %u %u\n", info.box.left, info.box.top, info.box.width, info.box.height); - printf("slot_state: %u\n", info.slot_state); - printf("client_box: %u %u %u %u\n", info.client_box.left, + fprintf(ctx->fout, "slot_state: %u\n", info.slot_state); + fprintf(ctx->fout, "client_box: %u %u %u %u\n", info.client_box.left, info.client_box.top, info.client_box.width, info.client_box.height); - printf("wnd_state: 0x%.2" PRIx8 "\n", info.wnd_state); + fprintf(ctx->fout, "wnd_state: 0x%.2" PRIx8 "\n", info.wnd_state); } static void @@ -1114,13 +1130,13 @@ cmd_check_for_event(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: check_for_event"; if (argc != 1) { - puts(usage); + fputs(usage, ctx->fout); return; } COVERAGE_ON(); uint32_t event = umka_sys_check_for_event(); COVERAGE_OFF(); - printf("%" PRIu32 "\n", event); + fprintf(ctx->fout, "%" PRIu32 "\n", event); } static void @@ -1145,7 +1161,7 @@ cmd_display_number(struct shell_ctx *ctx, int argc, char **argv) { " scale_factor 0 = x1, ..., 7 = x8\n" " bg_color_or_buf depending on flags fill_bg and draw_to_buf"; if (argc != 15) { - puts(usage); + fputs(usage, ctx->fout); return; } int is_pointer = strtoul(argv[1], NULL, 0); @@ -1183,7 +1199,7 @@ cmd_set_window_colors(struct shell_ctx *ctx, int argc, char **argv) { " \n" " * all colors are in hex"; if (argc != (1 + sizeof(system_colors_t)/4)) { - puts(usage); + fputs(usage, ctx->fout); return; } system_colors_t colors; @@ -1209,7 +1225,7 @@ cmd_get_window_colors(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: get_window_colors"; if (argc != 1) { - puts(usage); + fputs(usage, ctx->fout); return; } system_colors_t colors; @@ -1217,17 +1233,17 @@ cmd_get_window_colors(struct shell_ctx *ctx, int argc, char **argv) { COVERAGE_ON(); umka_sys_get_window_colors(&colors); COVERAGE_OFF(); - printf("0x%.8" PRIx32 " frame\n", colors.frame); - printf("0x%.8" PRIx32 " grab\n", colors.grab); - printf("0x%.8" PRIx32 " work_3d_dark\n", colors.work_3d_dark); - printf("0x%.8" PRIx32 " work_3d_light\n", colors.work_3d_light); - printf("0x%.8" PRIx32 " grab_text\n", colors.grab_text); - printf("0x%.8" PRIx32 " work\n", colors.work); - printf("0x%.8" PRIx32 " work_button\n", colors.work_button); - printf("0x%.8" PRIx32 " work_button_text\n", + fprintf(ctx->fout, "0x%.8" PRIx32 " frame\n", colors.frame); + fprintf(ctx->fout, "0x%.8" PRIx32 " grab\n", colors.grab); + fprintf(ctx->fout, "0x%.8" PRIx32 " work_3d_dark\n", colors.work_3d_dark); + fprintf(ctx->fout, "0x%.8" PRIx32 " work_3d_light\n", colors.work_3d_light); + fprintf(ctx->fout, "0x%.8" PRIx32 " grab_text\n", colors.grab_text); + fprintf(ctx->fout, "0x%.8" PRIx32 " work\n", colors.work); + fprintf(ctx->fout, "0x%.8" PRIx32 " work_button\n", colors.work_button); + fprintf(ctx->fout, "0x%.8" PRIx32 " work_button_text\n", colors.work_button_text); - printf("0x%.8" PRIx32 " work_text\n", colors.work_text); - printf("0x%.8" PRIx32 " work_graph\n", colors.work_graph); + fprintf(ctx->fout, "0x%.8" PRIx32 " work_text\n", colors.work_text); + fprintf(ctx->fout, "0x%.8" PRIx32 " work_graph\n", colors.work_graph); } static void @@ -1237,13 +1253,13 @@ cmd_get_skin_height(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: get_skin_height"; if (argc != 1) { - puts(usage); + fputs(usage, ctx->fout); return; } COVERAGE_ON(); uint32_t skin_height = umka_sys_get_skin_height(); COVERAGE_OFF(); - printf("%" PRIu32 "\n", skin_height); + fprintf(ctx->fout, "%" PRIu32 "\n", skin_height); } static void @@ -1253,17 +1269,17 @@ cmd_get_screen_area(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: get_screen_area"; if (argc != 1) { - puts(usage); + fputs(usage, ctx->fout); return; } rect_t wa; COVERAGE_ON(); umka_sys_get_screen_area(&wa); COVERAGE_OFF(); - printf("%" PRIu32 " left\n", wa.left); - printf("%" PRIu32 " top\n", wa.top); - printf("%" PRIu32 " right\n", wa.right); - printf("%" PRIu32 " bottom\n", wa.bottom); + fprintf(ctx->fout, "%" PRIu32 " left\n", wa.left); + fprintf(ctx->fout, "%" PRIu32 " top\n", wa.top); + fprintf(ctx->fout, "%" PRIu32 " right\n", wa.right); + fprintf(ctx->fout, "%" PRIu32 " bottom\n", wa.bottom); } static void @@ -1276,7 +1292,7 @@ cmd_set_screen_area(struct shell_ctx *ctx, int argc, char **argv) { " right right x coord (not length!)\n" " bottom bottom y coord"; if (argc != 5) { - puts(usage); + fputs(usage, ctx->fout); return; } rect_t wa; @@ -1296,17 +1312,17 @@ cmd_get_skin_margins(struct shell_ctx *ctx, int argc, char **argv) { const char *usage = \ "usage: get_skin_margins"; if (argc != 1) { - puts(usage); + fputs(usage, ctx->fout); return; } rect_t wa; COVERAGE_ON(); umka_sys_get_skin_margins(&wa); COVERAGE_OFF(); - printf("%" PRIu32 " left\n", wa.left); - printf("%" PRIu32 " top\n", wa.top); - printf("%" PRIu32 " right\n", wa.right); - printf("%" PRIu32 " bottom\n", wa.bottom); + fprintf(ctx->fout, "%" PRIu32 " left\n", wa.left); + fprintf(ctx->fout, "%" PRIu32 " top\n", wa.top); + fprintf(ctx->fout, "%" PRIu32 " right\n", wa.right); + fprintf(ctx->fout, "%" PRIu32 " bottom\n", wa.bottom); } static void @@ -1316,7 +1332,7 @@ cmd_set_button_style(struct shell_ctx *ctx, int argc, char **argv) { "usage: set_button_style