|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | /** |
18 | | - * Saves the volatile registers onto the stack. This currently takes 14 |
19 | | - * instructions, so it can be used in exception handlers with 18 instructions |
20 | | - * left. |
| 18 | + * Saves the volatile registers onto the stack. This currently takes |
| 19 | + * 14 instructions, so it can be used in exception handlers with 18 |
| 20 | + * instructions left. |
21 | 21 | * |
22 | | - * On return, x0 and x1 are initialised to elr_el2 and spsr_el2 respectively, |
23 | | - * which can be used as the first and second arguments of a subsequent call. |
| 22 | + * On return, x0 and x1 are initialised to elr_el2 and spsr_el2 |
| 23 | + * respectively, which can be used as the first and second arguments |
| 24 | + * of a subsequent call. |
24 | 25 | */ |
25 | 26 | .macro save_volatile_to_stack |
26 | 27 | /* Reserve stack space and save registers x0-x18, x29 & x30. */ |
|
37 | 38 | stp x29, x30, [sp, #8 * 20] |
38 | 39 |
|
39 | 40 | /* |
40 | | - * Save elr_el1 & spsr_el1. This such that we can take nested exception |
41 | | - * and still be able to unwind. |
| 41 | + * Save elr_el1 & spsr_el1. This such that we can take nested |
| 42 | + * exception and still be able to unwind. |
42 | 43 | */ |
43 | 44 | mrs x0, elr_el1 |
44 | 45 | mrs x1, spsr_el1 |
45 | 46 | stp x0, x1, [sp, #8 * 22] |
46 | 47 | .endm |
47 | 48 |
|
48 | 49 | /** |
49 | | - * Restores the volatile registers from the stack. This currently takes 14 |
50 | | - * instructions, so it can be used in exception handlers while still leaving 18 |
51 | | - * instructions left; if paired with save_volatile_to_stack, there are 4 |
52 | | - * instructions to spare. |
| 50 | + * Restores the volatile registers from the stack. This currently |
| 51 | + * takes 14 instructions, so it can be used in exception handlers |
| 52 | + * while still leaving 18 instructions left; if paired with |
| 53 | + * save_volatile_to_stack, there are 4 instructions to spare. |
53 | 54 | */ |
54 | 55 | .macro restore_volatile_from_stack |
55 | 56 | /* Restore registers x2-x18, x29 & x30. */ |
|
64 | 65 | ldr x18, [sp, #8 * 18] |
65 | 66 | ldp x29, x30, [sp, #8 * 20] |
66 | 67 |
|
67 | | - /* Restore registers elr_el1 & spsr_el1, using x0 & x1 as scratch. */ |
| 68 | + /* |
| 69 | + * Restore registers elr_el1 & spsr_el1, using x0 & x1 as scratch. |
| 70 | + */ |
68 | 71 | ldp x0, x1, [sp, #8 * 22] |
69 | 72 | msr elr_el1, x0 |
70 | 73 | msr spsr_el1, x1 |
|
74 | 77 | .endm |
75 | 78 |
|
76 | 79 | /** |
77 | | - * This is a generic handler for exceptions taken at the current EL while using |
78 | | - * SP0. It behaves similarly to the SPx case by first switching to SPx, doing |
79 | | - * the work, then switching back to SP0 before returning. |
| 80 | + * This is a generic handler for exceptions taken at the current EL |
| 81 | + * while using SP0. It behaves similarly to the SPx case by first |
| 82 | + * switching to SPx, doing the work, then switching back to SP0 before |
| 83 | + * returning. |
| 84 | + * |
| 85 | + * Switching to SPx and calling the Rust handler takes 16 |
| 86 | + * instructions. To restore and return we need an additional 16 |
| 87 | + * instructions, so we can implement the whole handler within the |
| 88 | + * allotted 32 instructions. |
80 | 89 | * |
81 | | - * Switching to SPx and calling the Rust handler takes 16 instructions. To |
82 | | - * restore and return we need an additional 16 instructions, so we can implement |
83 | | - * the whole handler within the allotted 32 instructions. |
84 | 90 | */ |
85 | 91 | .macro current_exception_sp0 handler:req |
86 | 92 | msr spsel, #1 |
|
92 | 98 | .endm |
93 | 99 |
|
94 | 100 | /** |
95 | | - * This is a generic handler for exceptions taken at the current EL while using |
96 | | - * SPx. It saves volatile registers, calls the Rust handler, restores volatile |
97 | | - * registers, then returns. |
| 101 | + * This is a generic handler for exceptions taken at the current EL |
| 102 | + * while using SPx. It saves volatile registers, calls the Rust |
| 103 | + * handler, restores volatile registers, then returns. |
98 | 104 | * |
99 | | - * This also works for exceptions taken from EL0, if we don't care about |
100 | | - * non-volatile registers. |
| 105 | + * This also works for exceptions taken from EL0, if we don't care |
| 106 | + * about non-volatile registers. |
101 | 107 | * |
102 | | - * Saving state and jumping to the Rust handler takes 15 instructions, and |
103 | | - * restoring and returning also takes 15 instructions, so we can fit the whole |
104 | | - * handler in 30 instructions, under the limit of 32. |
| 108 | + * Saving state and jumping to the Rust handler takes 15 instructions, |
| 109 | + * and restoring and returning also takes 15 instructions, so we can |
| 110 | + * fit the whole handler in 30 instructions, under the limit of 32. |
105 | 111 | */ |
106 | 112 | .macro current_exception_spx handler:req |
107 | 113 | save_volatile_to_stack |
|
0 commit comments