machdep.c revision 1.93 1 1.93 garbled /* $NetBSD: machdep.c,v 1.93 2007/10/17 19:56:10 garbled Exp $ */
2 1.1 ws
3 1.1 ws /*
4 1.1 ws * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 ws * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 ws * All rights reserved.
7 1.1 ws *
8 1.1 ws * Redistribution and use in source and binary forms, with or without
9 1.1 ws * modification, are permitted provided that the following conditions
10 1.1 ws * are met:
11 1.1 ws * 1. Redistributions of source code must retain the above copyright
12 1.1 ws * notice, this list of conditions and the following disclaimer.
13 1.1 ws * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ws * notice, this list of conditions and the following disclaimer in the
15 1.1 ws * documentation and/or other materials provided with the distribution.
16 1.1 ws * 3. All advertising materials mentioning features or use of this software
17 1.1 ws * must display the following acknowledgement:
18 1.1 ws * This product includes software developed by TooLs GmbH.
19 1.1 ws * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 ws * derived from this software without specific prior written permission.
21 1.1 ws *
22 1.1 ws * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 ws * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 ws * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 ws * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 ws * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 ws * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 ws * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 ws * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 ws * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 ws * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 ws */
33 1.86 lukem
34 1.86 lukem #include <sys/cdefs.h>
35 1.93 garbled __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.93 2007/10/17 19:56:10 garbled Exp $");
36 1.1 ws
37 1.1 ws #include <sys/param.h>
38 1.1 ws #include <sys/buf.h>
39 1.93 garbled #include <sys/boot_flag.h>
40 1.1 ws #include <sys/mount.h>
41 1.43 thorpej #include <sys/kernel.h>
42 1.1 ws
43 1.19 sakamoto #include <uvm/uvm_extern.h>
44 1.19 sakamoto
45 1.70 thorpej #include <dev/ofw/openfirm.h>
46 1.93 garbled #include <dev/cons.h>
47 1.70 thorpej
48 1.68 matt #include <machine/autoconf.h>
49 1.1 ws #include <machine/pmap.h>
50 1.1 ws #include <machine/powerpc.h>
51 1.1 ws #include <machine/trap.h>
52 1.93 garbled #include <machine/bus.h>
53 1.93 garbled #include <machine/isa_machdep.h>
54 1.54 thorpej
55 1.87 matt #include <powerpc/oea/bat.h>
56 1.93 garbled #include <powerpc/ofw_cons.h>
57 1.71 thorpej
58 1.1 ws
59 1.93 garbled struct pmap ofw_pmap;
60 1.78 chs char bootpath[256];
61 1.1 ws
62 1.93 garbled void ofwppc_batinit(void);
63 1.71 thorpej void ofppc_bootstrap_console(void);
64 1.77 matt
65 1.1 ws void
66 1.93 garbled initppc(u_int startkernel, u_int endkernel, char *args)
67 1.1 ws {
68 1.71 thorpej /* Initialize the bootstrap console. */
69 1.71 thorpej ofppc_bootstrap_console();
70 1.93 garbled printf( "\n\nHallo Welt!\n\n");
71 1.93 garbled ofwoea_initppc(startkernel, endkernel, args);
72 1.93 garbled map_isa_ioregs();
73 1.1 ws }
74 1.1 ws
75 1.1 ws void
76 1.93 garbled cpu_startup(void)
77 1.1 ws {
78 1.82 matt oea_startup(NULL);
79 1.1 ws }
80 1.1 ws
81 1.93 garbled /*
82 1.1 ws void
83 1.93 garbled consinit(void)
84 1.1 ws {
85 1.93 garbled ofwoea_consinit();
86 1.71 thorpej }
87 1.93 garbled */
88 1.71 thorpej
89 1.71 thorpej void
90 1.93 garbled dumpsys(void)
91 1.71 thorpej {
92 1.93 garbled printf("dumpsys: TBD\n");
93 1.1 ws }
94 1.1 ws
95 1.1 ws /*
96 1.93 garbled * Halt or reboot the machine after syncing/dumping according to howto.
97 1.1 ws */
98 1.1 ws
99 1.1 ws void
100 1.93 garbled cpu_reboot(int howto, char *what)
101 1.1 ws {
102 1.1 ws static int syncing;
103 1.1 ws static char str[256];
104 1.1 ws char *ap = str, *ap1 = ap;
105 1.1 ws
106 1.1 ws boothowto = howto;
107 1.1 ws if (!cold && !(howto & RB_NOSYNC) && !syncing) {
108 1.1 ws syncing = 1;
109 1.93 garbled vfs_shutdown(); /* sync */
110 1.93 garbled resettodr(); /* set wall clock */
111 1.1 ws }
112 1.1 ws splhigh();
113 1.1 ws if (howto & RB_HALT) {
114 1.1 ws doshutdownhooks();
115 1.3 christos printf("halted\n\n");
116 1.1 ws ppc_exit();
117 1.1 ws }
118 1.1 ws if (!cold && (howto & RB_DUMP))
119 1.82 matt oea_dumpsys();
120 1.1 ws doshutdownhooks();
121 1.3 christos printf("rebooting\n\n");
122 1.1 ws if (what && *what) {
123 1.1 ws if (strlen(what) > sizeof str - 5)
124 1.3 christos printf("boot string too large, ignored\n");
125 1.1 ws else {
126 1.1 ws strcpy(str, what);
127 1.1 ws ap1 = ap = str + strlen(str);
128 1.1 ws *ap++ = ' ';
129 1.1 ws }
130 1.1 ws }
131 1.1 ws *ap++ = '-';
132 1.1 ws if (howto & RB_SINGLE)
133 1.1 ws *ap++ = 's';
134 1.1 ws if (howto & RB_KDB)
135 1.1 ws *ap++ = 'd';
136 1.1 ws *ap++ = 0;
137 1.1 ws if (ap[-2] == '-')
138 1.1 ws *ap1 = 0;
139 1.1 ws ppc_boot(str);
140 1.1 ws }
141 1.1 ws
142 1.1 ws /*
143 1.93 garbled * XXX
144 1.93 garbled * The following code is subject to die at a later date. This is the only
145 1.93 garbled * remaining code in this file subject to the Tools GmbH copyright.
146 1.1 ws */
147 1.93 garbled
148 1.1 ws void
149 1.93 garbled consinit()
150 1.1 ws {
151 1.93 garbled
152 1.93 garbled (*cn_tab->cn_probe)(cn_tab);
153 1.60 thorpej }
154 1.60 thorpej
155 1.93 garbled void ofcons_cnprobe(struct consdev *);
156 1.93 garbled int ofppc_cngetc(dev_t);
157 1.93 garbled void ofppc_cnputc(dev_t, int);
158 1.93 garbled
159 1.93 garbled struct consdev ofppc_bootcons = {
160 1.93 garbled ofcons_cnprobe, NULL, ofppc_cngetc, ofppc_cnputc, nullcnpollc, NULL,
161 1.93 garbled NULL, NULL, makedev(0,0), 1,
162 1.93 garbled };
163 1.60 thorpej
164 1.93 garbled int ofppc_stdin_ihandle, ofppc_stdout_ihandle;
165 1.93 garbled int ofppc_stdin_phandle, ofppc_stdout_phandle;
166 1.1 ws
167 1.93 garbled void
168 1.93 garbled ofppc_bootstrap_console(void)
169 1.7 thorpej {
170 1.93 garbled int chosen;
171 1.93 garbled char data[4];
172 1.93 garbled
173 1.93 garbled chosen = OF_finddevice("/chosen");
174 1.7 thorpej
175 1.93 garbled if (OF_getprop(chosen, "stdin", data, sizeof(data)) != sizeof(int))
176 1.93 garbled goto nocons;
177 1.93 garbled ofppc_stdin_ihandle = of_decode_int(data);
178 1.93 garbled ofppc_stdin_phandle = OF_instance_to_package(ofppc_stdin_ihandle);
179 1.7 thorpej
180 1.93 garbled if (OF_getprop(chosen, "stdout", data, sizeof(data)) != sizeof(int))
181 1.93 garbled goto nocons;
182 1.93 garbled ofppc_stdout_ihandle = of_decode_int(data);
183 1.93 garbled ofppc_stdout_phandle = OF_instance_to_package(ofppc_stdout_ihandle);
184 1.7 thorpej
185 1.93 garbled cn_tab = &ofppc_bootcons;
186 1.73 thorpej
187 1.93 garbled nocons:
188 1.93 garbled return;
189 1.7 thorpej }
190 1.7 thorpej
191 1.93 garbled int
192 1.93 garbled ofppc_cngetc(dev_t dev)
193 1.7 thorpej {
194 1.93 garbled u_char ch = '\0';
195 1.93 garbled int l;
196 1.93 garbled
197 1.93 garbled while ((l = OF_read(ofppc_stdin_ihandle, &ch, 1)) != 1)
198 1.93 garbled if (l != -2 && l != 0)
199 1.93 garbled return (-1);
200 1.88 nonaka
201 1.93 garbled return (ch);
202 1.1 ws }
203 1.1 ws
204 1.93 garbled void
205 1.93 garbled ofppc_cnputc(dev_t dev, int c)
206 1.73 thorpej {
207 1.93 garbled char ch = c;
208 1.73 thorpej
209 1.93 garbled OF_write(ofppc_stdout_ihandle, &ch, 1);
210 1.73 thorpej }
211 1.73 thorpej
212