locore.h revision 1.16 1 1.16 uwe /* $NetBSD: locore.h,v 1.16 2008/02/23 17:49:22 uwe 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.12 uwe #ifdef _LOCORE
37 1.12 uwe
38 1.1 uch #if defined(SH3) && defined(SH4)
39 1.11 uwe #define MOV(x, r) mov.l .L_/**/x, r; mov.l @r, r
40 1.11 uwe #define REG_SYMBOL(x) .L_/**/x: .long _C_LABEL(__sh_/**/x)
41 1.11 uwe #define FUNC_SYMBOL(x) .L_/**/x: .long _C_LABEL(__sh_/**/x)
42 1.1 uch #elif defined(SH3)
43 1.11 uwe #define MOV(x, r) mov.l .L_/**/x, r
44 1.11 uwe #define REG_SYMBOL(x) .L_/**/x: .long SH3_/**/x
45 1.11 uwe #define FUNC_SYMBOL(x) .L_/**/x: .long _C_LABEL(sh3_/**/x)
46 1.6 uch #elif defined(SH4)
47 1.11 uwe #define MOV(x, r) mov.l .L_/**/x, r
48 1.11 uwe #define REG_SYMBOL(x) .L_/**/x: .long SH4_/**/x
49 1.11 uwe #define FUNC_SYMBOL(x) .L_/**/x: .long _C_LABEL(sh4_/**/x)
50 1.4 uch #endif /* SH3 && SH4 */
51 1.1 uch
52 1.1 uch /*
53 1.13 uwe * BANK1 r6 contains current trapframe pointer.
54 1.13 uwe * BANK1 r7 contains bottom address of lwp's kernel stack.
55 1.6 uch */
56 1.1 uch /*
57 1.6 uch * __EXCEPTION_ENTRY:
58 1.1 uch * + setup stack pointer
59 1.13 uwe * + save all registers to trapframe.
60 1.3 uch * + setup kernel stack.
61 1.1 uch * + change bank from 1 to 0
62 1.5 uch * + set BANK0 (r4, r5, r6) = (ssr, spc, ssp)
63 1.1 uch */
64 1.9 uwe #define __EXCEPTION_ENTRY ;\
65 1.1 uch /* Check kernel/user mode. */ ;\
66 1.1 uch mov #0x40, r3 ;\
67 1.1 uch swap.b r3, r3 ;\
68 1.3 uch stc ssr, r2 ;\
69 1.1 uch swap.w r3, r3 /* r3 = 0x40000000 */ ;\
70 1.3 uch mov r2, r0 /* r2 = r0 = SSR */ ;\
71 1.1 uch and r3, r0 ;\
72 1.1 uch tst r0, r0 /* if (SSR.MD == 0) T = 1 */ ;\
73 1.3 uch mov r14, r1 ;\
74 1.3 uch mov r6, r14 /* frame pointer */ ;\
75 1.1 uch bf/s 1f /* T==0 ...Exception from kernel mode */;\
76 1.3 uch mov r15, r0 ;\
77 1.1 uch /* Exception from user mode */ ;\
78 1.1 uch mov r7, r15 /* change to kernel stack */ ;\
79 1.1 uch 1: ;\
80 1.1 uch /* Save registers */ ;\
81 1.3 uch mov.l r1, @-r14 /* tf_r14 */ ;\
82 1.3 uch mov.l r0, @-r14 /* tf_r15 */ ;\
83 1.3 uch stc.l r0_bank,@-r14 /* tf_r0 */ ;\
84 1.3 uch stc.l r1_bank,@-r14 /* tf_r1 */ ;\
85 1.3 uch stc.l r2_bank,@-r14 /* tf_r2 */ ;\
86 1.3 uch stc.l r3_bank,@-r14 /* tf_r3 */ ;\
87 1.3 uch stc.l r4_bank,@-r14 /* tf_r4 */ ;\
88 1.3 uch stc.l r5_bank,@-r14 /* tf_r5 */ ;\
89 1.3 uch stc.l r6_bank,@-r14 /* tf_r6 */ ;\
90 1.3 uch stc.l r7_bank,@-r14 /* tf_r7 */ ;\
91 1.3 uch mov.l r8, @-r14 /* tf_r8 */ ;\
92 1.3 uch mov.l r9, @-r14 /* tf_r9 */ ;\
93 1.3 uch mov.l r10, @-r14 /* tf_r10 */ ;\
94 1.3 uch mov.l r11, @-r14 /* tf_r11 */ ;\
95 1.3 uch mov.l r12, @-r14 /* tf_r12 */ ;\
96 1.3 uch mov.l r13, @-r14 /* tf_r13 */ ;\
97 1.3 uch sts.l pr, @-r14 /* tf_pr */ ;\
98 1.3 uch sts.l mach, @-r14 /* tf_mach*/ ;\
99 1.3 uch sts.l macl, @-r14 /* tf_macl*/ ;\
100 1.3 uch mov.l r2, @-r14 /* tf_ssr */ ;\
101 1.3 uch stc.l spc, @-r14 /* tf_spc */ ;\
102 1.7 uch add #-8, r14 /* skip tf_ubc, tf_expevt */ ;\
103 1.3 uch mov r14, r6 /* store frame pointer */ ;\
104 1.1 uch /* Change register bank to 0 */ ;\
105 1.1 uch shlr r3 /* r3 = 0x20000000 */ ;\
106 1.5 uch stc sr, r1 /* r1 = SR */ ;\
107 1.1 uch not r3, r3 ;\
108 1.5 uch and r1, r3 ;\
109 1.1 uch ldc r3, sr /* SR.RB = 0 */ ;\
110 1.13 uwe /* Set up arguments. r4 = ssr, r5 = spc */ ;\
111 1.3 uch stc r2_bank,r4 ;\
112 1.1 uch stc spc, r5
113 1.1 uch
114 1.6 uch /*
115 1.6 uch * __EXCEPTION_RETURN:
116 1.13 uwe * + block exceptions
117 1.13 uwe * + restore all registers from stack.
118 1.6 uch * + rte.
119 1.1 uch */
120 1.5 uch #define __EXCEPTION_RETURN ;\
121 1.1 uch mov #0x10, r0 ;\
122 1.1 uch swap.b r0, r0 ;\
123 1.1 uch swap.w r0, r0 /* r0 = 0x10000000 */ ;\
124 1.1 uch stc sr, r1 ;\
125 1.1 uch or r0, r1 ;\
126 1.1 uch ldc r1, sr /* SR.BL = 1 */ ;\
127 1.3 uch stc r6_bank,r0 ;\
128 1.3 uch mov r0, r14 ;\
129 1.3 uch add #TF_SIZE, r0 ;\
130 1.3 uch ldc r0, r6_bank /* roll up frame pointer */ ;\
131 1.7 uch add #8, r14 /* skip tf_expevt, tf_ubc */ ;\
132 1.3 uch mov.l @r14+, r0 /* tf_spc */ ;\
133 1.1 uch ldc r0, spc ;\
134 1.3 uch mov.l @r14+, r0 /* tf_ssr */ ;\
135 1.1 uch ldc r0, ssr ;\
136 1.3 uch lds.l @r14+, macl /* tf_macl*/ ;\
137 1.3 uch lds.l @r14+, mach /* tf_mach*/ ;\
138 1.3 uch lds.l @r14+, pr /* tf_pr */ ;\
139 1.3 uch mov.l @r14+, r13 /* tf_r13 */ ;\
140 1.3 uch mov.l @r14+, r12 /* tf_r12 */ ;\
141 1.3 uch mov.l @r14+, r11 /* tf_r11 */ ;\
142 1.3 uch mov.l @r14+, r10 /* tf_r10 */ ;\
143 1.3 uch mov.l @r14+, r9 /* tf_r9 */ ;\
144 1.3 uch mov.l @r14+, r8 /* tf_r8 */ ;\
145 1.3 uch mov.l @r14+, r7 /* tf_r7 */ ;\
146 1.3 uch mov.l @r14+, r6 /* tf_r6 */ ;\
147 1.3 uch mov.l @r14+, r5 /* tf_r5 */ ;\
148 1.3 uch mov.l @r14+, r4 /* tf_r4 */ ;\
149 1.3 uch mov.l @r14+, r3 /* tf_r3 */ ;\
150 1.3 uch mov.l @r14+, r2 /* tf_r2 */ ;\
151 1.3 uch mov.l @r14+, r1 /* tf_r1 */ ;\
152 1.3 uch mov.l @r14+, r0 /* tf_r0 */ ;\
153 1.3 uch mov.l @r14+ r15 /* tf_r15 */ ;\
154 1.3 uch mov.l @r14+, r14 /* tf_r14 */ ;\
155 1.1 uch rte ;\
156 1.2 uch nop
157 1.1 uch
158 1.1 uch
159 1.1 uch /*
160 1.1 uch * Macros to disable and enable exceptions (including interrupts).
161 1.1 uch * This modifies SR.BL
162 1.1 uch */
163 1.1 uch
164 1.6 uch #define __EXCEPTION_BLOCK(Rn, Rm) ;\
165 1.12 uwe mov #0x10, Rn ;\
166 1.2 uch swap.b Rn, Rn ;\
167 1.2 uch swap.w Rn, Rn /* Rn = 0x10000000 */ ;\
168 1.2 uch stc sr, Rm ;\
169 1.16 uwe or Rm, Rn ;\
170 1.16 uwe ldc Rn, sr /* block exceptions */
171 1.2 uch
172 1.6 uch #define __EXCEPTION_UNBLOCK(Rn, Rm) ;\
173 1.14 uwe mov #0xef, Rn /* ~0x10 */ ;\
174 1.2 uch swap.b Rn, Rn ;\
175 1.14 uwe swap.w Rn, Rn /* Rn = ~0x10000000 */ ;\
176 1.2 uch stc sr, Rm ;\
177 1.2 uch and Rn, Rm ;\
178 1.2 uch ldc Rm, sr /* unblock exceptions */
179 1.1 uch
180 1.1 uch /*
181 1.1 uch * Macros to disable and enable interrupts.
182 1.1 uch * This modifies SR.I[0-3]
183 1.1 uch */
184 1.2 uch #define __INTR_MASK(Rn, Rm) ;\
185 1.12 uwe mov #0x78, Rn ;\
186 1.2 uch shll Rn /* Rn = 0x000000f0 */ ;\
187 1.2 uch stc sr, Rm ;\
188 1.2 uch or Rn, Rm ;\
189 1.13 uwe ldc Rm, sr /* mask all interrupts */
190 1.2 uch
191 1.6 uch #define __INTR_UNMASK(Rn, Rm) ;\
192 1.12 uwe mov #0x78, Rn ;\
193 1.2 uch shll Rn /* Rn = 0x000000f0 */ ;\
194 1.2 uch not Rn, Rn ;\
195 1.2 uch stc sr, Rm ;\
196 1.2 uch and Rn, Rm ;\
197 1.13 uwe ldc Rm, sr /* unmask all interrupts */
198 1.3 uch
199 1.12 uwe #else /* !_LOCORE */
200 1.12 uwe
201 1.8 thorpej void sh3_switch_setup(struct lwp *);
202 1.8 thorpej void sh4_switch_setup(struct lwp *);
203 1.8 thorpej void sh3_switch_resume(struct lwp *);
204 1.8 thorpej void sh4_switch_resume(struct lwp *);
205 1.8 thorpej extern void (*__sh_switch_resume)(struct lwp *);
206 1.12 uwe
207 1.4 uch #endif /* !_LOCORE */
208