xref: /netbsd/sys/arch/emips/emips/promcall.c (revision 6550d01e)
1 
2 /*	$NetBSD: promcall.c,v 1.1 2011/01/26 01:18:50 pooka Exp $	*/
3 
4 /*
5  * Copyright (c) 1992, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * the Systems Programming Group of the University of Utah Computer
10  * Science Department and Ralph Campbell.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  * from: Utah Hdr: cons.c 1.1 90/07/09
37  *
38  *	@(#)cons.c	8.2 (Berkeley) 1/11/94
39  */
40 /*
41  * Copyright (c) 1988 University of Utah.
42  *
43  * This code is derived from software contributed to Berkeley by
44  * the Systems Programming Group of the University of Utah Computer
45  * Science Department and Ralph Campbell.
46  *
47  * Redistribution and use in source and binary forms, with or without
48  * modification, are permitted provided that the following conditions
49  * are met:
50  * 1. Redistributions of source code must retain the above copyright
51  *    notice, this list of conditions and the following disclaimer.
52  * 2. Redistributions in binary form must reproduce the above copyright
53  *    notice, this list of conditions and the following disclaimer in the
54  *    documentation and/or other materials provided with the distribution.
55  * 3. All advertising materials mentioning features or use of this software
56  *    must display the following acknowledgement:
57  *	This product includes software developed by the University of
58  *	California, Berkeley and its contributors.
59  * 4. Neither the name of the University nor the names of its contributors
60  *    may be used to endorse or promote products derived from this software
61  *    without specific prior written permission.
62  *
63  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73  * SUCH DAMAGE.
74  *
75  * from: Utah Hdr: cons.c 1.1 90/07/09
76  *
77  *	@(#)cons.c	8.2 (Berkeley) 1/11/94
78  */
79 
80 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
81 __KERNEL_RCSID(0, "$NetBSD: promcall.c,v 1.1 2011/01/26 01:18:50 pooka Exp $");
82 
83 #include <sys/param.h>
84 #include <sys/device.h>
85 #include <sys/reboot.h>
86 #include <sys/systm.h>
87 
88 #include <dev/cons.h>
89 
90 #include <mips/cpuregs.h>
91 #include <emips/stand/common/prom_iface.h>
92 #include <emips/emips/machdep.h>
93 
94 static int  romgetc(dev_t);
95 static void romputc(dev_t, int);
96 static void *nope(void);
97 static int  nogetchar(void);
98 static void noprintf(const char *, ...);
99 static int  nogetsysid(void);
100 static void nohalt(int *, int);
101 
102 /* Callback vector. We keep this fall-back copy jic the bootloader is broken.
103  */
104 static void *nope(void)
105 {
106     return NULL;
107 }
108 
109 static int  nogetchar(void)
110 {
111     return -1;
112 }
113 
114 static void noprintf(const char *fmt, ...)
115 {
116 }
117 
118 static int  nogetsysid(void)
119 {
120     /* say its an eMIPS, ML board */
121     return MAKESYSID(1,1,XS_ML40x,MIPS_eMIPS);
122 }
123 
124 static void nohalt(int *unused, int howto)
125 {
126 	while(1) ;	/* fool gcc */
127 	/*NOTREACHED*/
128 }
129 
130 const struct callback callvec = {
131     nope,
132     nope,
133     nope,
134     nope,
135     nope,
136     nope,
137     nope,
138     nope,
139     nope,
140 	nogetchar,
141     nope,
142     nope,
143 	noprintf,
144     nope,
145     nope,
146     nope,
147     nope,
148     nope,
149     nope,
150     nope,
151     nope,
152     nope,
153     nope,
154     nope,
155     nope,
156     nope,
157     nope,
158     nope,
159     nope,
160     nope,
161     nope,
162     nope,
163     nogetsysid,
164     nope,
165     nope,
166     nope,
167     nope,
168     nope,
169     nope,
170 	nohalt
171 };
172 
173 const   struct callback *callv = &callvec;
174 
175 /*
176  * Default consdev, for errors or warnings before
177  * consinit runs: use the PROM.
178  */
179 struct consdev promcd = {
180 	NULL,		/* probe */
181 	NULL,		/* init */
182 	romgetc,	/* getc */
183 	romputc,	/* putc */
184 	nullcnpollc,	/* pollc */
185 	NULL,		/* bell */
186 	makedev(0, 0),
187 	CN_DEAD,
188 };
189 
190 /*
191  * Get character from PROM console.
192  */
193 static int
194 romgetc(dev_t dev)
195 {
196 	int chr, s;
197 
198 	s  = splhigh();
199 	chr = (*callv->_getchar)();
200 	splx(s);
201 	return chr;
202 }
203 
204 /*
205  * Print a character on PROM console.
206  */
207 static void
208 romputc(dev_t dev,
209         int c)
210 {
211 	int s;
212 
213 	s = splhigh();
214 	(*callv->_printf)("%c", c);
215 	splx(s);
216 }
217 
218 /*
219  * Get 32bit system type:
220  *	cputype,		u_int8_t [3]
221  *	systype,		u_int8_t [2]
222  *	firmware revision,	u_int8_t [1]
223  *	hardware revision.	u_int8_t [0]
224  */
225 int
226 prom_systype(void)
227 {
228     return (*callv->_getsysid)();
229 }
230 
231 /*
232  * Halt/reboot machine.
233  */
234 void __attribute__((__noreturn__))
235 prom_halt(int howto)
236 {
237 	(*callv->_halt)((int *)0, howto);
238 	while(1) ;	/* fool gcc */
239 	/*NOTREACHED*/
240 }
241 
242