Skip to content

Commit

Permalink
IAR compiler abstraction fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
JonatanAntoni committed Nov 24, 2023
1 parent d8151ca commit 0e65378
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 27 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/ubuntu-22.04/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ RUN pip install \
lit \
python-matrix-runner

RUN pushd /root && \
curl -LO http://files.iar.com/ftp/pub/box/bxarm-9.40.2.deb && \
dpkg -i bxarm-9.40.2.deb && \
rm bxarm-9.40.2.deb

ENV PATH=$PATH:/opt/iarsystems/bxarm/arm/bin
ENV IAR_TOOLCHAIN_9_40_2=/opt/iarsystems/bxarm/arm/bin
ENV IAR_LMS_SETTINGS_DIR=/home/$USERNAME/.iarlm

# Create the user
RUN groupadd --gid $USER_GID $USERNAME \
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \
Expand Down
11 changes: 4 additions & 7 deletions CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
#define __get_CONTROL() (__arm_rsr("CONTROL"))
#define __get_FAULTMASK() (__arm_rsr("FAULTMASK"))

#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
#if (defined(__ARM_FP) && (__ARM_FP >= 1))
#define __get_FPSCR() (__arm_rsr("FPSCR"))
#define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE)))
#else
Expand Down Expand Up @@ -536,8 +535,7 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
#endif


#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
#if (!defined(__ARM_FP) || (__ARM_FP == 0))
#define __get_FPSCR __cmsis_iar_get_FPSR_not_active
#define __set_FPSCR __cmsis_iar_set_FPSR_not_active
#endif
Expand Down Expand Up @@ -593,8 +591,7 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)

#endif

#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
#if (!defined(__ARM_FP) || (__ARM_FP == 0))
#undef __get_FPSCR
#undef __set_FPSCR
#define __get_FPSCR() (0)
Expand Down Expand Up @@ -865,7 +862,7 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
}
#endif

#if (__CORTEX_M >= 0x03) /* __CORTEX_M is defined in core_cm0.h, core_cm3.h and core_cm4.h. */
#if (__ARM_ARCH_ISA_THUMB >= 2)

__IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
{
Expand Down
20 changes: 11 additions & 9 deletions CMSIS/Core/Test/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,23 @@ class OptimizationAxis(Enum):


@matrix_action
def lit(config):
"""Run tests for the selected configurations using llvm's lit."""
yield run_lit(config.compiler[0], config.device[1], config.optimize[0])
def lit(config, extra_args = None):
"""Run tests for the selected configurations using llvm's lit."""
yield run_lit(config.compiler[0], config.device[1], config.optimize[0], extra_args)


def timestamp():
return datetime.now().strftime('%Y%m%d%H%M%S')

@matrix_command()
def run_lit(toolchain, device, optimize):
return ["lit", "--xunit-xml-output", f"lit-{toolchain}-{optimize}-{device}.xunit", "-D", f"toolchain={toolchain}", "-D", f"device={device}", "-D", f"optimize={optimize}", "." ]

@matrix_filter
def filter_iar(config):
return config.compiler == CompilerAxis.IAR
def run_lit(toolchain, device, optimize, extra_args = None):
if not extra_args:
extra_args = ["."]
return ["lit", "--xunit-xml-output", f"lit-{toolchain}-{optimize}-{device}.xunit", "-D", f"toolchain={toolchain}", "-D", f"device={device}", "-D", f"optimize={optimize}"]+extra_args

# @matrix_filter
# def filter_iar(config):
# return config.compiler == CompilerAxis.IAR

@matrix_filter
def filter_gcc_cm85(config):
Expand Down
77 changes: 76 additions & 1 deletion CMSIS/Core/Test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
'triple': 'thumbv7-em',
'abi': 'eabi',
'mcpu': 'cortex-m7',
'mfpu': 'fpv4-sp-d16',
'mfpu': 'fpv5-sp-d16',
'mpu': True,
'features': ['thumbv6m', 'thumbv7m', 'dsp', 'thumb-2', 'sat', 'ldrex', 'clz'],
'header': 'core_cm7.h',
Expand Down Expand Up @@ -640,6 +640,11 @@
# test_source_root: The root path where tests are located.
config.test_source_root = os.path.dirname(__file__)

# environment
preserv_env_vars = ['IAR_LMS_SETTINGS_DIR']
for var in preserv_env_vars:
if var in os.environ:
config.environment[var] = os.environ[var]

# clang_path = get_toolchain_from_env('CLANG')

Expand Down Expand Up @@ -717,6 +722,7 @@ def get_ccflags(self):
ccflags += list(sum([('-D', f'{define}={value}') for (define, value) in DEVICES[self.device]['defines'].items()], ()))
return ccflags


class Toolchain_Clang(Toolchain):
TARGET = {
'CM0': 'thumbv6m-none-unknown-eabi',
Expand Down Expand Up @@ -772,13 +778,82 @@ def get_ccflags(self):

return ccflags


class Toolchain_IAR(Toolchain):
OPTIMIZE = {
'none': '-Ol',
'balanced': '-Oh',
'speed': '-Ohs',
'size': '-Ohz'
}

CPU = {
'CM0': 'cortex-m0',
'CM0plus': 'cortex-m0+',
'CM3': 'cortex-m3',
'CM4': 'cortex-m4',
'CM4FP': 'cortex-m4.fp.sp',
'CM7': 'cortex-m7',
'CM7SP': 'cortex-m7.fp.sp',
'CM7DP': 'cortex-m7.fp.dp',
'CM23': 'cortex-m.no_se',
'CM23S': 'cortex-m',
'CM23NS': 'cortex-m',
'CM33': 'cortex-m.no_se',
'CM33S': 'cortex-m',
'CM33NS': 'cortex-m',
'CM35P': 'cortex-m.no_se',
'CM35PS': 'cortex-m',
'CM35PNS': 'cortex-m',
'CM55': 'cortex-m.no_se',
'CM55S': 'cortex-m',
'CM55NS': 'cortex-m',
'CM85': 'cortex-m.no_se',
'CM85S': 'cortex-m',
'CM85NS': 'cortex-m',
'CA5': 'cortex-a5',
'CA5neon': 'cortex-a5.neon',
'CA7': 'cortex-a7.no_neon.no_vfp',
'CA7neon': 'cortex-a7',
'CA9': 'cortex-a9.no_neon.no_vfp',
'CA9neon': 'cortex-a9'
}

FPU = {
'none': 'none',
'fpv3-d16': 'vfpv3_d16',
'fpv4-sp-d16': 'vfpv4-sp',
'fpv5-sp-d16': 'vfpv5-sp',
'fpv5-d16': 'vfpv5_d16',
'neon-vfpv3': 'vfpv3',
'neon-vfpv4': 'vfpv4'
}

def __init__(self, **args):
super().__init__('IAR', **args)

def get_cc(self):
return os.path.join(self.get_root(), 'iccarm')

def get_ccflags(self):
ccflags = [
'-e', f'--cpu={self.CPU[self.device]}', f'--fpu={self.FPU[DEVICES[self.device]["mfpu"]]}',
self.OPTIMIZE[self.optimize], '-I', '../Include', '-c', '-D', f'CORE_HEADER=\\"{DEVICES[device]["header"]}\\"']
if device.endswith('S') and not device.endswith('NS'):
ccflags += ["--cmse"]
ccflags += list(sum([('-D', f'{define}={value}') for (define, value) in DEVICES[self.device]['defines'].items()], ()))
return ccflags


tc = None
if toolchain == 'AC6':
tc = Toolchain_AC6(device=device, optimize=optimize)
elif toolchain == 'GCC':
tc = Toolchain_GCC(device=device, optimize=optimize)
elif toolchain == 'Clang':
tc = Toolchain_Clang(device=device, optimize=optimize)
elif toolchain == 'IAR':
tc = Toolchain_IAR(device=device, optimize=optimize)

prefixes = ['CHECK']
if device.endswith('NS'):
Expand Down
6 changes: 1 addition & 5 deletions CMSIS/Core/Test/noreturn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
#include "cmsis_compiler.h"

__NO_RETURN
static void func() {
while(1);
}

void noreturn() {
// CHECK-LABEL: <noreturn>:
// CHECK: b 0x0 <noreturn>
func();
while(1);
// CHECK-NOT: bx lr
}
2 changes: 1 addition & 1 deletion CMSIS/Core/Test/ror.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static volatile uint32_t b = 2u;

void ror() {
// CHECK-LABEL: <ror>:
// CHECK-THUMB: ror{{s|.w}} {{r[0-9]+}}, {{r[0-9]+}}
// CHECK-THUMB: ror{{(s)?(.w)?}} {{r[0-9]+}}, {{r[0-9]+}}
// CHECK-ARM: ror {{r[0-9]+}}, {{r[0-9]+}}, {{r[0-9]+}}
volatile uint32_t c = __ROR(a, b);
// CHECK: {{(bx lr)|(pop {.*pc})}}
Expand Down
2 changes: 1 addition & 1 deletion CMSIS/Core/Test/rrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ static volatile uint32_t a = 10u;

void rrx() {
// CHECK-LABEL: <rrx>:
// CHECK: rrx {{r[0-9]+}}, {{r[0-9]+}}
// CHECK: rrx{{(s)?}} {{r[0-9]+}}, {{r[0-9]+}}
volatile uint32_t c = __RRX(a);
// CHECK: {{(bx lr)|(pop {.*pc})}}
}
6 changes: 3 additions & 3 deletions CMSIS/CoreValidation/Project/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,9 @@ def model_exec(config):
return cmdline


@matrix_filter
def filter_iar(config):
return config.compiler == CompilerAxis.IAR
# @matrix_filter
# def filter_iar(config):
# return config.compiler == CompilerAxis.IAR


@matrix_filter
Expand Down

0 comments on commit 0e65378

Please sign in to comment.