Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b2d90fd
changes to compile runtime under FreeBSD ARM64 host
sec Jun 29, 2022
f333fd0
TOOLSET_PREFIX for FreeBSD host set to llvm during crossbuild
sec Jun 29, 2022
a4b266d
Detect FreeBSD amd64 or aarch64 message
sec Jun 29, 2022
1a6d288
Fix gen-dactable-rva.sh padding zeros
Jun 30, 2022
3f2e848
cross build options for FreeBSD arm64 for mono
Jun 30, 2022
8300f7c
Merge branch 'main' into freebsd.arm64
sec Jun 30, 2022
60ab856
Revert eng/native/configuretools.cmake
Jun 30, 2022
c0c5dea
Try to better detect host arch under FreeBSD
Jun 30, 2022
001bb3d
Indent
Jun 30, 2022
5b623a2
Don't pad DAC_TABLE_RVA
Jun 30, 2022
54d0412
Comment update
Jun 30, 2022
9c8775d
Add freebsd-arm64 RIDs, enable CG2 package generation for FreeBSD builds
Jun 30, 2022
edf36ff
Extra condition for mono build
Jun 30, 2022
951c92a
Added targetos to crossgen2 command during build
sec Jul 5, 2022
98d39cd
Add targetos along with targetarch for crossgen2 commands
sec Jul 5, 2022
88b8895
Merge branch 'dotnet:main' into freebsd.arm64
sec Jul 6, 2022
69a5c15
Typo fixed in comment
sec Jul 7, 2022
ed3368c
Set Cpsr to gp_spsr for FreeBSD/aarch64 (still crashing exception
sec Jul 7, 2022
e1aa560
Merge branch 'main' into freebsd.arm64
sec Aug 11, 2022
4aef1fb
Fix mono configure/build CPU_COUNT for FreeBSD
sec Aug 14, 2022
6575aee
Merge branch 'main' into freebsd.arm64
sec Sep 19, 2022
723ec0b
Merge branch 'main' into freebsd.arm64
sec Oct 20, 2022
48fa1fa
Merge branch 'main' into freebsd.arm64
sec Nov 9, 2022
6f07838
Merge branch 'main' into freebsd.arm64
sec Dec 5, 2022
82139da
Use check_symbol_exists for HAVE_GNU_CPU_COUNT check
sec Dec 5, 2022
3362c01
Merge branch 'main' into freebsd.arm64
sec Dec 21, 2022
14a6f04
fix cross compile error
sec Dec 21, 2022
1303ab7
Merge branch 'main' into freebsd.arm64
sec Jan 5, 2023
e499941
Fix build error with targetos
sec Jan 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions eng/common/cross/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ elseif(TARGET_ARCH_NAME STREQUAL "arm64")
set(CMAKE_SYSTEM_PROCESSOR aarch64)
if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl)
set(TOOLCHAIN "aarch64-alpine-linux-musl")
else()
elseif(LINUX)
set(TOOLCHAIN "aarch64-linux-gnu")
endif()
if(TIZEN)
set(TIZEN_TOOLCHAIN "aarch64-tizen-linux-gnu/9.2.0")
if(TIZEN)
set(TIZEN_TOOLCHAIN "aarch64-tizen-linux-gnu/9.2.0")
endif()
elseif(FREEBSD)
set(triple "aarch64-unknown-freebsd12")
endif()
elseif(TARGET_ARCH_NAME STREQUAL "ppc64le")
set(CMAKE_SYSTEM_PROCESSOR ppc64le)
Expand All @@ -66,12 +68,18 @@ elseif(TARGET_ARCH_NAME STREQUAL "x86")
if(TIZEN)
set(TIZEN_TOOLCHAIN "i586-tizen-linux-gnu/9.2.0")
endif()
elseif (FREEBSD)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(triple "x86_64-unknown-freebsd12")
elseif (ILLUMOS)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(TOOLCHAIN "x86_64-illumos")
elseif(TARGET_ARCH_NAME STREQUAL "x64")
set(CMAKE_SYSTEM_PROCESSOR x86_64)
if(LINUX)
set(TOOLCHAIN "x86_64-linux-gnu")
if(TIZEN)
set(TIZEN_TOOLCHAIN "x86_64-tizen-linux-gnu/9.2.0")
endif()
elseif(FREEBSD)
set(triple "x86_64-unknown-freebsd12")
elseif(ILLUMOS)
set(TOOLCHAIN "x86_64-illumos")
endif()
else()
message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, armv6, arm64, ppc64le, s390x and x86 are supported!")
endif()
Expand Down Expand Up @@ -218,7 +226,7 @@ endif()

# Specify compile options

if((TARGET_ARCH_NAME MATCHES "^(arm|armv6|armel|arm64|ppc64le|s390x)$" AND NOT ANDROID) OR ILLUMOS)
if((TARGET_ARCH_NAME MATCHES "^(arm|armv6|armel|arm64|ppc64le|s390x)$" AND NOT ANDROID AND NOT FREEBSD) OR ILLUMOS)
set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN})
set(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN})
set(CMAKE_ASM_COMPILER_TARGET ${TOOLCHAIN})
Expand Down
8 changes: 7 additions & 1 deletion eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,13 @@ if (CLR_CMAKE_HOST_UNIX)
clr_unknown_arch()
endif()
elseif(CLR_CMAKE_HOST_FREEBSD)
message("Detected FreeBSD amd64")
if(CLR_CMAKE_HOST_UNIX_ARM64)
message("Detected FreeBSD aarch64")
elseif(CLR_CMAKE_HOST_UNIX_AMD64)
message("Detected FreeBSD amd64")
else()
message(FATAL_ERROR "Unsupported FreeBSD architecture")
endif()
elseif(CLR_CMAKE_HOST_NETBSD)
message("Detected NetBSD amd64")
elseif(CLR_CMAKE_HOST_SUNOS)
Expand Down
8 changes: 7 additions & 1 deletion eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,13 @@ endif(CLR_CMAKE_HOST_OS STREQUAL Android)

if(CLR_CMAKE_HOST_OS STREQUAL FreeBSD)
set(CLR_CMAKE_HOST_UNIX 1)
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL amd64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64)
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64)
set(CLR_CMAKE_HOST_UNIX_ARM64 1)
else()
clr_unknown_arch()
endif()
set(CLR_CMAKE_HOST_FREEBSD 1)
endif(CLR_CMAKE_HOST_OS STREQUAL FreeBSD)

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/inc/crosscomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ typedef struct _T_KNONVOLATILE_CONTEXT_POINTERS {
#define DAC_CS_NATIVE_DATA_SIZE 12
#elif defined(TARGET_FREEBSD) && defined(TARGET_AMD64)
#define DAC_CS_NATIVE_DATA_SIZE 24
#elif defined(TARGET_FREEBSD) && defined(TARGET_ARM64)
#define DAC_CS_NATIVE_DATA_SIZE 24
#elif defined(TARGET_LINUX) && defined(TARGET_ARM)
#define DAC_CS_NATIVE_DATA_SIZE 80
#elif defined(TARGET_LINUX) && defined(TARGET_ARM64)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2677,6 +2677,8 @@ PALIMPORT BOOL PALAPI PAL_VirtualUnwindOutOfProc(CONTEXT *context, KNONVOLATILE_
#define PAL_CS_NATIVE_DATA_SIZE 12
#elif defined(__FreeBSD__) && defined(__x86_64__)
#define PAL_CS_NATIVE_DATA_SIZE 24
#elif defined(__FreeBSD__) && defined(HOST_ARM64)
#define PAL_CS_NATIVE_DATA_SIZE 24
#elif defined(__linux__) && defined(HOST_ARM)
#define PAL_CS_NATIVE_DATA_SIZE 80
#elif defined(__linux__) && defined(HOST_ARM64)
Expand Down
8 changes: 7 additions & 1 deletion src/coreclr/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,13 @@ elseif(CLR_CMAKE_TARGET_FREEBSD)
set(PAL_PT_READ_D PT_READ_D)
set(PAL_PT_WRITE_D PT_WRITE_D)
set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
set(BSD_REGS_STYLE "((reg).r_##rr)")
if (CLR_CMAKE_HOST_ARCH_AMD64)
set(BSD_REGS_STYLE "((reg).r_##rr)")
elseif(CLR_CMAKE_HOST_ARCH_ARM64)
set(BSD_REGS_STYLE "((reg).rr)")
else()
message(FATAL_ERROR "Unknown FreeBSD architecture")
endif()
set(HAVE_SCHED_OTHER_ASSIGNABLE 1)
elseif(CLR_CMAKE_TARGET_NETBSD)
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
Expand Down
36 changes: 36 additions & 0 deletions src/coreclr/pal/src/exception/seh-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,42 @@ enum
ASSIGN_REG(R29) \
ASSIGN_REG(R30) \
ASSIGN_REG(R31)
#elif (defined(HOST_ARM64) && defined(TARGET_FREEBSD))
#define ASSIGN_UNWIND_REGS \
ASSIGN_REG(X0) \
ASSIGN_REG(X1) \
ASSIGN_REG(X2) \
ASSIGN_REG(X3) \
ASSIGN_REG(X4) \
ASSIGN_REG(X5) \
ASSIGN_REG(X6) \
ASSIGN_REG(X7) \
ASSIGN_REG(X8) \
ASSIGN_REG(X9) \
ASSIGN_REG(X10) \
ASSIGN_REG(X11) \
ASSIGN_REG(X12) \
ASSIGN_REG(X13) \
ASSIGN_REG(X14) \
ASSIGN_REG(X15) \
ASSIGN_REG(X16) \
ASSIGN_REG(X17) \
ASSIGN_REG(X18) \
ASSIGN_REG(X19) \
ASSIGN_REG(X20) \
ASSIGN_REG(X21) \
ASSIGN_REG(X22) \
ASSIGN_REG(X23) \
ASSIGN_REG(X24) \
ASSIGN_REG(X25) \
ASSIGN_REG(X26) \
ASSIGN_REG(X27) \
ASSIGN_REG(X28) \
ASSIGN_REG(Lr) \
ASSIGN_REG(Sp) \
ASSIGN_REG(Pc) \
ASSIGN_REG(Fp) \
ASSIGN_REG(Cpsr)
#else
#error unsupported architecture
#endif
Expand Down
93 changes: 92 additions & 1 deletion src/coreclr/pal/src/include/pal/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,57 @@ inline void *FPREG_Xstate_Ymmh(const ucontext_t *uc)

#if defined(HOST_ARM64)

#ifndef TARGET_OSX
#if defined(TARGET_FREEBSD)

#define MCREG_X0(mc) (mc.mc_gpregs.gp_x[0])
#define MCREG_X1(mc) (mc.mc_gpregs.gp_x[1])
#define MCREG_X2(mc) (mc.mc_gpregs.gp_x[2])
#define MCREG_X3(mc) (mc.mc_gpregs.gp_x[3])
#define MCREG_X4(mc) (mc.mc_gpregs.gp_x[4])
#define MCREG_X5(mc) (mc.mc_gpregs.gp_x[5])
#define MCREG_X6(mc) (mc.mc_gpregs.gp_x[6])
#define MCREG_X7(mc) (mc.mc_gpregs.gp_x[7])
#define MCREG_X8(mc) (mc.mc_gpregs.gp_x[8])
#define MCREG_X9(mc) (mc.mc_gpregs.gp_x[9])
#define MCREG_X10(mc) (mc.mc_gpregs.gp_x[10])
#define MCREG_X11(mc) (mc.mc_gpregs.gp_x[11])
#define MCREG_X12(mc) (mc.mc_gpregs.gp_x[12])
#define MCREG_X13(mc) (mc.mc_gpregs.gp_x[13])
#define MCREG_X14(mc) (mc.mc_gpregs.gp_x[14])
#define MCREG_X15(mc) (mc.mc_gpregs.gp_x[15])
#define MCREG_X16(mc) (mc.mc_gpregs.gp_x[16])
#define MCREG_X17(mc) (mc.mc_gpregs.gp_x[17])
#define MCREG_X18(mc) (mc.mc_gpregs.gp_x[18])
#define MCREG_X19(mc) (mc.mc_gpregs.gp_x[19])
#define MCREG_X20(mc) (mc.mc_gpregs.gp_x[20])
#define MCREG_X21(mc) (mc.mc_gpregs.gp_x[21])
#define MCREG_X22(mc) (mc.mc_gpregs.gp_x[22])
#define MCREG_X23(mc) (mc.mc_gpregs.gp_x[23])
#define MCREG_X24(mc) (mc.mc_gpregs.gp_x[24])
#define MCREG_X25(mc) (mc.mc_gpregs.gp_x[25])
#define MCREG_X26(mc) (mc.mc_gpregs.gp_x[26])
#define MCREG_X27(mc) (mc.mc_gpregs.gp_x[27])
#define MCREG_X28(mc) (mc.mc_gpregs.gp_x[28])

#define MCREG_Cpsr(mc) (mc.mc_fpregs.fp_sr)
#define MCREG_Lr(mc) (mc.mc_gpregs.gp_lr)
#define MCREG_Sp(mc) (mc.mc_gpregs.gp_sp)
#define MCREG_Pc(mc) (mc.mc_gpregs.gp_elr)
#define MCREG_Fp(mc) (mc.mc_gpregs.gp_x[29])

inline
struct fpregs* GetNativeSigSimdContext(native_context_t *mc)
{
return &(mc->uc_mcontext.mc_fpregs);
}

inline
const struct fpregs* GetConstNativeSigSimdContext(const native_context_t *mc)
{
return GetNativeSigSimdContext(const_cast<native_context_t*>(mc));
}

#elif !defined(TARGET_OSX) // TARGET_FREEBSD

#define MCREG_X0(mc) ((mc).regs[0])
#define MCREG_X1(mc) ((mc).regs[1])
Expand Down Expand Up @@ -912,6 +962,8 @@ const VfpSigFrame* GetConstNativeSigSimdContext(const native_context_t *mc)

#ifdef HOST_64BIT

#ifdef HOST_AMD64

#define BSDREG_Rbx(reg) BSD_REGS_STYLE(reg,RBX,rbx)
#define BSDREG_Rcx(reg) BSD_REGS_STYLE(reg,RCX,rcx)
#define BSDREG_Rdx(reg) BSD_REGS_STYLE(reg,RDX,rdx)
Expand All @@ -933,6 +985,45 @@ const VfpSigFrame* GetConstNativeSigSimdContext(const native_context_t *mc)
#define BSDREG_R15(reg) BSD_REGS_STYLE(reg,R15,r15)
#define BSDREG_EFlags(reg) BSD_REGS_STYLE(reg,RFLAGS,rflags)

#elif defined(HOST_ARM64)

#define BSDREG_X0(reg) BSD_REGS_STYLE(reg,X[0],x[0])
#define BSDREG_X1(reg) BSD_REGS_STYLE(reg,X[1],x[1])
#define BSDREG_X2(reg) BSD_REGS_STYLE(reg,X[2],x[2])
#define BSDREG_X3(reg) BSD_REGS_STYLE(reg,X[3],x[3])
#define BSDREG_X4(reg) BSD_REGS_STYLE(reg,X[4],x[4])
#define BSDREG_X5(reg) BSD_REGS_STYLE(reg,X[5],x[5])
#define BSDREG_X6(reg) BSD_REGS_STYLE(reg,X[6],x[6])
#define BSDREG_X7(reg) BSD_REGS_STYLE(reg,X[7],x[7])
#define BSDREG_X8(reg) BSD_REGS_STYLE(reg,X[8],x[8])
#define BSDREG_X9(reg) BSD_REGS_STYLE(reg,X[9],x[9])
#define BSDREG_X10(reg) BSD_REGS_STYLE(reg,X[10],x[10])
#define BSDREG_X11(reg) BSD_REGS_STYLE(reg,X[11],x[11])
#define BSDREG_X12(reg) BSD_REGS_STYLE(reg,X[12],x[12])
#define BSDREG_X13(reg) BSD_REGS_STYLE(reg,X[13],x[13])
#define BSDREG_X14(reg) BSD_REGS_STYLE(reg,X[14],x[14])
#define BSDREG_X15(reg) BSD_REGS_STYLE(reg,X[15],x[15])
#define BSDREG_X16(reg) BSD_REGS_STYLE(reg,X[16],x[16])
#define BSDREG_X17(reg) BSD_REGS_STYLE(reg,X[17],x[17])
#define BSDREG_X18(reg) BSD_REGS_STYLE(reg,X[18],x[18])
#define BSDREG_X19(reg) BSD_REGS_STYLE(reg,X[19],x[19])
#define BSDREG_X20(reg) BSD_REGS_STYLE(reg,X[20],x[20])
#define BSDREG_X21(reg) BSD_REGS_STYLE(reg,X[21],x[21])
#define BSDREG_X22(reg) BSD_REGS_STYLE(reg,X[22],x[22])
#define BSDREG_X23(reg) BSD_REGS_STYLE(reg,X[23],x[23])
#define BSDREG_X24(reg) BSD_REGS_STYLE(reg,X[24],x[24])
#define BSDREG_X25(reg) BSD_REGS_STYLE(reg,X[25],x[25])
#define BSDREG_X26(reg) BSD_REGS_STYLE(reg,X[26],x[26])
#define BSDREG_X27(reg) BSD_REGS_STYLE(reg,X[27],x[27])
#define BSDREG_X28(reg) BSD_REGS_STYLE(reg,X[28],x[28])
#define BSDREG_Pc(reg) BSD_REGS_STYLE(reg,Elr,elr)
#define BSDREG_Fp(reg) BSD_REGS_STYLE(reg,X[29],x[29])
#define BSDREG_Sp(reg) BSD_REGS_STYLE(reg,Sp,sp)
#define BSDREG_Lr(reg) BSD_REGS_STYLE(reg,Lr,lr)
#define BSDREG_Cpsr(reg) BSD_REGS_STYLE(reg,Spsr,spsr)

#endif // HOST_AMD64

#else // HOST_64BIT

#define BSDREG_Ebx(reg) BSD_REGS_STYLE(reg,EBX,ebx)
Expand Down
22 changes: 22 additions & 0 deletions src/coreclr/pal/src/thread/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,17 @@ void CONTEXTToNativeContext(CONST CONTEXT *lpContext, native_context_t *native)
{
*(NEON128*) &fp->__v[i] = lpContext->V[i];
}
#elif defined(TARGET_FREEBSD)
struct fpregs* fp = GetNativeSigSimdContext(native);
if (fp)
{
fp->fp_sr = lpContext->Fpsr;
fp->fp_cr = lpContext->Fpcr;
for (int i = 0; i < 32; i++)
{
*(NEON128*) &fp->fp_q[i] = lpContext->V[i];
}
}
#else // TARGET_OSX
fpsimd_context* fp = GetNativeSigSimdContext(native);
if (fp)
Expand Down Expand Up @@ -740,6 +751,17 @@ void CONTEXTFromNativeContext(const native_context_t *native, LPCONTEXT lpContex
{
lpContext->V[i] = *(NEON128*) &fp->__v[i];
}
#elif defined(TARGET_FREEBSD)
const struct fpregs* fp = GetConstNativeSigSimdContext(native);
if (fp)
{
lpContext->Fpsr = fp->fp_sr;
lpContext->Fpcr = fp->fp_cr;
for (int i = 0; i < 32; i++)
{
lpContext->V[i] = *(NEON128*) &fp->fp_q[i];
}
}
#else // TARGET_OSX
const fpsimd_context* fp = GetConstNativeSigSimdContext(native);
if (fp)
Expand Down
7 changes: 3 additions & 4 deletions src/coreclr/pal/tools/gen-dactable-rva.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ fi
while read -r line; do
if [[ "$line" =~ g_dacTable ]]; then

# Parse line for DAC relative address, if length of value is:
# * shorter than 16, zero pad.
# * longer than 16, capture last 16 characters.
# Parse line for DAC relative address. If length of value is longer than 16,
# capture the last 16 characters.
#
array=($line)
value="$(printf "%016s\n" ${array[2]:(${#array[2]} > 16 ? -16 : 0)})"
value="$(printf "%s\n" ${array[2]:(${#array[2]} > 16 ? -16 : 0)})"

# Write line to file and exit
printf "#define DAC_TABLE_RVA 0x%s\n" "$value" > "$2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3468,6 +3468,14 @@
"any",
"base"
],
"freebsd-arm64": [
"freebsd-arm64",
"freebsd",
"unix-arm64",
"unix",
"any",
"base"
],
"freebsd.12": [
"freebsd.12",
"freebsd",
Expand All @@ -3485,6 +3493,16 @@
"any",
"base"
],
"freebsd.12-arm64": [
"freebsd.12-arm64",
"freebsd.12",
"freebsd-arm64",
"freebsd",
"unix-arm64",
"unix",
"any",
"base"
],
"freebsd.13": [
"freebsd.13",
"freebsd.12",
Expand All @@ -3505,6 +3523,18 @@
"any",
"base"
],
"freebsd.13-arm64": [
"freebsd.13-arm64",
"freebsd.13",
"freebsd.12-arm64",
"freebsd.12",
"freebsd-arm64",
"freebsd",
"unix-arm64",
"unix",
"any",
"base"
],
"gentoo": [
"gentoo",
"linux",
Expand Down
Loading