Skip to contentSkip to conversation

Add support for ARCv3 ISA processors

PATCH Superseded Alexey Brodkin via buildroot 2 participants 10 messages Jan 4, 2024 – Jan 27, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for ARCv3 ISA processors

It's been quite some time since introduction to the market of new Synopsys ARCv3 ISA processors, which are meant to build on top of success of their predecessors in ARCv2 family.

ARCv3 ISA is meant to improve efficiency of high-performance embedded microprocessors and thus by definition is not binary compatible with previous generation of ARC cores such as ARCompact (ARC600 and ARC700 processors) and ARCv2 (ARC EM and ARC HS processors).

Moreover, finally in ARCv3 line there's a 64-bit processor family called ARC HS6x meant to cover cases when 32-bit address space is not enough.

Since ARCv3 ISA in not binary compatible with older ARC cores, we have to switch to newer tools, which in fact are already available as a part of ARC GNU toolchain v2023.09, see [1] & integration of them into Buildroot [2].

Even though that update is long overdue (for too long we kept all that in our GitHub repo [3]) it's better late than never.

I'd like to say thank you for all the folks who used to work on Linux bring-up on ARCv3 processors, most of whom did contribute to these changes I'm sending out today, some even no longer work with us, but still it's another amazing example of close and efficient collaboration of a group of truly highly motivated professionals. And it is my pleasure to work with such talented and bright people!

You guys rock!

[1] https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/tag/arc-2023.09-release
[2] https://lists.buildroot.org/pipermail/buildroot/2024-January/682184.html
[3] https://github.com/foss-for-synopsys-dwc-arc-processors/buildroot

Alexey Brodkin (3):
ARCv3: Add support of ARCv3 32-bit and 64-bit processors
ARC: Add defconfigs for ARC HS58 & HS68 processors in simulators
libffi: ARCv3: Switch to upstream version

 arch/Config.in.arc                            |   51 +-
 arch/arch.mk                                  |    2 +-
 arch/arch.mk.arc                              |    4 +
 board/synopsys/nsim/hs5x.props                |   30 +
 board/synopsys/nsim/hs6x.props                |   30 +
 board/synopsys/nsim/post-image-arcv3.sh       |    4 +
 board/synopsys/nsim/readme.txt                |   16 +
 configs/snps_arc32_defconfig                  |   29 +
 configs/snps_arc64_defconfig                  |   26 +
 package/binutils/Config.in.host               |    3 +
 package/binutils/binutils.mk                  |    8 +
 package/gcc/Config.in.host                    |    6 +
 ...01-arc64-Remove-faulty-sub.f-pattern.patch |   47 +
 package/gdb/Config.in                         |    1 +
 ...ARC-Add-support-for-ARCv3-processors.patch | 4036 +++++++++++++++++
 .../0004-Update-ARC-s-libffi-port-771.patch   |  871 ++++
 package/uclibc/Config.in                      |    2 +-
 support/gnuconfig/config.sub                  |    2 +-
 18 files changed, 5163 insertions(+), 5 deletions(-)
 create mode 100644 board/synopsys/nsim/hs5x.props
 create mode 100644 board/synopsys/nsim/hs6x.props
 create mode 100755 board/synopsys/nsim/post-image-arcv3.sh
 create mode 100644 configs/snps_arc32_defconfig
 create mode 100644 configs/snps_arc64_defconfig
 create mode 100644 package/gcc/arc-2023.09-release/0001-arc64-Remove-faulty-sub.f-pattern.patch
 create mode 100644 package/glibc/0004-ARC-Add-support-for-ARCv3-processors.patch
 create mode 100644 package/libffi/0004-Update-ARC-s-libffi-port-771.patch
Signature · 6 lines
2.31.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 1/3 ARCv3: Add support of ARCv3 32-bit and 64-bit processors

These are new generation of high performance ARC HS5x and HS6x cores that implement new ARCv3 ISA binary incompatible with previous ARCompact & ARCv2.

On top of the ARC GNU toolchain 2023.09 there's an incremental fix [1]. Also instead of adding a reference to glibc fork there's just a patch which adds changes required for ARCv3 support on top of the current glibc. Since most of changes are ARC-specific there shouldn't be any problems with moving to a newer glibc version and as wit hother toolchain components that glibc patch will eventually be gone once ARCv3 changes are accepted in the corresponding upstream projects.

Given ARC HS68 may have 64 KiB MMU pages, this patch depends on the following fix [2].

[1] https://github.com/foss-for-synopsys-dwc-arc-processors/gcc/commit/9729b848e5e4886f9adf10d2adf9d3358e5bf343
[2] https://lists.buildroot.org/pipermail/buildroot/2024-January/682140.html

---
 arch/Config.in.arc                            |   51 +-
 arch/arch.mk                                  |    2 +-
 arch/arch.mk.arc                              |    4 +
 package/binutils/Config.in.host               |    3 +
 package/binutils/binutils.mk                  |    8 +
 package/gcc/Config.in.host                    |    6 +
 ...01-arc64-Remove-faulty-sub.f-pattern.patch |   47 +
 package/gdb/Config.in                         |    1 +
 ...ARC-Add-support-for-ARCv3-processors.patch | 4036 +++++++++++++++++
 package/uclibc/Config.in                      |    2 +-
 support/gnuconfig/config.sub                  |    2 +-
 11 files changed, 4157 insertions(+), 5 deletions(-)
 create mode 100644 package/gcc/arc-2023.09-release/0001-arc64-Remove-faulty-sub.f-pattern.patch
 create mode 100644 package/glibc/0004-ARC-Add-support-for-ARCv3-processors.patch
arch/Config.in.arc +49 -2
index 388d3496bc..29b72b4850 100644
@@ -49,18 +49,53 @@ config BR2_archs4x
 	   - Dual and Quad multiply and MAC operations
 	   - Double-precision FPU
 
+config BR2_arc64
+	bool "64-bit ARC HS68"
+	select BR2_ARCH_IS_64
+	help
+	   64-bit ARC HS6x processor
+
+config BR2_arc32
+	bool "32-bit ARC HS58"
+	help
+	   32-bit ARC HS5x processor
+
+endchoice
+
+if BR2_arc64
+
+choice
+	prompt "Floating point strategy"
+
+config BR2_ARC64_SOFT_FLOAT
+	bool "Soft float"
+	help
+	  This option uses software emulated floating point code for ARC
+	  cores with Floating Point unit not configured.
+
+config BR2_ARC64_HARD_FLOAT
+	bool "ARCv3 Floating Point Unit"
+	help
+	  This option uses Hardware Floating Point Unit in ARCv3 ISA
+	  based ARC cores.
+
 endchoice
 
+endif
+
 # Choice of atomic instructions presence
 config BR2_ARC_ATOMIC_EXT
 	bool "Atomic extension (LLOCK/SCOND instructions)"
 	default y if BR2_arc770d
 	default y if BR2_archs38 || BR2_archs38_64mpy || BR2_archs38_full
 	default y if BR2_archs4x_rel31 || BR2_archs4x
+	default y if BR2_arc64 || BR2_arc32
 
 config BR2_ARCH
-	default "arc"	if BR2_arcle
-	default "arceb"	if BR2_arceb
+	default "arc"	if BR2_arcle && !BR2_arc64 && !BR2_arc32
+	default "arceb"	if BR2_arceb && !BR2_arc64 && !BR2_arc32
+	default "arc64" if BR2_arc64
+	default "arc32" if BR2_arc32
 
 config BR2_NORMALIZED_ARCH
 	default "arc"
@@ -81,14 +116,22 @@ config BR2_GCC_TARGET_CPU
 	default "hs38_linux"	 if BR2_archs38_full
 	default "hs4x_rel31"	 if BR2_archs4x_rel31
 	default "hs4x"	 if BR2_archs4x
+	default "hs5x"	 if BR2_arc32
+	default "hs6x"	 if BR2_arc64
+
+config BR2_GCC_TARGET_FPU
+	default "fpud"   if BR2_ARC64_HARD_FLOAT
 
 config BR2_READELF_ARCH_NAME
 	default "ARCompact"	if BR2_arc750d || BR2_arc770d
 	default "ARCv2"		if BR2_archs38 || BR2_archs38_64mpy || BR2_archs38_full
 	default "ARCv2"		if BR2_archs4x_rel31 || BR2_archs4x
+	default "Synopsys ARCv3 64-bit processor"	if BR2_arc64
+	default "Synopsys ARCv3 32-bit processor"	if BR2_arc32
 
 choice
 	prompt "MMU Page Size"
+	default BR2_ARC_PAGE_SIZE_4K	if BR2_arc64 || BR2_arc32
 	default BR2_ARC_PAGE_SIZE_8K
 	help
 	  MMU starting from version 3 (found in ARC 770) and now
@@ -117,6 +160,10 @@ config BR2_ARC_PAGE_SIZE_16K
 	bool "16KB"
 	depends on !BR2_arc750d
 
+config BR2_ARC_PAGE_SIZE_64K
+	bool "64KB"
+	depends on BR2_arc64
+
 endchoice
 
 config BR2_ARC_PAGE_SIZE
arch/arch.mk +1 -1
index 23733eb199..102fe8029f 100644
@@ -31,7 +31,7 @@ else ifeq ($(BR2_ARC_PAGE_SIZE_16K),y)
 ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384
 TARGET_CFLAGS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384
 TARGET_LDFLAGS += -Wl,-z,max-page-size=16384 -Wl,-z,common-page-size=16384
-else ifeq ($(BR2_ARM64_PAGE_SIZE_64K),y)
+else ifeq ($(BR2_ARC_PAGE_SIZE_64K)$(BR2_ARM64_PAGE_SIZE_64K),y)
 ARCH_TOOLCHAIN_WRAPPER_OPTS += -Wl,-z,max-page-size=65536 -Wl,-z,common-page-size=65536
 TARGET_CFLAGS += -Wl,-z,max-page-size=65536 -Wl,-z,common-page-size=65536
 TARGET_LDFLAGS += -Wl,-z,max-page-size=65536 -Wl,-z,common-page-size=65536
arch/arch.mk.arc +4 -0
index 42037626a6..2d56fe01cf 100644
@@ -2,7 +2,11 @@ ifeq ($(BR2_arc),y)
 
 # -matomic is always required when the ARC core has the atomic extensions
 ifeq ($(BR2_ARC_ATOMIC_EXT),y)
+ifeq ($(BR2_arc64)$(BR2_arc32),y)
+ARCH_TOOLCHAIN_WRAPPER_OPTS += -matomic=1
+else
 ARCH_TOOLCHAIN_WRAPPER_OPTS += -matomic
 endif
+endif
 
 endif
package/binutils/Config.in.host +3 -0
index 2f1ddf4bdc..032152086b 100644
@@ -18,12 +18,15 @@ choice
 config BR2_BINUTILS_VERSION_2_39_X
 	bool "binutils 2.39"
 	select BR2_PACKAGE_BINUTILS_HAS_NO_LIBSFRAME
+	depends on !(BR2_arc32 || BR2_arc64)
 
 config BR2_BINUTILS_VERSION_2_40_X
 	bool "binutils 2.40"
+	depends on !(BR2_arc32 || BR2_arc64)
 
 config BR2_BINUTILS_VERSION_2_41_X
 	bool "binutils 2.41"
+	depends on !(BR2_arc32 || BR2_arc64)
 
 config BR2_BINUTILS_VERSION_ARC
 	bool "binutils arc (2.41)"
package/binutils/binutils.mk +8 -0
index 6846933646..d15588d952 100644
@@ -21,6 +21,12 @@ BINUTILS_SOURCE = binutils-gdb-$(BINUTILS_VERSION).tar.gz
 BINUTILS_FROM_GIT = y
 endif
 
+ifeq ($(BINUTILS_VERSION),arc64)
+BINUTILS_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,binutils-gdb,$(BINUTILS_VERSION))
+BINUTILS_SOURCE = binutils-gdb-$(BINUTILS_VERSION).tar.gz
+BINUTILS_FROM_GIT = y
+endif
+
 BINUTILS_SITE ?= $(BR2_GNU_MIRROR)/binutils
 BINUTILS_SOURCE ?= binutils-$(BINUTILS_VERSION).tar.xz
 BINUTILS_EXTRA_CONFIG_OPTIONS = $(call qstrip,$(BR2_BINUTILS_EXTRA_CONFIG_OPTIONS))
@@ -31,6 +37,8 @@ BINUTILS_LICENSE = GPL-3.0+, libiberty LGPL-2.1+
 BINUTILS_LICENSE_FILES = COPYING3 COPYING.LIB
 BINUTILS_CPE_ID_VENDOR = gnu
 
+BR_NO_CHECK_HASH_FOR += $(BINUTILS_SOURCE)
+
 ifeq ($(BINUTILS_FROM_GIT),y)
 BINUTILS_DEPENDENCIES += host-flex host-bison
 HOST_BINUTILS_DEPENDENCIES += host-flex host-bison
package/gcc/Config.in.host +6 -0
index fabc6173f5..3c3d144d72 100644
@@ -30,6 +30,8 @@ config BR2_GCC_VERSION_11_X
 	depends on !BR2_POWERPC_CPU_HAS_SPE
 	# ARC HS48 rel 31 only supported by gcc arc fork.
 	depends on !BR2_archs4x_rel31
+	# ARCv3 processors are not yet supported in upstream GCC 11.x
+	depends on !(BR2_arc32 || BR2_arc64)
 	select BR2_TOOLCHAIN_GCC_AT_LEAST_11
 
 config BR2_GCC_VERSION_12_X
@@ -40,6 +42,8 @@ config BR2_GCC_VERSION_12_X
 	depends on !BR2_POWERPC_CPU_HAS_SPE
 	# ARC HS48 rel 31 only supported by gcc arc fork.
 	depends on !BR2_archs4x_rel31
+	# ARCv3 processors are not yet supported in upstream GCC 12.x
+	depends on !(BR2_arc32 || BR2_arc64)
 	select BR2_TOOLCHAIN_GCC_AT_LEAST_12
 
 config BR2_GCC_VERSION_13_X
@@ -47,6 +51,8 @@ config BR2_GCC_VERSION_13_X
 	# powerpc spe support has been deprecated since gcc 8.x.
 	# https://gcc.gnu.org/ml/gcc/2018-04/msg00102.html
 	depends on !BR2_POWERPC_CPU_HAS_SPE
+	# ARCv3 processors are not yet supported in upstream GCC 13.x
+	depends on !(BR2_arc32 || BR2_arc64)
 	select BR2_TOOLCHAIN_GCC_AT_LEAST_13
 
 endchoice
package/gcc/arc-2023.09-release/0001-arc64-Remove-faulty-sub.f-pattern.patch new file +47 -0

47 lines not on this page · raw message

package/gdb/Config.in +1 -0
index 574ad5462f..bb6bd663d8 100644
@@ -58,6 +58,7 @@ config BR2_PACKAGE_GDB_DEBUGGER
 	bool "full debugger"
 	depends on BR2_USE_WCHAR
 	depends on !BR2_sh
+	depends on !(BR2_arc32 || BR2_arc64)
 	select BR2_PACKAGE_GMP
 	select BR2_PACKAGE_MPFR if (BR2_GDB_VERSION_14 || BR2_arc)
 	select BR2_PACKAGE_NCURSES
package/glibc/0004-ARC-Add-support-for-ARCv3-processors.patch new file +4036 -0

2,781 lines not on this page · raw message

package/uclibc/Config.in +1 -1
index 2555487f06..b763c4b283 100644

Lines of this file are not shown. View the raw message.

support/gnuconfig/config.sub +1 -1
index 9bc49a7e92..75e4df84e8 100755

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 6 lines
2.31.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

Part of the diff is not shown here. View the raw message.

#2 lore raw

Re: [Buildroot] [PATCH 1/3] ARCv3: Add support of ARCv3 32-bit and 64-bit processors

Hi Alexey, All,
Alexey Brodkin via buildroot wrote,

Quoted 9 lines

These are new generation of high performance ARC HS5x and HS6x cores that implement new ARCv3 ISA binary incompatible with previous ARCompact & ARCv2.

On top of the ARC GNU toolchain 2023.09 there's an incremental fix [1]. Also instead of adding a reference to glibc fork there's just a patch which adds changes required for ARCv3 support on top of the current glibc. Since most of changes are ARC-specific there shouldn't be any problems with moving to a newer glibc version and as wit hother

                                                       ^^^^^^^^^^
                                                       with other 
Quoted 3 lines

toolchain components that glibc patch will eventually be gone once ARCv3 changes are accepted in the corresponding upstream projects.

best regards
Waldemar
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

PATCH 2/3 ARC: Add defconfigs for ARC HS58 & HS68 processors in simulators

In reply to Alexey Brodkin via buildroot

To simplify ramp-up with Linux on32-bit ARC HS58 & 64-bit ARC HS68 processors we introduce 2 defconfigs with instructions on how to build embedded Linux image for them and how to run resultoing image.

As with earlier images for simulated platforms it's possible to use the same image with either proprietary Synopsys nSIM simulator, QEMU or even with real FPGA-based prototyping platform called HAPS.

That not only convenient, but also helps to work on observed issues, i.e. run the same image on so very different platforms and see if earlier observed problem is still there. That way we may easily verify various platforms against each other.

For example, if one image works on nSIM & FPGA but doesn't work on QEMU, it's clear something needs to be fixed in QEMU.

But if exactly the same though unexpected behavior is observed on all the platforms, we may say with quite some confidence, that we're dealing with a pure software or tools issue.

---
 board/synopsys/nsim/hs5x.props          | 30 +++++++++++++++++++++++++
 board/synopsys/nsim/hs6x.props          | 30 +++++++++++++++++++++++++
 board/synopsys/nsim/post-image-arcv3.sh |  4 ++++
 board/synopsys/nsim/readme.txt          | 16 +++++++++++++
 configs/snps_arc32_defconfig            | 29 ++++++++++++++++++++++++
 configs/snps_arc64_defconfig            | 26 +++++++++++++++++++++
 6 files changed, 135 insertions(+)
 create mode 100644 board/synopsys/nsim/hs5x.props
 create mode 100644 board/synopsys/nsim/hs6x.props
 create mode 100755 board/synopsys/nsim/post-image-arcv3.sh
 create mode 100644 configs/snps_arc32_defconfig
 create mode 100644 configs/snps_arc64_defconfig
board/synopsys/nsim/hs5x.props new file +30 -0
new file mode 100644
index 0000000000..1d8974650e
@@ -0,0 +1,30 @@
+nsim_isa_family=av3hs
+nsim_isa_dc_hw_prefetch=1
+nsim_isa_dual_issue_option=1
+nsim_isa_atomic_option=2
+nsim_isa_m128_option=0
+nsim_isa_ll64_option=1
+nsim_isa_mpy_option=9
+nsim_isa_div_rem_option=2
+nsim_isa_enable_timer_0=1
+nsim_isa_enable_timer_1=1
+nsim_isa_rtc_option=1
+icache=16384,64,4
+dcache=16384,64,2
+mmu_version=16
+mmu_pagesize=4096
+mmu_address_space=32
+nsim_mem-dev=uart0,kind=dwuart,base=0xf0000000,irq=24
+nsim_isa_number_of_interrupts=32
+nsim_isa_number_of_external_interrupts=32
+nsim_isa_has_fp=1
+nsim_isa_fp_dds_option=1
+nsim_isa_fp_div_option=1
+nsim_isa_fp_dp_option=1
+nsim_isa_fp_hp_option=1
+nsim_isa_fp_vec_option=1
+nsim_isa_fp_wide_option=1
+nsim_isa_mpy64=1
+nsim_isa_div64_option=1
+nsim_isa_dsp_option=3
+nsim_isa_dsp_wide_option=1
board/synopsys/nsim/hs6x.props new file +30 -0
new file mode 100644
index 0000000000..e26cec0a64
@@ -0,0 +1,30 @@
+nsim_fast=0
+nsim_isa_dual_issue_option=1
+nsim_isa_has_hw_pf=1
+nsim_isa_m128_option=1
+nsim_isa_has_hw_pf=1
+nsim_isa_vec64=1
+nsim_isa_family=arc64
+nsim_isa_enable_timer_0=1
+nsim_isa_enable_timer_1=1
+nsim_isa_rtc_option=1
+nsim_isa_addr_size=64
+nsim_isa_pc_size=64
+icache=16384,64,4,o
+dcache=16384,64,4,o
+mmu_version=16
+mmu_pagesize=4096
+mmu_address_space=48
+nsim_mem-dev=uart0,kind=dwuart,base=0xf0000000,irq=24
+nsim_isa_mpy_option=9
+nsim_isa_mpy64=1
+nsim_isa_div64_option=1
+nsim_isa_div_rem_option=2
+nsim_isa_atomic_option=2
+nsim_isa_has_fp=1
+nsim_isa_fp_dds_option=1
+nsim_isa_fp_div_option=1
+nsim_isa_fp_dp_option=1
+nsim_isa_fp_hp_option=1
+nsim_isa_fp_vec_option=1
+nsim_isa_fp_wide_option=1
board/synopsys/nsim/post-image-arcv3.sh new file +4 -0
new file mode 100755
index 0000000000..dd5a634661
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Install vmlinux with debug symbols
+install -m 0644 ${2}/vmlinux ${1}/
board/synopsys/nsim/readme.txt +16 -0
index cc89cf87ac..e43a70038f 100644
@@ -41,3 +41,19 @@ $ nsimdrv \
 	-prop=nsim_isa_pct_counters=8 \
 	-prop=nsim_isa_pct_size=48 \
 	output/images/vmlinux
+
+Build & run image on ARC HS58:
+ * Build:       make snps_arc32_defconfig && make
+ * Run in nSIM: nsimdrv -propsfile=board/synopsys/nsim/hs5x.props output/images/loader
+ * Run in QEMU: qemu-system-arc -M virt,ram_start=0 -cpu hs5x -m 2G -display none \
+                        -nographic -monitor none -kernel output/images/loader \
+                        -netdev user,id=net0 -device virtio-net-device,netdev=net0 \
+                        -device virtio-rng-pci
+
+Build & run image on ARC HS58:
+ * Build:       make snps_arc64_defconfig && make
+ * Run in nSIM: nsimdrv -propsfile=board/synopsys/nsim/hs6x.props output/images/loader
+ * Run in QEMU: qemu-system-arc64 -M virt,ram_start=0 -cpu hs6x -m 2G -display none \
+                        -nographic -monitor none -kernel output/images/loader \
+                        -netdev user,id=net0 -device virtio-net-device,netdev=net0 \
+                        -device virtio-rng-pci
configs/snps_arc32_defconfig new file +29 -0
new file mode 100644
index 0000000000..e94b0fdfeb
@@ -0,0 +1,29 @@
+#Architecture
+BR2_arcle=y
+BR2_arc32=y
+
+# System
+BR2_SYSTEM_DHCP="eth0"
+BR2_TARGET_GENERIC_GETTY=y
+
+# Filesystem
+BR2_TARGET_ROOTFS_INITRAMFS=y
+
+# Image
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/synopsys/nsim/post-image-arcv3.sh"
+BR2_ROOTFS_POST_SCRIPT_ARGS="$(LINUX_DIR)"
+
+# Toolchain
+BR2_TOOLCHAIN_BUILDROOT_UCLIBC=y
+
+# Linux headers same as kernel
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_16=y
+
+# Kernel
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_GIT=y
+BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/linux.git"
+BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="f6e9dab9d1dc1e8fa2acb75504bf5ff86b885b8e"
+BR2_LINUX_KERNEL_DEFCONFIG="haps_hs5x"
+BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y
+BR2_LINUX_KERNEL_IMAGE_TARGET_NAME="loader"
configs/snps_arc64_defconfig new file +26 -0
new file mode 100644
index 0000000000..7275b233eb
@@ -0,0 +1,26 @@
+#Architecture
+BR2_arcle=y
+BR2_arc64=y
+
+# System
+BR2_SYSTEM_DHCP="eth0"
+BR2_TARGET_GENERIC_GETTY=y
+
+# Filesystem
+BR2_TARGET_ROOTFS_INITRAMFS=y
+
+# Image
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/synopsys/nsim/post-image-arcv3.sh"
+BR2_ROOTFS_POST_SCRIPT_ARGS="$(LINUX_DIR)"
+
+# Linux headers same as kernel
+BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_5_16=y
+
+# Kernel
+BR2_LINUX_KERNEL=y
+BR2_LINUX_KERNEL_CUSTOM_GIT=y
+BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/foss-for-synopsys-dwc-arc-processors/linux.git"
+BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="f6e9dab9d1dc1e8fa2acb75504bf5ff86b885b8e"
+BR2_LINUX_KERNEL_DEFCONFIG="haps_arc64"
+BR2_LINUX_KERNEL_IMAGE_TARGET_CUSTOM=y
+BR2_LINUX_KERNEL_IMAGE_TARGET_NAME="loader"
Signature · 6 lines
2.31.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Re: [Buildroot] [PATCH 2/3] ARC: Add defconfigs for ARC HS58 & HS68 processors in simulators

Hi Alexey, All,
Alexey Brodkin via buildroot wrote,

Quoted 1 line

To simplify ramp-up with Linux on32-bit ARC HS58 & 64-bit ARC HS68

                                 ^^^^^^^^
                                 missing space.
Quoted 12 lines

processors we introduce 2 defconfigs with instructions on how to build embedded Linux image for them and how to run resultoing image.

As with earlier images for simulated platforms it's possible to use the same image with either proprietary Synopsys nSIM simulator, QEMU or even with real FPGA-based prototyping platform called HAPS.

That not only convenient, but also helps to work on observed issues, i.e. run the same image on so very different platforms and see if earlier observed problem is still there. That way we may easily verify various platforms against each other.

Quoted 6 lines

For example, if one image works on nSIM & FPGA but doesn't work on QEMU, it's clear something needs to be fixed in QEMU.

But if exactly the same though unexpected behavior is observed on all the platforms, we may say with quite some confidence, that we're dealing with a pure software or tools issue.

It seems networking is broken in nsimdrv for both defconfigs. I am using nsimdrv -v
nSIM, Version: 2022.06 (Build: 006_FREE)

Is there a reason arc32 is using uclibc toolchain and arc64 is using glibc by default?

best regards
Waldemar
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#5 lore raw

Re: [Buildroot] [PATCH 2/3] ARC: Add defconfigs for ARC HS58 & HS68 processors in simulators

Hi Waldemar,

Quoted 3 lines
Quoted 1 line

To simplify ramp-up with Linux on32-bit ARC HS58 & 64-bit ARC HS68

                                 ^^^^^^^^
                                 missing space.

Thanks, fixed in v2, see https://lists.buildroot.org/pipermail/buildroot/2024-January/682466.html

Quoted 15 lines
Quoted 15 lines

processors we introduce 2 defconfigs with instructions on how to build embedded Linux image for them and how to run resultoing image.

As with earlier images for simulated platforms it's possible to use the same image with either proprietary Synopsys nSIM simulator, QEMU or even with real FPGA-based prototyping platform called HAPS.

That not only convenient, but also helps to work on observed issues, i.e. run the same image on so very different platforms and see if earlier observed problem is still there. That way we may easily verify various platforms against each other.

For example, if one image works on nSIM & FPGA but doesn't work on QEMU, it's clear something needs to be fixed in QEMU.

Quoted 7 lines
Quoted 3 lines

But if exactly the same though unexpected behavior is observed on all the platforms, we may say with quite some confidence, that we're dealing with a pure software or tools issue.

It seems networking is broken in nsimdrv for both defconfigs. I am using nsimdrv -v
nSIM, Version: 2022.06 (Build: 006_FREE)

First of all, 2022.06 is quite old and for good ARCv3 support you'd rather switch to a newer version. Here https://www.synopsys.com/cgi-bin/dwarcnsim/req1.cgi
we have 2023.06.

Please get that later version, give it a try and let me know - if problems still happen - we'll take a look at it.

But frankly speaking since QEMU port for ARC became stable I've been using it for most of the purposes especally related to Linux stuff. That's because QEMU has much nicer integration with the host. For example, SLIRP networking doesn't require to mess with TUN/TAP stuff with elevated permissions, you may mount various block devices and even pass-through USB & PCIe devices.

You may find more information on how to build and use QEMU for ARC here:
https://foss-for-synopsys-dwc-arc-processors.github.io/experimental-documentation/2023.09/simulators/qemu/

Quoted 2 lines

Is there a reason arc32 is using uclibc toolchain and arc64 is using glibc by default?

Good that you asked :)

Back in the day uClibc used to be the default C library in Buildroot, so the situation was quite the reverse: arc64 was forcefully set to use glibc. Because we've started from glibc for ARCv3 as the ultimate and complete solution and had it working. But then pretty unexpectedly we've got uClibc port for ARC HS58. Sergey Matyukevich who joined Synopsys at that time made that as a warm-up project literally in a week. And so we decided to keep at least ARC HS58 with the default C library (which used to be uClibc), while for HS68 we had to use glibc as adding new 64-bit port to uClibc could have been a much bigger project.

Then eventually glibc dethroned uClibc as the default C library and situation has changed - now HS58 was using non-default C library.

But my take on that is we're getting more testing of things:
- glibc for 32-bit targets is tested with ARCv2 defconfigs
- uClibc for 32-bit ARC targets is tested with HS58 defconfigs
- glibc for 64-bit ARC HS68 is tested by its defconfigs

If you think though we should switch HS58 defconfig to glibc - we may easily do that, as glibc works there perfectly fine.

-Alexey
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#6 lore raw

Re: [Buildroot] [PATCH 2/3] ARC: Add defconfigs for ARC HS58 & HS68 processors in simulators

Hi Alexey,
Alexey Brodkin wrote,

Quoted 6 lines

Hi Waldemar,

Quoted 3 lines

It seems networking is broken in nsimdrv for both defconfigs. I am using nsimdrv -v
nSIM, Version: 2022.06 (Build: 006_FREE)

Quoted 6 lines

First of all, 2022.06 is quite old and for good ARCv3 support you'd rather switch to a newer version. Here https://www.synopsys.com/cgi-bin/dwarcnsim/req1.cgi
we have 2023.06.

Please get that later version, give it a try and let me know - if problems still happen - we'll take a look at it.

I now checked with 2023.06 and the network does not come up here, too.

best regards
Waldemar
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#7 lore raw

PATCH 3/3 libffi: ARCv3: Switch to upstream version

In reply to Alexey Brodkin via buildroot

ARCv3 processors support was added to the upstream libffi project a while ago, see [1]. Both 32- (ARC HS58) and 64-bit (ARC HS68 ) versions are supported.

Unfortunately, there was no release of libffi since October 2022 and so our changes got stuck in their development branch. Thus, we need to apply that change to the Buildroot separately.

[1] https://github.com/libffi/libffi/commit/c4df19c99f8d8841942e3edaadbf331d30e298c8

---
 .../0004-Update-ARC-s-libffi-port-771.patch   | 871 ++++++++++++++++++
 1 file changed, 871 insertions(+)
 create mode 100644 package/libffi/0004-Update-ARC-s-libffi-port-771.patch
package/libffi/0004-Update-ARC-s-libffi-port-771.patch new file +871 -0
new file mode 100644
index 0000000000..a0d93b91db
@@ -0,0 +1,871 @@
+From 9a494f3902cb9c096c98033311c24a61b6ecb73c Mon Sep 17 00:00:00 2001
+From: Claudiu Zissulescu <[email protected]>
+Date: Sat, 18 Feb 2023 03:33:47 +0200
+Subject: [PATCH] Update ARC's libffi port (#771)
+
+* Add support for ARC and ARC64
+
+Add support for ARC/ARC32/ARC64
+
+* Implementation of GO Closure for ARC/ARC32/ARC64 Architectures
+
+---------
+
+Co-authored-by: Nuno Cardoso <[email protected]>
+Co-authored-by: Luis Silva <[email protected]>
+---
+ src/arc/arcompact.S | 263 +++++++++++++++---------
+ src/arc/ffi.c       | 473 ++++++++++++++++++++++++++++++--------------
+ src/arc/ffitarget.h |  14 ++
+ 3 files changed, 508 insertions(+), 242 deletions(-)
+
+diff --git a/src/arc/arcompact.S b/src/arc/arcompact.S
+index 03715fd..1d7f1a1 100644
+--- a/src/arc/arcompact.S
++++ b/src/arc/arcompact.S
+@@ -33,103 +33,178 @@
+ #define ENTRY(x) .globl CNAME(x)` .type CNAME(x),%function` CNAME(x):
+ #endif
+ 
++#if __SIZEOF_POINTER__ == 8
++#define PTRS 8
++#define FLTS 8
++#define LARG ldl
++#define SARG stl
++#define ADDPTR addl
++#define MOVPTR movl_s
++#else
++#define PTRS 4
++#define FLTS 4
++#define LARG ld
++#define SARG st
++#define ADDPTR add
++#define MOVPTR mov_s
++#endif
++
++#define FRAME_LEN (8 * PTRS + 16)
++
+ .text
+ 
+-        /* R0:   ffi_prep_args */
+-        /* R1:   &ecif */
+-        /* R2:   cif->bytes */
+-        /* R3:   fig->flags */
+-        /* R4:   ecif.rvalue */
+-        /* R5:   fn */
+-ENTRY(ffi_call_ARCompact)
++ENTRY(ffi_call_asm)
++        .cfi_startproc
++
+         /* Save registers.  */
+-        st.a       fp, [sp, -4]        /* fp + 20, fp */
+-        push_s     blink               /* fp + 16, blink */
+-        st.a       r4, [sp, -4]        /* fp + 12, ecif.rvalue */
+-        push_s     r3                  /* fp +  8, fig->flags */
+-        st.a       r5, [sp, -4]        /* fp +  4, fn */
+-        push_s     r2                  /* fp +  0, cif->bytes */
+-        mov        fp, sp
+-
+-        /* Make room for all of the new args.  */
+-        sub        sp, sp, r2
+-
+-        /* Place all of the ffi_prep_args in position.  */
+-        /* ffi_prep_args(char *stack, extended_cif *ecif) */
+-        /* R1 already set.  */
+-
+-        /* And call.  */
+-        jl_s.d     [r0]
+-        mov_s      r0, sp
+-
+-        ld.ab      r12, [fp, 4]        /* cif->bytes */
+-        ld.ab      r11, [fp, 4]        /* fn */
+-
+-        /* Move first 8 parameters in registers...  */
+-        ld_s       r0, [sp]
+-        ld_s       r1, [sp, 4]
+-        ld_s       r2, [sp, 8]
+-        ld_s       r3, [sp, 12]
+-        ld         r4, [sp, 16]
+-        ld         r5, [sp, 20]
+-        ld         r6, [sp, 24]
+-        ld         r7, [sp, 28]
+-
+-        /* ...and adjust the stack.  */
+-        min        r12, r12, 32
++        .cfi_def_cfa r1, FRAME_LEN
++        SARG    fp, [r1, FRAME_LEN - 2*PTRS]
++        .cfi_offset fp, -2*PTRS
++        SARG    blink, [r1, FRAME_LEN - 1*PTRS]
++        .cfi_offset blink, -1*PTRS
++        ADDPTR  fp, r1, FRAME_LEN
++        MOVPTR  sp, r0
++        .cfi_def_cfa fp, 0
++
++        /* Load arguments.  */
++        MOVPTR  r11, r2      /* fn */
++        MOVPTR  r12, r3      /* closure */
++
++        /* Save arguments.  */
++        LARG    r0, [fp, -FRAME_LEN+0*PTRS]
++        LARG    r1, [fp, -FRAME_LEN+1*PTRS]
++        LARG    r2, [fp, -FRAME_LEN+2*PTRS]
++        LARG    r3, [fp, -FRAME_LEN+3*PTRS]
++        LARG    r4, [fp, -FRAME_LEN+4*PTRS]
++        LARG    r5, [fp, -FRAME_LEN+5*PTRS]
++        LARG    r6, [fp, -FRAME_LEN+6*PTRS]
++        LARG    r7, [fp, -FRAME_LEN+7*PTRS]
+ 
+         /* Call the function.  */
+-        jl.d       [r11]
+-        add        sp, sp, r12 
+-
+-        mov        sp, fp        
+-        pop_s      r3        /* fig->flags, return type */
+-        pop_s      r2        /* ecif.rvalue, pointer for return value */
+-
+-        /* If the return value pointer is NULL, assume no return value.  */
+-        breq.d     r2, 0, epilogue
+-        pop_s      blink
+-
+-        /* Return INT.  */
+-        brne       r3, FFI_TYPE_INT, return_double
+-        b.d        epilogue
+-        st_s       r0, [r2]        
+-
+-return_double:
+-        brne       r3, FFI_TYPE_DOUBLE, epilogue
+-        st_s       r0, [r2]        
+-        st_s       r1, [r2,4]
+-
+-epilogue:
+-        j_s.d      [blink]
+-        ld.ab      fp, [sp, 4]
+-
+-ENTRY(ffi_closure_ARCompact)
+-        st.a       r0, [sp, -32]
+-        st_s       r1, [sp, 4]
+-        st_s       r2, [sp, 8]
+-        st_s       r3, [sp, 12]
+-        st         r4, [sp, 16]
+-        st         r5, [sp, 20]
+-        st         r6, [sp, 24]
+-        st         r7, [sp, 28]
+-
+-        /* pointer to arguments */
+-        mov_s      r2, sp
+-
+-        /* return value goes here */
+-        sub        sp, sp, 8
+-        mov_s      r1, sp
+-
+-        push_s     blink
++        jl         [r11] 
++
++        /* Save return value (r0/r1)  */
++        SARG    r0, [fp, -FRAME_LEN+0*PTRS]
++        SARG    r1, [fp, -FRAME_LEN+1*PTRS]
++
++        /* Restore and return.  */
++        add     sp, fp, -FRAME_LEN
++        .cfi_def_cfa sp, FRAME_LEN
++        LARG    blink, [fp, -1*PTRS]
++        .cfi_restore blink
++        LARG    fp, [fp, -2*PTRS]
++        .cfi_restore fp
++        j_s     [blink]
++        .cfi_endproc
++        .size   ffi_call_asm, .-ffi_call_asm
++
++/*
++  ffi_closure_asm. Expects address of the passed-in ffi_closure in r8.
++  void ffi_closure_inner (ffi_cif *cif,
++		          void (*fun) (ffi_cif *, void *, void **, void *),
++		          void *user_data,
++		          size_t *stackargs, struct call_context *regargs)
++*/
++
++ENTRY(ffi_closure_asm)
++        .cfi_startproc
++
++        ADDPTR  sp, sp, -FRAME_LEN
++        .cfi_def_cfa_offset FRAME_LEN
++
++        /* Make a frame.  */
++        SARG    fp, [sp, FRAME_LEN-2*PTRS]
++        .cfi_offset fp, -2*PTRS
++        SARG    blink, [sp, FRAME_LEN-1*PTRS]
++        .cfi_offset blink, -1*PTRS
++        ADDPTR  fp, sp, FRAME_LEN
++
++        /* Save arguments.  */
++        SARG    r0, [sp, 0*PTRS]
++        SARG    r1, [sp, 1*PTRS]
++        SARG    r2, [sp, 2*PTRS]
++        SARG    r3, [sp, 3*PTRS]
++        SARG    r4, [sp, 4*PTRS]
++        SARG    r5, [sp, 5*PTRS]
++        SARG    r6, [sp, 6*PTRS]
++        SARG    r7, [sp, 7*PTRS]
++
++        /* Enter C.  */
++        LARG    r0, [r8, FFI_TRAMPOLINE_SIZE+0*PTRS]
++        LARG    r1, [r8, FFI_TRAMPOLINE_SIZE+1*PTRS]
++        LARG    r2, [r8, FFI_TRAMPOLINE_SIZE+2*PTRS]
++        ADDPTR  r3, sp, FRAME_LEN
++        MOVPTR  r4, sp
++
++        /* Call the C code.  */
++        bl      ffi_closure_inner
+         
+-        bl.d       ffi_closure_inner_ARCompact
+-        mov_s      r0, r8                /* codeloc, set by trampoline */
+-
+-        pop_s      blink
+-
+-        /* set return value to r1:r0 */
+-        pop_s      r0
+-        pop_s      r1
+-        j_s.d      [blink]
+-        add_s      sp, sp, 32
++        /* Return values.  */
++        LARG    r0, [sp, 0*PTRS]
++        LARG    r1, [sp, 1*PTRS]
++
++        /* Restore and return.  */
++        LARG    blink, [sp, FRAME_LEN-1*PTRS]
++        .cfi_restore blink
++        LARG    fp, [sp, FRAME_LEN-2*PTRS]
++        .cfi_restore fp
++        ADDPTR  sp, sp, FRAME_LEN
++        .cfi_def_cfa_offset 0
++        j_s     [blink]
++        .cfi_endproc
++        .size ffi_closure_asm, .-ffi_closure_asm
++
++/*
++  ffi_go_closure_asm.  Expects address of the passed-in ffi_go_closure in r12.
++  void ffi_closure_inner (ffi_cif *cif,
++		          void (*fun) (ffi_cif *, void *, void **, void *),
++		          void *user_data,
++		          size_t *stackargs, struct call_context *regargs)
++*/
++
++ENTRY(ffi_go_closure_asm)
++        .cfi_startproc
++
++        ADDPTR  sp, sp, -FRAME_LEN
++        .cfi_def_cfa_offset FRAME_LEN
++
++        /* make a frame */
++        SARG    fp, [sp, FRAME_LEN-2*PTRS]
++        .cfi_offset fp, -2*PTRS
++        SARG    blink, [sp, FRAME_LEN-1*PTRS]
++        .cfi_offset blink, -1*PTRS
++        ADDPTR  fp, sp, FRAME_LEN
++
++        /* save arguments */
++        SARG    r0, [sp, 0*PTRS]
++        SARG    r1, [sp, 1*PTRS]
++        SARG    r2, [sp, 2*PTRS]
++        SARG    r3, [sp, 3*PTRS]
++        SARG    r4, [sp, 4*PTRS]
++        SARG    r5, [sp, 5*PTRS]
++        SARG    r6, [sp, 6*PTRS]
++        SARG    r7, [sp, 7*PTRS]
++
++        /* enter C */
++        LARG    r0, [r12, 1*PTRS]
++        LARG    r1, [r12, 2*PTRS]
++        MOVPTR  r2, r12
++        ADDPTR  r3, sp, FRAME_LEN
++        MOVPTR  r4, sp
++
++        bl      ffi_closure_inner
++
++        /* Return values. */
++        LARG    r0, [sp, 0*PTRS]
++        LARG    r1, [sp, 1*PTRS]
++
++
++        LARG    blink, [sp, FRAME_LEN-1*PTRS]
++        .cfi_restore blink
++        LARG    fp, [sp, FRAME_LEN-2*PTRS]
++        .cfi_restore fp
++        ADDPTR  sp, sp, FRAME_LEN
++        .cfi_def_cfa_offset 0
++        j_s     [blink]
++        .cfi_endproc
++        .size ffi_go_closure_asm, .-ffi_go_closure_asm
+diff --git a/src/arc/ffi.c b/src/arc/ffi.c
+index 4d10b21..d729274 100644
+--- a/src/arc/ffi.c
++++ b/src/arc/ffi.c
+@@ -31,6 +31,34 @@
+ 
+ #include <sys/cachectl.h>
+ 
++#define NARGREG 8
++#define STKALIGN 4
++#define MAXCOPYARG (2 * sizeof(double))
++
++typedef struct call_context
++{
++  size_t r[8];
++  /* used by the assembly code to in-place construct its own stack frame */
++  char frame[16];
++} call_context;
++
++typedef struct call_builder
++{
++  call_context *aregs;
++  int used_integer;
++  //int used_float;
++  size_t *used_stack;
++  void *struct_stack;
++} call_builder;
++
++/* integer (not pointer) less than ABI XLEN */
++/* FFI_TYPE_INT does not appear to be used */
++#if defined(__ARC64_ARCH64__)
++#define IS_INT(type) ((type) >= FFI_TYPE_UINT8 && (type) <= FFI_TYPE_SINT64)
++#else
++#define IS_INT(type) ((type) >= FFI_TYPE_UINT8 && (type) <= FFI_TYPE_SINT32)
++#endif
++
+ /* for little endian ARC, the code is in fact stored as mixed endian for
+    performance reasons */
+ #if __BIG_ENDIAN__
+@@ -39,94 +67,6 @@
+ #define CODE_ENDIAN(x) ( (((uint32_t) (x)) << 16) | (((uint32_t) (x)) >> 16))
+ #endif
+ 
+-/* ffi_prep_args is called by the assembly routine once stack
+-   space has been allocated for the function's arguments.  */
+-
+-void
+-ffi_prep_args (char *stack, extended_cif * ecif)
+-{
+-  unsigned int i;
+-  void **p_argv;
+-  char *argp;
+-  ffi_type **p_arg;
+-
+-  argp = stack;
+-
+-  if (ecif->cif->rtype->type == FFI_TYPE_STRUCT)
+-    {
+-      *(void **) argp = ecif->rvalue;
+-      argp += 4;
+-    }
+-
+-  p_argv = ecif->avalue;
+-
+-  for (i = ecif->cif->nargs, p_arg = ecif->cif->arg_types;
+-       (i != 0); i--, p_arg++)
+-    {
+-      size_t z;
+-      int alignment;
+-
+-      /* align alignment to 4 */
+-      alignment = (((*p_arg)->alignment - 1) | 3) + 1;
+-
+-      /* Align if necessary.  */
+-      if ((alignment - 1) & (unsigned) argp)
+-	argp = (char *) FFI_ALIGN (argp, alignment);
+-
+-      z = (*p_arg)->size;
+-      if (z < sizeof (int))
+-	{
+-	  z = sizeof (int);
+-
+-	  switch ((*p_arg)->type)
+-	    {
+-	    case FFI_TYPE_SINT8:
+-	      *(signed int *) argp = (signed int) *(SINT8 *) (*p_argv);
+-	      break;
+-
+-	    case FFI_TYPE_UINT8:
+-	      *(unsigned int *) argp = (unsigned int) *(UINT8 *) (*p_argv);
+-	      break;
+-
+-	    case FFI_TYPE_SINT16:
+-	      *(signed int *) argp = (signed int) *(SINT16 *) (*p_argv);
+-	      break;
+-
+-	    case FFI_TYPE_UINT16:
+-	      *(unsigned int *) argp = (unsigned int) *(UINT16 *) (*p_argv);
+-	      break;
+-
+-	    case FFI_TYPE_STRUCT:
+-	      memcpy (argp, *p_argv, (*p_arg)->size);
+-	      break;
+-
+-	    default:
+-	      FFI_ASSERT (0);
+-	    }
+-	}
+-      else if (z == sizeof (int))
+-	{
+-	  *(unsigned int *) argp = (unsigned int) *(UINT32 *) (*p_argv);
+-	}
+-      else
+-	{
+-	  if ((*p_arg)->type == FFI_TYPE_STRUCT)
+-	    {
+-	      memcpy (argp, *p_argv, z);
+-	    }
+-	  else
+-	    {
+-	      /* Double or long long 64bit.  */
+-	      memcpy (argp, *p_argv, z);
+-	    }
+-	}
+-      p_argv++;
+-      argp += z;
+-    }
+-
+-  return;
+-}
+-
+ /* Perform machine dependent cif processing.  */
+ ffi_status
+ ffi_prep_cif_machdep (ffi_cif * cif)
+@@ -157,85 +97,250 @@ ffi_prep_cif_machdep (ffi_cif * cif)
+   return FFI_OK;
+ }
+ 
+-extern void ffi_call_ARCompact (void (*)(char *, extended_cif *),
+-				extended_cif *, unsigned, unsigned,
+-				unsigned *, void (*fn) (void));
+-
+-void
+-ffi_call (ffi_cif * cif, void (*fn) (void), void *rvalue, void **avalue)
+-{
+-  extended_cif ecif;
+-
+-  ecif.cif = cif;
+-  ecif.avalue = avalue;
++/* allocates a single register, float register, or XLEN-sized stack slot to a datum */
++static void marshal_atom(call_builder *cb, int type, void *data) {
++  size_t value = 0;
++  switch (type) {
++    case FFI_TYPE_UINT8: value = *(uint8_t *)data; break;
++    case FFI_TYPE_SINT8: value = *(int8_t *)data; break;
++    case FFI_TYPE_UINT16: value = *(uint16_t *)data; break;
++    case FFI_TYPE_SINT16: value = *(int16_t *)data; break;
++    /* 32-bit quantities are always sign-extended in the ABI */
++    case FFI_TYPE_UINT32: value = *(int32_t *)data; break;
++    case FFI_TYPE_SINT32: value = *(int32_t *)data; break;
++#if defined(__ARC64_ARCH64__)
++    case FFI_TYPE_UINT64: value = *(uint64_t *)data; break;
++    case FFI_TYPE_SINT64: value = *(int64_t *)data; break;
++#endif
++    case FFI_TYPE_POINTER: value = *(size_t *)data; break;
++    default: FFI_ASSERT(0); break;
++  }
++
++  if (cb->used_integer == NARGREG) {
++    *cb->used_stack++ = value;
++  } else {
++    cb->aregs->r[cb->used_integer++] = value;
++  }
++}
+ 
+-  /* If the return value is a struct and we don't have
+-     a return value address then we need to make one.  */
+-  if ((rvalue == NULL) && (cif->rtype->type == FFI_TYPE_STRUCT))
+-    {
+-      ecif.rvalue = alloca (cif->rtype->size);
++/* adds an argument to a call, or a not by reference return value */
++static void marshal(call_builder *cb, ffi_type *type, int var, void *data) {
++  size_t realign[2];
++
++#if (defined(__ARC64_ARCH64__) || defined(__ARC64_ARCH32__))
++  if (type->size > 2 * __SIZEOF_POINTER__) {
++    if (var) {
++      marshal_atom(cb, FFI_TYPE_POINTER, &data);
++    } else {
++      /* copy to stack and pass by reference */
++      data = memcpy (cb->struct_stack, data, type->size);
++      cb->struct_stack = (size_t *) FFI_ALIGN ((char *) cb->struct_stack + type->size, __SIZEOF_POINTER__);
++      marshal_atom(cb, FFI_TYPE_POINTER, &data);
+     }
+-  else
+-    ecif.rvalue = rvalue;
++  }
++#else
++  if (type->type == FFI_TYPE_STRUCT) {
++    if (var) {
++      if (type->size > 0)
++        marshal_atom(cb, FFI_TYPE_POINTER, data);
++    } else {
++      int i;
++      
++      for (i = 0; i < type->size; i += sizeof(size_t)) {
++        marshal_atom(cb, FFI_TYPE_POINTER, data);
++        data += sizeof(size_t);
++      }
++    }
++  }
++#endif
++  else if (IS_INT(type->type) || type->type == FFI_TYPE_POINTER) {
++    marshal_atom(cb, type->type, data);
++  } else {
++      memcpy(realign, data, type->size);
++      if (type->size > 0)
++        marshal_atom(cb, FFI_TYPE_POINTER, realign);
++      if (type->size > __SIZEOF_POINTER__)
++        marshal_atom(cb, FFI_TYPE_POINTER, realign + 1);
++  }
++}
+ 
+-  switch (cif->abi)
+-    {
+-    case FFI_ARCOMPACT:
+-      ffi_call_ARCompact (ffi_prep_args, &ecif, cif->bytes,
+-			  cif->flags, ecif.rvalue, fn);
+-      break;
++static void unmarshal_atom(call_builder *cb, int type, void *data) {
++  size_t value;
++
++  if (cb->used_integer == NARGREG) {
++    value = *cb->used_stack++;
++  } else {
++    value = cb->aregs->r[cb->used_integer++];
++  }
++
++  switch (type) {
++    case FFI_TYPE_UINT8: *(uint8_t *)data = value; break;
++    case FFI_TYPE_SINT8: *(uint8_t *)data = value; break;
++    case FFI_TYPE_UINT16: *(uint16_t *)data = value; break;
++    case FFI_TYPE_SINT16: *(uint16_t *)data = value; break;
++    case FFI_TYPE_UINT32: *(uint32_t *)data = value; break;
++    case FFI_TYPE_SINT32: *(uint32_t *)data = value; break;
++#if defined(__ARC64_ARCH64__)
++    case FFI_TYPE_UINT64: *(uint64_t *)data = value; break;
++    case FFI_TYPE_SINT64: *(uint64_t *)data = value; break;
++#endif
++    case FFI_TYPE_POINTER: *(size_t *)data = value; break;
++    default: FFI_ASSERT(0); break;
++  }
++}
+ 
+-    default:
+-      FFI_ASSERT (0);
+-      break;
++/* for arguments passed by reference returns the pointer, otherwise the arg is copied (up to MAXCOPYARG bytes) */
++static void *unmarshal(call_builder *cb, ffi_type *type, int var, void *data) {
++  size_t realign[2];
++  void *pointer;
++
++#if defined(__ARC64_ARCH64__)
++  if (type->size > 2 * __SIZEOF_POINTER__) {
++        /* pass by reference */
++        unmarshal_atom(cb, FFI_TYPE_POINTER, (char*)&pointer);
++        return pointer;
+     }
++#elif defined(__ARC64_ARCH32__)
++  if (type->type == FFI_TYPE_STRUCT) {
++    if (type->size > 2 * __SIZEOF_POINTER__) {
++      unmarshal_atom(cb, FFI_TYPE_POINTER, &realign[0]);
++      memcpy(data, (const void*)realign[0], type->size);
++      return data;
++    } else {
++      int i;
++      void *pdata = data;
++
++      for (i = 0; i < type->size; i += sizeof(size_t)) {
++        unmarshal_atom(cb, FFI_TYPE_POINTER, pdata);
++        pdata += sizeof(size_t);
++      }
++      return data;
++    }
++  }
++#else
++  if (type->type == FFI_TYPE_STRUCT) {
++
++      if (var) {
++        int i;
++        void *pdata = data;
++
++        for (i = 0; i < type->size; i += sizeof(size_t)) {
++          unmarshal_atom(cb, FFI_TYPE_POINTER, pdata);
++          pdata += sizeof(size_t);
++        }
++        return data;
++      } else {
++        if (type->size > 0)
++          unmarshal_atom(cb, FFI_TYPE_POINTER, &realign[0]);
++        memcpy(data, (const void*)realign[0], type->size);
++        return data;
++      }
++  }
++#endif
++  else if (IS_INT(type->type) || type->type == FFI_TYPE_POINTER) {
++    unmarshal_atom(cb, type->type, data);
++    return data;
++  } else {
++      if (type->size > 0)
++        unmarshal_atom(cb, FFI_TYPE_POINTER, realign);
++      if (type->size > __SIZEOF_POINTER__)
++        unmarshal_atom(cb, FFI_TYPE_POINTER, realign + 1);
++      memcpy(data, realign, type->size);
++      return data;
++  }
+ }
+ 
+-int
+-ffi_closure_inner_ARCompact (ffi_closure * closure, void *rvalue,
+-			     ffi_arg * args)
++static int passed_by_ref(ffi_type *type, int var) {
++  if (type->type == FFI_TYPE_STRUCT)
++	  return 1;
++  
++  return type->size > 2 * __SIZEOF_POINTER__;
++}
++
++/* Low level routine for calling functions */
++extern void ffi_call_asm (void *stack, struct call_context *regs,
++			  void (*fn) (void), void *closure) FFI_HIDDEN;
++
++static void
++ffi_call_int (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue,
++	      void *closure)
+ {
+-  void **arg_area, **p_argv;
+-  ffi_cif *cif = closure->cif;
+-  char *argp = (char *) args;
+-  ffi_type **p_argt;
+-  int i;
++  int return_by_ref = passed_by_ref(cif->rtype, 0);
+ 
+-  arg_area = (void **) alloca (cif->nargs * sizeof (void *));
++  /* Allocate space for stack arg parameters.  */
++  size_t arg_bytes = FFI_ALIGN(2 * sizeof(size_t) * cif->nargs, STKALIGN);
++  /* Allocate space for copies of big structures.  */
++  size_t struct_bytes = FFI_ALIGN(cif->bytes, STKALIGN);
++  // size_t rval_bytes = 0;
++  // if (rvalue == NULL && cif->rtype->size > 2*__SIZEOF_POINTER__)
++  //   rval_bytes = FFI_ALIGN(cif->rtype->size, STKALIGN);
++  size_t alloc_size = arg_bytes + /*rval_bytes +*/ struct_bytes + sizeof(call_context);
++  size_t alloc_base = (size_t)alloca(alloc_size);
+ 
+-  /* handle hidden argument */
+-  if (cif->flags == FFI_TYPE_STRUCT)
+-    {
+-      rvalue = *(void **) argp;
+-      argp += 4;
+-    }
++  // if (rval_bytes)
++  //   rvalue = (void*)(alloc_base + arg_bytes);
+ 
+-  p_argv = arg_area;
++  call_builder cb;
++  cb.used_integer = 0;
++  cb.aregs = (call_context*)(alloc_base + arg_bytes /*+ rval_bytes*/ + struct_bytes);
++  cb.used_stack = (void*)alloc_base;
++  cb.struct_stack = (void *)(alloc_base + arg_bytes /*+ rval_bytes*/);
+ 
+-  for (i = 0, p_argt = cif->arg_types; i < cif->nargs;
+-       i++, p_argt++, p_argv++)
+-    {
+-      size_t z;
+-      int alignment;
++  // if (cif->rtype->type == FFI_TYPE_STRUCT)
++  //   marshal(&cb, &ffi_type_pointer, 0, &rvalue);
++
++  if (return_by_ref)
++	  marshal(&cb, &ffi_type_pointer, 0, &rvalue);
+ 
+-      /* align alignment to 4 */
+-      alignment = (((*p_argt)->alignment - 1) | 3) + 1;
++  int i;
++  for (i = 0; i < cif->nargs; i++)
++    marshal(&cb, cif->arg_types[i], 0, avalue[i]);
+ 
+-      /* Align if necessary.  */
+-      if ((alignment - 1) & (unsigned) argp)
+-	argp = (char *) FFI_ALIGN (argp, alignment);
++  ffi_call_asm ((void *) alloc_base, cb.aregs, fn, closure);
+ 
+-      z = (*p_argt)->size;
+-      *p_argv = (void *) argp;
+-      argp += z;
++  cb.used_integer = 0;
++  if (!return_by_ref && rvalue)
++    {
++	    if (IS_INT(cif->rtype->type)
++	        && cif->rtype->size < sizeof (ffi_arg))
++	    {
++        /* Integer types smaller than ffi_arg need to be extended.  */
++	    switch (cif->rtype->type) {
++	      case FFI_TYPE_SINT8:
++	      case FFI_TYPE_SINT16:
++	      case FFI_TYPE_SINT32:
++		      unmarshal_atom (&cb, (sizeof (ffi_arg) > 4
++                          ? FFI_TYPE_SINT64 : FFI_TYPE_SINT32),
++				                  rvalue);
++		      break;
++	      case FFI_TYPE_UINT8:
++	      case FFI_TYPE_UINT16:
++	      case FFI_TYPE_UINT32:
++		      unmarshal_atom (&cb, (sizeof (ffi_arg) > 4
++				                  ? FFI_TYPE_UINT64 : FFI_TYPE_UINT32),
++				                  rvalue);
++		      break;
++	      }
++	    }
++	    else
++	      unmarshal(&cb, cif->rtype, 0, rvalue);
+     }
++}
+ 
+-  (closure->fun) (cif, rvalue, arg_area, closure->user_data);
++void
++ffi_call (ffi_cif *cif, void (*fn) (void), void *rvalue, void **avalue)
++{
++  ffi_call_int(cif, fn, rvalue, avalue, NULL);
++}
+ 
+-  return cif->flags;
++void
++ffi_call_go (ffi_cif *cif, void (*fn) (void), void *rvalue,
++	     void **avalue, void *closure)
++{
++  ffi_call_int(cif, fn, rvalue, avalue, closure);
+ }
+ 
+-extern void ffi_closure_ARCompact (void);
++extern void ffi_closure_asm(void) FFI_HIDDEN;
+ 
+ ffi_status
+ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
+@@ -243,15 +348,28 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
+ 		      void *user_data, void *codeloc)
+ {
+   uint32_t *tramp = (uint32_t *) & (closure->tramp[0]);
++  size_t address_ffi_closure = (size_t) ffi_closure_asm;
+ 
+   switch (cif->abi)
+     {
++#if defined(__ARC64_ARCH64__)
++    case FFI_ARC64:
++      FFI_ASSERT (tramp == codeloc);
++      tramp[0] = CODE_ENDIAN (0x580a1fc0);	/* movl r8, pcl  */
++      tramp[1] = CODE_ENDIAN (0x5c0b1f80);	/* movhl r12, limm */
++      tramp[2] = CODE_ENDIAN ((uint32_t)(address_ffi_closure >> 32));
++      tramp[3] = CODE_ENDIAN (0x5c051f8c);	/* orl r12, r12, limm */
++      tramp[4] = CODE_ENDIAN ((uint32_t)(address_ffi_closure & 0xffffffff));
++      tramp[5] = CODE_ENDIAN (0x20200300);	/* j [r12] */
++      break;
++#else
+     case FFI_ARCOMPACT:
+       FFI_ASSERT (tramp == codeloc);
+       tramp[0] = CODE_ENDIAN (0x200a1fc0);	/* mov r8, pcl  */
+       tramp[1] = CODE_ENDIAN (0x20200f80);	/* j [long imm] */
+-      tramp[2] = CODE_ENDIAN (ffi_closure_ARCompact);
++      tramp[2] = CODE_ENDIAN (ffi_closure_asm);
+       break;
++#endif
+ 
+     default:
+       return FFI_BAD_ABI;
+@@ -264,3 +382,62 @@ ffi_prep_closure_loc (ffi_closure * closure, ffi_cif * cif,
+ 
+   return FFI_OK;
+ }
++
++extern void ffi_go_closure_asm (void) FFI_HIDDEN;
++
++ffi_status
++ffi_prep_go_closure (ffi_go_closure *closure, ffi_cif *cif,
++		     void (*fun) (ffi_cif *, void *, void **, void *))
++{
++  if (cif->abi <= FFI_FIRST_ABI || cif->abi >= FFI_LAST_ABI)
++    return FFI_BAD_ABI;
++
++  closure->tramp = (void *) ffi_go_closure_asm;
++  closure->cif = cif;
++  closure->fun = fun;
++
++  return FFI_OK;
++}
++
++/* Called by the assembly code with aregs pointing to saved argument registers
++   and stack pointing to the stacked arguments.  Return values passed in
++   registers will be reloaded from aregs. */
++void FFI_HIDDEN
++ffi_closure_inner (ffi_cif *cif,
++		   void (*fun) (ffi_cif *, void *, void **, void *),
++		   void *user_data,
++		   size_t *stack, call_context *aregs)
++{
++    void **avalue = alloca(cif->nargs * sizeof(void*));
++    /* storage for arguments which will be copied by unmarshal().  We could
++       theoretically avoid the copies in many cases and use at most 128 bytes
++       of memory, but allocating disjoint storage for each argument is
++       simpler. */
++    char *astorage = alloca(cif->bytes);
++    char *ptr = astorage;
++    void *rvalue;
++    call_builder cb;
++    int i;
++
++    cb.aregs = aregs;
++    cb.used_integer = 0;
++    cb.used_stack = stack;
++    
++    /* handle hidden argument */
++    if (cif->flags == FFI_TYPE_STRUCT)
++      unmarshal(&cb, &ffi_type_pointer, 0, &rvalue);
++    else
++      rvalue = alloca(cif->rtype->size);
++
++    for (i = 0; i < cif->nargs; i++) {
++      avalue[i] = unmarshal(&cb, cif->arg_types[i], 1, ptr);
++      ptr += cif->arg_types[i]->size;
++    }
++
++    fun (cif, rvalue, avalue, user_data);
++
++    if (cif->rtype->type != FFI_TYPE_VOID) {
++        cb.used_integer = 0;
++        marshal(&cb, cif->rtype, 1, rvalue);
++    }
++}
+diff --git a/src/arc/ffitarget.h b/src/arc/ffitarget.h
+index bf8311b..5b36902 100644
+--- a/src/arc/ffitarget.h
++++ b/src/arc/ffitarget.h
+@@ -40,14 +40,28 @@ typedef signed long ffi_sarg;
+ typedef enum ffi_abi
+ {
+   FFI_FIRST_ABI = 0,
++#if __SIZEOF_POINTER__ == 8
++  FFI_ARC64,
++#else
+   FFI_ARCOMPACT,
++#endif
+   FFI_LAST_ABI,
++#if __SIZEOF_POINTER__ == 8
++  FFI_DEFAULT_ABI = FFI_ARC64
++#else
+   FFI_DEFAULT_ABI = FFI_ARCOMPACT
++#endif
+ } ffi_abi;
+ #endif
+ 
+ #define FFI_CLOSURES 		1
++#define FFI_GO_CLOSURES 1
++#if __SIZEOF_POINTER__ == 8
++#define FFI_TRAMPOLINE_SIZE	24
++#else
+ #define FFI_TRAMPOLINE_SIZE	12
++#endif
++
+ #define FFI_NATIVE_RAW_API 	0
+ 
+ #endif
+-- 
+2.34.1
+
Signature · 6 lines
2.31.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Tested-by on the v1 series
#8 lore raw
In reply to Alexey Brodkin via buildroot

Hi Alexey, All,
Alexey Brodkin via buildroot wrote,

Quoted 20 lines

It's been quite some time since introduction to the market of new Synopsys ARCv3 ISA processors, which are meant to build on top of success of their predecessors in ARCv2 family.

ARCv3 ISA is meant to improve efficiency of high-performance embedded microprocessors and thus by definition is not binary compatible with previous generation of ARC cores such as ARCompact (ARC600 and ARC700 processors) and ARCv2 (ARC EM and ARC HS processors).

Moreover, finally in ARCv3 line there's a 64-bit processor family called ARC HS6x meant to cover cases when 32-bit address space is not enough.

Since ARCv3 ISA in not binary compatible with older ARC cores, we have to switch to newer tools, which in fact are already available as a part of ARC GNU toolchain v2023.09, see [1] & integration of them into Buildroot [2].

Even though that update is long overdue (for too long we kept all that in our GitHub repo [3]) it's better late than never.

Quoted 6 lines

I'd like to say thank you for all the folks who used to work on Linux bring-up on ARCv3 processors, most of whom did contribute to these changes I'm sending out today, some even no longer work with us, but still it's another amazing example of close and efficient collaboration of a group of truly highly motivated professionals. And it is my pleasure to work with such talented and bright people!

You can add a

Thanks for working on this. I think I can mark my patches as superseded. At least my work on this kicked you out of the silence ;=)

best regards
Waldemar
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#9 lore raw

Hi Thomas, Yann,

Quoted 30 lines

Hi Alexey, All,
Alexey Brodkin via buildroot wrote,

Quoted 20 lines

It's been quite some time since introduction to the market of new Synopsys ARCv3 ISA processors, which are meant to build on top of success of their predecessors in ARCv2 family.

ARCv3 ISA is meant to improve efficiency of high-performance embedded microprocessors and thus by definition is not binary compatible with previous generation of ARC cores such as ARCompact (ARC600 and ARC700 processors) and ARCv2 (ARC EM and ARC HS processors).

Moreover, finally in ARCv3 line there's a 64-bit processor family called ARC HS6x meant to cover cases when 32-bit address space is not enough.

Since ARCv3 ISA in not binary compatible with older ARC cores, we have to switch to newer tools, which in fact are already available as a part of ARC GNU toolchain v2023.09, see [1] & integration of them into Buildroot [2].

Even though that update is long overdue (for too long we kept all that in our GitHub repo [3]) it's better late than never.

Quoted 6 lines

I'd like to say thank you for all the folks who used to work on Linux bring-up on ARCv3 processors, most of whom did contribute to these changes I'm sending out today, some even no longer work with us, but still it's another amazing example of close and efficient collaboration of a group of truly highly motivated professionals. And it is my pleasure to work with such talented and bright people!

Quoted 6 lines

You can add a

Thanks for working on this. I think I can mark my patches as superseded. At least my work on this kicked you out of the silence ;=)

It's been some time since the series is sitting in the mailing list and the only response was from Waldemar (see above).

Any chance to get it merged if there're no commments or objections?

-Alexey

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot