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
This commit is contained in:
John Baldwin 2020-04-27 17:55:40 +00:00
parent 3da4d19be4
commit 61bbe53c2d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=360387
3 changed files with 22 additions and 10 deletions

View File

@ -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>

View File

@ -46,19 +46,17 @@
#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
#ifndef MAXCPU

View File

@ -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,9 +96,20 @@ 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,
.machine = EM_RISCV,