2021-11-03 15:28:03 +01:00
|
|
|
/*
|
2022-06-27 19:36:56 +02:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2021-11-03 15:28:03 +01:00
|
|
|
UMKa - User-Mode KolibriOS developer tools
|
2023-01-21 08:49:13 +01:00
|
|
|
umka_os - kind of KolibriOS anykernel
|
2021-11-03 15:28:03 +01:00
|
|
|
|
2023-01-17 01:49:11 +01:00
|
|
|
Copyright (C) 2018-2023 Ivan Baravy <dunkaist@gmail.com>
|
2021-11-03 15:28:03 +01:00
|
|
|
*/
|
|
|
|
|
2022-06-27 14:32:29 +02:00
|
|
|
#include <arpa/inet.h>
|
2023-01-30 07:24:23 +01:00
|
|
|
#include <errno.h>
|
2020-10-17 04:13:18 +02:00
|
|
|
#include <fcntl.h>
|
2023-01-16 03:50:19 +01:00
|
|
|
#include <limits.h>
|
2022-05-24 21:22:12 +02:00
|
|
|
#define __USE_GNU
|
2020-05-08 06:44:32 +02:00
|
|
|
#include <signal.h>
|
2023-01-31 03:38:48 +01:00
|
|
|
#include <stdatomic.h>
|
2020-05-08 06:44:32 +02:00
|
|
|
#include <stdio.h>
|
2020-05-10 06:21:49 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2022-05-24 21:22:12 +02:00
|
|
|
#define __USE_MISC
|
2020-10-12 05:02:02 +02:00
|
|
|
#include <sys/mman.h>
|
2020-05-10 06:21:49 +02:00
|
|
|
#include <sys/stat.h>
|
2020-05-08 06:44:32 +02:00
|
|
|
#include <sys/time.h>
|
2020-05-10 06:21:49 +02:00
|
|
|
#include <sys/types.h>
|
2023-01-28 03:57:08 +01:00
|
|
|
#include <SDL2/SDL.h>
|
2020-05-08 06:44:32 +02:00
|
|
|
#include "umka.h"
|
2023-01-31 03:38:48 +01:00
|
|
|
#include "umkart.h"
|
2020-05-10 06:21:49 +02:00
|
|
|
#include "shell.h"
|
2020-10-17 04:13:18 +02:00
|
|
|
#include "trace.h"
|
2022-06-27 14:32:29 +02:00
|
|
|
#include "vnet.h"
|
2023-02-05 08:32:43 +01:00
|
|
|
#include "isocline/include/isocline.h"
|
2023-02-05 00:41:26 +01:00
|
|
|
#include "optparse/optparse.h"
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2023-01-17 01:49:11 +01:00
|
|
|
#define HIST_FILE_BASENAME ".umka_os.history"
|
2021-11-03 15:28:03 +01:00
|
|
|
|
2023-02-02 17:25:20 +01:00
|
|
|
#define APP_MAX_MEM_SIZE 0x1000000
|
|
|
|
#define UMKA_LDR_BASE ((void*)0x1000000)
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2023-01-17 01:49:11 +01:00
|
|
|
struct umka_os_ctx {
|
|
|
|
struct umka_ctx *umka;
|
|
|
|
struct umka_io *io;
|
|
|
|
struct shell_ctx *shell;
|
2023-01-30 07:24:23 +01:00
|
|
|
FILE *fboardlog;
|
2023-01-17 01:49:11 +01:00
|
|
|
};
|
|
|
|
|
2023-01-30 07:24:23 +01:00
|
|
|
struct umka_os_ctx *os;
|
|
|
|
|
2023-01-16 03:50:19 +01:00
|
|
|
char history_filename[PATH_MAX];
|
|
|
|
|
2023-01-18 03:58:09 +01:00
|
|
|
static int
|
|
|
|
hw_int_mouse(void *arg) {
|
|
|
|
(void)arg;
|
|
|
|
kos_set_mouse_data(0, -50, 50, 0, 0);
|
|
|
|
return 1; // our interrupt
|
|
|
|
}
|
|
|
|
|
2023-01-17 01:49:11 +01:00
|
|
|
struct umka_os_ctx *
|
2023-02-05 08:32:43 +01:00
|
|
|
umka_os_init(FILE *fstartup, FILE *fboardlog) {
|
2023-01-17 01:49:11 +01:00
|
|
|
struct umka_os_ctx *ctx = malloc(sizeof(struct umka_os_ctx));
|
2023-01-30 07:24:23 +01:00
|
|
|
ctx->fboardlog = fboardlog;
|
2023-02-06 17:01:37 +01:00
|
|
|
ctx->umka = umka_init(UMKA_RUNNING_NOT_YET);
|
2023-01-18 09:29:08 +01:00
|
|
|
ctx->io = io_init(&ctx->umka->running);
|
2023-01-17 01:49:11 +01:00
|
|
|
ctx->shell = shell_init(SHELL_LOG_NONREPRODUCIBLE, history_filename,
|
2023-02-06 17:01:37 +01:00
|
|
|
ctx->umka, ctx->io, fstartup);
|
2023-01-17 01:49:11 +01:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2023-02-06 17:01:37 +01:00
|
|
|
static void
|
|
|
|
build_history_filename(void) {
|
2023-01-16 03:50:19 +01:00
|
|
|
const char *dir_name;
|
|
|
|
if (!(dir_name = getenv("HOME"))) {
|
|
|
|
dir_name = ".";
|
|
|
|
}
|
|
|
|
sprintf(history_filename, "%s/%s", dir_name, HIST_FILE_BASENAME);
|
|
|
|
}
|
|
|
|
|
2020-10-14 05:30:01 +02:00
|
|
|
struct itimerval timeout = {.it_value = {.tv_sec = 0, .tv_usec = 10000},
|
|
|
|
.it_interval = {.tv_sec = 0, .tv_usec = 10000}};
|
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
static void
|
2023-02-10 23:33:22 +01:00
|
|
|
thread_start(int is_kernel, kos_thread_t entry, size_t stack_size) {
|
|
|
|
fprintf(stderr, "[os] starting thread: %p\n", (void*)(uintptr_t)entry);
|
2020-10-17 04:13:18 +02:00
|
|
|
uint8_t *stack = malloc(stack_size);
|
2023-02-10 23:33:22 +01:00
|
|
|
kos_new_sys_threads(is_kernel, entry, stack + stack_size);
|
2020-10-17 04:13:18 +02:00
|
|
|
}
|
|
|
|
|
2022-06-25 00:41:23 +02:00
|
|
|
static void
|
2023-02-03 05:39:32 +01:00
|
|
|
dump_procs(void) {
|
2023-02-01 19:30:44 +01:00
|
|
|
for (int i = 0; i < KOS_NR_SCHED_QUEUES; i++) {
|
2023-02-10 23:33:22 +01:00
|
|
|
fprintf(stderr, "[os] sched queue #%i:", i);
|
2022-06-25 00:41:23 +02:00
|
|
|
appdata_t *p_begin = kos_scheduler_current[i];
|
|
|
|
appdata_t *p = p_begin;
|
|
|
|
do {
|
2023-02-02 17:25:20 +01:00
|
|
|
fprintf(stderr, " %p", (void*)p);
|
2022-06-25 00:41:23 +02:00
|
|
|
p = p->in_schedule.next;
|
|
|
|
} while (p != p_begin);
|
|
|
|
putchar('\n');
|
2020-10-17 04:13:18 +02:00
|
|
|
}
|
2023-02-14 00:48:48 +01:00
|
|
|
for (size_t i = 0; i < 256; i++) {
|
|
|
|
appdata_t *app = kos_slot_base + i;
|
|
|
|
if (app->state != KOS_TSTATE_FREE && app->app_name[0]) {
|
|
|
|
printf("slot %2.2d: %s\n", i, app->app_name);
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 04:13:18 +02:00
|
|
|
}
|
2022-05-24 21:22:12 +02:00
|
|
|
|
|
|
|
int
|
2023-02-02 17:25:20 +01:00
|
|
|
load_app_host(const char *fname, struct app_hdr *app) {
|
2023-02-10 23:33:22 +01:00
|
|
|
FILE *f = fopen(fname, "rb");
|
2022-05-24 21:22:12 +02:00
|
|
|
if (!f) {
|
2023-02-02 17:25:20 +01:00
|
|
|
fprintf(stderr, "[!] can't open app file: %s", fname);
|
2022-05-24 21:22:12 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2023-02-02 17:25:20 +01:00
|
|
|
fread(app, 1, APP_MAX_MEM_SIZE, f);
|
2022-05-24 21:22:12 +02:00
|
|
|
fclose(f);
|
|
|
|
|
2023-02-02 17:25:20 +01:00
|
|
|
kos_thread_t start = (kos_thread_t)(app->menuet.start);
|
2023-02-10 23:33:22 +01:00
|
|
|
thread_start(0, start, UMKA_DEFAULT_THREAD_STACK_SIZE);
|
2022-05-24 21:22:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-18 03:58:09 +01:00
|
|
|
/*
|
|
|
|
static int
|
2022-06-25 00:41:23 +02:00
|
|
|
load_app(const char *fname) {
|
|
|
|
int32_t result = umka_fs_execute(fname);
|
|
|
|
printf("result: %" PRIi32 "\n", result);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-01-18 03:58:09 +01:00
|
|
|
*/
|
2022-06-25 00:41:23 +02:00
|
|
|
|
2023-01-18 03:58:09 +01:00
|
|
|
static void
|
|
|
|
handle_i40(int signo, siginfo_t *info, void *context) {
|
2022-05-24 21:22:12 +02:00
|
|
|
(void)signo;
|
|
|
|
(void)info;
|
|
|
|
ucontext_t *ctx = context;
|
|
|
|
void *ip = (void*)ctx->uc_mcontext.__gregs[REG_EIP];
|
|
|
|
int eax = ctx->uc_mcontext.__gregs[REG_EAX];
|
|
|
|
if (*(uint16_t*)ip == 0x40cd) {
|
|
|
|
ctx->uc_mcontext.__gregs[REG_EIP] += 2; // skip int 0x40
|
|
|
|
}
|
2023-01-30 07:24:23 +01:00
|
|
|
fprintf(os->fboardlog, "i40: %i %p\n", eax, ip);
|
2022-05-24 21:22:12 +02:00
|
|
|
umka_i40((pushad_t*)(ctx->uc_mcontext.__gregs + REG_EDI));
|
|
|
|
}
|
|
|
|
|
2023-01-18 03:58:09 +01:00
|
|
|
static void
|
2023-02-02 01:37:11 +01:00
|
|
|
hw_int(int signo) {
|
2022-06-26 21:57:02 +02:00
|
|
|
(void)signo;
|
2023-02-02 01:37:11 +01:00
|
|
|
size_t irq = atomic_load_explicit(&umka_irq_number, memory_order_acquire);
|
|
|
|
struct idt_entry *e = kos_idts + UMKA_IRQ_BASE + irq;
|
|
|
|
uintptr_t handler_addr = ((uintptr_t)e->addr_hi << 16) + e->addr_lo;
|
|
|
|
void (*irq_handler)(void) = (void(*)(void)) handler_addr;
|
|
|
|
irq_handler();
|
2023-01-18 03:58:09 +01:00
|
|
|
umka_sti();
|
|
|
|
}
|
|
|
|
|
2023-02-02 17:25:20 +01:00
|
|
|
static void *
|
2023-02-01 19:30:44 +01:00
|
|
|
umka_display(void *arg) {
|
2023-01-28 03:57:08 +01:00
|
|
|
(void)arg;
|
|
|
|
if(SDL_Init(SDL_INIT_VIDEO) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to initialize the SDL2 library\n");
|
2023-02-02 17:25:20 +01:00
|
|
|
return NULL;
|
2023-01-28 03:57:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
char title[64];
|
|
|
|
sprintf(title, "umka0 %ux%u %ubpp", kos_display.width, kos_display.height,
|
|
|
|
kos_display.bits_per_pixel);
|
|
|
|
SDL_Window *window = SDL_CreateWindow(title,
|
2023-01-30 07:24:23 +01:00
|
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
SDL_WINDOWPOS_UNDEFINED,
|
|
|
|
kos_display.width,
|
|
|
|
kos_display.height,
|
2023-01-28 03:57:08 +01:00
|
|
|
0);
|
|
|
|
|
|
|
|
if(!window)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to create window\n");
|
2023-02-02 17:25:20 +01:00
|
|
|
return NULL;
|
2023-01-28 03:57:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Surface *window_surface = SDL_GetWindowSurface(window);
|
|
|
|
|
|
|
|
if(!window_surface)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Failed to get the surface from the window\n");
|
2023-02-02 17:25:20 +01:00
|
|
|
return NULL;
|
2023-01-28 03:57:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-03 05:39:32 +01:00
|
|
|
void (*copy_display)(void *) = NULL;
|
2023-01-28 03:57:08 +01:00
|
|
|
|
2023-01-30 07:24:23 +01:00
|
|
|
switch (window_surface->format->format) {
|
|
|
|
case SDL_PIXELFORMAT_RGB888:
|
|
|
|
copy_display = copy_display_to_rgb888;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("unknown SDL_PIXELFORMAT_* value: 0x%8.8x\n",
|
|
|
|
window_surface->format->format);
|
|
|
|
break;
|
|
|
|
}
|
2023-01-28 03:57:08 +01:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
SDL_LockSurface(window_surface);
|
2023-01-30 07:24:23 +01:00
|
|
|
copy_display(window_surface->pixels);
|
2023-01-28 03:57:08 +01:00
|
|
|
SDL_UnlockSurface(window_surface);
|
|
|
|
SDL_UpdateWindowSurface(window);
|
|
|
|
sleep(1);
|
|
|
|
}
|
2023-02-02 17:25:20 +01:00
|
|
|
return NULL;
|
2023-01-28 03:57:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-02 17:25:20 +01:00
|
|
|
static void *
|
2023-01-31 03:38:48 +01:00
|
|
|
umka_monitor(void *arg) {
|
2023-02-10 23:33:22 +01:00
|
|
|
struct shell_ctx *sh = arg;
|
|
|
|
run_test(sh);
|
2023-02-01 19:30:44 +01:00
|
|
|
exit(0);
|
2023-01-28 03:57:08 +01:00
|
|
|
}
|
|
|
|
|
2023-01-30 07:24:23 +01:00
|
|
|
static void
|
2023-02-03 05:39:32 +01:00
|
|
|
umka_thread_board(void) {
|
2023-01-30 07:24:23 +01:00
|
|
|
struct board_get_ret c;
|
|
|
|
while (1) {
|
|
|
|
c = umka_sys_board_get();
|
|
|
|
if (c.status) {
|
|
|
|
fprintf(os->fboardlog, "%c", c.value);
|
|
|
|
} else {
|
2023-02-12 17:52:01 +01:00
|
|
|
umka_sys_csleep(50);
|
2023-01-30 07:24:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
int
|
2023-01-16 03:50:19 +01:00
|
|
|
main(int argc, char *argv[]) {
|
|
|
|
(void)argc;
|
2023-01-30 07:24:23 +01:00
|
|
|
const char *usage = "umka_os [-i <infile>] [-o <outfile>]"
|
2023-02-10 23:33:22 +01:00
|
|
|
" [-b <boardlog>] [-s <startupfile>]\n";
|
2023-01-16 03:50:19 +01:00
|
|
|
if (coverage) {
|
2020-10-17 04:13:18 +02:00
|
|
|
trace_begin();
|
2023-01-16 03:50:19 +01:00
|
|
|
}
|
2020-10-17 04:13:18 +02:00
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
int show_display = 0;
|
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
umka_sti();
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2023-01-16 03:50:19 +01:00
|
|
|
build_history_filename();
|
2023-01-30 07:24:23 +01:00
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
const char *startupfile = NULL;
|
2023-01-30 07:24:23 +01:00
|
|
|
const char *infile = NULL;
|
|
|
|
const char *outfile = NULL;
|
|
|
|
const char *boardlogfile = NULL;
|
2023-02-01 19:30:44 +01:00
|
|
|
FILE *fstartup = NULL;
|
2023-01-30 07:24:23 +01:00
|
|
|
FILE *fin = stdin;
|
|
|
|
FILE *fout = stdout;
|
|
|
|
FILE *fboardlog;
|
2023-01-16 03:50:19 +01:00
|
|
|
|
|
|
|
struct optparse options;
|
|
|
|
int opt;
|
|
|
|
optparse_init(&options, argv);
|
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
while ((opt = optparse(&options, "b:di:o:s:")) != -1) {
|
2023-01-16 03:50:19 +01:00
|
|
|
switch (opt) {
|
2023-01-30 07:24:23 +01:00
|
|
|
case 'b':
|
|
|
|
boardlogfile = options.optarg;
|
|
|
|
break;
|
2023-02-01 19:30:44 +01:00
|
|
|
case 'd':
|
|
|
|
show_display = 1;
|
|
|
|
break;
|
2023-01-16 03:50:19 +01:00
|
|
|
case 'i':
|
|
|
|
infile = options.optarg;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
outfile = options.optarg;
|
|
|
|
break;
|
2023-02-01 19:30:44 +01:00
|
|
|
case 's':
|
|
|
|
startupfile = options.optarg;
|
|
|
|
break;
|
2023-01-16 03:50:19 +01:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "bad option: %c\n", opt);
|
|
|
|
fputs(usage, stderr);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-02 01:37:11 +01:00
|
|
|
if (startupfile) {
|
2023-02-10 23:33:22 +01:00
|
|
|
fstartup = fopen(startupfile, "rb");
|
2023-02-02 01:37:11 +01:00
|
|
|
if (!fstartup) {
|
|
|
|
fprintf(stderr, "[!] can't open file for reading: %s\n",
|
|
|
|
startupfile);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2023-01-30 07:24:23 +01:00
|
|
|
if (infile) {
|
2023-02-10 23:33:22 +01:00
|
|
|
fin = fopen(infile, "rb");
|
2023-01-30 07:24:23 +01:00
|
|
|
if (!fin) {
|
|
|
|
fprintf(stderr, "[!] can't open file for reading: %s\n", infile);
|
|
|
|
exit(1);
|
|
|
|
}
|
2023-01-16 03:50:19 +01:00
|
|
|
}
|
2023-01-30 07:24:23 +01:00
|
|
|
if (outfile) {
|
2023-02-10 23:33:22 +01:00
|
|
|
fout = fopen(outfile, "wb");
|
2023-01-30 07:24:23 +01:00
|
|
|
if (!fout) {
|
|
|
|
fprintf(stderr, "[!] can't open file for writing: %s\n", outfile);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (boardlogfile) {
|
2023-02-10 23:33:22 +01:00
|
|
|
fboardlog = fopen(boardlogfile, "wb");
|
2023-01-30 07:24:23 +01:00
|
|
|
if (!fboardlog) {
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "[!] can't open file for writing: %s\n",
|
|
|
|
boardlogfile);
|
2023-01-30 07:24:23 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fboardlog = fout;
|
2023-01-16 03:50:19 +01:00
|
|
|
}
|
|
|
|
|
2023-02-05 08:32:43 +01:00
|
|
|
os = umka_os_init(fstartup, fboardlog);
|
2023-01-17 01:49:11 +01:00
|
|
|
|
2020-10-10 01:30:52 +02:00
|
|
|
struct sigaction sa;
|
|
|
|
sa.sa_sigaction = irq0;
|
2020-05-08 06:44:32 +02:00
|
|
|
sigemptyset(&sa.sa_mask);
|
2023-02-02 01:37:11 +01:00
|
|
|
sa.sa_flags = SA_SIGINFO | SA_RESTART;
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2023-01-21 08:49:13 +01:00
|
|
|
if (sigaction(SIGALRM, &sa, NULL) == -1) {
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "Can't install timer interrupt handler!\n");
|
2020-05-08 06:44:32 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-05-24 21:22:12 +02:00
|
|
|
sa.sa_sigaction = handle_i40;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
2023-02-02 17:25:20 +01:00
|
|
|
sa.sa_flags = SA_SIGINFO | SA_NODEFER | SA_RESTART;
|
2022-05-24 21:22:12 +02:00
|
|
|
|
|
|
|
if (sigaction(SIGSEGV, &sa, NULL) == -1) {
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "Can't install 0x40 interrupt handler!\n");
|
2022-06-26 21:57:02 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-02-02 01:37:11 +01:00
|
|
|
sa.sa_handler = hw_int;
|
2023-01-18 03:58:09 +01:00
|
|
|
sigemptyset(&sa.sa_mask);
|
2023-02-02 01:37:11 +01:00
|
|
|
sa.sa_flags = SA_RESTART;
|
2023-01-18 03:58:09 +01:00
|
|
|
|
2023-02-02 01:37:11 +01:00
|
|
|
if (sigaction(UMKA_SIGNAL_IRQ, &sa, NULL) == -1) {
|
|
|
|
fprintf(stderr, "Can't install hardware interrupt handler!\n");
|
2023-01-18 03:58:09 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-02-02 17:25:20 +01:00
|
|
|
struct app_hdr *app_std = mmap(KOS_APP_BASE, APP_MAX_MEM_SIZE, PROT_READ
|
|
|
|
| PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
|
|
if (app_std == MAP_FAILED) {
|
|
|
|
perror("mmap app_std failed");
|
2020-10-12 05:02:02 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2023-02-02 17:25:20 +01:00
|
|
|
memset((void*)app_std, 0, APP_MAX_MEM_SIZE);
|
|
|
|
struct app_hdr *app_ldr = mmap(UMKA_LDR_BASE, APP_MAX_MEM_SIZE, PROT_READ
|
|
|
|
| PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
|
|
|
if (app_ldr == MAP_FAILED) {
|
|
|
|
perror("mmap app_ldr failed");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
memset((void*)app_ldr, 0, APP_MAX_MEM_SIZE);
|
2022-05-24 21:22:12 +02:00
|
|
|
|
2023-01-30 07:24:23 +01:00
|
|
|
run_test(os->shell);
|
2023-02-02 01:37:11 +01:00
|
|
|
os->shell->fin = fin;
|
2023-02-10 23:33:22 +01:00
|
|
|
clearerr(stdin); // reset feof
|
2020-10-14 05:30:01 +02:00
|
|
|
|
2022-06-26 10:44:16 +02:00
|
|
|
// load_app("/rd/1/loader");
|
2022-06-25 00:41:23 +02:00
|
|
|
|
2023-02-06 17:01:37 +01:00
|
|
|
struct vnet *vnet = vnet_init(VNET_DEVTYPE_TAP, &os->umka->running);
|
2023-02-02 01:37:11 +01:00
|
|
|
if (vnet) {
|
|
|
|
kos_net_add_device(&vnet->eth.net);
|
2023-02-01 19:30:44 +01:00
|
|
|
} else {
|
|
|
|
fprintf(stderr, "[!] can't initialize vnet device\n");
|
|
|
|
}
|
2022-06-27 14:32:29 +02:00
|
|
|
|
|
|
|
char devname[64];
|
|
|
|
for (size_t i = 0; i < umka_sys_net_get_dev_count(); i++) {
|
|
|
|
umka_sys_net_dev_reset(i);
|
|
|
|
umka_sys_net_get_dev_name(i, devname);
|
|
|
|
uint32_t devtype = umka_sys_net_get_dev_type(i);
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "[!] device %i: %s %u\n", i, devname, devtype);
|
2022-06-27 14:32:29 +02:00
|
|
|
}
|
|
|
|
|
2022-06-28 10:23:14 +02:00
|
|
|
// network setup should be done from the userspace app, e.g. via zeroconf
|
2022-06-27 14:32:29 +02:00
|
|
|
f76ret_t r76;
|
|
|
|
r76 = umka_sys_net_ipv4_set_subnet(1, inet_addr("255.255.255.0"));
|
|
|
|
if (r76.eax == (uint32_t)-1) {
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "[!] set subnet error\n");
|
|
|
|
// return -1;
|
2022-06-27 14:32:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r76 = umka_sys_net_ipv4_set_gw(1, inet_addr("10.50.0.1"));
|
|
|
|
if (r76.eax == (uint32_t)-1) {
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "[!] set gw error\n");
|
|
|
|
// return -1;
|
2022-06-27 14:32:29 +02:00
|
|
|
}
|
|
|
|
|
2023-02-02 01:37:11 +01:00
|
|
|
r76 = umka_sys_net_ipv4_set_dns(1, inet_addr("192.168.1.1"));
|
2022-06-27 14:32:29 +02:00
|
|
|
if (r76.eax == (uint32_t)-1) {
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "[!] set dns error\n");
|
|
|
|
// return -1;
|
2022-06-27 14:32:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r76 = umka_sys_net_ipv4_set_addr(1, inet_addr("10.50.0.2"));
|
|
|
|
if (r76.eax == (uint32_t)-1) {
|
2023-02-02 01:37:11 +01:00
|
|
|
fprintf(stderr, "[!] set ip addr error\n");
|
|
|
|
// return -1;
|
2022-06-27 14:32:29 +02:00
|
|
|
}
|
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
kos_attach_int_handler(UMKA_IRQ_MOUSE, hw_int_mouse, NULL);
|
2023-01-18 03:58:09 +01:00
|
|
|
|
2023-02-10 23:33:22 +01:00
|
|
|
thread_start(1, umka_thread_board, UMKA_DEFAULT_THREAD_STACK_SIZE);
|
2023-02-02 17:25:20 +01:00
|
|
|
load_app_host("../apps/loader", UMKA_LDR_BASE);
|
|
|
|
// load_app_host("../apps/justawindow", KOS_APP_BASE);
|
|
|
|
load_app_host("../apps/asciivju", KOS_APP_BASE);
|
2022-06-25 00:41:23 +02:00
|
|
|
|
|
|
|
dump_procs();
|
2020-10-10 01:30:52 +02:00
|
|
|
|
2023-02-02 17:25:20 +01:00
|
|
|
pthread_t thread_monitor;
|
2023-02-10 23:33:22 +01:00
|
|
|
pthread_create(&thread_monitor, NULL, umka_monitor, os->shell);
|
2023-01-28 03:57:08 +01:00
|
|
|
|
2023-02-01 19:30:44 +01:00
|
|
|
if (show_display) {
|
2023-02-02 17:25:20 +01:00
|
|
|
pthread_t thread_display;
|
|
|
|
pthread_create(&thread_display, NULL, umka_display, NULL);
|
2023-02-01 19:30:44 +01:00
|
|
|
}
|
2023-01-28 03:57:08 +01:00
|
|
|
|
2023-02-14 00:48:48 +01:00
|
|
|
atomic_store_explicit(&os->umka->running, UMKA_RUNNING_YES, memory_order_release);
|
2023-01-21 08:49:13 +01:00
|
|
|
setitimer(ITIMER_REAL, &timeout, NULL);
|
2020-10-10 01:30:52 +02:00
|
|
|
|
2022-06-28 18:13:41 +02:00
|
|
|
umka_osloop(); // doesn't return
|
2020-05-08 06:44:32 +02:00
|
|
|
|
2020-10-17 04:13:18 +02:00
|
|
|
if (coverage)
|
|
|
|
trace_end();
|
|
|
|
|
2020-05-08 06:44:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|