xref: /netbsd-src/sys/arch/hpcarm/hpcarm/hpc_machdep.c (revision 88fcb00c0357f2d7c1774f86a352637bfda96184)
1 /*	$NetBSD: hpc_machdep.c,v 1.99 2010/11/14 03:17:50 uebayasi 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.99 2010/11/14 03:17:50 uebayasi Exp $");
44 
45 #include <sys/param.h>
46 #include <sys/kernel.h>
47 #include <sys/reboot.h>
48 #include <sys/pmf.h>
49 
50 #include <uvm/uvm.h>
51 
52 #include <arm/cpufunc.h>
53 
54 #include <machine/bootconfig.h>
55 #include <machine/bootinfo.h>
56 #include <machine/pmap.h>
57 
58 #include <dev/cons.h>
59 #include <dev/hpc/apm/apmvar.h>
60 
61 BootConfig bootconfig;		/* Boot config storage */
62 struct bootinfo *bootinfo, bootinfo_storage;
63 char booted_kernel_storage[80];
64 char *booted_kernel = booted_kernel_storage;
65 
66 paddr_t physical_start;
67 paddr_t physical_freestart;
68 paddr_t physical_freeend;
69 paddr_t physical_end;
70 
71 #ifndef PMAP_STATIC_L1S
72 int max_processes = 64;			/* Default number */
73 #endif /* !PMAP_STATIC_L1S */
74 
75 /* Physical and virtual addresses for some global pages */
76 pv_addr_t irqstack;
77 pv_addr_t undstack;
78 pv_addr_t abtstack;
79 pv_addr_t kernelstack;
80 
81 char *boot_args = NULL;
82 char boot_file[16];
83 
84 vaddr_t msgbufphys;
85 
86 /* Prototypes */
87 void dumpsys(void);
88 
89 /* Mode dependent sleep function holder */
90 void (*__sleep_func)(void *);
91 void *__sleep_ctx;
92 
93 void (*__cpu_reset)(void) = cpu_reset;
94 
95 #ifdef BOOT_DUMP
96 void	dumppages(char *, int);
97 #endif
98 
99 /*
100  * Reboots the system.
101  *
102  * Deal with any syncing, unmounting, dumping and shutdown hooks,
103  * then reset the CPU.
104  */
105 void
106 cpu_reboot(int howto, char *bootstr)
107 {
108 	/*
109 	 * If we are still cold then hit the air brakes
110 	 * and crash to earth fast.
111 	 */
112 	if (cold) {
113 		doshutdownhooks();
114 		pmf_system_shutdown(boothowto);
115 		printf("Halted while still in the ICE age.\n");
116 		printf("The operating system has halted.\n");
117 		printf("Please press any key to reboot.\n\n");
118 		cngetc();
119 		printf("rebooting...\n");
120 		__cpu_reset();
121 		/* NOTREACHED */
122 	}
123 
124 	/* Reset the sleep function. */
125 	__sleep_func = NULL;
126 	__sleep_ctx = NULL;
127 
128 	/* Disable console buffering. */
129 	cnpollc(1);
130 
131 	/*
132 	 * If RB_NOSYNC was not specified sync the discs.
133 	 * Note: Unless cold is set to 1 here, syslogd will die during
134 	 * the unmount.  It looks like syslogd is getting woken up only
135 	 * to find that it cannot page part of the binary in as the
136 	 * file system has been unmounted.
137 	 */
138 	if (!(howto & RB_NOSYNC))
139 		bootsync();
140 
141 	/* Say NO to interrupts. */
142 	(void)splhigh();
143 
144 	/* Do a dump if requested. */
145 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
146 		dumpsys();
147 
148 	/* Run any shutdown hooks. */
149 	doshutdownhooks();
150 
151 	pmf_system_shutdown(boothowto);
152 
153 	/* Make sure IRQs are disabled. */
154 	IRQdisable;
155 
156 	if (howto & RB_HALT) {
157 		printf("The operating system has halted.\n");
158 		printf("Please press any key to reboot.\n\n");
159 		cngetc();
160 	}
161 
162 	printf("rebooting...\n");
163 	__cpu_reset();
164 	/* NOTREACHED */
165 }
166 
167 void
168 machine_sleep(void)
169 {
170 
171 	if (__sleep_func != NULL)
172 		__sleep_func(__sleep_ctx);
173 }
174 
175 void
176 machine_standby(void)
177 {
178 }
179 
180 #ifdef BOOT_DUMP
181 static void
182 dumppages(char *start, int nbytes)
183 {
184 	char *p = start;
185 	char *p1;
186 	int i;
187 
188 	for (i = nbytes; i > 0; i -= 16, p += 16) {
189 		for (p1 = p + 15; p != p1; p1--) {
190 			if (*p1)
191 				break;
192 		}
193 		if (!*p1)
194 			continue;
195 		printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x"
196 		    " %02x %02x %02x %02x %02x %02x %02x %02x\n",
197 		    (unsigned int)p,
198 		    p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
199 		    p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
200 	}
201 }
202 #endif
203