|
47 | 47 | * Pushes registers r4~r12 and lr on the stack. |
48 | 48 | * r0 is unmodified but other GPRs may be overwritten. |
49 | 49 | */ |
| 50 | +#if !defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) |
| 51 | +/* `push` on ARMv6-M / ARMv8-M Baseline: |
| 52 | + * only r0~r7 and lr may be pushed |
| 53 | + */ |
| 54 | +#define PUSH_GPRS \ |
| 55 | + push {r4-r7}; \ |
| 56 | + mov r1, r8; \ |
| 57 | + mov r2, r9; \ |
| 58 | + mov r3, r10; \ |
| 59 | + mov r4, r11; \ |
| 60 | + mov r5, r12; \ |
| 61 | + push {r1-r5, lr} |
| 62 | +#else |
| 63 | +/* `push` on ARMv7-M and ARMv8-M Mainline: no limitation */ |
50 | 64 | #define PUSH_GPRS \ |
51 | 65 | push {r4-r12, lr} |
| 66 | +#endif /* !CONFIG_ARMV7_M_ARMV8_M_MAINLINE */ |
52 | 67 |
|
53 | 68 | /* |
54 | 69 | * Pops registers r4~r12 and lr from the stack |
55 | 70 | * r0 is unmodified but other GPRs may be overwritten. |
56 | 71 | */ |
| 72 | +#if !defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) |
| 73 | +/* `pop` on ARMv6-M / ARMv8-M Baseline: |
| 74 | + * can only pop to r0~r7 and pc (not lr!) |
| 75 | + */ |
| 76 | +#define POP_GPRS \ |
| 77 | + pop {r1-r6}; \ |
| 78 | + mov lr, r6; \ |
| 79 | + mov r12, r5; \ |
| 80 | + mov r11, r4; \ |
| 81 | + mov r10, r3; \ |
| 82 | + mov r9, r2; \ |
| 83 | + mov r8, r1; \ |
| 84 | + pop {r4-r7} |
| 85 | +#else |
| 86 | +/* `pop` on ARMv7-M and ARMv8-M Mainline: no limitation */ |
57 | 87 | #define POP_GPRS \ |
58 | 88 | pop {r4-r12, lr} |
| 89 | +#endif /* !CONFIG_ARMV7_M_ARMV8_M_MAINLINE */ |
| 90 | + |
| 91 | + |
| 92 | +#if defined(CONFIG_ARMV7_M_ARMV8_M_MAINLINE) |
| 93 | +/* Registers present only on ARMv7-M and ARMv8-M Mainline */ |
| 94 | +#define SAVE_FM_BP_REGS(cpu_ctx, tmp_reg) \ |
| 95 | + SAVE_SPECIAL_REG(faultmask, cpu_ctx, tmp_reg) \ |
| 96 | + SAVE_SPECIAL_REG(basepri, cpu_ctx, tmp_reg) |
| 97 | + |
| 98 | +#define RESTORE_FM_BP_REGS(cpu_ctx, tmp_reg) \ |
| 99 | + RESTORE_SPECIAL_REG(faultmask, cpu_ctx, tmp_reg) \ |
| 100 | + RESTORE_SPECIAL_REG(basepri, cpu_ctx, tmp_reg) |
| 101 | +#else |
| 102 | +/* Registers not present: do nothing */ |
| 103 | +#define SAVE_FM_BP_REGS(cpu_ctx, tmp_reg) |
| 104 | +#define RESTORE_FM_BP_REGS(cpu_ctx, tmp_reg) |
| 105 | +#endif /* CONFIG_ARMV7_M_ARMV8_M_MAINLINE */ |
| 106 | + |
| 107 | +#if defined(CONFIG_CPU_CORTEX_M_HAS_SPLIM) |
| 108 | +/* Registers present only on certain ARMv8-M implementations */ |
| 109 | +#define SAVE_SPLIM_REGS(cpu_ctx, tmp_reg) \ |
| 110 | + SAVE_SPECIAL_REG(msplim, cpu_ctx, tmp_reg) \ |
| 111 | + SAVE_SPECIAL_REG(psplim, cpu_ctx, tmp_reg) |
| 112 | + |
| 113 | +#define RESTORE_SPLIM_REGS(cpu_ctx, tmp_reg) \ |
| 114 | + RESTORE_SPECIAL_REG(msplim, cpu_ctx, tmp_reg) \ |
| 115 | + RESTORE_SPECIAL_REG(psplim, cpu_ctx, tmp_reg) |
| 116 | +#else |
| 117 | +/* Registers not present: do nothing */ |
| 118 | +#define SAVE_SPLIM_REGS(cpu_ctx, tmp_reg) |
| 119 | +#define RESTORE_SPLIM_REGS(cpu_ctx, tmp_reg) |
| 120 | +#endif /* CONFIG_CPU_CORTEX_M_HAS_SPLIM */ |
59 | 121 |
|
60 | 122 | /* |
61 | 123 | * Saves the CPU's special registers in the `struct __cpu_context` |
|
64 | 126 | */ |
65 | 127 | #define SAVE_SPECIAL_REGISTERS(cpu_ctx, tmp_reg) \ |
66 | 128 | SAVE_SPECIAL_REG(msp, cpu_ctx, tmp_reg) \ |
67 | | - SAVE_SPECIAL_REG(msplim, cpu_ctx, tmp_reg) \ |
68 | 129 | SAVE_SPECIAL_REG(psp, cpu_ctx, tmp_reg) \ |
69 | | - SAVE_SPECIAL_REG(psplim, cpu_ctx, tmp_reg) \ |
70 | 130 | SAVE_SPECIAL_REG(primask, cpu_ctx, tmp_reg) \ |
71 | | - SAVE_SPECIAL_REG(faultmask, cpu_ctx, tmp_reg) \ |
72 | | - SAVE_SPECIAL_REG(basepri, cpu_ctx, tmp_reg) \ |
| 131 | + SAVE_SPLIM_REGS( cpu_ctx, tmp_reg) \ |
| 132 | + SAVE_FM_BP_REGS( cpu_ctx, tmp_reg) \ |
73 | 133 | SAVE_SPECIAL_REG(control, cpu_ctx, tmp_reg) |
74 | 134 |
|
75 | 135 | /* |
|
86 | 146 | */ |
87 | 147 | #define RESTORE_SPECIAL_REGISTERS(cpu_ctx, tmp_reg) \ |
88 | 148 | RESTORE_SPECIAL_REG(msp, cpu_ctx, tmp_reg) \ |
89 | | - RESTORE_SPECIAL_REG(msplim, cpu_ctx, tmp_reg) \ |
90 | 149 | RESTORE_SPECIAL_REG(psp, cpu_ctx, tmp_reg) \ |
91 | | - RESTORE_SPECIAL_REG(psplim, cpu_ctx, tmp_reg) \ |
92 | 150 | RESTORE_SPECIAL_REG(primask, cpu_ctx, tmp_reg) \ |
93 | | - RESTORE_SPECIAL_REG(faultmask, cpu_ctx, tmp_reg) \ |
94 | | - RESTORE_SPECIAL_REG(basepri, cpu_ctx, tmp_reg) \ |
| 151 | + RESTORE_SPLIM_REGS( cpu_ctx, tmp_reg) \ |
| 152 | + RESTORE_FM_BP_REGS( cpu_ctx, tmp_reg) \ |
95 | 153 | RESTORE_SPECIAL_REG(control, cpu_ctx, tmp_reg) \ |
96 | 154 | isb |
97 | 155 |
|
@@ -174,5 +232,5 @@ resume: |
174 | 232 | /* |
175 | 233 | * Set the return value and return |
176 | 234 | */ |
177 | | - mov r0, #0 |
| 235 | + movs r0, #0 |
178 | 236 | bx lr |
0 commit comments