svn commit: r360387 - in head/sys: kern riscv/include riscv/riscv
John Baldwin
jhb at FreeBSD.org
Mon Apr 27 17:55:42 UTC 2020
Author: jhb
Date: Mon Apr 27 17:55:40 2020
New Revision: 360387
URL: https://svnweb.freebsd.org/changeset/base/360387
Log:
Improve MACHINE_ARCH handling for hard vs soft-float on RISC-V.
For userland, MACHINE_ARCH reflects the current ABI via preprocessor
directives. For the kernel, the hw.machine_arch sysctl uses the ELF
header flags of the current process to select the correct MACHINE_ARCH
value.
Reviewed by: imp, kp
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D24543
Modified:
head/sys/kern/kern_mib.c
head/sys/riscv/include/param.h
head/sys/riscv/riscv/elf_machdep.c
Modified: head/sys/kern/kern_mib.c
==============================================================================
--- head/sys/kern/kern_mib.c Mon Apr 27 17:53:38 2020 (r360386)
+++ head/sys/kern/kern_mib.c Mon Apr 27 17:55:40 2020 (r360387)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/boot.h>
+#include <sys/elf.h>
#include <sys/jail.h>
#include <sys/kernel.h>
#include <sys/limits.h>
Modified: head/sys/riscv/include/param.h
==============================================================================
--- head/sys/riscv/include/param.h Mon Apr 27 17:53:38 2020 (r360386)
+++ head/sys/riscv/include/param.h Mon Apr 27 17:55:40 2020 (r360387)
@@ -46,18 +46,16 @@
#define MACHINE "riscv"
#endif
#ifndef MACHINE_ARCH
-/*
- * Check to see if we're building with hardware floating instructions
- * allowed. We check this instead of hard vs soft float ABI because we build the
- * kernel with soft float ABI to avoid hard float instruction generation. If
- * we ever allow a 'soft ABI but with hard floats' userland, then we'll need
- * to rethink this.
- */
-#ifdef __riscv_flen
-#define MACHINE_ARCH "riscv64"
-#else
+
+/* Always use the hard-float arch for the kernel. */
+#if !defined(_KERNEL) && defined(__riscv_float_abi_soft)
#define MACHINE_ARCH "riscv64sf"
+#else
+#define MACHINE_ARCH "riscv64"
#endif
+#endif
+#ifdef _KERNEL
+#define MACHINE_ARCHES "riscv64 riscv64sf"
#endif
#ifdef SMP
Modified: head/sys/riscv/riscv/elf_machdep.c
==============================================================================
--- head/sys/riscv/riscv/elf_machdep.c Mon Apr 27 17:53:38 2020 (r360386)
+++ head/sys/riscv/riscv/elf_machdep.c Mon Apr 27 17:55:40 2020 (r360387)
@@ -58,6 +58,8 @@ __FBSDID("$FreeBSD$");
#include <machine/elf.h>
#include <machine/md_var.h>
+static const char *riscv_machine_arch(struct proc *p);
+
u_long elf_hwcap;
struct sysentvec elf64_freebsd_sysvec = {
@@ -94,8 +96,19 @@ struct sysentvec elf64_freebsd_sysvec = {
.sv_thread_detach = NULL,
.sv_trap = NULL,
.sv_hwcap = &elf_hwcap,
+ .sv_machine_arch = riscv_machine_arch,
};
INIT_SYSENTVEC(elf64_sysvec, &elf64_freebsd_sysvec);
+
+static const char *
+riscv_machine_arch(struct proc *p)
+{
+
+ if ((p->p_elf_flags & EF_RISCV_FLOAT_ABI_MASK) ==
+ EF_RISCV_FLOAT_ABI_SOFT)
+ return (MACHINE_ARCH "sf");
+ return (MACHINE_ARCH);
+}
static Elf64_Brandinfo freebsd_brand_info = {
.brand = ELFOSABI_FREEBSD,
More information about the svn-src-all
mailing list