armdefs.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. /* armdefs.h -- ARMulator common definitions: ARM6 Instruction Emulator.
  2. Copyright (C) 1994 Advanced RISC Machines Ltd.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. #pragma once
  15. #include <cerrno>
  16. #include <csignal>
  17. #include <cstdio>
  18. #include <cstdlib>
  19. #include <cstring>
  20. #include <fcntl.h>
  21. #include <sys/stat.h>
  22. #include <sys/types.h>
  23. #include "arm_regformat.h"
  24. #include "common/common_types.h"
  25. #include "common/platform.h"
  26. #include "core/arm/skyeye_common/armmmu.h"
  27. #include "core/arm/skyeye_common/skyeye_defs.h"
  28. #define BITS(s, a, b) ((s << ((sizeof(s) * 8 - 1) - b)) >> (sizeof(s) * 8 - b + a - 1))
  29. #define BIT(s, n) ((s >> (n)) & 1)
  30. #define LOW 0
  31. #define HIGH 1
  32. #define LOWHIGH 1
  33. #define HIGHLOW 2
  34. //the define of cachetype
  35. #define NONCACHE 0
  36. #define DATACACHE 1
  37. #define INSTCACHE 2
  38. #define POS(i) ( (~(i)) >> 31 )
  39. #define NEG(i) ( (i) >> 31 )
  40. typedef u64 ARMdword; // must be 64 bits wide
  41. typedef u32 ARMword; // must be 32 bits wide
  42. typedef u16 ARMhword; // must be 16 bits wide
  43. typedef u8 ARMbyte; // must be 8 bits wide
  44. typedef struct ARMul_State ARMul_State;
  45. typedef unsigned ARMul_CPInits(ARMul_State* state);
  46. typedef unsigned ARMul_CPExits(ARMul_State* state);
  47. typedef unsigned ARMul_LDCs(ARMul_State* state, unsigned type, ARMword instr, ARMword value);
  48. typedef unsigned ARMul_STCs(ARMul_State* state, unsigned type, ARMword instr, ARMword* value);
  49. typedef unsigned ARMul_MRCs(ARMul_State* state, unsigned type, ARMword instr, ARMword* value);
  50. typedef unsigned ARMul_MCRs(ARMul_State* state, unsigned type, ARMword instr, ARMword value);
  51. typedef unsigned ARMul_MRRCs(ARMul_State* state, unsigned type, ARMword instr, ARMword* value1, ARMword* value2);
  52. typedef unsigned ARMul_MCRRs(ARMul_State* state, unsigned type, ARMword instr, ARMword value1, ARMword value2);
  53. typedef unsigned ARMul_CDPs(ARMul_State* state, unsigned type, ARMword instr);
  54. typedef unsigned ARMul_CPReads(ARMul_State* state, unsigned reg, ARMword* value);
  55. typedef unsigned ARMul_CPWrites(ARMul_State* state, unsigned reg, ARMword value);
  56. #define VFP_REG_NUM 64
  57. struct ARMul_State
  58. {
  59. ARMword Emulate; // To start and stop emulation
  60. unsigned EndCondition; // Reason for stopping
  61. unsigned ErrorCode; // Type of illegal instruction
  62. // Order of the following register should not be modified
  63. ARMword Reg[16]; // The current register file
  64. ARMword Cpsr; // The current PSR
  65. ARMword Spsr_copy;
  66. ARMword phys_pc;
  67. ARMword Reg_usr[2];
  68. ARMword Reg_svc[2]; // R13_SVC R14_SVC
  69. ARMword Reg_abort[2]; // R13_ABORT R14_ABORT
  70. ARMword Reg_undef[2]; // R13 UNDEF R14 UNDEF
  71. ARMword Reg_irq[2]; // R13_IRQ R14_IRQ
  72. ARMword Reg_firq[7]; // R8---R14 FIRQ
  73. ARMword Spsr[7]; // The exception psr's
  74. ARMword Mode; // The current mode
  75. ARMword Bank; // The current register bank
  76. ARMword exclusive_tag; // The address for which the local monitor is in exclusive access mode
  77. ARMword exclusive_state;
  78. ARMword exclusive_result;
  79. ARMword CP15[VFP_BASE - CP15_BASE];
  80. ARMword VFP[3]; // FPSID, FPSCR, and FPEXC
  81. // VFPv2 and VFPv3-D16 has 16 doubleword registers (D0-D16 or S0-S31).
  82. // VFPv3-D32/ASIMD may have up to 32 doubleword registers (D0-D31),
  83. // and only 32 singleword registers are accessible (S0-S31).
  84. ARMword ExtReg[VFP_REG_NUM];
  85. /* ---- End of the ordered registers ---- */
  86. ARMword RegBank[7][16]; // all the registers
  87. ARMword NFlag, ZFlag, CFlag, VFlag, IFFlags; // Dummy flags for speed
  88. unsigned int shifter_carry_out;
  89. // Add armv6 flags dyf:2010-08-09
  90. ARMword GEFlag, EFlag, AFlag, QFlag;
  91. #ifdef MODET
  92. ARMword TFlag; // Thumb state
  93. #endif
  94. unsigned long long NumInstrs; // The number of instructions executed
  95. unsigned NumInstrsToExecute;
  96. unsigned NextInstr;
  97. unsigned VectorCatch; // Caught exception mask
  98. ARMul_CPInits* CPInit[16]; // Coprocessor initialisers
  99. ARMul_CPExits* CPExit[16]; // Coprocessor finalisers
  100. ARMul_LDCs* LDC[16]; // LDC instruction
  101. ARMul_STCs* STC[16]; // STC instruction
  102. ARMul_MRCs* MRC[16]; // MRC instruction
  103. ARMul_MCRs* MCR[16]; // MCR instruction
  104. ARMul_MRRCs* MRRC[16]; // MRRC instruction
  105. ARMul_MCRRs* MCRR[16]; // MCRR instruction
  106. ARMul_CDPs* CDP[16]; // CDP instruction
  107. ARMul_CPReads* CPRead[16]; // Read CP register
  108. ARMul_CPWrites* CPWrite[16]; // Write CP register
  109. unsigned char* CPData[16]; // Coprocessor data
  110. unsigned char const* CPRegWords[16]; // Map of coprocessor register sizes
  111. unsigned NresetSig; // Reset the processor
  112. unsigned NfiqSig;
  113. unsigned NirqSig;
  114. unsigned abortSig;
  115. unsigned NtransSig;
  116. unsigned bigendSig;
  117. unsigned prog32Sig;
  118. unsigned data32Sig;
  119. unsigned syscallSig;
  120. /* 2004-05-09 chy
  121. ----------------------------------------------------------
  122. read ARM Architecture Reference Manual
  123. 2.6.5 Data Abort
  124. There are three Abort Model in ARM arch.
  125. Early Abort Model: used in some ARMv3 and earlier implementations. In this
  126. model, base register wirteback occurred for LDC,LDM,STC,STM instructions, and
  127. the base register was unchanged for all other instructions. (oldest)
  128. Base Restored Abort Model: If a Data Abort occurs in an instruction which
  129. specifies base register writeback, the value in the base register is
  130. unchanged. (strongarm, xscale)
  131. Base Updated Abort Model: If a Data Abort occurs in an instruction which
  132. specifies base register writeback, the base register writeback still occurs.
  133. (arm720T)
  134. read PART B
  135. chap2 The System Control Coprocessor CP15
  136. 2.4 Register1:control register
  137. L(bit 6): in some ARMv3 and earlier implementations, the abort model of the
  138. processor could be configured:
  139. 0=early Abort Model Selected(now obsolete)
  140. 1=Late Abort Model selceted(same as Base Updated Abort Model)
  141. on later processors, this bit reads as 1 and ignores writes.
  142. -------------------------------------------------------------
  143. So, if lateabtSig=1, then it means Late Abort Model(Base Updated Abort Model)
  144. if lateabtSig=0, then it means Base Restored Abort Model
  145. */
  146. unsigned lateabtSig;
  147. bool Aborted; // Sticky flag for aborts
  148. bool Reseted; // Sticky flag for Reset
  149. ARMword Inted, LastInted; // Sticky flags for interrupts
  150. ARMword Base; // Extra hand for base writeback
  151. ARMword AbortAddr; // To keep track of Prefetch aborts
  152. ARMword Vector; // Synthesize aborts in cycle modes
  153. // For differentiating ARM core emulaiton.
  154. bool is_v4; // Are we emulating a v4 architecture (or higher)?
  155. bool is_v5; // Are we emulating a v5 architecture?
  156. bool is_v5e; // Are we emulating a v5e architecture?
  157. bool is_v6; // Are we emulating a v6 architecture?
  158. bool is_v7; // Are we emulating a v7 architecture?
  159. bool is_XScale; // Are we emulating an XScale architecture?
  160. bool is_iWMMXt; // Are we emulating an iWMMXt co-processor?
  161. bool is_ep9312; // Are we emulating a Cirrus Maverick co-processor?
  162. bool is_pxa27x; // Are we emulating a Intel PXA27x co-processor?
  163. // ARM_ARM A2-18
  164. // 0 Base Restored Abort Model, 1 the Early Abort Model, 2 Base Updated Abort Model
  165. int abort_model;
  166. // Added by ksh in 2005-10-1
  167. cpu_config_t* cpu;
  168. u32 CurrInstr;
  169. u32 last_pc; // The last PC executed
  170. u32 last_instr; // The last instruction executed
  171. u32 WriteAddr[17];
  172. u32 WriteData[17];
  173. u32 WritePc[17];
  174. u32 CurrWrite;
  175. };
  176. typedef ARMul_State arm_core_t;
  177. /***************************************************************************\
  178. * Types of ARM we know about *
  179. \***************************************************************************/
  180. enum {
  181. ARM_Fix26_Prop = 0x01,
  182. ARM_Nexec_Prop = 0x02,
  183. ARM_Debug_Prop = 0x10,
  184. ARM_Isync_Prop = ARM_Debug_Prop,
  185. ARM_Lock_Prop = 0x20,
  186. ARM_v4_Prop = 0x40,
  187. ARM_v5_Prop = 0x80,
  188. ARM_v6_Prop = 0xc0,
  189. ARM_v5e_Prop = 0x100,
  190. ARM_XScale_Prop = 0x200,
  191. ARM_ep9312_Prop = 0x400,
  192. ARM_iWMMXt_Prop = 0x800,
  193. ARM_PXA27X_Prop = 0x1000,
  194. ARM_v7_Prop = 0x2000,
  195. // ARM2 family
  196. ARM2 = ARM_Fix26_Prop,
  197. ARM2as = ARM2,
  198. ARM61 = ARM2,
  199. ARM3 = ARM2,
  200. // ARM6 family
  201. ARM6 = ARM_Lock_Prop,
  202. ARM60 = ARM6,
  203. ARM600 = ARM6,
  204. ARM610 = ARM6,
  205. ARM620 = ARM6
  206. };
  207. /***************************************************************************\
  208. * The hardware vector addresses *
  209. \***************************************************************************/
  210. enum {
  211. ARMResetV = 0,
  212. ARMUndefinedInstrV = 4,
  213. ARMSWIV = 8,
  214. ARMPrefetchAbortV = 12,
  215. ARMDataAbortV = 16,
  216. ARMAddrExceptnV = 20,
  217. ARMIRQV = 24,
  218. ARMFIQV = 28,
  219. ARMErrorV = 32, // This is an offset, not an address!
  220. ARMul_ResetV = ARMResetV,
  221. ARMul_UndefinedInstrV = ARMUndefinedInstrV,
  222. ARMul_SWIV = ARMSWIV,
  223. ARMul_PrefetchAbortV = ARMPrefetchAbortV,
  224. ARMul_DataAbortV = ARMDataAbortV,
  225. ARMul_AddrExceptnV = ARMAddrExceptnV,
  226. ARMul_IRQV = ARMIRQV,
  227. ARMul_FIQV = ARMFIQV
  228. };
  229. /***************************************************************************\
  230. * Mode and Bank Constants *
  231. \***************************************************************************/
  232. enum {
  233. USER26MODE = 0,
  234. FIQ26MODE = 1,
  235. IRQ26MODE = 2,
  236. SVC26MODE = 3,
  237. USER32MODE = 16,
  238. FIQ32MODE = 17,
  239. IRQ32MODE = 18,
  240. SVC32MODE = 19,
  241. ABORT32MODE = 23,
  242. UNDEF32MODE = 27,
  243. SYSTEM32MODE = 31
  244. };
  245. enum {
  246. USERBANK = 0,
  247. FIQBANK = 1,
  248. IRQBANK = 2,
  249. SVCBANK = 3,
  250. ABORTBANK = 4,
  251. UNDEFBANK = 5,
  252. DUMMYBANK = 6,
  253. SYSTEMBANK = USERBANK
  254. };
  255. /***************************************************************************\
  256. * Definitons of things in the emulator *
  257. \***************************************************************************/
  258. #ifdef __cplusplus
  259. extern "C" {
  260. #endif
  261. extern void ARMul_EmulateInit();
  262. extern void ARMul_Reset(ARMul_State* state);
  263. #ifdef __cplusplus
  264. }
  265. #endif
  266. extern ARMul_State* ARMul_NewState(ARMul_State* state);
  267. /***************************************************************************\
  268. * Definitons of things in the co-processor interface *
  269. \***************************************************************************/
  270. enum {
  271. ARMul_FIRST = 0,
  272. ARMul_TRANSFER = 1,
  273. ARMul_BUSY = 2,
  274. ARMul_DATA = 3,
  275. ARMul_INTERRUPT = 4,
  276. ARMul_DONE = 0,
  277. ARMul_CANT = 1,
  278. ARMul_INC = 3
  279. };
  280. enum {
  281. ARMul_CP13_R0_FIQ = 0x1,
  282. ARMul_CP13_R0_IRQ = 0x2,
  283. ARMul_CP13_R8_PMUS = 0x1,
  284. ARMul_CP14_R0_ENABLE = 0x0001,
  285. ARMul_CP14_R0_CLKRST = 0x0004,
  286. ARMul_CP14_R0_CCD = 0x0008,
  287. ARMul_CP14_R0_INTEN0 = 0x0010,
  288. ARMul_CP14_R0_INTEN1 = 0x0020,
  289. ARMul_CP14_R0_INTEN2 = 0x0040,
  290. ARMul_CP14_R0_FLAG0 = 0x0100,
  291. ARMul_CP14_R0_FLAG1 = 0x0200,
  292. ARMul_CP14_R0_FLAG2 = 0x0400,
  293. ARMul_CP14_R10_MOE_IB = 0x0004,
  294. ARMul_CP14_R10_MOE_DB = 0x0008,
  295. ARMul_CP14_R10_MOE_BT = 0x000c,
  296. ARMul_CP15_R1_ENDIAN = 0x0080,
  297. ARMul_CP15_R1_ALIGN = 0x0002,
  298. ARMul_CP15_R5_X = 0x0400,
  299. ARMul_CP15_R5_ST_ALIGN = 0x0001,
  300. ARMul_CP15_R5_IMPRE = 0x0406,
  301. ARMul_CP15_R5_MMU_EXCPT = 0x0400,
  302. ARMul_CP15_DBCON_M = 0x0100,
  303. ARMul_CP15_DBCON_E1 = 0x000c,
  304. ARMul_CP15_DBCON_E0 = 0x0003
  305. };
  306. /***************************************************************************\
  307. * Definitons of things in the host environment *
  308. \***************************************************************************/
  309. enum ConditionCode {
  310. EQ = 0,
  311. NE = 1,
  312. CS = 2,
  313. CC = 3,
  314. MI = 4,
  315. PL = 5,
  316. VS = 6,
  317. VC = 7,
  318. HI = 8,
  319. LS = 9,
  320. GE = 10,
  321. LT = 11,
  322. GT = 12,
  323. LE = 13,
  324. AL = 14,
  325. NV = 15,
  326. };
  327. extern bool AddOverflow(ARMword, ARMword, ARMword);
  328. extern bool SubOverflow(ARMword, ARMword, ARMword);
  329. extern void ARMul_SelectProcessor(ARMul_State*, unsigned);
  330. extern u32 AddWithCarry(u32, u32, u32, bool*, bool*);
  331. extern bool ARMul_AddOverflowQ(ARMword, ARMword);
  332. extern u8 ARMul_SignedSaturatedAdd8(u8, u8);
  333. extern u8 ARMul_SignedSaturatedSub8(u8, u8);
  334. extern u16 ARMul_SignedSaturatedAdd16(u16, u16);
  335. extern u16 ARMul_SignedSaturatedSub16(u16, u16);
  336. extern u8 ARMul_UnsignedSaturatedAdd8(u8, u8);
  337. extern u16 ARMul_UnsignedSaturatedAdd16(u16, u16);
  338. extern u8 ARMul_UnsignedSaturatedSub8(u8, u8);
  339. extern u16 ARMul_UnsignedSaturatedSub16(u16, u16);
  340. extern u8 ARMul_UnsignedAbsoluteDifference(u8, u8);
  341. extern u32 ARMul_SignedSatQ(s32, u8, bool*);
  342. extern u32 ARMul_UnsignedSatQ(s32, u8, bool*);