armdefs.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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 3 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, see <http://www.gnu.org/licenses/>. */
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <stdint.h>
  16. #include <ansidecl.h>
  17. #define FALSE 0
  18. #define TRUE 1
  19. #define LOW 0
  20. #define HIGH 1
  21. #define LOWHIGH 1
  22. #define HIGHLOW 2
  23. typedef uint32_t ARMword;
  24. typedef int32_t ARMsword;
  25. typedef uint64_t ARMdword;
  26. typedef int64_t ARMsdword;
  27. typedef struct ARMul_State ARMul_State;
  28. typedef unsigned ARMul_CPInits (ARMul_State * state);
  29. typedef unsigned ARMul_CPExits (ARMul_State * state);
  30. typedef unsigned ARMul_LDCs (ARMul_State * state, unsigned type,
  31. ARMword instr, ARMword value);
  32. typedef unsigned ARMul_STCs (ARMul_State * state, unsigned type,
  33. ARMword instr, ARMword * value);
  34. typedef unsigned ARMul_MRCs (ARMul_State * state, unsigned type,
  35. ARMword instr, ARMword * value);
  36. typedef unsigned ARMul_MCRs (ARMul_State * state, unsigned type,
  37. ARMword instr, ARMword value);
  38. typedef unsigned ARMul_CDPs (ARMul_State * state, unsigned type,
  39. ARMword instr);
  40. typedef unsigned ARMul_CPReads (ARMul_State * state, unsigned reg,
  41. ARMword * value);
  42. typedef unsigned ARMul_CPWrites (ARMul_State * state, unsigned reg,
  43. ARMword value);
  44. typedef double ARMdval; /* FIXME: Must be a 64-bit floating point type. */
  45. typedef float ARMfval; /* FIXME: Must be a 32-bit floating point type. */
  46. typedef union
  47. {
  48. ARMword uword[2];
  49. ARMsword sword[2];
  50. ARMfval fval[2];
  51. ARMdword dword;
  52. ARMdval dval;
  53. } ARM_VFP_reg;
  54. #define VFP_fval(N) (state->VFP_Reg[(N)>> 1].fval[(N) & 1])
  55. #define VFP_uword(N) (state->VFP_Reg[(N)>> 1].uword[(N) & 1])
  56. #define VFP_sword(N) (state->VFP_Reg[(N)>> 1].sword[(N) & 1])
  57. #define VFP_dval(N) (state->VFP_Reg[(N)].dval)
  58. #define VFP_dword(N) (state->VFP_Reg[(N)].dword)
  59. struct ARMul_State
  60. {
  61. ARMword Emulate; /* to start and stop emulation */
  62. unsigned EndCondition; /* reason for stopping */
  63. ARMword Reg[16]; /* the current register file */
  64. ARMword RegBank[7][16]; /* all the registers */
  65. /* 40 bit accumulator. We always keep this 64 bits wide,
  66. and move only 40 bits out of it in an MRA insn. */
  67. ARMdword Accumulator;
  68. ARMword Cpsr; /* the current psr */
  69. ARMword Spsr[7]; /* the exception psr's */
  70. ARMword NFlag, ZFlag, CFlag, VFlag, IFFlags; /* dummy flags for speed */
  71. ARMword SFlag;
  72. #ifdef MODET
  73. ARMword TFlag; /* Thumb state */
  74. #endif
  75. ARMword Bank; /* the current register bank */
  76. ARMword Mode; /* the current mode */
  77. ARMword instr, pc, temp; /* saved register state */
  78. ARMword loaded, decoded; /* saved pipeline state */
  79. unsigned long NumScycles, NumNcycles, NumIcycles, NumCcycles, NumFcycles; /* emulated cycles used */
  80. unsigned long NumInstrs; /* the number of instructions executed */
  81. unsigned NextInstr;
  82. unsigned VectorCatch; /* caught exception mask */
  83. unsigned CallDebug; /* set to call the debugger */
  84. unsigned CanWatch; /* set by memory interface if its willing to suffer the
  85. overhead of checking for watchpoints on each memory
  86. access */
  87. unsigned MemReadDebug, MemWriteDebug;
  88. unsigned long StopHandle;
  89. unsigned char *MemDataPtr; /* admin data */
  90. unsigned char *MemInPtr; /* the Data In bus */
  91. unsigned char *MemOutPtr; /* the Data Out bus (which you may not need */
  92. unsigned char *MemSparePtr; /* extra space */
  93. ARMword MemSize;
  94. unsigned char *OSptr; /* OS Handle */
  95. char *CommandLine; /* Command Line from ARMsd */
  96. ARMul_CPInits *CPInit[16]; /* coprocessor initialisers */
  97. ARMul_CPExits *CPExit[16]; /* coprocessor finalisers */
  98. ARMul_LDCs *LDC[16]; /* LDC instruction */
  99. ARMul_STCs *STC[16]; /* STC instruction */
  100. ARMul_MRCs *MRC[16]; /* MRC instruction */
  101. ARMul_MCRs *MCR[16]; /* MCR instruction */
  102. ARMul_CDPs *CDP[16]; /* CDP instruction */
  103. ARMul_CPReads *CPRead[16]; /* Read CP register */
  104. ARMul_CPWrites *CPWrite[16]; /* Write CP register */
  105. unsigned char *CPData[16]; /* Coprocessor data */
  106. unsigned char const *CPRegWords[16]; /* map of coprocessor register sizes */
  107. unsigned long LastTime; /* Value of last call to ARMul_Time() */
  108. ARMword CP14R0_CCD; /* used to count 64 clock cycles with CP14 R0 bit
  109. 3 set */
  110. unsigned EventSet; /* the number of events in the queue */
  111. unsigned long Now; /* time to the nearest cycle */
  112. struct EventNode **EventPtr; /* the event list */
  113. unsigned Exception; /* enable the next four values */
  114. unsigned Debug; /* show instructions as they are executed */
  115. unsigned NresetSig; /* reset the processor */
  116. unsigned NfiqSig;
  117. unsigned NirqSig;
  118. unsigned abortSig;
  119. unsigned NtransSig;
  120. unsigned bigendSig;
  121. unsigned prog32Sig;
  122. unsigned data32Sig;
  123. unsigned lateabtSig;
  124. ARMword Vector; /* synthesize aborts in cycle modes */
  125. ARMword Aborted; /* sticky flag for aborts */
  126. ARMword Reseted; /* sticky flag for Reset */
  127. ARMword Inted, LastInted; /* sticky flags for interrupts */
  128. ARMword Base; /* extra hand for base writeback */
  129. ARMword AbortAddr; /* to keep track of Prefetch aborts */
  130. const struct Dbg_HostosInterface *hostif;
  131. unsigned is_v4; /* Are we emulating a v4 architecture (or higher) ? */
  132. unsigned is_v5; /* Are we emulating a v5 architecture ? */
  133. unsigned is_v5e; /* Are we emulating a v5e architecture ? */
  134. unsigned is_v6; /* Are we emulating a v6 architecture ? */
  135. unsigned is_XScale; /* Are we emulating an XScale architecture ? */
  136. unsigned is_iWMMXt; /* Are we emulating an iWMMXt co-processor ? */
  137. unsigned is_ep9312; /* Are we emulating a Cirrus Maverick co-processor ? */
  138. unsigned verbose; /* Print various messages like the banner */
  139. ARM_VFP_reg VFP_Reg[32]; /* Advanced SIMD registers. */
  140. ARMword FPSCR; /* Floating Point Status Register. */
  141. };
  142. /***************************************************************************\
  143. * Properties of ARM we know about *
  144. \***************************************************************************/
  145. /* The bitflags */
  146. #define ARM_Fix26_Prop 0x01
  147. #define ARM_Nexec_Prop 0x02
  148. #define ARM_Debug_Prop 0x10
  149. #define ARM_Isync_Prop ARM_Debug_Prop
  150. #define ARM_Lock_Prop 0x20
  151. #define ARM_v4_Prop 0x40
  152. #define ARM_v5_Prop 0x80
  153. #define ARM_v5e_Prop 0x100
  154. #define ARM_XScale_Prop 0x200
  155. #define ARM_ep9312_Prop 0x400
  156. #define ARM_iWMMXt_Prop 0x800
  157. #define ARM_v6_Prop 0x1000
  158. /***************************************************************************\
  159. * Macros to extract instruction fields *
  160. \***************************************************************************/
  161. #define BIT(n) ( (ARMword)(instr>>(n))&1) /* bit n of instruction */
  162. #define BITS(m,n) ( (ARMword)(instr<<(31-(n))) >> ((31-(n))+(m)) ) /* bits m to n of instr */
  163. #define TOPBITS(n) (instr >> (n)) /* bits 31 to n of instr */
  164. /***************************************************************************\
  165. * The hardware vector addresses *
  166. \***************************************************************************/
  167. #define ARMResetV 0L
  168. #define ARMUndefinedInstrV 4L
  169. #define ARMSWIV 8L
  170. #define ARMPrefetchAbortV 12L
  171. #define ARMDataAbortV 16L
  172. #define ARMAddrExceptnV 20L
  173. #define ARMIRQV 24L
  174. #define ARMFIQV 28L
  175. #define ARMErrorV 32L /* This is an offset, not an address ! */
  176. #define ARMul_ResetV ARMResetV
  177. #define ARMul_UndefinedInstrV ARMUndefinedInstrV
  178. #define ARMul_SWIV ARMSWIV
  179. #define ARMul_PrefetchAbortV ARMPrefetchAbortV
  180. #define ARMul_DataAbortV ARMDataAbortV
  181. #define ARMul_AddrExceptnV ARMAddrExceptnV
  182. #define ARMul_IRQV ARMIRQV
  183. #define ARMul_FIQV ARMFIQV
  184. /***************************************************************************\
  185. * Mode and Bank Constants *
  186. \***************************************************************************/
  187. #define USER26MODE 0L
  188. #define FIQ26MODE 1L
  189. #define IRQ26MODE 2L
  190. #define SVC26MODE 3L
  191. #define USER32MODE 16L
  192. #define FIQ32MODE 17L
  193. #define IRQ32MODE 18L
  194. #define SVC32MODE 19L
  195. #define ABORT32MODE 23L
  196. #define UNDEF32MODE 27L
  197. #define SYSTEMMODE 31L
  198. #define ARM32BITMODE (state->Mode > 3)
  199. #define ARM26BITMODE (state->Mode <= 3)
  200. #define ARMMODE (state->Mode)
  201. #define ARMul_MODEBITS 0x1fL
  202. #define ARMul_MODE32BIT ARM32BITMODE
  203. #define ARMul_MODE26BIT ARM26BITMODE
  204. #define USERBANK 0
  205. #define FIQBANK 1
  206. #define IRQBANK 2
  207. #define SVCBANK 3
  208. #define ABORTBANK 4
  209. #define UNDEFBANK 5
  210. #define DUMMYBANK 6
  211. #define SYSTEMBANK USERBANK
  212. #define BANK_CAN_ACCESS_SPSR(bank) \
  213. ((bank) != USERBANK && (bank) != SYSTEMBANK && (bank) != DUMMYBANK)
  214. /***************************************************************************\
  215. * Definitons of things in the emulator *
  216. \***************************************************************************/
  217. extern void ARMul_EmulateInit (void);
  218. extern ARMul_State *ARMul_NewState (void);
  219. extern void ARMul_Reset (ARMul_State * state);
  220. extern ARMword ARMul_DoProg (ARMul_State * state);
  221. extern ARMword ARMul_DoInstr (ARMul_State * state);
  222. /***************************************************************************\
  223. * Definitons of things for event handling *
  224. \***************************************************************************/
  225. extern void ARMul_ScheduleEvent (ARMul_State * state, unsigned long delay,
  226. unsigned (*func) ());
  227. extern void ARMul_EnvokeEvent (ARMul_State * state);
  228. extern unsigned long ARMul_Time (ARMul_State * state);
  229. /***************************************************************************\
  230. * Useful support routines *
  231. \***************************************************************************/
  232. extern ARMword ARMul_GetReg (ARMul_State * state, unsigned mode,
  233. unsigned reg);
  234. extern void ARMul_SetReg (ARMul_State * state, unsigned mode, unsigned reg,
  235. ARMword value);
  236. extern ARMword ARMul_GetPC (ARMul_State * state);
  237. extern ARMword ARMul_GetNextPC (ARMul_State * state);
  238. extern void ARMul_SetPC (ARMul_State * state, ARMword value);
  239. extern ARMword ARMul_GetR15 (ARMul_State * state);
  240. extern void ARMul_SetR15 (ARMul_State * state, ARMword value);
  241. extern ARMword ARMul_GetCPSR (ARMul_State * state);
  242. extern void ARMul_SetCPSR (ARMul_State * state, ARMword value);
  243. extern ARMword ARMul_GetSPSR (ARMul_State * state, ARMword mode);
  244. extern void ARMul_SetSPSR (ARMul_State * state, ARMword mode, ARMword value);
  245. /***************************************************************************\
  246. * Definitons of things to handle aborts *
  247. \***************************************************************************/
  248. extern void ARMul_Abort (ARMul_State * state, ARMword address);
  249. #define ARMul_ABORTWORD 0xefffffff /* SWI -1 */
  250. #define ARMul_PREFETCHABORT(address) if (state->AbortAddr == 1) \
  251. state->AbortAddr = (address & ~3L)
  252. #define ARMul_DATAABORT(address) state->abortSig = HIGH ; \
  253. state->Aborted = ARMul_DataAbortV ;
  254. #define ARMul_CLEARABORT state->abortSig = LOW
  255. /***************************************************************************\
  256. * Definitons of things in the memory interface *
  257. \***************************************************************************/
  258. extern unsigned ARMul_MemoryInit (ARMul_State * state,
  259. unsigned long initmemsize);
  260. extern void ARMul_MemoryExit (ARMul_State * state);
  261. extern ARMword ARMul_LoadInstrS (ARMul_State * state, ARMword address,
  262. ARMword isize);
  263. extern ARMword ARMul_LoadInstrN (ARMul_State * state, ARMword address,
  264. ARMword isize);
  265. extern ARMword ARMul_ReLoadInstr (ARMul_State * state, ARMword address,
  266. ARMword isize);
  267. extern ARMword ARMul_LoadWordS (ARMul_State * state, ARMword address);
  268. extern ARMword ARMul_LoadWordN (ARMul_State * state, ARMword address);
  269. extern ARMword ARMul_LoadHalfWord (ARMul_State * state, ARMword address);
  270. extern ARMword ARMul_LoadByte (ARMul_State * state, ARMword address);
  271. extern void ARMul_StoreWordS (ARMul_State * state, ARMword address,
  272. ARMword data);
  273. extern void ARMul_StoreWordN (ARMul_State * state, ARMword address,
  274. ARMword data);
  275. extern void ARMul_StoreHalfWord (ARMul_State * state, ARMword address,
  276. ARMword data);
  277. extern void ARMul_StoreByte (ARMul_State * state, ARMword address,
  278. ARMword data);
  279. extern ARMword ARMul_SwapWord (ARMul_State * state, ARMword address,
  280. ARMword data);
  281. extern ARMword ARMul_SwapByte (ARMul_State * state, ARMword address,
  282. ARMword data);
  283. extern void ARMul_Icycles (ARMul_State * state, unsigned number,
  284. ARMword address);
  285. extern void ARMul_Ccycles (ARMul_State * state, unsigned number,
  286. ARMword address);
  287. extern ARMword ARMul_ReadWord (ARMul_State * state, ARMword address);
  288. extern ARMword ARMul_ReadByte (ARMul_State * state, ARMword address);
  289. extern ARMword ARMul_SafeReadByte (ARMul_State * state, ARMword address);
  290. extern void ARMul_WriteWord (ARMul_State * state, ARMword address,
  291. ARMword data);
  292. extern void ARMul_WriteByte (ARMul_State * state, ARMword address,
  293. ARMword data);
  294. extern void ARMul_SafeWriteByte (ARMul_State * state, ARMword address,
  295. ARMword data);
  296. extern ARMword ARMul_MemAccess (ARMul_State * state, ARMword, ARMword,
  297. ARMword, ARMword, ARMword, ARMword, ARMword,
  298. ARMword, ARMword, ARMword);
  299. /***************************************************************************\
  300. * Definitons of things in the co-processor interface *
  301. \***************************************************************************/
  302. #define ARMul_FIRST 0
  303. #define ARMul_TRANSFER 1
  304. #define ARMul_BUSY 2
  305. #define ARMul_DATA 3
  306. #define ARMul_INTERRUPT 4
  307. #define ARMul_DONE 0
  308. #define ARMul_CANT 1
  309. #define ARMul_INC 3
  310. #define ARMul_CP13_R0_FIQ 0x1
  311. #define ARMul_CP13_R0_IRQ 0x2
  312. #define ARMul_CP13_R8_PMUS 0x1
  313. #define ARMul_CP14_R0_ENABLE 0x0001
  314. #define ARMul_CP14_R0_CLKRST 0x0004
  315. #define ARMul_CP14_R0_CCD 0x0008
  316. #define ARMul_CP14_R0_INTEN0 0x0010
  317. #define ARMul_CP14_R0_INTEN1 0x0020
  318. #define ARMul_CP14_R0_INTEN2 0x0040
  319. #define ARMul_CP14_R0_FLAG0 0x0100
  320. #define ARMul_CP14_R0_FLAG1 0x0200
  321. #define ARMul_CP14_R0_FLAG2 0x0400
  322. #define ARMul_CP14_R10_MOE_IB 0x0004
  323. #define ARMul_CP14_R10_MOE_DB 0x0008
  324. #define ARMul_CP14_R10_MOE_BT 0x000c
  325. #define ARMul_CP15_R1_ENDIAN 0x0080
  326. #define ARMul_CP15_R1_ALIGN 0x0002
  327. #define ARMul_CP15_R5_X 0x0400
  328. #define ARMul_CP15_R5_ST_ALIGN 0x0001
  329. #define ARMul_CP15_R5_IMPRE 0x0406
  330. #define ARMul_CP15_R5_MMU_EXCPT 0x0400
  331. #define ARMul_CP15_DBCON_M 0x0100
  332. #define ARMul_CP15_DBCON_E1 0x000c
  333. #define ARMul_CP15_DBCON_E0 0x0003
  334. extern unsigned ARMul_CoProInit (ARMul_State * state);
  335. extern void ARMul_CoProExit (ARMul_State * state);
  336. extern void ARMul_CoProAttach (ARMul_State * state, unsigned number,
  337. ARMul_CPInits * init, ARMul_CPExits * exit,
  338. ARMul_LDCs * ldc, ARMul_STCs * stc,
  339. ARMul_MRCs * mrc, ARMul_MCRs * mcr,
  340. ARMul_CDPs * cdp,
  341. ARMul_CPReads * read, ARMul_CPWrites * write);
  342. extern void ARMul_CoProDetach (ARMul_State * state, unsigned number);
  343. extern void XScale_check_memacc (ARMul_State * state, ARMword * address,
  344. int store);
  345. extern void XScale_set_fsr_far (ARMul_State * state, ARMword fsr, ARMword far);
  346. extern int XScale_debug_moe (ARMul_State * state, int moe);
  347. /***************************************************************************\
  348. * Definitons of things in the host environment *
  349. \***************************************************************************/
  350. extern unsigned ARMul_OSInit (ARMul_State * state);
  351. extern unsigned ARMul_OSHandleSWI (ARMul_State * state, ARMword number);
  352. /***************************************************************************\
  353. * Host-dependent stuff *
  354. \***************************************************************************/
  355. extern void ARMul_UndefInstr (ARMul_State *, ARMword);
  356. extern void ARMul_FixCPSR (ARMul_State *, ARMword, ARMword);
  357. extern void ARMul_FixSPSR (ARMul_State *, ARMword, ARMword);
  358. extern void ARMul_ConsolePrint (ARMul_State *, const char *, ...)
  359. ATTRIBUTE_PRINTF (2, 3);
  360. extern void ARMul_SelectProcessor (ARMul_State *, unsigned);