locore.h revision 1.1 1 1.1 uch /* $NetBSD: locore.h,v 1.1 2002/02/24 18:19:42 uch Exp $ */
2 1.1 uch
3 1.1 uch /*-
4 1.1 uch * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * Redistribution and use in source and binary forms, with or without
8 1.1 uch * modification, are permitted provided that the following conditions
9 1.1 uch * are met:
10 1.1 uch * 1. Redistributions of source code must retain the above copyright
11 1.1 uch * notice, this list of conditions and the following disclaimer.
12 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 uch * notice, this list of conditions and the following disclaimer in the
14 1.1 uch * documentation and/or other materials provided with the distribution.
15 1.1 uch * 3. All advertising materials mentioning features or use of this software
16 1.1 uch * must display the following acknowledgement:
17 1.1 uch * This product includes software developed by the NetBSD
18 1.1 uch * Foundation, Inc. and its contributors.
19 1.1 uch * 4. Neither the name of The NetBSD Foundation nor the names of its
20 1.1 uch * contributors may be used to endorse or promote products derived
21 1.1 uch * from this software without specific prior written permission.
22 1.1 uch *
23 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 1.1 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 1.1 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 1.1 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 1.1 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 1.1 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 1.1 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 1.1 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 1.1 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 1.1 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 1.1 uch * POSSIBILITY OF SUCH DAMAGE.
34 1.1 uch */
35 1.1 uch
36 1.1 uch /* XXX XXX XXX */
37 1.1 uch #define SH3_BBRA 0xffffffb8
38 1.1 uch #define SH4_BBRA 0xff200008
39 1.1 uch #define SH3_EXPEVT 0xffffffd4
40 1.1 uch #define SH3_INTEVT 0xffffffd8
41 1.1 uch #define SH4_EXPEVT 0xff000024
42 1.1 uch #define SH4_INTEVT 0xff000028
43 1.1 uch /* XXX XXX XXX */
44 1.1 uch
45 1.1 uch #if defined(SH3) && defined(SH4)
46 1.1 uch #define MOV(x, r) mov.l _L./**/x, r; mov.l @r, r
47 1.1 uch #define REG_SYMBOL(x) _L./**/x: .long _C_LABEL(__sh_/**/x)
48 1.1 uch #define FUNC_SYMBOL(x) _L./**/x: .long _C_LABEL(__sh_/**/x)
49 1.1 uch #elif defined(SH3)
50 1.1 uch #define MOV(x, r) mov.l _L./**/x, r
51 1.1 uch #define REG_SYMBOL(x) _L./**/x: .long SH3_/**/x
52 1.1 uch #define FUNC_SYMBOL(x) _L./**/x: .long _C_LABEL(sh3_/**/x)
53 1.1 uch #elif defined(SH4)
54 1.1 uch #define MOV(x, r) mov.l _L./**/x, r
55 1.1 uch #define REG_SYMBOL(x) _L./**/x: .long SH4_/**/x
56 1.1 uch #define FUNC_SYMBOL(x) _L./**/x: .long _C_LABEL(sh4_/**/x)
57 1.1 uch #endif
58 1.1 uch
59 1.1 uch /*
60 1.1 uch * BANK1 r7 contains kernel stack top address.
61 1.1 uch */
62 1.1 uch /*
63 1.1 uch * EXCEPTION_ENTRY:
64 1.1 uch * + setup stack pointer
65 1.1 uch * + save all register to stack. (struct trapframe)
66 1.1 uch * + change bank from 1 to 0
67 1.1 uch * + set BANK0 (r4, r5) = (ssr, spc)
68 1.1 uch */
69 1.1 uch #define EXCEPTION_ENTRY ;\
70 1.1 uch /* Check kernel/user mode. */ ;\
71 1.1 uch mov #0x40, r3 ;\
72 1.1 uch swap.b r3, r3 ;\
73 1.1 uch stc ssr, r1 ;\
74 1.1 uch swap.w r3, r3 /* r3 = 0x40000000 */ ;\
75 1.1 uch mov r1, r0 /* r1 = r0 = SSR */ ;\
76 1.1 uch and r3, r0 ;\
77 1.1 uch tst r0, r0 /* if (SSR.MD == 0) T = 1 */ ;\
78 1.1 uch bf/s 1f /* T==0 ...Exception from kernel mode */;\
79 1.1 uch mov r15, r0 /* r0 = old stack */ ;\
80 1.1 uch /* Exception from user mode */ ;\
81 1.1 uch mov r7, r15 /* change to kernel stack */ ;\
82 1.1 uch 1: ;\
83 1.1 uch /* Save registers */ ;\
84 1.1 uch mov.l r0, @-r15 /* tf_r15 */ ;\
85 1.1 uch stc.l r0_bank,@-r15 /* tf_r0 */ ;\
86 1.1 uch stc.l r1_bank,@-r15 /* tf_r1 */ ;\
87 1.1 uch stc.l r2_bank,@-r15 /* tf_r2 */ ;\
88 1.1 uch stc.l r3_bank,@-r15 /* tf_r3 */ ;\
89 1.1 uch stc.l r4_bank,@-r15 /* tf_r4 */ ;\
90 1.1 uch stc.l r5_bank,@-r15 /* tf_r5 */ ;\
91 1.1 uch stc.l r6_bank,@-r15 /* tf_r6 */ ;\
92 1.1 uch stc.l r7_bank,@-r15 /* tf_r7 */ ;\
93 1.1 uch mov.l r8, @-r15 /* tf_r8 */ ;\
94 1.1 uch mov.l r9, @-r15 /* tf_r9 */ ;\
95 1.1 uch mov.l r10, @-r15 /* tf_r10 */ ;\
96 1.1 uch mov.l r11, @-r15 /* tf_r11 */ ;\
97 1.1 uch mov.l r12, @-r15 /* tf_r12 */ ;\
98 1.1 uch mov.l r13, @-r15 /* tf_r13 */ ;\
99 1.1 uch mov.l r14, @-r15 /* tf_r14 */ ;\
100 1.1 uch sts.l pr, @-r15 /* tf_pr */ ;\
101 1.1 uch sts.l mach, @-r15 /* tf_mach*/ ;\
102 1.1 uch sts.l macl, @-r15 /* tf_macl*/ ;\
103 1.1 uch mov.l r1, @-r15 /* tf_ssr */ ;\
104 1.1 uch stc.l spc, @-r15 /* tf_spc */ ;\
105 1.1 uch add #-8, r15 /* skip tf_ubc, tf_trapno */ ;\
106 1.1 uch /* Change register bank to 0 */ ;\
107 1.1 uch shlr r3 /* r3 = 0x20000000 */ ;\
108 1.1 uch stc sr, r0 /* r0 = SR */ ;\
109 1.1 uch not r3, r3 ;\
110 1.1 uch and r0, r3 ;\
111 1.1 uch ldc r3, sr /* SR.RB = 0 */ ;\
112 1.1 uch /* Set up argument. r4 = ssr, r5 = spc */ ;\
113 1.1 uch stc r1_bank,r4 ;\
114 1.1 uch stc spc, r5
115 1.1 uch
116 1.1 uch /*
117 1.1 uch * EXCEPTION_RETURN:
118 1.1 uch * + block exception
119 1.1 uch * + restore all register from stack.
120 1.1 uch * + rte.
121 1.1 uch */
122 1.1 uch #define EXCEPTION_RETURN ;\
123 1.1 uch mov #0x10, r0 ;\
124 1.1 uch swap.b r0, r0 ;\
125 1.1 uch swap.w r0, r0 /* r0 = 0x10000000 */ ;\
126 1.1 uch stc sr, r1 ;\
127 1.1 uch or r0, r1 ;\
128 1.1 uch ldc r1, sr /* SR.BL = 1 */ ;\
129 1.1 uch add #8, r15 /* skip tf_trapno, tf_ubc */ ;\
130 1.1 uch mov.l @r15+, r0 /* tf_spc */ ;\
131 1.1 uch ldc r0, spc ;\
132 1.1 uch mov.l @r15+, r0 /* tf_ssr */ ;\
133 1.1 uch ldc r0, ssr ;\
134 1.1 uch lds.l @r15+, macl /* tf_macl*/ ;\
135 1.1 uch lds.l @r15+, mach /* tf_mach*/ ;\
136 1.1 uch lds.l @r15+, pr /* tf_pr */ ;\
137 1.1 uch mov.l @r15+, r14 /* tf_r14 */ ;\
138 1.1 uch mov.l @r15+, r13 /* tf_r13 */ ;\
139 1.1 uch mov.l @r15+, r12 /* tf_r12 */ ;\
140 1.1 uch mov.l @r15+, r11 /* tf_r11 */ ;\
141 1.1 uch mov.l @r15+, r10 /* tf_r10 */ ;\
142 1.1 uch mov.l @r15+, r9 /* tf_r9 */ ;\
143 1.1 uch mov.l @r15+, r8 /* tf_r8 */ ;\
144 1.1 uch mov.l @r15+, r7 /* tf_r7 */ ;\
145 1.1 uch mov.l @r15+, r6 /* tf_r6 */ ;\
146 1.1 uch mov.l @r15+, r5 /* tf_r5 */ ;\
147 1.1 uch mov.l @r15+, r4 /* tf_r4 */ ;\
148 1.1 uch mov.l @r15+, r3 /* tf_r3 */ ;\
149 1.1 uch mov.l @r15+, r2 /* tf_r2 */ ;\
150 1.1 uch mov.l @r15+, r1 /* tf_r1 */ ;\
151 1.1 uch mov.l @r15+, r0 /* tf_r0 */ ;\
152 1.1 uch mov.l @r15, r15 /* tf_r15 */ ;\
153 1.1 uch rte ;\
154 1.1 uch nop
155 1.1 uch
156 1.1 uch
157 1.1 uch /*
158 1.1 uch * Macros to disable and enable exceptions (including interrupts).
159 1.1 uch * This modifies SR.BL
160 1.1 uch */
161 1.1 uch #define __EXCEPTION_BLOCK_r0_r1 ;\
162 1.1 uch mov #0x10, r0 ;\
163 1.1 uch swap.b r0, r0 ;\
164 1.1 uch swap.w r0, r0 /* r0 = 0x10000000 */ ;\
165 1.1 uch stc sr, r1 ;\
166 1.1 uch or r0, r1 ;\
167 1.1 uch ldc r1, sr /* block exceptions */
168 1.1 uch
169 1.1 uch #define __EXCEPTION_UNBLOCK_r0_r1 ;\
170 1.1 uch mov #0x10, r0 ;\
171 1.1 uch swap.b r0, r0 ;\
172 1.1 uch swap.w r0, r0 /* r0 = 0x10000000 */ ;\
173 1.1 uch not r0, r0 ;\
174 1.1 uch stc sr, r1 ;\
175 1.1 uch and r0, r1 ;\
176 1.1 uch ldc r1, sr /* unblock exceptions */
177 1.1 uch
178 1.1 uch /*
179 1.1 uch * Macros to disable and enable interrupts.
180 1.1 uch * This modifies SR.I[0-3]
181 1.1 uch */
182 1.1 uch #define __INTR_MASK_r0_r1 ;\
183 1.1 uch mov #0x78, r0 ;\
184 1.1 uch shll r0 /* r0 = 0x000000f0 */ ;\
185 1.1 uch stc sr, r1 ;\
186 1.1 uch or r0, r1 ;\
187 1.1 uch ldc r1, sr /* mask all interrupt */
188 1.1 uch
189 1.1 uch #define __INTR_UNMASK_r0_r1 ;\
190 1.1 uch mov #0x78, r0 ;\
191 1.1 uch shll r0 /* r0 = 0x000000f0 */ ;\
192 1.1 uch not r0, r0 ;\
193 1.1 uch stc sr, r1 ;\
194 1.1 uch and r0, r1 ;\
195 1.1 uch ldc r1, sr /* unmask all interrupt */
196 1.1 uch
197 1.1 uch
198 1.1 uch #define RECURSEENTRY ;\
199 1.1 uch mov r15, r0 ;\
200 1.1 uch mov.l r0, @-r15 ;\
201 1.1 uch mov.l r0, @-r15 ;\
202 1.1 uch mov.l r1, @-r15 ;\
203 1.1 uch mov.l r2, @-r15 ;\
204 1.1 uch mov.l r3, @-r15 ;\
205 1.1 uch mov.l r4, @-r15 ;\
206 1.1 uch mov.l r5, @-r15 ;\
207 1.1 uch mov.l r6, @-r15 ;\
208 1.1 uch mov.l r7, @-r15 ;\
209 1.1 uch mov.l r8, @-r15 ;\
210 1.1 uch mov.l r9, @-r15 ;\
211 1.1 uch mov.l r10, @-r15 ;\
212 1.1 uch mov.l r11, @-r15 ;\
213 1.1 uch mov.l r12, @-r15 ;\
214 1.1 uch mov.l r13, @-r15 ;\
215 1.1 uch mov.l r14, @-r15 ;\
216 1.1 uch sts.l pr, @-r15 ;\
217 1.1 uch sts.l mach, @-r15 ;\
218 1.1 uch sts.l macl, @-r15 ;\
219 1.1 uch stc.l ssr, @-r15 ;\
220 1.1 uch stc.l spc, @-r15 ;\
221 1.1 uch add #-8, r15 /* tf_ubc, tf_trapno */
222