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