Skip to content

Commit

Permalink
ARCMWDT: Add compiler support for nSIM RMX platform
Browse files Browse the repository at this point in the history
Add MetaWare compiller support for nSIM RMX platform

Signed-off-by: Nikolay Agishev <[email protected]>
  • Loading branch information
Nikolay Agishev authored and nashif committed Jun 14, 2024
1 parent 85ae583 commit efedf1c
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 6 deletions.
13 changes: 9 additions & 4 deletions boards/snps/nsim/arc_v/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ either `DesignWare ARC nSIM`_ or `DesignWare ARC Free nSIM`_ is required.
Building & Running Sample Applications
======================================

Most board targets support building with GNU toolchains, however
Most board targets support building with both GNU and ARC MWDT toolchains, however
there might be exceptions from that, especially for newly added targets. You can check supported
toolchains for the board targets in the corresponding ``.yaml`` file.

Expand All @@ -54,7 +54,12 @@ The supported toolchains are listed in ``toolchain:`` array in ``.yaml`` file, w
``zephyr`` toolchain support because corresponding target CPU support hasn't been added to Zephyr
SDK yet. You can find more information about its usage here: :ref:`here <other_x_compilers>`.
* **arcmwdt** - implies proprietary ARC MWDT toolchain. You can find more information about its
usage here: :ref:`here <toolchain_designware_arc_mwdt>`. Not yet supported: work in progress.
usage here: :ref:`here <toolchain_designware_arc_mwdt>`.

.. note::
Note that even if both GNU and MWDT toolchain support is declared for the target some tests or
samples can be only built with either GNU or MWDT toolchain due to some features limited to a
particular toolchain.

Use this configuration to run basic Zephyr applications and kernel tests in
nSIM, for example, with the :zephyr:code-sample:`synchronization` sample:
Expand Down Expand Up @@ -134,7 +139,7 @@ new one it's required to maintain alignment between

* Zephyr OS configuration
* nSIM configuration
* GNU toolchain compiler options
* GNU & MWDT toolchain compiler options

.. note::
The ``.tcf`` configuration files are not supported by Zephyr directly. There are multiple
Expand Down Expand Up @@ -170,7 +175,7 @@ exceptions:
* The UART model is added
* CLINT model is added

GNU toolchain compiler options
GNU & MWDT toolchain compiler options
=====================================

The hardware-specific compiler options are set in corresponding SoC cmake file. For ``nsim_arc_v`` board
Expand Down
1 change: 1 addition & 0 deletions boards/snps/nsim/arc_v/nsim_arc_v_rmx100.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ arch: riscv
toolchain:
- zephyr
- cross-compile
- arcmwdt
testing:
ignore_tags:
- net
Expand Down
6 changes: 5 additions & 1 deletion cmake/compiler/arcmwdt/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ set_compiler_property(PROPERTY security_fortify_compile_time)
set_compiler_property(PROPERTY security_fortify_run_time)

# Required C++ flags when using mwdt
set_property(TARGET compiler-cpp PROPERTY required "-Hcplus" "-Hoff=Stackcheck_alloca")
set_property(TARGET compiler-cpp PROPERTY required "-Hcplus" )

if(CONFIG_ARC)
set_property(TARGET compiler-cpp PROPERTY required "-Hoff=Stackcheck_alloca")
endif()

# Compiler flag for turning off thread-safe initialization of local statics
set_property(TARGET compiler-cpp PROPERTY no_threadsafe_statics "-fno-threadsafe-statics")
Expand Down
12 changes: 11 additions & 1 deletion cmake/compiler/arcmwdt/target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ set(NOSTDINC ${TOOLCHAIN_HOME}/arc/inc)

# common compile options, no copyright msg, little-endian, no small data,
# no MWDT stack checking
list(APPEND TOOLCHAIN_C_FLAGS -Hnocopyr -HL -Hnosdata -Hoff=Stackcheck_alloca)
list(APPEND TOOLCHAIN_C_FLAGS -Hnocopyr -HL -Hnosdata)

if(CONFIG_ARC)
list(APPEND TOOLCHAIN_C_FLAGS -Hoff=Stackcheck_alloca)
endif()

# The MWDT compiler can replace some code with call to builtin functions.
# We can't rely on these functions presence if we don't use MWDT libc.
Expand All @@ -39,3 +43,9 @@ list(APPEND TOOLCHAIN_C_FLAGS -Hnocopyr -HL -Hnosdata -Hoff=Stackcheck_alloca)
if(NOT CONFIG_ARCMWDT_LIBC)
list(APPEND TOOLCHAIN_C_FLAGS -fno-builtin)
endif()

# The MWDT compiler requires different macro definitions for ARC and RISC-V
# architectures. __MW_ASM_RV_MACRO__ allows to select appropriate compilation branch.
if(CONFIG_RISCV)
list(APPEND TOOLCHAIN_C_FLAGS -D__MW_ASM_RV_MACRO__)
endif()
49 changes: 49 additions & 0 deletions include/zephyr/toolchain/mwdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
#define FUNC_CODE()
#define FUNC_INSTR(a)

#ifdef __MW_ASM_RV_MACRO__
.macro section_var_mwdt, section, symbol
.section \section().\symbol, "aw"
\symbol :
.endm

.macro section_func_mwdt, section, symbol
.section \section().\symbol, "ax"
FUNC_CODE()
PERFOPT_ALIGN
\symbol :
FUNC_INSTR(symbol)
.endm

.macro section_subsec_func_mwdt, section, subsection, symbol
.section \section().\subsection, "ax"
PERFOPT_ALIGN
\symbol :
.endm
#else
.macro section_var_mwdt, section, symbol
.section .\&section\&.\&symbol, "aw"
symbol :
Expand All @@ -38,12 +58,34 @@
PERFOPT_ALIGN
symbol :
.endm
#endif /* __MW_ASM_RV_MACRO__ */

#define SECTION_VAR(sect, sym) section_var_mwdt sect, sym
#define SECTION_FUNC(sect, sym) section_func_mwdt sect, sym
#define SECTION_SUBSEC_FUNC(sect, subsec, sym) \
section_subsec_func_mwdt sect, subsec, sym

#ifdef __MW_ASM_RV_MACRO__
.macro glbl_text_mwdt, symbol
.globl \symbol
.type \symbol, @function
.endm

.macro glbl_data_mwdt, symbol
.globl \symbol
.type \symbol, @object
.endm

.macro weak_data_mwdt, symbol
.weak \symbol
.type \symbol, @object
.endm

.macro weak_text_mwdt, symbol
.weak \symbol
.type \symbol, @function
.endm
#else
.macro glbl_text_mwdt, symbol
.globl symbol
.type symbol, @function
Expand All @@ -59,9 +101,16 @@
.type symbol, @object
.endm

.macro weak_text_mwdt, symbol
.weak symbol
.type symbol, @function
.endm
#endif /* __MW_ASM_RV_MACRO__ */

#define GTEXT(sym) glbl_text_mwdt sym
#define GDATA(sym) glbl_data_mwdt sym
#define WDATA(sym) weak_data_mwdt sym
#define WTEXT(sym) weak_text_mwdt sym

#else /* defined(_ASMLANGUAGE) */

Expand Down
9 changes: 9 additions & 0 deletions soc/snps/nsim/arc_v/rmx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# SPDX-License-Identifier: Apache-2.0

if(COMPILER STREQUAL arcmwdt)
# CCAC:
zephyr_compile_options_ifdef(CONFIG_SOC_SERIES_RMX
-av5rmx -Zicsr -Zifencei -Zihintpause -Zba -Zbb
-Zbs -Zca -Zcb -Zcmp -Zcmt -Za -Zm -Zicbom)

zephyr_ld_options(-Hlib=rmx100)
endif()

set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "")

0 comments on commit efedf1c

Please sign in to comment.