From ac151ef588456ae49d0abf4077f00a4e1a9e8c4a Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Sun, 26 Jun 2022 23:57:02 +0400 Subject: [PATCH] [umka_os/linux] Simulate hw interrupts via signals --- umka.asm | 21 +++++++++++++++++++++ umka.h | 6 ++++++ umka_os.c | 16 ++++++++++++++++ vnet.c | 8 ++++++++ 4 files changed, 51 insertions(+) diff --git a/umka.asm b/umka.asm index a8df4d1..416e338 100644 --- a/umka.asm +++ b/umka.asm @@ -79,6 +79,8 @@ UMKA_OS = 3 UMKA_MEMORY_BYTES = 256 SHL 20 +pubsym irq_serv.irq_10, 'kos_irq_serv_irq10' +pubsym attach_int_handler, 'kos_attach_int_handler', 12 pubsym fs_execute, 'kos_fs_execute' pubsym set_keyboard_data, 'kos_set_keyboard_data' pubsym KEY_COUNT as 'kos_key_count' @@ -191,6 +193,7 @@ macro sti { } iretd equ retd +iret equ ret lang fix en @@ -383,7 +386,15 @@ purge call ;include 'core/exports.inc' include 'core/string.inc' ;include 'core/v86.inc' +macro mov dst, src { + if dst eq ds + else if dst eq es + else + mov dst, src + end if +} include 'core/irq.inc' +purge mov include 'core/apic.inc' include 'core/hpet.inc' include 'core/timers.inc' @@ -535,6 +546,10 @@ proc umka_init c uses ebx esi edi ebp ; call mem_test ; call init_mem ; call init_page_map + mov [irq_mode], IRQ_APIC + mov [IOAPIC_base], ioapic_data + mov [LAPIC_BASE], lapic_data + mov [ioapic_cnt], 1 mov [xsave_area_size], 0x1000 @@ -724,6 +739,9 @@ proc umka_init c uses ebx esi edi ebp mov ebx, SLOT_BASE + 2*sizeof.APPDATA mov word[cur_dir.path], '/' mov [ebx+APPDATA.cur_dir], cur_dir + ; end of set_variables + + call init_irqs ret endp @@ -1034,6 +1052,9 @@ ide_channel6_mutex MUTEX ide_channel7_mutex MUTEX ide_channel8_mutex MUTEX +ioapic_data rb 0x400 +lapic_data rb 0x400 + lfb_base rd MAX_SCREEN_WIDTH*MAX_SCREEN_HEIGHT align 4096 diff --git a/umka.h b/umka.h index 86a5c7f..3f742ec 100644 --- a/umka.h +++ b/umka.h @@ -541,6 +541,12 @@ 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); +STDCALL void +kos_attach_int_handler(int irq, int (*handler)(void*), void *user_data); + +void +kos_irq_serv_irq10(void); + static inline int32_t umka_fs_execute(const char *filename) { // edx Flags diff --git a/umka_os.c b/umka_os.c index 162e410..6e1129d 100644 --- a/umka_os.c +++ b/umka_os.c @@ -111,6 +111,13 @@ void handle_i40(int signo, siginfo_t *info, void *context) { umka_i40((pushad_t*)(ctx->uc_mcontext.__gregs + REG_EDI)); } +void handle_irq_net(int signo, siginfo_t *info, void *context) { + (void)signo; + (void)info; + (void)context; + kos_irq_serv_irq10(); +} + int main() { if (coverage) @@ -138,6 +145,15 @@ main() { return 1; } + sa.sa_sigaction = handle_irq_net; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO; + + if (sigaction(SIGUSR1, &sa, NULL) == -1) { + printf("Can't install SIGUSR1 handler!\n"); + return 1; + } + void *app_base = mmap((void*)0, 16*0x100000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); diff --git a/vnet.c b/vnet.c index ea474b2..cb4a099 100644 --- a/vnet.c +++ b/vnet.c @@ -17,6 +17,12 @@ typedef struct { int fd; } vnet_userdata_t; +int vnet_input(void *udata) { + vnet_userdata_t *u = udata; + fprintf(stderr, "###### vnet_input\n"); + return 1; +} + net_device_t *vnet_init(int fd) { // printf("vnet_init\n"); vnet_userdata_t *u = (vnet_userdata_t*)malloc(sizeof(vnet_userdata_t)); @@ -44,6 +50,8 @@ net_device_t *vnet_init(int fd) { .userdata = u, }; + kos_attach_int_handler(SIGUSR1, vnet_input, u); + return vnet; }