diff --git a/sys/riscv/conf/GENERIC b/sys/riscv/conf/GENERIC
index 74ca1a94fc87..ca71f7423cfa 100644
--- a/sys/riscv/conf/GENERIC
+++ b/sys/riscv/conf/GENERIC
@@ -1,208 +1,208 @@
#
# GENERIC -- Generic kernel configuration file for FreeBSD/RISC-V
#
# For more information on this file, please read the config(5) manual page,
# and/or the handbook section on Kernel Configuration Files:
#
# https://docs.freebsd.org/en/books/handbook/kernelconfig/#kernelconfig-config
#
# The handbook is also available locally in /usr/share/doc/handbook
# if you've installed the doc distribution, otherwise always see the
# FreeBSD World Wide Web server (https://www.FreeBSD.org/) for the
# latest information.
#
# An exhaustive list of options and more detailed explanations of the
# device lines is also present in the ../../conf/NOTES and NOTES files.
# If you are in doubt as to the purpose or necessity of a line, check first
# in NOTES.
#
cpu RISCV
ident GENERIC
makeoptions DEBUG=-g # Build kernel with gdb(1) debug symbols
makeoptions WITH_CTF=1 # Run ctfconvert(1) for DTrace support
options SCHED_ULE # ULE scheduler
options PREEMPTION # Enable kernel thread preemption
options VIMAGE # Subsystem virtualization, e.g. VNET
options INET # InterNETworking
options INET6 # IPv6 communications protocols
options TCP_HHOOK # hhook(9) framework for TCP
options IPSEC_SUPPORT # Allow kldload of ipsec and tcpmd5
options ROUTE_MPATH # Multipath routing support
options TCP_OFFLOAD # TCP offload
options TCP_BLACKBOX # Enhanced TCP event logging
options TCP_RFC7413 # TCP Fast Open
options SCTP_SUPPORT # Allow kldload of SCTP
options FFS # Berkeley Fast Filesystem
options SOFTUPDATES # Enable FFS soft updates support
options UFS_ACL # Support for access control lists
options UFS_DIRHASH # Improve performance on big directories
options UFS_GJOURNAL # Enable gjournal-based UFS journaling
options QUOTA # Enable disk quotas for UFS
options NFSCL # Network Filesystem Client
options NFSD # Network Filesystem Server
options NFSLOCKD # Network Lock Manager
options NFS_ROOT # NFS usable as /, requires NFSCL
options MSDOSFS # MSDOS Filesystem
options CD9660 # ISO 9660 Filesystem
options PROCFS # Process filesystem (requires PSEUDOFS)
options PSEUDOFS # Pseudo-filesystem framework
options TMPFS # Efficient memory filesystem
options GEOM_RAID # Soft RAID functionality.
options GEOM_LABEL # Provides labelization
options COMPAT_FREEBSD12 # Compatible with FreeBSD12
options COMPAT_FREEBSD13 # Compatible with FreeBSD13
options COMPAT_FREEBSD14 # Compatible with FreeBSD14
options SCSI_DELAY=5000 # Delay (in ms) before probing SCSI
options KTRACE # ktrace(1) support
options STACK # stack(9) support
options SYSVSHM # SYSV-style shared memory
options SYSVMSG # SYSV-style message queues
options SYSVSEM # SYSV-style semaphores
options _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions
options PRINTF_BUFR_SIZE=128 # Prevent printf output being interspersed.
options KBD_INSTALL_CDEV # install a CDEV entry in /dev
# options HWPMC_HOOKS # Necessary kernel hooks for hwpmc(4)
options AUDIT # Security event auditing
options CAPABILITY_MODE # Capsicum capability mode
options CAPABILITIES # Capsicum capabilities
options MAC # TrustedBSD MAC Framework
options KDTRACE_FRAME # Ensure frames are compiled in
options KDTRACE_HOOKS # Kernel DTrace hooks
options DDB_CTF # Kernel ELF linker loads CTF data
options RACCT # Resource accounting framework
options RACCT_DEFAULT_TO_DISABLED # Set kern.racct.enable=0 by default
options RCTL # Resource limits
options SMP
# RISC-V SBI console
device rcons
# pseudo devices
device clk
device hwreset
device phy
device regulator
device syscon
device syscon_power
device riscv_syscon
# Bus drivers
device pci
# Block devices
device scbus
device da
# VirtIO support
device virtio # Generic VirtIO bus (required)
device virtio_pci # VirtIO PCI device
device vtnet # VirtIO Ethernet device
device virtio_blk # VirtIO Block device
device virtio_mmio # VirtIO MMIO bus
# ATA/SCSI peripherals
device pass # Passthrough device (direct ATA/SCSI access)
# NVM Express (NVMe) support
device nvme # base NVMe driver
options NVME_USE_NVD=0 # prefer the cam(4) based nda(4) driver
device nvd # expose NVMe namespaces as disks, depends on nvme
# USB support
options USB_DEBUG # enable debug msgs
device ohci # OHCI USB interface
device uhci # UHCI USB interface
device ehci # EHCI USB interface (USB 2.0)
device xhci # XHCI USB interface (USB 3.0)
device usb # USB Bus (required)
device ukbd # Keyboard
device umass # Disks/Mass storage - Requires scbus and da
# HID support
options HID_DEBUG # enable debug msgs
device hid # Generic HID support
# Serial (COM) ports
device uart # Generic UART driver
device uart_lowrisc # lowRISC UART driver
device uart_ns8250 # ns8250-type UART driver
# Console
device vt
device kbdmux
# RTC
device goldfish_rtc # QEMU RTC
# Ethernet drivers
device miibus # MII bus support
device xae # Xilinx AXI Ethernet MAC
# DMA support
device xdma # DMA interface
device axidma # Xilinx AXI DMA Controller
# GPIO
device gpio
# SPI
device spibus
device spigen
# Debugging support. Always need this:
options KDB # Enable kernel debugger support.
options KDB_TRACE # Print a stack trace for a panic.
# For full debugger support use (turn off in stable branch):
options DDB # Support DDB.
options GDB # Support remote GDB.
options DEADLKRES # Enable the deadlock resolver
options INVARIANTS # Enable calls of extra sanity checking
options INVARIANT_SUPPORT # Extra sanity checks of internal structures, required by INVARIANTS
options WITNESS # Enable checks to detect deadlocks and cycles
options WITNESS_SKIPSPIN # Don't run witness on spinlocks for speed
options MALLOC_DEBUG_MAXZONES=8 # Separate malloc(9) zones
options ALT_BREAK_TO_DEBUGGER # Enter debugger on keyboard escape sequence
-# options EARLY_PRINTF
+# options EARLY_PRINTF=sbi
options VERBOSE_SYSINIT=0 # Support debug.verbose_sysinit, off by default
# Kernel dump features.
options EKCD # Support for encrypted kernel dumps
options GZIO # gzip-compressed kernel and user dumps
options ZSTDIO # zstd-compressed kernel and user dumps
options DEBUGNET # debugnet networking
options NETDUMP # netdump(4) client support
# Pseudo devices.
device crypto # core crypto support
device loop # Network loopback
device ether # Ethernet support
device vlan # 802.1Q VLAN support
device tuntap # Packet tunnel.
device md # Memory "disks"
device gif # IPv6 and IPv4 tunneling
device firmware # firmware assist module
# MMC/SD/SDIO Card slot support
device sdhci
device mmc # MMC/SD bus
device mmcsd # MMC/SD flash cards
# The `bpf' device enables the Berkeley Packet Filter.
# Be aware of the administrative consequences of enabling this!
# Note that 'bpf' is required for DHCP.
device bpf # Berkeley packet filter
# Flattened Device Tree
options FDT
# I2C support
device iicbus # Bus support, required for iicoc below.
device iicoc # OpenCores I2C controller support
# Include SoC specific configuration
include "std.allwinner"
include "std.sifive"
include "std.starfive"
diff --git a/sys/riscv/riscv/riscv_console.c b/sys/riscv/riscv/riscv_console.c
index d6c4ce4540cb..e582b3385384 100644
--- a/sys/riscv/riscv/riscv_console.c
+++ b/sys/riscv/riscv/riscv_console.c
@@ -1,264 +1,264 @@
/*-
* Copyright (c) 2015-2017 Ruslan Bukin
* All rights reserved.
*
* Portions of this software were developed by SRI International and the
* University of Cambridge Computer Laboratory under DARPA/AFRL contract
* FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
*
* Portions of this software were developed by the University of Cambridge
* Computer Laboratory as part of the CTSRD Project, with support from the
* UK Higher Education Innovation Fund (HEIF).
*
* 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
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/* bus softc */
struct rcons_softc {
struct resource *res[1];
void *ihl[1];
device_t dev;
};
/* CN Console interface */
static tsw_outwakeup_t riscvtty_outwakeup;
static struct ttydevsw riscv_ttydevsw = {
.tsw_flags = TF_NOPREFIX,
.tsw_outwakeup = riscvtty_outwakeup,
};
static int polltime;
static struct callout riscv_callout;
static struct tty *tp = NULL;
#if defined(KDB)
static int alt_break_state;
#endif
static void riscv_timeout(void *);
static cn_probe_t riscv_cnprobe;
static cn_init_t riscv_cninit;
static cn_term_t riscv_cnterm;
static cn_getc_t riscv_cngetc;
static cn_putc_t riscv_cnputc;
static cn_grab_t riscv_cngrab;
static cn_ungrab_t riscv_cnungrab;
CONSOLE_DRIVER(riscv);
#define MAX_BURST_LEN 1
static void
riscv_putc(int c)
{
sbi_console_putchar(c);
}
-#ifdef EARLY_PRINTF
+#if CHECK_EARLY_PRINTF(sbi)
early_putc_t *early_putc = riscv_putc;
#endif
static void
cn_drvinit(void *unused)
{
if (riscv_consdev.cn_pri != CN_DEAD &&
riscv_consdev.cn_name[0] != '\0') {
tp = tty_alloc(&riscv_ttydevsw, NULL);
tty_init_console(tp, 0);
tty_makedev(tp, NULL, "%s", "rcons");
polltime = 1;
callout_init(&riscv_callout, 1);
callout_reset(&riscv_callout, polltime, riscv_timeout, NULL);
}
}
SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);
static void
riscvtty_outwakeup(struct tty *tp)
{
u_char buf[MAX_BURST_LEN];
int len;
int i;
for (;;) {
len = ttydisc_getc(tp, buf, sizeof(buf));
if (len == 0)
break;
KASSERT(len == 1, ("tty error"));
for (i = 0; i < len; i++)
riscv_putc(buf[i]);
}
}
static void
riscv_timeout(void *v)
{
int c;
tty_lock(tp);
while ((c = riscv_cngetc(NULL)) != -1)
ttydisc_rint(tp, c, 0);
ttydisc_rint_done(tp);
tty_unlock(tp);
callout_reset(&riscv_callout, polltime, riscv_timeout, NULL);
}
static void
riscv_cnprobe(struct consdev *cp)
{
cp->cn_pri = CN_NORMAL;
}
static void
riscv_cninit(struct consdev *cp)
{
strcpy(cp->cn_name, "rcons");
}
static void
riscv_cnterm(struct consdev *cp)
{
}
static void
riscv_cngrab(struct consdev *cp)
{
}
static void
riscv_cnungrab(struct consdev *cp)
{
}
static int
riscv_cngetc(struct consdev *cp)
{
int ch;
ch = sbi_console_getchar();
if (ch > 0 && ch < 0xff) {
#if defined(KDB)
kdb_alt_break(ch, &alt_break_state);
#endif
return (ch);
}
return (-1);
}
static void
riscv_cnputc(struct consdev *cp, int c)
{
riscv_putc(c);
}
/* Bus interface */
static int
rcons_probe(device_t dev)
{
device_set_desc(dev, "RISC-V console");
return (BUS_PROBE_DEFAULT);
}
static int
rcons_attach(device_t dev)
{
struct rcons_softc *sc;
if (device_get_unit(dev) != 0)
return (ENXIO);
sc = device_get_softc(dev);
sc->dev = dev;
bus_generic_attach(sc->dev);
return (0);
}
static device_method_t rcons_methods[] = {
DEVMETHOD(device_probe, rcons_probe),
DEVMETHOD(device_attach, rcons_attach),
DEVMETHOD_END
};
static driver_t rcons_driver = {
"rcons",
rcons_methods,
sizeof(struct rcons_softc)
};
DRIVER_MODULE(rcons, nexus, rcons_driver, 0, 0);
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index f72f82c100dc..17a1c814cf75 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -1,593 +1,594 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1982, 1988, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* 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 the University 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 REGENTS 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 REGENTS 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.
*/
#ifndef _SYS_SYSTM_H_
#define _SYS_SYSTM_H_
#include
#include
#include
#include
#include /* for people using printf mainly */
#include
#include
__NULLABILITY_PRAGMA_PUSH
#ifdef _KERNEL
extern int cold; /* nonzero if we are doing a cold boot */
extern int suspend_blocked; /* block suspend due to pending shutdown */
extern int rebooting; /* kern_reboot() has been called. */
extern char version[]; /* system version */
extern char compiler_version[]; /* compiler version */
extern char copyright[]; /* system copyright */
extern int kstack_pages; /* number of kernel stack pages */
extern u_long pagesizes[]; /* supported page sizes */
extern long physmem; /* physical memory */
extern long realmem; /* 'real' memory */
extern char *rootdevnames[2]; /* names of possible root devices */
extern int boothowto; /* reboot flags, from console subsystem */
extern int bootverbose; /* nonzero to print verbose messages */
extern int maxusers; /* system tune hint */
extern int ngroups_max; /* max # of supplemental groups */
extern int vm_guest; /* Running as virtual machine guest? */
extern u_long maxphys; /* max raw I/O transfer size */
/*
* Detected virtual machine guest types. The intention is to expand
* and/or add to the VM_GUEST_VM type if specific VM functionality is
* ever implemented (e.g. vendor-specific paravirtualization features).
* Keep in sync with vm_guest_sysctl_names[].
*/
enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN, VM_GUEST_HV,
VM_GUEST_VMWARE, VM_GUEST_KVM, VM_GUEST_BHYVE, VM_GUEST_VBOX,
VM_GUEST_PARALLELS, VM_LAST };
#endif /* KERNEL */
/*
* Align variables.
*/
#define __read_mostly __section(".data.read_mostly")
#define __read_frequently __section(".data.read_frequently")
#define __exclusive_cache_line __aligned(CACHE_LINE_SIZE) \
__section(".data.exclusive_cache_line")
#if defined(_STANDALONE)
struct ucred;
#endif
#ifdef _KERNEL
#include /* MAXCPU */
#include /* curthread */
#include
extern bool scheduler_stopped;
/*
* If we have already panic'd and this is the thread that called
* panic(), then don't block on any mutexes but silently succeed.
* Otherwise, the kernel will deadlock since the scheduler isn't
* going to run the thread that holds any lock we need.
*/
#define SCHEDULER_STOPPED() __predict_false(scheduler_stopped)
extern int osreldate;
extern const void *zero_region; /* address space maps to a zeroed page */
extern int unmapped_buf_allowed;
#ifdef __LP64__
#define IOSIZE_MAX iosize_max()
#define DEVFS_IOSIZE_MAX devfs_iosize_max()
#else
#define IOSIZE_MAX SSIZE_MAX
#define DEVFS_IOSIZE_MAX SSIZE_MAX
#endif
/*
* General function declarations.
*/
struct inpcb;
struct lock_object;
struct malloc_type;
struct mtx;
struct proc;
struct socket;
struct thread;
struct tty;
struct ucred;
struct uio;
struct _jmp_buf;
struct trapframe;
struct eventtimer;
int setjmp(struct _jmp_buf *) __returns_twice;
void longjmp(struct _jmp_buf *, int) __dead2;
int dumpstatus(vm_offset_t addr, off_t count);
int nullop(void);
int eopnotsupp(void);
int ureadc(int, struct uio *);
void hashdestroy(void *, struct malloc_type *, u_long);
void *hashinit(int count, struct malloc_type *type, u_long *hashmask);
void *hashinit_flags(int count, struct malloc_type *type,
u_long *hashmask, int flags);
#define HASH_NOWAIT 0x00000001
#define HASH_WAITOK 0x00000002
void *phashinit(int count, struct malloc_type *type, u_long *nentries);
void *phashinit_flags(int count, struct malloc_type *type, u_long *nentries,
int flags);
void cpu_flush_dcache(void *, size_t);
void cpu_rootconf(void);
void critical_enter_KBI(void);
void critical_exit_KBI(void);
void critical_exit_preempt(void);
void init_param1(void);
void init_param2(long physpages);
void init_static_kenv(char *, size_t);
void tablefull(const char *);
/*
* Allocate per-thread "current" state in the linuxkpi
*/
extern int (*lkpi_alloc_current)(struct thread *, int);
int linux_alloc_current_noop(struct thread *, int);
#if (defined(KLD_MODULE) && !defined(KLD_TIED)) || defined(KTR_CRITICAL) || !defined(_KERNEL) || defined(GENOFFSET)
#define critical_enter() critical_enter_KBI()
#define critical_exit() critical_exit_KBI()
#else
static __inline void
critical_enter(void)
{
struct thread_lite *td;
td = (struct thread_lite *)curthread;
td->td_critnest++;
atomic_interrupt_fence();
}
static __inline void
critical_exit(void)
{
struct thread_lite *td;
td = (struct thread_lite *)curthread;
KASSERT(td->td_critnest != 0,
("critical_exit: td_critnest == 0"));
atomic_interrupt_fence();
td->td_critnest--;
atomic_interrupt_fence();
if (__predict_false(td->td_owepreempt))
critical_exit_preempt();
}
#endif
#ifdef EARLY_PRINTF
typedef void early_putc_t(int ch);
extern early_putc_t *early_putc;
#define CHECK_EARLY_PRINTF(x) \
__CONCAT(early_printf_, EARLY_PRINTF) == __CONCAT(early_printf_, x)
#define early_printf_1 1
#define early_printf_mvebu 2
#define early_printf_ns8250 3
#define early_printf_pl011 4
#define early_printf_snps 5
+#define early_printf_sbi 6
#else
#define CHECK_EARLY_PRINTF(x) 0
#endif
int kvprintf(char const *, void (*)(int, void*), void *, int,
__va_list) __printflike(1, 0);
void log(int, const char *, ...) __printflike(2, 3);
void log_console(struct uio *);
void vlog(int, const char *, __va_list) __printflike(2, 0);
int asprintf(char **ret, struct malloc_type *mtp, const char *format,
...) __printflike(3, 4);
int printf(const char *, ...) __printflike(1, 2);
int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
int sprintf(char *buf, const char *, ...) __printflike(2, 3);
int uprintf(const char *, ...) __printflike(1, 2);
int vprintf(const char *, __va_list) __printflike(1, 0);
int vasprintf(char **ret, struct malloc_type *mtp, const char *format,
__va_list ap) __printflike(3, 0);
int vsnprintf(char *, size_t, const char *, __va_list) __printflike(3, 0);
int vsnrprintf(char *, size_t, int, const char *, __va_list) __printflike(4, 0);
int vsprintf(char *buf, const char *, __va_list) __printflike(2, 0);
int sscanf(const char *, char const * _Nonnull, ...) __scanflike(2, 3);
int vsscanf(const char * _Nonnull, char const * _Nonnull, __va_list) __scanflike(2, 0);
long strtol(const char *, char **, int);
u_long strtoul(const char *, char **, int);
quad_t strtoq(const char *, char **, int);
u_quad_t strtouq(const char *, char **, int);
void tprintf(struct proc *p, int pri, const char *, ...) __printflike(3, 4);
void vtprintf(struct proc *, int, const char *, __va_list) __printflike(3, 0);
void hexdump(const void *ptr, int length, const char *hdr, int flags);
#define HD_COLUMN_MASK 0xff
#define HD_DELIM_MASK 0xff00
#define HD_OMIT_COUNT (1 << 16)
#define HD_OMIT_HEX (1 << 17)
#define HD_OMIT_CHARS (1 << 18)
#define ovbcopy(f, t, l) bcopy((f), (t), (l))
void explicit_bzero(void * _Nonnull, size_t);
void *memset(void * _Nonnull buf, int c, size_t len);
void *memcpy(void * _Nonnull to, const void * _Nonnull from, size_t len);
void *memmove(void * _Nonnull dest, const void * _Nonnull src, size_t n);
int memcmp(const void *b1, const void *b2, size_t len);
#ifdef SAN_NEEDS_INTERCEPTORS
#define SAN_INTERCEPTOR(func) \
__CONCAT(SAN_INTERCEPTOR_PREFIX, __CONCAT(_, func))
void *SAN_INTERCEPTOR(memset)(void *, int, size_t);
void *SAN_INTERCEPTOR(memcpy)(void *, const void *, size_t);
void *SAN_INTERCEPTOR(memmove)(void *, const void *, size_t);
int SAN_INTERCEPTOR(memcmp)(const void *, const void *, size_t);
#ifndef SAN_RUNTIME
#define bcopy(from, to, len) SAN_INTERCEPTOR(memmove)((to), (from), (len))
#define bzero(buf, len) SAN_INTERCEPTOR(memset)((buf), 0, (len))
#define bcmp(b1, b2, len) SAN_INTERCEPTOR(memcmp)((b1), (b2), (len))
#define memset(buf, c, len) SAN_INTERCEPTOR(memset)((buf), (c), (len))
#define memcpy(to, from, len) SAN_INTERCEPTOR(memcpy)((to), (from), (len))
#define memmove(dest, src, n) SAN_INTERCEPTOR(memmove)((dest), (src), (n))
#define memcmp(b1, b2, len) SAN_INTERCEPTOR(memcmp)((b1), (b2), (len))
#endif /* !SAN_RUNTIME */
#else /* !SAN_NEEDS_INTERCEPTORS */
#define bcopy(from, to, len) __builtin_memmove((to), (from), (len))
#define bzero(buf, len) __builtin_memset((buf), 0, (len))
#define bcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len))
#define memset(buf, c, len) __builtin_memset((buf), (c), (len))
#define memcpy(to, from, len) __builtin_memcpy((to), (from), (len))
#define memmove(dest, src, n) __builtin_memmove((dest), (src), (n))
#define memcmp(b1, b2, len) __builtin_memcmp((b1), (b2), (len))
#endif /* SAN_NEEDS_INTERCEPTORS */
void *memset_early(void * _Nonnull buf, int c, size_t len);
#define bzero_early(buf, len) memset_early((buf), 0, (len))
void *memcpy_early(void * _Nonnull to, const void * _Nonnull from, size_t len);
void *memmove_early(void * _Nonnull dest, const void * _Nonnull src, size_t n);
#define bcopy_early(from, to, len) memmove_early((to), (from), (len))
#define copystr(src, dst, len, outlen) ({ \
size_t __r, __len, *__outlen; \
\
__len = (len); \
__outlen = (outlen); \
__r = strlcpy((dst), (src), __len); \
if (__outlen != NULL) \
*__outlen = ((__r >= __len) ? __len : __r + 1); \
((__r >= __len) ? ENAMETOOLONG : 0); \
})
int __result_use_check copyinstr(const void * __restrict udaddr,
void * _Nonnull __restrict kaddr, size_t len,
size_t * __restrict lencopied);
int __result_use_check copyin(const void * __restrict udaddr,
void * _Nonnull __restrict kaddr, size_t len);
int __result_use_check copyin_nofault(const void * __restrict udaddr,
void * _Nonnull __restrict kaddr, size_t len);
int __result_use_or_ignore_check copyout(const void * _Nonnull __restrict kaddr,
void * __restrict udaddr, size_t len);
int __result_use_or_ignore_check copyout_nofault(
const void * _Nonnull __restrict kaddr, void * __restrict udaddr,
size_t len);
#ifdef SAN_NEEDS_INTERCEPTORS
int SAN_INTERCEPTOR(copyin)(const void *, void *, size_t);
int SAN_INTERCEPTOR(copyinstr)(const void *, void *, size_t, size_t *);
int SAN_INTERCEPTOR(copyout)(const void *, void *, size_t);
#ifndef SAN_RUNTIME
#define copyin(u, k, l) SAN_INTERCEPTOR(copyin)((u), (k), (l))
#define copyinstr(u, k, l, lc) SAN_INTERCEPTOR(copyinstr)((u), (k), (l), (lc))
#define copyout(k, u, l) SAN_INTERCEPTOR(copyout)((k), (u), (l))
#endif /* !SAN_RUNTIME */
#endif /* SAN_NEEDS_INTERCEPTORS */
int fubyte(volatile const void *base);
long fuword(volatile const void *base);
int fuword16(volatile const void *base);
int32_t fuword32(volatile const void *base);
int64_t fuword64(volatile const void *base);
int __result_use_check fueword(volatile const void *base, long *val);
int __result_use_check fueword32(volatile const void *base, int32_t *val);
int __result_use_check fueword64(volatile const void *base, int64_t *val);
int __result_use_or_ignore_check subyte(volatile void *base, int byte);
int __result_use_or_ignore_check suword(volatile void *base, long word);
int __result_use_or_ignore_check suword16(volatile void *base, int word);
int __result_use_or_ignore_check suword32(volatile void *base, int32_t word);
int __result_use_or_ignore_check suword64(volatile void *base, int64_t word);
uint32_t casuword32(volatile uint32_t *base, uint32_t oldval, uint32_t newval);
u_long casuword(volatile u_long *p, u_long oldval, u_long newval);
int casueword32(volatile uint32_t *base, uint32_t oldval, uint32_t *oldvalp,
uint32_t newval);
int casueword(volatile u_long *p, u_long oldval, u_long *oldvalp,
u_long newval);
#if defined(SAN_NEEDS_INTERCEPTORS) && !defined(KCSAN)
int SAN_INTERCEPTOR(fubyte)(volatile const void *base);
int SAN_INTERCEPTOR(fuword16)(volatile const void *base);
int SAN_INTERCEPTOR(fueword)(volatile const void *base, long *val);
int SAN_INTERCEPTOR(fueword32)(volatile const void *base, int32_t *val);
int SAN_INTERCEPTOR(fueword64)(volatile const void *base, int64_t *val);
int SAN_INTERCEPTOR(subyte)(volatile void *base, int byte);
int SAN_INTERCEPTOR(suword)(volatile void *base, long word);
int SAN_INTERCEPTOR(suword16)(volatile void *base, int word);
int SAN_INTERCEPTOR(suword32)(volatile void *base, int32_t word);
int SAN_INTERCEPTOR(suword64)(volatile void *base, int64_t word);
int SAN_INTERCEPTOR(casueword32)(volatile uint32_t *base, uint32_t oldval,
uint32_t *oldvalp, uint32_t newval);
int SAN_INTERCEPTOR(casueword)(volatile u_long *p, u_long oldval,
u_long *oldvalp, u_long newval);
#ifndef SAN_RUNTIME
#define fubyte(b) SAN_INTERCEPTOR(fubyte)((b))
#define fuword16(b) SAN_INTERCEPTOR(fuword16)((b))
#define fueword(b, v) SAN_INTERCEPTOR(fueword)((b), (v))
#define fueword32(b, v) SAN_INTERCEPTOR(fueword32)((b), (v))
#define fueword64(b, v) SAN_INTERCEPTOR(fueword64)((b), (v))
#define subyte(b, w) SAN_INTERCEPTOR(subyte)((b), (w))
#define suword(b, w) SAN_INTERCEPTOR(suword)((b), (w))
#define suword16(b, w) SAN_INTERCEPTOR(suword16)((b), (w))
#define suword32(b, w) SAN_INTERCEPTOR(suword32)((b), (w))
#define suword64(b, w) SAN_INTERCEPTOR(suword64)((b), (w))
#define casueword32(b, o, p, n) SAN_INTERCEPTOR(casueword32)((b), (o), (p), (n))
#define casueword(b, o, p, n) SAN_INTERCEPTOR(casueword)((b), (o), (p), (n))
#endif /* !SAN_RUNTIME */
#endif /* SAN_NEEDS_INTERCEPTORS && !KCSAN */
int sysbeep(int hertz, sbintime_t duration);
void hardclock(int cnt, int usermode);
void hardclock_sync(int cpu);
void statclock(int cnt, int usermode);
void profclock(int cnt, int usermode, uintfptr_t pc);
int hardclockintr(void);
void startprofclock(struct proc *);
void stopprofclock(struct proc *);
void cpu_startprofclock(void);
void cpu_stopprofclock(void);
void suspendclock(void);
void resumeclock(void);
sbintime_t cpu_idleclock(void);
void cpu_activeclock(void);
void cpu_new_callout(int cpu, sbintime_t bt, sbintime_t bt_opt);
void cpu_et_frequency(struct eventtimer *et, uint64_t newfreq);
extern int cpu_disable_c2_sleep;
extern int cpu_disable_c3_sleep;
extern void (*tcp_hpts_softclock)(void);
#define tcp_hpts_softclock() do { \
if (tcp_hpts_softclock != NULL) \
tcp_hpts_softclock(); \
} while (0)
char *kern_getenv(const char *name);
void freeenv(char *env);
int getenv_int(const char *name, int *data);
int getenv_uint(const char *name, unsigned int *data);
int getenv_long(const char *name, long *data);
int getenv_ulong(const char *name, unsigned long *data);
int getenv_string(const char *name, char *data, int size);
int getenv_int64(const char *name, int64_t *data);
int getenv_uint64(const char *name, uint64_t *data);
int getenv_quad(const char *name, quad_t *data);
int getenv_bool(const char *name, bool *data);
bool getenv_is_true(const char *name);
bool getenv_is_false(const char *name);
int kern_setenv(const char *name, const char *value);
int kern_unsetenv(const char *name);
int testenv(const char *name);
int getenv_array(const char *name, void *data, int size, int *psize,
int type_size, bool allow_signed);
#define GETENV_UNSIGNED false /* negative numbers not allowed */
#define GETENV_SIGNED true /* negative numbers allowed */
typedef uint64_t (cpu_tick_f)(void);
void set_cputicker(cpu_tick_f *func, uint64_t freq, bool isvariable);
extern cpu_tick_f *cpu_ticks;
uint64_t cpu_tickrate(void);
uint64_t cputick2usec(uint64_t tick);
#include
/* Initialize the world */
void consinit(void);
void cpu_initclocks(void);
void cpu_initclocks_bsp(void);
void cpu_initclocks_ap(void);
void usrinfoinit(void);
/* Finalize the world */
void kern_reboot(int) __dead2;
void shutdown_nice(int);
/* Stubs for obsolete functions that used to be for interrupt management */
static __inline intrmask_t splhigh(void) { return 0; }
static __inline intrmask_t splimp(void) { return 0; }
static __inline intrmask_t splnet(void) { return 0; }
static __inline intrmask_t spltty(void) { return 0; }
static __inline void splx(intrmask_t ipl __unused) { return; }
/*
* Common `proc' functions are declared here so that proc.h can be included
* less often.
*/
int _sleep(const void * _Nonnull chan, struct lock_object *lock, int pri,
const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags);
#define msleep(chan, mtx, pri, wmesg, timo) \
_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), \
tick_sbt * (timo), 0, C_HARDCLOCK)
#define msleep_sbt(chan, mtx, pri, wmesg, bt, pr, flags) \
_sleep((chan), &(mtx)->lock_object, (pri), (wmesg), (bt), (pr), \
(flags))
int msleep_spin_sbt(const void * _Nonnull chan, struct mtx *mtx,
const char *wmesg, sbintime_t sbt, sbintime_t pr, int flags);
#define msleep_spin(chan, mtx, wmesg, timo) \
msleep_spin_sbt((chan), (mtx), (wmesg), tick_sbt * (timo), \
0, C_HARDCLOCK)
int pause_sbt(const char *wmesg, sbintime_t sbt, sbintime_t pr,
int flags);
static __inline int
pause(const char *wmesg, int timo)
{
return (pause_sbt(wmesg, tick_sbt * timo, 0, C_HARDCLOCK));
}
#define pause_sig(wmesg, timo) \
pause_sbt((wmesg), tick_sbt * (timo), 0, C_HARDCLOCK | C_CATCH)
#define tsleep(chan, pri, wmesg, timo) \
_sleep((chan), NULL, (pri), (wmesg), tick_sbt * (timo), \
0, C_HARDCLOCK)
#define tsleep_sbt(chan, pri, wmesg, bt, pr, flags) \
_sleep((chan), NULL, (pri), (wmesg), (bt), (pr), (flags))
void wakeup(const void *chan);
void wakeup_one(const void *chan);
void wakeup_any(const void *chan);
/*
* Common `struct cdev *' stuff are declared here to avoid #include poisoning
*/
struct cdev;
dev_t dev2udev(struct cdev *x);
const char *devtoname(struct cdev *cdev);
#ifdef __LP64__
size_t devfs_iosize_max(void);
size_t iosize_max(void);
#endif
int poll_no_poll(int events);
/* XXX: Should be void nanodelay(u_int nsec); */
void DELAY(int usec);
int kcmp_cmp(uintptr_t a, uintptr_t b);
/* Root mount holdback API */
struct root_hold_token {
int flags;
const char *who;
TAILQ_ENTRY(root_hold_token) list;
};
struct root_hold_token *root_mount_hold(const char *identifier);
void root_mount_hold_token(const char *identifier, struct root_hold_token *h);
void root_mount_rel(struct root_hold_token *h);
int root_mounted(void);
/*
* Unit number allocation API. (kern/subr_unit.c)
*/
struct unrhdr;
#define UNR_NO_MTX ((void *)(uintptr_t)-1)
struct unrhdr *new_unrhdr(int low, int high, struct mtx *mutex);
void init_unrhdr(struct unrhdr *uh, int low, int high, struct mtx *mutex);
void delete_unrhdr(struct unrhdr *uh);
void clear_unrhdr(struct unrhdr *uh);
void clean_unrhdr(struct unrhdr *uh);
void clean_unrhdrl(struct unrhdr *uh);
int alloc_unr(struct unrhdr *uh);
int alloc_unr_specific(struct unrhdr *uh, u_int item);
int alloc_unrl(struct unrhdr *uh);
void free_unr(struct unrhdr *uh, u_int item);
void *create_iter_unr(struct unrhdr *uh);
int next_iter_unr(void *handle);
void free_iter_unr(void *handle);
struct unrhdr64 {
uint64_t counter;
};
static __inline void
new_unrhdr64(struct unrhdr64 *unr64, uint64_t low)
{
unr64->counter = low;
}
static __inline uint64_t
alloc_unr64(struct unrhdr64 *unr64)
{
return (atomic_fetchadd_64(&unr64->counter, 1));
}
void intr_prof_stack_use(struct thread *td, struct trapframe *frame);
void counted_warning(unsigned *counter, const char *msg);
/*
* APIs to manage deprecation and obsolescence.
*/
void _gone_in(int major, const char *msg);
void _gone_in_dev(device_t dev, int major, const char *msg);
#ifdef NO_OBSOLETE_CODE
#define __gone_ok(m, msg) \
_Static_assert(m < P_OSREL_MAJOR(__FreeBSD_version)), \
"Obsolete code: " msg);
#else
#define __gone_ok(m, msg)
#endif
#define gone_in(major, msg) __gone_ok(major, msg) _gone_in(major, msg)
#define gone_in_dev(dev, major, msg) __gone_ok(major, msg) _gone_in_dev(dev, major, msg)
#ifdef INVARIANTS
#define __diagused
#else
#define __diagused __unused
#endif
#ifdef WITNESS
#define __witness_used
#else
#define __witness_used __unused
#endif
#endif /* _KERNEL */
__NULLABILITY_PRAGMA_POP
#endif /* !_SYS_SYSTM_H_ */