xref: /dragonfly/stand/boot/pc32/libi386/bootinfo.c (revision 655933d6)
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  * $FreeBSD: src/sys/boot/i386/libi386/bootinfo.c,v 1.35 2003/08/25 23:28:31 obrien Exp $
27  */
28 
29 #include <stand.h>
30 #include <sys/param.h>
31 #include <sys/reboot.h>
32 #include <sys/boot.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     int		howto;
43     int		active;
44     int		i;
45 
46     /* Parse kargs */
47     howto = 0;
48     if (kargs  != NULL) {
49 	cp = kargs;
50 	active = 0;
51 	while (*cp != 0) {
52 	    if (!active && (*cp == '-')) {
53 		active = 1;
54 	    } else if (active)
55 		switch (*cp) {
56 		case 'a':
57 		    howto |= RB_ASKNAME;
58 		    break;
59 		case 'C':
60 		    howto |= RB_CDROM;
61 		    break;
62 		case 'd':
63 		    howto |= RB_KDB;
64 		    break;
65 		case 'D':
66 		    /* all available consoles become active */
67 		    howto &= ~(RB_MUTE|RB_VIDEO|RB_SERIAL);
68 		    break;
69 		case 'V':
70 		    howto |= RB_VIDEO;
71 		    break;
72 		case 'm':
73 		    howto |= RB_MUTE;
74 		    break;
75 		case 'g':
76 		    howto |= RB_GDB;
77 		    break;
78 		case 'h':
79 		    howto |= RB_SERIAL;
80 		    break;
81 		case 'p':
82 		    howto |= RB_PAUSE;
83 		    break;
84 		case 'r':
85 		    howto |= RB_DFLTROOT;
86 		    break;
87 		case 's':
88 		    howto |= RB_SINGLE;
89 		    break;
90 		case 'v':
91 		    howto |= RB_VERBOSE;
92 		    break;
93 		default:
94 		    active = 0;
95 		    break;
96 		}
97 	    cp++;
98 	}
99     }
100     /* get equivalents from the environment */
101     for (i = 0; howto_names[i].ev != NULL; i++)
102 	if (getenv(howto_names[i].ev) != NULL)
103 	    howto |= howto_names[i].mask;
104     if (!strcmp(getenv("console"), "comconsole"))
105 	howto |= RB_SERIAL;
106     if (!strcmp(getenv("console"), "nullconsole"))
107 	howto |= RB_MUTE;
108     if (!strcmp(getenv("console"), "vidconsole"))
109 	howto |= RB_VIDEO;
110     return(howto);
111 }
112 
113 /*
114  * Copy the environment into the load area starting at (addr).
115  * Each variable is formatted as <name>=<value>, with a single nul
116  * separating each variable, and a double nul terminating the environment.
117  */
118 vm_offset_t
119 bi_copyenv(vm_offset_t addr)
120 {
121     struct env_var	*ep;
122 
123     /* traverse the environment */
124     for (ep = environ; ep != NULL; ep = ep->ev_next) {
125 	i386_copyin(ep->ev_name, addr, strlen(ep->ev_name));
126 	addr += strlen(ep->ev_name);
127 	i386_copyin("=", addr, 1);
128 	addr++;
129 	if (ep->ev_value != NULL) {
130 	    i386_copyin(ep->ev_value, addr, strlen(ep->ev_value));
131 	    addr += strlen(ep->ev_value);
132 	}
133 	i386_copyin("", addr, 1);
134 	addr++;
135     }
136     i386_copyin("", addr, 1);
137     addr++;
138     return(addr);
139 }
140