xref: /netbsd-src/sys/arch/hpcarm/hpcarm/hpc_machdep.c (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1 /*	$NetBSD: hpc_machdep.c,v 1.98 2010/04/29 01:54:26 nonaka Exp $	*/
2 
3 /*
4  * Copyright (c) 1994-1998 Mark Brinicombe.
5  * Copyright (c) 1994 Brini.
6  * All rights reserved.
7  *
8  * This code is derived from software written for Brini by Mark Brinicombe
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by Brini.
21  * 4. The name of the company nor the name of the author may be used to
22  *    endorse or promote products derived from this software without specific
23  *    prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
26  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  */
37 
38 /*
39  * Machine dependent functions for kernel setup.
40  */
41 
42 #include <sys/cdefs.h>
43 __KERNEL_RCSID(0, "$NetBSD: hpc_machdep.c,v 1.98 2010/04/29 01:54:26 nonaka Exp $");
44 
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/reboot.h>
48 
49 #include <uvm/uvm.h>
50 
51 #include <arm/cpufunc.h>
52 
53 #include <machine/bootconfig.h>
54 #include <machine/bootinfo.h>
55 #include <machine/pmap.h>
56 
57 #include <dev/cons.h>
58 #include <dev/hpc/apm/apmvar.h>
59 
60 BootConfig bootconfig;		/* Boot config storage */
61 struct bootinfo *bootinfo, bootinfo_storage;
62 char booted_kernel_storage[80];
63 char *booted_kernel = booted_kernel_storage;
64 
65 paddr_t physical_start;
66 paddr_t physical_freestart;
67 paddr_t physical_freeend;
68 paddr_t physical_end;
69 
70 #ifndef PMAP_STATIC_L1S
71 int max_processes = 64;			/* Default number */
72 #endif /* !PMAP_STATIC_L1S */
73 
74 /* Physical and virtual addresses for some global pages */
75 pv_addr_t irqstack;
76 pv_addr_t undstack;
77 pv_addr_t abtstack;
78 pv_addr_t kernelstack;
79 
80 char *boot_args = NULL;
81 char boot_file[16];
82 
83 vaddr_t msgbufphys;
84 
85 /* Prototypes */
86 void dumpsys(void);
87 
88 /* Mode dependent sleep function holder */
89 void (*__sleep_func)(void *);
90 void *__sleep_ctx;
91 
92 void (*__cpu_reset)(void) = cpu_reset;
93 
94 #ifdef BOOT_DUMP
95 void	dumppages(char *, int);
96 #endif
97 
98 /*
99  * Reboots the system.
100  *
101  * Deal with any syncing, unmounting, dumping and shutdown hooks,
102  * then reset the CPU.
103  */
104 void
105 cpu_reboot(int howto, char *bootstr)
106 {
107 	/*
108 	 * If we are still cold then hit the air brakes
109 	 * and crash to earth fast.
110 	 */
111 	if (cold) {
112 		doshutdownhooks();
113 		pmf_system_shutdown(boothowto);
114 		printf("Halted while still in the ICE age.\n");
115 		printf("The operating system has halted.\n");
116 		printf("Please press any key to reboot.\n\n");
117 		cngetc();
118 		printf("rebooting...\n");
119 		__cpu_reset();
120 		/* NOTREACHED */
121 	}
122 
123 	/* Reset the sleep function. */
124 	__sleep_func = NULL;
125 	__sleep_ctx = NULL;
126 
127 	/* Disable console buffering. */
128 	cnpollc(1);
129 
130 	/*
131 	 * If RB_NOSYNC was not specified sync the discs.
132 	 * Note: Unless cold is set to 1 here, syslogd will die during
133 	 * the unmount.  It looks like syslogd is getting woken up only
134 	 * to find that it cannot page part of the binary in as the
135 	 * file system has been unmounted.
136 	 */
137 	if (!(howto & RB_NOSYNC))
138 		bootsync();
139 
140 	/* Say NO to interrupts. */
141 	(void)splhigh();
142 
143 	/* Do a dump if requested. */
144 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
145 		dumpsys();
146 
147 	/* Run any shutdown hooks. */
148 	doshutdownhooks();
149 
150 	pmf_system_shutdown(boothowto);
151 
152 	/* Make sure IRQs are disabled. */
153 	IRQdisable;
154 
155 	if (howto & RB_HALT) {
156 		printf("The operating system has halted.\n");
157 		printf("Please press any key to reboot.\n\n");
158 		cngetc();
159 	}
160 
161 	printf("rebooting...\n");
162 	__cpu_reset();
163 	/* NOTREACHED */
164 }
165 
166 void
167 machine_sleep(void)
168 {
169 
170 	if (__sleep_func != NULL)
171 		__sleep_func(__sleep_ctx);
172 }
173 
174 void
175 machine_standby(void)
176 {
177 }
178 
179 #ifdef BOOT_DUMP
180 static void
181 dumppages(char *start, int nbytes)
182 {
183 	char *p = start;
184 	char *p1;
185 	int i;
186 
187 	for (i = nbytes; i > 0; i -= 16, p += 16) {
188 		for (p1 = p + 15; p != p1; p1--) {
189 			if (*p1)
190 				break;
191 		}
192 		if (!*p1)
193 			continue;
194 		printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x"
195 		    " %02x %02x %02x %02x %02x %02x %02x %02x\n",
196 		    (unsigned int)p,
197 		    p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
198 		    p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
199 	}
200 }
201 #endif
202