@@ -198,47 +198,53 @@ asmlinkage __visible __trap_section void do_trap_insn_illegal(struct pt_regs *re
198
198
DO_ERROR_INFO (do_trap_load_fault ,
199
199
SIGSEGV , SEGV_ACCERR , "load access fault" );
200
200
201
- asmlinkage __visible __trap_section void do_trap_load_misaligned (struct pt_regs * regs )
201
+ enum misaligned_access_type {
202
+ MISALIGNED_STORE ,
203
+ MISALIGNED_LOAD ,
204
+ };
205
+ static const struct {
206
+ const char * type_str ;
207
+ int (* handler )(struct pt_regs * regs );
208
+ } misaligned_handler [] = {
209
+ [MISALIGNED_STORE ] = {
210
+ .type_str = "Oops - store (or AMO) address misaligned" ,
211
+ .handler = handle_misaligned_store ,
212
+ },
213
+ [MISALIGNED_LOAD ] = {
214
+ .type_str = "Oops - load address misaligned" ,
215
+ .handler = handle_misaligned_load ,
216
+ },
217
+ };
218
+
219
+ static void do_trap_misaligned (struct pt_regs * regs , enum misaligned_access_type type )
202
220
{
203
- if (user_mode (regs )) {
221
+ irqentry_state_t state ;
222
+
223
+ if (user_mode (regs ))
204
224
irqentry_enter_from_user_mode (regs );
225
+ else
226
+ state = irqentry_nmi_enter (regs );
205
227
206
- if (handle_misaligned_load (regs ))
207
- do_trap_error (regs , SIGBUS , BUS_ADRALN , regs -> epc ,
208
- "Oops - load address misaligned" );
228
+ if (misaligned_handler [ type ]. handler (regs ))
229
+ do_trap_error (regs , SIGBUS , BUS_ADRALN , regs -> epc ,
230
+ misaligned_handler [ type ]. type_str );
209
231
232
+ if (user_mode (regs ))
210
233
irqentry_exit_to_user_mode (regs );
211
- } else {
212
- irqentry_state_t state = irqentry_nmi_enter (regs );
213
-
214
- if (handle_misaligned_load (regs ))
215
- do_trap_error (regs , SIGBUS , BUS_ADRALN , regs -> epc ,
216
- "Oops - load address misaligned" );
217
-
234
+ else
218
235
irqentry_nmi_exit (regs , state );
219
- }
220
236
}
221
237
222
- asmlinkage __visible __trap_section void do_trap_store_misaligned (struct pt_regs * regs )
238
+ asmlinkage __visible __trap_section void do_trap_load_misaligned (struct pt_regs * regs )
223
239
{
224
- if (user_mode (regs )) {
225
- irqentry_enter_from_user_mode (regs );
226
-
227
- if (handle_misaligned_store (regs ))
228
- do_trap_error (regs , SIGBUS , BUS_ADRALN , regs -> epc ,
229
- "Oops - store (or AMO) address misaligned" );
230
-
231
- irqentry_exit_to_user_mode (regs );
232
- } else {
233
- irqentry_state_t state = irqentry_nmi_enter (regs );
234
-
235
- if (handle_misaligned_store (regs ))
236
- do_trap_error (regs , SIGBUS , BUS_ADRALN , regs -> epc ,
237
- "Oops - store (or AMO) address misaligned" );
240
+ do_trap_misaligned (regs , MISALIGNED_LOAD );
241
+ }
238
242
239
- irqentry_nmi_exit (regs , state );
240
- }
243
+ asmlinkage __visible __trap_section void do_trap_store_misaligned (struct pt_regs * regs )
244
+ {
245
+ do_trap_misaligned (regs , MISALIGNED_STORE );
241
246
}
247
+
242
248
DO_ERROR_INFO (do_trap_store_fault ,
243
249
SIGSEGV , SEGV_ACCERR , "store (or AMO) access fault" );
244
250
DO_ERROR_INFO (do_trap_ecall_s ,
0 commit comments