Skip to content

Commit

Permalink
Added RISC-V and fixed for Arm
Browse files Browse the repository at this point in the history
  • Loading branch information
libiot committed Jun 13, 2024
1 parent 8716e20 commit 5cb5adb
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
52 changes: 43 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Copyright (c) 2022, Arm Limited and affiliates.
# Copyright (c) 2024, Pawel Wodnicki 32bitmicro.
# Copyright (c) 2024, Pawel Wodnicki 32bitmicro.com
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -19,7 +19,7 @@

# How to use this file
#
# This file is used to build LLVM Embedded Toolchain for Arm.
# This file is used to build LLVM Embedded Toolchain.
# Recent versions of the following tools are pre-requisites:
# * A toolchain such as gcc & binutils
# * cmake
Expand Down Expand Up @@ -76,7 +76,7 @@
# If cross-building, there will be two toolchains built:
# 1. The "build" toolchain. This is used to build the libraries.
# 2. The "host" toolchain. This is the toolchain that will be packaged
# up into "LLVM Embedded Toolchain for Arm".
# up into "LLVM Embedded Toolchain".
# For "native" builds the "build" toolchain is also used as the "host"
# toolchain.
#
Expand Down Expand Up @@ -151,6 +151,7 @@ set(LLVM_DISTRIBUTION_COMPONENTS
clang
dsymutil
lld
lldb
llvm-ar
llvm-config
llvm-cov
Expand Down Expand Up @@ -178,8 +179,8 @@ set(LLVM_TOOLCHAIN_DISTRIBUTION_COMPONENTS
CACHE STRING "Components defined by this CMakeLists that should be
installed by the install-llvm-toolchain target"
)
set(LLVM_ENABLE_PROJECTS clang;lld CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD AArch64;ARM CACHE STRING "")
set(LLVM_ENABLE_PROJECTS clang;lld;lldb CACHE STRING "")
set(LLVM_TARGETS_TO_BUILD AArch64;ARM;RISCV CACHE STRING "")
set(LLVM_DEFAULT_TARGET_TRIPLE aarch64-linux-gnu CACHE STRING "")
set(LLVM_APPEND_VC_REV OFF CACHE BOOL "")
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
Expand Down Expand Up @@ -338,12 +339,12 @@ get_directory_property(LLVM_VERSION_PATCH DIRECTORY ${llvmproject_SOURCE_DIR}/ll
project(
LLVMEmbeddedToolchain
VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
DESCRIPTION "LLVM Embedded Toolchain for Arm"
DESCRIPTION "LLVM Embedded Toolchain"
HOMEPAGE_URL "https://github.com/32bitmicro/LLVM-Embedded-Toolchain"
)

# Set package name for shorter archive file name
set(SHORT_PACKAGE_NAME "LLVM-ET-Arm")
set(SHORT_PACKAGE_NAME "LLVM-ETOOL")

# Set package name and version.
if(DEFINED LLVM_TOOLCHAIN_PACKAGE_NAME)
Expand Down Expand Up @@ -514,6 +515,7 @@ if(LIBS_DEPEND_ON_TOOLS)
set(lib_tool_dependencies
clang
lld
lldb
llvm-ar
llvm-config
llvm-nm
Expand Down Expand Up @@ -567,6 +569,8 @@ add_custom_target(check-newlib) # FIXME: put things in this
function(get_test_executor_params target_triple qemu_machine qemu_cpu qemu_params)
if(target_triple MATCHES "^aarch64")
set(qemu_command "qemu-system-aarch64")
elseif(target_triple MATCHES "^riscv32")
set(qemu_command "qemu-system-riscv32")
else()
set(qemu_command "qemu-system-arm")
endif()
Expand Down Expand Up @@ -611,6 +615,9 @@ function(
if(target_triple MATCHES "^aarch64")
set(cpu_family aarch64)
set(enable_long_double_test false)
elseif(target_triple MATCHES "^riscv32")
set(cpu_family riscv32)
set(enable_long_double_test true)
else()
set(cpu_family arm)
set(enable_long_double_test true)
Expand Down Expand Up @@ -707,6 +714,8 @@ function(
)
if(target_triple MATCHES "^aarch64")
set(cpu_family aarch64)
elseif(target_triple MATCHES "^riscv32")
set(cpu_family riscv32)
else()
set(cpu_family arm)
endif()
Expand Down Expand Up @@ -870,7 +879,7 @@ function(
# Exceptions are architectures pre-armv7, which compiler-rt expects to
# see in the triple because that's where it looks to decide whether to
# use specific assembly sources.
if(NOT target_triple MATCHES "^(aarch64-none-elf|arm-none-eabi|armv[4-6])")
if(NOT target_triple MATCHES "^(aarch64-none-elf|arm-none-eabi|armv[4-6]|riscv32)")
message(FATAL_ERROR "\
Target triple name \"${target_triple}\" not compatible with compiler-rt.
Use -march to specify the architecture.")
Expand Down Expand Up @@ -1094,6 +1103,10 @@ endfunction()
function(get_compiler_rt_target_triple target_arch flags)
if(target_arch STREQUAL "aarch64")
set(target_triple "aarch64-none-elf")
elseif(target_arch MATCHES "^riscv32")
if(target_arch STREQUAL "riscv32")
set(target_triple "riscv32-none-elf")
endif()
else()
# Choose the target triple so that compiler-rt will do the
# right thing. We can't always put the exact target
Expand Down Expand Up @@ -1165,12 +1178,16 @@ function(add_library_variant target_arch)

if(target_arch STREQUAL "aarch64")
set(parent_dir_name aarch64-none-elf)
elseif(target_arch MATCHES "^riscv32")
set(parent_dir_name riscv32-none-elf)
else()
set(parent_dir_name arm-none-eabi)
endif()

get_compiler_rt_target_triple("${target_arch}" "${VARIANT_COMPILE_FLAGS}")

message("add_library_variant for ${target_arch} -> ${TARGET_LIBRARIES_DIR} : ${library_subdir} : ${parent_dir_name} : ${variant} ")

set(directory "${TARGET_LIBRARIES_DIR}${library_subdir}/${parent_dir_name}/${variant}")
set(VARIANT_COMPILE_FLAGS "--target=${target_triple} ${VARIANT_COMPILE_FLAGS}")
get_test_executor_params(
Expand Down Expand Up @@ -1306,6 +1323,24 @@ endfunction()

set(multilib_yaml_content "")

# RISC-V
add_library_variants_for_cpu(
riscv32
SUFFIX soft_nofp
COMPILE_FLAGS ""
MULTILIB_FLAGS "--target=riscv32-unknown-elf"
PICOLIBC_BUILD_TYPE "release"
QEMU_MACHINE "sifive_e"
QEMU_CPU "sifive-e31"
BOOT_FLASH_ADDRESS 0x00000000
BOOT_FLASH_SIZE 128k
FLASH_ADDRESS 0x00001000
FLASH_SIZE 0x3ff000
RAM_ADDRESS 0x20000000
RAM_SIZE 16k
STACK_SIZE 256
)

# Define which library variants to build and which flags to use.
# For most variants, the "flash" memory is placed in address range, where
# simulated boards have RAM. This is because code for some tests does not fit
Expand Down Expand Up @@ -1626,7 +1661,6 @@ add_library_variants_for_cpu(
STACK_SIZE 4K
)


configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake/multilib.yaml.in
${CMAKE_CURRENT_BINARY_DIR}/multilib-without-fpus.yaml
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ relying on the GNU Toolchain.

> *Note:* `picolibc` provides excellent
> [support GNU Toolchain](https://github.com/picolibc/picolibc/blob/main/doc/using.md),
> so projects that require using both GNU Toolchain and LLVM Embedded Toolchain for Arm
> so projects that require using both GNU Toolchain and LLVM Embedded Toolchain
> can choose either `picolibc` or `newlib`.
## Building from source
Expand Down
2 changes: 1 addition & 1 deletion cmake/VERSION.txt.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
LLVM Embedded Toolchain ${LLVMEmbeddedToolchain_VERSION}

Sources:
* LLVM Embedded Toolchain for Arm: https://github.com/32bitmicro/LLVM-Embedded-Toolchain (commit ${LLVMEmbeddedToolchain_COMMIT})
* LLVM Embedded Toolchain: https://github.com/32bitmicro/LLVM-Embedded-Toolchain (commit ${LLVMEmbeddedToolchain_COMMIT})
* LLVM: https://github.com/llvm/llvm-project.git (commit ${llvmproject_COMMIT})
* Picolibc: https://github.com/picolibc/picolibc.git (commit ${picolibc_COMMIT})
9 changes: 8 additions & 1 deletion cmake/multilib.yaml.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright (c) 2023, Arm Limited and affiliates.
# Copyright (c) 2024, Pawel Wodnicki 32bitmicro.com
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,7 +17,7 @@
#

# If you're reading this file under the name 'multilib.yaml.in' in the
# LLVM-embedded-toolchain-for-Arm source tree, then it's not valid
# LLVM-embedded-toolchain source tree, then it's not valid
# YAML in its own right: it's a template that CMakeLists.txt will
# expand into a real 'multilib.yaml' containing a list of library
# variants and the flags that will select them.
Expand Down Expand Up @@ -138,3 +139,9 @@ Mappings:
- Match: -march=thumbv8\.[1-9]m\.main(\+[^\+]+)*\+lob(\+[^\+]+)*
Flags:
- -march=thumbv8.1m.main+lob

# RISC-Variants
# riscv32
- Match: --target=riscv32\.base-unknown-none-eabi
Flags:
- --target=riscv32-unknown-none-eabi
8 changes: 4 additions & 4 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contribution Guide

*LLVM Embedded Toolchain for Arm* integrates
*LLVM Embedded Toolchain* integrates
[llvm-project](https://github.com/llvm/llvm-project)
and [picolibc](https://github.com/picolibc/picolibc).
Contributions are welcome that improve the project in areas including but not
Expand All @@ -14,7 +14,7 @@ Where an issue is encountered that originates within `llvm-project`
or `picolibc`, it is strongly preferred that the issue is reported
and addressed directly within that project.
This benefits all users of the upstream projects and makes it easier to
support *LLVM Embedded Toolchain for Arm* going forward.
support *LLVM Embedded Toolchain* going forward.

For guidance on how to contribute to the upstream projects see:
* `llvm-project` [Contributing to LLVM](https://llvm.org/docs/Contributing.html)
Expand All @@ -25,7 +25,7 @@ For guidance on how to contribute to the upstream projects see:

### Report an issue

Please create a Github issue in the *LLVM Embedded Toolchain for Arm* project
Please create a Github issue in the *LLVM Embedded Toolchain* project
[Issues](https://github.com/32bitmicro/LLVM-Embedded-Toolchain/issues)
list and label is as a `bug`.

Expand All @@ -37,7 +37,7 @@ _How to submit a change_ section below.
### Suggest a feature or bigger change

For a bigger change, please create an issue in the
*LLVM Embedded Toolchain for Arm* project
*LLVM Embedded Toolchain* project
[Issues](https://github.com/32bitmicro/LLVM-Embedded-Toolchain/issues)
list and label is as an `rfc` (Request for Comments) to initiate the discussion
first, before submitting the change itself.
Expand Down
2 changes: 1 addition & 1 deletion docs/newlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ library variants is provided.
## Using pre-built `newlib` library package

1. Install LLVM Embedded Toolchain for Arm
1. Install LLVM Embedded Toolchain
1. Download corresponding `LLVMEmbeddedToolchain-newlib-overlay` package
and extract it on top of the main toolchain folder.

Expand Down
8 changes: 4 additions & 4 deletions samples/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Sample code for the LLVM Embedded Toolchain for Arm
# Sample code for the LLVM Embedded Toolchain

This directory contains sample code which demonstrates how to use the LLVM
Embedded Toolchain for Arm.
Embedded Toolchain.

## Directory structure

Expand Down Expand Up @@ -40,13 +40,13 @@ https://www.qemu.org/download/#windows.

To debug the samples you will need to install a debugger
that supports Arm targets, for example,
[LLDB](https://lldb.llvm.org/) version matching LLVM Embedded Toolchain for Arm.
[LLDB](https://lldb.llvm.org/) version matching LLVM Embedded Toolchain.
Debugging is only supported on Linux and macOS.

## Specifying the location of the installed toolchain

The Makefiles of the code samples need the location of the installed LLVM
Embedded Toolchain for Arm.
Embedded Toolchain.

If you are using Linux or MSYS2 and running the samples directly from the
installation directory the Makefiles will determine the correct location
Expand Down

0 comments on commit 5cb5adb

Please sign in to comment.