cpu.c revision 1.57 1 /* $NetBSD: cpu.c,v 1.57 2005/05/10 13:02:55 rearnsha Exp $ */
2
3 /*
4 * Copyright (c) 1995 Mark Brinicombe.
5 * Copyright (c) 1995 Brini.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Brini.
19 * 4. The name of the company nor the name of the author may be used to
20 * endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * RiscBSD kernel project
36 *
37 * cpu.c
38 *
39 * Probing and configuration for the master CPU
40 *
41 * Created : 10/10/95
42 */
43
44 #include "opt_armfpe.h"
45 #include "opt_multiprocessor.h"
46
47 #include <sys/param.h>
48
49 __KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.57 2005/05/10 13:02:55 rearnsha Exp $");
50
51 #include <sys/systm.h>
52 #include <sys/malloc.h>
53 #include <sys/device.h>
54 #include <sys/proc.h>
55 #include <sys/conf.h>
56 #include <uvm/uvm_extern.h>
57 #include <machine/cpu.h>
58
59 #include <arm/cpuconf.h>
60 #include <arm/undefined.h>
61
62 #ifdef ARMFPE
63 #include <machine/bootconfig.h> /* For boot args */
64 #include <arm/fpe-arm/armfpe.h>
65 #endif
66
67 char cpu_model[256];
68
69 /* Prototypes */
70 void identify_arm_cpu(struct device *dv, struct cpu_info *);
71
72 /*
73 * Identify the master (boot) CPU
74 */
75
76 void
77 cpu_attach(struct device *dv)
78 {
79 int usearmfpe;
80
81 usearmfpe = 1; /* when compiled in, its enabled by default */
82
83 curcpu()->ci_dev = dv;
84
85 evcnt_attach_dynamic(&curcpu()->ci_arm700bugcount, EVCNT_TYPE_MISC,
86 NULL, dv->dv_xname, "arm700swibug");
87
88 /* Get the CPU ID from coprocessor 15 */
89
90 curcpu()->ci_arm_cpuid = cpu_id();
91 curcpu()->ci_arm_cputype = curcpu()->ci_arm_cpuid & CPU_ID_CPU_MASK;
92 curcpu()->ci_arm_cpurev =
93 curcpu()->ci_arm_cpuid & CPU_ID_REVISION_MASK;
94
95 identify_arm_cpu(dv, curcpu());
96
97 if (curcpu()->ci_arm_cputype == CPU_ID_SA110 &&
98 curcpu()->ci_arm_cpurev < 3) {
99 aprint_normal("%s: SA-110 with bugged STM^ instruction\n",
100 dv->dv_xname);
101 }
102
103 #ifdef CPU_ARM8
104 if ((curcpu()->ci_arm_cpuid & CPU_ID_CPU_MASK) == CPU_ID_ARM810) {
105 int clock = arm8_clock_config(0, 0);
106 char *fclk;
107 aprint_normal("%s: ARM810 cp15=%02x", dv->dv_xname, clock);
108 aprint_normal(" clock:%s", (clock & 1) ? " dynamic" : "");
109 aprint_normal("%s", (clock & 2) ? " sync" : "");
110 switch ((clock >> 2) & 3) {
111 case 0:
112 fclk = "bus clock";
113 break;
114 case 1:
115 fclk = "ref clock";
116 break;
117 case 3:
118 fclk = "pll";
119 break;
120 default:
121 fclk = "illegal";
122 break;
123 }
124 aprint_normal(" fclk source=%s\n", fclk);
125 }
126 #endif
127
128 #ifdef ARMFPE
129 /*
130 * Ok now we test for an FPA
131 * At this point no floating point emulator has been installed.
132 * This means any FP instruction will cause undefined exception.
133 * We install a temporay coproc 1 handler which will modify
134 * undefined_test if it is called.
135 * We then try to read the FP status register. If undefined_test
136 * has been decremented then the instruction was not handled by
137 * an FPA so we know the FPA is missing. If undefined_test is
138 * still 1 then we know the instruction was handled by an FPA.
139 * We then remove our test handler and look at the
140 * FP status register for identification.
141 */
142
143 /*
144 * Ok if ARMFPE is defined and the boot options request the
145 * ARM FPE then it will be installed as the FPE.
146 * This is just while I work on integrating the new FPE.
147 * It means the new FPE gets installed if compiled int (ARMFPE
148 * defined) and also gives me a on/off option when I boot in
149 * case the new FPE is causing panics.
150 */
151
152
153 if (boot_args)
154 get_bootconf_option(boot_args, "armfpe",
155 BOOTOPT_TYPE_BOOLEAN, &usearmfpe);
156 if (usearmfpe)
157 initialise_arm_fpe();
158 #endif
159 }
160
161 enum cpu_class {
162 CPU_CLASS_NONE,
163 CPU_CLASS_ARM2,
164 CPU_CLASS_ARM2AS,
165 CPU_CLASS_ARM3,
166 CPU_CLASS_ARM6,
167 CPU_CLASS_ARM7,
168 CPU_CLASS_ARM7TDMI,
169 CPU_CLASS_ARM8,
170 CPU_CLASS_ARM9TDMI,
171 CPU_CLASS_ARM9ES,
172 CPU_CLASS_ARM10E,
173 CPU_CLASS_ARM10EJ,
174 CPU_CLASS_SA1,
175 CPU_CLASS_XSCALE
176 };
177
178 static const char * const generic_steppings[16] = {
179 "rev 0", "rev 1", "rev 2", "rev 3",
180 "rev 4", "rev 5", "rev 6", "rev 7",
181 "rev 8", "rev 9", "rev 10", "rev 11",
182 "rev 12", "rev 13", "rev 14", "rev 15",
183 };
184
185 static const char * const sa110_steppings[16] = {
186 "rev 0", "step J", "step K", "step S",
187 "step T", "rev 5", "rev 6", "rev 7",
188 "rev 8", "rev 9", "rev 10", "rev 11",
189 "rev 12", "rev 13", "rev 14", "rev 15",
190 };
191
192 static const char * const sa1100_steppings[16] = {
193 "rev 0", "step B", "step C", "rev 3",
194 "rev 4", "rev 5", "rev 6", "rev 7",
195 "step D", "step E", "rev 10" "step G",
196 "rev 12", "rev 13", "rev 14", "rev 15",
197 };
198
199 static const char * const sa1110_steppings[16] = {
200 "step A-0", "rev 1", "rev 2", "rev 3",
201 "step B-0", "step B-1", "step B-2", "step B-3",
202 "step B-4", "step B-5", "rev 10", "rev 11",
203 "rev 12", "rev 13", "rev 14", "rev 15",
204 };
205
206 static const char * const ixp12x0_steppings[16] = {
207 "(IXP1200 step A)", "(IXP1200 step B)",
208 "rev 2", "(IXP1200 step C)",
209 "(IXP1200 step D)", "(IXP1240/1250 step A)",
210 "(IXP1240 step B)", "(IXP1250 step B)",
211 "rev 8", "rev 9", "rev 10", "rev 11",
212 "rev 12", "rev 13", "rev 14", "rev 15",
213 };
214
215 static const char * const xscale_steppings[16] = {
216 "step A-0", "step A-1", "step B-0", "step C-0",
217 "step D-0", "rev 5", "rev 6", "rev 7",
218 "rev 8", "rev 9", "rev 10", "rev 11",
219 "rev 12", "rev 13", "rev 14", "rev 15",
220 };
221
222 static const char * const i80321_steppings[16] = {
223 "step A-0", "step B-0", "rev 2", "rev 3",
224 "rev 4", "rev 5", "rev 6", "rev 7",
225 "rev 8", "rev 9", "rev 10", "rev 11",
226 "rev 12", "rev 13", "rev 14", "rev 15",
227 };
228
229 /* Steppings for PXA2[15]0 */
230 static const char * const pxa2x0_steppings[16] = {
231 "step A-0", "step A-1", "step B-0", "step B-1",
232 "step B-2", "step C-0", "rev 6", "rev 7",
233 "rev 8", "rev 9", "rev 10", "rev 11",
234 "rev 12", "rev 13", "rev 14", "rev 15",
235 };
236
237 /* Steppings for PXA255/26x.
238 * rev 5: PXA26x B0, rev 6: PXA255 A0
239 */
240 static const char * const pxa255_steppings[16] = {
241 "rev 0", "rev 1", "rev 2", "step A-0",
242 "rev 4", "step B-0", "step A-0", "rev 7",
243 "rev 8", "rev 9", "rev 10", "rev 11",
244 "rev 12", "rev 13", "rev 14", "rev 15",
245 };
246
247 static const char * const ixp425_steppings[16] = {
248 "step 0", "rev 1", "rev 2", "rev 3",
249 "rev 4", "rev 5", "rev 6", "rev 7",
250 "rev 8", "rev 9", "rev 10", "rev 11",
251 "rev 12", "rev 13", "rev 14", "rev 15",
252 };
253
254 struct cpuidtab {
255 u_int32_t cpuid;
256 enum cpu_class cpu_class;
257 const char *cpu_name;
258 const char * const *cpu_steppings;
259 };
260
261 const struct cpuidtab cpuids[] = {
262 { CPU_ID_ARM2, CPU_CLASS_ARM2, "ARM2",
263 generic_steppings },
264 { CPU_ID_ARM250, CPU_CLASS_ARM2AS, "ARM250",
265 generic_steppings },
266
267 { CPU_ID_ARM3, CPU_CLASS_ARM3, "ARM3",
268 generic_steppings },
269
270 { CPU_ID_ARM600, CPU_CLASS_ARM6, "ARM600",
271 generic_steppings },
272 { CPU_ID_ARM610, CPU_CLASS_ARM6, "ARM610",
273 generic_steppings },
274 { CPU_ID_ARM620, CPU_CLASS_ARM6, "ARM620",
275 generic_steppings },
276
277 { CPU_ID_ARM700, CPU_CLASS_ARM7, "ARM700",
278 generic_steppings },
279 { CPU_ID_ARM710, CPU_CLASS_ARM7, "ARM710",
280 generic_steppings },
281 { CPU_ID_ARM7500, CPU_CLASS_ARM7, "ARM7500",
282 generic_steppings },
283 { CPU_ID_ARM710A, CPU_CLASS_ARM7, "ARM710a",
284 generic_steppings },
285 { CPU_ID_ARM7500FE, CPU_CLASS_ARM7, "ARM7500FE",
286 generic_steppings },
287 { CPU_ID_ARM710T, CPU_CLASS_ARM7TDMI, "ARM710T",
288 generic_steppings },
289 { CPU_ID_ARM720T, CPU_CLASS_ARM7TDMI, "ARM720T",
290 generic_steppings },
291 { CPU_ID_ARM740T8K, CPU_CLASS_ARM7TDMI, "ARM740T (8 KB cache)",
292 generic_steppings },
293 { CPU_ID_ARM740T4K, CPU_CLASS_ARM7TDMI, "ARM740T (4 KB cache)",
294 generic_steppings },
295
296 { CPU_ID_ARM810, CPU_CLASS_ARM8, "ARM810",
297 generic_steppings },
298
299 { CPU_ID_ARM920T, CPU_CLASS_ARM9TDMI, "ARM920T",
300 generic_steppings },
301 { CPU_ID_ARM922T, CPU_CLASS_ARM9TDMI, "ARM922T",
302 generic_steppings },
303 { CPU_ID_ARM940T, CPU_CLASS_ARM9TDMI, "ARM940T",
304 generic_steppings },
305 { CPU_ID_ARM946ES, CPU_CLASS_ARM9ES, "ARM946E-S",
306 generic_steppings },
307 { CPU_ID_ARM966ES, CPU_CLASS_ARM9ES, "ARM966E-S",
308 generic_steppings },
309 { CPU_ID_ARM966ESR1, CPU_CLASS_ARM9ES, "ARM966E-S",
310 generic_steppings },
311 { CPU_ID_TI925T, CPU_CLASS_ARM9TDMI, "TI ARM925T",
312 generic_steppings },
313
314 { CPU_ID_ARM1020E, CPU_CLASS_ARM10E, "ARM1020E",
315 generic_steppings },
316 { CPU_ID_ARM1022ES, CPU_CLASS_ARM10E, "ARM1022E-S",
317 generic_steppings },
318 { CPU_ID_ARM1026EJS, CPU_CLASS_ARM10EJ, "ARM1026EJ-S",
319 generic_steppings },
320
321 { CPU_ID_SA110, CPU_CLASS_SA1, "SA-110",
322 sa110_steppings },
323 { CPU_ID_SA1100, CPU_CLASS_SA1, "SA-1100",
324 sa1100_steppings },
325 { CPU_ID_SA1110, CPU_CLASS_SA1, "SA-1110",
326 sa1110_steppings },
327
328 { CPU_ID_IXP1200, CPU_CLASS_SA1, "IXP1200",
329 ixp12x0_steppings },
330
331 { CPU_ID_80200, CPU_CLASS_XSCALE, "i80200",
332 xscale_steppings },
333
334 { CPU_ID_80321_400, CPU_CLASS_XSCALE, "i80321 400MHz",
335 i80321_steppings },
336 { CPU_ID_80321_600, CPU_CLASS_XSCALE, "i80321 600MHz",
337 i80321_steppings },
338 { CPU_ID_80321_400_B0, CPU_CLASS_XSCALE, "i80321 400MHz",
339 i80321_steppings },
340 { CPU_ID_80321_600_B0, CPU_CLASS_XSCALE, "i80321 600MHz",
341 i80321_steppings },
342
343 { CPU_ID_PXA250A, CPU_CLASS_XSCALE, "PXA250",
344 pxa2x0_steppings },
345 { CPU_ID_PXA210A, CPU_CLASS_XSCALE, "PXA210",
346 pxa2x0_steppings },
347 { CPU_ID_PXA250B, CPU_CLASS_XSCALE, "PXA250",
348 pxa2x0_steppings },
349 { CPU_ID_PXA210B, CPU_CLASS_XSCALE, "PXA210",
350 pxa2x0_steppings },
351 { CPU_ID_PXA250C, CPU_CLASS_XSCALE, "PXA255/26x",
352 pxa255_steppings },
353 { CPU_ID_PXA210C, CPU_CLASS_XSCALE, "PXA210",
354 pxa2x0_steppings },
355
356 { CPU_ID_IXP425_533, CPU_CLASS_XSCALE, "IXP425 533MHz",
357 ixp425_steppings },
358 { CPU_ID_IXP425_400, CPU_CLASS_XSCALE, "IXP425 400MHz",
359 ixp425_steppings },
360 { CPU_ID_IXP425_266, CPU_CLASS_XSCALE, "IXP425 266MHz",
361 ixp425_steppings },
362
363 { 0, CPU_CLASS_NONE, NULL, NULL }
364 };
365
366 struct cpu_classtab {
367 const char *class_name;
368 const char *class_option;
369 };
370
371 const struct cpu_classtab cpu_classes[] = {
372 { "unknown", NULL }, /* CPU_CLASS_NONE */
373 { "ARM2", "CPU_ARM2" }, /* CPU_CLASS_ARM2 */
374 { "ARM2as", "CPU_ARM250" }, /* CPU_CLASS_ARM2AS */
375 { "ARM3", "CPU_ARM3" }, /* CPU_CLASS_ARM3 */
376 { "ARM6", "CPU_ARM6" }, /* CPU_CLASS_ARM6 */
377 { "ARM7", "CPU_ARM7" }, /* CPU_CLASS_ARM7 */
378 { "ARM7TDMI", "CPU_ARM7TDMI" }, /* CPU_CLASS_ARM7TDMI */
379 { "ARM8", "CPU_ARM8" }, /* CPU_CLASS_ARM8 */
380 { "ARM9TDMI", NULL }, /* CPU_CLASS_ARM9TDMI */
381 { "ARM9E-S", NULL }, /* CPU_CLASS_ARM9ES */
382 { "ARM10E", "CPU_ARM10" }, /* CPU_CLASS_ARM10E */
383 { "ARM10EJ", "CPU_ARM10" }, /* CPU_CLASS_ARM10EJ */
384 { "SA-1", "CPU_SA110" }, /* CPU_CLASS_SA1 */
385 { "XScale", "CPU_XSCALE_..." }, /* CPU_CLASS_XSCALE */
386 };
387
388 /*
389 * Report the type of the specified arm processor. This uses the generic and
390 * arm specific information in the CPU structure to identify the processor.
391 * The remaining fields in the CPU structure are filled in appropriately.
392 */
393
394 static const char * const wtnames[] = {
395 "write-through",
396 "write-back",
397 "write-back",
398 "**unknown 3**",
399 "**unknown 4**",
400 "write-back-locking", /* XXX XScale-specific? */
401 "write-back-locking-A",
402 "write-back-locking-B",
403 "**unknown 8**",
404 "**unknown 9**",
405 "**unknown 10**",
406 "**unknown 11**",
407 "**unknown 12**",
408 "**unknown 13**",
409 "write-back-locking-C",
410 "**unknown 15**",
411 };
412
413 void
414 identify_arm_cpu(struct device *dv, struct cpu_info *ci)
415 {
416 u_int cpuid;
417 enum cpu_class cpu_class = CPU_CLASS_NONE;
418 int i;
419
420 cpuid = ci->ci_arm_cpuid;
421
422 if (cpuid == 0) {
423 aprint_error("Processor failed probe - no CPU ID\n");
424 return;
425 }
426
427 for (i = 0; cpuids[i].cpuid != 0; i++)
428 if (cpuids[i].cpuid == (cpuid & CPU_ID_CPU_MASK)) {
429 cpu_class = cpuids[i].cpu_class;
430 sprintf(cpu_model, "%s %s (%s core)",
431 cpuids[i].cpu_name,
432 cpuids[i].cpu_steppings[cpuid &
433 CPU_ID_REVISION_MASK],
434 cpu_classes[cpu_class].class_name);
435 break;
436 }
437
438 if (cpuids[i].cpuid == 0)
439 sprintf(cpu_model, "unknown CPU (ID = 0x%x)", cpuid);
440
441 aprint_naive(": %s\n", cpu_model);
442 aprint_normal(": %s\n", cpu_model);
443
444 aprint_normal("%s:", dv->dv_xname);
445
446 switch (cpu_class) {
447 case CPU_CLASS_ARM6:
448 case CPU_CLASS_ARM7:
449 case CPU_CLASS_ARM7TDMI:
450 case CPU_CLASS_ARM8:
451 if ((ci->ci_ctrl & CPU_CONTROL_IDC_ENABLE) == 0)
452 aprint_normal(" IDC disabled");
453 else
454 aprint_normal(" IDC enabled");
455 break;
456 case CPU_CLASS_ARM9TDMI:
457 case CPU_CLASS_ARM10E:
458 case CPU_CLASS_ARM10EJ:
459 case CPU_CLASS_SA1:
460 case CPU_CLASS_XSCALE:
461 if ((ci->ci_ctrl & CPU_CONTROL_DC_ENABLE) == 0)
462 aprint_normal(" DC disabled");
463 else
464 aprint_normal(" DC enabled");
465 if ((ci->ci_ctrl & CPU_CONTROL_IC_ENABLE) == 0)
466 aprint_normal(" IC disabled");
467 else
468 aprint_normal(" IC enabled");
469 break;
470 default:
471 break;
472 }
473 if ((ci->ci_ctrl & CPU_CONTROL_WBUF_ENABLE) == 0)
474 aprint_normal(" WB disabled");
475 else
476 aprint_normal(" WB enabled");
477
478 if (ci->ci_ctrl & CPU_CONTROL_LABT_ENABLE)
479 aprint_normal(" LABT");
480 else
481 aprint_normal(" EABT");
482
483 if (ci->ci_ctrl & CPU_CONTROL_BPRD_ENABLE)
484 aprint_normal(" branch prediction enabled");
485
486 aprint_normal("\n");
487
488 /* Print cache info. */
489 if (arm_picache_line_size == 0 && arm_pdcache_line_size == 0)
490 goto skip_pcache;
491
492 if (arm_pcache_unified) {
493 aprint_normal("%s: %dKB/%dB %d-way %s unified cache\n",
494 dv->dv_xname, arm_pdcache_size / 1024,
495 arm_pdcache_line_size, arm_pdcache_ways,
496 wtnames[arm_pcache_type]);
497 } else {
498 aprint_normal("%s: %dKB/%dB %d-way Instruction cache\n",
499 dv->dv_xname, arm_picache_size / 1024,
500 arm_picache_line_size, arm_picache_ways);
501 aprint_normal("%s: %dKB/%dB %d-way %s Data cache\n",
502 dv->dv_xname, arm_pdcache_size / 1024,
503 arm_pdcache_line_size, arm_pdcache_ways,
504 wtnames[arm_pcache_type]);
505 }
506
507 skip_pcache:
508
509 switch (cpu_class) {
510 #ifdef CPU_ARM2
511 case CPU_CLASS_ARM2:
512 #endif
513 #ifdef CPU_ARM250
514 case CPU_CLASS_ARM2AS:
515 #endif
516 #ifdef CPU_ARM3
517 case CPU_CLASS_ARM3:
518 #endif
519 #ifdef CPU_ARM6
520 case CPU_CLASS_ARM6:
521 #endif
522 #ifdef CPU_ARM7
523 case CPU_CLASS_ARM7:
524 #endif
525 #ifdef CPU_ARM7TDMI
526 case CPU_CLASS_ARM7TDMI:
527 #endif
528 #ifdef CPU_ARM8
529 case CPU_CLASS_ARM8:
530 #endif
531 #ifdef CPU_ARM9
532 case CPU_CLASS_ARM9TDMI:
533 #endif
534 #ifdef CPU_ARM10
535 case CPU_CLASS_ARM10E:
536 case CPU_CLASS_ARM10EJ:
537 #endif
538 #if defined(CPU_SA110) || defined(CPU_SA1100) || \
539 defined(CPU_SA1110) || defined(CPU_IXP12X0)
540 case CPU_CLASS_SA1:
541 #endif
542 #if defined(CPU_XSCALE_80200) || defined(CPU_XSCALE_80321) || \
543 defined(CPU_XSCALE_PXA2X0) || defined(CPU_XSCALE_IXP425)
544 case CPU_CLASS_XSCALE:
545 #endif
546 break;
547 default:
548 if (cpu_classes[cpu_class].class_option != NULL)
549 aprint_error("%s: %s does not fully support this CPU."
550 "\n", dv->dv_xname, ostype);
551 else {
552 aprint_error("%s: This kernel does not fully support "
553 "this CPU.\n", dv->dv_xname);
554 aprint_normal("%s: Recompile with \"options %s\" to "
555 "correct this.\n", dv->dv_xname,
556 cpu_classes[cpu_class].class_option);
557 }
558 break;
559 }
560
561 }
562 #ifdef MULTIPROCESSOR
563 int
564 cpu_alloc_idlepcb(struct cpu_info *ci)
565 {
566 vaddr_t uaddr;
567 struct pcb *pcb;
568 struct trapframe *tf;
569 int error;
570
571 /*
572 * Generate a kernel stack and PCB (in essence, a u-area) for the
573 * new CPU.
574 */
575 if (uvm_uarea_alloc(&uaddr)) {
576 error = uvm_fault_wire(kernel_map, uaddr, uaddr + USPACE,
577 VM_FAULT_WIRE, VM_PROT_READ | VM_PROT_WRITE);
578 if (error)
579 return error;
580 }
581 ci->ci_idlepcb = pcb = (struct pcb *)uaddr;
582
583 /*
584 * This code is largely derived from cpu_fork(), with which it
585 * should perhaps be shared.
586 */
587
588 /* Copy the pcb */
589 *pcb = proc0.p_addr->u_pcb;
590
591 /* Set up the undefined stack for the process. */
592 pcb->pcb_un.un_32.pcb32_und_sp = uaddr + USPACE_UNDEF_STACK_TOP;
593 pcb->pcb_un.un_32.pcb32_sp = uaddr + USPACE_SVC_STACK_TOP;
594
595 #ifdef STACKCHECKS
596 /* Fill the undefined stack with a known pattern */
597 memset(((u_char *)uaddr) + USPACE_UNDEF_STACK_BOTTOM, 0xdd,
598 (USPACE_UNDEF_STACK_TOP - USPACE_UNDEF_STACK_BOTTOM));
599 /* Fill the kernel stack with a known pattern */
600 memset(((u_char *)uaddr) + USPACE_SVC_STACK_BOTTOM, 0xdd,
601 (USPACE_SVC_STACK_TOP - USPACE_SVC_STACK_BOTTOM));
602 #endif /* STACKCHECKS */
603
604 pcb->pcb_tf = tf =
605 (struct trapframe *)pcb->pcb_un.un_32.pcb32_sp - 1;
606 *tf = *proc0.p_addr->u_pcb.pcb_tf;
607 return 0;
608 }
609 #endif /* MULTIPROCESSOR */
610
611 /* End of cpu.c */
612