138465Smsmith/*- 238465Smsmith * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 338465Smsmith * All rights reserved. 438465Smsmith * 538465Smsmith * Redistribution and use in source and binary forms, with or without 638465Smsmith * modification, are permitted provided that the following conditions 738465Smsmith * are met: 838465Smsmith * 1. Redistributions of source code must retain the above copyright 938465Smsmith * notice, this list of conditions and the following disclaimer. 1038465Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1138465Smsmith * notice, this list of conditions and the following disclaimer in the 1238465Smsmith * documentation and/or other materials provided with the distribution. 1338465Smsmith * 1438465Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1538465Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1638465Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1738465Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1838465Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1938465Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2038465Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2138465Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2238465Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2338465Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2438465Smsmith * SUCH DAMAGE. 2538465Smsmith */ 2638465Smsmith 27119482Sobrien#include <sys/cdefs.h> 28119482Sobrien__FBSDID("$FreeBSD: stable/11/stand/i386/libi386/bootinfo.c 344378 2019-02-20 19:19:24Z kevans $"); 29119482Sobrien 3039902Smsmith#include <stand.h> 3139902Smsmith#include <sys/param.h> 3238465Smsmith#include <sys/reboot.h> 33344378Skevans#include <sys/boot.h> 3440146Speter#include <sys/linker.h> 3538465Smsmith#include "bootstrap.h" 3639902Smsmith#include "libi386.h" 3739902Smsmith#include "btxv86.h" 3838465Smsmith 3938465Smsmithint 4038465Smsmithbi_getboothowto(char *kargs) 4138465Smsmith{ 42146698Sjhb char *curpos, *next, *string; 4338465Smsmith int howto; 44146698Sjhb int vidconsole; 45146698Sjhb 46344378Skevans howto = boot_parse_cmdline(kargs); 47344378Skevans howto |= boot_env_to_howto(); 48146698Sjhb 49146698Sjhb /* Enable selected consoles */ 50146698Sjhb string = next = strdup(getenv("console")); 51146698Sjhb vidconsole = 0; 52146698Sjhb while (next != NULL) { 53146698Sjhb curpos = strsep(&next, " ,"); 54146698Sjhb if (*curpos == '\0') 55146698Sjhb continue; 56146698Sjhb if (!strcmp(curpos, "vidconsole")) 57146698Sjhb vidconsole = 1; 58146698Sjhb else if (!strcmp(curpos, "comconsole")) 59146698Sjhb howto |= RB_SERIAL; 60146698Sjhb else if (!strcmp(curpos, "nullconsole")) 61146698Sjhb howto |= RB_MUTE; 62146698Sjhb } 63146698Sjhb 64146698Sjhb if (vidconsole && (howto & RB_SERIAL)) 65146698Sjhb howto |= RB_MULTIPLE; 66146698Sjhb 67146698Sjhb /* 68146698Sjhb * XXX: Note that until the kernel is ready to respect multiple consoles 69146698Sjhb * for the boot messages, the first named console is the primary console 70146698Sjhb */ 71146698Sjhb if (!strcmp(string, "vidconsole")) 72146698Sjhb howto &= ~RB_SERIAL; 73146698Sjhb 74146698Sjhb free(string); 75146698Sjhb 7638465Smsmith return(howto); 7738465Smsmith} 7838465Smsmith 79150470Sruvoid 80150470Srubi_setboothowto(int howto) 81150470Sru{ 82150470Sru 83344378Skevans boot_howto_to_env(howto); 84150470Sru} 85150470Sru 8638465Smsmith/* 8738465Smsmith * Copy the environment into the load area starting at (addr). 8838465Smsmith * Each variable is formatted as <name>=<value>, with a single nul 8938465Smsmith * separating each variable, and a double nul terminating the environment. 9038465Smsmith */ 9138465Smsmithvm_offset_t 9238465Smsmithbi_copyenv(vm_offset_t addr) 9338465Smsmith{ 9438465Smsmith struct env_var *ep; 9538465Smsmith 9638465Smsmith /* traverse the environment */ 9738465Smsmith for (ep = environ; ep != NULL; ep = ep->ev_next) { 9839441Smsmith i386_copyin(ep->ev_name, addr, strlen(ep->ev_name)); 9938465Smsmith addr += strlen(ep->ev_name); 10039441Smsmith i386_copyin("=", addr, 1); 10138465Smsmith addr++; 10238465Smsmith if (ep->ev_value != NULL) { 10339441Smsmith i386_copyin(ep->ev_value, addr, strlen(ep->ev_value)); 10438465Smsmith addr += strlen(ep->ev_value); 10538465Smsmith } 10639441Smsmith i386_copyin("", addr, 1); 10738465Smsmith addr++; 10838465Smsmith } 10939441Smsmith i386_copyin("", addr, 1); 11038465Smsmith addr++; 11139730Speter return(addr); 11238465Smsmith} 113