bootinfo.c revision 335755
12061Sjkh/*- 250479Speter * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 32061Sjkh * All rights reserved. 438666Sjb * 532427Sjb * Redistribution and use in source and binary forms, with or without 6111131Sru * modification, are permitted provided that the following conditions 7111131Sru * are met: 8217733Sbz * 1. Redistributions of source code must retain the above copyright 9217733Sbz * notice, this list of conditions and the following disclaimer. 1038666Sjb * 2. Redistributions in binary form must reproduce the above copyright 1138666Sjb * notice, this list of conditions and the following disclaimer in the 1238666Sjb * documentation and/or other materials provided with the distribution. 13159363Strhodes * 1464049Salex * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1564049Salex * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16116679Ssimokawa * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1766071Smarkm * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18116679Ssimokawa * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1973504Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20204661Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21158962Snetchild * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2238666Sjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23169597Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24169597Sdes * SUCH DAMAGE. 25169597Sdes */ 26169597Sdes 27169597Sdes#include <sys/cdefs.h> 28169597Sdes__FBSDID("$FreeBSD: stable/11/stand/i386/libi386/bootinfo.c 335755 2018-06-28 01:32:37Z kevans $"); 29169597Sdes 30169597Sdes#include <stand.h> 31217815Sbz#include <sys/param.h> 32217815Sbz#include <sys/reboot.h> 3332427Sjb#include <sys/linker.h> 3438666Sjb#include "bootstrap.h" 35108451Sschweikh#include "libi386.h" 3638666Sjb#include "btxv86.h" 3738666Sjb 3838666Sjbint 3938666Sjbbi_getboothowto(char *kargs) 4017308Speter{ 41217273Simp char *cp; 42217294Simp char *curpos, *next, *string; 4319175Sbde int howto; 4496205Sjwd int active; 45217297Simp int vidconsole; 46217297Simp 4738042Sbde /* Parse kargs */ 4896205Sjwd howto = 0; 4996205Sjwd if (kargs != NULL) { 5038042Sbde cp = kargs; 5196205Sjwd active = 0; 52159363Strhodes while (*cp != 0) { 53159363Strhodes if (!active && (*cp == '-')) { 5417308Speter active = 1; 5596205Sjwd } else if (active) 5696205Sjwd switch (*cp) { 5717308Speter case 'a': 58148330Snetchild howto |= RB_ASKNAME; 59148330Snetchild break; 60148330Snetchild case 'C': 61148330Snetchild howto |= RB_CDROM; 62159831Sobrien break; 63148330Snetchild case 'd': 64148330Snetchild howto |= RB_KDB; 65148330Snetchild break; 66148330Snetchild case 'D': 67178653Srwatson howto |= RB_MULTIPLE; 68148330Snetchild break; 69148330Snetchild case 'm': 7096205Sjwd howto |= RB_MUTE; 7196205Sjwd break; 7296205Sjwd case 'g': 73162147Sru howto |= RB_GDB; 74162147Sru break; 7598723Sdillon case 'h': 7698723Sdillon howto |= RB_SERIAL; 7798723Sdillon break; 7838666Sjb case 'p': 7938666Sjb howto |= RB_PAUSE; 8017308Speter break; 81123311Speter case 'r': 82123311Speter howto |= RB_DFLTROOT; 83123311Speter break; 84123311Speter case 's': 85175833Sjhb howto |= RB_SINGLE; 86175833Sjhb break; 87169597Sdes case 'v': 88169597Sdes howto |= RB_VERBOSE; 89169597Sdes break; 90169597Sdes default: 91159349Simp active = 0; 92158962Snetchild break; 93158962Snetchild } 94158962Snetchild cp++; 95156840Sru } 96123311Speter } 97137288Speter howto |= bootenv_flags(); 98209128Sraj 99209128Sraj /* Enable selected consoles */ 100156740Sru string = next = strdup(getenv("console")); 1012061Sjkh vidconsole = 0; 10297769Sru while (next != NULL) { 10397252Sru curpos = strsep(&next, " ,"); 104119579Sru if (*curpos == '\0') 10597252Sru continue; 10695730Sru if (!strcmp(curpos, "vidconsole")) 10795793Sru vidconsole = 1; 108111617Sru else if (!strcmp(curpos, "comconsole")) 10995730Sru howto |= RB_SERIAL; 110116679Ssimokawa else if (!strcmp(curpos, "nullconsole")) 11195730Sru howto |= RB_MUTE; 112116679Ssimokawa } 11395730Sru 114110035Sru if (vidconsole && (howto & RB_SERIAL)) 115107516Sru howto |= RB_MULTIPLE; 116138921Sru 117156145Syar /* 118138921Sru * XXX: Note that until the kernel is ready to respect multiple consoles 119133942Sru * for the boot messages, the first named console is the primary console 120133942Sru */ 121156145Syar if (!strcmp(string, "vidconsole")) 122133942Sru howto &= ~RB_SERIAL; 123110035Sru 124117234Sru free(string); 125110035Sru 126117229Sru return(howto); 127117234Sru} 12854324Smarcel 129218130Simpvoid 130218130Simpbi_setboothowto(int howto) 131218130Simp{ 132218130Simp 133218130Simp bootenv_set(howto); 134218130Simp} 135218130Simp 136218130Simp/* 137218130Simp * Copy the environment into the load area starting at (addr). 138218130Simp * Each variable is formatted as <name>=<value>, with a single nul 139218130Simp * separating each variable, and a double nul terminating the environment. 140218130Simp */ 141218130Simpvm_offset_t 142218130Simpbi_copyenv(vm_offset_t addr) 143218130Simp{ 144218130Simp struct env_var *ep; 145218130Simp 146218130Simp /* traverse the environment */ 147218130Simp for (ep = environ; ep != NULL; ep = ep->ev_next) { 148218130Simp i386_copyin(ep->ev_name, addr, strlen(ep->ev_name)); 149218130Simp addr += strlen(ep->ev_name); 150218130Simp i386_copyin("=", addr, 1); 151218130Simp addr++; 152218130Simp if (ep->ev_value != NULL) { 153218130Simp i386_copyin(ep->ev_value, addr, strlen(ep->ev_value)); 154218130Simp addr += strlen(ep->ev_value); 155218130Simp } 156218130Simp i386_copyin("", addr, 1); 157218130Simp addr++; 158218130Simp } 159218130Simp i386_copyin("", addr, 1); 160218130Simp addr++; 16117308Speter return(addr); 162119519Smarcel} 163119519Smarcel