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