xref: /netbsd-src/sys/arch/hpcarm/hpcarm/hpc_machdep.c (revision b62fc9e20372b08e1785ff6d769312d209fa2005)
1 /*	$NetBSD: hpc_machdep.c,v 1.97 2010/04/17 13:36:21 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.97 2010/04/17 13:36:21 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 #ifdef BOOT_DUMP
93 void	dumppages(char *, int);
94 #endif
95 
96 /*
97  * Reboots the system.
98  *
99  * Deal with any syncing, unmounting, dumping and shutdown hooks,
100  * then reset the CPU.
101  */
102 void
103 cpu_reboot(int howto, char *bootstr)
104 {
105 	/*
106 	 * If we are still cold then hit the air brakes
107 	 * and crash to earth fast.
108 	 */
109 	if (cold) {
110 		doshutdownhooks();
111 		pmf_system_shutdown(boothowto);
112 		printf("Halted while still in the ICE age.\n");
113 		printf("The operating system has halted.\n");
114 		printf("Please press any key to reboot.\n\n");
115 		cngetc();
116 		printf("rebooting...\n");
117 		cpu_reset();
118 		/* NOTREACHED */
119 	}
120 
121 	/* Reset the sleep function. */
122 	__sleep_func = NULL;
123 	__sleep_ctx = NULL;
124 
125 	/* Disable console buffering. */
126 	cnpollc(1);
127 
128 	/*
129 	 * If RB_NOSYNC was not specified sync the discs.
130 	 * Note: Unless cold is set to 1 here, syslogd will die during
131 	 * the unmount.  It looks like syslogd is getting woken up only
132 	 * to find that it cannot page part of the binary in as the
133 	 * file system has been unmounted.
134 	 */
135 	if (!(howto & RB_NOSYNC))
136 		bootsync();
137 
138 	/* Say NO to interrupts. */
139 	(void)splhigh();
140 
141 	/* Do a dump if requested. */
142 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
143 		dumpsys();
144 
145 	/* Run any shutdown hooks. */
146 	doshutdownhooks();
147 
148 	pmf_system_shutdown(boothowto);
149 
150 	/* Make sure IRQs are disabled. */
151 	IRQdisable;
152 
153 	if (howto & RB_HALT) {
154 		printf("The operating system has halted.\n");
155 		printf("Please press any key to reboot.\n\n");
156 		cngetc();
157 	}
158 
159 	printf("rebooting...\n");
160 	cpu_reset();
161 	/* NOTREACHED */
162 }
163 
164 void
165 machine_sleep(void)
166 {
167 
168 	if (__sleep_func != NULL)
169 		__sleep_func(__sleep_ctx);
170 }
171 
172 void
173 machine_standby(void)
174 {
175 }
176 
177 #ifdef BOOT_DUMP
178 static void
179 dumppages(char *start, int nbytes)
180 {
181 	char *p = start;
182 	char *p1;
183 	int i;
184 
185 	for (i = nbytes; i > 0; i -= 16, p += 16) {
186 		for (p1 = p + 15; p != p1; p1--) {
187 			if (*p1)
188 				break;
189 		}
190 		if (!*p1)
191 			continue;
192 		printf("%08x %02x %02x %02x %02x %02x %02x %02x %02x"
193 		    " %02x %02x %02x %02x %02x %02x %02x %02x\n",
194 		    (unsigned int)p,
195 		    p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],
196 		    p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);
197 	}
198 }
199 #endif
200