Implement common command buffer for the shell and os

This commit is contained in:
Ivan Baravy 2023-01-31 02:38:48 +00:00
parent 68cfb39f8d
commit d16177c36d
13 changed files with 285 additions and 234 deletions

View File

@ -57,7 +57,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 \
$(HOST)/pci.o $(HOST)/thread.o io.o $(HOST)/io_async.o umkart.o \
optparse32.o bestline32.o
$(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld
@ -68,11 +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 bestline32.o optparse32.o
$(HOST)/thread.o io.o $(HOST)/io_async.o umkart.o bestline32.o \
optparse32.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
$(HOST)/thread.o umkart.o
$(CC) $(LDFLAGS_32) $^ -o $@ -T umka.ld
umka.o umka.fas: umka.asm
@ -108,7 +109,7 @@ optparse32.o: optparse.c optparse.h
optparse.o: optparse.c optparse.h
$(CC) $(CFLAGS) -c $< -o $@
util.o: util.c util.h umka.h
umkart.o: umkart.c umkart.h umka.h
$(CC) $(CFLAGS_32) -c $<
default.skn: $(KOLIBRIOS)/skins/Leency/Shkvorka/default.asm colors.dtp
@ -168,7 +169,7 @@ 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.h
umka_os.o: umka_os.c umka.h
$(CC) $(CFLAGS_32) `sdl2-config --cflags` -c $<
umka_gen_devices_dat.o: umka_gen_devices_dat.c umka.h

316
shell.c

File diff suppressed because it is too large Load Diff

10
shell.h
View File

@ -11,6 +11,7 @@
#define SHELL_H_INCLUDED
#include <stdio.h>
#include <threads.h>
#include "umka.h"
#include "io.h"
@ -40,11 +41,15 @@ struct shell_ctx {
struct shell_var *var;
FILE *fin;
FILE *fout;
const int *running;
cnd_t cmd_done;
mtx_t cmd_mutex;
};
struct shell_ctx *
shell_init(int reproducible, const char *hist_file, struct umka_ctx *umka,
struct umka_io *io, FILE *fin, FILE *fout);
struct umka_io *io, FILE *fin, FILE *fout, const int *running);
void
shell_close(struct shell_ctx *shell);
@ -52,4 +57,7 @@ shell_close(struct shell_ctx *shell);
void *
run_test(struct shell_ctx *ctx);
void
umka_run_cmd_sync(struct shell_ctx *ctx);
#endif // SHELL_H_INCLUDED

View File

@ -1,3 +1,4 @@
; /usr/include/asm/unistd_32.h
SYS_EXIT = 1
SYS_READ = 3
SYS_WRITE = 4
@ -5,6 +6,7 @@ SYS_OPEN = 5
SYS_CLOSE = 6
SYS_PAUSE = 29
SYS_LLSEEK = 140
SYS_FUTEX = 240
SEEK_SET = 0
SEEK_CUR = 1

51
umka.h
View File

@ -588,14 +588,6 @@ STDCALL void
kos_set_mouse_data(uint32_t btn_state, int32_t xmoving, int32_t ymoving,
int32_t vscroll, int32_t hscroll);
static inline void
umka_mouse_move(int lbheld, int mbheld, int rbheld, int xabs, int32_t xmoving,
int yabs, int32_t ymoving, int32_t hscroll, int32_t vscroll) {
uint32_t btn_state = lbheld + (rbheld << 1) + (mbheld << 2) +
(yabs << 30) + (xabs << 31);
kos_set_mouse_data(btn_state, xmoving, ymoving, vscroll, hscroll);
}
STDCALL net_buff_t *
kos_net_buff_alloc(size_t size);
@ -2414,4 +2406,47 @@ umka_set_keyboard_data(uint32_t scancode) {
: "eax", "edx", "memory", "cc");
}
#define CMD_BUF_LEN 0x10
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;
};
#endif // UMKA_H_INCLUDED

View File

@ -24,7 +24,6 @@
#include <fcntl.h>
#include "io.h"
#include "vdisk.h"
#include "umka.h"
#define DIRENTS_TO_READ 100

View File

@ -17,7 +17,7 @@
#include <sys/types.h>
#include <unistd.h>
#include "umka.h"
#include "util.h"
#include "umkart.h"
#include <pci.h>
#define UMKA_DEFAULT_DISPLAY_WIDTH 400

View File

@ -8,13 +8,13 @@
*/
#include <arpa/inet.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <netinet/in.h>
#define __USE_GNU
#include <signal.h>
#include <stdatomic.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -30,8 +30,7 @@
#include <threads.h>
#include <SDL2/SDL.h>
#include "umka.h"
#include "util.h"
#include "umka_os.h"
#include "umkart.h"
#include "bestline.h"
#include "optparse.h"
#include "shell.h"
@ -42,8 +41,6 @@
#define THREAD_STACK_SIZE 0x100000
#define CMD_BUF_LEN 0x10000
struct umka_os_ctx {
struct umka_ctx *umka;
struct umka_io *io;
@ -53,8 +50,6 @@ struct umka_os_ctx {
struct umka_os_ctx *os;
uint8_t cmd_buf[CMD_BUF_LEN];
char history_filename[PATH_MAX];
static void
@ -89,7 +84,7 @@ umka_os_init(FILE *fin, FILE *fout, FILE *fboardlog) {
ctx->umka = umka_init();
ctx->io = io_init(&ctx->umka->running);
ctx->shell = shell_init(SHELL_LOG_NONREPRODUCIBLE, history_filename,
ctx->umka, ctx->io, fin, fout);
ctx->umka, ctx->io, fin, fout, &ctx->umka->running);
return ctx;
}
@ -101,15 +96,6 @@ void build_history_filename() {
sprintf(history_filename, "%s/%s", dir_name, HIST_FILE_BASENAME);
}
/*
static void
monitor(void) {
umka_sti();
fprintf(stderr, "Start monitor thread\n");
__asm__ __inline__ __volatile__ ("jmp $");
}
*/
void umka_thread_net_drv(void);
struct itimerval timeout = {.it_value = {.tv_sec = 0, .tv_usec = 10000},
@ -251,16 +237,29 @@ sdlthr(void *arg) {
return 0;
}
int
uint32_t
umka_run_cmd_wait_test(/* void *wait_param in ebx */) {
appdata_t *app;
__asm__ __volatile__ __inline__ ("":"=b"(app)::);
struct umka_cmd *cmd = (struct umka_cmd*)app->wait_param;
return (uint32_t)(atomic_load_explicit(&cmd->status, memory_order_acquire) == UMKA_CMD_STATUS_READY);
}
static void
umka_thread_cmd_runner() {
umka_sti();
while (1) {
kos_wait_events(umka_run_cmd_wait_test, umka_cmd_buf);
umka_run_cmd_sync(os->shell);
}
}
static int
umka_monitor(void *arg) {
(void)arg;
union sigval sval = (union sigval){.sival_int = 14};
pid_t mypid = getpid();
char *line;
while((line = bestline(">"))) {
sigqueue(mypid, SIGUSR2, sval);
}
os->shell->fin = stdin;
os->shell->fout = stdout;
run_test(os->shell);
return 0;
}
@ -445,16 +444,13 @@ main(int argc, char *argv[]) {
kos_attach_int_handler(14, hw_int_mouse, NULL);
// thread_start(0, monitor, THREAD_STACK_SIZE);
thread_start(1, umka_thread_board, THREAD_STACK_SIZE);
thread_start(1, umka_thread_cmd_runner, THREAD_STACK_SIZE);
kos_thread_t start = (kos_thread_t)(KOS_APP_BASE + app->menuet.start);
thread_start(0, start, THREAD_STACK_SIZE);
dump_procs();
fflush(stdin);
fflush(stdout);
fflush(stderr);
thrd_t thrd_monitor;
thrd_create(&thrd_monitor, umka_monitor, NULL);
@ -463,7 +459,7 @@ main(int argc, char *argv[]) {
setitimer(ITIMER_REAL, &timeout, NULL);
os->umka->running = 1;
atomic_store_explicit(&os->umka->running, 1, memory_order_release);
umka_osloop(); // doesn't return
if (coverage)

View File

@ -1,51 +0,0 @@
/*
SPDX-License-Identifier: GPL-2.0-or-later
UMKa - User-Mode KolibriOS developer tools
umka_os - kind of KolibriOS anykernel
Copyright (C) 2023 Ivan Baravy <dunkaist@gmail.com>
*/
#include "umka.h"
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;
};

View File

@ -1,4 +1,4 @@
umka_set_boot_params --bpp32
umka_set_boot_params --bpp 32
umka_boot
ramdisk_init ../img/kolibri.raw
set_skin /sys/DEFAULT.SKN

View File

@ -19,7 +19,6 @@
#include "optparse.h"
#include "shell.h"
#include "io.h"
#include "umka.h"
#include "trace.h"
#define HIST_FILE_BASENAME ".umka_shell.history"
@ -38,7 +37,7 @@ umka_shell_init(int reproducible, FILE *fin, FILE *fout) {
ctx->umka = umka_init();
ctx->io = io_init(&ctx->umka->running);
ctx->shell = shell_init(reproducible, history_filename, ctx->umka, ctx->io,
fin, fout);
fin, fout, &ctx->umka->running);
return ctx;
}

View File

@ -6,8 +6,11 @@
Copyright (C) 2021, 2023 Ivan Baravy <dunkaist@gmail.com>
*/
#include <stdatomic.h>
#include <stdio.h>
#include <threads.h>
#include "umka.h"
#include "shell.h"
struct devices_dat_entry {
uint8_t fun:3;
@ -20,7 +23,9 @@ struct devices_dat_entry {
uint32_t pad2;
};
STDCALL void*
struct umka_cmd umka_cmd_buf[CMD_BUF_LEN];
static STDCALL void*
dump_devices_dat_iter(struct pci_dev *node, void *arg) {
FILE *f = arg;
if (node->gsi) {
@ -73,7 +78,7 @@ copy_display_bpp24_to_rgb888(void *to) {
}
}
void
static void
copy_display_bpp32_to_rgb888(void *to) {
memcpy(to, kos_lfb_base, kos_display.width*kos_display.height*4);
}

View File

@ -9,6 +9,11 @@
#ifndef UTIL_H_INCLUDED
#define UTIL_H_INCLUDED
#include "umka.h"
#include "shell.h"
extern struct umka_cmd umka_cmd_buf[CMD_BUF_LEN];
void
dump_devices_dat(const char *filename);