1*e7cbe64fSgw25295 /*
2*e7cbe64fSgw25295 * CDDL HEADER START
3*e7cbe64fSgw25295 *
4*e7cbe64fSgw25295 * The contents of this file are subject to the terms of the
5*e7cbe64fSgw25295 * Common Development and Distribution License (the "License").
6*e7cbe64fSgw25295 * You may not use this file except in compliance with the License.
7*e7cbe64fSgw25295 *
8*e7cbe64fSgw25295 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*e7cbe64fSgw25295 * or http://www.opensolaris.org/os/licensing.
10*e7cbe64fSgw25295 * See the License for the specific language governing permissions
11*e7cbe64fSgw25295 * and limitations under the License.
12*e7cbe64fSgw25295 *
13*e7cbe64fSgw25295 * When distributing Covered Code, include this CDDL HEADER in each
14*e7cbe64fSgw25295 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*e7cbe64fSgw25295 * If applicable, add the following below this CDDL HEADER, with the
16*e7cbe64fSgw25295 * fields enclosed by brackets "[]" replaced with your own identifying
17*e7cbe64fSgw25295 * information: Portions Copyright [yyyy] [name of copyright owner]
18*e7cbe64fSgw25295 *
19*e7cbe64fSgw25295 * CDDL HEADER END
20*e7cbe64fSgw25295 */
21*e7cbe64fSgw25295 /*
22*e7cbe64fSgw25295 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23*e7cbe64fSgw25295 * Use is subject to license terms.
24*e7cbe64fSgw25295 */
25*e7cbe64fSgw25295 #pragma ident "%Z%%M% %I% %E% SMI"
26*e7cbe64fSgw25295
27*e7cbe64fSgw25295 #include <sys/sysmacros.h>
28*e7cbe64fSgw25295 #include <sys/salib.h>
29*e7cbe64fSgw25295 #include <sys/promif.h>
30*e7cbe64fSgw25295
31*e7cbe64fSgw25295 #define MINALLOC 8
32*e7cbe64fSgw25295 #define TOPMEM ((caddr_t)0x1000000)
33*e7cbe64fSgw25295
34*e7cbe64fSgw25295 extern caddr_t _end;
35*e7cbe64fSgw25295 extern struct boot_fs_ops promfs_ops;
36*e7cbe64fSgw25295
37*e7cbe64fSgw25295 struct boot_fs_ops *boot_fsw[] = {
38*e7cbe64fSgw25295 &promfs_ops,
39*e7cbe64fSgw25295 };
40*e7cbe64fSgw25295 int boot_nfsw = sizeof (boot_fsw) / sizeof (boot_fsw[0]);
41*e7cbe64fSgw25295
42*e7cbe64fSgw25295 void *
bkmem_alloc(size_t s)43*e7cbe64fSgw25295 bkmem_alloc(size_t s)
44*e7cbe64fSgw25295 {
45*e7cbe64fSgw25295 static caddr_t next;
46*e7cbe64fSgw25295 caddr_t ret;
47*e7cbe64fSgw25295
48*e7cbe64fSgw25295 if (next == NULL)
49*e7cbe64fSgw25295 next = (caddr_t)roundup((uintptr_t)&_end, MINALLOC);
50*e7cbe64fSgw25295 ret = next;
51*e7cbe64fSgw25295 next += roundup(s, MINALLOC);
52*e7cbe64fSgw25295 if (next >= TOPMEM)
53*e7cbe64fSgw25295 prom_panic("out of memory");
54*e7cbe64fSgw25295 return (ret);
55*e7cbe64fSgw25295 }
56*e7cbe64fSgw25295
57*e7cbe64fSgw25295 /*ARGSUSED*/
58*e7cbe64fSgw25295 void
bkmem_free(void * p,size_t s)59*e7cbe64fSgw25295 bkmem_free(void *p, size_t s)
60*e7cbe64fSgw25295 {
61*e7cbe64fSgw25295 }
62*e7cbe64fSgw25295
63*e7cbe64fSgw25295 int
cons_getchar(void)64*e7cbe64fSgw25295 cons_getchar(void)
65*e7cbe64fSgw25295 {
66*e7cbe64fSgw25295 register int c;
67*e7cbe64fSgw25295
68*e7cbe64fSgw25295 while ((c = prom_mayget()) == -1)
69*e7cbe64fSgw25295 ;
70*e7cbe64fSgw25295 if (c == '\r') {
71*e7cbe64fSgw25295 prom_putchar(c);
72*e7cbe64fSgw25295 c = '\n';
73*e7cbe64fSgw25295 }
74*e7cbe64fSgw25295 if (c == 0177 || c == '\b') {
75*e7cbe64fSgw25295 prom_putchar('\b');
76*e7cbe64fSgw25295 prom_putchar(' ');
77*e7cbe64fSgw25295 c = '\b';
78*e7cbe64fSgw25295 }
79*e7cbe64fSgw25295 prom_putchar(c);
80*e7cbe64fSgw25295 return (c);
81*e7cbe64fSgw25295 }
82*e7cbe64fSgw25295
83*e7cbe64fSgw25295 char *
cons_gets(char * buf,int n)84*e7cbe64fSgw25295 cons_gets(char *buf, int n)
85*e7cbe64fSgw25295 {
86*e7cbe64fSgw25295 char *lp;
87*e7cbe64fSgw25295 char *limit;
88*e7cbe64fSgw25295 int c;
89*e7cbe64fSgw25295
90*e7cbe64fSgw25295 lp = buf;
91*e7cbe64fSgw25295 limit = &buf[n - 1];
92*e7cbe64fSgw25295 for (;;) {
93*e7cbe64fSgw25295 c = cons_getchar() & 0177;
94*e7cbe64fSgw25295 switch (c) {
95*e7cbe64fSgw25295 case '\n':
96*e7cbe64fSgw25295 case '\r':
97*e7cbe64fSgw25295 *lp = '\0';
98*e7cbe64fSgw25295 return (buf);
99*e7cbe64fSgw25295 case '\b':
100*e7cbe64fSgw25295 if (lp > buf)
101*e7cbe64fSgw25295 lp--;
102*e7cbe64fSgw25295 continue;
103*e7cbe64fSgw25295 case 'u'&037: /* ^U */
104*e7cbe64fSgw25295 lp = buf;
105*e7cbe64fSgw25295 prom_putchar('\r');
106*e7cbe64fSgw25295 prom_putchar('\n');
107*e7cbe64fSgw25295 continue;
108*e7cbe64fSgw25295 case 0:
109*e7cbe64fSgw25295 continue;
110*e7cbe64fSgw25295 default:
111*e7cbe64fSgw25295 if (lp < limit)
112*e7cbe64fSgw25295 *lp++ = (char)c;
113*e7cbe64fSgw25295 else
114*e7cbe64fSgw25295 prom_putchar('\a'); /* bell */
115*e7cbe64fSgw25295 }
116*e7cbe64fSgw25295 }
117*e7cbe64fSgw25295 }
118