Skip to content

Commit a160e94

Browse files
committed
xtensa: fix unaligned and load/store configuration interaction
Unaligned exception handler is needed in configurations with hardware support for unaligned access when the load/store exception handler is enabled because such configurations would still raise an exception on unaligned access through the instruction bus. Fixes: f29cf77 ("xtensa: add load/store exception handler") Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
1 parent bc8d591 commit a160e94

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

arch/xtensa/kernel/align.S

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* arch/xtensa/kernel/align.S
33
*
4-
* Handle unalignment exceptions in kernel space.
4+
* Handle unalignment and load/store exceptions.
55
*
66
* This file is subject to the terms and conditions of the GNU General
77
* Public License. See the file "COPYING" in the main directory of
@@ -26,20 +26,18 @@
2626
#define LOAD_EXCEPTION_HANDLER
2727
#endif
2828

29-
#if XCHAL_UNALIGNED_STORE_EXCEPTION || defined LOAD_EXCEPTION_HANDLER
29+
#if XCHAL_UNALIGNED_STORE_EXCEPTION || defined CONFIG_XTENSA_LOAD_STORE
30+
#define STORE_EXCEPTION_HANDLER
31+
#endif
32+
33+
#if defined LOAD_EXCEPTION_HANDLER || defined STORE_EXCEPTION_HANDLER
3034
#define ANY_EXCEPTION_HANDLER
3135
#endif
3236

33-
#if XCHAL_HAVE_WINDOWED
37+
#if XCHAL_HAVE_WINDOWED && defined CONFIG_MMU
3438
#define UNALIGNED_USER_EXCEPTION
3539
#endif
3640

37-
/* First-level exception handler for unaligned exceptions.
38-
*
39-
* Note: This handler works only for kernel exceptions. Unaligned user
40-
* access should get a seg fault.
41-
*/
42-
4341
/* Big and little endian 16-bit values are located in
4442
* different halves of a register. HWORD_START helps to
4543
* abstract the notion of extracting a 16-bit value from a
@@ -228,8 +226,6 @@ ENDPROC(fast_load_store)
228226
#ifdef ANY_EXCEPTION_HANDLER
229227
ENTRY(fast_unaligned)
230228

231-
#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
232-
233229
call0 .Lsave_and_load_instruction
234230

235231
/* Analyze the instruction (load or store?). */
@@ -244,8 +240,7 @@ ENTRY(fast_unaligned)
244240
/* 'store indicator bit' not set, jump */
245241
_bbci.l a4, OP1_SI_BIT + INSN_OP1, .Lload
246242

247-
#endif
248-
#if XCHAL_UNALIGNED_STORE_EXCEPTION
243+
#ifdef STORE_EXCEPTION_HANDLER
249244

250245
/* Store: Jump to table entry to get the value in the source register.*/
251246

@@ -254,7 +249,7 @@ ENTRY(fast_unaligned)
254249
addx8 a5, a6, a5
255250
jx a5 # jump into table
256251
#endif
257-
#if XCHAL_UNALIGNED_LOAD_EXCEPTION
252+
#ifdef LOAD_EXCEPTION_HANDLER
258253

259254
/* Load: Load memory address. */
260255

@@ -328,7 +323,7 @@ ENTRY(fast_unaligned)
328323
mov a14, a3 ; _j .Lexit; .align 8
329324
mov a15, a3 ; _j .Lexit; .align 8
330325
#endif
331-
#if XCHAL_UNALIGNED_STORE_EXCEPTION
326+
#ifdef STORE_EXCEPTION_HANDLER
332327
.Lstore_table:
333328
l32i a3, a2, PT_AREG0; _j .Lstore_w; .align 8
334329
mov a3, a1; _j .Lstore_w; .align 8 # fishy??
@@ -348,7 +343,6 @@ ENTRY(fast_unaligned)
348343
mov a3, a15 ; _j .Lstore_w; .align 8
349344
#endif
350345

351-
#ifdef ANY_EXCEPTION_HANDLER
352346
/* We cannot handle this exception. */
353347

354348
.extern _kernel_exception
@@ -377,8 +371,8 @@ ENTRY(fast_unaligned)
377371

378372
2: movi a0, _user_exception
379373
jx a0
380-
#endif
381-
#if XCHAL_UNALIGNED_STORE_EXCEPTION
374+
375+
#ifdef STORE_EXCEPTION_HANDLER
382376

383377
# a7: instruction pointer, a4: instruction, a3: value
384378
.Lstore_w:
@@ -444,7 +438,7 @@ ENTRY(fast_unaligned)
444438
s32i a6, a4, 4
445439
#endif
446440
#endif
447-
#ifdef ANY_EXCEPTION_HANDLER
441+
448442
.Lexit:
449443
#if XCHAL_HAVE_LOOPS
450444
rsr a4, lend # check if we reached LEND
@@ -539,7 +533,7 @@ ENTRY(fast_unaligned)
539533
__src_b a4, a4, a5 # a4 has the instruction
540534

541535
ret
542-
#endif
536+
543537
ENDPROC(fast_unaligned)
544538

545539
ENTRY(fast_unaligned_fixup)

arch/xtensa/kernel/traps.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ static dispatch_init_table_t __initdata dispatch_init_table[] = {
102102
#endif
103103
{ EXCCAUSE_INTEGER_DIVIDE_BY_ZERO, 0, do_div0 },
104104
/* EXCCAUSE_PRIVILEGED unhandled */
105-
#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION
105+
#if XCHAL_UNALIGNED_LOAD_EXCEPTION || XCHAL_UNALIGNED_STORE_EXCEPTION || \
106+
IS_ENABLED(CONFIG_XTENSA_LOAD_STORE)
106107
#ifdef CONFIG_XTENSA_UNALIGNED_USER
107108
{ EXCCAUSE_UNALIGNED, USER, fast_unaligned },
108109
#endif

0 commit comments

Comments
 (0)