Skip to content

Commit 0e65378

Browse files
committed
IAR compiler abstraction fixes
1 parent d8151ca commit 0e65378

File tree

8 files changed

+106
-27
lines changed

8 files changed

+106
-27
lines changed

.devcontainer/ubuntu-22.04/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ RUN pip install \
3939
lit \
4040
python-matrix-runner
4141

42+
RUN pushd /root && \
43+
curl -LO http://files.iar.com/ftp/pub/box/bxarm-9.40.2.deb && \
44+
dpkg -i bxarm-9.40.2.deb && \
45+
rm bxarm-9.40.2.deb
46+
47+
ENV PATH=$PATH:/opt/iarsystems/bxarm/arm/bin
48+
ENV IAR_TOOLCHAIN_9_40_2=/opt/iarsystems/bxarm/arm/bin
49+
ENV IAR_LMS_SETTINGS_DIR=/home/$USERNAME/.iarlm
50+
4251
# Create the user
4352
RUN groupadd --gid $USER_GID $USERNAME \
4453
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME -s /bin/bash \

CMSIS/Core/Include/m-profile/cmsis_iccarm_m.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ __STATIC_FORCEINLINE void __TZ_set_STACKSEAL_S (uint32_t* stackTop) {
323323
#define __get_CONTROL() (__arm_rsr("CONTROL"))
324324
#define __get_FAULTMASK() (__arm_rsr("FAULTMASK"))
325325

326-
#if ((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
327-
(defined (__FPU_USED ) && (__FPU_USED == 1U)) )
326+
#if (defined(__ARM_FP) && (__ARM_FP >= 1))
328327
#define __get_FPSCR() (__arm_rsr("FPSCR"))
329328
#define __set_FPSCR(VALUE) (__arm_wsr("FPSCR", (VALUE)))
330329
#else
@@ -536,8 +535,7 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
536535
#endif
537536

538537

539-
#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
540-
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
538+
#if (!defined(__ARM_FP) || (__ARM_FP == 0))
541539
#define __get_FPSCR __cmsis_iar_get_FPSR_not_active
542540
#define __set_FPSCR __cmsis_iar_set_FPSR_not_active
543541
#endif
@@ -593,8 +591,7 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
593591

594592
#endif
595593

596-
#if (!((defined (__FPU_PRESENT) && (__FPU_PRESENT == 1U)) && \
597-
(defined (__FPU_USED ) && (__FPU_USED == 1U)) ))
594+
#if (!defined(__ARM_FP) || (__ARM_FP == 0))
598595
#undef __get_FPSCR
599596
#undef __set_FPSCR
600597
#define __get_FPSCR() (0)
@@ -865,7 +862,7 @@ __STATIC_FORCEINLINE void __TZ_set_CONTROL_NS(uint32_t control)
865862
}
866863
#endif
867864

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

870867
__IAR_FT uint8_t __LDRBT(volatile uint8_t *addr)
871868
{

CMSIS/Core/Test/build.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,23 @@ class OptimizationAxis(Enum):
5959

6060

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

6666

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

7070
@matrix_command()
71-
def run_lit(toolchain, device, optimize):
72-
return ["lit", "--xunit-xml-output", f"lit-{toolchain}-{optimize}-{device}.xunit", "-D", f"toolchain={toolchain}", "-D", f"device={device}", "-D", f"optimize={optimize}", "." ]
73-
74-
@matrix_filter
75-
def filter_iar(config):
76-
return config.compiler == CompilerAxis.IAR
71+
def run_lit(toolchain, device, optimize, extra_args = None):
72+
if not extra_args:
73+
extra_args = ["."]
74+
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
75+
76+
# @matrix_filter
77+
# def filter_iar(config):
78+
# return config.compiler == CompilerAxis.IAR
7779

7880
@matrix_filter
7981
def filter_gcc_cm85(config):

CMSIS/Core/Test/lit.cfg.py

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
'triple': 'thumbv7-em',
118118
'abi': 'eabi',
119119
'mcpu': 'cortex-m7',
120-
'mfpu': 'fpv4-sp-d16',
120+
'mfpu': 'fpv5-sp-d16',
121121
'mpu': True,
122122
'features': ['thumbv6m', 'thumbv7m', 'dsp', 'thumb-2', 'sat', 'ldrex', 'clz'],
123123
'header': 'core_cm7.h',
@@ -640,6 +640,11 @@
640640
# test_source_root: The root path where tests are located.
641641
config.test_source_root = os.path.dirname(__file__)
642642

643+
# environment
644+
preserv_env_vars = ['IAR_LMS_SETTINGS_DIR']
645+
for var in preserv_env_vars:
646+
if var in os.environ:
647+
config.environment[var] = os.environ[var]
643648

644649
# clang_path = get_toolchain_from_env('CLANG')
645650

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

725+
720726
class Toolchain_Clang(Toolchain):
721727
TARGET = {
722728
'CM0': 'thumbv6m-none-unknown-eabi',
@@ -772,13 +778,82 @@ def get_ccflags(self):
772778

773779
return ccflags
774780

781+
782+
class Toolchain_IAR(Toolchain):
783+
OPTIMIZE = {
784+
'none': '-Ol',
785+
'balanced': '-Oh',
786+
'speed': '-Ohs',
787+
'size': '-Ohz'
788+
}
789+
790+
CPU = {
791+
'CM0': 'cortex-m0',
792+
'CM0plus': 'cortex-m0+',
793+
'CM3': 'cortex-m3',
794+
'CM4': 'cortex-m4',
795+
'CM4FP': 'cortex-m4.fp.sp',
796+
'CM7': 'cortex-m7',
797+
'CM7SP': 'cortex-m7.fp.sp',
798+
'CM7DP': 'cortex-m7.fp.dp',
799+
'CM23': 'cortex-m.no_se',
800+
'CM23S': 'cortex-m',
801+
'CM23NS': 'cortex-m',
802+
'CM33': 'cortex-m.no_se',
803+
'CM33S': 'cortex-m',
804+
'CM33NS': 'cortex-m',
805+
'CM35P': 'cortex-m.no_se',
806+
'CM35PS': 'cortex-m',
807+
'CM35PNS': 'cortex-m',
808+
'CM55': 'cortex-m.no_se',
809+
'CM55S': 'cortex-m',
810+
'CM55NS': 'cortex-m',
811+
'CM85': 'cortex-m.no_se',
812+
'CM85S': 'cortex-m',
813+
'CM85NS': 'cortex-m',
814+
'CA5': 'cortex-a5',
815+
'CA5neon': 'cortex-a5.neon',
816+
'CA7': 'cortex-a7.no_neon.no_vfp',
817+
'CA7neon': 'cortex-a7',
818+
'CA9': 'cortex-a9.no_neon.no_vfp',
819+
'CA9neon': 'cortex-a9'
820+
}
821+
822+
FPU = {
823+
'none': 'none',
824+
'fpv3-d16': 'vfpv3_d16',
825+
'fpv4-sp-d16': 'vfpv4-sp',
826+
'fpv5-sp-d16': 'vfpv5-sp',
827+
'fpv5-d16': 'vfpv5_d16',
828+
'neon-vfpv3': 'vfpv3',
829+
'neon-vfpv4': 'vfpv4'
830+
}
831+
832+
def __init__(self, **args):
833+
super().__init__('IAR', **args)
834+
835+
def get_cc(self):
836+
return os.path.join(self.get_root(), 'iccarm')
837+
838+
def get_ccflags(self):
839+
ccflags = [
840+
'-e', f'--cpu={self.CPU[self.device]}', f'--fpu={self.FPU[DEVICES[self.device]["mfpu"]]}',
841+
self.OPTIMIZE[self.optimize], '-I', '../Include', '-c', '-D', f'CORE_HEADER=\\"{DEVICES[device]["header"]}\\"']
842+
if device.endswith('S') and not device.endswith('NS'):
843+
ccflags += ["--cmse"]
844+
ccflags += list(sum([('-D', f'{define}={value}') for (define, value) in DEVICES[self.device]['defines'].items()], ()))
845+
return ccflags
846+
847+
775848
tc = None
776849
if toolchain == 'AC6':
777850
tc = Toolchain_AC6(device=device, optimize=optimize)
778851
elif toolchain == 'GCC':
779852
tc = Toolchain_GCC(device=device, optimize=optimize)
780853
elif toolchain == 'Clang':
781854
tc = Toolchain_Clang(device=device, optimize=optimize)
855+
elif toolchain == 'IAR':
856+
tc = Toolchain_IAR(device=device, optimize=optimize)
782857

783858
prefixes = ['CHECK']
784859
if device.endswith('NS'):

CMSIS/Core/Test/noreturn.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
#include "cmsis_compiler.h"
44

55
__NO_RETURN
6-
static void func() {
7-
while(1);
8-
}
9-
106
void noreturn() {
117
// CHECK-LABEL: <noreturn>:
128
// CHECK: b 0x0 <noreturn>
13-
func();
9+
while(1);
1410
// CHECK-NOT: bx lr
1511
}

CMSIS/Core/Test/ror.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ static volatile uint32_t b = 2u;
77

88
void ror() {
99
// CHECK-LABEL: <ror>:
10-
// CHECK-THUMB: ror{{s|.w}} {{r[0-9]+}}, {{r[0-9]+}}
10+
// CHECK-THUMB: ror{{(s)?(.w)?}} {{r[0-9]+}}, {{r[0-9]+}}
1111
// CHECK-ARM: ror {{r[0-9]+}}, {{r[0-9]+}}, {{r[0-9]+}}
1212
volatile uint32_t c = __ROR(a, b);
1313
// CHECK: {{(bx lr)|(pop {.*pc})}}

CMSIS/Core/Test/rrx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ static volatile uint32_t a = 10u;
77

88
void rrx() {
99
// CHECK-LABEL: <rrx>:
10-
// CHECK: rrx {{r[0-9]+}}, {{r[0-9]+}}
10+
// CHECK: rrx{{(s)?}} {{r[0-9]+}}, {{r[0-9]+}}
1111
volatile uint32_t c = __RRX(a);
1212
// CHECK: {{(bx lr)|(pop {.*pc})}}
1313
}

CMSIS/CoreValidation/Project/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ def model_exec(config):
253253
return cmdline
254254

255255

256-
@matrix_filter
257-
def filter_iar(config):
258-
return config.compiler == CompilerAxis.IAR
256+
# @matrix_filter
257+
# def filter_iar(config):
258+
# return config.compiler == CompilerAxis.IAR
259259

260260

261261
@matrix_filter

0 commit comments

Comments
 (0)