arm64 lib32: prepare arm64 headers to redirect to arm

In order to compile lib32 libraries and other 32-bit code on arm64,
<machine/foo.h> needs to be redirected to an arm header rather
than arm64 when building with -m32.  Ifdef the arm64 headers that
are installed in /usr/include/machine and used by user-level software
(including references from /usr/include/*.h) so that if __arm__ is
defined when including the arm64 version, <arm/foo.h> is included
rather than using the rest of the file's contents.  Some arm headers
had no arm64 equivalent; headers were added just to do the redirection.
These files use #error if __arm__ is not defined to guard against
confusion.  Also add an include/arm Makefile, and modify Makefiles
as needed to install everything, including the arm files in
/usr/include/arm.  fenv.h comes from lib/msun/arm/fenv.h.

The new arm64 headers are:
    acle-compat.h
    cpuinfo.h
    sysreg.h

Reviewed by:	jrtc27, imp
Differential Revision:	https://reviews.freebsd.org/D40944
This commit is contained in:
Mike Karels 2023-07-25 18:59:26 -05:00
parent f1d5183124
commit d5d97bed4a
45 changed files with 324 additions and 4 deletions

View File

@ -9,7 +9,12 @@ PACKAGE=runtime
CLEANFILES= osreldate.h version
SUBDIR= arpa protocols rpcsvc rpc xlocale
.if ${MACHINE_CPUARCH} == "amd64"
SUBDIR+= i386
SUBDIR+= i386
INCLUDE_SUBDIRS+= i386
.endif
.if ${MACHINE_CPUARCH} == "aarch64"
SUBDIR+= arm
INCLUDE_SUBDIRS+= arm
.endif
SUBDIR_PARALLEL=
INCS= a.out.h ar.h assert.h bitstring.h byteswap.h \
@ -353,10 +358,10 @@ compat:
mtree -deU ${NO_ROOT:D-W} ${MTREE_FOLLOWS_SYMLINKS} \
-f ${SRCTOP}/etc/mtree/BSD.include.dist \
-p ${SDESTDIR}${INCLUDEDIR} > /dev/null
.if ${MACHINE_CPUARCH} == "amd64"
.for d in ${INCLUDE_SUBDIRS}
${INSTALL} -d ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 755 \
${SDESTDIR}${INCLUDEDIR}/i386
.endif
${SDESTDIR}${INCLUDEDIR}/${d}
.endfor
copies: .PHONY .META
cd ${SDESTDIR}${INCLUDEDIR}; find ${LDIRS} ${LSUBDIRS} ${LSUBSUBDIRS} crypto \

60
include/arm/Makefile Normal file
View File

@ -0,0 +1,60 @@
# arm headers installed on arm64
.PATH: ${SRCTOP}/sys/arm/include ${SRCTOP}/lib/msun/arm
INCS= _align.h \
_inttypes.h \
_limits.h \
_stdint.h \
_types.h \
acle-compat.h \
armreg.h \
asm.h \
atomic.h \
bus.h \
counter.h \
cpu.h \
cpufunc.h \
cpuinfo.h \
efi.h \
elf.h \
exec.h \
float.h \
frame.h \
ieeefp.h \
param.h \
pcb.h \
pcpu.h \
pmap.h \
proc.h \
profile.h \
pte.h \
reg.h \
reloc.h \
resource.h \
runq.h \
setjmp.h \
signal.h \
sysarch.h \
sysreg.h \
tls.h \
ucontext.h \
vdso.h \
vfp.h \
vmparam.h
# These kernel-only headers are used by procstat's ZFS support.
# This should be fixed.
INCS+= pcpu_aux.h \
sf_buf.h
# from lib/msun/arm
INCS+= fenv.h
INCSDIR= ${INCLUDEDIR}/arm
beforeinstall: armdir
META_TARGETS+= armdir
armdir:
${INSTALL} -d ${TAG_ARGS} -o ${BINOWN} -g ${BINGRP} -m 755 \
${DESTDIR}${INCLUDEDIR}/arm
.include <bsd.prog.mk>

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/fenv.h>
#else /* __arm__ */
#ifndef _FENV_H_
#define _FENV_H_
@ -244,3 +248,5 @@ fegetexcept(void)
__END_DECLS
#endif /* !_FENV_H_ */
#endif /* __arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/_align.h>
#else /* !__arm__ */
#ifndef _MACHINE__ALIGN_H_
#define _MACHINE__ALIGN_H_
@ -42,3 +46,5 @@
#define _ALIGN(p) (((u_long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
#endif /* !_MACHINE__ALIGN_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/_inttypes.h>
#else /* !__arm__ */
#ifndef _MACHINE__INTTYPES_H_
#define _MACHINE__INTTYPES_H_
@ -211,3 +215,5 @@
#define SCNxPTR "lx" /* uintptr_t */
#endif /* !_MACHINE__INTTYPES_H_ */
#endif /* !__arm__ */

View File

@ -27,6 +27,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/_limits.h>
#else /* !__arm__ */
#ifndef _MACHINE__LIMITS_H_
#define _MACHINE__LIMITS_H_
@ -83,3 +87,5 @@
#define __MINSIGSTKSZ (1024 * 4)
#endif /* !_MACHINE__LIMITS_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/_stdint.h>
#else /* !__arm__ */
#ifndef _MACHINE__STDINT_H_
#define _MACHINE__STDINT_H_
@ -156,3 +160,5 @@
#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */
#endif /* !_MACHINE__STDINT_H_ */
#endif /* !__arm__ */

View File

@ -32,6 +32,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/_types.h>
#else /* !__arm__ */
#ifndef _MACHINE__TYPES_H_
#define _MACHINE__TYPES_H_
@ -67,3 +71,5 @@ typedef unsigned int ___wchar_t;
#define __WCHAR_MAX __UINT_MAX /* max value for a wchar_t */
#endif /* !_MACHINE__TYPES_H_ */
#endif /* !__arm__ */

View File

@ -0,0 +1,5 @@
#ifdef __arm__
#include <arm/acle-compat.h>
#else /* !__arm__ */
#error Do not include this header, used only for 32-bit compatibility
#endif /* !__arm__ */

View File

@ -29,6 +29,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/armreg.h>
#else /* !__arm__ */
#ifndef _MACHINE_ARMREG_H_
#define _MACHINE_ARMREG_H_
@ -1994,3 +1998,5 @@
#define ZCR_LEN_BYTES(x) ((((x) & ZCR_LEN_MASK) + 1) * 16)
#endif /* !_MACHINE_ARMREG_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/asm.h>
#else /* !__arm__ */
#ifndef _MACHINE_ASM_H_
#define _MACHINE_ASM_H_
@ -113,3 +117,5 @@
isb
#endif /* _MACHINE_ASM_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/atomic.h>
#else /* !__arm__ */
#ifndef _MACHINE_ATOMIC_H_
#define _MACHINE_ATOMIC_H_
@ -670,3 +674,5 @@ atomic_thread_fence_seq_cst(void)
#endif /* KCSAN && !KCSAN_RUNTIME */
#endif /* _MACHINE_ATOMIC_H_ */
#endif /* !__arm__ */

View File

@ -65,6 +65,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/bus.h>
#else /* !__arm__ */
#ifndef _MACHINE_BUS_H_
#define _MACHINE_BUS_H_
@ -521,3 +525,5 @@ struct bus_space {
#include <machine/bus_dma.h>
#endif /* _MACHINE_BUS_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/counter.h>
#else /* !__arm__ */
#ifndef _MACHINE_COUNTER_H_
#define _MACHINE_COUNTER_H_
@ -85,3 +89,5 @@ counter_u64_add(counter_u64_t c, int64_t inc)
}
#endif /* ! _MACHINE_COUNTER_H_ */
#endif /* !__arm__ */

View File

@ -38,6 +38,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/cpu.h>
#else /* !__arm__ */
#ifndef _MACHINE_CPU_H_
#define _MACHINE_CPU_H_
@ -253,3 +257,5 @@ ADDRESS_TRANSLATE_FUNC(s1e1w)
#endif
#endif /* !_MACHINE_CPU_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/cpufunc.h>
#else /* !__arm__ */
#ifndef _MACHINE_CPUFUNC_H_
#define _MACHINE_CPUFUNC_H_
@ -193,3 +197,5 @@ bool arm64_get_writable_addr(vm_offset_t, vm_offset_t *);
#endif /* _KERNEL */
#endif /* _MACHINE_CPUFUNC_H_ */
#endif /* !__arm__ */

View File

@ -0,0 +1,5 @@
#ifdef __arm__
#include <arm/cpuinfo.h>
#else /* !__arm__ */
#error Do not include this header, used only for 32-bit compatibility
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/efi.h>
#else /* !__arm__ */
#ifndef __ARM64_INCLUDE_EFI_H_
#define __ARM64_INCLUDE_EFI_H_
@ -58,3 +62,5 @@ struct efirt_callinfo {
};
#endif /* __ARM64_INCLUDE_EFI_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/elf.h>
#else /* !__arm__ */
#ifndef _MACHINE_ELF_H_
#define _MACHINE_ELF_H_
@ -180,3 +184,5 @@ __ElfType(Auxinfo);
#endif
#endif /* !_MACHINE_ELF_H_ */
#endif /* !__arm__ */

View File

@ -1 +1,7 @@
/* $FreeBSD$ */
#ifdef __arm__
#include <arm/exec.h>
#else /* !__arm__ */
/* empty */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/float.h>
#else /* !__arm__ */
#ifndef _MACHINE_FLOAT_H_
#define _MACHINE_FLOAT_H_
@ -92,3 +96,5 @@ __END_DECLS
#endif /* __ISO_C_VISIBLE >= 2011 */
#endif /* _MACHINE_FLOAT_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/frame.h>
#else /* !__arm__ */
#ifndef _MACHINE_FRAME_H_
#define _MACHINE_FRAME_H_
@ -77,3 +81,5 @@ struct sigframe32 {
#endif /* !LOCORE */
#endif /* !_MACHINE_FRAME_H_ */
#endif /* !__arm__ */

View File

@ -4,6 +4,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/ieeefp.h>
#else /* !__arm__ */
#ifndef _MACHINE_IEEEFP_H_
#define _MACHINE_IEEEFP_H_
@ -41,3 +45,5 @@ extern fp_except_t fpsetmask(fp_except_t);
__END_DECLS
#endif /* _MACHINE_IEEEFP_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/param.h>
#else /* !__arm__ */
#ifndef _MACHINE_PARAM_H_
#define _MACHINE_PARAM_H_
@ -130,3 +134,5 @@
#define pgtok(x) ((unsigned long)(x) * (PAGE_SIZE / 1024))
#endif /* !_MACHINE_PARAM_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/pcb.h>
#else /* !__arm__ */
#ifndef _MACHINE_PCB_H_
#define _MACHINE_PCB_H_
@ -87,3 +91,5 @@ int savectx(struct pcb *pcb) __returns_twice;
#endif /* !LOCORE */
#endif /* !_MACHINE_PCB_H_ */
#endif /* !__arm__ */

View File

@ -27,6 +27,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/pcpu.h>
#else /* !__arm__ */
#ifndef _MACHINE_PCPU_H_
#define _MACHINE_PCPU_H_
@ -89,3 +93,5 @@ get_curthread(void)
#endif /* _KERNEL */
#endif /* !_MACHINE_PCPU_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/pcpu_aux.h>
#else /* !__arm__ */
#ifndef _MACHINE_PCPU_AUX_H_
#define _MACHINE_PCPU_AUX_H_
@ -50,3 +54,5 @@ _Static_assert(PAGE_SIZE % sizeof(struct pcpu) == 0, "fix pcpu size");
extern struct pcpu pcpu0;
#endif /* _MACHINE_PCPU_AUX_H_ */
#endif /* !__arm__ */

View File

@ -33,6 +33,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/pmap.h>
#else /* !__arm__ */
#ifndef _MACHINE_PMAP_H_
#define _MACHINE_PMAP_H_
@ -198,3 +202,5 @@ void pmap_san_bootstrap(struct arm64_bootparams *);
#endif /* !LOCORE */
#endif /* !_MACHINE_PMAP_H_ */
#endif /* !__arm__ */

View File

@ -31,6 +31,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/proc.h>
#else /* !__arm__ */
#ifndef _MACHINE_PROC_H_
#define _MACHINE_PROC_H_
@ -75,3 +79,5 @@ struct mdproc {
#define KINFO_PROC32_SIZE 816
#endif /* !_MACHINE_PROC_H_ */
#endif /* !__arm__ */

View File

@ -31,6 +31,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/profile.h>
#else /* !__arm__ */
#ifndef _MACHINE_PROFILE_H_
#define _MACHINE_PROFILE_H_
@ -89,3 +93,5 @@ mcount(uintfptr_t frompc)
#endif /* !_KERNEL */
#endif /* !_MACHINE_PROFILE_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/pte.h>
#else /* !__arm__ */
#ifndef _MACHINE_PTE_H_
#define _MACHINE_PTE_H_
@ -188,3 +192,5 @@ typedef uint64_t pt_entry_t; /* page table entry */
#endif /* !_MACHINE_PTE_H_ */
/* End of pte.h */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/reg.h>
#else /* !__arm__ */
#ifndef _MACHINE_REG_H_
#define _MACHINE_REG_H_
@ -91,3 +95,5 @@ struct arm64_addr_mask {
#define __HAVE_REG32
#endif /* !_MACHINE_REG_H_ */
#endif /* !__arm__ */

View File

@ -1 +1,7 @@
/* $FreeBSD$ */
#ifdef __arm__
#include <arm/reloc.h>
#else /* !__arm__ */
/* empty */
#endif /* !__arm__ */

View File

@ -29,6 +29,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/resource.h>
#else /* !__arm__ */
#ifndef _MACHINE_RESOURCE_H_
#define _MACHINE_RESOURCE_H_ 1
@ -47,3 +51,5 @@
#endif
#endif /* !_MACHINE_RESOURCE_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/runq.h>
#else /* !__arm__ */
#ifndef _MACHINE_RUNQ_H_
#define _MACHINE_RUNQ_H_
@ -44,3 +48,5 @@
typedef unsigned long rqb_word_t;
#endif
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/setjmp.h>
#else /* !__arm__ */
#ifndef _MACHINE_SETJMP_H_
#define _MACHINE_SETJMP_H_
@ -71,3 +75,5 @@ typedef struct _jmp_buf { __int128_t _jb[_JBLEN + 1]; } jmp_buf[1];
#endif /* __ASSEMBLER__ */
#endif /* !_MACHINE_SETJMP_H_ */
#endif /* !__arm__ */

View File

@ -26,6 +26,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/sf_buf.h>
#else /* !__arm__ */
#ifndef _MACHINE_SF_BUF_H_
#define _MACHINE_SF_BUF_H_
@ -49,3 +53,5 @@ sf_buf_page(struct sf_buf *sf)
return ((vm_page_t)sf);
}
#endif /* !_MACHINE_SF_BUF_H_ */
#endif /* !__arm__ */

View File

@ -32,6 +32,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/signal.h>
#else /* !__arm__ */
#ifndef _MACHINE_SIGNAL_H_
#define _MACHINE_SIGNAL_H_
@ -48,3 +52,5 @@ struct sigcontext {
#endif
#endif /* !_MACHINE_SIGNAL_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/sysarch.h>
#else /* !__arm__ */
/*
* Architecture specific syscalls (arm64)
*/
@ -45,3 +49,5 @@ __END_DECLS
#endif
#endif /* !_MACHINE_SYSARCH_H_ */
#endif /* !__arm__ */

View File

@ -0,0 +1,5 @@
#ifdef __arm__
#include <arm/sysreg.h>
#else /* !__arm__ */
#error Do not include this header, used only for 32-bit compatibility
#endif /* !__arm__ */

View File

@ -28,6 +28,10 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __arm__
#include <arm/tls.h>
#else /* !__arm__ */
#ifndef _MACHINE_TLS_H_
#define _MACHINE_TLS_H_
@ -53,3 +57,5 @@ _tcb_get(void)
}
#endif /* !_MACHINE_TLS_H_ */
#endif /* !__arm__ */

View File

@ -30,6 +30,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/ucontext.h>
#else /* !__arm__ */
#ifndef _MACHINE_UCONTEXT_H_
#define _MACHINE_UCONTEXT_H_
@ -86,3 +90,5 @@ typedef struct __mcontext32_vfp {
#endif /* COMPAT_FREEBSD32 */
#endif /* !_MACHINE_UCONTEXT_H_ */
#endif /* !__arm__ */

View File

@ -25,6 +25,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/vdso.h>
#else /* !__arm__ */
#ifndef _MACHINE_VDSO_H_
#define _MACHINE_VDSO_H_
@ -37,3 +41,5 @@
#define VDSO_TIMEHANDS_MD32 VDSO_TIMEHANDS_MD
#endif /* !_MACHINE_VDSO_H_ */
#endif /* !__arm__ */

View File

@ -28,6 +28,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/vfp.h>
#else /* !__arm__ */
#ifndef _MACHINE_VFP_H_
#define _MACHINE_VFP_H_
@ -113,3 +117,5 @@ void set_fpcontext32(struct thread *td, mcontext32_vfp_t *mcp);
#endif
#endif /* !_MACHINE_VFP_H_ */
#endif /* !__arm__ */

View File

@ -36,6 +36,10 @@
* $FreeBSD$
*/
#ifdef __arm__
#include <arm/vmparam.h>
#else /* !__arm__ */
#ifndef _MACHINE_VMPARAM_H_
#define _MACHINE_VMPARAM_H_
@ -275,3 +279,5 @@ extern vm_offset_t vm_max_kernel_address;
#define MINIDUMP_PAGE_TRACKING 1
#endif /* !_MACHINE_VMPARAM_H_ */
#endif /* !__arm__ */