added -y/--side-by-side option
[dfdiff.git] / sys / boot / ofw / libofw / ofw_console.c
blob616a8c405f8649e2d3068334ddcdcce640bd7e49
1 /*
2 * $NetBSD: prom.c,v 1.3 1997/09/06 14:03:58 drochner Exp $
3 * $FreeBSD: src/sys/boot/ofw/libofw/ofw_console.c,v 1.7 2002/02/23 04:33:15 jake Exp $
4 * $DragonFly: src/sys/boot/ofw/libofw/ofw_console.c,v 1.1 2003/11/10 06:08:37 dillon Exp $
5 */
7 /*
8 * Mach Operating System
9 * Copyright (c) 1992 Carnegie Mellon University
10 * All Rights Reserved.
12 * Permission to use, copy, modify and distribute this software and its
13 * documentation is hereby granted, provided that both the copyright
14 * notice and this permission notice appear in all copies of the
15 * software, derivative works or modified versions, and any portions
16 * thereof, and that both notices appear in supporting documentation.
18 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
19 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
20 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
22 * Carnegie Mellon requests users of this software to return to
24 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
25 * School of Computer Science
26 * Carnegie Mellon University
27 * Pittsburgh PA 15213-3890
29 * any improvements or extensions that they make and grant Carnegie Mellon
30 * the rights to redistribute these changes.
33 #include <sys/types.h>
35 #include "bootstrap.h"
36 #include "openfirm.h"
38 int console;
40 static void ofw_cons_probe(struct console *cp);
41 static int ofw_cons_init(int);
42 void ofw_cons_putchar(int);
43 int ofw_cons_getchar(void);
44 int ofw_cons_poll(void);
46 static ihandle_t stdin;
47 static ihandle_t stdout;
49 struct console ofwconsole = {
50 "ofw",
51 "OpenFirmware console",
53 ofw_cons_probe,
54 ofw_cons_init,
55 ofw_cons_putchar,
56 ofw_cons_getchar,
57 ofw_cons_poll,
60 static void
61 ofw_cons_probe(struct console *cp)
63 phandle_t chosen;
65 if ((chosen = OF_finddevice("/chosen")) == -1)
66 OF_exit();
67 OF_getprop(chosen, "stdin", &stdin, sizeof(stdin));
68 OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
69 cp->c_flags |= C_PRESENTIN|C_PRESENTOUT;
72 static int
73 ofw_cons_init(int arg)
75 return 0;
78 void
79 ofw_cons_putchar(int c)
81 char cbuf;
83 if (c == '\n') {
84 cbuf = '\r';
85 OF_write(stdout, &cbuf, 1);
88 cbuf = c;
89 OF_write(stdout, &cbuf, 1);
92 static int saved_char = -1;
94 int
95 ofw_cons_getchar()
97 unsigned char ch = '\0';
98 int l;
100 if (saved_char != -1) {
101 l = saved_char;
102 saved_char = -1;
103 return l;
106 while ((l = OF_read(stdin, &ch, 1)) != 1)
107 if (l != -2 && l != 0)
108 return -1;
109 return ch;
113 ofw_cons_poll()
115 unsigned char ch;
116 int l;
118 if (saved_char != -1)
119 return 1;
121 if (OF_read(stdin, &ch, 1) > 0) {
122 saved_char = ch;
123 return 1;
126 return 0;