From 23d6224395b669a677ce834dc432a7cd5809be23 Mon Sep 17 00:00:00 2001 From: TXuian <1163589503@qq.com> Date: Thu, 7 Mar 2024 14:21:47 +0800 Subject: [PATCH] Add some ipc related comments; Fix one dabort and iabort bug. --- Ubiquitous/XiZi_AIoT/Makefile | 2 ++ .../hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c | 7 +++++-- Ubiquitous/XiZi_AIoT/services/app/Makefile | 6 +++++- Ubiquitous/XiZi_AIoT/services/app/simple_server.c | 2 ++ Ubiquitous/XiZi_AIoT/services/app/test_fs.c | 8 +++++--- Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h | 8 ++++++++ Ubiquitous/XiZi_AIoT/softkernel/Makefile | 2 +- Ubiquitous/XiZi_AIoT/softkernel/ipc/Makefile | 3 --- Ubiquitous/XiZi_AIoT/softkernel/memory/Makefile | 2 +- .../XiZi_AIoT/softkernel/{ipc => memory}/share_page.c | 0 .../XiZi_AIoT/softkernel/trap/default_irq_handler.c | 2 +- 11 files changed, 30 insertions(+), 12 deletions(-) delete mode 100644 Ubiquitous/XiZi_AIoT/softkernel/ipc/Makefile rename Ubiquitous/XiZi_AIoT/softkernel/{ipc => memory}/share_page.c (100%) diff --git a/Ubiquitous/XiZi_AIoT/Makefile b/Ubiquitous/XiZi_AIoT/Makefile index 5d19bdb59..4a560ba9c 100755 --- a/Ubiquitous/XiZi_AIoT/Makefile +++ b/Ubiquitous/XiZi_AIoT/Makefile @@ -31,7 +31,9 @@ MAKEFILES =$(KERNEL_ROOT)/.config export BSP_ROOT ?= $(KERNEL_ROOT)/services/boards/$(BOARD) export UBIQUITOUS_ROOT ?= .. +ifneq ($(findstring $(BOARD), imx6q-sabrelite zynq7000-zc702), ) include $(KERNEL_ROOT)/hardkernel/arch/arm/armv7-a/cortex-a9/preboot_for_$(BOARD)/config.mk +endif export BSP_BUILD_DIR := $(KERNEL_ROOT) export HOSTTOOLS_DIR ?= $(KERNEL_ROOT)/services/tools/hosttools export CONFIG2H_EXE ?= $(HOSTTOOLS_DIR)/xsconfig.sh diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c index a9fccbe4f..9d7224da8 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/arm/armv7-a/cortex-a9/error_debug.c @@ -91,6 +91,7 @@ void handle_undefined_instruction(struct trapframe* tf) panic(""); } +extern void context_switch(struct context**, struct context*); void dabort_handler(struct trapframe* r) { uint32_t dfs, dfa; @@ -100,15 +101,16 @@ void dabort_handler(struct trapframe* r) if (r->pc < KERN_MEM_BASE) { // Exception occured in User space: exit ERROR("dabort in user space: %s\n", cur_cpu()->task->name); - LOG("program counter: 0x%x(%s) caused\n", r->pc, cur_cpu()->task); + LOG("program counter: 0x%x caused\n", r->pc); LOG("data abort at 0x%x, status 0x%x\n", dfa, dfs); _abort_reason(dfs); dump_tf(r); } if (cur_cpu()->task != NULL) { sys_exit(); + context_switch(&cur_cpu()->task->main_thread.context, cur_cpu()->scheduler); } else { // Exception occured in Kernel space: panic - LOG("program counter: 0x%x(%s) caused\n", r->pc, cur_cpu()->task); + LOG("program counter: 0x%x caused\n", r->pc); LOG("data abort at 0x%x, status 0x%x\n", dfa, dfs); _abort_reason(dfs); dump_tf(r); @@ -132,6 +134,7 @@ void iabort_handler(struct trapframe* r) } if (cur_cpu()->task != NULL) { sys_exit(); + context_switch(&cur_cpu()->task->main_thread.context, cur_cpu()->scheduler); } else { // Exception occured in Kernel space: panic LOG("program counter: 0x%x(%s) caused\n", r->pc, cur_cpu()->task); LOG("prefetch abort at 0x%x, status 0x%x\n", ifa, ifs); diff --git a/Ubiquitous/XiZi_AIoT/services/app/Makefile b/Ubiquitous/XiZi_AIoT/services/app/Makefile index 56dba7e38..fd0fb506b 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/app/Makefile @@ -23,7 +23,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \ -I$(KERNEL_ROOT)/services/boards/$(BOARD) \ -I$(KERNEL_ROOT)/services/app -all: init simple_client simple_server shell fs_server test_priority readme.txt | bin +all: init test_fs simple_client simple_server shell fs_server test_priority readme.txt | bin ../tools/mkfs/mkfs ./fs.img $^ @mv $(filter-out readme.txt, $^) bin @mv *.o bin @@ -40,6 +40,10 @@ init: init.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o @${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} @${objdump} -S $@ > $@.asm +test_fs: test_fs.o libfs_to_client.o libipc.o session.o libserial.o usyscall.o + @${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} + @${objdump} -S $@ > $@.asm + simple_client: simple_client.o libserial.o libipc.o session.o simple_service.o libfs_to_client.o usyscall.o @${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} @${objdump} -S $@ > $@.asm diff --git a/Ubiquitous/XiZi_AIoT/services/app/simple_server.c b/Ubiquitous/XiZi_AIoT/services/app/simple_server.c index 612ce293a..90cb8e442 100755 --- a/Ubiquitous/XiZi_AIoT/services/app/simple_server.c +++ b/Ubiquitous/XiZi_AIoT/services/app/simple_server.c @@ -15,6 +15,8 @@ #include "simple_service.h" #include "usyscall.h" +/// @warning all the parameters should in the form of pointers +/// for the true storing memory of parameters is session(shared memory between tasks) int IPC_DO_SERVE_FUNC(Ipc_add)(int* a, int* b) { return *a + *b; diff --git a/Ubiquitous/XiZi_AIoT/services/app/test_fs.c b/Ubiquitous/XiZi_AIoT/services/app/test_fs.c index 4c612e6d7..3e592530f 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/test_fs.c +++ b/Ubiquitous/XiZi_AIoT/services/app/test_fs.c @@ -19,6 +19,7 @@ #include "libfs_to_client.h" #include "usyscall.h" +#define BLOCK_SIZE 256 int main(int argc, char* argv[]) { printf("file system test\n"); @@ -26,8 +27,6 @@ int main(int argc, char* argv[]) struct Session session; connect_session(&session, "MemFS", 4096); - register_server("TEST_FS"); - int fd; char* fd_path = "/readme.txt"; fd = open(&session, fd_path); @@ -43,9 +42,12 @@ int main(int argc, char* argv[]) printf("file content: %s\n", buffer); close(&session, fd); - free_session(&session); + printf("file test done.\n"); + printf("Test memry error %s.\n", 0x50000000); + printf("After error computing.\n"); + exit(); return 0; } diff --git a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h index 73e018e39..86148a9a6 100644 --- a/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h +++ b/Ubiquitous/XiZi_AIoT/services/lib/ipc/libipc.h @@ -182,6 +182,14 @@ void ipc_server_loop(struct IpcNode* ipc_node); #define IPC_SERVE(ipc_name) ipc_serve_##ipc_name #define IPC_DO_SERVE_FUNC(ipc_name) ipc_do_serve_##ipc_name +/// when defining a ipc server: +/// 1. requires a IPC_SERVICES(server_name, interface_name, ...) to announce the name and interfaces that the server will support +/// 2. implement IPC_DO_SERVE_FUNC(interface_name) for each interface +/// 3. use IPC_SERVER_INTERFACE(interface_name, argc) to generate necessary helper functions +/// 4. use IPC_SERVER_REGISTER_INTERFACES(server_name, nr_interfaces, interface_names, ...) to bind interfaces to server after implementations +/// 5. use ipc_server_loop in main() +/// Refer to simple_service.h, simple_service.c and simple_server.c for example + #define IPC_INTERFACE(ipc_name, argc, ...) \ __always_inline static inline struct IpcMsg* IPC_CREATE_MSG_FUNC(ipc_name)(struct Session * session, _VA_FRONT_PTR_ARG##argc(__VA_ARGS__)) \ { \ diff --git a/Ubiquitous/XiZi_AIoT/softkernel/Makefile b/Ubiquitous/XiZi_AIoT/softkernel/Makefile index 7e15af1a7..1464fe7b9 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/Makefile +++ b/Ubiquitous/XiZi_AIoT/softkernel/Makefile @@ -1,4 +1,4 @@ -SRC_DIR := init memory trap task syscall ipc +SRC_DIR := init memory trap task syscall SRC_FILES := main.c load_apps.S diff --git a/Ubiquitous/XiZi_AIoT/softkernel/ipc/Makefile b/Ubiquitous/XiZi_AIoT/softkernel/ipc/Makefile deleted file mode 100644 index a8abfc5fb..000000000 --- a/Ubiquitous/XiZi_AIoT/softkernel/ipc/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -SRC_FILES := share_page.c - -include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_AIoT/softkernel/memory/Makefile b/Ubiquitous/XiZi_AIoT/softkernel/memory/Makefile index efc31e387..9014b9e7c 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/memory/Makefile +++ b/Ubiquitous/XiZi_AIoT/softkernel/memory/Makefile @@ -1,3 +1,3 @@ -SRC_FILES:= kalloc.c pagetable.c pagetable_level2.c buddy.c object_allocator.c +SRC_FILES:= kalloc.c pagetable.c pagetable_level2.c buddy.c object_allocator.c share_page.c include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_AIoT/softkernel/ipc/share_page.c b/Ubiquitous/XiZi_AIoT/softkernel/memory/share_page.c similarity index 100% rename from Ubiquitous/XiZi_AIoT/softkernel/ipc/share_page.c rename to Ubiquitous/XiZi_AIoT/softkernel/memory/share_page.c diff --git a/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c b/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c index d737452ea..445c64add 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/trap/default_irq_handler.c @@ -60,7 +60,7 @@ void intr_irq_dispatch(struct trapframe* tf) p_intr_driver->cpu_irq_disable(); // enter irq - uint32_t int_info = 0; + uintptr_t int_info = 0; if ((int_info = p_intr_driver->hw_before_irq()) == 0) { return; }