machdep.c revision 176928
1176771Sraj/*-
2176771Sraj * Copyright (C) 2006 Semihalf, Marian Balakowicz <m8@semihalf.com>
3176771Sraj * All rights reserved.
4176771Sraj *
5176771Sraj * Redistribution and use in source and binary forms, with or without
6176771Sraj * modification, are permitted provided that the following conditions
7176771Sraj * are met:
8176771Sraj * 1. Redistributions of source code must retain the above copyright
9176771Sraj *    notice, this list of conditions and the following disclaimer.
10176771Sraj * 2. Redistributions in binary form must reproduce the above copyright
11176771Sraj *    notice, this list of conditions and the following disclaimer in the
12176771Sraj *    documentation and/or other materials provided with the distribution.
13176771Sraj * 3. The name of the author may not be used to endorse or promote products
14176771Sraj *    derived from this software without specific prior written permission.
15176771Sraj *
16176771Sraj * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17176771Sraj * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18176771Sraj * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
19176771Sraj * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20176771Sraj * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21176771Sraj * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22176771Sraj * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23176771Sraj * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24176771Sraj * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25176771Sraj * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26176771Sraj */
27176771Sraj/*-
28176771Sraj * Copyright (C) 2001 Benno Rice
29176771Sraj * All rights reserved.
30176771Sraj *
31176771Sraj * Redistribution and use in source and binary forms, with or without
32176771Sraj * modification, are permitted provided that the following conditions
33176771Sraj * are met:
34176771Sraj * 1. Redistributions of source code must retain the above copyright
35176771Sraj *    notice, this list of conditions and the following disclaimer.
36176771Sraj * 2. Redistributions in binary form must reproduce the above copyright
37176771Sraj *    notice, this list of conditions and the following disclaimer in the
38176771Sraj *    documentation and/or other materials provided with the distribution.
39176771Sraj *
40176771Sraj * THIS SOFTWARE IS PROVIDED BY Benno Rice ``AS IS'' AND ANY EXPRESS OR
41176771Sraj * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42176771Sraj * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
43176771Sraj * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44176771Sraj * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
45176771Sraj * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
46176771Sraj * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
47176771Sraj * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
48176771Sraj * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
49176771Sraj * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50176771Sraj * $NetBSD: machdep.c,v 1.74.2.1 2000/11/01 16:13:48 tv Exp $
51176771Sraj */
52176771Sraj/*-
53176771Sraj * Copyright (C) 1995, 1996 Wolfgang Solfrank.
54176771Sraj * Copyright (C) 1995, 1996 TooLs GmbH.
55176771Sraj * All rights reserved.
56176771Sraj *
57176771Sraj * Redistribution and use in source and binary forms, with or without
58176771Sraj * modification, are permitted provided that the following conditions
59176771Sraj * are met:
60176771Sraj * 1. Redistributions of source code must retain the above copyright
61176771Sraj *    notice, this list of conditions and the following disclaimer.
62176771Sraj * 2. Redistributions in binary form must reproduce the above copyright
63176771Sraj *    notice, this list of conditions and the following disclaimer in the
64176771Sraj *    documentation and/or other materials provided with the distribution.
65176771Sraj * 3. All advertising materials mentioning features or use of this software
66176771Sraj *    must display the following acknowledgement:
67176771Sraj *      This product includes software developed by TooLs GmbH.
68176771Sraj * 4. The name of TooLs GmbH may not be used to endorse or promote products
69176771Sraj *    derived from this software without specific prior written permission.
70176771Sraj *
71176771Sraj * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
72176771Sraj * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
73176771Sraj * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
74176771Sraj * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
75176771Sraj * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
76176771Sraj * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
77176771Sraj * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
78176771Sraj * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
79176771Sraj * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
80176771Sraj * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
81176771Sraj */
82176771Sraj
83176771Sraj#include <sys/cdefs.h>
84176771Sraj__FBSDID("$FreeBSD: head/sys/powerpc/booke/machdep.c 176928 2008-03-08 05:36:25Z marcel $");
85176771Sraj
86176771Sraj#include "opt_compat.h"
87176771Sraj#include "opt_kstack_pages.h"
88176771Sraj
89176771Sraj#include <sys/cdefs.h>
90176771Sraj#include <sys/types.h>
91176771Sraj
92176771Sraj#include <sys/param.h>
93176771Sraj#include <sys/proc.h>
94176771Sraj#include <sys/systm.h>
95176771Sraj#include <sys/time.h>
96176771Sraj#include <sys/bio.h>
97176771Sraj#include <sys/buf.h>
98176771Sraj#include <sys/bus.h>
99176771Sraj#include <sys/cons.h>
100176771Sraj#include <sys/cpu.h>
101176771Sraj#include <sys/kdb.h>
102176771Sraj#include <sys/kernel.h>
103176771Sraj#include <sys/lock.h>
104176771Sraj#include <sys/mutex.h>
105176771Sraj#include <sys/sysctl.h>
106176771Sraj#include <sys/exec.h>
107176771Sraj#include <sys/ktr.h>
108176771Sraj#include <sys/sysproto.h>
109176771Sraj#include <sys/signalvar.h>
110176771Sraj#include <sys/sysent.h>
111176771Sraj#include <sys/imgact.h>
112176771Sraj#include <sys/msgbuf.h>
113176771Sraj#include <sys/ptrace.h>
114176771Sraj
115176771Sraj#include <vm/vm.h>
116176771Sraj#include <vm/pmap.h>
117176771Sraj#include <vm/vm_page.h>
118176771Sraj#include <vm/vm_object.h>
119176771Sraj#include <vm/vm_pager.h>
120176771Sraj
121176771Sraj#include <machine/cpu.h>
122176771Sraj#include <machine/kdb.h>
123176771Sraj#include <machine/reg.h>
124176771Sraj#include <machine/vmparam.h>
125176771Sraj#include <machine/spr.h>
126176771Sraj#include <machine/hid.h>
127176771Sraj#include <machine/psl.h>
128176771Sraj#include <machine/trap.h>
129176771Sraj#include <machine/md_var.h>
130176771Sraj#include <machine/mmuvar.h>
131176771Sraj#include <machine/pmap.h>
132176771Sraj#include <machine/sigframe.h>
133176771Sraj#include <machine/metadata.h>
134176771Sraj#include <machine/bootinfo.h>
135176771Sraj#include <machine/powerpc.h>
136176771Sraj
137176771Sraj#include <sys/linker.h>
138176771Sraj#include <sys/reboot.h>
139176771Sraj
140176771Sraj#ifdef  DEBUG
141176771Sraj#define debugf(fmt, args...) printf(fmt, ##args)
142176771Sraj#else
143176771Sraj#define debugf(fmt, args...)
144176771Sraj#endif
145176771Sraj
146176771Srajextern unsigned char kernel_text[];
147176771Srajextern unsigned char _etext[];
148176771Srajextern unsigned char _edata[];
149176771Srajextern unsigned char __bss_start[];
150176771Srajextern unsigned char __sbss_start[];
151176771Srajextern unsigned char __sbss_end[];
152176771Srajextern unsigned char _end[];
153176771Sraj
154176771Srajextern struct mem_region availmem_regions[];
155176771Srajextern int availmem_regions_sz;
156176771Sraj
157176771Srajextern void *trapcode, *trapsize;
158176771Sraj
159176771Srajextern unsigned char kstack0_space[];
160176771Sraj
161176928Smarcelextern void dcache_enable(void);
162176928Smarcelextern void dcache_inval(void);
163176928Smarcelextern void icache_enable(void);
164176928Smarcelextern void icache_inval(void);
165176928Smarcel
166176771Srajstruct kva_md_info kmi;
167176771Srajstruct pcpu __pcpu[MAXCPU];
168176771Srajstruct trapframe frame0;
169176771Srajint cold = 1;
170176771Srajlong realmem = 0;
171176771Srajlong Maxmem = 0;
172176771Sraj
173176771Srajstruct bootinfo *bootinfo;
174176771Sraj
175176771Srajchar machine[] = "powerpc";
176176771SrajSYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
177176771Sraj
178176771Srajstatic int cacheline_size = CACHELINESIZE;
179176771SrajSYSCTL_INT(_machdep, CPU_CACHELINE, cacheline_size,
180176771Sraj    CTLFLAG_RD, &cacheline_size, 0, "");
181176771Sraj
182176771Srajstatic void cpu_e500_startup(void *);
183176771SrajSYSINIT(cpu, SI_SUB_CPU, SI_ORDER_FIRST, cpu_e500_startup, NULL)
184176771Sraj
185176771Srajvoid print_kernel_section_addr(void);
186176771Srajvoid dump_bootinfo(void);
187176771Srajvoid dump_kenv(void);
188176771Srajvoid e500_init(u_int32_t, u_int32_t, void *);
189176771Srajvoid setPQL2(int *const size, int *const ways);
190176771Sraj
191176771Srajvoid
192176771SrajsetPQL2(int *const size, int *const ways)
193176771Sraj{
194176771Sraj
195176771Sraj	return;
196176771Sraj}
197176771Sraj
198176771Srajstatic void
199176771Srajcpu_e500_startup(void *dummy)
200176771Sraj{
201176771Sraj
202176771Sraj	/* Initialise the decrementer-based clock. */
203176771Sraj	decr_init();
204176771Sraj
205176771Sraj	/* Good {morning,afternoon,evening,night}. */
206176771Sraj	cpu_setup(PCPU_GET(cpuid));
207176771Sraj
208176771Sraj	printf("real memory  = %ld (%ld MB)\n", ptoa(physmem),
209176771Sraj			ptoa(physmem) / 1048576);
210176771Sraj	realmem = physmem;
211176771Sraj
212176771Sraj	/* Display any holes after the first chunk of extended memory. */
213176771Sraj	if (bootverbose) {
214176771Sraj		int indx;
215176771Sraj
216176771Sraj		printf("Physical memory chunk(s):\n");
217176771Sraj		for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
218176771Sraj			int size1 = phys_avail[indx + 1] - phys_avail[indx];
219176771Sraj
220176771Sraj			printf("0x%08x - 0x%08x, %d bytes (%d pages)\n",
221176771Sraj					phys_avail[indx], phys_avail[indx + 1] - 1, size1,
222176771Sraj					size1 / PAGE_SIZE);
223176771Sraj		}
224176771Sraj	}
225176771Sraj
226176771Sraj	vm_ksubmap_init(&kmi);
227176771Sraj
228176771Sraj	printf("avail memory = %ld (%ld MB)\n", ptoa(cnt.v_free_count),
229176771Sraj			ptoa(cnt.v_free_count) / 1048576);
230176771Sraj
231176771Sraj	/* Set up buffers, so they can be used to read disk labels. */
232176771Sraj	bufinit();
233176771Sraj	vm_pager_bufferinit();
234176771Sraj}
235176771Sraj
236176771Srajstatic char *
237176771Srajkenv_next(char *cp)
238176771Sraj{
239176771Sraj
240176771Sraj	if (cp != NULL) {
241176771Sraj		while (*cp != 0)
242176771Sraj			cp++;
243176771Sraj		cp++;
244176771Sraj		if (*cp == 0)
245176771Sraj			cp = NULL;
246176771Sraj	}
247176771Sraj	return (cp);
248176771Sraj}
249176771Sraj
250176771Srajvoid
251176771Srajdump_kenv(void)
252176771Sraj{
253176771Sraj	int len;
254176771Sraj	char *cp;
255176771Sraj
256176771Sraj	debugf("loader passed (static) kenv:\n");
257176771Sraj	if (kern_envp == NULL) {
258176771Sraj		debugf(" no env, null ptr\n");
259176771Sraj		return;
260176771Sraj	}
261176771Sraj	debugf(" kern_envp = 0x%08x\n", (u_int32_t)kern_envp);
262176771Sraj
263176771Sraj	len = 0;
264176771Sraj	for (cp = kern_envp; cp != NULL; cp = kenv_next(cp))
265176771Sraj		debugf(" %x %s\n", (u_int32_t)cp, cp);
266176771Sraj}
267176771Sraj
268176771Srajvoid
269176771Srajdump_bootinfo(void)
270176771Sraj{
271176771Sraj	struct bi_mem_region *mr;
272176771Sraj	struct bi_eth_addr *eth;
273176771Sraj	int i, j;
274176771Sraj
275176771Sraj	debugf("bootinfo:\n");
276176771Sraj	if (bootinfo == NULL) {
277176771Sraj		debugf(" no bootinfo, null ptr\n");
278176771Sraj		return;
279176771Sraj	}
280176771Sraj
281176771Sraj	debugf(" version = 0x%08x\n", bootinfo->bi_version);
282176771Sraj	debugf(" ccsrbar = 0x%08x\n", bootinfo->bi_bar_base);
283176771Sraj	debugf(" cpu_clk = 0x%08x\n", bootinfo->bi_cpu_clk);
284176771Sraj	debugf(" bus_clk = 0x%08x\n", bootinfo->bi_bus_clk);
285176771Sraj
286176771Sraj	debugf(" mem regions:\n");
287176771Sraj	mr = (struct bi_mem_region *)bootinfo->bi_data;
288176771Sraj	for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++)
289176771Sraj		debugf("    #%d, base = 0x%08x, size = 0x%08x\n", i,
290176771Sraj		    mr->mem_base, mr->mem_size);
291176771Sraj
292176771Sraj	debugf(" eth addresses:\n");
293176771Sraj	eth = (struct bi_eth_addr *)mr;
294176771Sraj	for (i = 0; i < bootinfo->bi_eth_addr_no; i++, eth++) {
295176771Sraj		debugf("    #%d, addr = ", i);
296176771Sraj		for (j = 0; j < 6; j++)
297176771Sraj			debugf("%02x ", eth->mac_addr[j]);
298176771Sraj		debugf("\n");
299176771Sraj	}
300176771Sraj}
301176771Sraj
302176771Srajvoid
303176771Srajprint_kernel_section_addr(void)
304176771Sraj{
305176771Sraj
306176771Sraj	debugf("kernel image addresses:\n");
307176771Sraj	debugf(" kernel_text    = 0x%08x\n", (u_int32_t)kernel_text);
308176771Sraj	debugf(" _etext (sdata) = 0x%08x\n", (u_int32_t)_etext);
309176771Sraj	debugf(" _edata         = 0x%08x\n", (u_int32_t)_edata);
310176771Sraj	debugf(" __sbss_start   = 0x%08x\n", (u_int32_t)__sbss_start);
311176771Sraj	debugf(" __sbss_end     = 0x%08x\n", (u_int32_t)__sbss_end);
312176771Sraj	debugf(" __sbss_start   = 0x%08x\n", (u_int32_t)__bss_start);
313176771Sraj	debugf(" _end           = 0x%08x\n", (u_int32_t)_end);
314176771Sraj}
315176771Sraj
316176771Srajvoid
317176771Sraje500_init(u_int32_t startkernel, u_int32_t endkernel, void *mdp)
318176771Sraj{
319176771Sraj	struct pcpu *pc;
320176771Sraj	void *kmdp;
321176771Sraj	vm_offset_t end;
322176771Sraj	struct bi_mem_region *mr;
323176928Smarcel	uint32_t csr;
324176771Sraj	int i;
325176771Sraj
326176771Sraj	kmdp = NULL;
327176771Sraj
328176771Sraj	end = endkernel;
329176771Sraj
330176771Sraj	/*
331176771Sraj	 * Parse metadata and fetch parameters. This must be done as the first
332176771Sraj	 * step as we need bootinfo data to at least init the console
333176771Sraj	 */
334176771Sraj	if (mdp != NULL) {
335176771Sraj		preload_metadata = mdp;
336176771Sraj		kmdp = preload_search_by_type("elf kernel");
337176771Sraj		if (kmdp != NULL) {
338176771Sraj			bootinfo = (struct bootinfo *)preload_search_info(kmdp,
339176771Sraj			    MODINFO_METADATA|MODINFOMD_BOOTINFO);
340176771Sraj
341176771Sraj			boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
342176771Sraj			kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
343176771Sraj			end = MD_FETCH(kmdp, MODINFOMD_KERNEND, vm_offset_t);
344176771Sraj		}
345176771Sraj	} else {
346176771Sraj		/*
347176771Sraj		 * We should scream but how? - without CCSR bar (in bootinfo)
348176771Sraj		 * cannot even output anything...
349176771Sraj		 */
350176771Sraj
351176771Sraj		 /*
352176771Sraj		  * FIXME add return value and handle in the locore so we can
353176771Sraj		  * return to the loader maybe? (this seems not very easy to
354176771Sraj		  * restore everything as the TLB have all been reprogrammed
355176771Sraj		  * in the locore etc...)
356176771Sraj		  */
357176771Sraj		while(1);
358176771Sraj	}
359176771Sraj
360176771Sraj	/* Initialize memory regions table */
361176771Sraj	mr = (struct bi_mem_region *)bootinfo->bi_data;
362176771Sraj	for (i = 0; i < bootinfo->bi_mem_reg_no; i++, mr++) {
363176771Sraj		if (i == MEM_REGIONS)
364176771Sraj			break;
365176771Sraj		availmem_regions[i].mr_start = mr->mem_base;
366176771Sraj		availmem_regions[i].mr_size = mr->mem_size;
367176771Sraj	}
368176771Sraj	availmem_regions_sz = i;
369176771Sraj
370176771Sraj	/* Initialize TLB1 handling */
371176771Sraj	tlb1_init(bootinfo->bi_bar_base);
372176771Sraj
373176771Sraj	/*
374176771Sraj	 * Time Base and Decrementer are updated every 8 CCB bus clocks.
375176771Sraj	 * HID0[SEL_TBCLK] = 0
376176771Sraj	 */
377176771Sraj	decr_config(bootinfo->bi_bus_clk/8);
378176771Sraj
379176771Sraj	/* Init params/tunables that can be overridden by the loader. */
380176771Sraj	init_param1();
381176771Sraj
382176771Sraj	/* Start initializing proc0 and thread0. */
383176771Sraj	proc_linkup(&proc0, &thread0);
384176771Sraj	thread0.td_frame = &frame0;
385176771Sraj
386176771Sraj	/* Set up per-cpu data and store the pointer in SPR general 0. */
387176771Sraj	pc = &__pcpu[0];
388176771Sraj	pcpu_init(pc, 0, sizeof(struct pcpu));
389176771Sraj	pc->pc_curthread = &thread0;
390176771Sraj	pc->pc_cpuid = 0;
391176771Sraj	__asm __volatile("mtsprg 0, %0" :: "r"(pc));
392176771Sraj
393176771Sraj	/* Initialize system mutexes. */
394176771Sraj	mutex_init();
395176771Sraj
396176771Sraj	/* Initialize the console before printing anything. */
397176771Sraj	cninit();
398176771Sraj
399176771Sraj	/* Print out some debug info... */
400176771Sraj	debugf("e500_init: console initialized\n");
401176771Sraj	debugf(" arg1 startkernel = 0x%08x\n", startkernel);
402176771Sraj	debugf(" arg2 endkernel = 0x%08x\n", endkernel);
403176771Sraj	debugf(" arg3 midp = 0x%08x\n", (u_int32_t)mdp);
404176771Sraj	debugf(" end = 0x%08x\n", (u_int32_t)end);
405176771Sraj	debugf(" boothowto = 0x%08x\n", boothowto);
406176771Sraj	debugf(" kernel ccsrbar = 0x%08x\n", CCSRBAR_VA);
407176771Sraj	debugf(" MSR = 0x%08x\n", mfmsr());
408176771Sraj	dump_bootinfo();
409176771Sraj	print_kernel_section_addr();
410176771Sraj	dump_kenv();
411176771Sraj	//tlb1_print_entries();
412176771Sraj	//tlb1_print_tlbentries();
413176771Sraj
414176771Sraj	kdb_init();
415176771Sraj
416176771Sraj#ifdef KDB
417176771Sraj	if (boothowto & RB_KDB)
418176771Sraj		kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
419176771Sraj#endif
420176771Sraj	kobj_machdep_init();
421176771Sraj
422176771Sraj	/* Initialise virtual memory. */
423176771Sraj	pmap_mmu_install(MMU_TYPE_BOOKE, 0);
424176771Sraj	pmap_bootstrap(startkernel, end);
425176771Sraj	debugf("MSR = 0x%08x\n", mfmsr());
426176771Sraj	//tlb1_print_entries();
427176771Sraj	//tlb1_print_tlbentries();
428176771Sraj
429176771Sraj	/* Initialize params/tunables that are derived from memsize. */
430176771Sraj	init_param2(physmem);
431176771Sraj
432176771Sraj	/* Finish setting up thread0. */
433176771Sraj	thread0.td_kstack = (vm_offset_t)kstack0_space;
434176771Sraj	thread0.td_pcb = (struct pcb *)
435176771Sraj	    (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
436176771Sraj	bzero((void *)thread0.td_pcb, sizeof(struct pcb));
437176771Sraj	pc->pc_curpcb = thread0.td_pcb;
438176771Sraj
439176771Sraj	/* Initialise the message buffer. */
440176771Sraj	msgbufinit(msgbufp, MSGBUF_SIZE);
441176771Sraj
442176771Sraj	/* Enable Machine Check interrupt. */
443176771Sraj	mtmsr(mfmsr() | PSL_ME);
444176771Sraj	isync();
445176771Sraj
446176928Smarcel	/* Enable D-cache if applicable */
447176928Smarcel	csr = mfspr(SPR_L1CSR0);
448176928Smarcel	if ((csr & L1CSR0_DCE) == 0) {
449176928Smarcel		dcache_inval();
450176928Smarcel		dcache_enable();
451176928Smarcel	}
452176928Smarcel	csr = mfspr(SPR_L1CSR0);
453176928Smarcel	if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR0_DCE) == 0)
454176928Smarcel		printf("L1 D-cache %sabled\n",
455176928Smarcel		    (csr & L1CSR0_DCE) ? "en" : "dis");
456176928Smarcel
457176928Smarcel	/* Enable L1 I-cache if applicable. */
458176928Smarcel	csr = mfspr(SPR_L1CSR1);
459176928Smarcel	if ((csr & L1CSR1_ICE) == 0) {
460176928Smarcel		icache_inval();
461176928Smarcel		icache_enable();
462176928Smarcel	}
463176928Smarcel	csr = mfspr(SPR_L1CSR1);
464176928Smarcel	if ((boothowto & RB_VERBOSE) != 0 || (csr & L1CSR1_ICE) == 0)
465176928Smarcel		printf("L1 I-cache %sabled\n",
466176928Smarcel		    (csr & L1CSR1_ICE) ? "en" : "dis");
467176928Smarcel
468176771Sraj	debugf("e500_init: e\n");
469176771Sraj}
470176771Sraj
471176771Sraj/* Initialise a struct pcpu. */
472176771Srajvoid
473176771Srajcpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t sz)
474176771Sraj{
475176771Sraj
476176771Sraj}
477176771Sraj
478176771Sraj/* Set set up registers on exec. */
479176771Srajvoid
480176771Srajexec_setregs(struct thread *td, u_long entry, u_long stack, u_long ps_strings)
481176771Sraj{
482176771Sraj	struct trapframe *tf;
483176771Sraj	struct ps_strings arginfo;
484176771Sraj
485176771Sraj	tf = trapframe(td);
486176771Sraj	bzero(tf, sizeof *tf);
487176771Sraj	tf->fixreg[1] = -roundup(-stack + 8, 16);
488176771Sraj
489176771Sraj	/*
490176771Sraj	 * XXX Machine-independent code has already copied arguments and
491176771Sraj	 * XXX environment to userland.  Get them back here.
492176771Sraj	 */
493176771Sraj	(void)copyin((char *)PS_STRINGS, &arginfo, sizeof(arginfo));
494176771Sraj
495176771Sraj	/*
496176771Sraj	 * Set up arguments for _start():
497176771Sraj	 *	_start(argc, argv, envp, obj, cleanup, ps_strings);
498176771Sraj	 *
499176771Sraj	 * Notes:
500176771Sraj	 *	- obj and cleanup are the auxilliary and termination
501176771Sraj	 *	  vectors.  They are fixed up by ld.elf_so.
502176771Sraj	 *	- ps_strings is a NetBSD extention, and will be
503176771Sraj	 * 	  ignored by executables which are strictly
504176771Sraj	 *	  compliant with the SVR4 ABI.
505176771Sraj	 *
506176771Sraj	 * XXX We have to set both regs and retval here due to different
507176771Sraj	 * XXX calling convention in trap.c and init_main.c.
508176771Sraj	 */
509176771Sraj	/*
510176771Sraj	 * XXX PG: these get overwritten in the syscall return code.
511176771Sraj	 * execve() should return EJUSTRETURN, like it does on NetBSD.
512176771Sraj	 * Emulate by setting the syscall return value cells. The
513176771Sraj	 * registers still have to be set for init's fork trampoline.
514176771Sraj	 */
515176771Sraj	td->td_retval[0] = arginfo.ps_nargvstr;
516176771Sraj	td->td_retval[1] = (register_t)arginfo.ps_argvstr;
517176771Sraj	tf->fixreg[3] = arginfo.ps_nargvstr;
518176771Sraj	tf->fixreg[4] = (register_t)arginfo.ps_argvstr;
519176771Sraj	tf->fixreg[5] = (register_t)arginfo.ps_envstr;
520176771Sraj	tf->fixreg[6] = 0;			/* auxillary vector */
521176771Sraj	tf->fixreg[7] = 0;			/* termination vector */
522176771Sraj	tf->fixreg[8] = (register_t)PS_STRINGS;	/* NetBSD extension */
523176771Sraj
524176771Sraj	tf->srr0 = entry;
525176771Sraj	tf->srr1 = PSL_USERSET;
526176771Sraj	td->td_pcb->pcb_flags = 0;
527176771Sraj}
528176771Sraj
529176771Srajint
530176771Srajfill_regs(struct thread *td, struct reg *regs)
531176771Sraj{
532176771Sraj	struct trapframe *tf;
533176771Sraj
534176771Sraj	tf = td->td_frame;
535176771Sraj	memcpy(regs, tf, sizeof(struct reg));
536176771Sraj
537176771Sraj	return (0);
538176771Sraj}
539176771Sraj
540176771Srajint
541176771Srajfill_fpregs(struct thread *td, struct fpreg *fpregs)
542176771Sraj{
543176771Sraj
544176771Sraj	return (0);
545176771Sraj}
546176771Sraj
547176771Sraj/* Get current clock frequency for the given cpu id. */
548176771Srajint
549176771Srajcpu_est_clockrate(int cpu_id, uint64_t *rate)
550176771Sraj{
551176771Sraj
552176771Sraj	return (ENXIO);
553176771Sraj}
554176771Sraj
555176771Sraj/*
556176771Sraj * Construct a PCB from a trapframe. This is called from kdb_trap() where
557176771Sraj * we want to start a backtrace from the function that caused us to enter
558176771Sraj * the debugger. We have the context in the trapframe, but base the trace
559176771Sraj * on the PCB. The PCB doesn't have to be perfect, as long as it contains
560176771Sraj * enough for a backtrace.
561176771Sraj */
562176771Srajvoid
563176771Srajmakectx(struct trapframe *tf, struct pcb *pcb)
564176771Sraj{
565176771Sraj
566176771Sraj	pcb->pcb_lr = tf->srr0;
567176771Sraj	pcb->pcb_sp = tf->fixreg[1];
568176771Sraj}
569176771Sraj
570176771Sraj/*
571176771Sraj * get_mcontext/sendsig helper routine that doesn't touch the
572176771Sraj * proc lock.
573176771Sraj */
574176771Srajstatic int
575176771Srajgrab_mcontext(struct thread *td, mcontext_t *mcp, int flags)
576176771Sraj{
577176771Sraj	struct pcb *pcb;
578176771Sraj
579176771Sraj	pcb = td->td_pcb;
580176771Sraj	memset(mcp, 0, sizeof(mcontext_t));
581176771Sraj
582176771Sraj	mcp->mc_vers = _MC_VERSION;
583176771Sraj	mcp->mc_flags = 0;
584176771Sraj	memcpy(&mcp->mc_frame, td->td_frame, sizeof(struct trapframe));
585176771Sraj	if (flags & GET_MC_CLEAR_RET) {
586176771Sraj		mcp->mc_gpr[3] = 0;
587176771Sraj		mcp->mc_gpr[4] = 0;
588176771Sraj	}
589176771Sraj
590176771Sraj	/* XXX Altivec context ? */
591176771Sraj
592176771Sraj	mcp->mc_len = sizeof(*mcp);
593176771Sraj	return (0);
594176771Sraj}
595176771Sraj
596176771Srajint
597176771Srajget_mcontext(struct thread *td, mcontext_t *mcp, int flags)
598176771Sraj{
599176771Sraj	int error;
600176771Sraj
601176771Sraj	error = grab_mcontext(td, mcp, flags);
602176771Sraj	if (error == 0) {
603176771Sraj		PROC_LOCK(curthread->td_proc);
604176771Sraj		mcp->mc_onstack = sigonstack(td->td_frame->fixreg[1]);
605176771Sraj		PROC_UNLOCK(curthread->td_proc);
606176771Sraj	}
607176771Sraj
608176771Sraj	return (error);
609176771Sraj}
610176771Sraj
611176771Srajint
612176771Srajset_mcontext(struct thread *td, const mcontext_t *mcp)
613176771Sraj{
614176771Sraj	struct pcb *pcb;
615176771Sraj	struct trapframe *tf;
616176771Sraj
617176771Sraj	pcb = td->td_pcb;
618176771Sraj	tf = td->td_frame;
619176771Sraj
620176771Sraj	if (mcp->mc_vers != _MC_VERSION || mcp->mc_len != sizeof(*mcp))
621176771Sraj		return (EINVAL);
622176771Sraj
623176771Sraj	memcpy(tf, mcp->mc_frame, sizeof(mcp->mc_frame));
624176771Sraj
625176771Sraj	/* XXX Altivec context? */
626176771Sraj
627176771Sraj	return (0);
628176771Sraj}
629176771Sraj
630176771Srajint
631176771Srajsigreturn(struct thread *td, struct sigreturn_args *uap)
632176771Sraj{
633176771Sraj	struct proc *p;
634176771Sraj	ucontext_t uc;
635176771Sraj	int error;
636176771Sraj
637176771Sraj	CTR2(KTR_SIG, "sigreturn: td=%p ucp=%p", td, uap->sigcntxp);
638176771Sraj
639176771Sraj	if (copyin(uap->sigcntxp, &uc, sizeof(uc)) != 0) {
640176771Sraj		CTR1(KTR_SIG, "sigreturn: efault td=%p", td);
641176771Sraj		return (EFAULT);
642176771Sraj	}
643176771Sraj
644176771Sraj	error = set_mcontext(td, &uc.uc_mcontext);
645176771Sraj	if (error != 0)
646176771Sraj		return (error);
647176771Sraj
648176771Sraj	p = td->td_proc;
649176771Sraj	PROC_LOCK(p);
650176771Sraj	td->td_sigmask = uc.uc_sigmask;
651176771Sraj	SIG_CANTMASK(td->td_sigmask);
652176771Sraj	signotify(td);
653176771Sraj	PROC_UNLOCK(p);
654176771Sraj
655176771Sraj	CTR3(KTR_SIG, "sigreturn: return td=%p pc=%#x sp=%#x",
656176771Sraj	    td, uc.uc_mcontext.mc_srr0, uc.uc_mcontext.mc_gpr[1]);
657176771Sraj
658176771Sraj	return (EJUSTRETURN);
659176771Sraj}
660176771Sraj
661176771Sraj#ifdef COMPAT_FREEBSD4
662176771Srajint
663176771Srajfreebsd4_sigreturn(struct thread *td, struct freebsd4_sigreturn_args *uap)
664176771Sraj{
665176771Sraj
666176771Sraj	return sigreturn(td, (struct sigreturn_args *)uap);
667176771Sraj}
668176771Sraj#endif
669176771Sraj
670176771Sraj/*
671176771Sraj * cpu_idle
672176771Sraj *
673176771Sraj * Set Wait state enable.
674176771Sraj */
675176771Srajvoid
676176771Srajcpu_idle (void)
677176771Sraj{
678176771Sraj	register_t msr;
679176771Sraj
680176771Sraj	msr = mfmsr();
681176771Sraj#ifdef INVARIANTS
682176771Sraj	if ((msr & PSL_EE) != PSL_EE) {
683176771Sraj		struct thread *td = curthread;
684176771Sraj		printf("td msr %x\n", td->td_md.md_saved_msr);
685176771Sraj		panic("ints disabled in idleproc!");
686176771Sraj	}
687176771Sraj#endif
688176771Sraj#if 0
689176771Sraj	/*
690176771Sraj	 * Freescale E500 core RM section 6.4.1
691176771Sraj	 */
692176771Sraj	msr = msr | PSL_WE;
693176771Sraj
694176771Sraj	__asm__("	msync;"
695176771Sraj		"	mtmsr	%0;"
696176771Sraj		"	isync;"
697176771Sraj		"loop:	b	loop" :
698176771Sraj		/* no output */	:
699176771Sraj		"r" (msr));
700176771Sraj#endif
701176771Sraj}
702176771Sraj
703176771Srajvoid
704176771Srajspinlock_enter(void)
705176771Sraj{
706176771Sraj	struct thread *td;
707176771Sraj
708176771Sraj	td = curthread;
709176771Sraj	if (td->td_md.md_spinlock_count == 0)
710176771Sraj		td->td_md.md_saved_msr = intr_disable();
711176771Sraj	td->td_md.md_spinlock_count++;
712176771Sraj	critical_enter();
713176771Sraj}
714176771Sraj
715176771Srajvoid
716176771Srajspinlock_exit(void)
717176771Sraj{
718176771Sraj	struct thread *td;
719176771Sraj
720176771Sraj	td = curthread;
721176771Sraj	critical_exit();
722176771Sraj	td->td_md.md_spinlock_count--;
723176771Sraj	if (td->td_md.md_spinlock_count == 0)
724176771Sraj		intr_restore(td->td_md.md_saved_msr);
725176771Sraj}
726176771Sraj
727176771Sraj/* Shutdown the CPU as much as possible. */
728176771Srajvoid
729176771Srajcpu_halt(void)
730176771Sraj{
731176771Sraj
732176771Sraj	mtmsr(mfmsr() & ~(PSL_CE | PSL_EE | PSL_ME | PSL_DE));
733176771Sraj	while (1);
734176771Sraj}
735176771Sraj
736176771Srajint
737176771Srajset_regs(struct thread *td, struct reg *regs)
738176771Sraj{
739176771Sraj	struct trapframe *tf;
740176771Sraj
741176771Sraj	tf = td->td_frame;
742176771Sraj	memcpy(tf, regs, sizeof(struct reg));
743176771Sraj	return (0);
744176771Sraj}
745176771Sraj
746176771Srajint
747176771Srajfill_dbregs(struct thread *td, struct dbreg *dbregs)
748176771Sraj{
749176771Sraj
750176771Sraj	/* No debug registers on PowerPC */
751176771Sraj	return (ENOSYS);
752176771Sraj}
753176771Sraj
754176771Srajint
755176771Srajset_dbregs(struct thread *td, struct dbreg *dbregs)
756176771Sraj{
757176771Sraj
758176771Sraj	/* No debug registers on PowerPC */
759176771Sraj	return (ENOSYS);
760176771Sraj}
761176771Sraj
762176771Srajint
763176771Srajset_fpregs(struct thread *td, struct fpreg *fpregs)
764176771Sraj{
765176771Sraj
766176771Sraj	return (0);
767176771Sraj}
768176771Sraj
769176771Srajint
770176771Srajptrace_set_pc(struct thread *td, unsigned long addr)
771176771Sraj{
772176771Sraj	struct trapframe *tf;
773176771Sraj
774176771Sraj	tf = td->td_frame;
775176771Sraj	tf->srr0 = (register_t)addr;
776176771Sraj
777176771Sraj	return (0);
778176771Sraj}
779176771Sraj
780176771Srajint
781176771Srajptrace_single_step(struct thread *td)
782176771Sraj{
783176771Sraj	struct trapframe *tf;
784176771Sraj	u_int reg;
785176771Sraj
786176771Sraj	reg = mfspr(SPR_DBCR0);
787176771Sraj	reg |= DBCR0_IC | DBCR0_IDM;
788176771Sraj	mtspr(SPR_DBCR0, reg);
789176771Sraj
790176771Sraj	tf = td->td_frame;
791176771Sraj	tf->srr1 |= PSL_DE;
792176771Sraj	return (0);
793176771Sraj}
794176771Sraj
795176771Srajint
796176771Srajptrace_clear_single_step(struct thread *td)
797176771Sraj{
798176771Sraj	struct trapframe *tf;
799176771Sraj
800176771Sraj	tf = td->td_frame;
801176771Sraj	tf->srr1 &= ~PSL_DE;
802176771Sraj	return (0);
803176771Sraj}
804176771Sraj
805176771Srajvoid
806176771Srajkdb_cpu_clear_singlestep(void)
807176771Sraj{
808176771Sraj	register_t r;
809176771Sraj
810176771Sraj	r = mfspr(SPR_DBCR0);
811176771Sraj	mtspr(SPR_DBCR0, r & ~DBCR0_IC);
812176771Sraj	kdb_frame->srr1 &= ~PSL_DE;
813176771Sraj}
814176771Sraj
815176771Srajvoid
816176771Srajkdb_cpu_set_singlestep(void)
817176771Sraj{
818176771Sraj	register_t r;
819176771Sraj
820176771Sraj	r = mfspr(SPR_DBCR0);
821176771Sraj	mtspr(SPR_DBCR0, r | DBCR0_IC | DBCR0_IDM);
822176771Sraj	kdb_frame->srr1 |= PSL_DE;
823176771Sraj}
824176771Sraj
825176771Srajvoid
826176771Srajsendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
827176771Sraj{
828176771Sraj	struct trapframe *tf;
829176771Sraj	struct sigframe *sfp;
830176771Sraj	struct sigacts *psp;
831176771Sraj	struct sigframe sf;
832176771Sraj	struct thread *td;
833176771Sraj	struct proc *p;
834176771Sraj	int oonstack, rndfsize;
835176771Sraj	int sig, code;
836176771Sraj
837176771Sraj	td = curthread;
838176771Sraj	p = td->td_proc;
839176771Sraj	PROC_LOCK_ASSERT(p, MA_OWNED);
840176771Sraj	sig = ksi->ksi_signo;
841176771Sraj	code = ksi->ksi_code;
842176771Sraj	psp = p->p_sigacts;
843176771Sraj	mtx_assert(&psp->ps_mtx, MA_OWNED);
844176771Sraj	tf = td->td_frame;
845176771Sraj	oonstack = sigonstack(tf->fixreg[1]);
846176771Sraj
847176771Sraj	rndfsize = ((sizeof(sf) + 15) / 16) * 16;
848176771Sraj
849176771Sraj	CTR4(KTR_SIG, "sendsig: td=%p (%s) catcher=%p sig=%d", td, p->p_comm,
850176771Sraj	    catcher, sig);
851176771Sraj
852176771Sraj	/*
853176771Sraj	 * Save user context
854176771Sraj	 */
855176771Sraj	memset(&sf, 0, sizeof(sf));
856176771Sraj	grab_mcontext(td, &sf.sf_uc.uc_mcontext, 0);
857176771Sraj	sf.sf_uc.uc_sigmask = *mask;
858176771Sraj	sf.sf_uc.uc_stack = td->td_sigstk;
859176771Sraj	sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
860176771Sraj		? ((oonstack) ? SS_ONSTACK : 0) : SS_DISABLE;
861176771Sraj
862176771Sraj	sf.sf_uc.uc_mcontext.mc_onstack = (oonstack) ? 1 : 0;
863176771Sraj
864176771Sraj	/*
865176771Sraj	 * Allocate and validate space for the signal handler context.
866176771Sraj	 */
867176771Sraj	if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
868176771Sraj	    SIGISMEMBER(psp->ps_sigonstack, sig)) {
869176771Sraj		sfp = (struct sigframe *)((caddr_t)td->td_sigstk.ss_sp +
870176771Sraj		    td->td_sigstk.ss_size - rndfsize);
871176771Sraj	} else {
872176771Sraj		sfp = (struct sigframe *)(tf->fixreg[1] - rndfsize);
873176771Sraj	}
874176771Sraj
875176771Sraj	/*
876176771Sraj	 * Translate the signal if appropriate (Linux emu ?)
877176771Sraj	 */
878176771Sraj	if (p->p_sysent->sv_sigtbl && sig <= p->p_sysent->sv_sigsize)
879176771Sraj		sig = p->p_sysent->sv_sigtbl[_SIG_IDX(sig)];
880176771Sraj
881176771Sraj	/*
882176771Sraj	 * Save the floating-point state, if necessary, then copy it.
883176771Sraj	 */
884176771Sraj	/* XXX */
885176771Sraj
886176771Sraj	/*
887176771Sraj	 * Set up the registers to return to sigcode.
888176771Sraj	 *
889176771Sraj	 *   r1/sp - sigframe ptr
890176771Sraj	 *   lr    - sig function, dispatched to by blrl in trampoline
891176771Sraj	 *   r3    - sig number
892176771Sraj	 *   r4    - SIGINFO ? &siginfo : exception code
893176771Sraj	 *   r5    - user context
894176771Sraj	 *   srr0  - trampoline function addr
895176771Sraj	 */
896176771Sraj	tf->lr = (register_t)catcher;
897176771Sraj	tf->fixreg[1] = (register_t)sfp;
898176771Sraj	tf->fixreg[FIRSTARG] = sig;
899176771Sraj	tf->fixreg[FIRSTARG+2] = (register_t)&sfp->sf_uc;
900176771Sraj	if (SIGISMEMBER(psp->ps_siginfo, sig)) {
901176771Sraj		/*
902176771Sraj		 * Signal handler installed with SA_SIGINFO.
903176771Sraj		 */
904176771Sraj		tf->fixreg[FIRSTARG+1] = (register_t)&sfp->sf_si;
905176771Sraj
906176771Sraj		/*
907176771Sraj		 * Fill siginfo structure.
908176771Sraj		 */
909176771Sraj		sf.sf_si = ksi->ksi_info;
910176771Sraj		sf.sf_si.si_signo = sig;
911176771Sraj		sf.sf_si.si_addr = (void *) ((tf->exc == EXC_DSI) ?
912176771Sraj		    tf->cpu.booke.dear : tf->srr0);
913176771Sraj	} else {
914176771Sraj		/* Old FreeBSD-style arguments. */
915176771Sraj		tf->fixreg[FIRSTARG+1] = code;
916176771Sraj		tf->fixreg[FIRSTARG+3] = (tf->exc == EXC_DSI) ?
917176771Sraj		    tf->cpu.booke.dear : tf->srr0;
918176771Sraj	}
919176771Sraj	mtx_unlock(&psp->ps_mtx);
920176771Sraj	PROC_UNLOCK(p);
921176771Sraj
922176771Sraj	tf->srr0 = (register_t)(PS_STRINGS - *(p->p_sysent->sv_szsigcode));
923176771Sraj
924176771Sraj	/*
925176771Sraj	 * copy the frame out to userland.
926176771Sraj	 */
927176771Sraj	if (copyout((caddr_t)&sf, (caddr_t)sfp, sizeof(sf)) != 0) {
928176771Sraj		/*
929176771Sraj		 * Process has trashed its stack. Kill it.
930176771Sraj		 */
931176771Sraj		CTR2(KTR_SIG, "sendsig: sigexit td=%p sfp=%p", td, sfp);
932176771Sraj		PROC_LOCK(p);
933176771Sraj		sigexit(td, SIGILL);
934176771Sraj	}
935176771Sraj
936176771Sraj	CTR3(KTR_SIG, "sendsig: return td=%p pc=%#x sp=%#x", td,
937176771Sraj	    tf->srr0, tf->fixreg[1]);
938176771Sraj
939176771Sraj	PROC_LOCK(p);
940176771Sraj	mtx_lock(&psp->ps_mtx);
941176771Sraj}
942176771Sraj
943176771Srajvoid
944176771Srajbzero(void *buf, size_t len)
945176771Sraj{
946176771Sraj	caddr_t p;
947176771Sraj
948176771Sraj	p = buf;
949176771Sraj
950176771Sraj	while (((vm_offset_t) p & (sizeof(u_long) - 1)) && len) {
951176771Sraj		*p++ = 0;
952176771Sraj		len--;
953176771Sraj	}
954176771Sraj
955176771Sraj	while (len >= sizeof(u_long) * 8) {
956176771Sraj		*(u_long*) p = 0;
957176771Sraj		*((u_long*) p + 1) = 0;
958176771Sraj		*((u_long*) p + 2) = 0;
959176771Sraj		*((u_long*) p + 3) = 0;
960176771Sraj		len -= sizeof(u_long) * 8;
961176771Sraj		*((u_long*) p + 4) = 0;
962176771Sraj		*((u_long*) p + 5) = 0;
963176771Sraj		*((u_long*) p + 6) = 0;
964176771Sraj		*((u_long*) p + 7) = 0;
965176771Sraj		p += sizeof(u_long) * 8;
966176771Sraj	}
967176771Sraj
968176771Sraj	while (len >= sizeof(u_long)) {
969176771Sraj		*(u_long*) p = 0;
970176771Sraj		len -= sizeof(u_long);
971176771Sraj		p += sizeof(u_long);
972176771Sraj	}
973176771Sraj
974176771Sraj	while (len) {
975176771Sraj		*p++ = 0;
976176771Sraj		len--;
977176771Sraj	}
978176771Sraj}
979176771Sraj
980176771Sraj/*
981176771Sraj * XXX what is the better/proper place for this routine?
982176771Sraj */
983176771Srajint
984176771Srajmem_valid(vm_offset_t addr, int len)
985176771Sraj{
986176771Sraj
987176771Sraj	return (1);
988176771Sraj}
989