diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/core.h b/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/core.h index d52b8dafb..21a86db89 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/core.h +++ b/Ubiquitous/XiZi_AIoT/hardkernel/arch/riscv/rv64gc/core.h @@ -211,8 +211,8 @@ extern int syscall(int sys_num, uintptr_t param1, uintptr_t param2, uintptr_t pa __attribute__((__always_inline__)) static inline int arch_syscall(struct trapframe* tf, int* syscall_num) { // call syscall - *syscall_num = tf->a0; - return syscall(*syscall_num, tf->a1, tf->a2, tf->a3, tf->a4); + *syscall_num = tf->a7; + return syscall(*syscall_num, tf->a0, tf->a1, tf->a2, tf->a3); } /// @brief set return reg to trapframe diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/jh7110/trap.c b/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/jh7110/trap.c index 84bfdd01f..3a1a4c8db 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/jh7110/trap.c +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/jh7110/trap.c @@ -78,42 +78,20 @@ void kernel_intr_handler(struct trapframe* tf) extern void context_switch(struct context**, struct context*); void syscall_arch_handler(struct trapframe* tf) { + uint64_t ec = tf->cause; - uint64_t esr = r_esr_el1(); - uint64_t ec = (esr >> 0x1A) & 0x3F; switch (ec) { - case 0B010101: + case EXC_SYSCALL: software_irq_dispatch(tf); break; - case 0b100100: - case 0b100101: - dabort_handler(tf); - break; - case 0b100000: - case 0b100001: - iabort_handler(tf); - break; + default: { ERROR("USYSCALL: unexpected\n"); - ERROR(" esr: %016lx\n", esr); - ERROR(" elr = %016lx far = %016lx\n", r_elr_el1(), r_far_el1()); - w_esr_el1(0); + ERROR("tf->cause: %016lx\n", tf->cause); + extern void dump_tf(struct trapframe * tf); dump_tf(tf); - uint32_t sctlr = 0; - SCTLR_R(sctlr); - DEBUG("SCTLR: %x\n", sctlr); - uint32_t spsr = 0; -// __asm__ volatile("mrs %0, spsr_el1" : "=r"(spsr)::"memory"); - DEBUG("SPSR: %x\n", spsr); - uint64_t tcr = 0; -// __asm__ volatile("mrs %0, tcr_el1" : "=r"(tcr)::"memory"); - DEBUG("TCR: %x\n", tcr); - uint64_t mair = 0; -// __asm__ volatile("mrs %0, mair_el1" : "=r"(mair)::"memory"); - DEBUG("MAIR: %x\n", mair); - // kill error task xizi_enter_kernel(); assert(cur_cpu()->task != NULL); diff --git a/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/trampoline.S b/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/trampoline.S index 0d6d12b54..c8c2ce3fa 100644 --- a/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/trampoline.S +++ b/Ubiquitous/XiZi_AIoT/hardkernel/intr/riscv/rv64gc/trampoline.S @@ -151,7 +151,41 @@ _save_context: tail do_exception handle_syscall: - j . + /* save the initial A0 value (needed in signal handlers) */ + REG_S a0, PT_ORIG_A0(sp) + /* + * Advance SEPC to avoid executing the original + * scall instruction on sret + */ + addi s2, s2, 0x4 + REG_S s2, PT_EPC(sp) + + /* Trace syscalls, but only if requested by the user. */ + j handle_syscall_trace_enter + + ret + + +/* Slow paths for ptrace. */ +handle_syscall_trace_enter: + move a0, sp + //call do_syscall_trace_enter + call syscall_arch_handler + move t0, a0 + REG_L a0, PT_A0(sp) + REG_L a1, PT_A1(sp) + REG_L a2, PT_A2(sp) + REG_L a3, PT_A3(sp) + REG_L a4, PT_A4(sp) + REG_L a5, PT_A5(sp) + REG_L a6, PT_A6(sp) + REG_L a7, PT_A7(sp) + //bnez t0, ret_from_syscall_rejected + //j check_syscall_nr +handle_syscall_trace_exit: + move a0, sp + //call do_syscall_trace_exit + j ret_from_exception ret_from_exception: diff --git a/Ubiquitous/XiZi_AIoT/services/boards/jh7110/arch_usyscall.c b/Ubiquitous/XiZi_AIoT/services/boards/jh7110/arch_usyscall.c index 4f9eceb3c..9b2d788d6 100644 --- a/Ubiquitous/XiZi_AIoT/services/boards/jh7110/arch_usyscall.c +++ b/Ubiquitous/XiZi_AIoT/services/boards/jh7110/arch_usyscall.c @@ -11,22 +11,33 @@ */ #include "usyscall.h" +int sbi_ecall(int ext, int fid, unsigned long arg0, + unsigned long arg1, unsigned long arg2, + unsigned long arg3, unsigned long arg4, + unsigned long arg5) +{ + int ret; + + register uintptr_t a0 __asm__ ("a0") = (uintptr_t)(arg0); + register uintptr_t a1 __asm__ ("a1") = (uintptr_t)(arg1); + register uintptr_t a2 __asm__ ("a2") = (uintptr_t)(arg2); + register uintptr_t a3 __asm__ ("a3") = (uintptr_t)(arg3); + register uintptr_t a4 __asm__ ("a4") = (uintptr_t)(arg4); + register uintptr_t a5 __asm__ ("a5") = (uintptr_t)(arg5); + register uintptr_t a6 __asm__ ("a6") = (uintptr_t)(fid); + register uintptr_t a7 __asm__ ("a7") = (uintptr_t)(ext); + __asm__ volatile ("ecall" + : "+r" (a0), "+r" (a1) + : "r" (a2), "r" (a3), "r" (a4), "r" (a5), "r" (a6), "r" (a7) + : "memory"); + ret = a0; + + return ret; +} + int syscall(int sys_num, intptr_t a1, intptr_t a2, intptr_t a3, intptr_t a4) { int ret = -1; - - __asm__ volatile( - "mv a0, %1;\ - mv a1, %2;\ - mv a2, %3;\ - mv a3, %4;\ - mv a4, %5;\ - ecall;\ - mv %0, a0" - : "=r"(ret) - : "r"(sys_num), "r"(a1), "r"(a2), "r"(a3), "r"(a4) - : "memory", "a0", "a1", "a2", "a3", "a4" - ); - + ret = sbi_ecall(sys_num, 0, a1, a2, a3, a4, 0, 0); return ret; -} \ No newline at end of file +} diff --git a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c index 67aea6b05..6f672a1bb 100644 --- a/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c +++ b/Ubiquitous/XiZi_AIoT/softkernel/syscall/sys_state.c @@ -153,8 +153,13 @@ int sys_state(sys_state_option option, sys_state_info* info) { switch (option) { case SYS_STATE_MEMBLOCK_INFO: { +#ifndef __riscv 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 + info->memblock_info.memblock_start = (uintptr_t)V2P_LINK(_binary_fs_img_start); + info->memblock_info.memblock_end = (uintptr_t)V2P_LINK(_binary_fs_img_end); +#endif break; } case SYS_STATE_GET_HEAP_BASE: