No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / alpha / stand / common / prom.c
blobfbef31f89f85801167fc5113a4704d4f1fa338ba
1 /* $NetBSD: prom.c,v 1.13 2009/03/14 21:04:03 dsl Exp $ */
3 /*
4 * Mach Operating System
5 * Copyright (c) 1992 Carnegie Mellon University
6 * All Rights Reserved.
7 *
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
29 #include <lib/libkern/libkern.h>
31 #include <sys/types.h>
33 #include <machine/prom.h>
34 #include <machine/rpb.h>
36 #include "common.h"
38 int console;
40 #if !defined(NO_GETCHAR) || !defined(NO_PUTCHAR_HALT)
41 static int test_getchar(int *);
42 #endif
43 static void putonechar(int c);
45 void
46 init_prom_calls(void)
48 extern struct prom_vec prom_dispatch_v;
49 struct rpb *r;
50 struct crb *c;
51 char buf[4];
53 r = (struct rpb *)HWRPB_ADDR;
54 c = (struct crb *)((u_int8_t *)r + r->rpb_crb_off);
56 prom_dispatch_v.routine_arg = c->crb_v_dispatch;
57 prom_dispatch_v.routine = c->crb_v_dispatch->entry_va;
59 /* Look for console tty. */
60 prom_getenv(PROM_E_TTY_DEV, buf, 4);
61 console = buf[0] - '0';
64 #if !defined(NO_GETCHAR) || !defined(NO_PUTCHAR_HALT)
65 static int
66 test_getchar(int *xc)
68 prom_return_t ret;
70 ret.bits = prom_dispatch(PROM_R_GETC, console);
71 *xc = ret.u.retval;
72 return ret.u.status == 0 || ret.u.status == 1;
74 #endif
76 #if !defined(NO_GETCHAR)
77 int
78 getchar(void)
80 int c;
82 for (;;) {
83 if (test_getchar(&c)) {
84 if (c == 3)
85 halt();
86 return c;
90 #endif
92 static void
93 putonechar(int c)
95 prom_return_t ret;
96 char cbuf = c;
98 do {
99 ret.bits = prom_dispatch(PROM_R_PUTS, console, &cbuf, 1);
100 } while ((ret.u.retval & 1) == 0);
103 void
104 putchar(int c)
106 #if !defined(NO_PUTCHAR_HALT)
107 int typed_c;
108 #endif
110 if (c == '\r' || c == '\n') {
111 putonechar('\r');
112 c = '\n';
114 putonechar(c);
115 #if !defined(NO_PUTCHAR_HALT)
116 if (test_getchar(&typed_c))
117 if (typed_c == 3)
118 halt();
119 #endif
123 prom_getenv(int id, char *buf, int len)
126 * On at least some systems, the GETENV call requires a
127 * 8-byte-aligned buffer, or it bails out with a "kernel stack
128 * not valid halt". Provide a local, aligned buffer here and
129 * then copy to the caller's buffer.
131 static char abuf[128] __attribute__((aligned (8)));
132 prom_return_t ret;
134 ret.bits = prom_dispatch(PROM_R_GETENV, id, abuf, 128);
135 if (ret.u.status & 0x4)
136 ret.u.retval = 0;
137 len = min(len - 1, ret.u.retval);
138 memcpy(buf, abuf, len);
139 buf[len] = '\0';
141 return (len);