Merge branch 'freebsd/current/main' into hardened/current/master

This commit is contained in:
HardenedBSD Sync Services 2024-09-20 12:01:37 -06:00
commit c0da032159
No known key found for this signature in database
51 changed files with 827 additions and 115 deletions

View File

@ -78,7 +78,7 @@ extern int __swsetup(FILE *);
extern int __sflags(const char *, int *);
extern int __ungetc(int, FILE *);
extern wint_t __ungetwc(wint_t, FILE *, locale_t);
extern int __vfprintf(FILE *, locale_t, const char *, __va_list);
extern int __vfprintf(FILE *, locale_t, int, const char *, __va_list);
extern int __vfscanf(FILE *, const char *, __va_list);
extern int __vfwprintf(FILE *, locale_t, const wchar_t *, __va_list);
extern int __vfwscanf(FILE * __restrict, locale_t, const wchar_t * __restrict,

View File

@ -50,10 +50,11 @@
int
snprintf(char * __restrict str, size_t n, char const * __restrict fmt, ...)
{
size_t on;
int ret;
va_list ap;
FILE f = FAKE_FILE;
va_list ap;
size_t on;
int serrno = errno;
int ret;
on = n;
if (n != 0)
@ -67,7 +68,7 @@ snprintf(char * __restrict str, size_t n, char const * __restrict fmt, ...)
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
ret = __vfprintf(&f, __get_locale(), fmt, ap);
ret = __vfprintf(&f, __get_locale(), serrno, fmt, ap);
if (on > 0)
*f._p = '\0';
va_end(ap);
@ -77,10 +78,11 @@ int
snprintf_l(char * __restrict str, size_t n, locale_t locale,
char const * __restrict fmt, ...)
{
size_t on;
int ret;
va_list ap;
FILE f = FAKE_FILE;
va_list ap;
size_t on;
int serrno = errno;
int ret;
FIX_LOCALE(locale);
on = n;
@ -95,7 +97,7 @@ snprintf_l(char * __restrict str, size_t n, locale_t locale,
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
ret = __vfprintf(&f, locale, fmt, ap);
ret = __vfprintf(&f, locale, serrno, fmt, ap);
if (on > 0)
*f._p = '\0';
va_end(ap);

View File

@ -34,9 +34,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "xlocale_private.h"
#include "local.h"
@ -44,6 +44,7 @@ int
vasprintf_l(char **str, locale_t locale, const char *fmt, __va_list ap)
{
FILE f = FAKE_FILE;
int serrno = errno;
int ret;
FIX_LOCALE(locale);
@ -55,7 +56,7 @@ vasprintf_l(char **str, locale_t locale, const char *fmt, __va_list ap)
return (-1);
}
f._bf._size = f._w = 127; /* Leave room for the NUL */
ret = __vfprintf(&f, locale, fmt, ap);
ret = __vfprintf(&f, locale, serrno, fmt, ap);
if (ret < 0) {
free(f._bf._base);
*str = NULL;

View File

@ -46,6 +46,7 @@ vdprintf(int fd, const char * __restrict fmt, va_list ap)
{
FILE f = FAKE_FILE;
unsigned char buf[BUFSIZ];
int serrno = errno;
int ret;
if (fd > SHRT_MAX) {
@ -62,7 +63,7 @@ vdprintf(int fd, const char * __restrict fmt, va_list ap)
f._bf._base = buf;
f._bf._size = sizeof(buf);
if ((ret = __vfprintf(&f, __get_locale(), fmt, ap)) < 0)
if ((ret = __vfprintf(&f, __get_locale(), serrno, fmt, ap)) < 0)
return (ret);
return (__fflush(&f) ? EOF : ret);

View File

@ -68,7 +68,8 @@
#include "printflocal.h"
static int __sprint(FILE *, struct __suio *, locale_t);
static int __sbprintf(FILE *, locale_t, const char *, va_list) __printflike(3, 0)
static int __sbprintf(FILE *, locale_t, int, const char *, va_list)
__printflike(4, 0)
__noinline;
static char *__wcsconv(wchar_t *, int);
@ -169,7 +170,7 @@ __sprint(FILE *fp, struct __suio *uio, locale_t locale)
* worries about ungetc buffers and so forth.
*/
static int
__sbprintf(FILE *fp, locale_t locale, const char *fmt, va_list ap)
__sbprintf(FILE *fp, locale_t locale, int serrno, const char *fmt, va_list ap)
{
int ret;
FILE fake = FAKE_FILE;
@ -193,7 +194,7 @@ __sbprintf(FILE *fp, locale_t locale, const char *fmt, va_list ap)
fake._lbfsize = 0; /* not actually used, but Just In Case */
/* do the work, then copy any error status */
ret = __vfprintf(&fake, locale, fmt, ap);
ret = __vfprintf(&fake, locale, serrno, fmt, ap);
if (ret >= 0 && __fflush(&fake))
ret = EOF;
if (fake._flags & __SERR)
@ -265,8 +266,9 @@ __wcsconv(wchar_t *wcsarg, int prec)
*/
int
vfprintf_l(FILE * __restrict fp, locale_t locale, const char * __restrict fmt0,
va_list ap)
va_list ap)
{
int serrno = errno;
int ret;
FIX_LOCALE(locale);
@ -274,9 +276,9 @@ vfprintf_l(FILE * __restrict fp, locale_t locale, const char * __restrict fmt0,
/* optimise fprintf(stderr) (and other unbuffered Unix files) */
if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) &&
fp->_file >= 0)
ret = __sbprintf(fp, locale, fmt0, ap);
ret = __sbprintf(fp, locale, serrno, fmt0, ap);
else
ret = __vfprintf(fp, locale, fmt0, ap);
ret = __vfprintf(fp, locale, serrno, fmt0, ap);
FUNLOCKFILE_CANCELSAFE();
return (ret);
}
@ -301,7 +303,7 @@ vfprintf(FILE * __restrict fp, const char * __restrict fmt0, va_list ap)
* Non-MT-safe version
*/
int
__vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
__vfprintf(FILE *fp, locale_t locale, int serrno, const char *fmt0, va_list ap)
{
char *fmt; /* format string */
int ch; /* character from fmt */
@ -311,7 +313,6 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
int ret; /* return value accumulator */
int width; /* width from format (%8d), or 0 */
int prec; /* precision from format; <0 for N/A */
int saved_errno;
int error;
char errnomsg[NL_TEXTMAX];
char sign; /* sign prefix (' ', '+', '-', or \0) */
@ -463,7 +464,6 @@ __vfprintf(FILE *fp, locale_t locale, const char *fmt0, va_list ap)
savserr = fp->_flags & __SERR;
fp->_flags &= ~__SERR;
saved_errno = errno;
convbuf = NULL;
fmt = (char *)fmt0;
argtable = NULL;
@ -831,7 +831,7 @@ fp_common:
break;
#endif /* !NO_FLOATING_POINT */
case 'm':
error = __strerror_rl(saved_errno, errnomsg,
error = __strerror_rl(serrno, errnomsg,
sizeof(errnomsg), locale);
cp = error == 0 ? errnomsg : "<strerror failure>";
size = (prec >= 0) ? strnlen(cp, prec) : strlen(cp);

View File

@ -47,12 +47,13 @@
int
vsnprintf_l(char * __restrict str, size_t n, locale_t locale,
const char * __restrict fmt, __va_list ap)
const char * __restrict fmt, __va_list ap)
{
FILE f = FAKE_FILE;
size_t on;
int serrno = errno;
int ret;
char dummy[2];
FILE f = FAKE_FILE;
FIX_LOCALE(locale);
on = n;
@ -73,7 +74,7 @@ vsnprintf_l(char * __restrict str, size_t n, locale_t locale,
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = n;
ret = __vfprintf(&f, locale, fmt, ap);
ret = __vfprintf(&f, locale, serrno, fmt, ap);
if (on > 0)
*f._p = '\0';
return (ret);

View File

@ -37,8 +37,9 @@
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include "local.h"
#include "xlocale_private.h"
@ -46,16 +47,17 @@
int
vsprintf_l(char * __restrict str, locale_t locale,
const char * __restrict fmt, __va_list ap)
const char * __restrict fmt, __va_list ap)
{
int ret;
FILE f = FAKE_FILE;
int serrno = errno;
int ret;
FIX_LOCALE(locale);
f._flags = __SWR | __SSTR;
f._bf._base = f._p = (unsigned char *)str;
f._bf._size = f._w = INT_MAX;
ret = __vfprintf(&f, locale, fmt, ap);
ret = __vfprintf(&f, locale, serrno, fmt, ap);
*f._p = 0;
return (ret);
}

View File

@ -38,7 +38,6 @@
.Fn fhlink "fhandle_t *fhp" "const char *to"
.Ft int
.Fn fhlinkat "fhandle_t *fhp" "int tofd" "const char *to"
.Fc
.Sh DESCRIPTION
The
.Fn fhlink

View File

@ -36,7 +36,6 @@
.In sys/mount.h
.Ft int
.Fn fhreadlink "fhandle_t *fhp" "char *buf" "size_t bufsize"
.Fc
.Sh DESCRIPTION
The
.Fn fhreadlink
@ -86,7 +85,6 @@ The file handle
.Fa fhp
is no longer valid
.El
.El
.Sh SEE ALSO
.Xr fhstat 2 ,
.Xr fhlink 2 ,

View File

@ -212,6 +212,7 @@ argument is not an absolute path and
is neither
.Dv AT_FDCWD
nor a file descriptor associated with a directory.
.El
.Sh SEE ALSO
.Xr fhopen 2 ,
.Xr open 2 ,

View File

@ -712,6 +712,7 @@ following statuses:
The status is or-ed with the
.Va PROC_KPTI_STATUS_ACTIVE
in case KPTI is active for the current address space of the process.
.El
.Sh NOTES
Disabling tracing on a process should not be considered a security
feature, as it is bypassable both by the kernel and privileged processes,

View File

@ -830,7 +830,7 @@ value.
If the system call completed in an unusual fashion,
.Va sr_error
is set to a negative value:
.Bl -tag -width Dv EJUSTRETURN -compact
.Bl -tag -width EJUSTRETURN -compact
.It Dv ERESTART
System call will be restarted.
.It Dv EJUSTRETURN

View File

@ -34,8 +34,9 @@
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.It vm/vm_param.h
.It vm/swap_pager.h
.In vm/vm_param.h
.In vm/swap_pager.h
.Pp
.In unistd.h
.Ft int
.Fn swapon "const char *special"

View File

@ -62,7 +62,12 @@ fi
# Make an ESP in a file.
espfilename=$(mktemp /tmp/efiboot.XXXXXX)
make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi
if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then
make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi bootx64 \
${BASEBITSDIR}/boot/loader_ia32.efi bootia32
else
make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi
fi
mkimg -s mbr \
-b ${BASEBITSDIR}/boot/mbr \

View File

@ -66,7 +66,12 @@ if [ "$1" = "-b" ]; then
espfilename=$(mktemp /tmp/efiboot.XXXXXX)
# ESP file size in KB.
espsize="2048"
make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then
make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi bootx64 \
${BASEBITSDIR}/boot/loader_ia32.efi bootia32
else
make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi
fi
bootable="$bootable -o bootimage=i386;${espfilename} -o no-emul-boot -o platformid=efi"
shift

View File

@ -30,6 +30,11 @@
.Nd "generic interface to the Accelerated Graphics Port (AGP)"
.Sh SYNOPSIS
.Cd "device agp"
.Sh DEPRECATION NOTICE
The
.Nm
driver is slated to be removed in
.Fx 15.0 .
.Sh DESCRIPTION
The
.Nm

View File

@ -135,6 +135,7 @@ __DEFAULT_YES_OPTIONS = \
LOADER_OFW \
LOADER_PXEBOOT \
LOADER_UBOOT \
LOADER_IA32 \
LOCALES \
LOCATE \
LPR \
@ -373,6 +374,10 @@ BROKEN_OPTIONS+=LOADER_KBOOT
.if (${__T:Marm*} == "" && ${__T:Mpowerpc*} == "") || ${__T} == "powerpc64le"
BROKEN_OPTIONS+=LOADER_UBOOT
.endif
# The 32-bit UEFI loader is only for amd64
.if ${__T} != "amd64"
BROKEN_OPTIONS+=LOADER_IA32
.endif
# GELI and Lua in loader currently cause boot failures on powerpc.
# Further debugging is required -- probably they are just broken on big
# endian systems generically (they jump to null pointers or try to read

View File

@ -66,6 +66,7 @@ SUBDIR_DEPEND_${MACHINE}+= libofw
SUBDIR+=${_x}
.if defined(LIB32LIST) && ${LIB32LIST:M${_x}}
SUBDIR+=${_x}32
INTERP_DEPENDS+=${_x}32
.endif
.if ${_x} != "libsa"
SUBDIR_DEPEND_${_x}+= libsa

View File

@ -239,7 +239,7 @@ struct preloaded_file
size_t f_size; /* file size */
struct kernel_module *f_modules; /* list of modules if any */
struct preloaded_file *f_next; /* next file */
#ifdef __amd64__
#if defined(__amd64__) || defined(__i386__)
bool f_kernphys_relocatable;
#endif
#if defined(__i386__)

View File

@ -217,7 +217,7 @@ static int elf_section_header_convert(const Elf_Ehdr *ehdr, Elf_Shdr *shdr)
}
#endif
#ifdef __amd64__
#if defined(__amd64__) || defined(__i386__)
static bool
is_kernphys_relocatable(elf_file_t ef)
{
@ -491,7 +491,7 @@ __elfN(loadfile_raw)(char *filename, uint64_t dest,
/* Load OK, return module pointer */
*result = (struct preloaded_file *)fp;
err = 0;
#ifdef __amd64__
#if defined(__amd64__) || defined(__i386__)
fp->f_kernphys_relocatable = multiboot || is_kernphys_relocatable(&ef);
#endif
#ifdef __i386__

View File

@ -42,7 +42,14 @@ WARNS?= 1
BOOTSRC= ${SRCTOP}/stand
EFISRC= ${BOOTSRC}/efi
EFIINC= ${EFISRC}/include
# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is
# built 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here
# and activate it when DO32 is explicitly defined to be 1.
.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
EFIINCMD= ${EFIINC}/i386
.else
EFIINCMD= ${EFIINC}/${MACHINE}
.endif
FDTSRC= ${BOOTSRC}/fdt
FICLSRC= ${BOOTSRC}/ficl
LDRSRC= ${BOOTSRC}/common
@ -136,9 +143,6 @@ CFLAGS+= -m32 -mcpu=powerpc -mbig-endian
CFLAGS+= -m32 -mcpu=powerpc -mlittle-endian
.endif
# For amd64, there's a bit of mixed bag. Some of the tree (i386, lib*32) is
# build 32-bit and some 64-bit (lib*, efi). Centralize all the 32-bit magic here
# and activate it when DO32 is explicitly defined to be 1.
.if ${MACHINE_ARCH} == "amd64" && ${DO32:U0} == 1
CFLAGS+= -m32
# LD_FLAGS is passed directly to ${LD}, not via ${CC}:

View File

@ -3,6 +3,7 @@ NO_OBJ=t
.include <bsd.init.mk>
SUBDIR.yes+= libefi
SUBDIR.${MK_LOADER_IA32}+= libefi32
SUBDIR.${MK_FDT}+= fdt
SUBDIR.yes+= .WAIT
@ -10,6 +11,7 @@ SUBDIR.yes+= boot1 gptboot
SUBDIR.${MK_FORTH}+= loader_4th
SUBDIR.${MK_LOADER_LUA}+= loader_lua
SUBDIR.${MK_LOADER_IA32}+= loader_ia32
SUBDIR.yes+= loader_simp
.include <bsd.subdir.mk>

View File

@ -18,7 +18,11 @@ CFLAGS+= -fPIC
.endif
.if ${MACHINE_CPUARCH} == "amd64"
.if ${DO32:U0} == 1
EFI_TARGET= efi-app-ia32
.else
EFI_TARGET= efi-app-x86_64
.endif
.else
EFI_TARGET= binary
.endif

View File

@ -0,0 +1,4 @@
DO32=1
.PATH: ${.CURDIR}/../libefi
.include "${.CURDIR}/../libefi/Makefile"

View File

@ -6,7 +6,13 @@ LOADER_EXT2FS_SUPPORT?= no
.include <bsd.init.mk>
.if ${MACHINE} == "amd64" && ${DO32:U0} == 1
__arch= i386
LOADER?= loader_ia32
.else
__arch= ${MACHINE}
LOADER?= loader_${LOADER_INTERP}
.endif
PROG= ${LOADER}.sym
INTERNALPROG=
WARNS?= 3
@ -56,13 +62,13 @@ CFLAGS.gfx_fb.c += -DHAVE_MEMCPY -I${SRCTOP}/sys/contrib/zlib
CWARNFLAGS.main.c+= -Wno-format
.PATH: ${.CURDIR}/../loader
.PATH: ${.CURDIR}/../loader/arch/${MACHINE}
.include "${.CURDIR}/../loader/arch/${MACHINE}/Makefile.inc"
.PATH: ${.CURDIR}/../loader/arch/${__arch}
.include "${.CURDIR}/../loader/arch/${__arch}/Makefile.inc"
CFLAGS+= -I${.CURDIR}
CFLAGS+= -I${.CURDIR}/arch/${MACHINE}
CFLAGS+= -I${.CURDIR}/arch/${__arch}
CFLAGS+= -I${EFISRC}/include
CFLAGS+= -I${EFISRC}/include/${MACHINE}
CFLAGS+= -I${EFISRC}/include/${__arch}
CFLAGS+= -I${SYSDIR}/contrib/dev/acpica/include
CFLAGS+= -I${BOOTSRC}/i386/libi386
CFLAGS+= -DEFI
@ -99,11 +105,11 @@ CLEANFILES+= 8x16.c
FILES+= ${LOADER}.efi
FILESMODE_${LOADER}.efi= ${BINMODE}
.if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP}
.if ${LOADER_INTERP} == ${LOADER_DEFAULT_INTERP} && ${__arch} != "i386"
LINKS+= ${BINDIR}/${LOADER}.efi ${BINDIR}/loader.efi
.endif
LDSCRIPT= ${.CURDIR}/../loader/arch/${MACHINE}/${MACHINE}.ldscript
LDSCRIPT= ${.CURDIR}/../loader/arch/${__arch}/${__arch}.ldscript
LDFLAGS+= -Wl,-T${LDSCRIPT},-Bsymbolic,-znotext -pie
.if ${LINKER_TYPE} == "bfd" && ${LINKER_VERSION} >= 23400
LDFLAGS+= -Wl,--no-dynamic-linker
@ -129,8 +135,14 @@ ${LOADER}.efi: ${PROG}
--output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET}
LIBEFI= ${BOOTOBJ}/efi/libefi/libefi.a
LIBEFI32= ${BOOTOBJ}/efi/libefi32/libefi.a
.if ${__arch} == "i386"
DPADD= ${LDR_INTERP32} ${LIBEFI32} ${LIBSA32} ${LDSCRIPT}
LDADD= ${LDR_INTERP32} ${LIBEFI32} ${LIBSA32}
.else
DPADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA} ${LDSCRIPT}
LDADD= ${LDR_INTERP} ${LIBEFI} ${LIBSAFDT} ${LIBEFI_FDT} ${LIBSA}
.endif
.include <bsd.prog.mk>

View File

@ -0,0 +1,9 @@
SRCS+= amd64_tramp.S \
start.S \
setup.c \
elf64_freebsd.c
.PATH: ${BOOTSRC}/i386/libi386
SRCS+= nullconsole.c \
comconsole.c \
spinconsole.c

View File

@ -0,0 +1,100 @@
/*-
* Copyright (c) 2013 The FreeBSD Foundation
* Copyright (c) 2023 Ahmad Khalifa <ahmadkhalifa570@gmail.com>
*
* This software was developed by Benno Rice under sponsorship from
* the FreeBSD Foundation.
* 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 <machine/asmacros.h>
.text
.globl amd64_tramp
/*
* void amd64_tramp(uint32_t stack, void *copy_finish, uint32_t kernend,
* uint32_t modulep, uint32_t pagetable, uint32_t gdtr, uint64_t entry)
*/
amd64_tramp:
cli /* Make sure we don't get interrupted. */
calll *8(%esp) /* Call copy_finish so we're all ready to go. */
movl %cr0, %eax /* Paging may be enabled, disable it. */
andl $0x7FFFFFFF, %eax
movl %eax, %cr0
movl %cr4, %eax /* PAE may be disabled, enable it. */
orl $0x20, %eax
movl %eax, %cr4
movl 20(%esp), %eax /* Swap page tables. */
movl %eax, %cr3
movl $0xC0000080, %ecx /* Enable long mode. */
rdmsr
orl $0x100, %eax
wrmsr
movl 12(%esp), %edi /* Stash the kernel and GDT values for later. */
movl 16(%esp), %esi
movl 24(%esp), %ebx
movl 28(%esp), %edx
movl 32(%esp), %ebp
movl 4(%esp), %esp /* Switch to our temporary stack. */
movl %cr0, %eax /* Enable paging and enter compatibility mode. */
orl $0x80000000, %eax
movl %eax, %cr0
lgdtl (%ebx) /* Load GDT. */
pushl %edi /* Push kernend. */
pushl %esi /* Push modulep. */
pushl $0x0
pushl %ebp /* Push 64-bit entry address. */
pushl %edx
calll 0f /* Find the address of ".longmode". */
0: popl %eax
addl $(.longmode-0b), %eax
pushl $0x8 /* Push CS. */
pushl %eax /* Push the address. */
lretl /* "Return" to 64-bit code. */
.code64
.longmode:
retq /* "Return" to kernel entry. */
.code32
ALIGN_TEXT
amd64_tramp_end:
.data
.globl amd64_tramp_size
amd64_tramp_size:
.long amd64_tramp_end-amd64_tramp

View File

@ -0,0 +1,274 @@
/*-
* Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
* Copyright (c) 2014 The FreeBSD Foundation
* 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.
*/
#define __ELF_WORD_SIZE 64
#include <sys/param.h>
#include <sys/linker.h>
#include <machine/elf.h>
#include <efi.h>
#include <efilib.h>
#include "bootstrap.h"
#include "loader_efi.h"
extern int bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp,
bool exit_bs);
static int elf64_exec(struct preloaded_file *amp);
static int elf64_obj_exec(struct preloaded_file *amp);
static struct file_format amd64_elf = {
.l_load = elf64_loadfile,
.l_exec = elf64_exec
};
static struct file_format amd64_elf_obj = {
.l_load = elf64_obj_loadfile,
.l_exec = elf64_obj_exec
};
struct file_format *file_formats[] = {
&amd64_elf,
&amd64_elf_obj,
NULL
};
struct gdtr {
uint16_t size;
uint64_t ptr;
} __packed;
#define PG_V 0x001
#define PG_RW 0x002
#define PG_PS 0x080
#define GDT_P 0x00800000000000
#define GDT_E 0x00080000000000
#define GDT_S 0x00100000000000
#define GDT_RW 0x00020000000000
#define GDT_L 0x20000000000000
#define M(x) ((x) * 1024 * 1024)
#define G(x) (1ULL * (x) * 1024 * 1024 * 1024)
typedef uint64_t p4_entry_t;
typedef uint64_t p3_entry_t;
typedef uint64_t p2_entry_t;
typedef uint64_t gdt_t;
static p4_entry_t *PT4;
static p3_entry_t *PT3;
static p3_entry_t *PT3_l, *PT3_u;
static p2_entry_t *PT2;
static p2_entry_t *PT2_l0, *PT2_l1, *PT2_l2, *PT2_l3, *PT2_u0, *PT2_u1;
static gdt_t *GDT;
extern EFI_PHYSICAL_ADDRESS staging;
static void (*trampoline)(uint32_t stack, void *copy_finish, uint32_t kernend,
uint32_t modulep, uint64_t *pagetable, struct gdtr *gdtr, uint64_t entry);
extern void *amd64_tramp;
extern uint32_t amd64_tramp_size;
/*
* There is an ELF kernel and one or more ELF modules loaded.
* We wish to start executing the kernel image, so make such
* preparations as are required, and do so.
*/
static int
elf64_exec(struct preloaded_file *fp)
{
EFI_PHYSICAL_ADDRESS ptr;
EFI_ALLOCATE_TYPE type;
EFI_STATUS err;
struct file_metadata *md;
struct gdtr *gdtr;
Elf_Ehdr *ehdr;
vm_offset_t modulep, kernend, trampstack;
int i;
switch (copy_staging) {
case COPY_STAGING_ENABLE:
type = AllocateMaxAddress;
break;
case COPY_STAGING_DISABLE:
type = AllocateAnyPages;
break;
case COPY_STAGING_AUTO:
type = fp->f_kernphys_relocatable ?
AllocateAnyPages : AllocateMaxAddress;
break;
}
if ((md = file_findmetadata(fp, MODINFOMD_ELFHDR)) == NULL)
return (EFTYPE);
ehdr = (Elf_Ehdr *)&(md->md_data);
/*
* Make our temporary stack 32 bytes big, which is
* a little more than we need.
*/
ptr = G(1);
err = BS->AllocatePages(type, EfiLoaderCode,
EFI_SIZE_TO_PAGES(amd64_tramp_size + 32), &ptr);
if (EFI_ERROR(err)) {
printf("Unable to allocate trampoline\n");
return (ENOMEM);
}
trampoline = (void *)(uintptr_t)ptr;
trampstack = ptr + amd64_tramp_size + 32;
bcopy(&amd64_tramp, trampoline, amd64_tramp_size);
ptr = G(1);
err = BS->AllocatePages(type, EfiLoaderData,
EFI_SIZE_TO_PAGES(sizeof(struct gdtr) + sizeof(uint64_t) * 2), &ptr);
if (EFI_ERROR(err)) {
printf("Unable to allocate GDT\n");
BS->FreePages((uintptr_t)trampoline, 1);
return (ENOMEM);
}
GDT = (gdt_t *)(uintptr_t)ptr;
GDT[1] = GDT_P | GDT_E | GDT_S | GDT_RW | GDT_L; /* CS */
GDT[0] = 0;
gdtr = (struct gdtr *)&GDT[2];
gdtr->size = sizeof(uint64_t) * 2 - 1;
gdtr->ptr = (uintptr_t)GDT;
if (type == AllocateMaxAddress) {
/* Copy staging enabled */
ptr = G(1);
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData,
EFI_SIZE_TO_PAGES(512 * 3 * sizeof(uint64_t)), &ptr);
if (EFI_ERROR(err)) {
printf("Unable to allocate trampoline page table\n");
BS->FreePages((uintptr_t)trampoline, 1);
BS->FreePages((uintptr_t)GDT, 1);
return (ENOMEM);
}
PT4 = (p4_entry_t *)(uintptr_t)ptr;
PT3 = &PT4[512];
PT2 = &PT3[512];
/*
* This is kinda brutal, but every single 1GB VM
* memory segment points to the same first 1GB of
* physical memory. But it is more than adequate.
*/
for (i = 0; i < 512; i++) {
/*
* Each slot of the L4 pages points to the
* same L3 page.
*/
PT4[i] = (uintptr_t)PT3 | PG_V | PG_RW;
/*
* Each slot of the L3 pages points to the
* same L2 page.
*/
PT3[i] = (uintptr_t)PT2 | PG_V | PG_RW;
/*
* The L2 page slots are mapped with 2MB pages for 1GB.
*/
PT2[i] = (i * M(2)) | PG_V | PG_RW | PG_PS;
}
} else {
err = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
EFI_SIZE_TO_PAGES(512 * 9 * sizeof(uint64_t)), &ptr);
if (EFI_ERROR(err)) {
printf("Unable to allocate trampoline page table\n");
BS->FreePages((uintptr_t)trampoline, 1);
BS->FreePages((uintptr_t)GDT, 1);
return (ENOMEM);
}
PT4 = (p4_entry_t *)(uintptr_t)ptr;
PT3_l = &PT4[512];
PT3_u = &PT3_l[512];
PT2_l0 = &PT3_u[512];
PT2_l1 = &PT2_l0[512];
PT2_l2 = &PT2_l1[512];
PT2_l3 = &PT2_l2[512];
PT2_u0 = &PT2_l3[512];
PT2_u1 = &PT2_u0[512];
/* 1:1 mapping of lower 4G */
PT4[0] = (uintptr_t)PT3_l | PG_V | PG_RW;
PT3_l[0] = (uintptr_t)PT2_l0 | PG_V | PG_RW;
PT3_l[1] = (uintptr_t)PT2_l1 | PG_V | PG_RW;
PT3_l[2] = (uintptr_t)PT2_l2 | PG_V | PG_RW;
PT3_l[3] = (uintptr_t)PT2_l3 | PG_V | PG_RW;
for (i = 0; i < 2048; i++) {
PT2_l0[i] = ((p2_entry_t)i * M(2)) | PG_V | PG_RW | PG_PS;
}
/* mapping of kernel 2G below top */
PT4[511] = (uintptr_t)PT3_u | PG_V | PG_RW;
PT3_u[511] = (uintptr_t)PT2_u1 | PG_V | PG_RW;
PT3_u[510] = (uintptr_t)PT2_u0 | PG_V | PG_RW;
/* compat mapping of phys @0 */
PT2_u0[0] = PG_PS | PG_V | PG_RW;
/* this maps past staging area */
for (i = 1; i < 1024; i++) {
PT2_u0[i] = (staging + (i - 1) * M(2))
| PG_V | PG_RW | PG_PS;
}
}
printf(
"staging %#llx (%scopying) tramp %p PT4 %p GDT %p\n"
"Start @ %#llx ...\n", staging,
type == AllocateMaxAddress ? "" : "not ", trampoline, PT4, GDT,
ehdr->e_entry
);
efi_time_fini();
err = bi_load(fp->f_args, &modulep, &kernend, true);
if (err != 0) {
efi_time_init();
return (err);
}
dev_cleanup();
trampoline(trampstack, type == AllocateMaxAddress ? efi_copy_finish :
efi_copy_finish_nop, kernend, modulep, PT4, gdtr, ehdr->e_entry);
panic("exec returned");
}
static int
elf64_obj_exec(struct preloaded_file *fp)
{
return (EFTYPE);
}

View File

@ -0,0 +1,55 @@
OUTPUT_FORMAT("elf32-i386-freebsd", "elf32-i386-freebsd", "elf32-i386-freebsd")
OUTPUT_ARCH(i386)
ENTRY(_start)
SECTIONS
{
/* Read-only sections, merged into text segment: */
. = 0;
ImageBase = .;
. = SIZEOF_HEADERS;
. = ALIGN(4096);
.text : {
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
*(.plt)
} =0xCCCCCCCC
. = ALIGN(4096);
.data : {
*(.rodata .rodata.* .gnu.linkonce.r.*)
*(.rodata1)
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
*(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)
*(.opd)
*(.data .data.* .gnu.linkonce.d.*)
*(.data1)
*(.plabel)
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
}
. = ALIGN(4096);
__gp = .;
.sdata : {
*(.got.plt .got)
*(.sdata .sdata.* .gnu.linkonce.s.*)
*(dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
}
. = ALIGN(4096);
.dynamic : { *(.dynamic) }
. = ALIGN(4096);
.rel.dyn : {
*(.rel.*)
*(.relset_*)
}
. = ALIGN(4096);
.reloc : { *(.reloc) }
. = ALIGN(4096);
.hash : { *(.hash) }
. = ALIGN(4096);
.dynsym : { *(.dynsym) }
. = ALIGN(4096);
.dynstr : { *(.dynstr) }
}

View File

@ -0,0 +1,51 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2024 Ahmad Khalifa <ahmadkhalifa570@gmail.com>
*
* 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 AUTHORS 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 AUTHORS 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 <sys/types.h>
#include <efi.h>
#include <efilib.h>
#include <machine/specialreg.h>
/*
* Check for long mode then call efi_main
*/
EFI_STATUS
setup(EFI_HANDLE IH, EFI_SYSTEM_TABLE *ST) {
u_int edx;
asm("cpuid" : "=d"(edx) : "a"(0x80000001) : "ebx", "ecx");
if ((edx & AMDID_LM) == 0) {
ST->ConOut->OutputString(ST->ConOut, (CHAR16 *)
L"This CPU doesn't support long mode.\r\n"
L"Unable to proceed.\r\n");
ST->BootServices->Exit(IH, EFI_UNSUPPORTED, 0, NULL);
}
return (efi_main(IH, ST));
}

View File

@ -0,0 +1,75 @@
/*-
* Copyright (C) 1999 Hewlett-Packard Co.
* Contributed by David Mosberger <davidm@hpl.hp.com>.
* 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.
* 3. Neither the name of Hewlett-Packard Co. nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
* OWNER 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.
*/
/*
* crt0-efi-ia32.S - x86 EFI startup code.
*/
.text
.align 4
.globl _start
_start:
pushl %ebp
movl %esp, %ebp
pushl 12(%ebp)
pushl 8(%ebp)
call 0f
0: popl %eax
movl %eax, %ebx
addl $ImageBase-0b, %eax
addl $_DYNAMIC-0b, %ebx
pushl %ebx
pushl %eax
call self_reloc
popl %ebx
popl %ebx
call setup
.exit:
leave
ret
/*
* hand-craft a dummy .reloc section so EFI knows it's a relocatable
* executable:
*/
.data
.section .reloc, "a"
.long 0
.long 10
.word 0

View File

@ -185,7 +185,7 @@ bi_load_efi_data(struct preloaded_file *kfp, bool exit_bs)
struct efi_map_header *efihdr;
bool do_vmap;
#if defined(__amd64__) || defined(__aarch64__)
#if defined(__amd64__) || defined(__aarch64__) || defined(__i386__)
struct efi_fb efifb;
efifb.fb_addr = gfx_state.tg_fb.fb_addr;
@ -339,7 +339,16 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
vm_offset_t size;
char *rootdevname;
int howto;
#ifdef __i386__
/*
* The 32-bit UEFI loader is used to
* boot the 64-bit kernel on machines
* that support it.
*/
bool is64 = true;
#else
bool is64 = sizeof(long) == 8;
#endif
#if defined(LOADER_FDT_SUPPORT)
vm_offset_t dtbp;
int dtb_size;
@ -439,8 +448,14 @@ bi_load(char *args, vm_offset_t *modulep, vm_offset_t *kernendp, bool exit_bs)
file_addmetadata(kfp, MODINFOMD_MODULEP, sizeof(module), &module);
#endif
#ifdef EFI
#ifndef __i386__
file_addmetadata(kfp, MODINFOMD_FW_HANDLE, sizeof(ST), &ST);
#endif
#if defined(__amd64__) || defined(__i386__)
file_addmetadata(kfp, MODINFOMD_EFI_ARCH, sizeof(MACHINE_ARCH),
MACHINE_ARCH);
#endif
#endif
#ifdef LOADER_GELI_SUPPORT
geli_export_key_metadata(kfp);
#endif

View File

@ -82,7 +82,7 @@ extern struct console eficom;
/* Hack for backward compatibility -- but only for a while */
extern struct console comconsole;
#endif
#if defined(__amd64__)
#if defined(__amd64__) || defined(__i386__)
extern struct console comconsole;
extern struct console nullconsole;
extern struct console spinconsole;
@ -94,7 +94,7 @@ struct console *consoles[] = {
#if defined(__aarch64__) && __FreeBSD_version < 1500000
&comconsole,
#endif
#if defined(__amd64__)
#if defined(__amd64__) || defined(__i386__)
&comconsole,
&nullconsole,
&spinconsole,

View File

@ -182,13 +182,13 @@ out:
#endif
#if defined(__aarch64__) || defined(__amd64__) || defined(__arm__) || \
defined(__riscv)
defined(__riscv) || defined(__i386__)
#define EFI_STAGING_2M_ALIGN 1
#else
#define EFI_STAGING_2M_ALIGN 0
#endif
#if defined(__amd64__)
#if defined(__amd64__) || defined(__i386__)
#define EFI_STAGING_SLOP M(8)
#else
#define EFI_STAGING_SLOP 0
@ -209,7 +209,7 @@ efi_copy_free(void)
stage_offset = 0;
}
#ifdef __amd64__
#if defined(__amd64__) || defined(__i386__)
int copy_staging = COPY_STAGING_AUTO;
static int
@ -281,7 +281,7 @@ command_staging_slop(int argc, char *argv[])
COMMAND_SET(staging_slop, "staging_slop", "set staging slop",
command_staging_slop);
#if defined(__amd64__)
#if defined(__amd64__) || defined(__i386__)
/*
* The staging area must reside in the first 1GB or 4GB physical
* memory: see elf64_exec() in
@ -320,7 +320,8 @@ efi_copy_init(void)
*/
if (running_on_hyperv())
efi_verify_staging_size(&nr_pages);
#endif
#if defined(__amd64__) || defined(__i386__)
staging = get_staging_max();
#endif
status = BS->AllocatePages(EFI_ALLOC_METHOD, EfiLoaderCode,
@ -380,9 +381,10 @@ efi_check_space(vm_offset_t end)
end += staging_slop;
nr_pages = EFI_SIZE_TO_PAGES(end - staging_end);
#if defined(__amd64__)
#if defined(__amd64__) || defined(__i386__)
/*
* amd64 needs all memory to be allocated under the 1G or 4G boundary.
* The amd64 kernel needs all memory to be allocated under the 1G or
* 4G boundary.
*/
if (end > get_staging_max())
goto before_staging;
@ -427,7 +429,7 @@ expand:
#if EFI_STAGING_2M_ALIGN
nr_pages += M(2) / EFI_PAGE_SIZE;
#endif
#if defined(__amd64__)
#if defined(__amd64__) || defined(__i386__)
new_base = get_staging_max();
#endif
status = BS->AllocatePages(EFI_ALLOC_METHOD, EfiLoaderCode,

View File

@ -149,7 +149,16 @@ efifb_from_gop(struct efi_fb *efifb, EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode,
{
int result;
efifb->fb_addr = mode->FrameBufferBase;
/*
* The Asus EEEPC 1025C, and possibly others,
* require the address to be masked.
*/
efifb->fb_addr =
#ifdef __i386__
mode->FrameBufferBase & 0xffffffff;
#else
mode->FrameBufferBase;
#endif
efifb->fb_size = mode->FrameBufferSize;
efifb->fb_height = info->VerticalResolution;
efifb->fb_width = info->HorizontalResolution;
@ -555,6 +564,7 @@ efi_has_gop(void)
int
efi_find_framebuffer(teken_gfx_t *gfx_state)
{
EFI_PHYSICAL_ADDRESS ptr;
EFI_HANDLE *hlist;
UINTN nhandles, i, hsize;
struct efi_fb efifb;
@ -651,16 +661,15 @@ efi_find_framebuffer(teken_gfx_t *gfx_state)
efifb.fb_mask_blue | efifb.fb_mask_reserved);
if (gfx_state->tg_shadow_fb != NULL)
BS->FreePages((EFI_PHYSICAL_ADDRESS)gfx_state->tg_shadow_fb,
BS->FreePages((uintptr_t)gfx_state->tg_shadow_fb,
gfx_state->tg_shadow_sz);
gfx_state->tg_shadow_sz =
EFI_SIZE_TO_PAGES(efifb.fb_height * efifb.fb_width *
sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
status = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData,
gfx_state->tg_shadow_sz,
(EFI_PHYSICAL_ADDRESS *)&gfx_state->tg_shadow_fb);
if (status != EFI_SUCCESS)
gfx_state->tg_shadow_fb = NULL;
status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData,
gfx_state->tg_shadow_sz, &ptr);
gfx_state->tg_shadow_fb = status == EFI_SUCCESS ?
(uint32_t *)(uintptr_t)ptr : NULL;
return (0);
}

View File

@ -32,7 +32,7 @@
#include <readin.h>
#include <efi.h>
#ifdef __amd64__
#if defined(__amd64__) || defined(__i386__)
enum {
COPY_STAGING_ENABLE,
COPY_STAGING_DISABLE,

View File

@ -45,6 +45,7 @@
#include <disk.h>
#include <dev_net.h>
#include <net.h>
#include <inttypes.h>
#include <efi.h>
#include <efilib.h>
@ -920,7 +921,7 @@ acpi_detect(void)
if ((rsdp = efi_get_table(&acpi)) == NULL)
return;
sprintf(buf, "0x%016llx", (unsigned long long)rsdp);
sprintf(buf, "0x%016"PRIxPTR, (uintptr_t)rsdp);
setenv("acpi.rsdp", buf, 1);
revision = rsdp->Revision;
if (revision == 0)
@ -963,7 +964,7 @@ main(int argc, CHAR16 *argv[])
archsw.arch_getdev = efi_getdev;
archsw.arch_copyin = efi_copyin;
archsw.arch_copyout = efi_copyout;
#ifdef __amd64__
#if defined(__amd64__) || defined(__i386__)
archsw.arch_hypervisor = x86_hypervisor;
#endif
archsw.arch_readin = efi_readin;

View File

@ -0,0 +1,6 @@
DO32=1
INSTALL_LOADER_HELP_FILE=no
NEWVERSWHAT?= "EFI loader" amd64-ia32
.include "../loader/Makefile"

View File

@ -1688,6 +1688,27 @@ SYSCTL_PROC(_machdep, OID_AUTO, efi_map,
NULL, 0, efi_map_sysctl_handler, "S,efi_map_header",
"Raw EFI Memory Map");
static int
efi_arch_sysctl_handler(SYSCTL_HANDLER_ARGS)
{
char *arch;
caddr_t kmdp;
kmdp = preload_search_by_type("elf kernel");
if (kmdp == NULL)
kmdp = preload_search_by_type("elf64 kernel");
arch = (char *)preload_search_info(kmdp,
MODINFO_METADATA | MODINFOMD_EFI_ARCH);
if (arch == NULL)
return (0);
return (SYSCTL_OUT_STR(req, arch));
}
SYSCTL_PROC(_machdep, OID_AUTO, efi_arch,
CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
efi_arch_sysctl_handler, "A", "EFI Firmware Architecture");
void
spinlock_enter(void)
{

View File

@ -900,7 +900,7 @@ initarm(struct arm64_bootparams *abp)
boot_el = abp->boot_el;
/* Parse loader or FDT boot parametes. Determine last used address. */
/* Parse loader or FDT boot parameters. Determine last used address. */
lastaddr = parse_boot_param(abp);
/* Find the kernel address */

View File

@ -592,10 +592,10 @@ retry:
}
vm_map_lock(pipe_map);
if (priv_check(curthread, PRIV_PIPEBUF) != 0 &&
(vm_map_max(pipe_map) - vm_map_min(pipe_map)) *
(100 - pipebuf_reserv) / 100 < pipe_map->size + size) {
if (priv_check(curthread, PRIV_PIPEBUF) != 0 && maxpipekva / 100 *
(100 - pipebuf_reserv) < amountpipekva + size) {
vm_map_unlock(pipe_map);
chgpipecnt(cpipe->pipe_pair->pp_owner->cr_ruidinfo, -size, 0);
if (cpipe->pipe_buffer.buffer == NULL &&
size > SMALL_PIPE_SIZE) {
size = SMALL_PIPE_SIZE;

View File

@ -789,7 +789,7 @@ ng_btsocket_l2cap_process_l2ca_cfg_req_rsp(struct ng_mesg *msg,
if (op->result == NG_L2CAP_SUCCESS) {
/*
* XXX FIXME Actually set flush and link timeout.
* Set QoS here if required. Resolve conficts (flush_timo).
* Set QoS here if required. Resolve conflicts (flush_timo).
* Save incoming MTU (peer's outgoing MTU) and outgoing flow
* spec.
*/
@ -991,7 +991,7 @@ ng_btsocket_l2cap_process_l2ca_cfg_ind(struct ng_mesg *msg,
/*
* XXX FIXME Actually set flush and link timeout. Set QoS here if
* required. Resolve conficts (flush_timo). Note outgoing MTU (peer's
* required. Resolve conflicts (flush_timo). Note outgoing MTU (peer's
* incoming MTU) and incoming flow spec.
*/

View File

@ -241,9 +241,9 @@ open_file(const char *path, struct nameidata *nid)
NDINIT(nid, LOOKUP, 0, UIO_SYSSPACE, path);
rc = vn_open(nid, &flags, 0, NULL);
NDFREE_PNBUF(nid);
if (rc != 0)
return (rc);
NDFREE_PNBUF(nid);
return (0);
}
@ -346,7 +346,6 @@ parse_entry(char *entry, char *prefix)
}
rc = open_file(path, &nid);
NDFREE_PNBUF(&nid);
if (rc != 0)
return (rc);

View File

@ -34,6 +34,7 @@
#define MODINFOMD_EFI_FB 0x1005
#define MODINFOMD_MODULEP 0x1006
#define MODINFOMD_VBE_FB 0x1007
#define MODINFOMD_EFI_ARCH 0x1008
struct efi_map_header {
uint64_t memory_size;

View File

@ -42,11 +42,10 @@ get_uefi_bootname() {
}
make_esp_file() {
local file sizekb loader device stagedir fatbits efibootname
local file sizekb device stagedir fatbits efibootname
file=$1
sizekb=$2
loader=$3
if [ "$sizekb" -ge "$fat32min" ]; then
fatbits=32
@ -58,8 +57,25 @@ make_esp_file() {
stagedir=$(mktemp -d /tmp/stand-test.XXXXXX)
mkdir -p "${stagedir}/EFI/BOOT"
efibootname=$(get_uefi_bootname)
cp "${loader}" "${stagedir}/EFI/BOOT/${efibootname}.efi"
# Allow multiple files to be copied.
# We do this in pairs, e.g:
# make_esp_file ... loader1.efi bootx64 loader2.efi bootia32
#
# If the second argument is left out,
# determine it automatically.
shift; shift # Skip $file and $sizekb
while [ ! -z $1 ]; do
if [ ! -z $2 ]; then
efibootname=$2
else
efibootname=$(get_uefi_bootname)
fi
cp "$1" "${stagedir}/EFI/BOOT/${efibootname}.efi"
shift; shift || : # Ignore failure to shift
done
makefs -t msdos \
-o fat_type=${fatbits} \
-o sectors_per_cluster=1 \
@ -70,13 +86,20 @@ make_esp_file() {
}
make_esp_device() {
local dev file mntpt fstype efibootname kbfree loadersize efibootfile
local dev file dst mntpt fstype efibootname kbfree loadersize efibootfile
local isboot1 existingbootentryloaderfile bootorder bootentry
# ESP device node
dev=$1
file=$2
# Allow caller to override the default
if [ ! -z $3 ]; then
efibootname=$3
else
efibootname=$(get_uefi_bootname)
fi
dst=$(basename ${file%.efi})
mntpt=$(mktemp -d /tmp/stand-test.XXXXXX)
# See if we're using an existing (formatted) ESP
@ -93,7 +116,6 @@ make_esp_device() {
echo "Mounted ESP ${dev} on ${mntpt}"
efibootname=$(get_uefi_bootname)
kbfree=$(df -k "${mntpt}" | tail -1 | cut -w -f 4)
loadersize=$(stat -f %z "${file}")
loadersize=$((loadersize / 1024))
@ -114,7 +136,7 @@ make_esp_device() {
fi
fi
if [ ! -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then
if [ ! -f "${mntpt}/EFI/freebsd/${dst}.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then
umount "${mntpt}"
rmdir "${mntpt}"
echo "Failed to update the EFI System Partition ${dev}"
@ -126,24 +148,26 @@ make_esp_device() {
mkdir -p "${mntpt}/EFI/freebsd"
# Keep a copy of the existing loader.efi in case there's a problem with the new one
if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then
cp "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi"
if [ -f "${mntpt}/EFI/freebsd/${dst}.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then
cp "${mntpt}/EFI/freebsd/${dst}.efi" "${mntpt}/EFI/freebsd/${dst}-old.efi"
fi
echo "Copying loader to /EFI/freebsd on ESP"
cp "${file}" "${mntpt}/EFI/freebsd/loader.efi"
cp "${file}" "${mntpt}/EFI/freebsd/${dst}.efi"
if [ -n "${updatesystem}" ]; then
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi")
# efibootmgr won't work on systems with ia32 UEFI firmware
# since we only use it to boot the 64-bit kernel
if [ -n "${updatesystem}" ] && [ ${efibootname} != "bootia32" ]; then
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/${dst}.efi")
if [ -z "$existingbootentryloaderfile" ]; then
# Try again without the double forward-slash in the path
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/loader.efi")
existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/${dst}.efi")
fi
if [ -z "$existingbootentryloaderfile" ]; then
echo "Creating UEFI boot entry for FreeBSD"
efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null
efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/${dst}.efi" > /dev/null
if [ $? -ne 0 ]; then
die "Failed to create new boot entry"
fi

View File

@ -0,0 +1 @@
Do not build the 32-bit UEFI loader.

View File

@ -0,0 +1 @@
Build the 32-bit UEFI loader.

View File

@ -501,8 +501,11 @@ intpr(void (*pfunc)(char *), int af)
IFA_STAT(ipackets), link|network, 1);
show_stat("lu", nerr_len, "received-errors", IFA_STAT(ierrors),
link, 1);
/* Below is kept for backwards compatibility. Will be removed before FreeBSD 16. */
show_stat("lu", nerr_len, "dropped-packets", IFA_STAT(iqdrops),
link, 1);
show_stat("lu", nerr_len, "dropped-packets-in", IFA_STAT(iqdrops),
link, 1);
if (bflag)
show_stat("lu", nbyte_len, "received-bytes",
IFA_STAT(ibytes), link|network, 0);
@ -516,7 +519,7 @@ intpr(void (*pfunc)(char *), int af)
show_stat("NRSlu", nerr_len, "collisions", IFA_STAT(collisions),
link, 1);
if (dflag)
show_stat("LSlu", nerr_len, "dropped-packets",
show_stat("LSlu", nerr_len, "dropped-packets-out",
IFA_STAT(oqdrops), link, 1);
xo_emit("\n");
@ -705,8 +708,11 @@ loop:
new->ift_ip - old->ift_ip, 1, 1);
show_stat("lu", 5, "received-errors",
new->ift_ie - old->ift_ie, 1, 1);
/* Below is kept for backwards compatibility. Will be removed before FreeBSD 16. */
show_stat("lu", 5, "dropped-packets",
new->ift_id - old->ift_id, 1, 1);
show_stat("lu", 5, "dropped-packets-in",
new->ift_id - old->ift_id, 1, 1);
show_stat("lu", 10, "received-bytes",
new->ift_ib - old->ift_ib, 1, 0);
show_stat("lu", 10, "sent-packets",
@ -718,7 +724,7 @@ loop:
show_stat("NRSlu", 5, "collisions",
new->ift_co - old->ift_co, 1, 1);
if (dflag)
show_stat("LSlu", 5, "dropped-packets",
show_stat("LSlu", 5, "dropped-packets-out",
new->ift_od - old->ift_od, 1, 1);
xo_close_instance("stats");
xo_emit("\n");

View File

@ -711,7 +711,7 @@ sctp_stats(u_long off, const char *name, int af1 __unused, int proto __unused)
"secret\n");
p(sctps_timopathmtu, "\t\t{:pmtu-timer/%ju} "
"{N:/PMTU timer%s fired}\n");
p(sctps_timoshutdownack, "\t\t{:shutdown-timer/%ju} "
p(sctps_timoshutdownack, "\t\t{:shutdown-ack-timer/%ju} "
"{N:/shutdown ack timer%s fired}\n");
p(sctps_timoshutdownguard, "\t\t{:shutdown-guard-timer/%ju} "
"{N:/shutdown guard timer%s fired}\n");

View File

@ -109,32 +109,40 @@ if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then
# i386) ARCHBOOTNAME=ia32 ;; # no support for this in i386 kernels, rare machines
*) die "Unsupported arch $(uname -m) for UEFI install"
esac
if [ `sysctl -n machdep.efi_arch` == i386 ]; then
ARCHBOOTNAME=ia32
file=loader_ia32.efi
else
file=loader.efi
fi
BOOTDIR="/efi/boot"
BOOTNAME="${BOOTDIR}/boot${ARCHBOOTNAME}.efi"
FREEBSD_BOOTDIR="/efi/freebsd"
FREEBSD_BOOTNAME="${FREEBSD_BOOTDIR}/loader.efi"
FREEBSD_BOOTNAME="${FREEBSD_BOOTDIR}/${file}"
mntpt="$BSDINSTALL_CHROOT/boot/efi"
f_dprintf "Installing loader.efi onto ESP"
f_dprintf "Installing ${file} onto ESP"
mkdir -p "${mntpt}/${FREEBSD_BOOTDIR}" "${mntpt}/${BOOTDIR}"
cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/${FREEBSD_BOOTNAME}"
cp "$BSDINSTALL_CHROOT/boot/${file}" "${mntpt}/${FREEBSD_BOOTNAME}"
#
# The following shouldn't be necessary. UEFI defines a way to
# specifically select what to boot (which we do via
# efibootmgr). However, virtual environments often times lack
# support for the NV variables efibootmgr sets. In addition,
# some UEFI implementations have features that interfere with
# the setting of these variables. To combat that, we install the
# default removable media boot file as a fallback if it doesn't
# exist. We don't install it all the time since that can
# interfere with other installations on the drive (like rEFInd).
# UEFI defines a way to specifically select what to boot
# (which we do via efibootmgr). However, if we booted from an ia32
# UEFI environment, we wouldn't have access to efirt. In addition,
# virtual environments often times lack support for the NV variables
# efibootmgr sets, and some UEFI implementations have features that
# interfere with the setting of these variables. To combat that, we
# install the default removable media boot file if it doesn't exist.
# We don't install it all the time since that can interfere with other
# installations on the drive (like rEFInd).
#
if [ ! -f "${mntpt}/${BOOTNAME}" ]; then
cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/${BOOTNAME}"
cp "$BSDINSTALL_CHROOT/boot/${file}" "${mntpt}/${BOOTNAME}"
fi
if [ "$BSDINSTALL_CONFIGCURRENT" ]; then
if [ "$BSDINSTALL_CONFIGCURRENT" ] && [ "$ARCHBOOTNAME" != ia32 ]; then
update_uefi_bootentry
fi

View File

@ -751,6 +751,7 @@ main(int argc, char** argv)
/* Default values */
i2c_opt.off = 0;
i2c_opt.addr = 0;
i2c_opt.verbose = 0;
i2c_opt.dir = 'r'; /* direction = read */
i2c_opt.width = "8";
@ -875,12 +876,6 @@ main(int argc, char** argv)
return(EX_USAGE);
}
if (i2c_opt.verbose)
fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, "
"offset: 0x%02x, width: %s, count: %u\n", dev,
i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off,
i2c_opt.width, i2c_opt.count);
fd = open(dev, O_RDWR);
if (fd == -1) {
fprintf(stderr, "Error opening I2C controller (%s): %s\n",
@ -890,6 +885,11 @@ main(int argc, char** argv)
switch (do_what) {
case 'a':
if (i2c_opt.verbose)
fprintf(stderr, "dev: %s, addr: 0x%x, r/w: %c, "
"offset: 0x%02x, width: %s, count: %u\n", dev,
i2c_opt.addr >> 1, i2c_opt.dir, i2c_opt.off,
i2c_opt.width, i2c_opt.count);
error = access_bus(fd, i2c_opt);
break;
case 's':