armdefs.h 22 KB

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