]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/aim/machdep.c
Set mdp only under #ifdef WII.
[FreeBSD/FreeBSD.git] / sys / powerpc / aim / machdep.c
1 /*-
2  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
3  * Copyright (C) 1995, 1996 TooLs GmbH.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by TooLs GmbH.
17  * 4. The name of TooLs GmbH may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /*-
32  * Copyright (C) 2001 Benno Rice
33  * All rights reserved.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  * 1. Redistributions of source code must retain the above copyright
39  *    notice, this list of conditions and the following disclaimer.
40  * 2. Redistributions in binary form must reproduce the above copyright
41  *    notice, this list of conditions and the following disclaimer in the
42  *    documentation and/or other materials provided with the distribution.
43  *
44  * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
45  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
46  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
47  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
49  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
50  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
51  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
52  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
53  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54  *      $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $
55  */
56
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
59
60 #include "opt_compat.h"
61 #include "opt_ddb.h"
62 #include "opt_kstack_pages.h"
63 #include "opt_platform.h"
64
65 #include <sys/param.h>
66 #include <sys/proc.h>
67 #include <sys/systm.h>
68 #include <sys/bio.h>
69 #include <sys/buf.h>
70 #include <sys/bus.h>
71 #include <sys/cons.h>
72 #include <sys/cpu.h>
73 #include <sys/eventhandler.h>
74 #include <sys/exec.h>
75 #include <sys/imgact.h>
76 #include <sys/kdb.h>
77 #include <sys/kernel.h>
78 #include <sys/ktr.h>
79 #include <sys/linker.h>
80 #include <sys/lock.h>
81 #include <sys/malloc.h>
82 #include <sys/mbuf.h>
83 #include <sys/msgbuf.h>
84 #include <sys/mutex.h>
85 #include <sys/ptrace.h>
86 #include <sys/reboot.h>
87 #include <sys/signalvar.h>
88 #include <sys/syscallsubr.h>
89 #include <sys/sysctl.h>
90 #include <sys/sysent.h>
91 #include <sys/sysproto.h>
92 #include <sys/ucontext.h>
93 #include <sys/uio.h>
94 #include <sys/vmmeter.h>
95 #include <sys/vnode.h>
96
97 #include <net/netisr.h>
98
99 #include <vm/vm.h>
100 #include <vm/vm_extern.h>
101 #include <vm/vm_kern.h>
102 #include <vm/vm_page.h>
103 #include <vm/vm_map.h>
104 #include <vm/vm_object.h>
105 #include <vm/vm_pager.h>
106
107 #include <machine/altivec.h>
108 #ifndef __powerpc64__
109 #include <machine/bat.h>
110 #endif
111 #include <machine/cpu.h>
112 #include <machine/elf.h>
113 #include <machine/fpu.h>
114 #include <machine/hid.h>
115 #include <machine/kdb.h>
116 #include <machine/md_var.h>
117 #include <machine/metadata.h>
118 #include <machine/mmuvar.h>
119 #include <machine/pcb.h>
120 #include <machine/reg.h>
121 #include <machine/sigframe.h>
122 #include <machine/spr.h>
123 #include <machine/trap.h>
124 #include <machine/vmparam.h>
125
126 #include <ddb/ddb.h>
127
128 #include <dev/ofw/openfirm.h>
129
130 #ifdef DDB
131 extern vm_offset_t ksym_start, ksym_end;
132 #endif
133
134 int cold = 1;
135 #ifdef __powerpc64__
136 extern int n_slbs;
137 int cacheline_size = 128;
138 #else
139 int cacheline_size = 32;
140 #endif
141 int hw_direct_map = 1;
142
143 struct pcpu __pcpu[MAXCPU];
144
145 static struct trapframe frame0;
146
147 char            machine[] = "powerpc";
148 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
149
150 static void     cpu_startup(void *);
151 SYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_startup, NULL);
152
153 SYSCTL_INT(_machdep, CPU_CACHELINE, cacheline_size,
154            CTLFLAG_RD, &cacheline_size, 0, "");
155
156 uintptr_t       powerpc_init(vm_offset_t, vm_offset_t, vm_offset_t, void *);
157
158 int             setfault(faultbuf);             /* defined in locore.S */
159
160 long            Maxmem = 0;
161 long            realmem = 0;
162
163 #ifndef __powerpc64__
164 struct bat      battable[16];
165 #endif
166
167 struct kva_md_info kmi;
168
169 static void
170 cpu_startup(void *dummy)
171 {
172
173         /*
174          * Initialise the decrementer-based clock.
175          */
176         decr_init();
177
178         /*
179          * Good {morning,afternoon,evening,night}.
180          */
181         cpu_setup(PCPU_GET(cpuid));
182
183 #ifdef PERFMON
184         perfmon_init();
185 #endif
186         printf("real memory  = %ld (%ld MB)\n", ptoa(physmem),
187             ptoa(physmem) / 1048576);
188         realmem = physmem;
189
190         if (bootverbose)
191                 printf("available KVA = %zd (%zd MB)\n",
192                     virtual_end - virtual_avail,
193                     (virtual_end - virtual_avail) / 1048576);
194
195         /*
196          * Display any holes after the first chunk of extended memory.
197          */
198         if (bootverbose) {
199                 int indx;
200
201                 printf("Physical memory chunk(s):\n");
202                 for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
203                         vm_offset_t size1 =
204                             phys_avail[indx + 1] - phys_avail[indx];
205
206                         #ifdef __powerpc64__
207                         printf("0x%016lx - 0x%016lx, %ld bytes (%ld pages)\n",
208                         #else
209                         printf("0x%08x - 0x%08x, %d bytes (%ld pages)\n",
210                         #endif
211                             phys_avail[indx], phys_avail[indx + 1] - 1, size1,
212                             size1 / PAGE_SIZE);
213                 }
214         }
215
216         vm_ksubmap_init(&kmi);
217
218         printf("avail memory = %ld (%ld MB)\n", ptoa(cnt.v_free_count),
219             ptoa(cnt.v_free_count) / 1048576);
220
221         /*
222          * Set up buffers, so they can be used to read disk labels.
223          */
224         bufinit();
225         vm_pager_bufferinit();
226 }
227
228 extern char     kernel_text[], _end[];
229
230 #ifndef __powerpc64__
231 /* Bits for running on 64-bit systems in 32-bit mode. */
232 extern void     *testppc64, *testppc64size;
233 extern void     *restorebridge, *restorebridgesize;
234 extern void     *rfid_patch, *rfi_patch1, *rfi_patch2;
235 extern void     *trapcode64;
236 #endif
237
238 #ifdef SMP
239 extern void     *rstcode, *rstsize;
240 #endif
241 extern void     *trapcode, *trapsize;
242 extern void     *slbtrap, *slbtrapsize;
243 extern void     *alitrap, *alisize;
244 extern void     *dsitrap, *dsisize;
245 extern void     *decrint, *decrsize;
246 extern void     *extint, *extsize;
247 extern void     *dblow, *dbsize;
248 extern void     *imisstrap, *imisssize;
249 extern void     *dlmisstrap, *dlmisssize;
250 extern void     *dsmisstrap, *dsmisssize;
251
252 uintptr_t
253 powerpc_init(vm_offset_t startkernel, vm_offset_t endkernel,
254     vm_offset_t basekernel, void *mdp)
255 {
256         struct          pcpu *pc;
257         void            *generictrap;
258         size_t          trap_offset;
259         void            *kmdp;
260         char            *env;
261         register_t      msr, scratch, vers;
262         uint8_t         *cache_check;
263         int             cacheline_warn;
264         #ifndef __powerpc64__
265         int             ppc64;
266         #endif
267
268         kmdp = NULL;
269         trap_offset = 0;
270         cacheline_warn = 0;
271
272 #ifdef WII
273         /*
274          * The Wii loader doesn't pass us any environment so, mdp
275          * points to garbage at this point. The Wii CPU is a 750CL.
276          */
277         vers = mfpvr();
278         if ((vers & 0xfffff0e0) == (MPC750 << 16 | MPC750CL)) 
279                 mdp = NULL;
280 #endif
281
282         /*
283          * Parse metadata if present and fetch parameters.  Must be done
284          * before console is inited so cninit gets the right value of
285          * boothowto.
286          */
287         if (mdp != NULL) {
288                 preload_metadata = mdp;
289                 kmdp = preload_search_by_type("elf kernel");
290                 if (kmdp != NULL) {
291                         boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
292                         kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
293                         endkernel = ulmax(endkernel, MD_FETCH(kmdp,
294                             MODINFOMD_KERNEND, vm_offset_t));
295 #ifdef DDB
296                         ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t);
297                         ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t);
298 #endif
299                 }
300         }
301
302         /*
303          * Init params/tunables that can be overridden by the loader
304          */
305         init_param1();
306
307         /*
308          * Start initializing proc0 and thread0.
309          */
310         proc_linkup0(&proc0, &thread0);
311         thread0.td_frame = &frame0;
312
313         /*
314          * Set up per-cpu data.
315          */
316         pc = __pcpu;
317         pcpu_init(pc, 0, sizeof(struct pcpu));
318         pc->pc_curthread = &thread0;
319 #ifdef __powerpc64__
320         __asm __volatile("mr 13,%0" :: "r"(pc->pc_curthread));
321 #else
322         __asm __volatile("mr 2,%0" :: "r"(pc->pc_curthread));
323 #endif
324         pc->pc_cpuid = 0;
325
326         __asm __volatile("mtsprg 0, %0" :: "r"(pc));
327
328         /*
329          * Init mutexes, which we use heavily in PMAP
330          */
331
332         mutex_init();
333
334         /*
335          * Install the OF client interface
336          */
337
338         OF_bootstrap();
339
340         /*
341          * Initialize the console before printing anything.
342          */
343         cninit();
344
345         /*
346          * Complain if there is no metadata.
347          */
348         if (mdp == NULL || kmdp == NULL) {
349                 printf("powerpc_init: no loader metadata.\n");
350         }
351
352         /*
353          * Init KDB
354          */
355
356         kdb_init();
357
358         /* Various very early CPU fix ups */
359         switch (mfpvr() >> 16) {
360                 /*
361                  * PowerPC 970 CPUs have a misfeature requested by Apple that
362                  * makes them pretend they have a 32-byte cacheline. Turn this
363                  * off before we measure the cacheline size.
364                  */
365                 case IBM970:
366                 case IBM970FX:
367                 case IBM970MP:
368                 case IBM970GX:
369                         scratch = mfspr(SPR_HID5);
370                         scratch &= ~HID5_970_DCBZ_SIZE_HI;
371                         mtspr(SPR_HID5, scratch);
372                         break;
373         #ifdef __powerpc64__
374                 case IBMPOWER7:
375                         /* XXX: get from ibm,slb-size in device tree */
376                         n_slbs = 32;
377                         break;
378         #endif
379         }
380
381         /*
382          * Initialize the interrupt tables and figure out our cache line
383          * size and whether or not we need the 64-bit bridge code.
384          */
385
386         /*
387          * Disable translation in case the vector area hasn't been
388          * mapped (G5). Note that no OFW calls can be made until
389          * translation is re-enabled.
390          */
391
392         msr = mfmsr();
393         mtmsr((msr & ~(PSL_IR | PSL_DR)) | PSL_RI);
394
395         /*
396          * Measure the cacheline size using dcbz
397          *
398          * Use EXC_PGM as a playground. We are about to overwrite it
399          * anyway, we know it exists, and we know it is cache-aligned.
400          */
401
402         cache_check = (void *)EXC_PGM;
403
404         for (cacheline_size = 0; cacheline_size < 0x100; cacheline_size++)
405                 cache_check[cacheline_size] = 0xff;
406
407         __asm __volatile("dcbz 0,%0":: "r" (cache_check) : "memory");
408
409         /* Find the first byte dcbz did not zero to get the cache line size */
410         for (cacheline_size = 0; cacheline_size < 0x100 &&
411             cache_check[cacheline_size] == 0; cacheline_size++);
412
413         /* Work around psim bug */
414         if (cacheline_size == 0) {
415                 cacheline_warn = 1;
416                 cacheline_size = 32;
417         }
418
419         /* Make sure the kernel icache is valid before we go too much further */
420         __syncicache((caddr_t)startkernel, endkernel - startkernel);
421
422         #ifndef __powerpc64__
423         /*
424          * Figure out whether we need to use the 64 bit PMAP. This works by
425          * executing an instruction that is only legal on 64-bit PPC (mtmsrd),
426          * and setting ppc64 = 0 if that causes a trap.
427          */
428
429         ppc64 = 1;
430
431         bcopy(&testppc64, (void *)EXC_PGM,  (size_t)&testppc64size);
432         __syncicache((void *)EXC_PGM, (size_t)&testppc64size);
433
434         __asm __volatile("\
435                 mfmsr %0;       \
436                 mtsprg2 %1;     \
437                                 \
438                 mtmsrd %0;      \
439                 mfsprg2 %1;"
440             : "=r"(scratch), "=r"(ppc64));
441
442         if (ppc64)
443                 cpu_features |= PPC_FEATURE_64;
444
445         /*
446          * Now copy restorebridge into all the handlers, if necessary,
447          * and set up the trap tables.
448          */
449
450         if (cpu_features & PPC_FEATURE_64) {
451                 /* Patch the two instances of rfi -> rfid */
452                 bcopy(&rfid_patch,&rfi_patch1,4);
453         #ifdef KDB
454                 /* rfi_patch2 is at the end of dbleave */
455                 bcopy(&rfid_patch,&rfi_patch2,4);
456         #endif
457
458                 /*
459                  * Copy a code snippet to restore 32-bit bridge mode
460                  * to the top of every non-generic trap handler
461                  */
462
463                 trap_offset += (size_t)&restorebridgesize;
464                 bcopy(&restorebridge, (void *)EXC_RST, trap_offset); 
465                 bcopy(&restorebridge, (void *)EXC_DSI, trap_offset); 
466                 bcopy(&restorebridge, (void *)EXC_ALI, trap_offset); 
467                 bcopy(&restorebridge, (void *)EXC_PGM, trap_offset); 
468                 bcopy(&restorebridge, (void *)EXC_MCHK, trap_offset); 
469                 bcopy(&restorebridge, (void *)EXC_TRC, trap_offset); 
470                 bcopy(&restorebridge, (void *)EXC_BPT, trap_offset); 
471
472                 /*
473                  * Set the common trap entry point to the one that
474                  * knows to restore 32-bit operation on execution.
475                  */
476
477                 generictrap = &trapcode64;
478         } else {
479                 generictrap = &trapcode;
480         }
481
482         #else /* powerpc64 */
483         cpu_features |= PPC_FEATURE_64;
484         generictrap = &trapcode;
485         #endif
486
487 #ifdef SMP
488         bcopy(&rstcode, (void *)(EXC_RST + trap_offset),  (size_t)&rstsize);
489 #else
490         bcopy(generictrap, (void *)EXC_RST,  (size_t)&trapsize);
491 #endif
492
493 #ifdef KDB
494         bcopy(&dblow,   (void *)(EXC_MCHK + trap_offset), (size_t)&dbsize);
495         bcopy(&dblow,   (void *)(EXC_PGM + trap_offset),  (size_t)&dbsize);
496         bcopy(&dblow,   (void *)(EXC_TRC + trap_offset),  (size_t)&dbsize);
497         bcopy(&dblow,   (void *)(EXC_BPT + trap_offset),  (size_t)&dbsize);
498 #else
499         bcopy(generictrap, (void *)EXC_MCHK, (size_t)&trapsize);
500         bcopy(generictrap, (void *)EXC_PGM,  (size_t)&trapsize);
501         bcopy(generictrap, (void *)EXC_TRC,  (size_t)&trapsize);
502         bcopy(generictrap, (void *)EXC_BPT,  (size_t)&trapsize);
503 #endif
504         bcopy(&alitrap,  (void *)(EXC_ALI + trap_offset),  (size_t)&alisize);
505         bcopy(&dsitrap,  (void *)(EXC_DSI + trap_offset),  (size_t)&dsisize);
506         bcopy(generictrap, (void *)EXC_ISI,  (size_t)&trapsize);
507         #ifdef __powerpc64__
508         bcopy(&slbtrap, (void *)EXC_DSE,  (size_t)&slbtrapsize);
509         bcopy(&slbtrap, (void *)EXC_ISE,  (size_t)&slbtrapsize);
510         #endif
511         bcopy(generictrap, (void *)EXC_EXI,  (size_t)&trapsize);
512         bcopy(generictrap, (void *)EXC_FPU,  (size_t)&trapsize);
513         bcopy(generictrap, (void *)EXC_DECR, (size_t)&trapsize);
514         bcopy(generictrap, (void *)EXC_SC,   (size_t)&trapsize);
515         bcopy(generictrap, (void *)EXC_FPA,  (size_t)&trapsize);
516         bcopy(generictrap, (void *)EXC_VEC,  (size_t)&trapsize);
517         bcopy(generictrap, (void *)EXC_PERF,  (size_t)&trapsize);
518         bcopy(generictrap, (void *)EXC_VECAST_G4, (size_t)&trapsize);
519         bcopy(generictrap, (void *)EXC_VECAST_G5, (size_t)&trapsize);
520         #ifndef __powerpc64__
521         /* G2-specific TLB miss helper handlers */
522         bcopy(&imisstrap, (void *)EXC_IMISS,  (size_t)&imisssize);
523         bcopy(&dlmisstrap, (void *)EXC_DLMISS,  (size_t)&dlmisssize);
524         bcopy(&dsmisstrap, (void *)EXC_DSMISS,  (size_t)&dsmisssize);
525         #endif
526         __syncicache(EXC_RSVD, EXC_LAST - EXC_RSVD);
527
528         /*
529          * Restore MSR
530          */
531         mtmsr(msr);
532         
533         /* Warn if cachline size was not determined */
534         if (cacheline_warn == 1) {
535                 printf("WARNING: cacheline size undetermined, setting to 32\n");
536         }
537
538         /*
539          * Choose a platform module so we can get the physical memory map.
540          */
541         
542         platform_probe_and_attach();
543
544         /*
545          * Initialise virtual memory. Use BUS_PROBE_GENERIC priority
546          * in case the platform module had a better idea of what we
547          * should do.
548          */
549         if (cpu_features & PPC_FEATURE_64)
550                 pmap_mmu_install(MMU_TYPE_G5, BUS_PROBE_GENERIC);
551         else
552                 pmap_mmu_install(MMU_TYPE_OEA, BUS_PROBE_GENERIC);
553
554         pmap_bootstrap(startkernel, endkernel);
555         mtmsr(PSL_KERNSET & ~PSL_EE);
556
557         /*
558          * Initialize params/tunables that are derived from memsize
559          */
560         init_param2(physmem);
561
562         /*
563          * Grab booted kernel's name
564          */
565         env = getenv("kernelname");
566         if (env != NULL) {
567                 strlcpy(kernelname, env, sizeof(kernelname));
568                 freeenv(env);
569         }
570
571         /*
572          * Finish setting up thread0.
573          */
574         thread0.td_pcb = (struct pcb *)
575             ((thread0.td_kstack + thread0.td_kstack_pages * PAGE_SIZE -
576             sizeof(struct pcb)) & ~15UL);
577         bzero((void *)thread0.td_pcb, sizeof(struct pcb));
578         pc->pc_curpcb = thread0.td_pcb;
579
580         /* Initialise the message buffer. */
581         msgbufinit(msgbufp, msgbufsize);
582
583 #ifdef KDB
584         if (boothowto & RB_KDB)
585                 kdb_enter(KDB_WHY_BOOTFLAGS,
586                     "Boot flags requested debugger");
587 #endif
588
589         return (((uintptr_t)thread0.td_pcb -
590             (sizeof(struct callframe) - 3*sizeof(register_t))) & ~15UL);
591 }
592
593 void
594 bzero(void *buf, size_t len)
595 {
596         caddr_t p;
597
598         p = buf;
599
600         while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) {
601                 *p++ = 0;
602                 len--;
603         }
604
605         while (len >= sizeof(u_long) * 8) {
606                 *(u_long*) p = 0;
607                 *((u_long*) p + 1) = 0;
608                 *((u_long*) p + 2) = 0;
609                 *((u_long*) p + 3) = 0;
610                 len -= sizeof(u_long) * 8;
611                 *((u_long*) p + 4) = 0;
612                 *((u_long*) p + 5) = 0;
613                 *((u_long*) p + 6) = 0;
614                 *((u_long*) p + 7) = 0;
615                 p += sizeof(u_long) * 8;
616         }
617
618         while (len >= sizeof(u_long)) {
619                 *(u_long*) p = 0;
620                 len -= sizeof(u_long);
621                 p += sizeof(u_long);
622         }
623
624         while (len) {
625                 *p++ = 0;
626                 len--;
627         }
628 }
629
630 void
631 cpu_boot(int howto)
632 {
633 }
634
635 /*
636  * Flush the D-cache for non-DMA I/O so that the I-cache can
637  * be made coherent later.
638  */
639 void
640 cpu_flush_dcache(void *ptr, size_t len)
641 {
642         /* TBD */
643 }
644
645 void
646 cpu_initclocks(void)
647 {
648
649         decr_tc_init();
650         cpu_initclocks_bsp();
651 }
652
653 /*
654  * Shutdown the CPU as much as possible.
655  */
656 void
657 cpu_halt(void)
658 {
659
660         OF_exit();
661 }
662
663 int
664 ptrace_set_pc(struct thread *td, unsigned long addr)
665 {
666         struct trapframe *tf;
667
668         tf = td->td_frame;
669         tf->srr0 = (register_t)addr;
670
671         return (0);
672 }
673
674 int
675 ptrace_single_step(struct thread *td)
676 {
677         struct trapframe *tf;
678         
679         tf = td->td_frame;
680         tf->srr1 |= PSL_SE;
681
682         return (0);
683 }
684
685 int
686 ptrace_clear_single_step(struct thread *td)
687 {
688         struct trapframe *tf;
689
690         tf = td->td_frame;
691         tf->srr1 &= ~PSL_SE;
692
693         return (0);
694 }
695
696 void
697 kdb_cpu_clear_singlestep(void)
698 {
699
700         kdb_frame->srr1 &= ~PSL_SE;
701 }
702
703 void
704 kdb_cpu_set_singlestep(void)
705 {
706
707         kdb_frame->srr1 |= PSL_SE;
708 }
709
710 /*
711  * Initialise a struct pcpu.
712  */
713 void
714 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
715 {
716 #ifdef __powerpc64__
717 /* Copy the SLB contents from the current CPU */
718 memcpy(pcpu->pc_slb, PCPU_GET(slb), sizeof(pcpu->pc_slb));
719 #endif
720 }
721
722 void
723 spinlock_enter(void)
724 {
725         struct thread *td;
726         register_t msr;
727
728         td = curthread;
729         if (td->td_md.md_spinlock_count == 0) {
730                 msr = intr_disable();
731                 td->td_md.md_spinlock_count = 1;
732                 td->td_md.md_saved_msr = msr;
733         } else
734                 td->td_md.md_spinlock_count++;
735         critical_enter();
736 }
737
738 void
739 spinlock_exit(void)
740 {
741         struct thread *td;
742         register_t msr;
743
744         td = curthread;
745         critical_exit();
746         msr = td->td_md.md_saved_msr;
747         td->td_md.md_spinlock_count--;
748         if (td->td_md.md_spinlock_count == 0)
749                 intr_restore(msr);
750 }
751
752 int db_trap_glue(struct trapframe *);           /* Called from trap_subr.S */
753
754 int
755 db_trap_glue(struct trapframe *frame)
756 {
757         if (!(frame->srr1 & PSL_PR)
758             && (frame->exc == EXC_TRC || frame->exc == EXC_RUNMODETRC
759                 || (frame->exc == EXC_PGM
760                     && (frame->srr1 & 0x20000))
761                 || frame->exc == EXC_BPT
762                 || frame->exc == EXC_DSI)) {
763                 int type = frame->exc;
764                 if (type == EXC_PGM && (frame->srr1 & 0x20000)) {
765                         type = T_BREAKPOINT;
766                 }
767                 return (kdb_trap(type, 0, frame));
768         }
769
770         return (0);
771 }
772
773 #ifndef __powerpc64__
774
775 uint64_t
776 va_to_vsid(pmap_t pm, vm_offset_t va)
777 {
778         return ((pm->pm_sr[(uintptr_t)va >> ADDR_SR_SHFT]) & SR_VSID_MASK);
779 }
780
781 #endif