ARMAssembler.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /* libs/pixelflinger/codeflinger/ARMAssembler.h
  2. **
  3. ** Copyright 2006, The Android Open Source Project
  4. **
  5. ** Licensed under the Apache License, Version 2.0 (the "License");
  6. ** you may not use this file except in compliance with the License.
  7. ** You may obtain a copy of the License at
  8. **
  9. ** http://www.apache.org/licenses/LICENSE-2.0
  10. **
  11. ** Unless required by applicable law or agreed to in writing, software
  12. ** distributed under the License is distributed on an "AS IS" BASIS,
  13. ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ** See the License for the specific language governing permissions and
  15. ** limitations under the License.
  16. */
  17. #ifndef ANDROID_ARMASSEMBLER_H
  18. #define ANDROID_ARMASSEMBLER_H
  19. #include <stdint.h>
  20. #include <sys/types.h>
  21. #include "tinyutils/smartpointer.h"
  22. #include "utils/Vector.h"
  23. #include "utils/KeyedVector.h"
  24. #include "ARMAssemblerInterface.h"
  25. #include "CodeCache.h"
  26. namespace android {
  27. // ----------------------------------------------------------------------------
  28. class ARMAssembler : public ARMAssemblerInterface
  29. {
  30. public:
  31. explicit ARMAssembler(const sp<Assembly>& assembly);
  32. virtual ~ARMAssembler();
  33. uint32_t* base() const;
  34. uint32_t* pc() const;
  35. void disassemble(const char* name);
  36. // ------------------------------------------------------------------------
  37. // ARMAssemblerInterface...
  38. // ------------------------------------------------------------------------
  39. virtual void reset();
  40. virtual int generate(const char* name);
  41. virtual int getCodegenArch();
  42. virtual void prolog();
  43. virtual void epilog(uint32_t touched);
  44. virtual void comment(const char* string);
  45. // -----------------------------------------------------------------------
  46. // shifters and addressing modes
  47. // -----------------------------------------------------------------------
  48. // shifters...
  49. virtual bool isValidImmediate(uint32_t immed);
  50. virtual int buildImmediate(uint32_t i, uint32_t& rot, uint32_t& imm);
  51. virtual uint32_t imm(uint32_t immediate);
  52. virtual uint32_t reg_imm(int Rm, int type, uint32_t shift);
  53. virtual uint32_t reg_rrx(int Rm);
  54. virtual uint32_t reg_reg(int Rm, int type, int Rs);
  55. // addressing modes...
  56. // LDR(B)/STR(B)/PLD
  57. // (immediate and Rm can be negative, which indicates U=0)
  58. virtual uint32_t immed12_pre(int32_t immed12, int W=0);
  59. virtual uint32_t immed12_post(int32_t immed12);
  60. virtual uint32_t reg_scale_pre(int Rm, int type=0, uint32_t shift=0, int W=0);
  61. virtual uint32_t reg_scale_post(int Rm, int type=0, uint32_t shift=0);
  62. // LDRH/LDRSB/LDRSH/STRH
  63. // (immediate and Rm can be negative, which indicates U=0)
  64. virtual uint32_t immed8_pre(int32_t immed8, int W=0);
  65. virtual uint32_t immed8_post(int32_t immed8);
  66. virtual uint32_t reg_pre(int Rm, int W=0);
  67. virtual uint32_t reg_post(int Rm);
  68. virtual void dataProcessing(int opcode, int cc, int s,
  69. int Rd, int Rn,
  70. uint32_t Op2);
  71. virtual void MLA(int cc, int s,
  72. int Rd, int Rm, int Rs, int Rn);
  73. virtual void MUL(int cc, int s,
  74. int Rd, int Rm, int Rs);
  75. virtual void UMULL(int cc, int s,
  76. int RdLo, int RdHi, int Rm, int Rs);
  77. virtual void UMUAL(int cc, int s,
  78. int RdLo, int RdHi, int Rm, int Rs);
  79. virtual void SMULL(int cc, int s,
  80. int RdLo, int RdHi, int Rm, int Rs);
  81. virtual void SMUAL(int cc, int s,
  82. int RdLo, int RdHi, int Rm, int Rs);
  83. virtual void B(int cc, uint32_t* pc);
  84. virtual void BL(int cc, uint32_t* pc);
  85. virtual void BX(int cc, int Rn);
  86. virtual void label(const char* theLabel);
  87. virtual void B(int cc, const char* label);
  88. virtual void BL(int cc, const char* label);
  89. virtual uint32_t* pcForLabel(const char* label);
  90. virtual void LDR (int cc, int Rd,
  91. int Rn, uint32_t offset = __immed12_pre(0));
  92. virtual void LDRB(int cc, int Rd,
  93. int Rn, uint32_t offset = __immed12_pre(0));
  94. virtual void STR (int cc, int Rd,
  95. int Rn, uint32_t offset = __immed12_pre(0));
  96. virtual void STRB(int cc, int Rd,
  97. int Rn, uint32_t offset = __immed12_pre(0));
  98. virtual void LDRH (int cc, int Rd,
  99. int Rn, uint32_t offset = __immed8_pre(0));
  100. virtual void LDRSB(int cc, int Rd,
  101. int Rn, uint32_t offset = __immed8_pre(0));
  102. virtual void LDRSH(int cc, int Rd,
  103. int Rn, uint32_t offset = __immed8_pre(0));
  104. virtual void STRH (int cc, int Rd,
  105. int Rn, uint32_t offset = __immed8_pre(0));
  106. virtual void LDM(int cc, int dir,
  107. int Rn, int W, uint32_t reg_list);
  108. virtual void STM(int cc, int dir,
  109. int Rn, int W, uint32_t reg_list);
  110. virtual void SWP(int cc, int Rn, int Rd, int Rm);
  111. virtual void SWPB(int cc, int Rn, int Rd, int Rm);
  112. virtual void SWI(int cc, uint32_t comment);
  113. virtual void PLD(int Rn, uint32_t offset);
  114. virtual void CLZ(int cc, int Rd, int Rm);
  115. virtual void QADD(int cc, int Rd, int Rm, int Rn);
  116. virtual void QDADD(int cc, int Rd, int Rm, int Rn);
  117. virtual void QSUB(int cc, int Rd, int Rm, int Rn);
  118. virtual void QDSUB(int cc, int Rd, int Rm, int Rn);
  119. virtual void SMUL(int cc, int xy,
  120. int Rd, int Rm, int Rs);
  121. virtual void SMULW(int cc, int y,
  122. int Rd, int Rm, int Rs);
  123. virtual void SMLA(int cc, int xy,
  124. int Rd, int Rm, int Rs, int Rn);
  125. virtual void SMLAL(int cc, int xy,
  126. int RdHi, int RdLo, int Rs, int Rm);
  127. virtual void SMLAW(int cc, int y,
  128. int Rd, int Rm, int Rs, int Rn);
  129. virtual void UXTB16(int cc, int Rd, int Rm, int rotate);
  130. virtual void UBFX(int cc, int Rd, int Rn, int lsb, int width);
  131. private:
  132. ARMAssembler(const ARMAssembler& rhs);
  133. ARMAssembler& operator = (const ARMAssembler& rhs);
  134. sp<Assembly> mAssembly;
  135. uint32_t* mBase;
  136. uint32_t* mPC;
  137. uint32_t* mPrologPC;
  138. int64_t mDuration;
  139. struct branch_target_t {
  140. inline branch_target_t() : label(0), pc(0) { }
  141. inline branch_target_t(const char* l, uint32_t* p)
  142. : label(l), pc(p) { }
  143. const char* label;
  144. uint32_t* pc;
  145. };
  146. Vector<branch_target_t> mBranchTargets;
  147. KeyedVector< const char*, uint32_t* > mLabels;
  148. KeyedVector< uint32_t*, const char* > mLabelsInverseMapping;
  149. KeyedVector< uint32_t*, const char* > mComments;
  150. };
  151. }; // namespace android
  152. #endif //ANDROID_ARMASSEMBLER_H