trap_c.c 874 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (C) 2017-2019 Alibaba Group Holding Limited
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-08-20 zx.chen source file for the trap process
  9. */
  10. #include <stdint.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <csi_config.h>
  14. #include <csi_core.h>
  15. void (*trap_c_callback)(void);
  16. void trap_c(uint32_t *regs)
  17. {
  18. int i;
  19. uint32_t vec = 0;
  20. vec = __get_MCAUSE() & 0x3FF;
  21. printf("CPU Exception: NO.%ld", vec);
  22. printf("\n");
  23. for (i = 0; i < 31; i++)
  24. {
  25. printf("x%d: %08lx\t", i + 1, regs[i]);
  26. if ((i % 4) == 3)
  27. {
  28. printf("\n");
  29. }
  30. }
  31. printf("\n");
  32. printf("mepc : %08lx\n", regs[31]);
  33. printf("mstatus: %08lx\n", regs[32]);
  34. if (trap_c_callback)
  35. {
  36. trap_c_callback();
  37. }
  38. while (1);
  39. }