armdefs.h 14 KB

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