trap_c.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /******************************************************************************
  17. * @file trap_c.c
  18. * @brief source file for the trap process
  19. * @version V1.0
  20. * @date 12. December 2017
  21. ******************************************************************************/
  22. #include <stdint.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <csi_config.h>
  26. #include "wm_debug.h"
  27. #include "wm_ram_config.h"
  28. #include "wm_watchdog.h"
  29. void trap_c(uint32_t *regs)
  30. {
  31. int i;
  32. uint32_t vec = 0;
  33. asm volatile(
  34. "mfcr %0, psr \n"
  35. "lsri %0, 16 \n"
  36. "sextb %0 \n"
  37. :"=r"(vec):);
  38. //while (1);
  39. printf("CPU Exception : %u", vec);
  40. printf("\n");
  41. for (i = 0; i < 16; i++) {
  42. printf("r%d: %08x\t", i, regs[i]);
  43. if ((i % 5) == 4) {
  44. printf("\n");
  45. }
  46. }
  47. printf("\n");
  48. printf("epsr: %8x\n", regs[16]);
  49. printf("epc : %8x\n", regs[17]);
  50. tls_sys_set_reboot_reason(REBOOT_REASON_EXCEPTION);
  51. tls_sys_reset();
  52. while (1);
  53. }