cpu.h revision 1.8 1 /* $NetBSD: cpu.h,v 1.8 2001/02/28 00:17:18 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 <machine/frame.h>
108 #endif /* !_LOCORE */
109
110 #ifdef arm26
111 extern int astpending;
112 #define setsoftast() (astpending = 1)
113 #else
114 #include <machine/psl.h>
115 #endif
116
117 #include <arm/armreg.h>
118
119 #ifdef PROG32
120 #ifdef _LOCORE
121 #define IRQdisable \
122 stmfd sp!, {r0} ; \
123 mrs r0, cpsr_all ; \
124 orr r0, r0, #(I32_bit) ; \
125 msr cpsr_all, r0 ; \
126 ldmfd sp!, {r0}
127
128 #define IRQenable \
129 stmfd sp!, {r0} ; \
130 mrs r0, cpsr_all ; \
131 bic r0, r0, #(I32_bit) ; \
132 msr cpsr_all, r0 ; \
133 ldmfd sp!, {r0}
134
135 #else
136 #define IRQdisable SetCPSR(I32_bit, I32_bit);
137 #define IRQenable SetCPSR(I32_bit, 0);
138 #endif /* _LOCORE */
139 #endif
140
141 /* All the CLKF_* macros take a struct clockframe * as an argument. */
142
143 #ifdef PROG32
144 /*
145 * Return TRUE/FALSE (1/0) depending on whether the frame came from USR
146 * mode or not.
147 */
148
149 #define CLKF_USERMODE(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
150
151 /*
152 * This needs straighening, prob is the frame does not have info on the
153 * priority a guess that needs trying is (current_spl_level == SPL0)
154 */
155
156 #define CLKF_BASEPRI(frame) ((frame->if_spsr & PSR_MODE) == PSR_USR32_MODE)
157
158 #define CLKF_PC(frame) (frame->if_pc)
159
160 /*#define CLKF_INTR(frame) (current_intr_depth > 1)*/
161
162 /* Hack to treat FPE time as interrupt time so we can measure it */
163 #define CLKF_INTR(frame) ((current_intr_depth > 1) || (frame->if_spsr & PSR_MODE) == PSR_UND32_MODE)
164
165 #define PROC_PC(p) ((p)->p_md.md_regs->tf_pc)
166
167 #elif defined(PROG26)
168
169 /* True if we took the interrupt in user mode */
170 #define CLKF_USERMODE(frame) ((frame->if_r15 & R15_MODE) == R15_MODE_USR)
171
172 /* True if we were at spl0 before the interrupt */
173 #define CLKF_BASEPRI(frame) 0 /* FIXME */
174
175 /* Extract the program counter from a clockframe */
176 #define CLKF_PC(frame) (frame->if_r15 & R15_PC)
177
178 /* True if we took the interrupt from inside another interrupt handler. */
179 /* Non-trivial to check because we handle interrupts in SVC mode. */
180 #define CLKF_INTR(frame) 0 /* FIXME */
181
182 #endif
183
184 /*
185 * definitions of cpu-dependent requirements
186 * referenced in generic code
187 */
188
189 #ifndef _LOCORE
190 #include <sys/sched.h>
191 struct cpu_info {
192 struct schedstate_percpu ci_schedstate; /* scheduler state */
193 #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
194 u_long ci_spin_locks; /* # of spin locks held */
195 u_long ci_simple_locks; /* # of simple locks held */
196 #endif
197 };
198 #ifdef _KERNEL
199 extern struct cpu_info cpu_info_store;
200 #define curcpu() (&cpu_info_store)
201 #endif /* _KERNEL */
202 #endif /* ! _LOCORE */
203
204 /*
205 * Notify the current process (p) that it has a signal pending,
206 * process as soon as possible.
207 */
208
209 #define signotify(p) setsoftast()
210
211 #define cpu_wait(p) /* nothing */
212 #define cpu_number() 0
213
214 #ifndef _LOCORE
215 extern int current_intr_depth;
216
217 /*
218 * Preempt the current process if in interrupt from user mode,
219 * or after the current trap/syscall if in system mode.
220 */
221 int want_resched; /* resched() was called */
222 #define need_resched(ci) (want_resched = 1, setsoftast())
223
224 /*
225 * Give a profiling tick to the current process when the user profiling
226 * buffer pages are invalid. On the i386, request an ast to send us
227 * through trap(), marking the proc as needing a profiling tick.
228 */
229 #define need_proftick(p) ((p)->p_flag |= P_OWEUPC, setsoftast())
230
231 /* locore.S */
232 void atomic_set_bit __P((u_int *address, u_int setmask));
233 void atomic_clear_bit __P((u_int *address, u_int clearmask));
234
235 /* cpuswitch.S */
236 struct pcb;
237 void savectx __P((struct pcb *pcb));
238
239 #ifndef arm26
240 /* ast.c */
241 void userret __P((register struct proc *p));
242 #endif
243
244 /* machdep.h */
245 void bootsync __P((void));
246
247 /* strstr.c */
248 char *strstr __P((const char *s1, const char *s2));
249
250 /* syscall.c */
251 void child_return __P((void *));
252
253 #endif /* !_LOCORE */
254
255 #endif /* _KERNEL */
256
257 #endif /* !_ARM32_CPU_H_ */
258
259 /* End of cpu.h */
260