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