|
56 | 56 | RV_I( sr s9, ___callee_saved_t_s9_OFFSET(sp) );\
|
57 | 57 | RV_I( sr s10, ___callee_saved_t_s10_OFFSET(sp) );\
|
58 | 58 | RV_I( sr s11, ___callee_saved_t_s11_OFFSET(sp) )
|
| 59 | + |
| 60 | +/** |
| 61 | + * Convenience macro to store the caller-saved registers (CSF) on stack, |
| 62 | + * and link it to the `struct arch_esf`. |
| 63 | + * 1. Restore the `s0` we saved early in ISR entry so it shows up properly in the CSF. |
| 64 | + * 2. Allocate space for CSF on current thread stack |
| 65 | + * 3. Save CSF to the allocated stack |
| 66 | + * 4. Link the saved CSF to the `struct arch_esf` |
| 67 | + */ |
| 68 | +#define STORE_CSF_IN_ESF(_esf) \ |
| 69 | + lr s0, __struct_arch_esf_s0_OFFSET(sp) ; \ |
| 70 | + addi sp, sp, -__callee_saved_t_SIZEOF ; \ |
| 71 | + STORE_CALLEE_SAVED() ; \ |
| 72 | + sr sp __struct_arch_esf_csf_OFFSET(_esf) |
59 | 73 | #endif /* CONFIG_EXCEPTION_DEBUG */
|
60 | 74 |
|
61 | 75 | .macro get_current_cpu dst
|
@@ -383,8 +397,18 @@ no_fp: /* increment _current->arch.exception_depth */
|
383 | 397 | * no_reschedule to restore stack.
|
384 | 398 | */
|
385 | 399 | mv a0, sp
|
| 400 | +#ifdef CONFIG_EXCEPTION_DEBUG |
| 401 | + STORE_CSF_IN_ESF(a0) ; |
| 402 | + |
| 403 | + call z_riscv_fault |
| 404 | + /* Restore SP if z_riscv_fault returns before jumping to no_reschedule */ |
| 405 | + addi sp, sp, __callee_saved_t_SIZEOF |
| 406 | + |
| 407 | + j no_reschedule |
| 408 | +#else |
386 | 409 | la ra, no_reschedule
|
387 | 410 | tail z_riscv_fault
|
| 411 | +#endif /* CONFIG_EXCEPTION_DEBUG */ |
388 | 412 |
|
389 | 413 | is_kernel_syscall:
|
390 | 414 | /*
|
@@ -454,20 +478,7 @@ do_fault:
|
454 | 478 | 1: mv a1, sp
|
455 | 479 |
|
456 | 480 | #ifdef CONFIG_EXCEPTION_DEBUG
|
457 |
| - /* |
458 |
| - * Restore the s0 we saved early in ISR entry |
459 |
| - * so it shows up properly in the CSF. |
460 |
| - */ |
461 |
| - lr s0, __struct_arch_esf_s0_OFFSET(sp) |
462 |
| - |
463 |
| - /* Allocate space for caller-saved registers on current thread stack */ |
464 |
| - addi sp, sp, -__callee_saved_t_SIZEOF |
465 |
| - |
466 |
| - /* Save callee-saved registers */ |
467 |
| - STORE_CALLEE_SAVED() ; |
468 |
| - |
469 |
| - /* Store csf's addr into esf (a1 still holds the pointer to the esf at this point) */ |
470 |
| - sr sp __struct_arch_esf_csf_OFFSET(a1) |
| 481 | + STORE_CSF_IN_ESF(a1) ; |
471 | 482 | #endif /* CONFIG_EXCEPTION_DEBUG */
|
472 | 483 | tail z_riscv_fatal_error
|
473 | 484 |
|
|
0 commit comments