cpu.h revision 1.9 1 /* $NetBSD: cpu.h,v 1.9 2001/02/28 18:15:43 bjh21 Exp $ */
2
3 /*
4 * Copyright (c) 1994-1996 Mark Brinicombe.
5 * Copyright (c) 1994 Brini.
6 * All rights reserved.
7 *
8 * This code is derived from software written for Brini by Mark Brinicombe
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Brini.
21 * 4. The name of the company nor the name of the author may be used to
22 * endorse or promote products derived from this software without specific
23 * prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * RiscBSD kernel project
38 *
39 * cpu.h
40 *
41 * CPU specific symbols
42 *
43 * Created : 18/09/94
44 *
45 * Based on kate/katelib/arm6.h
46 */
47
48 #ifndef _ARM32_CPU_H_
49 #define _ARM32_CPU_H_
50
51 /*
52 * User-visible definitions
53 */
54
55 /* CTL_MACHDEP definitions. */
56 #define CPU_DEBUG 1 /* int: misc kernel debug control */
57 #define CPU_BOOTED_DEVICE 2 /* string: device we booted from */
58 #define CPU_BOOTED_KERNEL 3 /* string: kernel we booted */
59 #define CPU_CONSDEV 4 /* struct: dev_t of our console */
60 #define CPU_MAXID 5 /* number of valid machdep ids */
61
62 #define CTL_MACHDEP_NAMES { \
63 { 0, 0 }, \
64 { "debug", CTLTYPE_INT }, \
65 { "booted_device", CTLTYPE_STRING }, \
66 { "booted_kernel", CTLTYPE_STRING }, \
67 { "console_device", CTLTYPE_STRUCT }, \
68 }
69
70 #ifdef _KERNEL
71
72 /*
73 * Kernel-only definitions
74 */
75
76 #ifndef _LKM
77 #include "opt_cputypes.h"
78 #include "opt_lockdebug.h"
79 #include "opt_progmode.h"
80
81 #if defined(PROG26) && defined(PROG32)
82 #error "26-bit and 32-bit CPU support are not compatible"
83 #endif
84 #if !defined(PROG26) && !defined(PROG32)
85 #error "Support for at least one CPU type must be configured into the kernel"
86 #endif
87
88 #ifdef CPU_ARM7500
89 #ifndef CPU_ARM7
90 #error "option CPU_ARM7 is required with CPU_ARM7500"
91 #endif
92 #ifdef CPU_ARM6
93 #error "CPU options CPU_ARM6 and CPU_ARM7500 are not compatible"
94 #endif
95 #ifdef CPU_ARM8
96 #error "CPU options CPU_ARM8 and CPU_ARM7500 are not compatible"
97 #endif
98 #ifdef CPU_SA110
99 #error "CPU options CPU_SA110 and CPU_ARM7500 are not compatible"
100 #endif
101 #endif /* CPU_ARM7500 */
102
103 #endif /* !_LKM */
104
105
106 #ifndef _LOCORE
107 #include <sys/user.h>
108 #include <machine/frame.h>
109 #include <machine/pcb.h>
110 #endif /* !_LOCORE */
111
112 #ifdef arm26
113 extern int astpending;
114 #define setsoftast() (astpending = 1)
115 #else
116 #include <machine/psl.h>
117 #endif
118
119 #include <arm/armreg.h>
120
121 #ifdef PROG32
122 #ifdef _LOCORE
123 #define IRQdisable \
124 stmfd sp!, {r0} ; \
125 mrs r0, cpsr_all ; \
126 orr r0, r0, #(I32_bit) ; \
127 msr cpsr_all, r0 ; \
128 ldmfd sp!, {r0}
129
130 #define IRQenable \
131 stmfd sp!, {r0} ; \
132 mrs r0, cpsr_all ; \
133 bic r0, r0, #(I32_bit) ; \
134 msr cpsr_all, r0 ; \
135 ldmfd sp!, {r0}
136
137 #else
138 #define IRQdisable SetCPSR(I32_bit, I32_bit);
139 #define IRQenable SetCPSR(I32_bit, 0);
140 #endif /* _LOCORE */
141 #endif
142
143 /* All the CLKF_* macros take a struct clockframe * as an argument. */
144
145 #ifdef PROG32
146 /*
147 * Return TRUE/FALSE (1/0) depending on whether the frame came from USR
148 * mode or not.
149 */
150
151 #define CLKF_USERMODE(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
152
153 /*
154 * This needs straighening, prob is the frame does not have info on the
155 * priority a guess that needs trying is (current_spl_level == SPL0)
156 */
157
158 #define CLKF_BASEPRI(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
159
160 #define CLKF_PC(frame) (frame->if_pc)
161
162 /*#define CLKF_INTR(frame) (current_intr_depth > 1)*/
163
164 /* Hack to treat FPE time as interrupt time so we can measure it */
165 #define CLKF_INTR(frame) ((current_intr_depth > 1) || (frame->if_spsr & PSR_MODE) == PSR_UND32_MODE)
166
167 #define PROC_PC(p) ((p)->p_addr->u_pcb.pcb_tf->tf_pc)
168
169 #elif defined(PROG26)
170
171 /* True if we took the interrupt in user mode */
172 #define CLKF_USERMODE(frame) ((frame->if_r15 & R15_MODE) == R15_MODE_USR)
173
174 /* True if we were at spl0 before the interrupt */
175 #define CLKF_BASEPRI(frame) 0 /* FIXME */
176
177 /* Extract the program counter from a clockframe */
178 #define CLKF_PC(frame) (frame->if_r15 & R15_PC)
179
180 /* True if we took the interrupt from inside another interrupt handler. */
181 /* Non-trivial to check because we handle interrupts in SVC mode. */
182 #define CLKF_INTR(frame) 0 /* FIXME */
183
184 #endif
185
186 /*
187 * definitions of cpu-dependent requirements
188 * referenced in generic code
189 */
190
191 #ifndef _LOCORE
192 #include <sys/sched.h>
193 struct cpu_info {
194 struct schedstate_percpu ci_schedstate; /* scheduler state */
195 #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
196 u_long ci_spin_locks; /* # of spin locks held */
197 u_long ci_simple_locks; /* # of simple locks held */
198 #endif
199 };
200 #ifdef _KERNEL
201 extern struct cpu_info cpu_info_store;
202 #define curcpu() (&cpu_info_store)
203 #endif /* _KERNEL */
204 #endif /* ! _LOCORE */
205
206 /*
207 * Notify the current process (p) that it has a signal pending,
208 * process as soon as possible.
209 */
210
211 #define signotify(p) setsoftast()
212
213 #define cpu_wait(p) /* nothing */
214 #define cpu_number() 0
215
216 #ifndef _LOCORE
217 extern int current_intr_depth;
218
219 /*
220 * Preempt the current process if in interrupt from user mode,
221 * or after the current trap/syscall if in system mode.
222 */
223 int want_resched; /* resched() was called */
224 #define need_resched(ci) (want_resched = 1, setsoftast())
225
226 /*
227 * Give a profiling tick to the current process when the user profiling
228 * buffer pages are invalid. On the i386, request an ast to send us
229 * through trap(), marking the proc as needing a profiling tick.
230 */
231 #define need_proftick(p) ((p)->p_flag |= P_OWEUPC, setsoftast())
232
233 /* locore.S */
234 void atomic_set_bit __P((u_int *address, u_int setmask));
235 void atomic_clear_bit __P((u_int *address, u_int clearmask));
236
237 /* cpuswitch.S */
238 struct pcb;
239 void savectx __P((struct pcb *pcb));
240
241 #ifndef arm26
242 /* ast.c */
243 void userret __P((register struct proc *p));
244 #endif
245
246 /* machdep.h */
247 void bootsync __P((void));
248
249 /* strstr.c */
250 char *strstr __P((const char *s1, const char *s2));
251
252 /* syscall.c */
253 void child_return __P((void *));
254
255 #endif /* !_LOCORE */
256
257 #endif /* _KERNEL */
258
259 #endif /* !_ARM32_CPU_H_ */
260
261 /* End of cpu.h */
262