From d82c5530ed3871c3b123bfb764834cae2367bc4f Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Sat, 25 Jun 2022 02:41:23 +0400 Subject: [PATCH] Wrap fs_execute, works for umka_os tool! --- .gitignore | 3 +- apps/board_cycle.asm | 30 +++++++++ apps/{hello_board.asm => board_hello.asm} | 0 apps/makefile | 4 +- img/makefile | 1 + shell.c | 17 +++++ test/053_#userevent_all.ref.log | 5 ++ test/053_#userevent_all.t | 3 + umka.asm | 3 +- umka.h | 58 ++++++++++++++++- umka_os.c | 78 ++++++++++------------- umka_ping.c | 52 --------------- 12 files changed, 151 insertions(+), 103 deletions(-) create mode 100644 apps/board_cycle.asm rename apps/{hello_board.asm => board_hello.asm} (100%) create mode 100644 test/053_#userevent_all.ref.log create mode 100644 test/053_#userevent_all.t diff --git a/.gitignore b/.gitignore index 2f5bac2..501d65e 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,5 @@ t.d *.exe colors.dtp .tup -hello_board +board_hello +board_cycle diff --git a/apps/board_cycle.asm b/apps/board_cycle.asm new file mode 100644 index 0000000..43f6a84 --- /dev/null +++ b/apps/board_cycle.asm @@ -0,0 +1,30 @@ +use32 + org 0 + db 'MENUET01' + dd 1, start, i_end, e_end, e_end, 0, 0 + +__DEBUG__ = 1 +__DEBUG_LEVEL__ = 1 + +include 'proc32.inc' +include 'macros.inc' +include 'debug-fdo.inc' + +EFLAGS.ID = 1 SHL 21 + +start: + pushfd + btr dword[esp], BSF EFLAGS.ID + popfd +@@: + mcall 63, 1, '*' + jmp @b +exit: + mcall 18, 9, 2 + mcall -1 + mcall -2 ; just to check it's unreachable + +;include_debug_strings +i_end: +rb 0x100 ;stack +e_end: diff --git a/apps/hello_board.asm b/apps/board_hello.asm similarity index 100% rename from apps/hello_board.asm rename to apps/board_hello.asm diff --git a/apps/makefile b/apps/makefile index 69b6aea..6d21e8f 100644 --- a/apps/makefile +++ b/apps/makefile @@ -11,7 +11,7 @@ else $(error your OS is not supported) endif -all: hello_board +all: board_hello board_cycle %: %.asm $(FASM) $< $@ @@ -20,4 +20,4 @@ all: hello_board .PHONY: all clean clean: - rm -f hello_board + rm -f board_hello board_cycle diff --git a/img/makefile b/img/makefile index dfd63de..243287d 100644 --- a/img/makefile +++ b/img/makefile @@ -25,6 +25,7 @@ kolibri.img: ../default.skn ../fill.cur mcopy -vmoi $@ ../default.skn ::DEFAULT.SKN mcopy -vmoi $@ ../fill.cur ::FILL.CUR mcopy -vmoi $@ ../spray.cur ::SPRAY.CUR + mcopy -vmoi $@ ../apps/board_cycle ::LOADER mmd -i $@ ::LIB mcopy -vmoi $@ ../network.obj ::LIB/NETWORK.OBJ diff --git a/shell.c b/shell.c index 427bc52..a875b0c 100644 --- a/shell.c +++ b/shell.c @@ -1054,6 +1054,22 @@ cmd_process_info(struct shell_ctx *ctx, int argc, char **argv) { printf("wnd_state: 0x%.2" PRIx8 "\n", info.wnd_state); } +static void +cmd_check_for_event(struct shell_ctx *ctx, int argc, char **argv) { + (void)ctx; + (void)argv; + const char *usage = \ + "usage: check_for_event"; + if (argc != 1) { + puts(usage); + return; + } + COVERAGE_ON(); + uint32_t event = umka_sys_check_for_event(); + COVERAGE_OFF(); + printf("%" PRIu32 "\n", event); +} + static void cmd_display_number(struct shell_ctx *ctx, int argc, char **argv) { (void)ctx; @@ -3703,6 +3719,7 @@ func_table_t cmd_cmds[] = { { "stat70", cmd_stat70 }, { "stat80", cmd_stat80 }, { "var", cmd_var }, + { "check_for_event", cmd_check_for_event }, { "window_redraw", cmd_window_redraw }, { "write_text", cmd_write_text }, { "switch_to_thread", cmd_switch_to_thread }, diff --git a/test/053_#userevent_all.ref.log b/test/053_#userevent_all.ref.log new file mode 100644 index 0000000..dd501aa --- /dev/null +++ b/test/053_#userevent_all.ref.log @@ -0,0 +1,5 @@ +/> umka_init +/> check_for_event +0 +/> check_for_event +0 diff --git a/test/053_#userevent_all.t b/test/053_#userevent_all.t new file mode 100644 index 0000000..882c32f --- /dev/null +++ b/test/053_#userevent_all.t @@ -0,0 +1,3 @@ +umka_init +check_for_event +check_for_event diff --git a/umka.asm b/umka.asm index b576896..a8df4d1 100644 --- a/umka.asm +++ b/umka.asm @@ -79,6 +79,7 @@ UMKA_OS = 3 UMKA_MEMORY_BYTES = 256 SHL 20 +pubsym fs_execute, 'kos_fs_execute' pubsym set_keyboard_data, 'kos_set_keyboard_data' pubsym KEY_COUNT as 'kos_key_count' pubsym KEY_BUFF as 'kos_key_buff' @@ -733,7 +734,7 @@ proc idle uses ebx esi edi mov ecx, 10000000 @@: loop @b -; DEBUGF 1, "1 idle\n" + DEBUGF 1, "1 idle\n" jmp .loop ret diff --git a/umka.h b/umka.h index d0afc7d..86a5c7f 100644 --- a/umka.h +++ b/umka.h @@ -3,6 +3,7 @@ #include #include +#include #include #define UMKA_PATH_MAX 4096 @@ -41,6 +42,17 @@ enum kos_lang { #define BDFE_LEN_CP866 304 #define BDFE_LEN_UNICODE 560 +#define EVENT_REDRAW 0x0001 +#define EVENT_KEY 0x0002 +#define EVENT_BUTTON 0x0004 +#define EVENT_BACKGROUND 0x0010 +#define EVENT_MOUSE 0x0020 +#define EVENT_IPC 0x0040 +#define EVENT_NETWORK 0x0080 +#define EVENT_DEBUG 0x0100 +#define EVENT_NETWORK2 0x0200 +#define EVENT_EXTENDED 0x0400 + struct point16s { int16_t y, x; }; @@ -164,8 +176,8 @@ enum { typedef struct lhead lhead_t; struct lhead { - lhead_t *next; - lhead_t *prev; + void *next; + void *prev; }; typedef struct { @@ -529,6 +541,26 @@ umka_mouse_move(int lbheld, int mbheld, int rbheld, int xabs, int32_t xmoving, STDCALL net_buff_t * kos_net_buff_alloc(size_t size); +static inline int32_t +umka_fs_execute(const char *filename) { +// edx Flags +// ecx Commandline +// ebx Absolute file path +// eax String length + int32_t result; + __asm__ __inline__ __volatile__ ( + "push %%ebp;" + "call kos_fs_execute;" + "pop %%ebp" + : "=a"(result) + : "a"(strlen(filename)), + "b"(filename), + "c"(NULL), + "d"(0) + : "memory"); + return result; +} + static inline size_t umka_new_sys_threads(uint32_t flags, void (*entry)(), void *stack) { size_t tid; @@ -1094,6 +1126,28 @@ umka_sys_process_info(int32_t pid, void *param) { : "memory"); } +static inline uint32_t +umka_sys_wait_for_event() { + uint32_t event; + __asm__ __inline__ __volatile__ ( + "call i40" + : "=a"(event) + : "a"(10) + : "memory"); + return event; +} + +static inline uint32_t +umka_sys_check_for_event() { + uint32_t event; + __asm__ __inline__ __volatile__ ( + "call i40" + : "=a"(event) + : "a"(11) + : "memory"); + return event; +} + static inline void umka_sys_window_redraw(int begin_end) { __asm__ __inline__ __volatile__ ( diff --git a/umka_os.c b/umka_os.c index 74cffc4..56842a3 100644 --- a/umka_os.c +++ b/umka_os.c @@ -43,9 +43,9 @@ static void monitor(void) { umka_sti(); fprintf(stderr, "Start monitor thread\n"); + __asm__ __inline__ __volatile__ ("jmp $"); } -void umka_thread_ping(void); void umka_thread_net_drv(void); struct itimerval timeout = {.it_value = {.tv_sec = 0, .tv_usec = 10000}, @@ -53,53 +53,27 @@ struct itimerval timeout = {.it_value = {.tv_sec = 0, .tv_usec = 10000}, static void thread_start(int is_kernel, void (*entry)(void), size_t stack_size) { + fprintf(stderr, "### thread_start: %p\n", (void*)(uintptr_t)entry); uint8_t *stack = malloc(stack_size); umka_new_sys_threads(is_kernel, entry, stack + stack_size); } -/* -can't get pty working -may be because of my custom threads and blocking, don't know -void new_monitor(void) { - umka_sti(); - fprintf(stderr, "Start monitor thread\n"); - - int mpty = posix_openpt(O_RDWR | O_NOCTTY); - if (mpty == -1) { - perror("open master pty"); - return; +static void +dump_procs() { + for (int i = 0; i < NR_SCHED_QUEUES; i++) { + printf("sched queue #%i:", i); + appdata_t *p_begin = kos_scheduler_current[i]; + appdata_t *p = p_begin; + do { + printf(" %p", (void*)p); + p = p->in_schedule.next; + } while (p != p_begin); + putchar('\n'); } - if (grantpt(mpty) == -1) { - perror("grantpt"); - return; - } - if (unlockpt(mpty) == -1) { - perror("unlockpt"); - return; - } - char *spty_name = ptsname(mpty); - if (spty_name == NULL) { - perror("open slave pty"); - return; - } - fprintf(stderr, "[os] pty=%s\n", spty_name); - FILE *fmpty = fdopen(mpty, "r+"); - if (fmpty == NULL) { - perror("fdopen mpty"); - return; - } - run_test(ctx); } -*/ - -struct app_menuet { - char signature[8]; // MENUETXX - uint32_t version; // 1 - void (*start) (void); // start -}; int -load_app(const char *fname, void *base) { +load_app_host(const char *fname, void *base) { FILE *f = fopen(fname, "r"); if (!f) { perror("Can't open app file"); @@ -116,6 +90,14 @@ load_app(const char *fname, void *base) { return 0; } +int +load_app(const char *fname) { + int32_t result = umka_fs_execute(fname); + printf("result: %" PRIi32 "\n", result); + + return result; +} + void handle_i40(int signo, siginfo_t *info, void *context) { (void)signo; (void)info; @@ -164,8 +146,6 @@ main() { exit(1); } - load_app("../apps/hello_board", app_base); - printf("pid=%d, kos_lfb_base=%p\n", getpid(), (void*)kos_lfb_base); kos_boot.bpp = 32; @@ -174,12 +154,20 @@ main() { kos_boot.pitch = UMKA_DEFAULT_DISPLAY_WIDTH*4; // 32bpp umka_init(); + dump_procs(); umka_stack_init(); + FILE *f = fopen("../img/kolibri.img", "r"); + fread(kos_ramdisk, 2880*512, 1, f); + fclose(f); + kos_ramdisk_init(); + load_app_host("../apps/board_cycle", app_base); + load_app("/rd/1/loader"); + thread_start(0, monitor, THREAD_STACK_SIZE); - thread_start(0, umka_thread_net_drv, THREAD_STACK_SIZE); - thread_start(0, ((struct app_menuet*)app_base)->start, THREAD_STACK_SIZE); -// thread_start(0, umka_thread_ping, THREAD_STACK_SIZE); +// thread_start(0, umka_thread_net_drv, THREAD_STACK_SIZE); + + dump_procs(); setitimer(ITIMER_PROF, &timeout, NULL); diff --git a/umka_ping.c b/umka_ping.c index 917b5cc..373a32e 100644 --- a/umka_ping.c +++ b/umka_ping.c @@ -40,11 +40,6 @@ #include "umka.h" #include "vnet.h" -uint8_t packet[4096] = {0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 0x77, 'a','b', - 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', - 'y', 'z', '0', '1', '2', '3', '4', '5'}; - static int tap_alloc(char *dev) { int flags = IFF_TAP | IFF_NO_PI; @@ -79,51 +74,6 @@ tap_alloc(char *dev) { return fd; } -int go_ping = 0; - -void -umka_thread_ping(void) { - umka_sti(); - fprintf(stderr, "[ping] starting\n"); - while (!go_ping) { /* wait until initialized */ } - - f75ret_t r75; - r75 = umka_sys_net_open_socket(AF_INET4, SOCK_STREAM, IPPROTO_TCP); - if (r75.value == (uint32_t)-1) { - fprintf(stderr, "[ping] open error %u\n", r75.errorcode); - exit(1); - } - uint32_t sockfd = r75.value; - -// uint32_t addr = inet_addr("127.0.0.1"); -// uint32_t addr = inet_addr("192.243.108.5"); - uint32_t addr = inet_addr("10.50.0.1"); -// uint32_t addr = inet_addr("192.168.1.30"); - uint16_t port = 5000; - - struct sockaddr_in sa; - memset(&sa, 0, sizeof(sa)); - sa.sin_family = AF_INET4; - sa.sin_port = htons(port); - sa.sin_addr.s_addr = addr; - - r75 = umka_sys_net_connect(sockfd, &sa, sizeof(struct sockaddr_in)); - if (r75.value == (uint32_t)-1) { - fprintf(stderr, "[ping] connect error %u\n", r75.errorcode); - return; - } - - r75 = umka_sys_net_send(sockfd, packet, 128, 0); - if (r75.value == (uint32_t)-1) { - fprintf(stderr, "[ping] send error %u\n", r75.errorcode); - return; - } - - while (true) {} - - return; -} - void umka_thread_net_drv(void) { umka_sti(); @@ -170,8 +120,6 @@ umka_thread_net_drv(void) { return; } - go_ping = 1; - while(true) { plen = read(tapfd, buffer, 2*1024);