Implement duel-console mode and make it the default. Adjust the boot
[dragonfly.git] / sys / boot / pc32 / libi386 / bootinfo.c
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  * $DragonFly: src/sys/boot/pc32/libi386/bootinfo.c,v 1.4 2004/06/25 05:37:58 dillon Exp $
28  */
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 /*
39  * Return a 'boothowto' value corresponding to the kernel arguments in
40  * (kargs) and any relevant environment variables.
41  */
42 static 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},
54     {"boot_vidcons",    RB_VIDEO},
55     {"boot_serial",     RB_SERIAL},
56     {NULL,      0}
57 };
58
59 int
60 bi_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;
89                 case 'D':
90                     /* all available consoles become active */
91                     howto &= ~(RB_MUTE|RB_VIDEO|RB_SERIAL);
92                     break;
93                 case 'V':
94                     howto |= RB_VIDEO;
95                     break;
96                 case 'm':
97                     howto |= RB_MUTE;
98                     break;
99                 case 'g':
100                     howto |= RB_GDB;
101                     break;
102                 case 'h':
103                     howto |= RB_SERIAL;
104                     break;
105                 case 'p':
106                     howto |= RB_PAUSE;
107                     break;
108                 case 'r':
109                     howto |= RB_DFLTROOT;
110                     break;
111                 case 's':
112                     howto |= RB_SINGLE;
113                     break;
114                 case 'v':
115                     howto |= RB_VERBOSE;
116                     break;
117                 default:
118                     active = 0;
119                     break;
120                 }
121             cp++;
122         }
123     }
124     /* get equivalents from the environment */
125     for (i = 0; howto_names[i].ev != NULL; i++)
126         if (getenv(howto_names[i].ev) != NULL)
127             howto |= howto_names[i].mask;
128     if (!strcmp(getenv("console"), "comconsole"))
129         howto |= RB_SERIAL;
130     if (!strcmp(getenv("console"), "nullconsole"))
131         howto |= RB_MUTE;
132     if (!strcmp(getenv("console"), "vidconsole"))
133         howto |= RB_VIDEO;
134     return(howto);
135 }
136
137 /*
138  * Copy the environment into the load area starting at (addr).
139  * Each variable is formatted as <name>=<value>, with a single nul
140  * separating each variable, and a double nul terminating the environment.
141  */
142 vm_offset_t
143 bi_copyenv(vm_offset_t addr)
144 {
145     struct env_var      *ep;
146     
147     /* traverse the environment */
148     for (ep = environ; ep != NULL; ep = ep->ev_next) {
149         i386_copyin(ep->ev_name, addr, strlen(ep->ev_name));
150         addr += strlen(ep->ev_name);
151         i386_copyin("=", addr, 1);
152         addr++;
153         if (ep->ev_value != NULL) {
154             i386_copyin(ep->ev_value, addr, strlen(ep->ev_value));
155             addr += strlen(ep->ev_value);
156         }
157         i386_copyin("", addr, 1);
158         addr++;
159     }
160     i386_copyin("", addr, 1);
161     addr++;
162     return(addr);
163 }