1 // Copyright 2015, VIXL authors
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 //   * Redistributions of source code must retain the above copyright notice,
8 //     this list of conditions and the following disclaimer.
9 //   * Redistributions in binary form must reproduce the above copyright
10 //     notice, this list of conditions and the following disclaimer in the
11 //     documentation and/or other materials provided with the distribution.
12 //   * Neither the name of ARM Limited nor the names of its contributors may
13 //     be used to endorse or promote products derived from this software
14 //     without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND
17 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef VIXL_CONSTANTS_AARCH32_H_
29 #define VIXL_CONSTANTS_AARCH32_H_
30 
31 extern "C" {
32 #include <stdint.h>
33 }
34 
35 #include "globals-vixl.h"
36 
37 
38 namespace vixl {
39 namespace aarch32 {
40 
41 enum InstructionSet { A32, T32 };
42 #ifdef VIXL_INCLUDE_TARGET_T32_ONLY
43 const InstructionSet kDefaultISA = T32;
44 #else
45 const InstructionSet kDefaultISA = A32;
46 #endif
47 
48 const unsigned kRegSizeInBits = 32;
49 const unsigned kRegSizeInBytes = kRegSizeInBits / 8;
50 const unsigned kSRegSizeInBits = 32;
51 const unsigned kSRegSizeInBytes = kSRegSizeInBits / 8;
52 const unsigned kDRegSizeInBits = 64;
53 const unsigned kDRegSizeInBytes = kDRegSizeInBits / 8;
54 const unsigned kQRegSizeInBits = 128;
55 const unsigned kQRegSizeInBytes = kQRegSizeInBits / 8;
56 
57 const unsigned kNumberOfRegisters = 16;
58 const unsigned kNumberOfSRegisters = 32;
59 const unsigned kMaxNumberOfDRegisters = 32;
60 const unsigned kNumberOfQRegisters = 16;
61 const unsigned kNumberOfT32LowRegisters = 8;
62 
63 const unsigned kIpCode = 12;
64 const unsigned kSpCode = 13;
65 const unsigned kLrCode = 14;
66 const unsigned kPcCode = 15;
67 
68 const unsigned kT32PcDelta = 4;
69 const unsigned kA32PcDelta = 8;
70 
71 const unsigned kRRXEncodedValue = 3;
72 
73 const unsigned kCoprocMask = 0xe;
74 const unsigned kInvalidCoprocMask = 0xa;
75 
76 const unsigned kLowestT32_32Opcode = 0xe8000000;
77 
78 const uint32_t kUnknownValue = 0xdeadbeef;
79 
80 const uint32_t kMaxInstructionSizeInBytes = 4;
81 const uint32_t kA32InstructionSizeInBytes = 4;
82 const uint32_t k32BitT32InstructionSizeInBytes = 4;
83 const uint32_t k16BitT32InstructionSizeInBytes = 2;
84 
85 // Maximum size emitted by a single T32 unconditional macro-instruction.
86 const uint32_t kMaxT32MacroInstructionSizeInBytes = 32;
87 
88 const uint32_t kCallerSavedRegistersMask = 0x500f;
89 
90 const uint16_t k16BitT32NopOpcode = 0xbf00;
91 const uint16_t kCbzCbnzMask = 0xf500;
92 const uint16_t kCbzCbnzValue = 0xb100;
93 
94 const int32_t kCbzCbnzRange = 126;
95 const int32_t kBConditionalNarrowRange = 254;
96 const int32_t kBNarrowRange = 2046;
97 const int32_t kNearLabelRange = kBNarrowRange;
98 
99 enum SystemFunctionsOpcodes { kPrintfCode };
100 
101 enum BranchHint { kNear, kFar, kBranchWithoutHint };
102 
103 // Start of generated code.
104 // AArch32 version implemented by the library (v8.0).
105 // The encoding for vX.Y is: (X << 8) | Y.
106 #define AARCH32_VERSION 0x0800
107 
108 enum InstructionAttribute {
109   kNoAttribute = 0,
110   kArithmetic = 0x1,
111   kBitwise = 0x2,
112   kShift = 0x4,
113   kAddress = 0x8,
114   kBranch = 0x10,
115   kSystem = 0x20,
116   kFpNeon = 0x40,
117   kLoadStore = 0x80,
118   kLoadStoreMultiple = 0x100
119 };
120 
121 enum InstructionType {
122   kUndefInstructionType,
123   kAdc,
124   kAdcs,
125   kAdd,
126   kAdds,
127   kAddw,
128   kAdr,
129   kAnd,
130   kAnds,
131   kAsr,
132   kAsrs,
133   kB,
134   kBfc,
135   kBfi,
136   kBic,
137   kBics,
138   kBkpt,
139   kBl,
140   kBlx,
141   kBx,
142   kBxj,
143   kCbnz,
144   kCbz,
145   kClrex,
146   kClz,
147   kCmn,
148   kCmp,
149   kCrc32b,
150   kCrc32cb,
151   kCrc32ch,
152   kCrc32cw,
153   kCrc32h,
154   kCrc32w,
155   kDmb,
156   kDsb,
157   kEor,
158   kEors,
159   kFldmdbx,
160   kFldmiax,
161   kFstmdbx,
162   kFstmiax,
163   kHlt,
164   kHvc,
165   kIsb,
166   kIt,
167   kLda,
168   kLdab,
169   kLdaex,
170   kLdaexb,
171   kLdaexd,
172   kLdaexh,
173   kLdah,
174   kLdm,
175   kLdmda,
176   kLdmdb,
177   kLdmea,
178   kLdmed,
179   kLdmfa,
180   kLdmfd,
181   kLdmib,
182   kLdr,
183   kLdrb,
184   kLdrd,
185   kLdrex,
186   kLdrexb,
187   kLdrexd,
188   kLdrexh,
189   kLdrh,
190   kLdrsb,
191   kLdrsh,
192   kLsl,
193   kLsls,
194   kLsr,
195   kLsrs,
196   kMla,
197   kMlas,
198   kMls,
199   kMov,
200   kMovs,
201   kMovt,
202   kMovw,
203   kMrs,
204   kMsr,
205   kMul,
206   kMuls,
207   kMvn,
208   kMvns,
209   kNop,
210   kOrn,
211   kOrns,
212   kOrr,
213   kOrrs,
214   kPkhbt,
215   kPkhtb,
216   kPld,
217   kPldw,
218   kPli,
219   kPop,
220   kPush,
221   kQadd,
222   kQadd16,
223   kQadd8,
224   kQasx,
225   kQdadd,
226   kQdsub,
227   kQsax,
228   kQsub,
229   kQsub16,
230   kQsub8,
231   kRbit,
232   kRev,
233   kRev16,
234   kRevsh,
235   kRor,
236   kRors,
237   kRrx,
238   kRrxs,
239   kRsb,
240   kRsbs,
241   kRsc,
242   kRscs,
243   kSadd16,
244   kSadd8,
245   kSasx,
246   kSbc,
247   kSbcs,
248   kSbfx,
249   kSdiv,
250   kSel,
251   kShadd16,
252   kShadd8,
253   kShasx,
254   kShsax,
255   kShsub16,
256   kShsub8,
257   kSmlabb,
258   kSmlabt,
259   kSmlad,
260   kSmladx,
261   kSmlal,
262   kSmlalbb,
263   kSmlalbt,
264   kSmlald,
265   kSmlaldx,
266   kSmlals,
267   kSmlaltb,
268   kSmlaltt,
269   kSmlatb,
270   kSmlatt,
271   kSmlawb,
272   kSmlawt,
273   kSmlsd,
274   kSmlsdx,
275   kSmlsld,
276   kSmlsldx,
277   kSmmla,
278   kSmmlar,
279   kSmmls,
280   kSmmlsr,
281   kSmmul,
282   kSmmulr,
283   kSmuad,
284   kSmuadx,
285   kSmulbb,
286   kSmulbt,
287   kSmull,
288   kSmulls,
289   kSmultb,
290   kSmultt,
291   kSmulwb,
292   kSmulwt,
293   kSmusd,
294   kSmusdx,
295   kSsat,
296   kSsat16,
297   kSsax,
298   kSsub16,
299   kSsub8,
300   kStl,
301   kStlb,
302   kStlex,
303   kStlexb,
304   kStlexd,
305   kStlexh,
306   kStlh,
307   kStm,
308   kStmda,
309   kStmdb,
310   kStmea,
311   kStmed,
312   kStmfa,
313   kStmfd,
314   kStmib,
315   kStr,
316   kStrb,
317   kStrd,
318   kStrex,
319   kStrexb,
320   kStrexd,
321   kStrexh,
322   kStrh,
323   kSub,
324   kSubs,
325   kSubw,
326   kSvc,
327   kSxtab,
328   kSxtab16,
329   kSxtah,
330   kSxtb,
331   kSxtb16,
332   kSxth,
333   kTbb,
334   kTbh,
335   kTeq,
336   kTst,
337   kUadd16,
338   kUadd8,
339   kUasx,
340   kUbfx,
341   kUdf,
342   kUdiv,
343   kUhadd16,
344   kUhadd8,
345   kUhasx,
346   kUhsax,
347   kUhsub16,
348   kUhsub8,
349   kUmaal,
350   kUmlal,
351   kUmlals,
352   kUmull,
353   kUmulls,
354   kUqadd16,
355   kUqadd8,
356   kUqasx,
357   kUqsax,
358   kUqsub16,
359   kUqsub8,
360   kUsad8,
361   kUsada8,
362   kUsat,
363   kUsat16,
364   kUsax,
365   kUsub16,
366   kUsub8,
367   kUxtab,
368   kUxtab16,
369   kUxtah,
370   kUxtb,
371   kUxtb16,
372   kUxth,
373   kVaba,
374   kVabal,
375   kVabd,
376   kVabdl,
377   kVabs,
378   kVacge,
379   kVacgt,
380   kVacle,
381   kVaclt,
382   kVadd,
383   kVaddhn,
384   kVaddl,
385   kVaddw,
386   kVand,
387   kVbic,
388   kVbif,
389   kVbit,
390   kVbsl,
391   kVceq,
392   kVcge,
393   kVcgt,
394   kVcle,
395   kVcls,
396   kVclt,
397   kVclz,
398   kVcmp,
399   kVcmpe,
400   kVcnt,
401   kVcvt,
402   kVcvta,
403   kVcvtb,
404   kVcvtm,
405   kVcvtn,
406   kVcvtp,
407   kVcvtr,
408   kVcvtt,
409   kVdiv,
410   kVdup,
411   kVeor,
412   kVext,
413   kVfma,
414   kVfms,
415   kVfnma,
416   kVfnms,
417   kVhadd,
418   kVhsub,
419   kVld1,
420   kVld2,
421   kVld3,
422   kVld4,
423   kVldm,
424   kVldmdb,
425   kVldmia,
426   kVldr,
427   kVmax,
428   kVmaxnm,
429   kVmin,
430   kVminnm,
431   kVmla,
432   kVmlal,
433   kVmls,
434   kVmlsl,
435   kVmov,
436   kVmovl,
437   kVmovn,
438   kVmrs,
439   kVmsr,
440   kVmul,
441   kVmull,
442   kVmvn,
443   kVneg,
444   kVnmla,
445   kVnmls,
446   kVnmul,
447   kVorn,
448   kVorr,
449   kVpadal,
450   kVpadd,
451   kVpaddl,
452   kVpmax,
453   kVpmin,
454   kVpop,
455   kVpush,
456   kVqabs,
457   kVqadd,
458   kVqdmlal,
459   kVqdmlsl,
460   kVqdmulh,
461   kVqdmull,
462   kVqmovn,
463   kVqmovun,
464   kVqneg,
465   kVqrdmulh,
466   kVqrshl,
467   kVqrshrn,
468   kVqrshrun,
469   kVqshl,
470   kVqshlu,
471   kVqshrn,
472   kVqshrun,
473   kVqsub,
474   kVraddhn,
475   kVrecpe,
476   kVrecps,
477   kVrev16,
478   kVrev32,
479   kVrev64,
480   kVrhadd,
481   kVrinta,
482   kVrintm,
483   kVrintn,
484   kVrintp,
485   kVrintr,
486   kVrintx,
487   kVrintz,
488   kVrshl,
489   kVrshr,
490   kVrshrn,
491   kVrsqrte,
492   kVrsqrts,
493   kVrsra,
494   kVrsubhn,
495   kVseleq,
496   kVselge,
497   kVselgt,
498   kVselvs,
499   kVshl,
500   kVshll,
501   kVshr,
502   kVshrn,
503   kVsli,
504   kVsqrt,
505   kVsra,
506   kVsri,
507   kVst1,
508   kVst2,
509   kVst3,
510   kVst4,
511   kVstm,
512   kVstmdb,
513   kVstmia,
514   kVstr,
515   kVsub,
516   kVsubhn,
517   kVsubl,
518   kVsubw,
519   kVswp,
520   kVtbl,
521   kVtbx,
522   kVtrn,
523   kVtst,
524   kVuzp,
525   kVzip,
526   kYield
527 };
528 
529 const char* ToCString(InstructionType type);
530 // End of generated code.
531 
532 inline InstructionAttribute operator|(InstructionAttribute left,
533                                       InstructionAttribute right) {
534   return static_cast<InstructionAttribute>(static_cast<uint32_t>(left) |
535                                            static_cast<uint32_t>(right));
536 }
537 
538 }  // namespace aarch32
539 }  // namespace vixl
540 
541 #endif  // VIXL_CONSTANTS_AARCH32_H_
542