1/*
2 * Copyright (c) 2019-2020 Cobham Gaisler AB
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7/*
8 * This file contains a full SPARC V8 trap table. The processor redirects
9 * exection to the trap table on trap events. Each trap table entrys is four
10 * instructions.
11 */
12
13#include <zephyr/toolchain.h>
14#include <zephyr/linker/sections.h>
15
16#define BAD_TRAP \
17	rd	%psr, %l0; \
18	sethi	%hi(__sparc_trap_fault), %l4; \
19	jmp	%l4+%lo(__sparc_trap_fault); \
20	 rd	%tbr, %l6;
21
22#define INTERRUPT_TRAP(level) \
23	rd	%psr, %l0; \
24	sethi	%hi(INT_HANDLER), %l4; \
25	jmp	%l4+%lo(INT_HANDLER); \
26	 mov	(0xf & level), %l3;
27
28#define TRAP(handler) \
29	rd	%psr, %l0; \
30	sethi	%hi(handler), %l4; \
31	jmp	%l4+%lo(handler); \
32	 rd	%tbr, %l6;
33
34#define RESET_TRAP(handler) \
35	mov	%g0, %g4; \
36	sethi	%hi(handler), %g4; \
37	jmp	%g4+%lo(handler); \
38	 nop;
39
40/*
41 * Generate the "trap in trap" condition which causes the processor to halt and
42 * enter error mode. Typically used to stop a simulator (QEMU, TSIM) or leave
43 * control to a hardware debug monitor (LEON DSU via GRMON).
44 */
45#define TRAP_IN_TRAP \
46	ta	0x00; \
47	nop; \
48	nop; \
49	nop;
50
51#define SOFT_TRAP BAD_TRAP
52
53#define WOF_TRAP                TRAP(__sparc_trap_window_overflow)
54#define WUF_TRAP                TRAP(__sparc_trap_window_underflow)
55#define FLW_TRAP                TRAP(__sparc_trap_flush_windows)
56#define INT_HANDLER             __sparc_trap_interrupt
57
58#ifdef CONFIG_IRQ_OFFLOAD
59 #define IRQ_OFFLOAD_TRAP       TRAP(__sparc_trap_irq_offload)
60#else
61 #define IRQ_OFFLOAD_TRAP       BAD_TRAP
62#endif
63
64GTEXT(__sparc_trap_table)
65GTEXT(__start)
66
67SECTION_SUBSEC_FUNC(TEXT, traptable, __sparc_trap_table)
68__start:
69	/*
70	 * Values in the range 0 to 0x5F that are not assigned in SPARC V8
71	 * specification Table 7-1 are reserved for future versions of the
72	 * architecture.
73	 */
74	RESET_TRAP(__sparc_trap_reset); ! 00 reset
75	BAD_TRAP;                       ! 01 instruction_access_exception
76	BAD_TRAP;                       ! 02 illegal_instruction
77	BAD_TRAP;                       ! 03 priveleged_instruction
78	BAD_TRAP;                       ! 04 fp_disabled
79	WOF_TRAP;                       ! 05 window_overflow
80	WUF_TRAP;                       ! 06 window_underflow
81	BAD_TRAP;                       ! 07 mem_address_not_aligned
82	BAD_TRAP;                       ! 08 fp_exception
83	BAD_TRAP;                       ! 09 data_access_exception
84	BAD_TRAP;                       ! 0A tag_overflow
85	BAD_TRAP;                       ! 0B watchpoint_detected
86	BAD_TRAP;                       ! 0C reserved
87	BAD_TRAP;                       ! 0D reserved
88	BAD_TRAP;                       ! 0E reserved
89	BAD_TRAP;                       ! 0F reserved
90	BAD_TRAP;                       ! 10 reserved
91
92	/* Interrupt traps */
93	INTERRUPT_TRAP(1);                      ! 11 interrupt_level_1
94	INTERRUPT_TRAP(2);                      ! 12 interrupt_level_2
95	INTERRUPT_TRAP(3);                      ! 13 interrupt_level_3
96	INTERRUPT_TRAP(4);                      ! 14 interrupt_level_4
97	INTERRUPT_TRAP(5);                      ! 15 interrupt_level_5
98	INTERRUPT_TRAP(6);                      ! 16 interrupt_level_6
99	INTERRUPT_TRAP(7);                      ! 17 interrupt_level_7
100	INTERRUPT_TRAP(8);                      ! 18 interrupt_level_8
101	INTERRUPT_TRAP(9);                      ! 19 interrupt_level_9
102	INTERRUPT_TRAP(10);                     ! 1A interrupt_level_1
103	INTERRUPT_TRAP(11);                     ! 1B interrupt_level_11
104	INTERRUPT_TRAP(12);                     ! 1C interrupt_level_12
105	INTERRUPT_TRAP(13);                     ! 1D interrupt_level_13
106	INTERRUPT_TRAP(14);                     ! 1E interrupt_level_14
107	INTERRUPT_TRAP(15);                     ! 1F interrupt_level_15
108	BAD_TRAP;                               ! 20 r_register_access_error
109	BAD_TRAP;                               ! 21 instruction_access_error
110	BAD_TRAP;                               ! 22 reserved
111	BAD_TRAP;                               ! 23 reserved
112	BAD_TRAP;                               ! 24 cp_disabled
113	BAD_TRAP;                               ! 25 unimplemented_FLUSH
114	BAD_TRAP;                               ! 26 reserved
115	BAD_TRAP;                               ! 27 reserved
116	BAD_TRAP;                               ! 28 cp_exception
117	BAD_TRAP;                               ! 29 data_access_error
118	BAD_TRAP;                               ! 2A division_by_zero
119	BAD_TRAP;                               ! 2B data_store_error
120	BAD_TRAP;                               ! 2C data_access_MMU_miss
121	BAD_TRAP;                               ! 2D reserved
122	BAD_TRAP;                               ! 2E reserved
123	BAD_TRAP;                               ! 2F reserved
124	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 30 - 33 reserved
125	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 34 - 37 reserved
126	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 38 - 3B reserved
127	BAD_TRAP;                               ! 3C instruction_access_MMU_miss
128	BAD_TRAP;                               ! 3D reserved
129	BAD_TRAP;                               ! 3E reserved
130	BAD_TRAP;                               ! 3F reserved
131	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 40 - 43 undefined
132	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 44 - 47 undefined
133	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 48 - 4B undefined
134	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 4C - 4F undefined
135	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 50 - 53 undefined
136	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 54 - 57 undefined
137	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 58 - 5B undefined
138	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 5C - 5F undefined
139
140	/*
141	 * tt values 0x60 to 0x7F are reserved for implementation-dependent
142	 * exceptions.
143	 */
144	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 60 - 63 undefined
145	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 64 - 67 undefined
146	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 68 - 6B undefined
147	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 6C - 6F undefined
148	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 70 - 73 undefined
149	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 74 - 77 undefined
150	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 78 - 7B undefined
151	BAD_TRAP; BAD_TRAP; BAD_TRAP; BAD_TRAP; ! 7C - 7F undefined
152
153	/* trap_instruction 0x80 - 0xFF */
154	/* NOTE: "ta 5" can be generated by compiler. */
155	TRAP_IN_TRAP;                                 !  0 System calls
156	SOFT_TRAP;                                    !  1 Breakpoints
157	SOFT_TRAP;                                    !  2 Division by zero
158	FLW_TRAP;                                     !  3 Flush windows
159	SOFT_TRAP;                                    !  4 Clean windows
160	SOFT_TRAP;                                    !  5 Range checking
161	SOFT_TRAP;                                    !  6 Fix alignment
162	SOFT_TRAP;                                    !  7 Integer overflow
163	SOFT_TRAP                                     !  8 System calls
164	TRAP(__sparc_trap_sw_set_pil);                !  9 Reserved for the os
165	SOFT_TRAP;                                    ! 10 Reserved for the os
166	SOFT_TRAP;                                    ! 11 Reserved for the os
167	/* See SPARC-ABI for purpose of the following software traps */
168	SOFT_TRAP;                                    ! 12
169	IRQ_OFFLOAD_TRAP;                             ! 13
170	SOFT_TRAP;                                    ! 14
171	TRAP(__sparc_trap_except_reason);             ! 15
172	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! 90 - 93
173	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! 94 - 97
174	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! 98 - 9B
175	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! 9C - 9F
176	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! A0 - A3
177	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! A4 - A7
178	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! A8 - AB
179	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! AC - AF
180	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! B0 - B3
181	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! B4 - B7
182	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! B8 - BB
183	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! BC - BF
184	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! C0 - C3
185	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! C4 - C7
186	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! C8 - CB
187	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! CC - CF
188	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! D0 - D3
189	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! D4 - D7
190	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! D8 - DB
191	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! DC - DF
192	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! E0 - E3
193	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! E4 - E7
194	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! E8 - EB
195	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! EC - EF
196	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! F0 - F3
197	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! F4 - F7
198	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! F8 - FB
199	SOFT_TRAP; SOFT_TRAP; SOFT_TRAP; SOFT_TRAP;   ! FC - FF
200