bootinfo.c revision 138249
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: head/sys/boot/i386/libi386/bootinfo.c 138249 2004-12-01 04:59:33Z scottl $"); 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 */ 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_ddb", RB_KDB}, 50 {"boot_gdb", RB_GDB}, 51 {"boot_single", RB_SINGLE}, 52 {"boot_verbose", RB_VERBOSE}, 53 {"boot_multicons", RB_MULTIPLE}, 54 {"boot_serial", RB_SERIAL}, 55 {NULL, 0} 56}; 57 58int 59bi_getboothowto(char *kargs) 60{ 61 char *cp; 62 int howto; 63 int active; 64 int i; 65 66 /* Parse kargs */ 67 howto = 0; 68 if (kargs != NULL) { 69 cp = kargs; 70 active = 0; 71 while (*cp != 0) { 72 if (!active && (*cp == '-')) { 73 active = 1; 74 } else if (active) 75 switch (*cp) { 76 case 'a': 77 howto |= RB_ASKNAME; 78 break; 79 case 'C': 80 howto |= RB_CDROM; 81 break; 82 case 'd': 83 howto |= RB_KDB; 84 break; 85 case 'D': 86 howto |= RB_MULTIPLE; 87 break; 88 case 'm': 89 howto |= RB_MUTE; 90 break; 91 case 'g': 92 howto |= RB_GDB; 93 break; 94 case 'h': 95 howto |= RB_SERIAL; 96 break; 97 case 'p': 98 howto |= RB_PAUSE; 99 break; 100 case 'r': 101 howto |= RB_DFLTROOT; 102 break; 103 case 's': 104 howto |= RB_SINGLE; 105 break; 106 case 'v': 107 howto |= RB_VERBOSE; 108 break; 109 default: 110 active = 0; 111 break; 112 } 113 cp++; 114 } 115 } 116 /* get equivalents from the environment */ 117 for (i = 0; howto_names[i].ev != NULL; i++) 118 if (getenv(howto_names[i].ev) != NULL) 119 howto |= howto_names[i].mask; 120 if (!strcmp(getenv("console"), "comconsole")) 121 howto |= RB_SERIAL; 122 if (!strcmp(getenv("console"), "nullconsole")) 123 howto |= RB_MUTE; 124 return(howto); 125} 126 127/* 128 * Copy the environment into the load area starting at (addr). 129 * Each variable is formatted as <name>=<value>, with a single nul 130 * separating each variable, and a double nul terminating the environment. 131 */ 132vm_offset_t 133bi_copyenv(vm_offset_t addr) 134{ 135 struct env_var *ep; 136 137 /* traverse the environment */ 138 for (ep = environ; ep != NULL; ep = ep->ev_next) { 139 i386_copyin(ep->ev_name, addr, strlen(ep->ev_name)); 140 addr += strlen(ep->ev_name); 141 i386_copyin("=", addr, 1); 142 addr++; 143 if (ep->ev_value != NULL) { 144 i386_copyin(ep->ev_value, addr, strlen(ep->ev_value)); 145 addr += strlen(ep->ev_value); 146 } 147 i386_copyin("", addr, 1); 148 addr++; 149 } 150 i386_copyin("", addr, 1); 151 addr++; 152 return(addr); 153} 154