1 /* $OpenBSD: romcons.c,v 1.2 2023/03/11 10:33:27 aoyama Exp $ */
2 /*
3 * Copyright (c) 2022 Kenji Aoyama
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 /*
19 * Mach Operating System
20 * Copyright (c) 1993-1991 Carnegie Mellon University
21 * Copyright (c) 1991 OMRON Corporation
22 * All Rights Reserved.
23 *
24 * Permission to use, copy, modify and distribute this software and its
25 * documentation is hereby granted, provided that both the copyright
26 * notice and this permission notice appear in all copies of the
27 * software, derivative works or modified versions, and any portions
28 * thereof, and that both notices appear in supporting documentation.
29 *
30 * CARNEGIE MELLON AND OMRON ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS"
31 * CONDITION. CARNEGIE MELLON AND OMRON DISCLAIM ANY LIABILITY OF ANY KIND
32 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
33 *
34 * Carnegie Mellon requests users of this software to return to
35 *
36 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
37 * School of Computer Science
38 * Carnegie Mellon University
39 * Pittsburgh PA 15213-3890
40 *
41 * any improvements or extensions that they make and grant Carnegie the
42 * rights to redistribute these changes.
43 */
44
45 /*
46 * LUNA-88K{,2} ROM console routines:
47 * Enables printing of boot messages before consinit().
48 */
49
50 #include <sys/types.h>
51 #include <sys/conf.h>
52 #include <sys/device.h>
53
54 #include <dev/cons.h>
55
56 #include <machine/intr.h>
57
58 #define __ROM_FUNC_TABLE ((int **)0x00001100)
59 #define ROMGETC() (*(int (*)(void))__ROM_FUNC_TABLE[3])()
60 #define ROMPUTC(x) (*(void (*)(int))__ROM_FUNC_TABLE[4])(x)
61
62 void
romcnprobe(struct consdev * cp)63 romcnprobe(struct consdev *cp)
64 {
65 cp->cn_dev = makedev(14, 0);
66 cp->cn_pri = CN_LOWPRI;
67 }
68
69 void
romcninit(struct consdev * cp)70 romcninit(struct consdev *cp)
71 {
72 /* Nothing to do */
73 }
74
75 int
romcngetc(dev_t dev)76 romcngetc(dev_t dev)
77 {
78 int s, c;
79
80 do {
81 s = splhigh();
82 c = ROMGETC();
83 splx(s);
84 } while (c == -1);
85 return c;
86 }
87
88 void
romcnputc(dev_t dev,int c)89 romcnputc(dev_t dev, int c)
90 {
91 int s;
92
93 s = splhigh();
94 ROMPUTC(c);
95 splx(s);
96 }
97
98 /*
99 * This is to fake out the console routines, while booting.
100 * We could use directly the rom console, but we want to be able to
101 * configure a kernel without rom since we do not necessarily need a
102 * full-blown console driver.
103 */
104 cons_decl(rom);
105 extern void nullcnpollc(dev_t, int);
106
107 struct consdev romcons = {
108 NULL,
109 NULL,
110 romcngetc,
111 romcnputc,
112 nullcnpollc,
113 NULL,
114 makedev(14, 0),
115 CN_LOWPRI,
116 };
117
118 struct consdev *cn_tab = &romcons;
119