From 94ebe027396945dde9fd3841388e1c18cd0ba21b Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Sat, 21 Jan 2023 07:49:13 +0000 Subject: [PATCH] Switch to the wall clock timer, communicate via shared memory --- apps/readdir.asm | 26 ++++++++++++++++++++++++-- makefile | 26 +++++++++++++++++++------- system.inc | 2 +- umka.asm | 7 +++---- umka_os.c | 39 +++++++++++++++++++++++++++++++-------- 5 files changed, 78 insertions(+), 22 deletions(-) diff --git a/apps/readdir.asm b/apps/readdir.asm index af4c98f..662c154 100644 --- a/apps/readdir.asm +++ b/apps/readdir.asm @@ -17,6 +17,8 @@ start: btr dword[esp], BSF EFLAGS.ID popfd + mcall 68, 11 + mcall 12, 1 mcall 0, <100,200>, <100,100>, 0x34888888, , window_title mcall 12, 2 @@ -25,13 +27,33 @@ start: mcall 70, fs70 DEBUGF 1, "files in dir: %d\n", ebx + mcall 15, 1, 2, 2 + mcall 15, 4, 1 + mcall 15, 6 + mov ecx, 0 + mov edx, 0xff + mov [eax+0], cl + mov [eax+1], cl + mov [eax+2], cl + mov [eax+3], dl + mov [eax+4], dl + mov [eax+5], dl + mov [eax+6], dl + mov [eax+7], dl + mov [eax+8], dl + mov [eax+9], cl + mov [eax+10], cl + mov [eax+11], cl + mcall 15, 7, eax + mcall 15, 3 + mcall 18, 19, 4, 0 .next: mcall 37, 0 - add eax, 0x00020002 + add eax, 0x00010001 mov edx, eax mcall 18, 19, 4 - mcall 5, 1 + mcall 5, 10 ; mov ecx, 0x1000000 ; loopnz $ jmp .next diff --git a/makefile b/makefile index e09e516..6e099fb 100644 --- a/makefile +++ b/makefile @@ -41,8 +41,8 @@ else endif ifeq ($(HOST),linux) -all: umka_shell umka_fuse umka_os umka_gen_devices_dat umka.sym umka.prp \ - umka.lst tags default.skn skin.skn +all: umka_shell umka_fuse umka_os umka_monitor umka_gen_devices_dat umka.sym \ + umka.prp umka.lst tags default.skn skin.skn else ifeq ($(HOST),windows) all: umka_shell umka.sym umka.prp \ umka.lst default.skn skin.skn @@ -58,7 +58,7 @@ test: umka_shell umka_shell: umka_shell.o umka.o shell.o trace.o trace_lbr.o vdisk.o \ vdisk/raw.o vdisk/qcow2.o vdisk/miniz/miniz.a vnet.o lodepng.o \ $(HOST)/pci.o $(HOST)/thread.o io.o $(HOST)/io_async.o util.o \ - optparse.o bestline.o + optparse32.o bestline32.o $(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o vdisk/raw.o \ @@ -68,9 +68,12 @@ 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 bestline.o optparse.o + $(HOST)/thread.o io.o $(HOST)/io_async.o util.o bestline32.o optparse32.o $(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld +umka_monitor: umka_monitor.o optparse.o bestline.o + $(CC) $(LDFLAGS) `sdl2-config --libs` $^ -o $@ + umka_gen_devices_dat: umka_gen_devices_dat.o umka.o $(HOST)/pci.o \ $(HOST)/thread.o util.o $(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld @@ -96,11 +99,17 @@ $(HOST)/pci.o: $(HOST)/pci.c 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 $@ + bestline.o: bestline.c bestline.h - $(CC) $(CFLAGS_32) -U_POSIX_C_SOURCE -Wno-logical-op -Wno-switch-enum -c $< + $(CC) $(CFLAGS) -U_POSIX_C_SOURCE -Wno-logical-op -Wno-switch-enum -c $< -o $@ + +optparse32.o: optparse.c optparse.h + $(CC) $(CFLAGS_32) -c $< -o $@ optparse.o: optparse.c optparse.h - $(CC) $(CFLAGS_32) -c $< + $(CC) $(CFLAGS) -c $< -o $@ util.o: util.c util.h umka.h $(CC) $(CFLAGS_32) -c $< @@ -162,9 +171,12 @@ umka_shell.o: umka_shell.c umka.h trace.h umka_fuse.o: umka_fuse.c umka.h $(CC) $(CFLAGS_32) `pkg-config fuse3 --cflags` -c $< -umka_os.o: umka_os.c umka.h +umka_os.o: umka_os.c umka.h umka_os.h $(CC) $(CFLAGS_32) -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/system.inc b/system.inc index 12a8248..a65ae07 100644 --- a/system.inc +++ b/system.inc @@ -3,7 +3,7 @@ SYS_READ = 3 SYS_WRITE = 4 SYS_OPEN = 5 SYS_CLOSE = 6 -;SYS_LSEEK = 19 +SYS_PAUSE = 29 SYS_LLSEEK = 140 SEEK_SET = 0 diff --git a/umka.asm b/umka.asm index 50f098d..2ff8508 100644 --- a/umka.asm +++ b/umka.asm @@ -803,12 +803,11 @@ endp pubsym skin_udata proc idle uses ebx esi edi sti -.loop: - mov ecx, 10000000 @@: - loop @b ; DEBUGF 1, "1 idle\n" - jmp .loop + movi eax, SYS_PAUSE + int 0x80 + jmp @b ret endp diff --git a/umka_os.c b/umka_os.c index 5583be8..8e481d3 100644 --- a/umka_os.c +++ b/umka_os.c @@ -2,7 +2,7 @@ SPDX-License-Identifier: GPL-2.0-or-later UMKa - User-Mode KolibriOS developer tools - umka_os - kind of KolibriOS rump kernel + umka_os - kind of KolibriOS anykernel Copyright (C) 2018-2023 Ivan Baravy */ @@ -25,6 +25,7 @@ #include #include #include "umka.h" +#include "umka_os.h" #include "optparse.h" #include "shell.h" #include "trace.h" @@ -168,13 +169,15 @@ hw_int(int signo, siginfo_t *info, void *context) { int main(int argc, char *argv[]) { (void)argc; - const char *usage = "umka_os [-i ] [-o ]\n"; + const char *usage = "umka_os [-i ] [-o ] [-s ]\n"; if (coverage) { trace_begin(); } umka_sti(); + const char *shname = "/umka"; + int shfd = 0; const char *infile = NULL, *outfile = NULL; build_history_filename(); @@ -182,7 +185,7 @@ main(int argc, char *argv[]) { int opt; optparse_init(&options, argv); - while ((opt = optparse(&options, "i:o:")) != -1) { + while ((opt = optparse(&options, "i:o:s:")) != -1) { switch (opt) { case 'i': infile = options.optarg; @@ -190,6 +193,9 @@ main(int argc, char *argv[]) { case 'o': outfile = options.optarg; break; + case 's': + shname = options.optarg; + break; default: fprintf(stderr, "bad option: %c\n", opt); fputs(usage, stderr); @@ -197,6 +203,13 @@ main(int argc, char *argv[]) { } } + if (shname) { + shfd = shm_open(shname, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); + if (!shfd) { + perror("[!] can't open shared memory"); + exit(1); + } + } if (infile && !freopen(infile, "r", stdin)) { fprintf(stderr, "[!] can't open file for reading: %s\n", infile); exit(1); @@ -213,8 +226,8 @@ main(int argc, char *argv[]) { sigemptyset(&sa.sa_mask); sa.sa_flags = SA_SIGINFO; - if (sigaction(SIGPROF, &sa, NULL) == -1) { - fprintf(stderr, "Can't install SIGPROF handler!\n"); + if (sigaction(SIGALRM, &sa, NULL) == -1) { + fprintf(stderr, "Can't install SIGALRM handler!\n"); return 1; } @@ -252,13 +265,23 @@ main(int argc, char *argv[]) { exit(1); } - printf("pid=%d, kos_lfb_base=%p\n", getpid(), (void*)kos_lfb_base); - kos_boot.bpp = UMKA_DEFAULT_DISPLAY_BPP; kos_boot.x_res = UMKA_DEFAULT_DISPLAY_WIDTH; kos_boot.y_res = UMKA_DEFAULT_DISPLAY_HEIGHT; kos_boot.pitch = UMKA_DEFAULT_DISPLAY_WIDTH * UMKA_DEFAULT_DISPLAY_BPP / 8; + struct shared_info sinfo = (struct shared_info) { + .pid = getpid(), + .lfb_base = (uintptr_t)kos_lfb_base, + .lfb_bpp = kos_boot.bpp, + .lfb_width = kos_boot.x_res, + .lfb_height = kos_boot.y_res, + .cmd_buf = (uintptr_t)cmd_buf, + }; + ftruncate(shfd, sizeof(sinfo)); + write(shfd, &sinfo, sizeof(sinfo)); +// printf("pid=%d, kos_lfb_base=%p\n", getpid(), (void*)kos_lfb_base); + run_test(ctx->shell); // umka_stack_init(); @@ -313,7 +336,7 @@ main(int argc, char *argv[]) { dump_procs(); - setitimer(ITIMER_PROF, &timeout, NULL); + setitimer(ITIMER_REAL, &timeout, NULL); ctx->umka->running = 1; umka_osloop(); // doesn't return