Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / sys / boot / alpha / libalpha / prom.c
1 /* $FreeBSD: src/sys/boot/alpha/libalpha/prom.c,v 1.3 1999/08/28 00:39:28 peter Exp $ */
2 /* $DragonFly: src/sys/boot/alpha/libalpha/Attic/prom.c,v 1.2 2003/06/17 04:28:16 dillon Exp $ */
3 /* $NetBSD: prom.c,v 1.3 1997/09/06 14:03:58 drochner Exp $ */
4
5 /*  
6  * Mach Operating System
7  * Copyright (c) 1992 Carnegie Mellon University
8  * All Rights Reserved.
9  * 
10  * Permission to use, copy, modify and distribute this software and its
11  * documentation is hereby granted, provided that both the copyright
12  * notice and this permission notice appear in all copies of the
13  * software, derivative works or modified versions, and any portions
14  * thereof, and that both notices appear in supporting documentation.
15  * 
16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
18  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19  * 
20  * Carnegie Mellon requests users of this software to return to
21  * 
22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
23  *  School of Computer Science
24  *  Carnegie Mellon University
25  *  Pittsburgh PA 15213-3890
26  * 
27  * any improvements or extensions that they make and grant Carnegie Mellon
28  * the rights to redistribute these changes.
29  */
30
31 #include <sys/types.h>
32
33 #include <machine/prom.h>
34 #include <machine/rpb.h>
35
36 #include "common.h"
37 #include "bootstrap.h"
38
39 int console;
40
41 static void prom_probe(struct console *cp);
42 static int prom_init(int);
43 void prom_putchar(int);
44 int prom_getchar(void);
45 int prom_poll(void);
46
47 struct console promconsole = {
48     "prom",
49     "SRM firmware console",
50     0,
51     prom_probe,
52     prom_init,
53     prom_putchar,
54     prom_getchar,
55     prom_poll,
56 };
57
58 void
59 init_prom_calls()
60 {
61     extern struct prom_vec prom_dispatch_v;
62     struct rpb *r;
63     struct crb *c;
64     char buf[4];
65
66     r = (struct rpb *)HWRPB_ADDR;
67     c = (struct crb *)((u_int8_t *)r + r->rpb_crb_off);
68
69     prom_dispatch_v.routine_arg = c->crb_v_dispatch;
70     prom_dispatch_v.routine = c->crb_v_dispatch->entry_va;
71
72     /* Look for console tty. */
73     prom_getenv(PROM_E_TTY_DEV, buf, 4);
74     console = buf[0] - '0';
75 }
76
77 static void
78 prom_probe(struct console *cp)
79 {
80     init_prom_calls();
81     cp->c_flags |= C_PRESENTIN|C_PRESENTOUT;
82 }
83
84 static int
85 prom_init(int arg)
86 {
87     return 0;
88 }
89
90 void
91 prom_putchar(int c)
92 {
93     prom_return_t ret;
94     char cbuf;
95
96     cbuf = c;
97     do {
98         ret.bits = prom_dispatch(PROM_R_PUTS, console, &cbuf, 1);
99     } while ((ret.u.retval & 1) == 0);
100 }
101
102 static int saved_char = -1;
103
104 int
105 prom_getchar()
106 {
107     prom_return_t ret;
108
109     if (saved_char != -1) {
110         int c = saved_char;
111         saved_char = -1;
112         return c;
113     }
114
115     for (;;) {
116         ret.bits = prom_dispatch(PROM_R_GETC, console);
117         if (ret.u.status == 0 || ret.u.status == 1)
118             return (ret.u.retval);
119     }
120 }
121
122 int
123 prom_poll()
124 {
125     prom_return_t ret;
126
127     if (saved_char != -1)
128         return 1;
129
130     ret.bits = prom_dispatch(PROM_R_GETC, console);
131     if (ret.u.status == 0 || ret.u.status == 1) {
132         saved_char = ret.u.retval;
133         return 1;
134     }
135
136     return 0;
137 }
138
139 int
140 prom_getenv(id, buf, len)
141     int id, len;
142     char *buf;
143 {
144     prom_return_t ret;
145
146     ret.bits = prom_dispatch(PROM_R_GETENV, id, buf, len-1);
147     if (ret.u.status & 0x4)
148         ret.u.retval = 0;
149     buf[ret.u.retval] = '\0';
150
151     return (ret.u.retval);
152 }
153
154 int
155 prom_open(dev, len)
156     char *dev;
157     int len;
158 {
159     prom_return_t ret;
160
161     ret.bits = prom_dispatch(PROM_R_OPEN, dev, len);
162     if (ret.u.status & 0x4)
163         return (-1);
164     else
165         return (ret.u.retval);
166 }