1 /* $NetBSD: prom.c,v 1.13 2009/03/14 21:04:03 dsl Exp $ */
4 * Mach Operating System
5 * Copyright (c) 1992 Carnegie Mellon University
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>
40 #if !defined(NO_GETCHAR) || !defined(NO_PUTCHAR_HALT)
41 static int test_getchar(int *);
43 static void putonechar(int c
);
48 extern struct prom_vec prom_dispatch_v
;
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)
70 ret
.bits
= prom_dispatch(PROM_R_GETC
, console
);
72 return ret
.u
.status
== 0 || ret
.u
.status
== 1;
76 #if !defined(NO_GETCHAR)
83 if (test_getchar(&c
)) {
99 ret
.bits
= prom_dispatch(PROM_R_PUTS
, console
, &cbuf
, 1);
100 } while ((ret
.u
.retval
& 1) == 0);
106 #if !defined(NO_PUTCHAR_HALT)
110 if (c
== '\r' || c
== '\n') {
115 #if !defined(NO_PUTCHAR_HALT)
116 if (test_getchar(&typed_c
))
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)));
134 ret
.bits
= prom_dispatch(PROM_R_GETENV
, id
, abuf
, 128);
135 if (ret
.u
.status
& 0x4)
137 len
= min(len
- 1, ret
.u
.retval
);
138 memcpy(buf
, abuf
, len
);