xref: /freebsd/stand/i386/libi386/bootinfo.c (revision b027d6545b60535c1c01508bc6f1254b2a2c3b94)
1 /*-
2  * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <stand.h>
31 #include <sys/param.h>
32 #include <sys/reboot.h>
33 #include <sys/linker.h>
34 #include "bootstrap.h"
35 #include "libi386.h"
36 #include "btxv86.h"
37 
38 int
39 bi_getboothowto(char *kargs)
40 {
41     char	*cp;
42     char	*curpos, *next, *string;
43     int		howto;
44     int		active;
45     int		vidconsole;
46 
47     /* Parse kargs */
48     howto = 0;
49     if (kargs  != NULL) {
50 	cp = kargs;
51 	active = 0;
52 	while (*cp != 0) {
53 	    if (!active && (*cp == '-')) {
54 		active = 1;
55 	    } else if (active)
56 		switch (*cp) {
57 		case 'a':
58 		    howto |= RB_ASKNAME;
59 		    break;
60 		case 'C':
61 		    howto |= RB_CDROM;
62 		    break;
63 		case 'd':
64 		    howto |= RB_KDB;
65 		    break;
66 		case 'D':
67 		    howto |= RB_MULTIPLE;
68 		    break;
69 		case 'm':
70 		    howto |= RB_MUTE;
71 		    break;
72 		case 'g':
73 		    howto |= RB_GDB;
74 		    break;
75 		case 'h':
76 		    howto |= RB_SERIAL;
77 		    break;
78 		case 'p':
79 		    howto |= RB_PAUSE;
80 		    break;
81 		case 'r':
82 		    howto |= RB_DFLTROOT;
83 		    break;
84 		case 's':
85 		    howto |= RB_SINGLE;
86 		    break;
87 		case 'v':
88 		    howto |= RB_VERBOSE;
89 		    break;
90 		default:
91 		    active = 0;
92 		    break;
93 		}
94 	    cp++;
95 	}
96     }
97     howto |= bootenv_flags();
98 
99     /* Enable selected consoles */
100     string = next = strdup(getenv("console"));
101     vidconsole = 0;
102     while (next != NULL) {
103 	curpos = strsep(&next, " ,");
104 	if (*curpos == '\0')
105 		continue;
106 	if (!strcmp(curpos, "vidconsole"))
107 	    vidconsole = 1;
108 	else if (!strcmp(curpos, "comconsole"))
109 	    howto |= RB_SERIAL;
110 	else if (!strcmp(curpos, "nullconsole"))
111 	    howto |= RB_MUTE;
112     }
113 
114     if (vidconsole && (howto & RB_SERIAL))
115 	howto |= RB_MULTIPLE;
116 
117     /*
118      * XXX: Note that until the kernel is ready to respect multiple consoles
119      * for the boot messages, the first named console is the primary console
120      */
121     if (!strcmp(string, "vidconsole"))
122 	howto &= ~RB_SERIAL;
123 
124     free(string);
125 
126     return(howto);
127 }
128 
129 void
130 bi_setboothowto(int howto)
131 {
132 
133     bootenv_set(howto);
134 }
135 
136 /*
137  * Copy the environment into the load area starting at (addr).
138  * Each variable is formatted as <name>=<value>, with a single nul
139  * separating each variable, and a double nul terminating the environment.
140  */
141 vm_offset_t
142 bi_copyenv(vm_offset_t addr)
143 {
144     struct env_var	*ep;
145 
146     /* traverse the environment */
147     for (ep = environ; ep != NULL; ep = ep->ev_next) {
148 	i386_copyin(ep->ev_name, addr, strlen(ep->ev_name));
149 	addr += strlen(ep->ev_name);
150 	i386_copyin("=", addr, 1);
151 	addr++;
152 	if (ep->ev_value != NULL) {
153 	    i386_copyin(ep->ev_value, addr, strlen(ep->ev_value));
154 	    addr += strlen(ep->ev_value);
155 	}
156 	i386_copyin("", addr, 1);
157 	addr++;
158     }
159     i386_copyin("", addr, 1);
160     addr++;
161     return(addr);
162 }
163