1 /* $OpenBSD: prom.c,v 1.1 2023/03/11 20:56:01 miod Exp $ */
2 /* $NetBSD: prom.c,v 1.2 1996/11/25 16:18:16 cgd Exp $ */
3
4 /*
5 * Mach Operating System
6 * Copyright (c) 1992 Carnegie Mellon University
7 * All Rights Reserved.
8 *
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie Mellon
27 * the rights to redistribute these changes.
28 */
29
30 #include <lib/libsa/stand.h>
31
32 #include <sys/types.h>
33 #include <machine/rpb.h>
34 #include <machine/prom.h>
35
36 void
init_prom_calls()37 init_prom_calls()
38 {
39 extern struct prom_vec prom_dispatch_v;
40 struct rpb *r;
41 struct crb *c;
42
43 r = (struct rpb *)HWRPB_ADDR;
44 c = (struct crb *)((u_int8_t *)r + r->rpb_crb_off);
45
46 prom_dispatch_v.routine_arg = c->crb_v_dispatch;
47 prom_dispatch_v.routine = c->crb_v_dispatch->entry_va;
48 }
49
50 int
prom_getenv(id,buf,len)51 prom_getenv(id, buf, len)
52 int id, len;
53 char *buf;
54 {
55 /*
56 * On at least some systems, the GETENV call requires a
57 * 8-byte-aligned buffer, or it bails out with a "kernel stack
58 * not valid halt". Provide a local, aligned buffer here and
59 * then copy to the caller's buffer.
60 */
61 static char abuf[128] __attribute__ ((aligned (8)));
62 prom_return_t ret;
63
64 ret.bits = prom_dispatch(PROM_R_GETENV, id, (u_int64_t)abuf, 128, 0);
65 if (ret.u.status & 0x4)
66 ret.u.retval = 0;
67 len--;
68 if (len > ret.u.retval)
69 len = ret.u.retval;
70 memcpy(buf, abuf, len);
71 buf[len] = '\0';
72
73 return (len);
74 }
75