bootinfo.c revision 114379
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: head/sys/boot/i386/libi386/bootinfo.c 114379 2003-05-01 03:56:30Z peter $ 27 */ 28 29#include <stand.h> 30#include <sys/param.h> 31#include <sys/reboot.h> 32#include <sys/linker.h> 33#include "bootstrap.h" 34#include "libi386.h" 35#include "btxv86.h" 36 37/* 38 * Return a 'boothowto' value corresponding to the kernel arguments in 39 * (kargs) and any relevant environment variables. 40 */ 41static struct 42{ 43 const char *ev; 44 int mask; 45} howto_names[] = { 46 {"boot_askname", RB_ASKNAME}, 47 {"boot_cdrom", RB_CDROM}, 48 {"boot_userconfig", RB_CONFIG}, 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_CONFIG; 81 break; 82 case 'C': 83 howto |= RB_CDROM; 84 break; 85 case 'd': 86 howto |= RB_KDB; 87 break; 88 case 'D': 89 howto |= RB_MULTIPLE; 90 break; 91 case 'm': 92 howto |= RB_MUTE; 93 break; 94 case 'g': 95 howto |= RB_GDB; 96 break; 97 case 'h': 98 howto |= RB_SERIAL; 99 break; 100 case 'p': 101 howto |= RB_PAUSE; 102 break; 103 case 'r': 104 howto |= RB_DFLTROOT; 105 break; 106 case 's': 107 howto |= RB_SINGLE; 108 break; 109 case 'v': 110 howto |= RB_VERBOSE; 111 break; 112 default: 113 active = 0; 114 break; 115 } 116 cp++; 117 } 118 } 119 /* get equivalents from the environment */ 120 for (i = 0; howto_names[i].ev != NULL; i++) 121 if (getenv(howto_names[i].ev) != NULL) 122 howto |= howto_names[i].mask; 123 if (!strcmp(getenv("console"), "comconsole")) 124 howto |= RB_SERIAL; 125 if (!strcmp(getenv("console"), "nullconsole")) 126 howto |= RB_MUTE; 127 return(howto); 128} 129 130/* 131 * Copy the environment into the load area starting at (addr). 132 * Each variable is formatted as <name>=<value>, with a single nul 133 * separating each variable, and a double nul terminating the environment. 134 */ 135vm_offset_t 136bi_copyenv(vm_offset_t addr) 137{ 138 struct env_var *ep; 139 140 /* traverse the environment */ 141 for (ep = environ; ep != NULL; ep = ep->ev_next) { 142 i386_copyin(ep->ev_name, addr, strlen(ep->ev_name)); 143 addr += strlen(ep->ev_name); 144 i386_copyin("=", addr, 1); 145 addr++; 146 if (ep->ev_value != NULL) { 147 i386_copyin(ep->ev_value, addr, strlen(ep->ev_value)); 148 addr += strlen(ep->ev_value); 149 } 150 i386_copyin("", addr, 1); 151 addr++; 152 } 153 i386_copyin("", addr, 1); 154 addr++; 155 return(addr); 156} 157