Skip to content

Commit 00c3a28

Browse files
authored
Use FVP models to test v8.1-M libraries with PACBTI (#506)
QEMU doesn't currently support the M-profile PACBTI extension, so we need to use FVP models to test those libraries. There are also other targets not supported by QEMU, such as v8-R, which we will need these for. These models are available free of cost (though not open source) from Arm, and the user must agree to a EULA before using them. I've added a script `fvp/get_fvps.sh' to download and extract them into the `fvp' directory. These models are currently only used for the v8.1-M libraries with PACBTI, but the script also downloads the AEMv8A and AEMv8R models for future use. If the FVPs aren't installed, then the CMakeLists.txt will skip any tests which need them. I don't think it's worth preserving the ability to run these tests with QEMU, because we still have the non-PACBTI library variants which are run with QEMU. The two models also have different memory maps and require different scatter files, so if we wanted the ability to run tests for one library on both then we'd need to add a way to build multiple linker scripts.
1 parent 7ca4213 commit 00c3a28

19 files changed

+566
-55
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ __pycache__
1111
# IDEs
1212
.vscode
1313
compile_commands.json
14+
15+
# Downloaded FVPs
16+
/fvp/download/
17+
/fvp/install/

CMakeLists.txt

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ option(
134134
the tools every time you update llvm-project."
135135
ON
136136
)
137-
137+
set(
138+
FVP_INSTALL_DIR
139+
"${CMAKE_CURRENT_SOURCE_DIR}/fvp/install" CACHE STRING
140+
"The directory in which the FVP models are installed. These are not
141+
included in this repository, but can be downloaded by the script
142+
fvp/get_fvps.sh"
143+
)
144+
set(FVP_CONFIG_DIR "${CMAKE_CURRENT_SOURCE_DIR}/fvp/config")
138145
set(LLVM_TOOLCHAIN_C_LIBRARY
139146
"picolibc" CACHE STRING
140147
"Which C library to use."
@@ -644,7 +651,7 @@ set(LLVM_DEFAULT_EXTERNAL_LIT "${LLVM_BINARY_DIR}/bin/llvm-lit")
644651

645652
add_custom_target(check-newlib) # FIXME: put things in this
646653

647-
function(get_test_executor_params target_triple qemu_machine qemu_cpu qemu_params)
654+
function(get_qemu_params target_triple qemu_machine qemu_cpu qemu_params)
648655
if(target_triple MATCHES "^aarch64")
649656
set(qemu_command "qemu-system-aarch64")
650657
else()
@@ -668,6 +675,24 @@ function(get_test_executor_params target_triple qemu_machine qemu_cpu qemu_param
668675
set(test_executor_params "${test_executor_params}" PARENT_SCOPE)
669676
endfunction()
670677

678+
function(get_fvp_params fvp_model fvp_config)
679+
set(
680+
test_executor_params
681+
--fvp-install-dir ${FVP_INSTALL_DIR}
682+
--fvp-config-dir ${FVP_CONFIG_DIR}
683+
--fvp-model ${fvp_model}
684+
)
685+
string(REPLACE " " ";" fvp_config_list ${fvp_config})
686+
foreach(cfg ${fvp_config_list})
687+
set(
688+
test_executor_params
689+
${test_executor_params}
690+
--fvp-config ${cfg}
691+
)
692+
endforeach()
693+
set(test_executor_params "${test_executor_params}" PARENT_SCOPE)
694+
endfunction()
695+
671696
function(
672697
add_picolibc
673698
directory
@@ -1328,9 +1353,12 @@ function(add_library_variant target_arch)
13281353
COMPILE_FLAGS
13291354
MULTILIB_FLAGS
13301355
PICOLIBC_BUILD_TYPE
1356+
EXECUTOR
13311357
QEMU_MACHINE
13321358
QEMU_CPU
13331359
QEMU_PARAMS
1360+
FVP_MODEL
1361+
FVP_CONFIG
13341362
BOOT_FLASH_ADDRESS
13351363
BOOT_FLASH_SIZE
13361364
FLASH_ADDRESS
@@ -1376,19 +1404,40 @@ function(add_library_variant target_arch)
13761404

13771405
set(directory "${TARGET_LIBRARIES_DIR}${library_subdir}/${parent_dir_name}/${variant}")
13781406
set(VARIANT_COMPILE_FLAGS "--target=${target_triple} ${VARIANT_COMPILE_FLAGS}")
1379-
get_test_executor_params(
1380-
"${target_triple}"
1381-
"${VARIANT_QEMU_MACHINE}"
1382-
"${VARIANT_QEMU_CPU}"
1383-
"${VARIANT_QEMU_PARAMS}"
1384-
)
1385-
set(
1386-
lit_test_executor
1387-
${CMAKE_CURRENT_SOURCE_DIR}/test-support/lit-exec-qemu.py
1388-
${test_executor_params}
1389-
)
1407+
1408+
if(VARIANT_EXECUTOR STREQUAL "fvp")
1409+
if(EXISTS "${FVP_INSTALL_DIR}")
1410+
get_fvp_params(
1411+
"${VARIANT_FVP_MODEL}"
1412+
"${VARIANT_FVP_CONFIG}"
1413+
)
1414+
set(
1415+
lit_test_executor
1416+
${CMAKE_CURRENT_SOURCE_DIR}/test-support/lit-exec-fvp.py
1417+
${test_executor_params}
1418+
)
1419+
set(have_executor TRUE)
1420+
else()
1421+
set(have_executor FALSE)
1422+
endif()
1423+
else()
1424+
get_qemu_params(
1425+
"${target_triple}"
1426+
"${VARIANT_QEMU_MACHINE}"
1427+
"${VARIANT_QEMU_CPU}"
1428+
"${VARIANT_QEMU_PARAMS}"
1429+
)
1430+
set(
1431+
lit_test_executor
1432+
${CMAKE_CURRENT_SOURCE_DIR}/test-support/lit-exec-qemu.py
1433+
${test_executor_params}
1434+
)
1435+
set(have_executor TRUE)
1436+
endif()
13901437
list(JOIN lit_test_executor " " lit_test_executor)
1391-
if(NOT PREBUILT_TARGET_LIBRARIES)
1438+
if(NOT have_executor)
1439+
message("All library tests disabled for ${variant}, due to missing executor")
1440+
elseif(NOT PREBUILT_TARGET_LIBRARIES)
13921441
add_libc(
13931442
"${directory}"
13941443
"${variant}"
@@ -1481,9 +1530,12 @@ function(add_library_variants_for_cpu target_arch)
14811530
COMPILE_FLAGS
14821531
MULTILIB_FLAGS
14831532
PICOLIBC_BUILD_TYPE
1533+
EXECUTOR
14841534
QEMU_MACHINE
14851535
QEMU_CPU
14861536
QEMU_PARAMS
1537+
FVP_MODEL
1538+
FVP_CONFIG
14871539
BOOT_FLASH_ADDRESS
14881540
BOOT_FLASH_SIZE
14891541
FLASH_ADDRESS
@@ -1513,9 +1565,12 @@ function(add_library_variants_for_cpu target_arch)
15131565
COMPILE_FLAGS "${VARIANT_COMPILE_FLAGS}"
15141566
MULTILIB_FLAGS "${VARIANT_MULTILIB_FLAGS}"
15151567
PICOLIBC_BUILD_TYPE "${VARIANT_PICOLIBC_BUILD_TYPE}"
1568+
EXECUTOR "${VARIANT_EXECUTOR}"
15161569
QEMU_MACHINE "${VARIANT_QEMU_MACHINE}"
15171570
QEMU_CPU "${VARIANT_QEMU_CPU}"
15181571
QEMU_PARAMS "${VARIANT_QEMU_PARAMS}"
1572+
FVP_MODEL "${VARIANT_FVP_MODEL}"
1573+
FVP_CONFIG "${VARIANT_FVP_CONFIG}"
15191574
BOOT_FLASH_ADDRESS "${VARIANT_BOOT_FLASH_ADDRESS}"
15201575
BOOT_FLASH_SIZE "${VARIANT_BOOT_FLASH_SIZE}"
15211576
FLASH_ADDRESS "${VARIANT_FLASH_ADDRESS}"
@@ -1898,20 +1953,17 @@ add_nonexistent_library_variant(
18981953
MULTILIB_FLAGS "--target=thumbv8.1m.main-unknown-none-eabi -march=thumbv8.1m.main+mve"
18991954
ERROR_MESSAGE "No library available for MVE with soft-float ABI. Try -mfloat-abi=hard."
19001955
)
1901-
# FIXME: qemu currently has no support for PACBTI-M, so the branch protection
1902-
# variants below can't be fully tested in runtime. Since PACBTI-M instructions
1903-
# are NOP-compatible we can use the cortex-m55 CPU for now, but these should be
1904-
# updated to use a PACBTI-M enabled CPU once this is available.
19051956
add_library_variants_for_cpu(
19061957
armv8.1m.main
19071958
SUFFIX soft_nofp_nomve_pacret_bti
19081959
COMPILE_FLAGS "-mfloat-abi=soft -march=armv8.1m.main+nomve+pacbti -mfpu=none -mbranch-protection=pac-ret+bti"
19091960
MULTILIB_FLAGS "--target=thumbv8.1m.main-unknown-none-eabi -mfpu=none -mbranch-protection=pac-ret+bti"
19101961
PICOLIBC_BUILD_TYPE "release"
1911-
QEMU_MACHINE "mps3-an547"
1912-
QEMU_CPU "cortex-m55"
1913-
BOOT_FLASH_ADDRESS 0x00000000
1914-
BOOT_FLASH_SIZE 512K
1962+
EXECUTOR fvp
1963+
FVP_MODEL corstone-310
1964+
FVP_CONFIG "cortex-m85 m-pacbti m-nofp mve-none"
1965+
BOOT_FLASH_ADDRESS 0x01000000
1966+
BOOT_FLASH_SIZE 2M
19151967
FLASH_ADDRESS 0x60000000
19161968
FLASH_SIZE 0x1000000
19171969
RAM_ADDRESS 0x61000000
@@ -1924,10 +1976,11 @@ add_library_variants_for_cpu(
19241976
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nomve+pacbti -mfpu=fp-armv8-fullfp16-sp-d16 -mbranch-protection=pac-ret+bti"
19251977
MULTILIB_FLAGS "--target=thumbv8.1m.main-unknown-none-eabihf -march=thumbv8.1m.main+fp16 -mfpu=fp-armv8-fullfp16-sp-d16 -mbranch-protection=pac-ret+bti"
19261978
PICOLIBC_BUILD_TYPE "release"
1927-
QEMU_MACHINE "mps3-an547"
1928-
QEMU_CPU "cortex-m55"
1929-
BOOT_FLASH_ADDRESS 0x00000000
1930-
BOOT_FLASH_SIZE 512K
1979+
EXECUTOR fvp
1980+
FVP_MODEL corstone-310
1981+
FVP_CONFIG "cortex-m85 m-pacbti m-fp mve-none"
1982+
BOOT_FLASH_ADDRESS 0x01000000
1983+
BOOT_FLASH_SIZE 2M
19311984
FLASH_ADDRESS 0x60000000
19321985
FLASH_SIZE 0x1000000
19331986
RAM_ADDRESS 0x61000000
@@ -1940,10 +1993,11 @@ add_library_variants_for_cpu(
19401993
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+nomve+pacbti -mfpu=fp-armv8-fullfp16-d16 -mbranch-protection=pac-ret+bti"
19411994
MULTILIB_FLAGS "--target=thumbv8.1m.main-unknown-none-eabihf -march=thumbv8.1m.main+fp16 -mfpu=fp-armv8-fullfp16-d16 -mbranch-protection=pac-ret+bti"
19421995
PICOLIBC_BUILD_TYPE "release"
1943-
QEMU_MACHINE "mps3-an547"
1944-
QEMU_CPU "cortex-m55"
1945-
BOOT_FLASH_ADDRESS 0x00000000
1946-
BOOT_FLASH_SIZE 512K
1996+
EXECUTOR fvp
1997+
FVP_MODEL corstone-310
1998+
FVP_CONFIG "cortex-m85 m-pacbti m-fp mve-none"
1999+
BOOT_FLASH_ADDRESS 0x01000000
2000+
BOOT_FLASH_SIZE 2M
19472001
FLASH_ADDRESS 0x60000000
19482002
FLASH_SIZE 0x1000000
19492003
RAM_ADDRESS 0x61000000
@@ -1956,10 +2010,11 @@ add_library_variants_for_cpu(
19562010
COMPILE_FLAGS "-mfloat-abi=hard -march=armv8.1m.main+mve+pacbti -mfpu=none -mbranch-protection=pac-ret+bti"
19572011
MULTILIB_FLAGS "--target=thumbv8.1m.main-unknown-none-eabihf -march=thumbv8.1m.main+mve -mfpu=none -mbranch-protection=pac-ret+bti"
19582012
PICOLIBC_BUILD_TYPE "release"
1959-
QEMU_MACHINE "mps3-an547"
1960-
QEMU_CPU "cortex-m55"
1961-
BOOT_FLASH_ADDRESS 0x00000000
1962-
BOOT_FLASH_SIZE 512K
2013+
EXECUTOR fvp
2014+
FVP_MODEL corstone-310
2015+
FVP_CONFIG "cortex-m85 m-pacbti m-nofp mve-int"
2016+
BOOT_FLASH_ADDRESS 0x01000000
2017+
BOOT_FLASH_SIZE 2M
19632018
FLASH_ADDRESS 0x60000000
19642019
FLASH_SIZE 0x1000000
19652020
RAM_ADDRESS 0x61000000

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ Content of this repository is licensed under Apache-2.0. See
6060
The resulting binaries are covered under their respective open source licenses,
6161
see component links above.
6262

63+
Testing for some targets uses the freely-available but not open-source Arm FVP
64+
models, which have their own licenses. These are not used by default, see
65+
[Building from source](docs/building-from-source.md) for details.
66+
6367
## Host platforms
6468

6569
LLVM Embedded Toolchain for Arm is built and tested on Ubuntu 18.04 LTS.

docs/building-from-source.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ $ brew install llvm python3 git make ninja qemu cmake
3636
$ pip install meson
3737
```
3838

39+
Some recent targets are not supported by QEMU, for these the Arm FVP models are
40+
used instead. These models are available free-of-change but are not
41+
open-source, and come with their own licenses.
42+
43+
These models can be downloaded and installed (into the source tree) with the
44+
`fvp/get_fvps.sh` script. This is currently only available for Linux. By
45+
default, `get_fvps.sh` will run the installers for packages which have them,
46+
which will prompt you to agree to their licenses. Some of the packages do not
47+
have installers, instead they place their license file into the
48+
`fvp/license_terms` directory, which you should read before continuing.
49+
50+
For non-interactive use (for example in CI systems), `get_fvps.sh` can be run
51+
with the `--non-interactive` option, which causes it to implcitly accept all of
52+
the EULAs. If you have previously downloaded and installed the FVPs outside of
53+
the source tree, you can set the `-DFVP_INSTALL_DIR=...` cmake option to set
54+
the path to them.
55+
56+
If the FVPs are not installed, tests which need them will be skipped, but QEMU
57+
tests will still be run, and all library variants will still be built.
58+
3959
## Customizing
4060

4161
To build additional library variants, edit the `CMakeLists.txt` by adding

fvp/config/cortex-m85.cfg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
2+
3+
# Disable GUI visualisation.
4+
mps3_board.visualisation.disable-visualisation=1
5+
6+
# Silence output about telnet ports.
7+
# Yes, the terminals are numbered 0, 1, 2 and 5
8+
mps3_board.telnetterminal0.quiet=1
9+
mps3_board.telnetterminal1.quiet=1
10+
mps3_board.telnetterminal2.quiet=1
11+
mps3_board.telnetterminal5.quiet=1
12+
13+
# Enable semihosting
14+
cpu0.semihosting-enable=1

fvp/config/m-fp.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
2+
3+
# Enable M-profile scalar FPU. This includes the double-precision extension, I
4+
# don't see a parameter to disable that in the Corstone-310 FVP, probably
5+
# because Cortex-M85 can't be configured with an SP-only FPU.
6+
cpu0.FPU=1

fvp/config/m-nofp.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
2+
3+
# Disable M-profile scalar FPU
4+
cpu0.FPU=0

fvp/config/m-pacbti.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
2+
3+
# Enable M-profile PAC and BTI
4+
cpu0.CFGPACBTI=1
5+
cpu0.ID_ISAR5.PACBTI=1

fvp/config/mve-fp.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
2+
3+
# Enable integer and floating-point MVE
4+
cpu0.MVE=2

fvp/config/mve-int.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# SPDX-FileCopyrightText: Copyright 2024 Arm Limited and/or its affiliates <[email protected]>
2+
3+
# Enable integer-only MVE
4+
cpu0.MVE=1

0 commit comments

Comments
 (0)