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