diff --git a/Ubiquitous/XiZi_AIoT/services/app/simple_server.c b/Ubiquitous/XiZi_AIoT/services/app/simple_server.c index f9ae98ee8..2ae2d9e12 100755 --- a/Ubiquitous/XiZi_AIoT/services/app/simple_server.c +++ b/Ubiquitous/XiZi_AIoT/services/app/simple_server.c @@ -31,7 +31,6 @@ int IPC_DO_SERVE_FUNC(Ipc_hello_string)(char* buf, int* len) } IPC_SERVER_INTERFACE(Ipc_add, 2); -//IPC_SERVER_THREAD_INTERFACE(Ipc_add, 2); IPC_SERVER_INTERFACE(Ipc_hello_string, 2); IPC_SERVER_REGISTER_INTERFACES(IpcSimpleServer, 2, Ipc_hello_string, Ipc_add); diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/3568/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/3568/Makefile index b14224115..2c285fffa 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/3568/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/3568/Makefile @@ -1,3 +1,4 @@ -SRC_DIR := + +SRC_DIR := hal include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/Makefile similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/Makefile rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/Makefile diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_base.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_base.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_base.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_base.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_bsp.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_bsp.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_bsp.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_bsp.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_cru.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_cru.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_cru.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_cru.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_cru_rk3568.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_cru_rk3568.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_cru_rk3568.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_cru_rk3568.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_debug.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_debug.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_debug.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_debug.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_gmac.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_gmac.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_gmac.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_gmac.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_gmac_3568.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_gmac_3568.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_gmac_3568.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_gmac_3568.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_gpio.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_gpio.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_gpio.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_gpio.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_pinctrl_v2.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_pinctrl_v2.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_pinctrl_v2.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_pinctrl_v2.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_timer.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_timer.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/hal_timer.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/hal_timer.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/system_rk3568.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/system_rk3568.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/system_rk3568.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/system_rk3568.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/test_gmac.c b/Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/test_gmac.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/hal/test_gmac.c rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/hal/test_gmac.c diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_base.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_base.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_base.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_base.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_bsp.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_bsp.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_bsp.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_bsp.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_conf.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_conf.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_conf.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_conf.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_cru.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_cru.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_cru.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_cru.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_debug.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_debug.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_debug.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_debug.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_def.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_def.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_def.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_def.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_driver.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_driver.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_driver.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_driver.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_gmac.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_gmac.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_gmac.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_gmac.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_gpio.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_gpio.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_gpio.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_gpio.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_list.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_list.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_list.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_list.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_pinctrl.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_pinctrl.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_pinctrl.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_pinctrl.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_pm.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_pm.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_pm.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_pm.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_timer.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_timer.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/hal_timer.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/hal_timer.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/rk3568.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/rk3568.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/rk3568.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/rk3568.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/soc.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/soc.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/soc.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/soc.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/system_rk3568.h b/Ubiquitous/XiZi_AIoT/services/drivers/3568/include/system_rk3568.h similarity index 100% rename from Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/include/system_rk3568.h rename to Ubiquitous/XiZi_AIoT/services/drivers/3568/include/system_rk3568.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/Makefile index e53a14564..1c8d601c7 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/Makefile @@ -1,4 +1,4 @@ -SRC_DIR := $(BOARD) rk-3568 +SRC_DIR := $(BOARD) include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile index 40096c142..0a382c704 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/imx6q-sabrelite/enet/Makefile @@ -9,14 +9,8 @@ ld = ${toolchain}g++ objdump = ${toolchain}objdump user_ldflags = -N -Ttext 0 -cflags = -std=c11 -march=armv7-a -mcpu=cortex-a9 -mtune=cortex-a9 -g \ - -Wno-unused -Wno-format -fno-common -ffreestanding -fno-builtin -static \ - -Wno-unaligned-access -fdce -Wall -Werror -Wno-uninitialized -Wno-strict-aliasing -fdiagnostics-show-option \ - -mapcs -marm -mfpu=neon -ftree-vectorize -fno-math-errno -funsafe-math-optimizations -fno-signed-zeros -mfloat-abi=softfp \ - -fno-omit-frame-pointer -fno-stack-protector -fno-pie - -# cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic \ -# -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie +cflags = -std=c11 -march=armv7-a -mtune=cortex-a9 -nostdlib -nodefaultlibs -mfloat-abi=soft -fno-pic \ + -static -fno-builtin -fno-strict-aliasing -Wall -ggdb -Wno-unused -Werror -fno-omit-frame-pointer -fno-stack-protector -fno-pie c_useropts = -O0 diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/Makefile deleted file mode 100644 index 2c285fffa..000000000 --- a/Ubiquitous/XiZi_AIoT/services/drivers/rk-3568/Makefile +++ /dev/null @@ -1,4 +0,0 @@ - -SRC_DIR := hal - -include $(KERNEL_ROOT)/compiler.mk \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c index 2f0f3b95f..0ff25461f 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c +++ b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.c @@ -182,7 +182,6 @@ void ipc_server_loop(struct IpcNode* ipc_node) /* handle each session */ for (int i = 0; i < NR_MAX_SESSION; i++) { if (session_list[i].buf == NULL) { - yield(SYS_TASK_YIELD_NO_REASON); break; } cur_sess_id = session_list[i].id; diff --git a/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.c b/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.c index f975d5aaf..a6fd43a4a 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.c +++ b/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.c @@ -101,9 +101,18 @@ int show_cpu() return syscall(SYSCALL_SYS_STATE, SYS_STATE_SHOW_CPU_INFO, 0, 0, 0); } -int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev) +uintptr_t mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev) { - return syscall(SYSCALL_MMAP, vaddr, paddr, (intptr_t)len, (intptr_t)is_dev); + uintptr_t vaddr_inner = vaddr, paddr_inner = paddr; + if (syscall(SYSCALL_MMAP, (intptr_t)&vaddr_inner, (intptr_t)&paddr_inner, (intptr_t)len, (intptr_t)is_dev) < 0) { + return (uintptr_t)NULL; + } + return vaddr_inner; +} + +int naive_mmap(uintptr_t* vaddr, uintptr_t* paddr, int len, bool is_dev) +{ + return syscall(SYSCALL_MMAP, (uintptr_t)vaddr, (intptr_t)paddr, (intptr_t)len, (intptr_t)is_dev); } int register_irq(int irq, int opcode) diff --git a/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.h b/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.h index ddb0cf0af..2ff0a2446 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.h +++ b/Ubiquitous/XiZi_AIoT/services/lib/usyscall/usyscall.h @@ -44,6 +44,8 @@ typedef enum { SYS_STATE_SHOW_TASKS, SYS_STATE_SHOW_MEM_INFO, SYS_STATE_SHOW_CPU_INFO, + SYS_STATE_GET_CURRENT_TICK, + SYS_STATE_GET_CURRENT_SECOND, } sys_state_option; typedef enum { @@ -58,6 +60,8 @@ typedef union { uintptr_t memblock_end; } memblock_info; int priority; + uintptr_t current_tick; + uintptr_t current_second; } sys_state_info; typedef enum { @@ -85,7 +89,8 @@ int poll_session(struct Session* userland_session_arr, int arr_capacity); int close_session(struct Session* session); int register_irq(int irq, int opcode); -int mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev); +uintptr_t mmap(uintptr_t vaddr, uintptr_t paddr, int len, bool is_dev); +int naive_mmap(uintptr_t* vaddr, uintptr_t* paddr, int len, bool is_dev); int task_heap_base(); int get_memblock_info(sys_state_info* info); diff --git a/Ubiquitous/XiZi_AIoT/softkernel/include/memspace.h b/Ubiquitous/XiZi_AIoT/softkernel/include/memspace.h index 41ae50482..03cb948b5 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/include/memspace.h +++ b/Ubiquitous/XiZi_AIoT/softkernel/include/memspace.h @@ -27,8 +27,12 @@ Author: AIIT XUOS Lab Modification: 1. first version *************************************************/ +#pragma once -#include "task.h" +#include "bitmap64.h" +#include "buddy.h" +#include "list.h" +#include "share_page.h" struct ThreadStackPointer { int argc; @@ -37,6 +41,22 @@ struct ThreadStackPointer { uintptr_t user_stack_vaddr; }; +struct MemSpace { + /* task memory resources */ + struct TopLevelPageDirectory pgdir; // [phy] vm pgtbl base address + uintptr_t heap_base; // mem size of proc used(allocated by kernel) + uintptr_t mem_size; + /* task communication mem resources */ + struct KBuddy* massive_ipc_allocator; + + /* thread using this memspace */ + struct bitmap64 thread_stack_idx_bitmap; + struct double_list_node thread_list_guard; + + // thread to notify when sub-thread exit + struct Thread* thread_to_notify; +}; + struct MemSpace* alloc_memspace(); void free_memspace(struct MemSpace* pmemspace); uintptr_t* load_memspace(struct MemSpace* pmemspace, char* img_start); diff --git a/Ubiquitous/XiZi_AIoT/softkernel/include/syscall.h b/Ubiquitous/XiZi_AIoT/softkernel/include/syscall.h index 4e1ba2a7a..14e2ddc7e 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/include/syscall.h +++ b/Ubiquitous/XiZi_AIoT/softkernel/include/syscall.h @@ -64,6 +64,8 @@ typedef enum { SYS_STATE_SHOW_TASKS, SYS_STATE_SHOW_MEM_INFO, SYS_STATE_SHOW_CPU_INFO, + SYS_STATE_GET_CURRENT_TICK, + SYS_STATE_GET_CURRENT_SECOND, } sys_state_option; typedef enum { @@ -78,6 +80,8 @@ typedef union { uintptr_t memblock_end; } memblock_info; int priority; + uintptr_t current_tick; + uintptr_t current_second; } sys_state_info; typedef enum { @@ -102,7 +106,7 @@ int sys_close_session(struct Thread* task, struct Session* session); int sys_exec(char* img_start, char* name, char** argv); int sys_state(sys_state_option option, sys_state_info* info); -int sys_mmap(uintptr_t vaddr, uintptr_t paddr, int len, int is_dev); +int sys_mmap(uintptr_t* vaddr, uintptr_t* paddr, int len, int is_dev); int sys_register_irq(int irq_num, int irq_opcode); int sys_unbind_irq_all(struct Thread* task); diff --git a/Ubiquitous/XiZi_AIoT/softkernel/include/task.h b/Ubiquitous/XiZi_AIoT/softkernel/include/task.h index 56320be0f..d33f88e09 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/include/task.h +++ b/Ubiquitous/XiZi_AIoT/softkernel/include/task.h @@ -31,10 +31,10 @@ Modification: #include "core.h" -#include "bitmap64.h" #include "buddy.h" #include "ksemaphore.h" #include "list.h" +#include "memspace.h" #include "object_allocator.h" #include "pagetable.h" #include "share_page.h" @@ -54,19 +54,6 @@ enum ProcState { NEVER_RUN, }; -struct MemSpace { - /* task memory resources */ - struct TopLevelPageDirectory pgdir; // [phy] vm pgtbl base address - uintptr_t heap_base; // mem size of proc used(allocated by kernel) - uintptr_t mem_size; - /* task communication mem resources */ - struct KBuddy* massive_ipc_allocator; - - /* thread using this memspace */ - struct bitmap64 thread_stack_idx_bitmap; - struct double_list_node thread_list_guard; -}; - /* Thread Control Block */ struct ThreadContext { struct Thread* task; // process of current thread @@ -105,8 +92,8 @@ struct Thread { /* task communication resources */ struct double_list_node cli_sess_listhead; struct double_list_node svr_sess_listhead; - bool current_ipc_handled; struct TraceTag server_identifier; + bool advance_unblock; /* task schedule attributes */ struct double_list_node node; diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_mmap.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_mmap.c index 1c94c1d5f..552e10263 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_mmap.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_mmap.c @@ -36,34 +36,36 @@ Modification: #include "syscall.h" #include "task.h" -int sys_mmap(uintptr_t vaddr, uintptr_t paddr, int len, int is_dev) +int sys_mmap(uintptr_t* vaddr, uintptr_t* paddr, int len, int is_dev) { struct Thread* cur_task = cur_cpu()->task; assert(cur_task != NULL); int true_len = ALIGNUP(len, PAGE_SIZE); - if (paddr != (uintptr_t)NULL) { - if (xizi_share_page_manager.task_map_pages(cur_task, vaddr, paddr, true_len / PAGE_SIZE, is_dev) == (uintptr_t)NULL) { + if (*paddr != (uintptr_t)NULL) { + if (xizi_share_page_manager.task_map_pages(cur_task, *vaddr, *paddr, true_len / PAGE_SIZE, is_dev) == (uintptr_t)NULL) { return -1; } } else { int load_len = 0; - uintptr_t load_vaddr = vaddr; + uintptr_t load_vaddr = *vaddr; while (load_len < true_len) { - char* paddr = raw_alloc(PAGE_SIZE); - if (paddr == NULL) { + char* new_paddr = raw_alloc(PAGE_SIZE); + if (new_paddr == NULL) { return -1; } - if (xizi_share_page_manager.task_map_pages(cur_task, load_vaddr, (uintptr_t)paddr, 1, false) == (uintptr_t)NULL) { - raw_free(paddr); + if (xizi_share_page_manager.task_map_pages(cur_task, load_vaddr, (uintptr_t)new_paddr, 1, false) == (uintptr_t)NULL) { + raw_free(new_paddr); return -1; } load_vaddr += PAGE_SIZE; load_len += PAGE_SIZE; + *paddr = (uintptr_t)new_paddr; } } cur_task->memspace->mem_size += true_len; - return vaddr + true_len; + *vaddr = *vaddr + true_len; + return 0; } \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_poll_session.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_poll_session.c index b1c751719..95fb8f743 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_poll_session.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_poll_session.c @@ -70,7 +70,7 @@ int sys_poll_session(struct Session* userland_session_arr, int arr_capacity) if (client->state == BLOCKED) { xizi_task_manager.task_unblock(client); } else { - client->current_ipc_handled = true; + client->advance_unblock = true; } } server_session->head = userland_session_arr[i].head; @@ -120,8 +120,12 @@ int sys_poll_session(struct Session* userland_session_arr, int arr_capacity) if (session_idx < arr_capacity) { userland_session_arr[session_idx].buf = NULL; if (!has_middle_delete && nr_sessions_need_to_handle == 0) { - xizi_task_manager.task_yield_noschedule(cur_task, false); - xizi_task_manager.task_block(&xizi_task_manager.task_blocked_list_head, cur_task); + if (cur_task->advance_unblock) { + cur_task->advance_unblock = false; + } else { + xizi_task_manager.task_yield_noschedule(cur_task, false); + xizi_task_manager.task_block(&xizi_task_manager.task_blocked_list_head, cur_task); + } } } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c index ddc3f5f69..67aea6b05 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c @@ -151,19 +151,39 @@ void show_cpu(void) int sys_state(sys_state_option option, sys_state_info* info) { - if (option == SYS_STATE_MEMBLOCK_INFO) { + switch (option) { + case SYS_STATE_MEMBLOCK_INFO: { info->memblock_info.memblock_start = (uintptr_t)V2P(_binary_fs_img_start); info->memblock_info.memblock_end = (uintptr_t)V2P(_binary_fs_img_end); - } else if (option == SYS_STATE_GET_HEAP_BASE) { + break; + } + case SYS_STATE_GET_HEAP_BASE: return cur_cpu()->task->memspace->heap_base; - } else if (option == SYS_STATE_SET_TASK_PRIORITY) { + case SYS_STATE_SET_TASK_PRIORITY: xizi_task_manager.set_cur_task_priority(info->priority); - } else if (option == SYS_STATE_SHOW_TASKS) { + break; + case SYS_STATE_SHOW_TASKS: show_tasks(); - } else if (option == SYS_STATE_SHOW_MEM_INFO) { + break; + case SYS_STATE_SHOW_MEM_INFO: show_mem(); - } else if (option == SYS_STATE_SHOW_CPU_INFO) { + break; + case SYS_STATE_SHOW_CPU_INFO: show_cpu(); + break; + case SYS_STATE_GET_CURRENT_TICK: { + extern void hw_current_tick(uintptr_t * tick); + hw_current_tick(&info->current_tick); + break; + } + case SYS_STATE_GET_CURRENT_SECOND: { + extern void hw_current_second(uintptr_t * tick); + hw_current_second(&info->current_second); + break; + } + case SYS_STATE_TEST: + default: + break; } return 0; diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c index 5d08d655e..f98ed1c81 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_thread.c @@ -65,6 +65,11 @@ int sys_new_thread(struct MemSpace* pmemspace, struct Thread* task, uintptr_t en // init pcb schedule attributes xizi_task_manager.task_set_default_schedule_attr(task); + // thread init done by here + if (pmemspace->thread_to_notify == NULL) { + pmemspace->thread_to_notify = task; + } + return task->tid; } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_yield.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_yield.c index 0db107e04..0e0f644e2 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_yield.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_yield.c @@ -40,8 +40,8 @@ int sys_yield(task_yield_reason reason) // handle ipc block if ((reason & SYS_TASK_YIELD_BLOCK_IPC) != 0) { - if (cur_task->current_ipc_handled) { - cur_task->current_ipc_handled = false; + if (cur_task->advance_unblock) { + cur_task->advance_unblock = false; } else { xizi_task_manager.task_block(&xizi_task_manager.task_blocked_list_head, cur_task); } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/syscall.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/syscall.c index 4a15e6389..d3ae51f67 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/syscall.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/syscall.c @@ -69,7 +69,7 @@ int syscall(int sys_num, uintptr_t param1, uintptr_t param2, uintptr_t param3, u ret = sys_state(param1, (sys_state_info*)param2); break; case SYSCALL_MMAP: - ret = sys_mmap(param1, param2, (int)param3, (int)param4); + ret = sys_mmap((uintptr_t*)param1, (uintptr_t*)param2, (int)param3, (int)param4); break; case SYSCALL_REGISTER_IRQ: ret = sys_register_irq((int)param1, (int)param2); diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c b/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c index a16509eed..8c15b852c 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/memspace.c @@ -55,6 +55,7 @@ struct MemSpace* alloc_memspace() pmemspace->heap_base = 0; pmemspace->mem_size = 0; pmemspace->pgdir.pd_addr = 0; + pmemspace->thread_to_notify = NULL; return pmemspace; } diff --git a/Ubiquitous/XiZi_AIoT/softkernel/task/task.c b/Ubiquitous/XiZi_AIoT/softkernel/task/task.c index bf8d7903d..ef52dc65a 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/task/task.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/task/task.c @@ -179,6 +179,19 @@ static void _dealloc_task_cb(struct Thread* task) /* free memspace if needed to */ if (task->memspace != NULL) { + // awake deamon in this memspace + if (task->memspace->thread_to_notify != NULL) { + if (task->memspace->thread_to_notify != task) { + if (task->memspace->thread_to_notify->state == BLOCKED) { + xizi_task_manager.task_unblock(task->memspace->thread_to_notify); + } else { + task->memspace->thread_to_notify->advance_unblock = true; + } + } else if (task->memspace->thread_to_notify == task) { + task->memspace->thread_to_notify = NULL; + } + } + doubleListDel(&task->memspace_list_node); /* free memspace if thread is the last one using it */ if (IS_DOUBLE_LIST_EMPTY(&task->memspace->thread_list_guard)) { diff --git a/Ubiquitous/XiZi_AIoT/softkernel/trap/clock_irq_handler.c b/Ubiquitous/XiZi_AIoT/softkernel/trap/clock_irq_handler.c index 2fdbdf67f..eba875e07 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/trap/clock_irq_handler.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/trap/clock_irq_handler.c @@ -44,6 +44,24 @@ bool clock_intr_handler_init(struct TraceTag* p_clock_driver_tag) return p_clock_driver != NULL; } +void hw_current_tick(uintptr_t* tick) +{ + if (p_clock_driver == NULL) { + *tick = 0; + return; + } + *tick = p_clock_driver->get_tick(); +} + +void hw_current_second(uintptr_t* second) +{ + if (p_clock_driver == NULL) { + *second = 0; + return; + } + *second = p_clock_driver->get_second(); +} + uint64_t global_tick = 0; int xizi_clock_handler(int irq, void* tf, void* arg) {