From 334866c2098c5a189ed51a22ddf974160052bf08 Mon Sep 17 00:00:00 2001 From: mkostoevr Date: Sun, 12 Dec 2021 13:35:35 +0300 Subject: [PATCH] Make it work on win32 --- getopt.c | 220 +++++++++++++++++++++++++++++++++++++++++++ getopt.h | 53 +++++++++++ isatty.c | 15 +++ isatty.h | 6 ++ makefile | 10 +- shell.c | 46 +++++---- trace_lbr.c | 32 +++++-- umka.asm | 249 ++++++++++++++++++++++++++++++++----------------- umka.h | 10 +- umka_shell.c | 4 - vdisk.c | 7 +- vnet.c | 12 ++- win32/pci.c | 12 +++ win32/pci.h | 8 ++ win32/thread.c | 8 ++ 15 files changed, 575 insertions(+), 117 deletions(-) create mode 100644 getopt.c create mode 100644 getopt.h create mode 100644 isatty.c create mode 100644 isatty.h create mode 100755 win32/pci.c create mode 100755 win32/pci.h create mode 100755 win32/thread.c diff --git a/getopt.c b/getopt.c new file mode 100644 index 0000000..21a27fe --- /dev/null +++ b/getopt.c @@ -0,0 +1,220 @@ +#include +#include +#include +#include "getopt.h" + +#ifdef _WIN32 + +char *optarg; +int optind=1, opterr=1, optopt, __optpos, optreset=0; + +#define optpos __optpos + +static void __getopt_msg(const char *a, const char *b, const char *c, size_t l) +{ + FILE *f = stderr; +#if !defined(WIN32) && !defined(_WIN32) + flockfile(f); +#endif + fputs(a, f); + fwrite(b, strlen(b), 1, f); + fwrite(c, 1, l, f); + fputc('\n', f); +#if !defined(WIN32) && !defined(_WIN32) + funlockfile(f); +#endif +} + +int getopt(int argc, char * const argv[], const char *optstring) +{ + int i, c, d; + int k, l; + char *optchar; + + if (!optind || optreset) { + optreset = 0; + __optpos = 0; + optind = 1; + } + + if (optind >= argc || !argv[optind]) + return -1; + + if (argv[optind][0] != '-') { + if (optstring[0] == '-') { + optarg = argv[optind++]; + return 1; + } + return -1; + } + + if (!argv[optind][1]) + return -1; + + if (argv[optind][1] == '-' && !argv[optind][2]) + return optind++, -1; + + if (!optpos) optpos++; + c = argv[optind][optpos], k = 1; + optchar = argv[optind]+optpos; + optopt = c; + optpos += k; + + if (!argv[optind][optpos]) { + optind++; + optpos = 0; + } + + if (optstring[0] == '-' || optstring[0] == '+') + optstring++; + + i = 0; + d = 0; + do { + d = optstring[i], l = 1; + if (l>0) i+=l; else i++; + } while (l && d != c); + + if (d != c) { + if (optstring[0] != ':' && opterr) + __getopt_msg(argv[0], ": unrecognized option: ", optchar, k); + return '?'; + } + if (optstring[i] == ':') { + if (optstring[i+1] == ':') optarg = 0; + else if (optind >= argc) { + if (optstring[0] == ':') return ':'; + if (opterr) __getopt_msg(argv[0], + ": option requires an argument: ", + optchar, k); + return '?'; + } + if (optstring[i+1] != ':' || optpos) { + optarg = argv[optind++] + optpos; + optpos = 0; + } + } + return c; +} + +static void permute(char *const *argv, int dest, int src) +{ + char **av = (char **)argv; + char *tmp = av[src]; + int i; + for (i=src; i>dest; i--) + av[i] = av[i-1]; + av[dest] = tmp; +} + +static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) +{ + optarg = 0; + if (longopts && argv[optind][0] == '-' && + ((longonly && argv[optind][1] && argv[optind][1] != '-') || + (argv[optind][1] == '-' && argv[optind][2]))) + { + int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':'; + int i, cnt, match = -1; + char *opt; + for (cnt=i=0; longopts[i].name; i++) { + const char *name = longopts[i].name; + opt = argv[optind]+1; + if (*opt == '-') opt++; + for (; *name && *name == *opt; name++, opt++); + if (*opt && *opt != '=') continue; + match = i; + if (!*name) { + cnt = 1; + break; + } + cnt++; + } + if (cnt==1) { + i = match; + optind++; + optopt = longopts[i].val; + if (*opt == '=') { + if (!longopts[i].has_arg) { + if (colon || !opterr) + return '?'; + __getopt_msg(argv[0], + ": option does not take an argument: ", + longopts[i].name, + strlen(longopts[i].name)); + return '?'; + } + optarg = opt+1; + } else if (longopts[i].has_arg == required_argument) { + if (!(optarg = argv[optind])) { + if (colon) return ':'; + if (!opterr) return '?'; + __getopt_msg(argv[0], + ": option requires an argument: ", + longopts[i].name, + strlen(longopts[i].name)); + return '?'; + } + optind++; + } + if (idx) *idx = i; + if (longopts[i].flag) { + *longopts[i].flag = longopts[i].val; + return 0; + } + return longopts[i].val; + } + if (argv[optind][1] == '-') { + if (!colon && opterr) + __getopt_msg(argv[0], cnt ? + ": option is ambiguous: " : + ": unrecognized option: ", + argv[optind]+2, + strlen(argv[optind]+2)); + optind++; + return '?'; + } + } + return getopt(argc, argv, optstring); +} + +static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) +{ + int ret, skipped, resumed; + if (!optind || optreset) { + optreset = 0; + __optpos = 0; + optind = 1; + } + if (optind >= argc || !argv[optind]) return -1; + skipped = optind; + if (optstring[0] != '+' && optstring[0] != '-') { + int i; + for (i=optind; ; i++) { + if (i >= argc || !argv[i]) return -1; + if (argv[i][0] == '-' && argv[i][1]) break; + } + optind = i; + } + resumed = optind; + ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly); + if (resumed > skipped) { + int i, cnt = optind-resumed; + for (i=0; i + +int isatty(int fd); +int fileno(FILE *fp); diff --git a/makefile b/makefile index 2c0672b..fe56215 100644 --- a/makefile +++ b/makefile @@ -14,11 +14,13 @@ LDFLAGS_32=$(LDFLAGS) -m32 all: umka_shell umka_fuse umka_os umka_gen_devices_dat umka.sym umka.prp \ umka.lst tags covpreproc default.skn skin.skn +.PHONY: test + covpreproc: covpreproc.c $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ umka_shell: umka_shell.o umka.o shell.o trace.o trace_lbr.o vdisk.o vnet.o \ - lodepng.o pci.o thread.o util.o + lodepng.o pci.o thread.o util.o getopt.o isatty.o $(CC) $(LDFLAGS_32) $^ -o $@ -static -T umka.ld umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o pci.o thread.o @@ -47,6 +49,12 @@ pci.o: linux/pci.c lodepng.o: lodepng.c lodepng.h $(CC) $(CFLAGS_32) -c $< +getopt.o: getopt.c getopt.h + $(CC) $(CFLAGS_32) -c $< + +isatty.o: isatty.c isatty.h + $(CC) $(CFLAGS_32) -c $< + util.o: util.c util.h umka.h $(CC) $(CFLAGS_32) -c $< diff --git a/shell.c b/shell.c index f0f83c6..e539ec2 100644 --- a/shell.c +++ b/shell.c @@ -25,19 +25,18 @@ #include #include #include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include #include + +// TODO: Cleanup +#ifndef _WIN32 +#include +#include +#endif + +#include "isatty.h" +#include "getopt.h" #include "vdisk.h" #include "vnet.h" #include "umka.h" @@ -211,6 +210,10 @@ next_line(int is_tty, int block) { if (is_tty) { prompt(); } +// TODO: Cleanup +#ifdef _WIN32 + return fgets(cmd_buf, FGETS_BUF_LEN, fin) != NULL; +#else if (block) { return fgets(cmd_buf, FGETS_BUF_LEN, fin) != NULL; } else { @@ -230,6 +233,7 @@ next_line(int is_tty, int block) { } return 1; } +#endif } static int @@ -338,7 +342,7 @@ shell_ramdisk_init(int argc, char **argv) { return; } const char *fname = argv[1]; - FILE *f = fopen(fname, "r"); + FILE *f = fopen(fname, "rb"); if (!f) { fprintf(fout, "[!] can't open file '%s': %s\n", fname, strerror(errno)); return; @@ -1124,7 +1128,7 @@ shell_put_image(int argc, char **argv) { fputs(usage, fout); return; } - FILE *f = fopen(argv[1], "r"); + FILE *f = fopen(argv[1], "rb"); fseek(f, 0, SEEK_END); size_t fsize = ftell(f); rewind(f); @@ -1157,7 +1161,7 @@ shell_put_image_palette(int argc, char **argv) { fputs(usage, fout); return; } - FILE *f = fopen(argv[1], "r"); + FILE *f = fopen(argv[1], "rb"); fseek(f, 0, SEEK_END); size_t fsize = ftell(f); rewind(f); @@ -1363,7 +1367,7 @@ shell_blit_bitmap(int argc, char **argv) { return; } const char *fname = argv[1]; - FILE *f = fopen(fname, "r"); + FILE *f = fopen(fname, "rb"); if (!f) { fprintf(fout, "[!] can't open file '%s': %s\n", fname, strerror(errno)); return; @@ -1808,7 +1812,7 @@ shell_acpi_preload_table(int argc, char **argv) { fputs(usage, fout); return; } - FILE *f = fopen(argv[1], "r"); + FILE *f = fopen(argv[1], "rb"); if (!f) { fprintf(fout, "[umka] can't open file: %s\n", argv[1]); return; @@ -1947,6 +1951,8 @@ shell_pci_get_path(int argc, char **argv) { fprintf(fout, "pci path: %s\n", pci_path); } +#ifndef _WIN32 + static void shell_stack_init(int argc, char **argv) { const char *usage = \ @@ -2602,6 +2608,8 @@ shell_net_arp_del_entry(int argc, char **argv) { } } +#endif // _WIN32 + static void shell_bg_set_size(int argc, char **argv) { const char *usage = \ @@ -2667,7 +2675,7 @@ shell_bg_put_img(int argc, char **argv) { fputs(usage, fout); return; } - FILE *f = fopen(argv[1], "r"); + FILE *f = fopen(argv[1], "rb"); fseek(f, 0, SEEK_END); size_t fsize = ftell(f); rewind(f); @@ -2754,6 +2762,8 @@ func_table_t shell_cmds[] = { { "ls80", shell_ls80 }, { "move_window", shell_move_window }, { "mouse_move", shell_mouse_move }, +#ifndef _WIN32 + { "stack_init", shell_stack_init }, { "net_accept", shell_net_accept }, { "net_add_device", shell_net_add_device }, { "net_arp_add_entry", shell_net_arp_add_entry }, @@ -2785,6 +2795,7 @@ func_table_t shell_cmds[] = { { "net_ipv4_set_subnet", shell_net_ipv4_set_subnet }, { "net_listen", shell_net_listen }, { "net_open_socket", shell_net_open_socket }, +#endif // _WIN32 { "pci_get_path", shell_pci_get_path }, { "pci_set_path", shell_pci_set_path }, { "process_info", shell_process_info }, @@ -2805,7 +2816,6 @@ func_table_t shell_cmds[] = { { "set_skin", shell_set_skin }, { "set_window_caption", shell_set_window_caption }, { "set_window_colors", shell_set_window_colors }, - { "stack_init", shell_stack_init }, { "stat70", shell_stat70 }, { "stat80", shell_stat80 }, { "window_redraw", shell_window_redraw }, @@ -2852,7 +2862,7 @@ run_test(FILE *in, FILE *out, int block) { fin = in; fout = out; int is_tty = isatty(fileno(fin)); - char **argv = (char**)malloc(sizeof(char*) * (MAX_COMMAND_ARGS + 1)); + char **argv = (char**)calloc(sizeof(char*), (MAX_COMMAND_ARGS + 1)); while(next_line(is_tty, block)) { if (cmd_buf[0] == '#' || cmd_buf[0] == '\n' || cmd_buf[0] == '\0' || cmd_buf[0] == '\r') { diff --git a/trace_lbr.c b/trace_lbr.c index e551eb0..4006ffa 100644 --- a/trace_lbr.c +++ b/trace_lbr.c @@ -1,11 +1,12 @@ #include -#include #include #include -#include -#include + +#ifndef _WIN32 +#include #include -#include +#endif + #include "umka.h" #define MSR_IA32_DEBUGCTLMSR 0x1d9 @@ -16,18 +17,23 @@ int covfd, msrfd; uint64_t rdmsr(uint32_t reg) { - uint64_t data; + uint64_t data = 0; +#ifndef _WIN32 if (pread(msrfd, &data, sizeof data, reg) != sizeof data) { perror("rdmsr: pread"); exit(1); } +#else + printf("STUB: %s:%d", __FILE__, __LINE__); +#endif return data; } void wrmsr(uint32_t reg, uint64_t data) { +#ifndef _WIN32 int fd; fd = open("/dev/cpu/0/msr", O_WRONLY); if (fd < 0) { @@ -41,10 +47,13 @@ void wrmsr(uint32_t reg, uint64_t data) } close(fd); - return; +#else + printf("STUB: %s:%d", __FILE__, __LINE__); +#endif } void handle_sigtrap() { +#ifndef _WIN32 uint64_t from = rdmsr(MSR_IA32_LASTBRANCHFROMIP); uint64_t to = rdmsr(MSR_IA32_LASTBRANCHTOIP); @@ -55,11 +64,15 @@ void handle_sigtrap() { } wrmsr(MSR_IA32_DEBUGCTLMSR, 3); +#else + printf("STUB: %s:%d", __FILE__, __LINE__); +#endif } uint32_t set_eflags_tf(uint32_t tf); void trace_lbr_begin() { +#ifndef _WIN32 struct sigaction action; action.sa_sigaction = &handle_sigtrap; action.sa_flags = SA_SIGINFO; @@ -78,12 +91,19 @@ void trace_lbr_begin() { void *coverage_end_addr = coverage_end; write(covfd, &coverage_begin_addr, 4); write(covfd, &coverage_end_addr, 4); +#else + printf("STUB: %s:%d", __FILE__, __LINE__); +#endif } void trace_lbr_end() { +#ifndef _WIN32 wrmsr(MSR_IA32_DEBUGCTLMSR, 0); close(msrfd); close(covfd); +#else + printf("STUB: %s:%d", __FILE__, __LINE__); +#endif } uint32_t trace_lbr_pause(void) { diff --git a/umka.asm b/umka.asm index 294ec1b..feb2e53 100644 --- a/umka.asm +++ b/umka.asm @@ -1,6 +1,68 @@ ; TODO: SPDX -format ELF +if defined WIN32 + format MS COFF +else + format ELF +end if + +; win32: +; pubsym name -> public name as "_name" +; pubsym name, 20 -> public name as "_name@20" +; pubsym name, no_mangle -> public name +; pubsym name, "name" -> public name as "_name" +; pubsym name, "name", 20 -> public name as "_name@20" +; pubsym name, "name", no_mangle -> public name as "name" +; linux: +; pubsym name -> public name +; pubsym name, 20 -> public name +; pubsym name, no_mangle -> public name +; pubsym name, "name" -> public name as "name" +; pubsym name, "name", 20 -> public name as "name" +; pubsym name, "name", no_mangle -> public name as "name" +macro pubsym name, marg1, marg2 { + if defined WIN32 + if marg1 eq no_mangle + public name + else if marg1 eqtype 20 + public name as '_' # `name # '@' # `marg1 + else if marg1 eqtype 'string' + if marg2 eq no_mangle + public name as marg1 + else if marg2 eqtype 20 + public name as '_' # marg1 # '@' # `marg2 + else + public name as '_' # marg1 + end if + else + public name as '_' # `name + end if + else + if marg1 eqtype 'string' + public name as marg1 + else + public name + end if + end if +} + +; win32: +; extrn name -> extrn _name +; extrn name, 20 -> extrn _name@20 +; linux: +; extrn name -> extrn name +; extrn name, 20 -> extrn name +macro extrn name, [argsize] { + if defined WIN32 + if argsize eqtype 20 + extrn '_' # `name # '@' # `argsize as name + else + extrn '_' # `name as name + end if + else + extrn name + end if +} __DEBUG__ = 1 __DEBUG_LEVEL__ = 1 @@ -11,92 +73,92 @@ UMKA_OS = 3 UMKA_MEMORY_BYTES = 256 SHL 20 -public disk_add -public disk_del -public disk_list -public disk_media_changed +pubsym disk_add, 16 +pubsym disk_del, 4 +pubsym disk_list +pubsym disk_media_changed, 8 -public xfs._.user_functions as 'xfs_user_functions' -public ext_user_functions -public fat_user_functions -public ntfs_user_functions +pubsym xfs._.user_functions, 'xfs_user_functions' +pubsym ext_user_functions +pubsym fat_user_functions +pubsym ntfs_user_functions -public i40 +pubsym i40, no_mangle -public coverage_begin -public coverage_end +pubsym coverage_begin +pubsym coverage_end -public sha3_256_oneshot as 'hash_oneshot' -public kos_time_to_epoch -public umka_init +pubsym sha3_256_oneshot, 'hash_oneshot' +pubsym kos_time_to_epoch +pubsym umka_init -public current_process as 'kos_current_process' -public current_slot as 'kos_current_slot' -public current_slot_idx as 'kos_current_slot_idx' +pubsym current_process, 'kos_current_process' +pubsym current_slot, 'kos_current_slot' +pubsym current_slot_idx, 'kos_current_slot_idx' -public thread_count as 'kos_thread_count' -public TASK_TABLE as 'kos_task_table' -public TASK_BASE as 'kos_task_base' -public TASK_DATA as 'kos_task_data' -public SLOT_BASE as 'kos_slot_base' -public window_data as 'kos_window_data' +pubsym thread_count, 'kos_thread_count' +pubsym TASK_TABLE, 'kos_task_table' +pubsym TASK_BASE, 'kos_task_base' +pubsym TASK_DATA, 'kos_task_data' +pubsym SLOT_BASE, 'kos_slot_base' +pubsym window_data, 'kos_window_data' -public WIN_STACK as 'kos_win_stack' -public WIN_POS as 'kos_win_pos' -public lfb_base as 'kos_lfb_base' +pubsym WIN_STACK, 'kos_win_stack' +pubsym WIN_POS, 'kos_win_pos' +pubsym lfb_base, 'kos_lfb_base' -public RAMDISK as 'kos_ramdisk' -public ramdisk_init as 'kos_ramdisk_init' +pubsym RAMDISK, 'kos_ramdisk' +pubsym ramdisk_init, 'kos_ramdisk_init' -public enable_acpi -public acpi.call_name -public acpi_ssdt_cnt as 'kos_acpi_ssdt_cnt' -public acpi_ssdt_base as 'kos_acpi_ssdt_base' -public acpi_ssdt_size as 'kos_acpi_ssdt_size' -public acpi_ctx -public acpi_usage as 'kos_acpi_usage' -public acpi_node_alloc_cnt as 'kos_acpi_node_alloc_cnt' -public acpi_node_free_cnt as 'kos_acpi_node_free_cnt' -public acpi.count_nodes as 'kos_acpi_count_nodes' +pubsym enable_acpi, no_mangle +pubsym acpi.call_name, no_mangle +pubsym acpi_ssdt_cnt, 'kos_acpi_ssdt_cnt' +pubsym acpi_ssdt_base, 'kos_acpi_ssdt_base' +pubsym acpi_ssdt_size, 'kos_acpi_ssdt_size' +pubsym acpi_ctx +pubsym acpi_usage, 'kos_acpi_usage' +pubsym acpi_node_alloc_cnt, 'kos_acpi_node_alloc_cnt' +pubsym acpi_node_free_cnt, 'kos_acpi_node_free_cnt' +pubsym acpi.count_nodes, 'kos_acpi_count_nodes', 4 -public stack_init as 'kos_stack_init' -public net_add_device +pubsym stack_init, 'kos_stack_init' +pubsym net_add_device -public draw_data -public img_background -public mem_BACKGROUND -public sys_background -public REDRAW_BACKGROUND as 'kos_redraw_background' -public new_sys_threads as 'kos_new_sys_threads' -public osloop as 'kos_osloop' -public set_mouse_data as 'kos_set_mouse_data' -public scheduler_current as 'kos_scheduler_current' -public kos_eth_input -public net_buff_alloc as 'kos_net_buff_alloc' +pubsym draw_data +pubsym img_background +pubsym mem_BACKGROUND +pubsym sys_background +pubsym REDRAW_BACKGROUND, 'kos_redraw_background' +pubsym new_sys_threads, 'kos_new_sys_threads', no_mangle +pubsym osloop, 'kos_osloop' +pubsym set_mouse_data, 'kos_set_mouse_data', 20 +pubsym scheduler_current, 'kos_scheduler_current' +pubsym kos_eth_input +pubsym net_buff_alloc, 'kos_net_buff_alloc', 4 -public mem_block_list -public pci_root as "kos_pci_root" +pubsym mem_block_list +pubsym pci_root, "kos_pci_root" -public acpi.aml.init as "kos_acpi_aml_init" -public acpi_root as "kos_acpi_root" -public aml._.attach as "kos_aml_attach" -public acpi.fill_pci_irqs as "kos_acpi_fill_pci_irqs" -public pci.walk_tree as "kos_pci_walk_tree" -public acpi.aml.new_thread as "kos_acpi_aml_new_thread" -public aml._.alloc_node as "kos_aml_alloc_node" -public aml._.constructor.integer as "kos_aml_constructor_integer" -public aml._.constructor.package as "kos_aml_constructor_package" -public acpi._.lookup_node as "kos_acpi_lookup_node" -public acpi._.print_tree as "kos_acpi_print_tree" -public acpi_dev_data as "kos_acpi_dev_data" -public acpi_dev_size as "kos_acpi_dev_size" -public acpi_dev_next as "kos_acpi_dev_next" -public kernel_alloc as "kos_kernel_alloc" +pubsym acpi.aml.init, "kos_acpi_aml_init" +pubsym acpi_root, "kos_acpi_root" +pubsym aml._.attach, "kos_aml_attach" +pubsym acpi.fill_pci_irqs, "kos_acpi_fill_pci_irqs" +pubsym pci.walk_tree, "kos_pci_walk_tree", 16 +pubsym acpi.aml.new_thread, "kos_acpi_aml_new_thread" +pubsym aml._.alloc_node, "kos_aml_alloc_node" +pubsym aml._.constructor.integer, "kos_aml_constructor_integer" +pubsym aml._.constructor.package, "kos_aml_constructor_package" +pubsym acpi._.lookup_node, "kos_acpi_lookup_node" +pubsym acpi._.print_tree, "kos_acpi_print_tree" +pubsym acpi_dev_data, "kos_acpi_dev_data" +pubsym acpi_dev_size, "kos_acpi_dev_size" +pubsym acpi_dev_next, "kos_acpi_dev_next" +pubsym kernel_alloc, "kos_kernel_alloc" -public window._.set_screen as 'kos_window_set_screen' -public _display as 'kos_display' +pubsym window._.set_screen, 'kos_window_set_screen' +pubsym _display, 'kos_display' -public BOOT as 'kos_boot' +pubsym BOOT, 'kos_boot' macro cli { pushfd @@ -130,8 +192,12 @@ include 'macros.inc' macro diff16 msg,blah2,blah3 { if msg eq "end of .data segment" -; fasm doesn't align on 65536, but ld script does -section '.bss.aligned65k' writeable align 65536 + if defined WIN32 + section '.bss.8k' writeable align 8192 + else + ; fasm doesn't align on 65536, but ld script does + section '.bss.aligned65k' writeable align 65536 + end if bss_base: end if } @@ -328,7 +394,7 @@ proc umka._.check_alignment ret endp -public i40_asm +pubsym i40_asm ;void i40_asm(uint32_t _eax, ; uint32_t _ebx, @@ -359,7 +425,7 @@ i40_asm: pop ebp edi esi edx ecx ebx eax ret -public set_eflags_tf +pubsym set_eflags_tf proc set_eflags_tf c uses ebx esi edi ebp, tf mov ecx, [tf] @@ -581,7 +647,7 @@ proc umka_init c uses ebx esi edi ebp ret endp -public skin_udata +pubsym skin_udata proc idle uses ebx esi edi .loop: mov ecx, 10000000 @@ -593,7 +659,7 @@ proc idle uses ebx esi edi ret endp -extrn pci_read +extrn pci_read, 20 proc pci_read_reg uses ebx esi edi mov ecx, eax and ecx, 3 @@ -617,6 +683,14 @@ endp proc sys_msg_board cmp cl, 0x0d jz @f +if defined WIN32 + extrn putchar + pushad + push ecx + call putchar + pop ecx + popad +else pushad mov eax, SYS_WRITE mov ebx, STDOUT @@ -626,6 +700,7 @@ proc sys_msg_board int 0x80 pop ecx popad +end if @@: ret endp @@ -635,13 +710,13 @@ proc delay_ms ret endp -public umka_cli +pubsym umka_cli proc umka_cli cli ; macro ret endp -public umka_sti +pubsym umka_sti proc umka_sti sti ; macro ret @@ -649,7 +724,7 @@ endp extrn reset_procmask extrn get_fake_if -public irq0 +pubsym irq0 proc irq0 c, _signo, _info, _context DEBUGF 2, "### irq0\n" pushfd @@ -813,11 +888,15 @@ restore sys_msg_board,delay_ms coverage_end: -; fasm doesn't align on 65536, but ld script does -section '.data.aligned65k' writeable align 65536 -public umka_tool +if defined WIN32 + section '.data.8k' writeable align 8192 +else + ; fasm doesn't align on 65536, but ld script does + section '.data.aligned65k' writeable align 65536 +end if +pubsym umka_tool umka_tool dd ? -public umka_initialized +pubsym umka_initialized umka_initialized dd 0 fpu_owner dd ? diff --git a/umka.h b/umka.h index 5a0fc52..4e6c4db 100644 --- a/umka.h +++ b/umka.h @@ -3,7 +3,15 @@ #include #include + +// TODO: Cleanup +#ifndef _WIN32 #include // for irq0: siginfo_t +#else +typedef int32_t ssize_t; +typedef int64_t off_t; +#define PATH_MAX 255 +#endif #define STDCALL __attribute__((__stdcall__)) @@ -397,7 +405,7 @@ __attribute__((__noreturn__)) void kos_osloop(void); void -irq0(int signo, siginfo_t *info, void *context); +irq0(int signo, void *info, void *context); void umka_init(void); diff --git a/umka_shell.c b/umka_shell.c index 5d0c999..fb524a7 100644 --- a/umka_shell.c +++ b/umka_shell.c @@ -16,15 +16,11 @@ along with this program. If not, see . */ -#include #include #include #include #include #include -#include -#include -#include #include "shell.h" #include "umka.h" #include "trace.h" diff --git a/vdisk.c b/vdisk.c index 605a91c..1cba7e2 100644 --- a/vdisk.c +++ b/vdisk.c @@ -7,6 +7,11 @@ #include "trace.h" #include "vdisk.h" +#ifdef _WIN32 +#define fseeko _fseeki64 +#define ftello _ftelli64 +#endif + typedef struct { FILE *file; uint32_t sect_size; @@ -16,7 +21,7 @@ typedef struct { } vdisk_t; void *vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size) { - FILE *f = fopen(fname, "r+"); + FILE *f = fopen(fname, "rb+"); if (!f) { printf("vdisk: can't open file '%s': %s\n", fname, strerror(errno)); return NULL; diff --git a/vnet.c b/vnet.c index b00cb0b..ea474b2 100644 --- a/vnet.c +++ b/vnet.c @@ -1,13 +1,18 @@ #include #include #include -#include #include #include +#include #include "umka.h" #include "trace.h" #include "vnet.h" +// TODO: Cleanup +#ifndef _WIN32 +#include +#endif + typedef struct { int fd; } vnet_userdata_t; @@ -65,6 +70,10 @@ static void dump_net_buff(net_buff_t *buf) { STDCALL int vnet_transmit(net_buff_t *buf) { + // TODO: Separate implementations for win32 and linux +#ifdef _WIN32 + assert(!"Function is not implemented for win32"); +#else net_device_t *vnet; __asm__ __inline__ __volatile__ ( "nop" @@ -80,6 +89,7 @@ vnet_transmit(net_buff_t *buf) { COVERAGE_OFF(); COVERAGE_ON(); printf("vnet_transmit: done\n"); +#endif return 0; } diff --git a/win32/pci.c b/win32/pci.c new file mode 100755 index 0000000..5b06210 --- /dev/null +++ b/win32/pci.c @@ -0,0 +1,12 @@ +#include "pci.h" + +#include + +char pci_path[PATH_MAX] = "."; + +__attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev, + uint32_t fun, uint32_t offset, + size_t len) { + printf("STUB: %s:%d", __FILE__, __LINE__); + return 0xffffffff; +} diff --git a/win32/pci.h b/win32/pci.h new file mode 100755 index 0000000..92ebb42 --- /dev/null +++ b/win32/pci.h @@ -0,0 +1,8 @@ +#ifndef PCI_H_INCLUDED +#define PCI_H_INCLUDED + +#define PATH_MAX 255 + +extern char pci_path[PATH_MAX]; + +#endif // PCI_H_INCLUDED diff --git a/win32/thread.c b/win32/thread.c new file mode 100755 index 0000000..d0bdff2 --- /dev/null +++ b/win32/thread.c @@ -0,0 +1,8 @@ +void reset_procmask(void) { + printf("STUB: %s:%d", __FILE__, __LINE__); +} + +int get_fake_if(void *ctx) { + printf("STUB: %s:%d", __FILE__, __LINE__); + return 0; +}