Skip to content

Commit bc0656a

Browse files
dcpleungcarlescufi
authored andcommitted
xtensa: mmu: allocate scratch registers for MMU
When MMU is enabled, we need some scratch registers to preload page table entries. So update gen_zsr.py to that. Signed-off-by: Daniel Leung <[email protected]> Signed-off-by: Flavio Ceolin <[email protected]>
1 parent c4706a3 commit bc0656a

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

arch/xtensa/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ add_custom_command(OUTPUT ${CORE_ISA_DM}
5959
set(ZSR_H ${CMAKE_BINARY_DIR}/zephyr/include/generated/zsr.h)
6060
add_custom_command(OUTPUT ${ZSR_H} DEPENDS ${CORE_ISA_DM}
6161
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gen_zsr.py
62+
$<$<BOOL:${CONFIG_XTENSA_MMU}>:--mmu>
6263
${CORE_ISA_DM} ${ZSR_H})
6364
add_custom_target(zsr_h DEPENDS ${ZSR_H})
6465
add_dependencies(zephyr_interface zsr_h)

arch/xtensa/core/gen_zsr.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python3
22
# Copyright (c) 2022 Intel corporation
33
# SPDX-License-Identifier: Apache-2.0
4-
import sys
4+
import argparse
55
import re
66

77
# Scratch register allocator. Zephyr uses multiple Xtensa SRs as
@@ -11,10 +11,26 @@
1111
# -dM") core-isa.h file for the current architecture and assigns
1212
# registers to usages.
1313

14-
NEEDED = ("A0SAVE", "CPU", "FLUSH")
14+
def parse_args():
15+
parser = argparse.ArgumentParser(allow_abbrev=False)
1516

16-
coreisa = sys.argv[1]
17-
outfile = sys.argv[2]
17+
parser.add_argument("--mmu", action="store_true",
18+
help="Enable scratch registers for MMU usage")
19+
parser.add_argument("coreisa",
20+
help="Path to preprocessed core-isa.h")
21+
parser.add_argument("outfile",
22+
help="Output file")
23+
24+
return parser.parse_args()
25+
26+
args = parse_args()
27+
28+
NEEDED = ["A0SAVE", "CPU", "FLUSH"]
29+
if args.mmu:
30+
NEEDED += ["MMU_0", "MMU_1", "DBLEXC"]
31+
32+
coreisa = args.coreisa
33+
outfile = args.outfile
1834

1935
syms = {}
2036

arch/xtensa/core/xtensa-asm2-util.S

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,14 +439,14 @@ _handle_tlb_miss_kernel:
439439
.global _DoubleExceptionVector
440440
_DoubleExceptionVector:
441441
#ifdef CONFIG_XTENSA_MMU
442-
wsr a0, ZSR_A0SAVE
442+
wsr a0, ZSR_DBLEXC
443443
rsync
444444

445445
rsr.exccause a0
446446
addi a0, a0, -EXCCAUSE_DTLB_MISS
447447
beqz a0, _handle_tlb_miss_dblexc
448448

449-
rsr a0, ZSR_A0SAVE
449+
rsr a0, ZSR_DBLEXC
450450

451451
j _Level1Vector
452452
#else
@@ -482,7 +482,7 @@ _handle_tlb_miss_dblexc:
482482
rsr.ptevaddr a0
483483
l32i a0, a0, 0
484484

485-
rsr a0, ZSR_A0SAVE
485+
rsr a0, ZSR_DBLEXC
486486
rfde
487487
#endif
488488
.popsection

arch/xtensa/include/xtensa-asm2-s.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,8 @@ _Level\LVL\()VectorHelper :
558558
_Level\LVL\()Vector:
559559
#endif
560560
#ifdef CONFIG_XTENSA_MMU
561-
wsr.ZSR_EXTRA0 a2
562-
wsr.ZSR_EXTRA1 a3
561+
wsr.ZSR_MMU_0 a2
562+
wsr.ZSR_MMU_1 a3
563563
rsync
564564

565565
/* Calculations below will clobber registers used.
@@ -579,8 +579,8 @@ _Level\LVL\()Vector:
579579
rsr.ZSR_CPU a3
580580
PRELOAD_PTEVADDR a3, a2
581581

582-
rsr.ZSR_EXTRA1 a3
583-
rsr.ZSR_EXTRA0 a2
582+
rsr.ZSR_MMU_1 a3
583+
rsr.ZSR_MMU_0 a2
584584
#endif /* CONFIG_XTENSA_MMU */
585585
addi a1, a1, -___xtensa_irq_bsa_t_SIZEOF
586586
s32i a0, a1, ___xtensa_irq_bsa_t_a0_OFFSET

0 commit comments

Comments
 (0)