From 5426a525ebb18a93cc04944584be1edfa663a63e Mon Sep 17 00:00:00 2001 From: "Matthias J. Kannwischer" Date: Fri, 26 Jul 2024 18:22:06 +0800 Subject: [PATCH] add native-linux platforms --- envs/common/common.mk | 74 +++++++++++++ envs/common/cross.mk | 81 +------------- envs/common/native-linux.mk | 4 + envs/cross-v9a/Makefile | 3 - envs/native-linux-v84a/Makefile | 3 + .../inc/hal_env.h | 0 .../src/hal.c | 0 envs/native-linux-v8a/Makefile | 3 + .../inc/hal_env.h | 2 +- .../src/hal.c | 0 envs/native_linux/.gitignore | 2 - envs/native_linux/Makefile | 102 ------------------ envs/native_linux/inc/test_inc | 1 - envs/native_linux/src/test_common | 1 - tests/helloworld/helloworld.mk | 3 +- tests/keccak-neon/keccak-neon.mk | 3 +- tests/ntt-dilithium/ntt-dilithium.mk | 3 + tests/ntt-kyber/ntt-kyber.mk | 2 + tests/ntt-neon/ntt-neon.mk | 3 +- tests/ntt-sve2/ntt-sve2.mk | 3 +- tests/profiling/profiling.mk | 3 +- tests/x25519/x25519.mk | 3 +- 22 files changed, 106 insertions(+), 193 deletions(-) create mode 100644 envs/common/common.mk create mode 100644 envs/common/native-linux.mk delete mode 100644 envs/cross-v9a/Makefile create mode 100644 envs/native-linux-v84a/Makefile rename envs/{cross-v9a => native-linux-v84a}/inc/hal_env.h (100%) rename envs/{cross-v9a => native-linux-v84a}/src/hal.c (100%) create mode 100644 envs/native-linux-v8a/Makefile rename envs/{native_linux => native-linux-v8a}/inc/hal_env.h (82%) rename envs/{native_linux => native-linux-v8a}/src/hal.c (100%) delete mode 100644 envs/native_linux/.gitignore delete mode 100644 envs/native_linux/Makefile delete mode 120000 envs/native_linux/inc/test_inc delete mode 120000 envs/native_linux/src/test_common diff --git a/envs/common/common.mk b/envs/common/common.mk new file mode 100644 index 0000000..d786927 --- /dev/null +++ b/envs/common/common.mk @@ -0,0 +1,74 @@ +LD=$(CC) + +COMMON_INC=../common/inc/ +ENV_INC=./inc/ +TEST_COMMON=../../tests/common/ +SRC_DIR=./src +BUILD_DIR=./build/$(TARGET) + + +CFLAGS += -fpic -Wall -Wextra -Werror -Wshadow -Wno-unused-parameter +CFLAGS += $(CFLAGS_EXTRA) + +CFLAGS+= -Ofast \ + -I$(COMMON_INC) \ + -I$(ENV_INC) \ + -I$(SRC_DIR) \ + -I$(TESTDIR) \ + -I$(TEST_COMMON) \ + + +LDFLAGS = -static + +CYCLES?=NO # PMU / PERF + +ifeq ($(CYCLES),PMU) + CFLAGS += -DPMU_CYCLES +endif + +ifeq ($(CYCLES),PERF) + CFLAGS += -DPERF_CYCLES +endif + +ifeq ($(CYCLES),NO) + CFLAGS += -DNO_CYCLES +endif + +all: $(TARGET) + +HAL_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*/*.c) +OBJECTS_HAL = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(HAL_SOURCES))) +TEST_COMMON_SOURCES = $(wildcard $(TEST_COMMON)/*.c) +OBJECTS_TEST_COMMON = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(TEST_COMMON_SOURCES))) +OBJECTS_SOURCES=$(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(SOURCES))) +OBJECTS_C = $(OBJECTS_SOURCES) $(OBJECTS_HAL) $(OBJECTS_TEST_COMMON) +OBJECTS_ASM = $(patsubst %.s, $(BUILD_DIR)/%.s.o, $(abspath $(ASMS))) + +OBJECTS = $(OBJECTS_C) $(OBJECTS_ASM) + +# Compilation +$(OBJECTS_C): $(BUILD_DIR)/%.o: % + mkdir -p $(@D) + $(CC) $(CFLAGS) -c -o $@ $< + +$(OBJECTS_ASM): $(BUILD_DIR)/%.o: % + mkdir -p $(@D) + $(CC) -x assembler-with-cpp $(CFLAGS) -c -o $@ $< + +# Linking +$(TARGET): $(OBJECTS) + mkdir -p $(@D) + $(LD) $(LDFLAGS) $(OBJECTS) -o $(TARGET) + +.PHONY: build +build: $(TARGET) + +# Running +.PHONY: run +run: $(TARGET) + $(EMU) ./$(TARGET) + +.PHONY: clean +clean: + rm -rf $(BUILD_DIR) + rm -f *.elf diff --git a/envs/common/cross.mk b/envs/common/cross.mk index e4882f0..104c3c8 100644 --- a/envs/common/cross.mk +++ b/envs/common/cross.mk @@ -1,77 +1,4 @@ -QEMU=qemu-aarch64 -CC=aarch64-linux-gnu-gcc -LD=$(CC) - - -COMMON_INC=../common/inc/ -ENV_INC=./inc/ -TEST_COMMON=../../tests/common/ -SRC_DIR=./src -BUILD_DIR=./build/$(TARGET) - - -CFLAGS += -fpic -Wall -Wextra -Werror -Wshadow -Wno-unused-parameter -CFLAGS += $(CFLAGS_EXTRA) - -CFLAGS+= -Ofast \ - -I$(COMMON_INC) \ - -I$(ENV_INC) \ - -I$(SRC_DIR) \ - -I$(TESTDIR) \ - -I$(TEST_COMMON) \ - - -LDFLAGS = -static - -CYCLES?=NO # PMU / PERF - -ifeq ($(CYCLES),PMU) - CFLAGS += -DPMU_CYCLES -endif - -ifeq ($(CYCLES),PERF) - CFLAGS += -DPERF_CYCLES -endif - -ifeq ($(CYCLES),NO) - CFLAGS += -DNO_CYCLES -endif - -all: $(TARGET) - -HAL_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*/*.c) -OBJECTS_HAL = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(HAL_SOURCES))) -TEST_COMMON_SOURCES = $(wildcard $(TEST_COMMON)/*.c) -OBJECTS_TEST_COMMON = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(TEST_COMMON_SOURCES))) -OBJECTS_SOURCES=$(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(SOURCES))) -OBJECTS_C = $(OBJECTS_SOURCES) $(OBJECTS_HAL) $(OBJECTS_TEST_COMMON) -OBJECTS_ASM = $(patsubst %.s, $(BUILD_DIR)/%.s.o, $(abspath $(ASMS))) - -OBJECTS = $(OBJECTS_C) $(OBJECTS_ASM) - -# Compilation -$(OBJECTS_C): $(BUILD_DIR)/%.o: % - mkdir -p $(@D) - $(CC) $(CFLAGS) -c -o $@ $< - -$(OBJECTS_ASM): $(BUILD_DIR)/%.o: % - mkdir -p $(@D) - $(CC) -x assembler-with-cpp $(CFLAGS) -c -o $@ $< - -# Linking -$(TARGET): $(OBJECTS) - mkdir -p $(@D) - $(LD) $(LDFLAGS) $(OBJECTS) -o $(TARGET) - -.PHONY: build -build: $(TARGET) - -# Running -.PHONY: run -run: $(TARGET) - $(QEMU) ./$(TARGET) - -.PHONY: clean -clean: - rm -rf $(BUILD_DIR) - rm -f *.elf +# emulation (qemu or empty for native) +EMU = qemu-aarch64 +CC = aarch64-linux-gnu-gcc +include ../common/common.mk \ No newline at end of file diff --git a/envs/common/native-linux.mk b/envs/common/native-linux.mk new file mode 100644 index 0000000..f70642c --- /dev/null +++ b/envs/common/native-linux.mk @@ -0,0 +1,4 @@ +# emulation (qemu or empty for native) +EMU = +CC = gcc +include ../common/common.mk \ No newline at end of file diff --git a/envs/cross-v9a/Makefile b/envs/cross-v9a/Makefile deleted file mode 100644 index 43448b5..0000000 --- a/envs/cross-v9a/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -CFLAGS += -march=armv9-a - -include ../common/cross.mk \ No newline at end of file diff --git a/envs/native-linux-v84a/Makefile b/envs/native-linux-v84a/Makefile new file mode 100644 index 0000000..d5b8475 --- /dev/null +++ b/envs/native-linux-v84a/Makefile @@ -0,0 +1,3 @@ +CFLAGS += -march=armv8.4-a+crypto+sha3+sve2 + +include ../common/native-linux.mk \ No newline at end of file diff --git a/envs/cross-v9a/inc/hal_env.h b/envs/native-linux-v84a/inc/hal_env.h similarity index 100% rename from envs/cross-v9a/inc/hal_env.h rename to envs/native-linux-v84a/inc/hal_env.h diff --git a/envs/cross-v9a/src/hal.c b/envs/native-linux-v84a/src/hal.c similarity index 100% rename from envs/cross-v9a/src/hal.c rename to envs/native-linux-v84a/src/hal.c diff --git a/envs/native-linux-v8a/Makefile b/envs/native-linux-v8a/Makefile new file mode 100644 index 0000000..3b1bbc8 --- /dev/null +++ b/envs/native-linux-v8a/Makefile @@ -0,0 +1,3 @@ +CFLAGS += -march=armv8-a + +include ../common/native-linux.mk \ No newline at end of file diff --git a/envs/native_linux/inc/hal_env.h b/envs/native-linux-v8a/inc/hal_env.h similarity index 82% rename from envs/native_linux/inc/hal_env.h rename to envs/native-linux-v8a/inc/hal_env.h index 7440a3f..e8dd570 100644 --- a/envs/native_linux/inc/hal_env.h +++ b/envs/native-linux-v8a/inc/hal_env.h @@ -6,4 +6,4 @@ #define ASM_LOAD(dst,symbol) \ adrp dst, symbol ; add dst, dst, :lo12:symbol; -#endif /* QEMU_V8A_HAL_ENV_H */ +#endif diff --git a/envs/native_linux/src/hal.c b/envs/native-linux-v8a/src/hal.c similarity index 100% rename from envs/native_linux/src/hal.c rename to envs/native-linux-v8a/src/hal.c diff --git a/envs/native_linux/.gitignore b/envs/native_linux/.gitignore deleted file mode 100644 index b882758..0000000 --- a/envs/native_linux/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -test_loaded_* -test \ No newline at end of file diff --git a/envs/native_linux/Makefile b/envs/native_linux/Makefile deleted file mode 100644 index 0c76694..0000000 --- a/envs/native_linux/Makefile +++ /dev/null @@ -1,102 +0,0 @@ -# Native AArch64 Linux test environment -# -# Copyright (c) 2021 Arm Limited (or its affiliates). All rights reserved. -# Use, modification and redistribution of this file is subject to your possession of a -# valid End User License Agreement for the Arm Product of which these examples are part of -# and your compliance with all applicable terms and conditions of such licence agreement. - -################################################################################ -### ### -### USER CONFIGURATION ### -### ADAPT THIS ### -### ### -################################################################################ - -# -# See README.md for setup instructions -# - -CC=gcc -LD=$(CC) - -PLATFORM ?= v84a - -CFLAGS = -fpic -Wall -Wextra -Werror -Wshadow -Wno-unused-parameter -Wno-incompatible-pointer-types - -################################################################################ -### ### -### END OF USER CONFIGURATION ### -### ### -################################################################################ - -# Final image -TARGET=test - -INC_DIR=./inc -INC_DIR_TEST=$(INC_DIR)/test_inc -I$(SRC_DIR)/test_src/manual -I$(SRC_DIR)/test_src/auto -BUILD_DIR=./build -SRC_DIR=./src - -CFLAGS+= -Ofast -I$(INC_DIR) \ - -I$(INC_DIR_TEST) - -CYCLES?=NO # PMU / PERF - -ifeq ($(CYCLES),PMU) - CFLAGS += -DPMU_CYCLES -endif - -ifeq ($(CYCLES),PERF) - CFLAGS += -DPERF_CYCLES -endif - -ifeq ($(CYCLES),NO) - CFLAGS += -DNO_CYCLES -endif - -CFLAGS_V8A := $(CFLAGS) -march=armv8-a -ifeq ($(PLATFORM),v84a) - CFLAGS += -march=armv8.4-a+crypto+sha3 -else - CFLAGS += -march=armv8-a -endif - -C_SRC_FILES_PRE=$(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*/*.c) $(wildcard $(SRC_DIR)/*/*/*.c) $(wildcard $(SRC_DIR)/*/*/*/*.c) -C_SRC_FILES=$(patsubst $(SRC_DIR)/%.c, %.c, $(C_SRC_FILES_PRE)) - -ASM_SRC_FILES_PRE=$(wildcard $(SRC_DIR)/*/*.s) $(wildcard $(SRC_DIR)/*.s) $(wildcard $(SRC_DIR)/*/*/*.s) $(wildcard $(SRC_DIR)/*/*/*/*.s) -ASM_SRC_FILES=$(patsubst $(SRC_DIR)/%.s, %.s, $(ASM_SRC_FILES_PRE)) - -HEADER_FILES_PRE=$(wildcard $(SRC_DIR)/*.h) $(wildcard $(SRC_DIR)/*/*.h) $(wildcard $(SRC_DIR)/*/*/*.h) - -ASM_OBJ_FILES=$(patsubst %.s, $(BUILD_DIR)/%.o, $(ASM_SRC_FILES)) -C_OBJ_FILES=$(patsubst %.c, $(BUILD_DIR)/%.o, $(C_SRC_FILES)) -OBJ_FILES=$(ASM_OBJ_FILES) $(C_OBJ_FILES) - -.phony: all clean debug run - -all: $(TARGET) - -# Compilation -$(C_OBJ_FILES): $(BUILD_DIR)/%.o: $(SRC_DIR)/%.c $(HEADER_FILES_PRE) - mkdir -p $(@D) - $(CC) $(CFLAGS) -c -o $@ $< -$(BUILD_DIR)/test_src/manual/third_party/keccakx2_cothan.o: $(SRC_DIR)/test_src/manual/third_party/keccakx2_cothan.c $(HEADER_FILES_PRE) - mkdir -p $(@D) - $(CC) $(CFLAGS_V8A) -c -o $@ $< -$(ASM_OBJ_FILES): $(BUILD_DIR)/%.o: $(SRC_DIR)/%.s $(HEADER_FILES_PRE) - mkdir -p $(@D) - $(CC) -x assembler-with-cpp $(CFLAGS) -c -o $@ $< - -# Linking -$(TARGET): $(OBJS_DIR) $(OBJ_FILES) - mkdir -p $(@D) - $(LD) $(OBJ_FILES) -o $(TARGET) - -# Running -run: $(TARGET) - ./$(TARGET) - -clean: - rm -rf $(OBJ_FILES) - rm -rf $(TARGET) diff --git a/envs/native_linux/inc/test_inc b/envs/native_linux/inc/test_inc deleted file mode 120000 index 31da609..0000000 --- a/envs/native_linux/inc/test_inc +++ /dev/null @@ -1 +0,0 @@ -../../../tests/inc \ No newline at end of file diff --git a/envs/native_linux/src/test_common b/envs/native_linux/src/test_common deleted file mode 120000 index 7c5f7b1..0000000 --- a/envs/native_linux/src/test_common +++ /dev/null @@ -1 +0,0 @@ -../../../tests/common \ No newline at end of file diff --git a/tests/helloworld/helloworld.mk b/tests/helloworld/helloworld.mk index 4b71f3f..ebee1f5 100644 --- a/tests/helloworld/helloworld.mk +++ b/tests/helloworld/helloworld.mk @@ -6,7 +6,8 @@ TESTS += helloworld # Platforms this test should run on (matching the directory name in envs/) HELLOWORLD_PLATFORMS += cross-v8a HELLOWORLD_PLATFORMS += cross-v84a -HELLOWORLD_PLATFORMS += cross-v9a +HELLOWORLD_PLATFORMS += native-linux-v8a +HELLOWORLD_PLATFORMS += native-linux-v84a # C sources required for this test HELLOWORLD_SOURCES += main.c diff --git a/tests/keccak-neon/keccak-neon.mk b/tests/keccak-neon/keccak-neon.mk index 9b6d96d..6630a6d 100644 --- a/tests/keccak-neon/keccak-neon.mk +++ b/tests/keccak-neon/keccak-neon.mk @@ -6,7 +6,8 @@ TESTS += keccak-neon # Platforms this test should run on (matching the directory name in envs/) KECCAK_NEON_PLATFORMS += cross-v8a KECCAK_NEON_PLATFORMS += cross-v84a -KECCAK_NEON_PLATFORMS += cross-v9a +KECCAK_NEON_PLATFORMS += natice-linux-v8a +KECCAK_NEON_PLATFORMS += natice-linux-v84a # C sources required for this test KECCAK_NEON_SOURCES += main.c diff --git a/tests/ntt-dilithium/ntt-dilithium.mk b/tests/ntt-dilithium/ntt-dilithium.mk index fde34f2..6fbaf46 100644 --- a/tests/ntt-dilithium/ntt-dilithium.mk +++ b/tests/ntt-dilithium/ntt-dilithium.mk @@ -6,6 +6,9 @@ TESTS += ntt-dilithium # Platforms this test should run on (matching the directory name in envs/) NTT_DILITHIUM_PLATFORMS += cross-v8a NTT_DILITHIUM_PLATFORMS += cross-v84a +NTT_DILITHIUM_PLATFORMS += native-linux-v8a +NTT_DILITHIUM_PLATFORMS += native-linux-v84a + # C sources required for this test NTT_DILITHIUM_SOURCES += main.c diff --git a/tests/ntt-kyber/ntt-kyber.mk b/tests/ntt-kyber/ntt-kyber.mk index 87251e9..453886d 100644 --- a/tests/ntt-kyber/ntt-kyber.mk +++ b/tests/ntt-kyber/ntt-kyber.mk @@ -6,6 +6,8 @@ TESTS += ntt-kyber # Platforms this test should run on (matching the directory name in envs/) NTT_KYBER_PLATFORMS += cross-v8a NTT_KYBER_PLATFORMS += cross-v84a +NTT_KYBER_PLATFORMS += native-linux-v8a +NTT_KYBER_PLATFORMS += native-linux-v84a # C sources required for this test NTT_KYBER_SOURCES += main.c diff --git a/tests/ntt-neon/ntt-neon.mk b/tests/ntt-neon/ntt-neon.mk index 4c44a94..7d55e09 100644 --- a/tests/ntt-neon/ntt-neon.mk +++ b/tests/ntt-neon/ntt-neon.mk @@ -6,7 +6,8 @@ TESTS += ntt-neon # Platforms this test should run on (matching the directory name in envs/) NTT_NEON_PLATFORMS += cross-v8a NTT_NEON_PLATFORMS += cross-v84a -NTT_NEON_PLATFORMS += cross-v9a +NTT_NEON_PLATFORMS += native-linux-v8a +NTT_NEON_PLATFORMS += native-linux-v84a # C sources required for this test NTT_NEON_SOURCES += main.c diff --git a/tests/ntt-sve2/ntt-sve2.mk b/tests/ntt-sve2/ntt-sve2.mk index 15cec9e..4ad3714 100644 --- a/tests/ntt-sve2/ntt-sve2.mk +++ b/tests/ntt-sve2/ntt-sve2.mk @@ -4,7 +4,8 @@ TESTS += ntt-sve2 # All further variables must be prefixed with the capitalized test name # Platforms this test should run on (matching the directory name in envs/) -NTT_SVE2_PLATFORMS += cross-v9a +NTT_SVE2_PLATFORMS += cross-v84a +NTT_SVE2_PLATFORMS += native-linux-v84a # C sources required for this test NTT_SVE2_SOURCES += main.c diff --git a/tests/profiling/profiling.mk b/tests/profiling/profiling.mk index 5d5196a..b1d6886 100644 --- a/tests/profiling/profiling.mk +++ b/tests/profiling/profiling.mk @@ -6,7 +6,8 @@ TESTS += profiling # Platforms this test should run on (matching the directory name in envs/) PROFILING_PLATFORMS += cross-v8a PROFILING_PLATFORMS += cross-v84a -PROFILING_PLATFORMS += cross-v9a +PROFILING_PLATFORMS += native-linux-v8a +PROFILING_PLATFORMS += native-linux-v84a # C sources required for this test PROFILING_SOURCES += main.c diff --git a/tests/x25519/x25519.mk b/tests/x25519/x25519.mk index e5902e9..2820994 100644 --- a/tests/x25519/x25519.mk +++ b/tests/x25519/x25519.mk @@ -6,7 +6,8 @@ TESTS += x25519 # Platforms this test should run on (matching the directory name in envs/) X25519_PLATFORMS += cross-v8a X25519_PLATFORMS += cross-v84a -X25519_PLATFORMS += cross-v9a +X25519_PLATFORMS += native-linux-v8a +X25519_PLATFORMS += native-linux-v84a # C sources required for this test X25519_SOURCES += main.c