Merge lfbview to umka_os

This commit is contained in:
Ivan Baravy 2023-01-28 02:57:08 +00:00
parent dc48e267d6
commit b5a345ad5f
3 changed files with 153 additions and 24 deletions

View File

@ -41,8 +41,8 @@ else
endif
ifeq ($(HOST),linux)
all: umka_shell umka_fuse umka_os umka_monitor umka_gen_devices_dat umka.sym \
umka.prp umka.lst tags default.skn skin.skn
all: umka_shell umka_fuse umka_os 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
@ -69,10 +69,10 @@ 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) $^ -o $@ -T umka.ld
$(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 $@
#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
@ -172,10 +172,10 @@ 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.h
$(CC) $(CFLAGS_32) -c $<
$(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_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 $<

120
umka_os.c
View File

@ -24,8 +24,13 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#define __USE_GNU
#include <sys/uio.h>
#include <threads.h>
#include <SDL2/SDL.h>
#include "umka.h"
#include "umka_os.h"
#include "bestline.h"
#include "optparse.h"
#include "shell.h"
#include "trace.h"
@ -41,6 +46,8 @@ struct umka_os_ctx {
struct shell_ctx *shell;
};
struct shared_info sinfo;
char history_filename[PATH_MAX];
static int
@ -166,18 +173,102 @@ hw_int(int signo, siginfo_t *info, void *context) {
umka_sti();
}
int
sdlthr(void *arg) {
(void)arg;
sigset_t set;
pthread_sigmask(SIG_BLOCK, NULL, &set);
pthread_sigmask(SIG_BLOCK, &set, NULL);
if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
fprintf(stderr, "Failed to initialize the SDL2 library\n");
return -1;
}
SDL_Window *window = SDL_CreateWindow("LFB Viewer SDL2",
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
sinfo.lfb_width, sinfo.lfb_height,
0);
if(!window)
{
fprintf(stderr, "Failed to create window\n");
return -1;
}
SDL_Surface *window_surface = SDL_GetWindowSurface(window);
if(!window_surface)
{
fprintf(stderr, "Failed to get the surface from the window\n");
return -1;
}
uint32_t *lfb = (uint32_t*)malloc(sinfo.lfb_width*sinfo.lfb_height*sizeof(uint32_t));
struct iovec remote = {.iov_base = (void*)(uintptr_t)sinfo.lfb_base,
.iov_len = sinfo.lfb_width*sinfo.lfb_height*4};
struct iovec local = {.iov_base = lfb,
.iov_len = sinfo.lfb_width*sinfo.lfb_height*4};
uint32_t *p = window_surface->pixels;
while (1) {
process_vm_readv(sinfo.pid, &local, 1, &remote, 1, 0);
memcpy(window_surface->pixels, lfb, 400*300*4);
SDL_LockSurface(window_surface);
for (ssize_t y = 0; y < window_surface->h; y++) {
for (ssize_t x = 0; x < window_surface->w; x++) {
p[y*window_surface->pitch/4+x] = lfb[y*400+x];
}
}
SDL_UnlockSurface(window_surface);
SDL_UpdateWindowSurface(window);
sleep(1);
}
return 0;
}
int
umka_monitor(void *arg) {
(void)arg;
sigset_t set;
pthread_sigmask(SIG_BLOCK, NULL, &set);
pthread_sigmask(SIG_BLOCK, &set, NULL);
/*
printf("read umka_os configuration:\n"
" pid: %d\n"
" lfb_base: %p\n"
" lfb_bpp: %u"
" lfb_width: %u"
" lfb_height: %u"
" cmd: %p\n",
(pid_t)sinfo.pid, (void*)(uintptr_t)sinfo.lfb_base, sinfo.lfb_bpp,
sinfo.lfb_width, sinfo.lfb_height, (void*)(uintptr_t)sinfo.cmd_buf);
*/
union sigval sval = (union sigval){.sival_int = 14};
while (1) {
// getchar();
// sigqueue(sinfo.pid, SIGUSR2, sval);
pause();
}
return 0;
}
int
main(int argc, char *argv[]) {
(void)argc;
const char *usage = "umka_os [-i <infile>] [-o <outfile>] [-s <shname>]\n";
const char *usage = "umka_os [-i <infile>] [-o <outfile>]\n";
if (coverage) {
trace_begin();
}
umka_sti();
const char *shname = "/umka";
int shfd = 0;
const char *infile = NULL, *outfile = NULL;
build_history_filename();
@ -193,9 +284,6 @@ 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);
@ -203,13 +291,6 @@ 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);
@ -270,7 +351,7 @@ main(int argc, char *argv[]) {
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) {
sinfo = (struct shared_info) {
.pid = getpid(),
.lfb_base = (uintptr_t)kos_lfb_base,
.lfb_bpp = kos_boot.bpp,
@ -278,8 +359,6 @@ main(int argc, char *argv[]) {
.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);
@ -336,6 +415,15 @@ main(int argc, char *argv[]) {
dump_procs();
fflush(stdin);
fflush(stdout);
fflush(stderr);
thrd_t thrd_monitor;
thrd_create(&thrd_monitor, umka_monitor, NULL);
thrd_t thrd_screen;
thrd_create(&thrd_screen, sdlthr, NULL);
setitimer(ITIMER_REAL, &timeout, NULL);
ctx->umka->running = 1;

View File

@ -7,6 +7,8 @@
Copyright (C) 2023 Ivan Baravy <dunkaist@gmail.com>
*/
#include "umka.h"
struct shared_info {
uint64_t pid;
uint32_t lfb_base;
@ -21,4 +23,43 @@ struct shared_info {
uint8_t cmd_buf[CMD_BUF_LEN];
enum {
UMKA_CMD_NONE,
UMKA_CMD_SET_MOUSE_DATA,
UMKA_CMD_SYS_PROCESS_INFO,
UMKA_CMD_SYS_GET_MOUSE_POS_SCREEN,
};
enum {
UMKA_CMD_STATUS_EMPTY,
UMKA_CMD_STATUS_READY,
UMKA_CMD_STATUS_DONE,
};
struct cmd_set_mouse_data {
uint32_t btn_state;
int32_t xmoving;
int32_t ymoving;
int32_t vscroll;
int32_t hscroll;
};
struct cmd_sys_process_info {
int32_t pid;
void *param;
};
struct cmd_ret_sys_get_mouse_pos_screen {
struct point16s pos;
};
struct umka_cmd {
uint32_t status;
uint32_t type;
union {
struct cmd_set_mouse_data set_mouse_data;
} arg;
union {
struct cmd_ret_sys_get_mouse_pos_screen sys_get_mouse_pos_screen;
} ret;
};