Skip to content

Commit

Permalink
arm64 lib32: prepare arm64 headers to redirect to arm
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mike Karels authored and Mike Karels committed Jul 25, 2023
1 parent f1d5183 commit d5d97be
Show file tree
Hide file tree
Showing 45 changed files with 324 additions and 4 deletions.
13 changes: 9 additions & 4 deletions include/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
60 changes: 60 additions & 0 deletions include/arm/Makefile
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 6 additions & 0 deletions lib/msun/aarch64/fenv.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/fenv.h>
#else /* __arm__ */

#ifndef _FENV_H_
#define _FENV_H_

Expand Down Expand Up @@ -244,3 +248,5 @@ fegetexcept(void)
__END_DECLS

#endif /* !_FENV_H_ */

#endif /* __arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/_align.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/_align.h>
#else /* !__arm__ */

#ifndef _MACHINE__ALIGN_H_
#define _MACHINE__ALIGN_H_

Expand All @@ -42,3 +46,5 @@
#define _ALIGN(p) (((u_long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)

#endif /* !_MACHINE__ALIGN_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/_inttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/_inttypes.h>
#else /* !__arm__ */

#ifndef _MACHINE__INTTYPES_H_
#define _MACHINE__INTTYPES_H_

Expand Down Expand Up @@ -211,3 +215,5 @@
#define SCNxPTR "lx" /* uintptr_t */

#endif /* !_MACHINE__INTTYPES_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/_limits.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/_limits.h>
#else /* !__arm__ */

#ifndef _MACHINE__LIMITS_H_
#define _MACHINE__LIMITS_H_

Expand Down Expand Up @@ -83,3 +87,5 @@
#define __MINSIGSTKSZ (1024 * 4)

#endif /* !_MACHINE__LIMITS_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/_stdint.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/_stdint.h>
#else /* !__arm__ */

#ifndef _MACHINE__STDINT_H_
#define _MACHINE__STDINT_H_

Expand Down Expand Up @@ -156,3 +160,5 @@
#endif /* !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) */

#endif /* !_MACHINE__STDINT_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/_types.h>
#else /* !__arm__ */

#ifndef _MACHINE__TYPES_H_
#define _MACHINE__TYPES_H_

Expand Down Expand Up @@ -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__ */
5 changes: 5 additions & 0 deletions sys/arm64/include/acle-compat.h
Original file line number Diff line number Diff line change
@@ -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__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/armreg.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/armreg.h>
#else /* !__arm__ */

#ifndef _MACHINE_ARMREG_H_
#define _MACHINE_ARMREG_H_

Expand Down Expand Up @@ -1994,3 +1998,5 @@
#define ZCR_LEN_BYTES(x) ((((x) & ZCR_LEN_MASK) + 1) * 16)

#endif /* !_MACHINE_ARMREG_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/asm.h>
#else /* !__arm__ */

#ifndef _MACHINE_ASM_H_
#define _MACHINE_ASM_H_

Expand Down Expand Up @@ -113,3 +117,5 @@
isb

#endif /* _MACHINE_ASM_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/atomic.h>
#else /* !__arm__ */

#ifndef _MACHINE_ATOMIC_H_
#define _MACHINE_ATOMIC_H_

Expand Down Expand Up @@ -670,3 +674,5 @@ atomic_thread_fence_seq_cst(void)

#endif /* KCSAN && !KCSAN_RUNTIME */
#endif /* _MACHINE_ATOMIC_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/bus.h>
#else /* !__arm__ */

#ifndef _MACHINE_BUS_H_
#define _MACHINE_BUS_H_

Expand Down Expand Up @@ -521,3 +525,5 @@ struct bus_space {
#include <machine/bus_dma.h>

#endif /* _MACHINE_BUS_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/counter.h>
#else /* !__arm__ */

#ifndef _MACHINE_COUNTER_H_
#define _MACHINE_COUNTER_H_

Expand Down Expand Up @@ -85,3 +89,5 @@ counter_u64_add(counter_u64_t c, int64_t inc)
}

#endif /* ! _MACHINE_COUNTER_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/cpu.h>
#else /* !__arm__ */

#ifndef _MACHINE_CPU_H_
#define _MACHINE_CPU_H_

Expand Down Expand Up @@ -253,3 +257,5 @@ ADDRESS_TRANSLATE_FUNC(s1e1w)
#endif

#endif /* !_MACHINE_CPU_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/cpufunc.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/cpufunc.h>
#else /* !__arm__ */

#ifndef _MACHINE_CPUFUNC_H_
#define _MACHINE_CPUFUNC_H_

Expand Down Expand Up @@ -193,3 +197,5 @@ bool arm64_get_writable_addr(vm_offset_t, vm_offset_t *);

#endif /* _KERNEL */
#endif /* _MACHINE_CPUFUNC_H_ */

#endif /* !__arm__ */
5 changes: 5 additions & 0 deletions sys/arm64/include/cpuinfo.h
Original file line number Diff line number Diff line change
@@ -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__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/efi.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/efi.h>
#else /* !__arm__ */

#ifndef __ARM64_INCLUDE_EFI_H_
#define __ARM64_INCLUDE_EFI_H_

Expand Down Expand Up @@ -58,3 +62,5 @@ struct efirt_callinfo {
};

#endif /* __ARM64_INCLUDE_EFI_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/elf.h>
#else /* !__arm__ */

#ifndef _MACHINE_ELF_H_
#define _MACHINE_ELF_H_

Expand Down Expand Up @@ -180,3 +184,5 @@ __ElfType(Auxinfo);
#endif

#endif /* !_MACHINE_ELF_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/exec.h
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
/* $FreeBSD$ */

#ifdef __arm__
#include <arm/exec.h>
#else /* !__arm__ */
/* empty */
#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/float.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/float.h>
#else /* !__arm__ */

#ifndef _MACHINE_FLOAT_H_
#define _MACHINE_FLOAT_H_

Expand Down Expand Up @@ -92,3 +96,5 @@ __END_DECLS
#endif /* __ISO_C_VISIBLE >= 2011 */

#endif /* _MACHINE_FLOAT_H_ */

#endif /* !__arm__ */
6 changes: 6 additions & 0 deletions sys/arm64/include/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
* $FreeBSD$
*/

#ifdef __arm__
#include <arm/frame.h>
#else /* !__arm__ */

#ifndef _MACHINE_FRAME_H_
#define _MACHINE_FRAME_H_

Expand Down Expand Up @@ -77,3 +81,5 @@ struct sigframe32 {
#endif /* !LOCORE */

#endif /* !_MACHINE_FRAME_H_ */

#endif /* !__arm__ */
Loading

0 comments on commit d5d97be

Please sign in to comment.