armdefs.h 17 KB

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