diff --git a/stand/i386/libi386/bootinfo.c b/stand/i386/libi386/bootinfo.c index cc9a42164ed3..4f652632b755 100644 --- a/stand/i386/libi386/bootinfo.c +++ b/stand/i386/libi386/bootinfo.c @@ -1,103 +1,84 @@ /*- * Copyright (c) 1998 Michael Smith * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include #include #include #include #include "bootstrap.h" #include "libi386.h" #include "vbe.h" #include "btxv86.h" -void -bi_load_vbe_data(struct preloaded_file *kfp) -{ - if (!kfp->f_tg_kernel_support) { - /* - * Loaded kernel does not have vt/vbe backend, - * switch console to text mode. - */ - if (vbe_available()) - bios_set_text_mode(VGA_TEXT_MODE); - return; - } - - if (vbe_available()) { - file_addmetadata(kfp, MODINFOMD_VBE_FB, - sizeof(gfx_state.tg_fb), &gfx_state.tg_fb); - } -} - int bi_getboothowto(char *kargs) { char *curpos, *next, *string; int howto; int vidconsole; howto = boot_parse_cmdline(kargs); howto |= boot_env_to_howto(); /* Enable selected consoles */ string = next = strdup(getenv("console")); vidconsole = 0; while (next != NULL) { curpos = strsep(&next, " ,"); if (*curpos == '\0') continue; if (!strcmp(curpos, "vidconsole")) vidconsole = 1; else if (!strcmp(curpos, "comconsole")) howto |= RB_SERIAL; else if (!strcmp(curpos, "nullconsole")) howto |= RB_MUTE; } if (vidconsole && (howto & RB_SERIAL)) howto |= RB_MULTIPLE; /* * XXX: Note that until the kernel is ready to respect multiple consoles * for the boot messages, the first named console is the primary console */ if (!strcmp(string, "vidconsole")) howto &= ~RB_SERIAL; free(string); return(howto); } void bi_setboothowto(int howto) { boot_howto_to_env(howto); } diff --git a/stand/i386/loader/Makefile b/stand/i386/loader/Makefile index 525561b7c4d1..ab446d67225b 100644 --- a/stand/i386/loader/Makefile +++ b/stand/i386/loader/Makefile @@ -1,131 +1,145 @@ HAVE_ZFS= ${MK_LOADER_ZFS} LOADER_NET_SUPPORT?= yes LOADER_NFS_SUPPORT?= yes LOADER_TFTP_SUPPORT?= yes LOADER_CD9660_SUPPORT?= yes LOADER_EXT2FS_SUPPORT?= yes LOADER_MSDOS_SUPPORT?= yes LOADER_UFS_SUPPORT?= yes LOADER_GZIP_SUPPORT?= yes LOADER_BZIP2_SUPPORT?= yes .include LOADER?= loader_${LOADER_INTERP} PROG= ${LOADER}.sym INTERNALPROG= NEWVERSWHAT?= "bootstrap loader" x86 VERSION_FILE= ${.CURDIR}/../loader/version # # There's 640k - 40k maximum space, less however much memory the BIOS uses. A # non-random survey suggests that 20k-25k is a good value for 'most' machines. # We also need to subtract maximum stack usage (20-25k). # # So 640k - 40k - 25k - 25k = 550k = 563,200 bytes, but use 560,000 below for # some extra buffer for more complex setups and/or wider BIOS lomem variation. # # Some systems use more stack or have BIOS reserve more RAM (or both), and will # need to set this lower in /etc/src.conf if the above buffer is too small. # # sudo dd if=/dev/mem bs=1 iseek=0x413 count=2 | hd -d # # will tell you how many kiB of lomem are available. # LOADERSIZE?= 560000 # Largest known safe size for loader.bin .PATH: ${BOOTSRC}/i386/loader # architecture-specific loader code -SRCS= main.c conf.c vers.c chain.c gfx_fb.c 8x16.c +SRCS+= chain.c +SRCS+= conf.c +SRCS+= gfx_bios.c +SRCS+= main.c +SRCS+= vers.c + +.if ${MK_LOADER_BIOS_TEXTONLY} == "no" +SRCS+= gfx_fb.c +SRCS+= 8x16.c CFLAGS.gfx_fb.c += -I${.CURDIR}/../libi386 CFLAGS.gfx_fb.c += -I$(SRCTOP)/sys/teken CFLAGS.gfx_fb.c += -I${SRCTOP}/sys/cddl/contrib/opensolaris/common/lz4 CFLAGS.gfx_fb.c += -I${SRCTOP}/contrib/pnglite CFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib +CFLAGS.gfx_bios.c += -I$(SRCTOP)/sys/teken +CFLAGS.gfx_bios.c += -I${SRCTOP}/contrib/pnglite +.else +CFLAGS.gfx_bios.c += -DBIOS_TEXT_ONLY +CFLAGS.conf.c += -DBIOS_TEXT_ONLY +.endif # Include bcache code. HAVE_BCACHE= yes # Enable PnP and ISA-PnP code. HAVE_PNP= yes HAVE_ISABUS= yes .if ${MK_LOADER_ZFS} == "yes" CFLAGS.main.c+= -I${SYSDIR}/contrib/openzfs/include CFLAGS.main.c+= -I${SYSDIR}/contrib/openzfs/include/os/freebsd/zfs .endif .if exists(${.CURDIR}/help.i386) HELP_FILES= ${.CURDIR}/help.i386 .endif HELP_FILENAME= loader.help.bios # Always add MI sources .include "${BOOTSRC}/loader.mk" CLEANFILES+= ${LOADER} ${LOADER}.bin 8x16.c ORG= 0x0 CFLAGS+= -Wall LDFLAGS+= -static ${LDFLAGS_ORG} -Wl,--gc-sections .if ${LINKER_TYPE} == "lld" && ${LINKER_VERSION} >= 130000 # lld 13 and higher default to garbage collecting start/stop symbols, # completely ruining our linker sets. For now, work around it by # disabling this un-feature. LDFLAGS+= -Wl,-z,nostart-stop-gc .endif # i386 standalone support library LIBI386= ${BOOTOBJ}/i386/libi386/libi386.a CFLAGS+= -I${BOOTSRC}/i386 # Debug me! #CFLAGS+= -g #LDFLAGS+= -g 8x16.c: ${SRCTOP}/contrib/terminus/ter-u16b.bdf vtfontcvt -f compressed-source -o ${.TARGET} ${.ALLSRC} ${LOADER}: ${LOADER}.bin ${BTXLDR} ${BTXKERN} btxld -v -f aout -e ${LOADER_ADDRESS} -o ${.TARGET} -l ${BTXLDR} \ -b ${BTXKERN} ${LOADER}.bin ${LOADER}.bin: ${LOADER}.sym ${STRIPBIN} -R .comment -R .note -o ${.TARGET} ${.ALLSRC} @set -- `ls -l ${.TARGET}` ; x=$$((${LOADERSIZE}-$$5)); \ echo "$$x bytes available"; test $$x -ge 0 .if ${MK_LOADER_ZFS} == "yes" && ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP} LINKS+= ${BINDIR}/${LOADER} ${BINDIR}/zfsloader .endif .if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP} LINKS+= ${BINDIR}/${LOADER} ${BINDIR}/loader .endif FILES+= ${LOADER} FILESMODE_${LOADER}= ${BINMODE} -b # Note: crt0.o needs to be first for pxeboot(8) to work. It assumes that the # startup code is located at the start of the loader and will jump # there. Although btx is more flexible than this, the emulated boot2 environment # that pxeldr provides has none of that flexibility assumes an entry point of # 0. In addition, pxeldr and cdboot assume that it is loading an a.out file. # # We must add it to the LDFLAGS instead of the OBJS because the former won't try # to clean it. When it is in OBJS, this cleaning can lead to races where # btxcrt.o is rebuilt, but boot2 isn't, leading to errors at installation time. # LDFLAGS does not have this baggage and will be included first in the list of # files. LDFLAGS+= ${BTXCRT} DPADD= ${LDR_INTERP32} ${LIBI386} ${LIBSA32} LDADD= ${LDR_INTERP32} ${LIBI386} ${LIBSA32} .if ${MACHINE_CPUARCH} == "amd64" CFLAGS+= -DLOADER_PREFER_AMD64 .endif .include diff --git a/stand/i386/loader/conf.c b/stand/i386/loader/conf.c index 329bcd577fbe..b4e9f401ded7 100644 --- a/stand/i386/loader/conf.c +++ b/stand/i386/loader/conf.c @@ -1,153 +1,158 @@ /*- * Copyright (c) 1998 Michael Smith * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include #include #include "libi386/libi386.h" #if defined(LOADER_ZFS_SUPPORT) #include "libzfs.h" #endif /* * We could use linker sets for some or all of these, but * then we would have to control what ended up linked into * the bootstrap. So it's easier to conditionalise things * here. * * XXX rename these arrays to be consistent and less namespace-hostile * * XXX as libi386 and biosboot merge, some of these can become linker sets. */ extern struct devsw vdisk_dev; /* Exported for libsa */ struct devsw *devsw[] = { &biosfd, &bioscd, &bioshd, #if defined(LOADER_NFS_SUPPORT) || defined(LOADER_TFTP_SUPPORT) &pxedisk, #endif &vdisk_dev, #if defined(LOADER_ZFS_SUPPORT) &zfs_dev, #endif NULL }; struct fs_ops *file_system[] = { #if defined(LOADER_ZFS_SUPPORT) &zfs_fsops, #endif #if defined(LOADER_UFS_SUPPORT) &ufs_fsops, #endif #if defined(LOADER_EXT2FS_SUPPORT) &ext2fs_fsops, #endif #if defined(LOADER_MSDOS_SUPPORT) &dosfs_fsops, #endif #if defined(LOADER_CD9660_SUPPORT) &cd9660_fsops, #endif #ifdef LOADER_NFS_SUPPORT &nfs_fsops, #endif #ifdef LOADER_TFTP_SUPPORT &tftp_fsops, #endif #ifdef LOADER_GZIP_SUPPORT &gzipfs_fsops, #endif #ifdef LOADER_BZIP2_SUPPORT &bzipfs_fsops, #endif #ifdef LOADER_SPLIT_SUPPORT &splitfs_fsops, #endif NULL }; /* Exported for i386 only */ /* * Sort formats so that those that can detect based on arguments * rather than reading the file go first. */ extern struct file_format i386_elf; extern struct file_format i386_elf_obj; extern struct file_format amd64_elf; extern struct file_format amd64_elf_obj; extern struct file_format multiboot; extern struct file_format multiboot_obj; struct file_format *file_formats[] = { &multiboot, &multiboot_obj, #ifdef LOADER_PREFER_AMD64 &amd64_elf, &amd64_elf_obj, #endif &i386_elf, &i386_elf_obj, #ifndef LOADER_PREFER_AMD64 &amd64_elf, &amd64_elf_obj, #endif NULL }; /* * Consoles * * We don't prototype these in libi386.h because they require * data structures from bootstrap.h as well. */ +extern struct console textvidc; extern struct console vidconsole; extern struct console comconsole; extern struct console nullconsole; extern struct console spinconsole; struct console *consoles[] = { +#ifdef BIOS_TEXT_ONLY + &textvidc, +#else &vidconsole, +#endif &comconsole, &nullconsole, &spinconsole, NULL }; extern struct pnphandler isapnphandler; extern struct pnphandler biospnphandler; extern struct pnphandler biospcihandler; struct pnphandler *pnphandlers[] = { &biospnphandler, /* should go first, as it may set isapnp_readport */ &isapnphandler, &biospcihandler, NULL }; diff --git a/stand/i386/loader/gfx_bios.c b/stand/i386/loader/gfx_bios.c new file mode 100644 index 000000000000..a0b08a7cbcde --- /dev/null +++ b/stand/i386/loader/gfx_bios.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024 Netflix, Inc. + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +/* + * This file provides all the gfx glue, or stubs, so that we can build, if we + * want, two versions of the bios loader: one with graphics support and one + * without. This allows us to keep the calls in other places, like libraries + * that are tricky to compile twice. It also reduces the number of ifdefs we + * need to support the old text-only video console. This could also be two + * separate files, but it is short and having it all here helps to constrain + * dependency creap somewhat. + */ + +#include +#ifndef BIOS_TEXT_ONLY +#include "bootstrap.h" +#include "libi386/libi386.h" +#include "libi386/vbe.h" +#include +#endif + +#ifdef BIOS_TEXT_ONLY +void autoload_font(bool bios); + +void +autoload_font(bool bios) +{ +} + +vm_offset_t build_font_module(vm_offset_t addr); + +vm_offset_t +build_font_module(vm_offset_t addr) +{ + return addr; +} + +struct preloaded_file; +void bi_load_vbe_data(struct preloaded_file *kfp); + +void bi_load_vbe_data(struct preloaded_file *kfp) +{ +} + +#else + +void +bi_load_vbe_data(struct preloaded_file *kfp) +{ + if (!kfp->f_tg_kernel_support) { + /* + * Loaded kernel does not have vt/vbe backend, + * switch console to text mode. + */ + if (vbe_available()) + bios_set_text_mode(VGA_TEXT_MODE); + return; + } + + if (vbe_available()) { + file_addmetadata(kfp, MODINFOMD_VBE_FB, + sizeof(gfx_state.tg_fb), &gfx_state.tg_fb); + } +} +#endif