Wrap fs_execute, works for umka_os tool!

This commit is contained in:
Ivan Baravy 2022-06-25 02:41:23 +04:00
parent 52c2167249
commit d82c5530ed
12 changed files with 151 additions and 103 deletions

3
.gitignore vendored
View File

@ -38,4 +38,5 @@ t.d
*.exe
colors.dtp
.tup
hello_board
board_hello
board_cycle

30
apps/board_cycle.asm Normal file
View File

@ -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:

View File

@ -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

View File

@ -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

17
shell.c
View File

@ -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 },

View File

@ -0,0 +1,5 @@
/> umka_init
/> check_for_event
0
/> check_for_event
0

View File

@ -0,0 +1,3 @@
umka_init
check_for_event
check_for_event

View File

@ -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

58
umka.h
View File

@ -3,6 +3,7 @@
#include <inttypes.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#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__ (

View File

@ -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);

View File

@ -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);