armdefs.h 16 KB

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