]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/powerpc/aim/machdep.c
Merge mandoc from vendor into contrib and provide the necessary Makefile glue.
[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;
262 #ifdef WII
263         register_t      vers;
264 #endif
265         uint8_t         *cache_check;
266         int             cacheline_warn;
267         #ifndef __powerpc64__
268         int             ppc64;
269         #endif
270
271         kmdp = NULL;
272         trap_offset = 0;
273         cacheline_warn = 0;
274
275 #ifdef WII
276         /*
277          * The Wii loader doesn't pass us any environment so, mdp
278          * points to garbage at this point. The Wii CPU is a 750CL.
279          */
280         vers = mfpvr();
281         if ((vers & 0xfffff0e0) == (MPC750 << 16 | MPC750CL)) 
282                 mdp = NULL;
283 #endif
284
285         /*
286          * Parse metadata if present and fetch parameters.  Must be done
287          * before console is inited so cninit gets the right value of
288          * boothowto.
289          */
290         if (mdp != NULL) {
291                 preload_metadata = mdp;
292                 kmdp = preload_search_by_type("elf kernel");
293                 if (kmdp != NULL) {
294                         boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
295                         kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
296                         endkernel = ulmax(endkernel, MD_FETCH(kmdp,
297                             MODINFOMD_KERNEND, vm_offset_t));
298 #ifdef DDB
299                         ksym_start = MD_FETCH(kmdp, MODINFOMD_SSYM, uintptr_t);
300                         ksym_end = MD_FETCH(kmdp, MODINFOMD_ESYM, uintptr_t);
301 #endif
302                 }
303         }
304
305         /*
306          * Init params/tunables that can be overridden by the loader
307          */
308         init_param1();
309
310         /*
311          * Start initializing proc0 and thread0.
312          */
313         proc_linkup0(&proc0, &thread0);
314         thread0.td_frame = &frame0;
315
316         /*
317          * Set up per-cpu data.
318          */
319         pc = __pcpu;
320         pcpu_init(pc, 0, sizeof(struct pcpu));
321         pc->pc_curthread = &thread0;
322 #ifdef __powerpc64__
323         __asm __volatile("mr 13,%0" :: "r"(pc->pc_curthread));
324 #else
325         __asm __volatile("mr 2,%0" :: "r"(pc->pc_curthread));
326 #endif
327         pc->pc_cpuid = 0;
328
329         __asm __volatile("mtsprg 0, %0" :: "r"(pc));
330
331         /*
332          * Init mutexes, which we use heavily in PMAP
333          */
334
335         mutex_init();
336
337         /*
338          * Install the OF client interface
339          */
340
341         OF_bootstrap();
342
343         /*
344          * Initialize the console before printing anything.
345          */
346         cninit();
347
348         /*
349          * Complain if there is no metadata.
350          */
351         if (mdp == NULL || kmdp == NULL) {
352                 printf("powerpc_init: no loader metadata.\n");
353         }
354
355         /*
356          * Init KDB
357          */
358
359         kdb_init();
360
361         /* Various very early CPU fix ups */
362         switch (mfpvr() >> 16) {
363                 /*
364                  * PowerPC 970 CPUs have a misfeature requested by Apple that
365                  * makes them pretend they have a 32-byte cacheline. Turn this
366                  * off before we measure the cacheline size.
367                  */
368                 case IBM970:
369                 case IBM970FX:
370                 case IBM970MP:
371                 case IBM970GX:
372                         scratch = mfspr(SPR_HID5);
373                         scratch &= ~HID5_970_DCBZ_SIZE_HI;
374                         mtspr(SPR_HID5, scratch);
375                         break;
376         #ifdef __powerpc64__
377                 case IBMPOWER7:
378                         /* XXX: get from ibm,slb-size in device tree */
379                         n_slbs = 32;
380                         break;
381         #endif
382         }
383
384         /*
385          * Initialize the interrupt tables and figure out our cache line
386          * size and whether or not we need the 64-bit bridge code.
387          */
388
389         /*
390          * Disable translation in case the vector area hasn't been
391          * mapped (G5). Note that no OFW calls can be made until
392          * translation is re-enabled.
393          */
394
395         msr = mfmsr();
396         mtmsr((msr & ~(PSL_IR | PSL_DR)) | PSL_RI);
397
398         /*
399          * Measure the cacheline size using dcbz
400          *
401          * Use EXC_PGM as a playground. We are about to overwrite it
402          * anyway, we know it exists, and we know it is cache-aligned.
403          */
404
405         cache_check = (void *)EXC_PGM;
406
407         for (cacheline_size = 0; cacheline_size < 0x100; cacheline_size++)
408                 cache_check[cacheline_size] = 0xff;
409
410         __asm __volatile("dcbz 0,%0":: "r" (cache_check) : "memory");
411
412         /* Find the first byte dcbz did not zero to get the cache line size */
413         for (cacheline_size = 0; cacheline_size < 0x100 &&
414             cache_check[cacheline_size] == 0; cacheline_size++);
415
416         /* Work around psim bug */
417         if (cacheline_size == 0) {
418                 cacheline_warn = 1;
419                 cacheline_size = 32;
420         }
421
422         /* Make sure the kernel icache is valid before we go too much further */
423         __syncicache((caddr_t)startkernel, endkernel - startkernel);
424
425         #ifndef __powerpc64__
426         /*
427          * Figure out whether we need to use the 64 bit PMAP. This works by
428          * executing an instruction that is only legal on 64-bit PPC (mtmsrd),
429          * and setting ppc64 = 0 if that causes a trap.
430          */
431
432         ppc64 = 1;
433
434         bcopy(&testppc64, (void *)EXC_PGM,  (size_t)&testppc64size);
435         __syncicache((void *)EXC_PGM, (size_t)&testppc64size);
436
437         __asm __volatile("\
438                 mfmsr %0;       \
439                 mtsprg2 %1;     \
440                                 \
441                 mtmsrd %0;      \
442                 mfsprg2 %1;"
443             : "=r"(scratch), "=r"(ppc64));
444
445         if (ppc64)
446                 cpu_features |= PPC_FEATURE_64;
447
448         /*
449          * Now copy restorebridge into all the handlers, if necessary,
450          * and set up the trap tables.
451          */
452
453         if (cpu_features & PPC_FEATURE_64) {
454                 /* Patch the two instances of rfi -> rfid */
455                 bcopy(&rfid_patch,&rfi_patch1,4);
456         #ifdef KDB
457                 /* rfi_patch2 is at the end of dbleave */
458                 bcopy(&rfid_patch,&rfi_patch2,4);
459         #endif
460
461                 /*
462                  * Copy a code snippet to restore 32-bit bridge mode
463                  * to the top of every non-generic trap handler
464                  */
465
466                 trap_offset += (size_t)&restorebridgesize;
467                 bcopy(&restorebridge, (void *)EXC_RST, trap_offset); 
468                 bcopy(&restorebridge, (void *)EXC_DSI, trap_offset); 
469                 bcopy(&restorebridge, (void *)EXC_ALI, trap_offset); 
470                 bcopy(&restorebridge, (void *)EXC_PGM, trap_offset); 
471                 bcopy(&restorebridge, (void *)EXC_MCHK, trap_offset); 
472                 bcopy(&restorebridge, (void *)EXC_TRC, trap_offset); 
473                 bcopy(&restorebridge, (void *)EXC_BPT, trap_offset); 
474
475                 /*
476                  * Set the common trap entry point to the one that
477                  * knows to restore 32-bit operation on execution.
478                  */
479
480                 generictrap = &trapcode64;
481         } else {
482                 generictrap = &trapcode;
483         }
484
485         #else /* powerpc64 */
486         cpu_features |= PPC_FEATURE_64;
487         generictrap = &trapcode;
488         #endif
489
490 #ifdef SMP
491         bcopy(&rstcode, (void *)(EXC_RST + trap_offset),  (size_t)&rstsize);
492 #else
493         bcopy(generictrap, (void *)EXC_RST,  (size_t)&trapsize);
494 #endif
495
496 #ifdef KDB
497         bcopy(&dblow,   (void *)(EXC_MCHK + trap_offset), (size_t)&dbsize);
498         bcopy(&dblow,   (void *)(EXC_PGM + trap_offset),  (size_t)&dbsize);
499         bcopy(&dblow,   (void *)(EXC_TRC + trap_offset),  (size_t)&dbsize);
500         bcopy(&dblow,   (void *)(EXC_BPT + trap_offset),  (size_t)&dbsize);
501 #else
502         bcopy(generictrap, (void *)EXC_MCHK, (size_t)&trapsize);
503         bcopy(generictrap, (void *)EXC_PGM,  (size_t)&trapsize);
504         bcopy(generictrap, (void *)EXC_TRC,  (size_t)&trapsize);
505         bcopy(generictrap, (void *)EXC_BPT,  (size_t)&trapsize);
506 #endif
507         bcopy(&alitrap,  (void *)(EXC_ALI + trap_offset),  (size_t)&alisize);
508         bcopy(&dsitrap,  (void *)(EXC_DSI + trap_offset),  (size_t)&dsisize);
509         bcopy(generictrap, (void *)EXC_ISI,  (size_t)&trapsize);
510         #ifdef __powerpc64__
511         bcopy(&slbtrap, (void *)EXC_DSE,  (size_t)&slbtrapsize);
512         bcopy(&slbtrap, (void *)EXC_ISE,  (size_t)&slbtrapsize);
513         #endif
514         bcopy(generictrap, (void *)EXC_EXI,  (size_t)&trapsize);
515         bcopy(generictrap, (void *)EXC_FPU,  (size_t)&trapsize);
516         bcopy(generictrap, (void *)EXC_DECR, (size_t)&trapsize);
517         bcopy(generictrap, (void *)EXC_SC,   (size_t)&trapsize);
518         bcopy(generictrap, (void *)EXC_FPA,  (size_t)&trapsize);
519         bcopy(generictrap, (void *)EXC_VEC,  (size_t)&trapsize);
520         bcopy(generictrap, (void *)EXC_PERF,  (size_t)&trapsize);
521         bcopy(generictrap, (void *)EXC_VECAST_G4, (size_t)&trapsize);
522         bcopy(generictrap, (void *)EXC_VECAST_G5, (size_t)&trapsize);
523         #ifndef __powerpc64__
524         /* G2-specific TLB miss helper handlers */
525         bcopy(&imisstrap, (void *)EXC_IMISS,  (size_t)&imisssize);
526         bcopy(&dlmisstrap, (void *)EXC_DLMISS,  (size_t)&dlmisssize);
527         bcopy(&dsmisstrap, (void *)EXC_DSMISS,  (size_t)&dsmisssize);
528         #endif
529         __syncicache(EXC_RSVD, EXC_LAST - EXC_RSVD);
530
531         /*
532          * Restore MSR
533          */
534         mtmsr(msr);
535         
536         /* Warn if cachline size was not determined */
537         if (cacheline_warn == 1) {
538                 printf("WARNING: cacheline size undetermined, setting to 32\n");
539         }
540
541         /*
542          * Choose a platform module so we can get the physical memory map.
543          */
544         
545         platform_probe_and_attach();
546
547         /*
548          * Initialise virtual memory. Use BUS_PROBE_GENERIC priority
549          * in case the platform module had a better idea of what we
550          * should do.
551          */
552         if (cpu_features & PPC_FEATURE_64)
553                 pmap_mmu_install(MMU_TYPE_G5, BUS_PROBE_GENERIC);
554         else
555                 pmap_mmu_install(MMU_TYPE_OEA, BUS_PROBE_GENERIC);
556
557         pmap_bootstrap(startkernel, endkernel);
558         mtmsr(PSL_KERNSET & ~PSL_EE);
559
560         /*
561          * Initialize params/tunables that are derived from memsize
562          */
563         init_param2(physmem);
564
565         /*
566          * Grab booted kernel's name
567          */
568         env = getenv("kernelname");
569         if (env != NULL) {
570                 strlcpy(kernelname, env, sizeof(kernelname));
571                 freeenv(env);
572         }
573
574         /*
575          * Finish setting up thread0.
576          */
577         thread0.td_pcb = (struct pcb *)
578             ((thread0.td_kstack + thread0.td_kstack_pages * PAGE_SIZE -
579             sizeof(struct pcb)) & ~15UL);
580         bzero((void *)thread0.td_pcb, sizeof(struct pcb));
581         pc->pc_curpcb = thread0.td_pcb;
582
583         /* Initialise the message buffer. */
584         msgbufinit(msgbufp, msgbufsize);
585
586 #ifdef KDB
587         if (boothowto & RB_KDB)
588                 kdb_enter(KDB_WHY_BOOTFLAGS,
589                     "Boot flags requested debugger");
590 #endif
591
592         return (((uintptr_t)thread0.td_pcb -
593             (sizeof(struct callframe) - 3*sizeof(register_t))) & ~15UL);
594 }
595
596 void
597 bzero(void *buf, size_t len)
598 {
599         caddr_t p;
600
601         p = buf;
602
603         while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) {
604                 *p++ = 0;
605                 len--;
606         }
607
608         while (len >= sizeof(u_long) * 8) {
609                 *(u_long*) p = 0;
610                 *((u_long*) p + 1) = 0;
611                 *((u_long*) p + 2) = 0;
612                 *((u_long*) p + 3) = 0;
613                 len -= sizeof(u_long) * 8;
614                 *((u_long*) p + 4) = 0;
615                 *((u_long*) p + 5) = 0;
616                 *((u_long*) p + 6) = 0;
617                 *((u_long*) p + 7) = 0;
618                 p += sizeof(u_long) * 8;
619         }
620
621         while (len >= sizeof(u_long)) {
622                 *(u_long*) p = 0;
623                 len -= sizeof(u_long);
624                 p += sizeof(u_long);
625         }
626
627         while (len) {
628                 *p++ = 0;
629                 len--;
630         }
631 }
632
633 void
634 cpu_boot(int howto)
635 {
636 }
637
638 /*
639  * Flush the D-cache for non-DMA I/O so that the I-cache can
640  * be made coherent later.
641  */
642 void
643 cpu_flush_dcache(void *ptr, size_t len)
644 {
645         /* TBD */
646 }
647
648 void
649 cpu_initclocks(void)
650 {
651
652         decr_tc_init();
653         cpu_initclocks_bsp();
654 }
655
656 /*
657  * Shutdown the CPU as much as possible.
658  */
659 void
660 cpu_halt(void)
661 {
662
663         OF_exit();
664 }
665
666 int
667 ptrace_set_pc(struct thread *td, unsigned long addr)
668 {
669         struct trapframe *tf;
670
671         tf = td->td_frame;
672         tf->srr0 = (register_t)addr;
673
674         return (0);
675 }
676
677 int
678 ptrace_single_step(struct thread *td)
679 {
680         struct trapframe *tf;
681         
682         tf = td->td_frame;
683         tf->srr1 |= PSL_SE;
684
685         return (0);
686 }
687
688 int
689 ptrace_clear_single_step(struct thread *td)
690 {
691         struct trapframe *tf;
692
693         tf = td->td_frame;
694         tf->srr1 &= ~PSL_SE;
695
696         return (0);
697 }
698
699 void
700 kdb_cpu_clear_singlestep(void)
701 {
702
703         kdb_frame->srr1 &= ~PSL_SE;
704 }
705
706 void
707 kdb_cpu_set_singlestep(void)
708 {
709
710         kdb_frame->srr1 |= PSL_SE;
711 }
712
713 /*
714  * Initialise a struct pcpu.
715  */
716 void
717 cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
718 {
719 #ifdef __powerpc64__
720 /* Copy the SLB contents from the current CPU */
721 memcpy(pcpu->pc_slb, PCPU_GET(slb), sizeof(pcpu->pc_slb));
722 #endif
723 }
724
725 void
726 spinlock_enter(void)
727 {
728         struct thread *td;
729         register_t msr;
730
731         td = curthread;
732         if (td->td_md.md_spinlock_count == 0) {
733                 msr = intr_disable();
734                 td->td_md.md_spinlock_count = 1;
735                 td->td_md.md_saved_msr = msr;
736         } else
737                 td->td_md.md_spinlock_count++;
738         critical_enter();
739 }
740
741 void
742 spinlock_exit(void)
743 {
744         struct thread *td;
745         register_t msr;
746
747         td = curthread;
748         critical_exit();
749         msr = td->td_md.md_saved_msr;
750         td->td_md.md_spinlock_count--;
751         if (td->td_md.md_spinlock_count == 0)
752                 intr_restore(msr);
753 }
754
755 int db_trap_glue(struct trapframe *);           /* Called from trap_subr.S */
756
757 int
758 db_trap_glue(struct trapframe *frame)
759 {
760         if (!(frame->srr1 & PSL_PR)
761             && (frame->exc == EXC_TRC || frame->exc == EXC_RUNMODETRC
762                 || (frame->exc == EXC_PGM
763                     && (frame->srr1 & 0x20000))
764                 || frame->exc == EXC_BPT
765                 || frame->exc == EXC_DSI)) {
766                 int type = frame->exc;
767                 if (type == EXC_PGM && (frame->srr1 & 0x20000)) {
768                         type = T_BREAKPOINT;
769                 }
770                 return (kdb_trap(type, 0, frame));
771         }
772
773         return (0);
774 }
775
776 #ifndef __powerpc64__
777
778 uint64_t
779 va_to_vsid(pmap_t pm, vm_offset_t va)
780 {
781         return ((pm->pm_sr[(uintptr_t)va >> ADDR_SR_SHFT]) & SR_VSID_MASK);
782 }
783
784 #endif