From dad581883c31e2b2eea89099ec3b1f632b4a1c2f Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Sat, 9 May 2020 00:50:54 +0300 Subject: [PATCH] Move thread logic to linux/thread.c, rewrite os and idle threads in asm. --- pci.c => linux/pci.c | 0 linux/thread.c | 39 +++++++++++++++++++++++++++++++++++++++ linux/thread.h | 8 ++++++++ 3 files changed, 47 insertions(+) rename pci.c => linux/pci.c (100%) create mode 100644 linux/thread.c create mode 100644 linux/thread.h diff --git a/pci.c b/linux/pci.c similarity index 100% rename from pci.c rename to linux/pci.c diff --git a/linux/thread.c b/linux/thread.c new file mode 100644 index 0000000..be15c49 --- /dev/null +++ b/linux/thread.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include "../umka.h" + +sigjmp_buf trampoline; + + +__attribute__((__stdcall__)) +uint32_t umka_new_sys_threads(void (*func)(void), void *stack, int type) { + (void)type; + (void)func; + fprintf(stderr, "umka_new_sys_threads before\n"); +// kos_slot_base[kos_task_count].fpu_state = malloc(4096); + fprintf(stderr, "kos_task_count: %d\n", kos_task_count); + if (!sigsetjmp(trampoline, 1)) { + __asm__ __inline__ __volatile__ ( + "mov esp, eax;" + "push ecx" + : + : "a"(stack), + "c"(func) + : "memory"); + if (!sigsetjmp(*kos_slot_base[kos_task_count++].fpu_state, 1)) { + longjmp(trampoline, 1); + } else { + __asm__ __inline__ __volatile__ ( + "pop ecx;" + "call ecx" + : + : + : "memory"); + } + } + fprintf(stderr, "umka_new_sys_threads after\n"); + return 0; +} + diff --git a/linux/thread.h b/linux/thread.h new file mode 100644 index 0000000..6ef8c18 --- /dev/null +++ b/linux/thread.h @@ -0,0 +1,8 @@ +#ifndef THREAD_H_INCLUDED +#define THREAD_H_INCLUDED + +#include + +uint32_t umka_new_sys_threads(void (*func)(void), void *stack, int type); + +#endif // THREAD_H_INCLUDED