Fully synchronize sys/boot from FreeBSD-5.x, but add / to the module path
[dragonfly.git] / sys / boot / pc32 / libi386 / bootinfo.c
CommitLineData
984263bc
MD
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 *
5ee58eed
MD
26 * $FreeBSD: src/sys/boot/i386/libi386/bootinfo.c,v 1.35 2003/08/25 23:28:31 obrien Exp $
27 * $DragonFly: src/sys/boot/pc32/libi386/bootinfo.c,v 1.3 2003/11/10 06:08:36 dillon Exp $
984263bc
MD
28 */
29
30#include <stand.h>
31#include <sys/param.h>
32#include <sys/reboot.h>
33#include <sys/linker.h>
984263bc
MD
34#include "bootstrap.h"
35#include "libi386.h"
36#include "btxv86.h"
37
984263bc
MD
38/*
39 * Return a 'boothowto' value corresponding to the kernel arguments in
40 * (kargs) and any relevant environment variables.
41 */
42static struct
43{
44 const char *ev;
45 int mask;
46} howto_names[] = {
47 {"boot_askname", RB_ASKNAME},
48 {"boot_cdrom", RB_CDROM},
49 {"boot_userconfig", RB_CONFIG},
50 {"boot_ddb", RB_KDB},
51 {"boot_gdb", RB_GDB},
52 {"boot_single", RB_SINGLE},
53 {"boot_verbose", RB_VERBOSE},
5ee58eed
MD
54 {"boot_multicons", RB_MULTIPLE},
55 {"boot_serial", RB_SERIAL},
984263bc
MD
56 {NULL, 0}
57};
58
984263bc
MD
59int
60bi_getboothowto(char *kargs)
61{
62 char *cp;
63 int howto;
64 int active;
65 int i;
66
67 /* Parse kargs */
68 howto = 0;
69 if (kargs != NULL) {
70 cp = kargs;
71 active = 0;
72 while (*cp != 0) {
73 if (!active && (*cp == '-')) {
74 active = 1;
75 } else if (active)
76 switch (*cp) {
77 case 'a':
78 howto |= RB_ASKNAME;
79 break;
80 case 'c':
81 howto |= RB_CONFIG;
82 break;
83 case 'C':
84 howto |= RB_CDROM;
85 break;
86 case 'd':
87 howto |= RB_KDB;
88 break;
5ee58eed
MD
89 case 'D':
90 howto |= RB_MULTIPLE;
91 break;
984263bc
MD
92 case 'm':
93 howto |= RB_MUTE;
94 break;
95 case 'g':
96 howto |= RB_GDB;
97 break;
98 case 'h':
99 howto |= RB_SERIAL;
100 break;
101 case 'p':
102 howto |= RB_PAUSE;
103 break;
104 case 'r':
105 howto |= RB_DFLTROOT;
106 break;
107 case 's':
108 howto |= RB_SINGLE;
109 break;
110 case 'v':
111 howto |= RB_VERBOSE;
112 break;
113 default:
114 active = 0;
115 break;
116 }
117 cp++;
118 }
119 }
120 /* get equivalents from the environment */
121 for (i = 0; howto_names[i].ev != NULL; i++)
122 if (getenv(howto_names[i].ev) != NULL)
123 howto |= howto_names[i].mask;
124 if (!strcmp(getenv("console"), "comconsole"))
125 howto |= RB_SERIAL;
126 if (!strcmp(getenv("console"), "nullconsole"))
127 howto |= RB_MUTE;
128 return(howto);
129}
130
131/*
132 * Copy the environment into the load area starting at (addr).
133 * Each variable is formatted as <name>=<value>, with a single nul
134 * separating each variable, and a double nul terminating the environment.
135 */
136vm_offset_t
137bi_copyenv(vm_offset_t addr)
138{
139 struct env_var *ep;
140
141 /* traverse the environment */
142 for (ep = environ; ep != NULL; ep = ep->ev_next) {
143 i386_copyin(ep->ev_name, addr, strlen(ep->ev_name));
144 addr += strlen(ep->ev_name);
145 i386_copyin("=", addr, 1);
146 addr++;
147 if (ep->ev_value != NULL) {
148 i386_copyin(ep->ev_value, addr, strlen(ep->ev_value));
149 addr += strlen(ep->ev_value);
150 }
151 i386_copyin("", addr, 1);
152 addr++;
153 }
154 i386_copyin("", addr, 1);
155 addr++;
156 return(addr);
157}