Skip to content

Commit fbd9dd4

Browse files
tbr-tthenrikbrixandersen
authored andcommitted
SPARC: Add support for single-vector trapping (SVT)
This adds support for the single-vector trapping (SVT) model, defined by SPARC-V8 Embedded (V8E) Architecture Specification. SVT is available in most LEON processors. With single-vector trapping enabled, all traps are vectored through a single trap vector (TBR.A) rather than one 16-byte entry for each trap type. This improves memory utilization because the full 4 KiB trap table is not needed. This implementation uses a two-level of lookup table to find the handler for the trap type (0..255). - Execution time is constant. - Condition flags are preserved. - The implementation footprint is 60 bytes .text and 284 bytes .rodata. For comparison, a non-SVT table is always 4096 .text. Signed-off-by: Martin Åberg <[email protected]>
1 parent dd5874b commit fbd9dd4

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

arch/sparc/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ config NUM_IRQS
2626
int
2727
default 32
2828

29+
config SPARC_SVT
30+
bool "Single-vector trapping"
31+
help
32+
Use Single-vector trapping (SVT). Defined by SPARC-V8 Embedded (V8E)
33+
Architecture Specification and available in some LEON processors.
34+
2935
config SPARC_CASA
3036
bool "CASA instructions"
3137
help

arch/sparc/core/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ zephyr_library_sources(
1313
thread.c
1414
window_trap.S
1515
sw_trap_set_pil.S
16-
trap_table_mvt.S
1716
)
1817

18+
zephyr_library_sources_ifdef(CONFIG_SPARC_SVT trap_table_svt.S)
19+
zephyr_library_sources_ifndef(CONFIG_SPARC_SVT trap_table_mvt.S)
1920
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
2021
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE tls.c)

arch/sparc/core/reset_trap.S

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212

1313
GTEXT(__sparc_trap_reset)
1414
SECTION_FUNC(TEXT, __sparc_trap_reset)
15+
#ifdef CONFIG_SPARC_SVT
16+
#ifdef CONFIG_SOC_SPARC_LEON
17+
/* On LEON, enable single vector trapping by setting ASR17.SV. */
18+
rd %asr17, %g1
19+
set (1<<13), %g2
20+
or %g1, %g2, %g1
21+
wr %g1, %asr17
22+
#else
23+
#error "Don't know how to enable SVT on this SOC"
24+
#endif
25+
#endif
26+
1527
set __sparc_trap_table, %g1
1628
wr %g1, %tbr
1729
wr 2, %wim

arch/sparc/core/trap_table_svt.S

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright (c) 2023 Frontgrade Gaisler AB
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*
8+
* This file contains the trap entry for SPARC operating with
9+
* single-vector trap model, defined in SPARC V8E. The processor
10+
* redirects execution to a single entry on any trap event. From
11+
* there, two levels of look-up tables are used to find the trap
12+
* handler.
13+
*
14+
* - Execution time is constant.
15+
* - Condition flags are not modified.
16+
* - Provides handler with PSR in l0, TBR in l6
17+
* - This SVT implementation is less than 400 bytes long. (An MVT
18+
* table is always 4096 bytes long.)
19+
*
20+
* See trap_table_mvt.S for information about SPARC trap types.
21+
*/
22+
23+
#include <zephyr/toolchain.h>
24+
#include <zephyr/linker/sections.h>
25+
#include <zephyr/arch/sparc/sparc.h>
26+
27+
#ifdef CONFIG_IRQ_OFFLOAD
28+
#define IRQ_OFFLOAD_HANDLER __sparc_trap_irq_offload
29+
#else
30+
#define IRQ_OFFLOAD_HANDLER __sparc_trap_fault
31+
#endif
32+
33+
GTEXT(__sparc_trap_table)
34+
GTEXT(__start)
35+
36+
SECTION_SUBSEC_FUNC(TEXT, traptable, __sparc_trap_table)
37+
__start:
38+
rd %psr, %l0
39+
mov %tbr, %l6
40+
41+
and %l6, 0xf00, %l7
42+
srl %l7, 6, %l7
43+
set __sparc_trap_table_svt_level0, %l4
44+
ld [%l4 + %l7], %l4
45+
46+
and %l6, 0x0f0, %l7
47+
srl %l7, 2, %l7
48+
ld [%l4 + %l7], %l4
49+
50+
srl %l6, 4, %l3
51+
jmp %l4
52+
and %l3, 0xf, %l3 /* Interrupt level */
53+
54+
__sparc_trap_svt_in_trap:
55+
ta 0x00
56+
nop
57+
58+
SECTION_VAR(RODATA, __sparc_trap_table_svt_tables)
59+
.align 4
60+
__sparc_trap_table_svt_level0:
61+
.word __sparc_trap_table_svt_00
62+
.word __sparc_trap_table_svt_10
63+
.word __sparc_trap_table_svt_allbad
64+
.word __sparc_trap_table_svt_allbad
65+
.word __sparc_trap_table_svt_allbad
66+
.word __sparc_trap_table_svt_allbad
67+
.word __sparc_trap_table_svt_allbad
68+
.word __sparc_trap_table_svt_allbad
69+
.word __sparc_trap_table_svt_80
70+
.word __sparc_trap_table_svt_allbad
71+
.word __sparc_trap_table_svt_allbad
72+
.word __sparc_trap_table_svt_allbad
73+
.word __sparc_trap_table_svt_allbad
74+
.word __sparc_trap_table_svt_allbad
75+
.word __sparc_trap_table_svt_allbad
76+
.word __sparc_trap_table_svt_allbad
77+
78+
__sparc_trap_table_svt_00:
79+
.word __sparc_trap_reset
80+
.word __sparc_trap_fault
81+
.word __sparc_trap_fault
82+
.word __sparc_trap_fault
83+
.word __sparc_trap_fault
84+
.word __sparc_trap_window_overflow
85+
.word __sparc_trap_window_underflow
86+
__sparc_trap_table_svt_allbad:
87+
.word __sparc_trap_fault
88+
.word __sparc_trap_fault
89+
.word __sparc_trap_fault
90+
.word __sparc_trap_fault
91+
.word __sparc_trap_fault
92+
.word __sparc_trap_fault
93+
.word __sparc_trap_fault
94+
.word __sparc_trap_fault
95+
.word __sparc_trap_fault
96+
.word __sparc_trap_fault
97+
.word __sparc_trap_fault
98+
.word __sparc_trap_fault
99+
.word __sparc_trap_fault
100+
.word __sparc_trap_fault
101+
.word __sparc_trap_fault
102+
.word __sparc_trap_fault
103+
104+
__sparc_trap_table_svt_10:
105+
.word __sparc_trap_fault
106+
.word __sparc_trap_interrupt
107+
.word __sparc_trap_interrupt
108+
.word __sparc_trap_interrupt
109+
.word __sparc_trap_interrupt
110+
.word __sparc_trap_interrupt
111+
.word __sparc_trap_interrupt
112+
.word __sparc_trap_interrupt
113+
.word __sparc_trap_interrupt
114+
.word __sparc_trap_interrupt
115+
.word __sparc_trap_interrupt
116+
.word __sparc_trap_interrupt
117+
.word __sparc_trap_interrupt
118+
.word __sparc_trap_interrupt
119+
.word __sparc_trap_interrupt
120+
.word __sparc_trap_interrupt
121+
122+
__sparc_trap_table_svt_80:
123+
.word __sparc_trap_svt_in_trap
124+
.word __sparc_trap_fault
125+
.word __sparc_trap_fault
126+
.word __sparc_trap_flush_windows
127+
.word __sparc_trap_fault
128+
.word __sparc_trap_fault
129+
.word __sparc_trap_fault
130+
.word __sparc_trap_fault
131+
.word __sparc_trap_fault
132+
.word __sparc_trap_sw_set_pil
133+
.word __sparc_trap_fault
134+
.word __sparc_trap_fault
135+
.word __sparc_trap_fault
136+
.word IRQ_OFFLOAD_HANDLER
137+
.word __sparc_trap_fault
138+
.word __sparc_trap_except_reason

0 commit comments

Comments
 (0)