syscall_c.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-02-03 lizhirui first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #define DBG_LEVEL DBG_WARNING
  13. //#define DBG_LEVEL DBG_INFO
  14. #include <rtdbg.h>
  15. #include <stdint.h>
  16. #include <mmu.h>
  17. #include <page.h>
  18. #include <lwp_mm_area.h>
  19. #include <lwp_user_mm.h>
  20. #include <stdio.h>
  21. #include "riscv_mmu.h"
  22. #include "stack.h"
  23. typedef rt_size_t (*syscallfunc_t)(rt_size_t,rt_size_t,rt_size_t,rt_size_t,rt_size_t,rt_size_t,rt_size_t);
  24. syscallfunc_t lwp_get_sys_api(uint32_t);
  25. void syscall_handler(struct rt_hw_stack_frame *regs)
  26. {
  27. if(regs -> a7 == 0)
  28. {
  29. rt_kprintf("syscall id = 0!\n");
  30. while(1);
  31. }
  32. if(regs -> a7 == 0xdeadbeef)
  33. {
  34. rt_kprintf("syscall id = 0xdeadbeef\n");
  35. while(1);
  36. }
  37. syscallfunc_t syscallfunc = (syscallfunc_t)lwp_get_sys_api(regs -> a7);
  38. if(syscallfunc == RT_NULL)
  39. {
  40. rt_kprintf("unsupported syscall!\n");
  41. while(1);
  42. }
  43. LOG_I("\033[36msyscall id = %d,arg0 = 0x%p,arg1 = 0x%p,arg2 = 0x%p,arg3 = 0x%p,arg4 = 0x%p,arg5 = 0x%p,arg6 = 0x%p\n\033[37m",regs -> a7,regs -> a0,regs -> a1,regs -> a2,regs -> a3,regs -> a4,regs -> a5,regs -> a6);
  44. regs -> a0 = syscallfunc(regs -> a0,regs -> a1,regs -> a2,regs -> a3,regs -> a4,regs -> a5,regs -> a6);
  45. regs -> a7 = 0;
  46. regs -> epc += 4;//skip ecall instruction
  47. LOG_I("\033[36msyscall deal ok,ret = 0x%p\n\033[37m",regs -> a0);
  48. }