llvm.org GIT mirror llvm / 9bdd785
ARM: diagnose ARM/Thumb assembly switches on CPUs only supporting one. Some ARM CPUs only support ARM mode (ancient v4 ones, for example) and some only support Thumb mode (M-class ones currently). This makes sure such CPUs default to the correct mode and makes the AsmParser diagnose an attempt to switch modes incorrectly. rdar://14024354 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183710 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Northover 6 years ago
8 changed file(s) with 59 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
3737 def FeatureThumb2 : SubtargetFeature<"thumb2", "HasThumb2", "true",
3838 "Enable Thumb2 instructions">;
3939 def FeatureNoARM : SubtargetFeature<"noarm", "NoARM", "true",
40 "Does not support ARM mode execution">;
40 "Does not support ARM mode execution",
41 [ModeThumb]>;
4142 def FeatureFP16 : SubtargetFeature<"fp16", "HasFP16", "true",
4243 "Enable half-precision floating point">;
4344 def FeatureVFP4 : SubtargetFeature<"vfp4", "HasVFPv4", "true",
151151 bool isThumbTwo() const {
152152 return isThumb() && (STI.getFeatureBits() & ARM::FeatureThumb2);
153153 }
154 bool hasThumb() const {
155 return STI.getFeatureBits() & ARM::HasV4TOps;
156 }
154157 bool hasV6Ops() const {
155158 return STI.getFeatureBits() & ARM::HasV6Ops;
156159 }
157160 bool hasV7Ops() const {
158161 return STI.getFeatureBits() & ARM::HasV7Ops;
159162 }
163 bool hasARM() const {
164 return !(STI.getFeatureBits() & ARM::FeatureNoARM);
165 }
166
160167 void SwitchMode() {
161168 unsigned FB = ComputeAvailableFeatures(STI.ToggleFeature(ARM::ModeThumb));
162169 setAvailableFeatures(FB);
78157822 return Error(L, "unexpected token in directive");
78167823 Parser.Lex();
78177824
7825 if (!hasThumb())
7826 return Error(L, "target does not support Thumb mode");
7827
78187828 if (!isThumb())
78197829 SwitchMode();
78207830 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
78277837 if (getLexer().isNot(AsmToken::EndOfStatement))
78287838 return Error(L, "unexpected token in directive");
78297839 Parser.Lex();
7840
7841 if (!hasARM())
7842 return Error(L, "target does not support ARM mode");
78307843
78317844 if (isThumb())
78327845 SwitchMode();
79177930 Parser.Lex();
79187931
79197932 if (Val == 16) {
7933 if (!hasThumb())
7934 return Error(L, "target does not support Thumb mode");
7935
79207936 if (!isThumb())
79217937 SwitchMode();
79227938 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
79237939 } else {
7940 if (!hasARM())
7941 return Error(L, "target does not support ARM mode");
7942
79247943 if (isThumb())
79257944 SwitchMode();
79267945 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
6060 unsigned SubVer = TT[Idx];
6161 if (SubVer >= '7' && SubVer <= '9') {
6262 if (Len >= Idx+2 && TT[Idx+1] == 'm') {
63 isThumb = true;
6364 if (NoCPU)
6465 // v7m: FeatureNoARM, FeatureDB, FeatureHWDiv, FeatureMClass
6566 ARMArchFeature = "+v7,+noarm,+db,+hwdiv,+mclass";
9899 if (Len >= Idx+3 && TT[Idx+1] == 't' && TT[Idx+2] == '2')
99100 ARMArchFeature = "+v6t2";
100101 else if (Len >= Idx+2 && TT[Idx+1] == 'm') {
102 isThumb = true;
101103 if (NoCPU)
102104 // v6m: FeatureNoARM, FeatureMClass
103105 ARMArchFeature = "+v6,+noarm,+mclass";
0 @ RUN: llvm-mc -show-encoding -arch=arm < %s | FileCheck %s --check-prefix=CHECK-ARM-ONLY
1 @ RUN: llvm-mc -show-encoding -triple=armv4t < %s | FileCheck %s --check-prefix=CHECK-ARM-THUMB
2 @ RUN: llvm-mc -show-encoding -arch=arm -mcpu=cortex-a15 < %s| FileCheck %s --check-prefix=CHECK-ARM-THUMB
3 @ RUN: llvm-mc -show-encoding -arch=arm -mcpu=cortex-m3 < %s | FileCheck %s --check-prefix=CHECK-THUMB-ONLY
4 @ RUN: llvm-mc -show-encoding -triple=armv7m < %s | FileCheck %s --check-prefix=CHECK-THUMB-ONLY
5 @ RUN: llvm-mc -show-encoding -triple=armv6m < %s | FileCheck %s --check-prefix=CHECK-THUMB-ONLY
6
7 @ Make sure the architecture chosen by LLVM defaults to a compatible
8 @ ARM/Thumb mode.
9 movs r0, r0
10 @ CHECK-ARM-THUMB: movs r0, r0 @ encoding: [0x00,0x00,0xb0,0xe1]
11 @ CHECK-ARM-ONLY: movs r0, r0 @ encoding: [0x00,0x00,0xb0,0xe1]
12 @ CHECK-THUMB-ONLY: movs r0, r0 @ encoding: [0x00,0x00]
0 @ RUN: llvm-mc -show-encoding -arch=arm < %s 2>&1 | FileCheck %s --check-prefix=CHECK-ARM-ONLY
1 @ RUN: llvm-mc -show-encoding -triple=armv4t < %s 2>&1| FileCheck %s --check-prefix=CHECK-ARM-THUMB
2 @ RUN: llvm-mc -show-encoding -arch=arm -mcpu=cortex-a15 < %s 2>&1| FileCheck %s --check-prefix=CHECK-ARM-THUMB
3 @ RUN: llvm-mc -show-encoding -arch=arm -mcpu=cortex-m3 < %s 2>&1 | FileCheck %s --check-prefix=CHECK-THUMB-ONLY
4 @ RUN: llvm-mc -show-encoding -triple=armv7m < %s 2>&1 | FileCheck %s --check-prefix=CHECK-THUMB-ONLY
5 @ RUN: llvm-mc -show-encoding -triple=armv6m < %s 2>&1 | FileCheck %s --check-prefix=CHECK-THUMB-ONLY
6
7 @ Make sure correct diagnostics are given for CPUs without support for
8 @ one or other of the execution states.
9 .thumb
10 .arm
11 .code 16
12 .code 32
13 @ CHECK-ARM-THUMB-NOT: target does not support
14
15 @ CHECK-ARM-ONLY: target does not support Thumb mode
16 @ CHECK-ARM-ONLY: target does not support Thumb mode
17
18 @ CHECK-THUMB-ONLY: target does not support ARM mode
19 @ CHECK-THUMB-ONLY: target does not support ARM mode
0 @@ test st_value bit 0 of thumb function
1 @ RUN: llvm-mc %s -triple=arm-freebsd-eabi -filetype=obj -o - | \
1 @ RUN: llvm-mc %s -triple=armv4t-freebsd-eabi -filetype=obj -o - | \
22 @ RUN: llvm-readobj -r | FileCheck %s
33
44
None @ RUN: llvm-mc -triple=arm-linux-gnueabi -filetype=obj < %s | llvm-objdump -t - | FileCheck %s
0 @ RUN: llvm-mc -triple=armv7-linux-gnueabi -filetype=obj < %s | llvm-objdump -t - | FileCheck %s
11
22 .text
33 @ $a at 0x0000
None @ RUN: llvm-mc -triple=arm-linux-gnueabi -filetype=obj < %s | llvm-objdump -t - | FileCheck %s
0 @ RUN: llvm-mc -triple=armv7-linux-gnueabi -filetype=obj < %s | llvm-objdump -t - | FileCheck %s
11
22 .text
33 add r0, r0, r0