cpu.h revision 1.1 1 1.1 reinoud /* $NetBSD: cpu.h,v 1.1 2001/02/23 21:23:47 reinoud Exp $ */
2 1.1 reinoud
3 1.1 reinoud /*
4 1.1 reinoud * Copyright (c) 1994-1996 Mark Brinicombe.
5 1.1 reinoud * Copyright (c) 1994 Brini.
6 1.1 reinoud * All rights reserved.
7 1.1 reinoud *
8 1.1 reinoud * This code is derived from software written for Brini by Mark Brinicombe
9 1.1 reinoud *
10 1.1 reinoud * Redistribution and use in source and binary forms, with or without
11 1.1 reinoud * modification, are permitted provided that the following conditions
12 1.1 reinoud * are met:
13 1.1 reinoud * 1. Redistributions of source code must retain the above copyright
14 1.1 reinoud * notice, this list of conditions and the following disclaimer.
15 1.1 reinoud * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 reinoud * notice, this list of conditions and the following disclaimer in the
17 1.1 reinoud * documentation and/or other materials provided with the distribution.
18 1.1 reinoud * 3. All advertising materials mentioning features or use of this software
19 1.1 reinoud * must display the following acknowledgement:
20 1.1 reinoud * This product includes software developed by Brini.
21 1.1 reinoud * 4. The name of the company nor the name of the author may be used to
22 1.1 reinoud * endorse or promote products derived from this software without specific
23 1.1 reinoud * prior written permission.
24 1.1 reinoud *
25 1.1 reinoud * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 1.1 reinoud * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 1.1 reinoud * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 1.1 reinoud * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 1.1 reinoud * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 1.1 reinoud * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 1.1 reinoud * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 reinoud * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 reinoud * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 reinoud * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 reinoud * SUCH DAMAGE.
36 1.1 reinoud *
37 1.1 reinoud * RiscBSD kernel project
38 1.1 reinoud *
39 1.1 reinoud * cpu.h
40 1.1 reinoud *
41 1.1 reinoud * CPU specific symbols
42 1.1 reinoud *
43 1.1 reinoud * Created : 18/09/94
44 1.1 reinoud *
45 1.1 reinoud * Based on kate/katelib/arm6.h
46 1.1 reinoud */
47 1.1 reinoud
48 1.1 reinoud #ifndef _ARM32_CPU_H_
49 1.1 reinoud #define _ARM32_CPU_H_
50 1.1 reinoud
51 1.1 reinoud #if defined(_KERNEL) && !defined(_LKM)
52 1.1 reinoud #include "opt_cputypes.h"
53 1.1 reinoud #include "opt_lockdebug.h"
54 1.1 reinoud #endif
55 1.1 reinoud
56 1.1 reinoud #ifndef _LOCORE
57 1.1 reinoud #include <machine/frame.h>
58 1.1 reinoud #endif /* !_LOCORE */
59 1.1 reinoud #include <machine/psl.h>
60 1.1 reinoud
61 1.1 reinoud #if defined(CPU_ARM7500) && !defined(CPU_ARM7)
62 1.1 reinoud #error "option CPU_ARM7 is required with CPU_ARM7500"
63 1.1 reinoud #endif
64 1.1 reinoud
65 1.1 reinoud #ifdef CPU_ARM7500
66 1.1 reinoud #ifdef CPU_ARM6
67 1.1 reinoud #error "CPU options CPU_ARM6 and CPU_ARM7500 are not compatible"
68 1.1 reinoud #endif
69 1.1 reinoud #ifdef CPU_ARM8
70 1.1 reinoud #error "CPU options CPU_ARM8 and CPU_ARM7500 are not compatible"
71 1.1 reinoud #endif
72 1.1 reinoud #ifdef CPU_SA110
73 1.1 reinoud #error "CPU options CPU_SA110 and CPU_ARM7500 are not compatible"
74 1.1 reinoud #endif
75 1.1 reinoud #endif /* CPU_ARM7500 */
76 1.1 reinoud
77 1.1 reinoud #define COPY_SIGCODE /* copy sigcode above user stack in exec */
78 1.1 reinoud
79 1.1 reinoud /*
80 1.1 reinoud * ARM Process Status Register
81 1.1 reinoud *
82 1.1 reinoud * The picture in the ARM manuals looks like this:
83 1.1 reinoud * 3 3 2 2 2
84 1.1 reinoud * 1 0 9 8 7 8 7 6 5 4 0
85 1.1 reinoud * +-------+---------------------------------------+-+-+-+---------+
86 1.1 reinoud * | flags | reserved |I|F| |M M M M M|
87 1.1 reinoud * |n z c v| | | | |4 3 2 1 0|
88 1.1 reinoud * +-------+---------------------------------------+-+-+-+---------+
89 1.1 reinoud */
90 1.1 reinoud
91 1.1 reinoud #define PSR_FLAGS 0xf0000000 /* flags */
92 1.1 reinoud #define PSR_N_bit (1 << 31) /* negative */
93 1.1 reinoud #define PSR_Z_bit (1 << 30) /* zero */
94 1.1 reinoud #define PSR_C_bit (1 << 29) /* carry */
95 1.1 reinoud #define PSR_V_bit (1 << 28) /* overflow */
96 1.1 reinoud
97 1.1 reinoud #define I32_bit (1 << 7) /* IRQ disable */
98 1.1 reinoud #define F32_bit (1 << 6) /* FIQ disable */
99 1.1 reinoud
100 1.1 reinoud #define PSR_MODE 0x0000001f /* mode mask */
101 1.1 reinoud #define PSR_USR32_MODE 0x00000010
102 1.1 reinoud #define PSR_FIQ32_MODE 0x00000011
103 1.1 reinoud #define PSR_IRQ32_MODE 0x00000012
104 1.1 reinoud #define PSR_SVC32_MODE 0x00000013
105 1.1 reinoud #define PSR_ABT32_MODE 0x00000017
106 1.1 reinoud #define PSR_UND32_MODE 0x0000001b
107 1.1 reinoud #define PSR_32_MODE 0x00000010
108 1.1 reinoud
109 1.1 reinoud #define PSR_IN_USR_MODE(psr) (!((psr) & 3)) /* XXX */
110 1.1 reinoud #define PSR_IN_32_MODE(psr) ((psr) & PSR_32_MODE)
111 1.1 reinoud
112 1.1 reinoud /*
113 1.1 reinoud * ARM Instructions
114 1.1 reinoud *
115 1.1 reinoud * 3 3 2 2 2
116 1.1 reinoud * 1 0 9 8 7 0
117 1.1 reinoud * +-------+-------------------------------------------------------+
118 1.1 reinoud * | cond | instruction dependant |
119 1.1 reinoud * |c c c c| |
120 1.1 reinoud * +-------+-------------------------------------------------------+
121 1.1 reinoud */
122 1.1 reinoud
123 1.1 reinoud #define INSN_SIZE 4 /* Always 4 bytes */
124 1.1 reinoud #define INSN_COND_MASK 0xf0000000 /* Condition mask */
125 1.1 reinoud #define INSN_COND_AL 0xe0000000 /* Always condition */
126 1.1 reinoud
127 1.1 reinoud /* Some of the definitions below need cleaning up for V3/V4 architectures */
128 1.1 reinoud
129 1.1 reinoud #define CPU_ID_DESIGNER_MASK 0xff000000
130 1.1 reinoud #define CPU_ID_ARM_LTD 0x41000000
131 1.1 reinoud #define CPU_ID_DEC 0x44000000
132 1.1 reinoud #define CPU_ID_TYPE_MASK 0x00ff0000
133 1.1 reinoud #define CPU_ID_ARM 0x00560000
134 1.1 reinoud #define CPU_ID_ARM7500 0x00020000
135 1.1 reinoud #define CPU_ID_CPU_MASK 0x0000fff0
136 1.1 reinoud #define ID_ARM610 0x00000610
137 1.1 reinoud #define ID_ARM700 0x00007000
138 1.1 reinoud #define ID_ARM710 0x00007100
139 1.1 reinoud #define ID_ARM810 0x00008100
140 1.1 reinoud #define ID_SA110 0x0000a100
141 1.1 reinoud #define ID_SA1100 0x0000a110
142 1.1 reinoud #define ID_SA1110 0x0000b110
143 1.1 reinoud
144 1.1 reinoud #define CPU_ID_REVISION_MASK 0x0000000f
145 1.1 reinoud
146 1.1 reinoud #define CPU_CONTROL_MMU_ENABLE 0x0001
147 1.1 reinoud #define CPU_CONTROL_AFLT_ENABLE 0x0002
148 1.1 reinoud #define CPU_CONTROL_DC_ENABLE 0x0004
149 1.1 reinoud #define CPU_CONTROL_WBUF_ENABLE 0x0008
150 1.1 reinoud #define CPU_CONTROL_32BP_ENABLE 0x0010
151 1.1 reinoud #define CPU_CONTROL_32BD_ENABLE 0x0020
152 1.1 reinoud #define CPU_CONTROL_LABT_ENABLE 0x0040
153 1.1 reinoud #define CPU_CONTROL_BEND_ENABLE 0x0080
154 1.1 reinoud #define CPU_CONTROL_SYST_ENABLE 0x0100
155 1.1 reinoud #define CPU_CONTROL_ROM_ENABLE 0x0200
156 1.1 reinoud #define CPU_CONTROL_CPCLK 0x0400
157 1.1 reinoud #define CPU_CONTROL_BPRD_ENABLE 0x0800
158 1.1 reinoud #define CPU_CONTROL_IC_ENABLE 0x1000
159 1.1 reinoud
160 1.1 reinoud #define CPU_CONTROL_IDC_ENABLE CPU_CONTROL_DC_ENABLE
161 1.1 reinoud
162 1.1 reinoud /* Fault status register definitions */
163 1.1 reinoud
164 1.1 reinoud #define FAULT_TYPE_MASK 0x0f
165 1.1 reinoud #define FAULT_USER 0x10
166 1.1 reinoud
167 1.1 reinoud #define FAULT_WRTBUF_0 0x00
168 1.1 reinoud #define FAULT_WRTBUF_1 0x02
169 1.1 reinoud #define FAULT_BUSERR_0 0x04
170 1.1 reinoud #define FAULT_BUSERR_1 0x06
171 1.1 reinoud #define FAULT_BUSERR_2 0x08
172 1.1 reinoud #define FAULT_BUSERR_3 0x0a
173 1.1 reinoud #define FAULT_ALIGN_0 0x01
174 1.1 reinoud #define FAULT_ALIGN_1 0x03
175 1.1 reinoud #define FAULT_BUSTRNL1 0x0c
176 1.1 reinoud #define FAULT_BUSTRNL2 0x0e
177 1.1 reinoud #define FAULT_TRANS_S 0x05
178 1.1 reinoud #define FAULT_TRANS_P 0x07
179 1.1 reinoud #define FAULT_DOMAIN_S 0x09
180 1.1 reinoud #define FAULT_DOMAIN_P 0x0b
181 1.1 reinoud #define FAULT_PERM_S 0x0d
182 1.1 reinoud #define FAULT_PERM_P 0x0f
183 1.1 reinoud
184 1.1 reinoud #ifdef _LOCORE
185 1.1 reinoud #define IRQdisable \
186 1.1 reinoud stmfd sp!, {r0} ; \
187 1.1 reinoud mrs r0, cpsr_all ; \
188 1.1 reinoud orr r0, r0, #(I32_bit) ; \
189 1.1 reinoud msr cpsr_all, r0 ; \
190 1.1 reinoud ldmfd sp!, {r0}
191 1.1 reinoud
192 1.1 reinoud #define IRQenable \
193 1.1 reinoud stmfd sp!, {r0} ; \
194 1.1 reinoud mrs r0, cpsr_all ; \
195 1.1 reinoud bic r0, r0, #(I32_bit) ; \
196 1.1 reinoud msr cpsr_all, r0 ; \
197 1.1 reinoud ldmfd sp!, {r0}
198 1.1 reinoud
199 1.1 reinoud #else
200 1.1 reinoud #define IRQdisable SetCPSR(I32_bit, I32_bit);
201 1.1 reinoud #define IRQenable SetCPSR(I32_bit, 0);
202 1.1 reinoud #endif /* _LOCORE */
203 1.1 reinoud
204 1.1 reinoud /*
205 1.1 reinoud * Return TRUE/FALSE (1/0) depending on whether the frame came from USR
206 1.1 reinoud * mode or not.
207 1.1 reinoud */
208 1.1 reinoud
209 1.1 reinoud #define CLKF_USERMODE(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
210 1.1 reinoud
211 1.1 reinoud /*
212 1.1 reinoud * This needs straighening, prob is the frame does not have info on the priority
213 1.1 reinoud * a guess that needs trying is (current_spl_level == SPL0)
214 1.1 reinoud */
215 1.1 reinoud
216 1.1 reinoud #define CLKF_BASEPRI(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
217 1.1 reinoud
218 1.1 reinoud #define CLKF_PC(frame) (frame->if_pc)
219 1.1 reinoud
220 1.1 reinoud /*#define CLKF_INTR(frame) (current_intr_depth > 1)*/
221 1.1 reinoud
222 1.1 reinoud /* Hack to treat FPE time as interrupt time so we can measure it */
223 1.1 reinoud #define CLKF_INTR(frame) ((current_intr_depth > 1) || (frame->if_spsr & PSR_MODE) == PSR_UND32_MODE)
224 1.1 reinoud
225 1.1 reinoud #define PROC_PC(p) ((p)->p_md.md_regs->tf_pc)
226 1.1 reinoud
227 1.1 reinoud /*
228 1.1 reinoud * definitions of cpu-dependent requirements
229 1.1 reinoud * referenced in generic code
230 1.1 reinoud */
231 1.1 reinoud
232 1.1 reinoud #ifndef _LOCORE
233 1.1 reinoud #include <sys/sched.h>
234 1.1 reinoud struct cpu_info {
235 1.1 reinoud struct schedstate_percpu ci_schedstate; /* scheduler state */
236 1.1 reinoud #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
237 1.1 reinoud u_long ci_spin_locks; /* # of spin locks held */
238 1.1 reinoud u_long ci_simple_locks; /* # of simple locks held */
239 1.1 reinoud #endif
240 1.1 reinoud };
241 1.1 reinoud #ifdef _KERNEL
242 1.1 reinoud extern struct cpu_info cpu_info_store;
243 1.1 reinoud #define curcpu() (&cpu_info_store)
244 1.1 reinoud #endif /* _KERNEL */
245 1.1 reinoud #endif /* ! _LOCORE */
246 1.1 reinoud
247 1.1 reinoud #define cpu_wait(p) /* nothing */
248 1.1 reinoud #define cpu_number() 0
249 1.1 reinoud
250 1.1 reinoud /*
251 1.1 reinoud * Notify the current process (p) that it has a signal pending,
252 1.1 reinoud * process as soon as possible.
253 1.1 reinoud */
254 1.1 reinoud
255 1.1 reinoud #define signotify(p) setsoftast()
256 1.1 reinoud
257 1.1 reinoud
258 1.1 reinoud #if defined(_KERNEL) && !defined(_LOCORE)
259 1.1 reinoud extern int current_intr_depth;
260 1.1 reinoud
261 1.1 reinoud /*
262 1.1 reinoud * Preempt the current process if in interrupt from user mode,
263 1.1 reinoud * or after the current trap/syscall if in system mode.
264 1.1 reinoud */
265 1.1 reinoud int want_resched; /* resched() was called */
266 1.1 reinoud #define need_resched(ci) (want_resched = 1, setsoftast())
267 1.1 reinoud
268 1.1 reinoud /*
269 1.1 reinoud * Give a profiling tick to the current process when the user profiling
270 1.1 reinoud * buffer pages are invalid. On the i386, request an ast to send us
271 1.1 reinoud * through trap(), marking the proc as needing a profiling tick.
272 1.1 reinoud */
273 1.1 reinoud #define need_proftick(p) ((p)->p_flag |= P_OWEUPC, setsoftast())
274 1.1 reinoud
275 1.1 reinoud /* locore.S */
276 1.1 reinoud void atomic_set_bit __P((u_int *address, u_int setmask));
277 1.1 reinoud void atomic_clear_bit __P((u_int *address, u_int clearmask));
278 1.1 reinoud
279 1.1 reinoud /* cpuswitch.S */
280 1.1 reinoud struct pcb;
281 1.1 reinoud void savectx __P((struct pcb *pcb));
282 1.1 reinoud
283 1.1 reinoud /* ast.c */
284 1.1 reinoud void userret __P((register struct proc *p));
285 1.1 reinoud
286 1.1 reinoud /* machdep.h */
287 1.1 reinoud void bootsync __P((void));
288 1.1 reinoud
289 1.1 reinoud /* strstr.c */
290 1.1 reinoud char *strstr __P((const char *s1, const char *s2));
291 1.1 reinoud
292 1.1 reinoud /* syscall.c */
293 1.1 reinoud void child_return __P((void *));
294 1.1 reinoud
295 1.1 reinoud #endif /* _KERNEL && !_LOCORE */
296 1.1 reinoud
297 1.1 reinoud /*
298 1.1 reinoud * CTL_MACHDEP definitions.
299 1.1 reinoud */
300 1.1 reinoud #define CPU_DEBUG 1 /* int: misc kernel debug control */
301 1.1 reinoud #define CPU_BOOTED_DEVICE 2 /* string: device we booted from */
302 1.1 reinoud #define CPU_BOOTED_KERNEL 3 /* string: kernel we booted */
303 1.1 reinoud #define CPU_CONSDEV 4 /* struct: dev_t of our console */
304 1.1 reinoud #define CPU_MAXID 5 /* number of valid machdep ids */
305 1.1 reinoud
306 1.1 reinoud #define CTL_MACHDEP_NAMES { \
307 1.1 reinoud { 0, 0 }, \
308 1.1 reinoud { "debug", CTLTYPE_INT }, \
309 1.1 reinoud { "booted_device", CTLTYPE_STRING }, \
310 1.1 reinoud { "booted_kernel", CTLTYPE_STRING }, \
311 1.1 reinoud { "console_device", CTLTYPE_STRUCT }, \
312 1.1 reinoud }
313 1.1 reinoud
314 1.1 reinoud #endif /* !_ARM32_CPU_H_ */
315 1.1 reinoud
316 1.1 reinoud /* End of cpu.h */
317