armdefs.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  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. #ifndef _ARMDEFS_H_
  15. #define _ARMDEFS_H_
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <errno.h>
  19. #include "common/platform.h"
  20. #if EMU_PLATFORM == PLATFORM_WINDOWS
  21. #include <windows.h>
  22. #endif
  23. //teawater add for arm2x86 2005.02.14-------------------------------------------
  24. // koodailar remove it for mingw 2005.12.18----------------
  25. //anthonylee modify it for portable 2007.01.30
  26. //#include "portable/mman.h"
  27. #include "arm_regformat.h"
  28. #include "common/platform.h"
  29. #include "skyeye_defs.h"
  30. //AJ2D--------------------------------------------------------------------------
  31. //teawater add for arm2x86 2005.07.03-------------------------------------------
  32. #include <sys/types.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <string.h>
  36. #if EMU_PLATFORM == PLATFORM_LINUX
  37. #include <unistd.h>
  38. #endif
  39. #include <errno.h>
  40. #include <sys/stat.h>
  41. #include <fcntl.h>
  42. //#include <memory_space.h>
  43. //AJ2D--------------------------------------------------------------------------
  44. #if 0
  45. #if 0
  46. #define DIFF_STATE 1
  47. #define __FOLLOW_MODE__ 0
  48. #else
  49. #define DIFF_STATE 0
  50. #define __FOLLOW_MODE__ 1
  51. #endif
  52. #endif
  53. #ifndef FALSE
  54. #define FALSE 0
  55. #define TRUE 1
  56. #endif
  57. #define LOW 0
  58. #define HIGH 1
  59. #define LOWHIGH 1
  60. #define HIGHLOW 2
  61. #ifndef u8
  62. #define u8 unsigned char
  63. #define u16 unsigned short
  64. #define u32 unsigned int
  65. #define u64 unsigned long long
  66. #endif /*u8 */
  67. //teawater add DBCT_TEST_SPEED 2005.10.04---------------------------------------
  68. #include <signal.h>
  69. #include "common/platform.h"
  70. #if EMU_PLATFORM == PLATFORM_LINUX
  71. #include <sys/time.h>
  72. #endif
  73. //#define DBCT_TEST_SPEED
  74. #define DBCT_TEST_SPEED_SEC 10
  75. //AJ2D--------------------------------------------------------------------------
  76. //teawater add compile switch for DBCT GDB RSP function 2005.10.21--------------
  77. //#define DBCT_GDBRSP
  78. //AJ2D--------------------------------------------------------------------------
  79. //#include <skyeye_defs.h>
  80. //#include <skyeye_types.h>
  81. #define ARM_BYTE_TYPE 0
  82. #define ARM_HALFWORD_TYPE 1
  83. #define ARM_WORD_TYPE 2
  84. //the define of cachetype
  85. #define NONCACHE 0
  86. #define DATACACHE 1
  87. #define INSTCACHE 2
  88. #ifndef __STDC__
  89. typedef char *VoidStar;
  90. #endif
  91. typedef unsigned long long ARMdword; /* must be 64 bits wide */
  92. typedef unsigned int ARMword; /* must be 32 bits wide */
  93. typedef unsigned char ARMbyte; /* must be 8 bits wide */
  94. typedef unsigned short ARMhword; /* must be 16 bits wide */
  95. typedef struct ARMul_State ARMul_State;
  96. typedef struct ARMul_io ARMul_io;
  97. typedef struct ARMul_Energy ARMul_Energy;
  98. //teawater add for arm2x86 2005.06.24-------------------------------------------
  99. #include <stdint.h>
  100. //AJ2D--------------------------------------------------------------------------
  101. /*
  102. //chy 2005-05-11
  103. #ifndef __CYGWIN__
  104. //teawater add for arm2x86 2005.02.14-------------------------------------------
  105. typedef unsigned char uint8_t;
  106. typedef unsigned short uint16_t;
  107. typedef unsigned int u32;
  108. #if defined (__x86_64__)
  109. typedef unsigned long uint64_t;
  110. #else
  111. typedef unsigned long long uint64_t;
  112. #endif
  113. ////AJ2D--------------------------------------------------------------------------
  114. #endif
  115. */
  116. #include "armmmu.h"
  117. //#include "lcd/skyeye_lcd.h"
  118. //#include "skyeye.h"
  119. //#include "skyeye_device.h"
  120. //#include "net/skyeye_net.h"
  121. //#include "skyeye_config.h"
  122. typedef unsigned ARMul_CPInits (ARMul_State * state);
  123. typedef unsigned ARMul_CPExits (ARMul_State * state);
  124. typedef unsigned ARMul_LDCs (ARMul_State * state, unsigned type,
  125. ARMword instr, ARMword value);
  126. typedef unsigned ARMul_STCs (ARMul_State * state, unsigned type,
  127. ARMword instr, ARMword * value);
  128. typedef unsigned ARMul_MRCs (ARMul_State * state, unsigned type,
  129. ARMword instr, ARMword * value);
  130. typedef unsigned ARMul_MCRs (ARMul_State * state, unsigned type,
  131. ARMword instr, ARMword value);
  132. typedef unsigned ARMul_MRRCs (ARMul_State * state, unsigned type,
  133. ARMword instr, ARMword * value1, ARMword * value2);
  134. typedef unsigned ARMul_MCRRs (ARMul_State * state, unsigned type,
  135. ARMword instr, ARMword value1, ARMword value2);
  136. typedef unsigned ARMul_CDPs (ARMul_State * state, unsigned type,
  137. ARMword instr);
  138. typedef unsigned ARMul_CPReads (ARMul_State * state, unsigned reg,
  139. ARMword * value);
  140. typedef unsigned ARMul_CPWrites (ARMul_State * state, unsigned reg,
  141. ARMword value);
  142. //added by ksh,2004-3-5
  143. struct ARMul_io
  144. {
  145. ARMword *instr; //to display the current interrupt state
  146. ARMword *net_flag; //to judge if network is enabled
  147. ARMword *net_int; //netcard interrupt
  148. //ywc,2004-04-01
  149. ARMword *ts_int;
  150. ARMword *ts_is_enable;
  151. ARMword *ts_addr_begin;
  152. ARMword *ts_addr_end;
  153. ARMword *ts_buffer;
  154. };
  155. /* added by ksh,2004-11-26,some energy profiling */
  156. struct ARMul_Energy
  157. {
  158. int energy_prof; /* <tktan> BUG200103282109 : for energy profiling */
  159. int enable_func_energy; /* <tktan> BUG200105181702 */
  160. char *func_energy;
  161. int func_display; /* <tktan> BUG200103311509 : for function call display */
  162. int func_disp_start; /* <tktan> BUG200104191428 : to start func profiling */
  163. char *start_func; /* <tktan> BUG200104191428 */
  164. FILE *outfile; /* <tktan> BUG200105201531 : direct console to file */
  165. long long tcycle, pcycle;
  166. float t_energy;
  167. void *cur_task; /* <tktan> BUG200103291737 */
  168. long long t_mem_cycle, t_idle_cycle, t_uart_cycle;
  169. long long p_mem_cycle, p_idle_cycle, p_uart_cycle;
  170. long long p_io_update_tcycle;
  171. /*record CCCR,to get current core frequency */
  172. ARMword cccr;
  173. };
  174. #if 0
  175. #define MAX_BANK 8
  176. #define MAX_STR 1024
  177. typedef struct mem_bank
  178. {
  179. ARMword (*read_byte) (ARMul_State * state, ARMword addr);
  180. void (*write_byte) (ARMul_State * state, ARMword addr, ARMword data);
  181. ARMword (*read_halfword) (ARMul_State * state, ARMword addr);
  182. void (*write_halfword) (ARMul_State * state, ARMword addr,
  183. ARMword data);
  184. ARMword (*read_word) (ARMul_State * state, ARMword addr);
  185. void (*write_word) (ARMul_State * state, ARMword addr, ARMword data);
  186. unsigned int addr, len;
  187. char filename[MAX_STR];
  188. unsigned type; //chy 2003-09-21: maybe io,ram,rom
  189. } mem_bank_t;
  190. typedef struct
  191. {
  192. int bank_num;
  193. int current_num; /*current num of bank */
  194. mem_bank_t mem_banks[MAX_BANK];
  195. } mem_config_t;
  196. #endif
  197. #define VFP_REG_NUM 64
  198. struct ARMul_State
  199. {
  200. ARMword Emulate; /* to start and stop emulation */
  201. unsigned EndCondition; /* reason for stopping */
  202. unsigned ErrorCode; /* type of illegal instruction */
  203. /* Order of the following register should not be modified */
  204. ARMword Reg[16]; /* the current register file */
  205. ARMword Cpsr; /* the current psr */
  206. ARMword Spsr_copy;
  207. ARMword phys_pc;
  208. ARMword Reg_usr[2];
  209. ARMword Reg_svc[2]; /* R13_SVC R14_SVC */
  210. ARMword Reg_abort[2]; /* R13_ABORT R14_ABORT */
  211. ARMword Reg_undef[2]; /* R13 UNDEF R14 UNDEF */
  212. ARMword Reg_irq[2]; /* R13_IRQ R14_IRQ */
  213. ARMword Reg_firq[7]; /* R8---R14 FIRQ */
  214. ARMword Spsr[7]; /* the exception psr's */
  215. ARMword Mode; /* the current mode */
  216. ARMword Bank; /* the current register bank */
  217. ARMword exclusive_tag;
  218. ARMword exclusive_state;
  219. ARMword exclusive_result;
  220. ARMword CP15[VFP_BASE - CP15_BASE];
  221. ARMword VFP[3]; /* FPSID, FPSCR, and FPEXC */
  222. /* VFPv2 and VFPv3-D16 has 16 doubleword registers (D0-D16 or S0-S31).
  223. VFPv3-D32/ASIMD may have up to 32 doubleword registers (D0-D31),
  224. and only 32 singleword registers are accessible (S0-S31). */
  225. ARMword ExtReg[VFP_REG_NUM];
  226. /* ---- End of the ordered registers ---- */
  227. ARMword RegBank[7][16]; /* all the registers */
  228. //chy:2003-08-19, used in arm xscale
  229. /* 40 bit accumulator. We always keep this 64 bits wide,
  230. and move only 40 bits out of it in an MRA insn. */
  231. ARMdword Accumulator;
  232. ARMword NFlag, ZFlag, CFlag, VFlag, IFFlags; /* dummy flags for speed */
  233. unsigned long long int icounter, debug_icounter, kernel_icounter;
  234. unsigned int shifter_carry_out;
  235. //ARMword translate_pc;
  236. /* add armv6 flags dyf:2010-08-09 */
  237. ARMword GEFlag, EFlag, AFlag, QFlags;
  238. //chy:2003-08-19, used in arm v5e|xscale
  239. ARMword SFlag;
  240. #ifdef MODET
  241. ARMword TFlag; /* Thumb state */
  242. #endif
  243. ARMword instr, pc, temp; /* saved register state */
  244. ARMword loaded, decoded; /* saved pipeline state */
  245. //chy 2006-04-12 for ICE breakpoint
  246. ARMword loaded_addr, decoded_addr; /* saved pipeline state addr*/
  247. unsigned int NumScycles, NumNcycles, NumIcycles, NumCcycles, NumFcycles; /* emulated cycles used */
  248. unsigned long long NumInstrs; /* the number of instructions executed */
  249. unsigned NumInstrsToExecute;
  250. unsigned NextInstr;
  251. unsigned VectorCatch; /* caught exception mask */
  252. unsigned CallDebug; /* set to call the debugger */
  253. unsigned CanWatch; /* set by memory interface if its willing to suffer the
  254. overhead of checking for watchpoints on each memory
  255. access */
  256. unsigned int StopHandle;
  257. char *CommandLine; /* Command Line from ARMsd */
  258. ARMul_CPInits *CPInit[16]; /* coprocessor initialisers */
  259. ARMul_CPExits *CPExit[16]; /* coprocessor finalisers */
  260. ARMul_LDCs *LDC[16]; /* LDC instruction */
  261. ARMul_STCs *STC[16]; /* STC instruction */
  262. ARMul_MRCs *MRC[16]; /* MRC instruction */
  263. ARMul_MCRs *MCR[16]; /* MCR instruction */
  264. ARMul_MRRCs *MRRC[16]; /* MRRC instruction */
  265. ARMul_MCRRs *MCRR[16]; /* MCRR instruction */
  266. ARMul_CDPs *CDP[16]; /* CDP instruction */
  267. ARMul_CPReads *CPRead[16]; /* Read CP register */
  268. ARMul_CPWrites *CPWrite[16]; /* Write CP register */
  269. unsigned char *CPData[16]; /* Coprocessor data */
  270. unsigned char const *CPRegWords[16]; /* map of coprocessor register sizes */
  271. unsigned EventSet; /* the number of events in the queue */
  272. unsigned int Now; /* time to the nearest cycle */
  273. struct EventNode **EventPtr; /* the event list */
  274. unsigned Debug; /* show instructions as they are executed */
  275. unsigned NresetSig; /* reset the processor */
  276. unsigned NfiqSig;
  277. unsigned NirqSig;
  278. unsigned abortSig;
  279. unsigned NtransSig;
  280. unsigned bigendSig;
  281. unsigned prog32Sig;
  282. unsigned data32Sig;
  283. unsigned syscallSig;
  284. /* 2004-05-09 chy
  285. ----------------------------------------------------------
  286. read ARM Architecture Reference Manual
  287. 2.6.5 Data Abort
  288. There are three Abort Model in ARM arch.
  289. Early Abort Model: used in some ARMv3 and earlier implementations. In this
  290. model, base register wirteback occurred for LDC,LDM,STC,STM instructions, and
  291. the base register was unchanged for all other instructions. (oldest)
  292. Base Restored Abort Model: If a Data Abort occurs in an instruction which
  293. specifies base register writeback, the value in the base register is
  294. unchanged. (strongarm, xscale)
  295. Base Updated Abort Model: If a Data Abort occurs in an instruction which
  296. specifies base register writeback, the base register writeback still occurs.
  297. (arm720T)
  298. read PART B
  299. chap2 The System Control Coprocessor CP15
  300. 2.4 Register1:control register
  301. L(bit 6): in some ARMv3 and earlier implementations, the abort model of the
  302. processor could be configured:
  303. 0=early Abort Model Selected(now obsolete)
  304. 1=Late Abort Model selceted(same as Base Updated Abort Model)
  305. on later processors, this bit reads as 1 and ignores writes.
  306. -------------------------------------------------------------
  307. So, if lateabtSig=1, then it means Late Abort Model(Base Updated Abort Model)
  308. if lateabtSig=0, then it means Base Restored Abort Model
  309. */
  310. unsigned lateabtSig;
  311. ARMword Vector; /* synthesize aborts in cycle modes */
  312. ARMword Aborted; /* sticky flag for aborts */
  313. ARMword Reseted; /* sticky flag for Reset */
  314. ARMword Inted, LastInted; /* sticky flags for interrupts */
  315. ARMword Base; /* extra hand for base writeback */
  316. ARMword AbortAddr; /* to keep track of Prefetch aborts */
  317. const struct Dbg_HostosInterface *hostif;
  318. int verbose; /* non-zero means print various messages like the banner */
  319. mmu_state_t mmu;
  320. int mmu_inited;
  321. //mem_state_t mem;
  322. /*remove io_state to skyeye_mach_*.c files */
  323. //io_state_t io;
  324. /* point to a interrupt pending register. now for skyeye-ne2k.c
  325. * later should move somewhere. e.g machine_config_t*/
  326. //chy: 2003-08-11, for different arm core type
  327. unsigned is_v4; /* Are we emulating a v4 architecture (or higher) ? */
  328. unsigned is_v5; /* Are we emulating a v5 architecture ? */
  329. unsigned is_v5e; /* Are we emulating a v5e architecture ? */
  330. unsigned is_v6; /* Are we emulating a v6 architecture ? */
  331. unsigned is_v7; /* Are we emulating a v7 architecture ? */
  332. unsigned is_XScale; /* Are we emulating an XScale architecture ? */
  333. unsigned is_iWMMXt; /* Are we emulating an iWMMXt co-processor ? */
  334. unsigned is_ep9312; /* Are we emulating a Cirrus Maverick co-processor ? */
  335. //chy 2005-09-19
  336. unsigned is_pxa27x; /* Are we emulating a Intel PXA27x co-processor ? */
  337. //chy: seems only used in xscale's CP14
  338. unsigned int LastTime; /* Value of last call to ARMul_Time() */
  339. ARMword CP14R0_CCD; /* used to count 64 clock cycles with CP14 R0 bit 3 set */
  340. //added by ksh:for handle different machs io 2004-3-5
  341. ARMul_io mach_io;
  342. /*added by ksh,2004-11-26,some energy profiling*/
  343. ARMul_Energy energy;
  344. //teawater add for next_dis 2004.10.27-----------------------
  345. int disassemble;
  346. //AJ2D------------------------------------------
  347. //teawater add for arm2x86 2005.02.15-------------------------------------------
  348. u32 trap;
  349. u32 tea_break_addr;
  350. u32 tea_break_ok;
  351. int tea_pc;
  352. //AJ2D--------------------------------------------------------------------------
  353. //teawater add for arm2x86 2005.07.03-------------------------------------------
  354. /*
  355. * 2007-01-24 removed the term-io functions by Anthony Lee,
  356. * moved to "device/uart/skyeye_uart_stdio.c".
  357. */
  358. //AJ2D--------------------------------------------------------------------------
  359. //teawater add for arm2x86 2005.07.05-------------------------------------------
  360. //arm_arm A2-18
  361. int abort_model; //0 Base Restored Abort Model, 1 the Early Abort Model, 2 Base Updated Abort Model
  362. //AJ2D--------------------------------------------------------------------------
  363. //teawater change for return if running tb dirty 2005.07.09---------------------
  364. void *tb_now;
  365. //AJ2D--------------------------------------------------------------------------
  366. //teawater add for record reg value to ./reg.txt 2005.07.10---------------------
  367. FILE *tea_reg_fd;
  368. //AJ2D--------------------------------------------------------------------------
  369. /*added by ksh in 2005-10-1*/
  370. cpu_config_t *cpu;
  371. //mem_config_t *mem_bank;
  372. /* added LPC remap function */
  373. int vector_remap_flag;
  374. u32 vector_remap_addr;
  375. u32 vector_remap_size;
  376. u32 step;
  377. u32 cycle;
  378. int stop_simulator;
  379. conf_object_t *dyncom_cpu;
  380. //teawater add DBCT_TEST_SPEED 2005.10.04---------------------------------------
  381. #ifdef DBCT_TEST_SPEED
  382. uint64_t instr_count;
  383. #endif //DBCT_TEST_SPEED
  384. // FILE * state_log;
  385. //diff log
  386. //#if DIFF_STATE
  387. FILE * state_log;
  388. //#endif
  389. /* monitored memory for exclusice access */
  390. ARMword exclusive_tag_array[128];
  391. /* 1 means exclusive access and 0 means open access */
  392. ARMword exclusive_access_state;
  393. memory_space_intf space;
  394. u32 CurrInstr;
  395. u32 last_pc; /* the last pc executed */
  396. u32 last_instr; /* the last inst executed */
  397. u32 WriteAddr[17];
  398. u32 WriteData[17];
  399. u32 WritePc[17];
  400. u32 CurrWrite;
  401. };
  402. #define DIFF_WRITE 0
  403. typedef ARMul_State arm_core_t;
  404. #define ResetPin NresetSig
  405. #define FIQPin NfiqSig
  406. #define IRQPin NirqSig
  407. #define AbortPin abortSig
  408. #define TransPin NtransSig
  409. #define BigEndPin bigendSig
  410. #define Prog32Pin prog32Sig
  411. #define Data32Pin data32Sig
  412. #define LateAbortPin lateabtSig
  413. /***************************************************************************\
  414. * Types of ARM we know about *
  415. \***************************************************************************/
  416. /* The bitflags */
  417. #define ARM_Fix26_Prop 0x01
  418. #define ARM_Nexec_Prop 0x02
  419. #define ARM_Debug_Prop 0x10
  420. #define ARM_Isync_Prop ARM_Debug_Prop
  421. #define ARM_Lock_Prop 0x20
  422. //chy 2003-08-11
  423. #define ARM_v4_Prop 0x40
  424. #define ARM_v5_Prop 0x80
  425. /*jeff.du 2010-08-05 */
  426. #define ARM_v6_Prop 0xc0
  427. #define ARM_v5e_Prop 0x100
  428. #define ARM_XScale_Prop 0x200
  429. #define ARM_ep9312_Prop 0x400
  430. #define ARM_iWMMXt_Prop 0x800
  431. //chy 2005-09-19
  432. #define ARM_PXA27X_Prop 0x1000
  433. #define ARM_v7_Prop 0x2000
  434. /* ARM2 family */
  435. #define ARM2 (ARM_Fix26_Prop)
  436. #define ARM2as ARM2
  437. #define ARM61 ARM2
  438. #define ARM3 ARM2
  439. #ifdef ARM60 /* previous definition in armopts.h */
  440. #undef ARM60
  441. #endif
  442. /* ARM6 family */
  443. #define ARM6 (ARM_Lock_Prop)
  444. #define ARM60 ARM6
  445. #define ARM600 ARM6
  446. #define ARM610 ARM6
  447. #define ARM620 ARM6
  448. /***************************************************************************\
  449. * Macros to extract instruction fields *
  450. \***************************************************************************/
  451. #define BIT(n) ( (ARMword)(instr>>(n))&1) /* bit n of instruction */
  452. #define BITS(m,n) ( (ARMword)(instr<<(31-(n))) >> ((31-(n))+(m)) ) /* bits m to n of instr */
  453. #define TOPBITS(n) (instr >> (n)) /* bits 31 to n of instr */
  454. /***************************************************************************\
  455. * The hardware vector addresses *
  456. \***************************************************************************/
  457. #define ARMResetV 0L
  458. #define ARMUndefinedInstrV 4L
  459. #define ARMSWIV 8L
  460. #define ARMPrefetchAbortV 12L
  461. #define ARMDataAbortV 16L
  462. #define ARMAddrExceptnV 20L
  463. #define ARMIRQV 24L
  464. #define ARMFIQV 28L
  465. #define ARMErrorV 32L /* This is an offset, not an address ! */
  466. #define ARMul_ResetV ARMResetV
  467. #define ARMul_UndefinedInstrV ARMUndefinedInstrV
  468. #define ARMul_SWIV ARMSWIV
  469. #define ARMul_PrefetchAbortV ARMPrefetchAbortV
  470. #define ARMul_DataAbortV ARMDataAbortV
  471. #define ARMul_AddrExceptnV ARMAddrExceptnV
  472. #define ARMul_IRQV ARMIRQV
  473. #define ARMul_FIQV ARMFIQV
  474. /***************************************************************************\
  475. * Mode and Bank Constants *
  476. \***************************************************************************/
  477. #define USER26MODE 0L
  478. #define FIQ26MODE 1L
  479. #define IRQ26MODE 2L
  480. #define SVC26MODE 3L
  481. #define USER32MODE 16L
  482. #define FIQ32MODE 17L
  483. #define IRQ32MODE 18L
  484. #define SVC32MODE 19L
  485. #define ABORT32MODE 23L
  486. #define UNDEF32MODE 27L
  487. //chy 2006-02-15 add system32 mode
  488. #define SYSTEM32MODE 31L
  489. #define ARM32BITMODE (state->Mode > 3)
  490. #define ARM26BITMODE (state->Mode <= 3)
  491. #define ARMMODE (state->Mode)
  492. #define ARMul_MODEBITS 0x1fL
  493. #define ARMul_MODE32BIT ARM32BITMODE
  494. #define ARMul_MODE26BIT ARM26BITMODE
  495. #define USERBANK 0
  496. #define FIQBANK 1
  497. #define IRQBANK 2
  498. #define SVCBANK 3
  499. #define ABORTBANK 4
  500. #define UNDEFBANK 5
  501. #define DUMMYBANK 6
  502. #define SYSTEMBANK USERBANK
  503. #define BANK_CAN_ACCESS_SPSR(bank) \
  504. ((bank) != USERBANK && (bank) != SYSTEMBANK && (bank) != DUMMYBANK)
  505. /***************************************************************************\
  506. * Definitons of things in the emulator *
  507. \***************************************************************************/
  508. #ifdef __cplusplus
  509. extern "C" {
  510. #endif
  511. extern void ARMul_EmulateInit (void);
  512. extern void ARMul_Reset (ARMul_State * state);
  513. #ifdef __cplusplus
  514. }
  515. #endif
  516. extern ARMul_State *ARMul_NewState (ARMul_State * state);
  517. extern ARMword ARMul_DoProg (ARMul_State * state);
  518. extern ARMword ARMul_DoInstr (ARMul_State * state);
  519. /***************************************************************************\
  520. * Definitons of things for event handling *
  521. \***************************************************************************/
  522. extern void ARMul_ScheduleEvent (ARMul_State * state, unsigned int delay,
  523. unsigned (*func) ());
  524. extern void ARMul_EnvokeEvent (ARMul_State * state);
  525. extern unsigned int ARMul_Time (ARMul_State * state);
  526. /***************************************************************************\
  527. * Useful support routines *
  528. \***************************************************************************/
  529. extern ARMword ARMul_GetReg (ARMul_State * state, unsigned mode,
  530. unsigned reg);
  531. extern void ARMul_SetReg (ARMul_State * state, unsigned mode, unsigned reg,
  532. ARMword value);
  533. extern ARMword ARMul_GetPC (ARMul_State * state);
  534. extern ARMword ARMul_GetNextPC (ARMul_State * state);
  535. extern void ARMul_SetPC (ARMul_State * state, ARMword value);
  536. extern ARMword ARMul_GetR15 (ARMul_State * state);
  537. extern void ARMul_SetR15 (ARMul_State * state, ARMword value);
  538. extern ARMword ARMul_GetCPSR (ARMul_State * state);
  539. extern void ARMul_SetCPSR (ARMul_State * state, ARMword value);
  540. extern ARMword ARMul_GetSPSR (ARMul_State * state, ARMword mode);
  541. extern void ARMul_SetSPSR (ARMul_State * state, ARMword mode, ARMword value);
  542. /***************************************************************************\
  543. * Definitons of things to handle aborts *
  544. \***************************************************************************/
  545. extern void ARMul_Abort (ARMul_State * state, ARMword address);
  546. #ifdef MODET
  547. #define ARMul_ABORTWORD (state->TFlag ? 0xefffdfff : 0xefffffff) /* SWI -1 */
  548. #define ARMul_PREFETCHABORT(address) if (state->AbortAddr == 1) \
  549. state->AbortAddr = (address & (state->TFlag ? ~1L : ~3L))
  550. #else
  551. #define ARMul_ABORTWORD 0xefffffff /* SWI -1 */
  552. #define ARMul_PREFETCHABORT(address) if (state->AbortAddr == 1) \
  553. state->AbortAddr = (address & ~3L)
  554. #endif
  555. #define ARMul_DATAABORT(address) state->abortSig = HIGH ; \
  556. state->Aborted = ARMul_DataAbortV ;
  557. #define ARMul_CLEARABORT state->abortSig = LOW
  558. /***************************************************************************\
  559. * Definitons of things in the memory interface *
  560. \***************************************************************************/
  561. extern unsigned ARMul_MemoryInit (ARMul_State * state,
  562. unsigned int initmemsize);
  563. extern void ARMul_MemoryExit (ARMul_State * state);
  564. extern ARMword ARMul_LoadInstrS (ARMul_State * state, ARMword address,
  565. ARMword isize);
  566. extern ARMword ARMul_LoadInstrN (ARMul_State * state, ARMword address,
  567. ARMword isize);
  568. #ifdef __cplusplus
  569. extern "C" {
  570. #endif
  571. extern ARMword ARMul_ReLoadInstr (ARMul_State * state, ARMword address,
  572. ARMword isize);
  573. #ifdef __cplusplus
  574. }
  575. #endif
  576. extern ARMword ARMul_LoadWordS (ARMul_State * state, ARMword address);
  577. extern ARMword ARMul_LoadWordN (ARMul_State * state, ARMword address);
  578. extern ARMword ARMul_LoadHalfWord (ARMul_State * state, ARMword address);
  579. extern ARMword ARMul_LoadByte (ARMul_State * state, ARMword address);
  580. extern void ARMul_StoreWordS (ARMul_State * state, ARMword address,
  581. ARMword data);
  582. extern void ARMul_StoreWordN (ARMul_State * state, ARMword address,
  583. ARMword data);
  584. extern void ARMul_StoreHalfWord (ARMul_State * state, ARMword address,
  585. ARMword data);
  586. extern void ARMul_StoreByte (ARMul_State * state, ARMword address,
  587. ARMword data);
  588. extern ARMword ARMul_SwapWord (ARMul_State * state, ARMword address,
  589. ARMword data);
  590. extern ARMword ARMul_SwapByte (ARMul_State * state, ARMword address,
  591. ARMword data);
  592. extern void ARMul_Icycles (ARMul_State * state, unsigned number,
  593. ARMword address);
  594. extern void ARMul_Ccycles (ARMul_State * state, unsigned number,
  595. ARMword address);
  596. extern ARMword ARMul_ReadWord (ARMul_State * state, ARMword address);
  597. extern ARMword ARMul_ReadByte (ARMul_State * state, ARMword address);
  598. extern void ARMul_WriteWord (ARMul_State * state, ARMword address,
  599. ARMword data);
  600. extern void ARMul_WriteByte (ARMul_State * state, ARMword address,
  601. ARMword data);
  602. extern ARMword ARMul_MemAccess (ARMul_State * state, ARMword, ARMword,
  603. ARMword, ARMword, ARMword, ARMword, ARMword,
  604. ARMword, ARMword, ARMword);
  605. /***************************************************************************\
  606. * Definitons of things in the co-processor interface *
  607. \***************************************************************************/
  608. #define ARMul_FIRST 0
  609. #define ARMul_TRANSFER 1
  610. #define ARMul_BUSY 2
  611. #define ARMul_DATA 3
  612. #define ARMul_INTERRUPT 4
  613. #define ARMul_DONE 0
  614. #define ARMul_CANT 1
  615. #define ARMul_INC 3
  616. #define ARMul_CP13_R0_FIQ 0x1
  617. #define ARMul_CP13_R0_IRQ 0x2
  618. #define ARMul_CP13_R8_PMUS 0x1
  619. #define ARMul_CP14_R0_ENABLE 0x0001
  620. #define ARMul_CP14_R0_CLKRST 0x0004
  621. #define ARMul_CP14_R0_CCD 0x0008
  622. #define ARMul_CP14_R0_INTEN0 0x0010
  623. #define ARMul_CP14_R0_INTEN1 0x0020
  624. #define ARMul_CP14_R0_INTEN2 0x0040
  625. #define ARMul_CP14_R0_FLAG0 0x0100
  626. #define ARMul_CP14_R0_FLAG1 0x0200
  627. #define ARMul_CP14_R0_FLAG2 0x0400
  628. #define ARMul_CP14_R10_MOE_IB 0x0004
  629. #define ARMul_CP14_R10_MOE_DB 0x0008
  630. #define ARMul_CP14_R10_MOE_BT 0x000c
  631. #define ARMul_CP15_R1_ENDIAN 0x0080
  632. #define ARMul_CP15_R1_ALIGN 0x0002
  633. #define ARMul_CP15_R5_X 0x0400
  634. #define ARMul_CP15_R5_ST_ALIGN 0x0001
  635. #define ARMul_CP15_R5_IMPRE 0x0406
  636. #define ARMul_CP15_R5_MMU_EXCPT 0x0400
  637. #define ARMul_CP15_DBCON_M 0x0100
  638. #define ARMul_CP15_DBCON_E1 0x000c
  639. #define ARMul_CP15_DBCON_E0 0x0003
  640. extern unsigned ARMul_CoProInit (ARMul_State * state);
  641. extern void ARMul_CoProExit (ARMul_State * state);
  642. extern void ARMul_CoProAttach (ARMul_State * state, unsigned number,
  643. ARMul_CPInits * init, ARMul_CPExits * exit,
  644. ARMul_LDCs * ldc, ARMul_STCs * stc,
  645. ARMul_MRCs * mrc, ARMul_MCRs * mcr,
  646. ARMul_MRRCs * mrrc, ARMul_MCRRs * mcrr,
  647. ARMul_CDPs * cdp,
  648. ARMul_CPReads * read, ARMul_CPWrites * write);
  649. extern void ARMul_CoProDetach (ARMul_State * state, unsigned number);
  650. /***************************************************************************\
  651. * Definitons of things in the host environment *
  652. \***************************************************************************/
  653. extern unsigned ARMul_OSInit (ARMul_State * state);
  654. extern void ARMul_OSExit (ARMul_State * state);
  655. #ifdef __cplusplus
  656. extern "C" {
  657. #endif
  658. extern unsigned ARMul_OSHandleSWI (ARMul_State * state, ARMword number);
  659. #ifdef __cplusplus
  660. }
  661. #endif
  662. extern ARMword ARMul_OSLastErrorP (ARMul_State * state);
  663. extern ARMword ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr);
  664. extern unsigned ARMul_OSException (ARMul_State * state, ARMword vector,
  665. ARMword pc);
  666. extern int rdi_log;
  667. /***************************************************************************\
  668. * Host-dependent stuff *
  669. \***************************************************************************/
  670. #ifdef macintosh
  671. pascal void SpinCursor (short increment); /* copied from CursorCtl.h */
  672. # define HOURGLASS SpinCursor( 1 )
  673. # define HOURGLASS_RATE 1023 /* 2^n - 1 */
  674. #endif
  675. //teawater add for arm2x86 2005.02.14-------------------------------------------
  676. /*ywc 2005-03-31*/
  677. /*
  678. #include "arm2x86.h"
  679. #include "arm2x86_dp.h"
  680. #include "arm2x86_movl.h"
  681. #include "arm2x86_psr.h"
  682. #include "arm2x86_shift.h"
  683. #include "arm2x86_mem.h"
  684. #include "arm2x86_mul.h"
  685. #include "arm2x86_test.h"
  686. #include "arm2x86_other.h"
  687. #include "list.h"
  688. #include "tb.h"
  689. */
  690. #define EQ 0
  691. #define NE 1
  692. #define CS 2
  693. #define CC 3
  694. #define MI 4
  695. #define PL 5
  696. #define VS 6
  697. #define VC 7
  698. #define HI 8
  699. #define LS 9
  700. #define GE 10
  701. #define LT 11
  702. #define GT 12
  703. #define LE 13
  704. #define AL 14
  705. #define NV 15
  706. #ifndef NFLAG
  707. #define NFLAG state->NFlag
  708. #endif //NFLAG
  709. #ifndef ZFLAG
  710. #define ZFLAG state->ZFlag
  711. #endif //ZFLAG
  712. #ifndef CFLAG
  713. #define CFLAG state->CFlag
  714. #endif //CFLAG
  715. #ifndef VFLAG
  716. #define VFLAG state->VFlag
  717. #endif //VFLAG
  718. #ifndef IFLAG
  719. #define IFLAG (state->IFFlags >> 1)
  720. #endif //IFLAG
  721. #ifndef FFLAG
  722. #define FFLAG (state->IFFlags & 1)
  723. #endif //FFLAG
  724. #ifndef IFFLAGS
  725. #define IFFLAGS state->IFFlags
  726. #endif //VFLAG
  727. #define FLAG_MASK 0xf0000000
  728. #define NBIT_SHIFT 31
  729. #define ZBIT_SHIFT 30
  730. #define CBIT_SHIFT 29
  731. #define VBIT_SHIFT 28
  732. #ifdef DBCT
  733. //teawater change for local tb branch directly jump 2005.10.18------------------
  734. #include "dbct/list.h"
  735. #include "dbct/arm2x86.h"
  736. #include "dbct/arm2x86_dp.h"
  737. #include "dbct/arm2x86_movl.h"
  738. #include "dbct/arm2x86_psr.h"
  739. #include "dbct/arm2x86_shift.h"
  740. #include "dbct/arm2x86_mem.h"
  741. #include "dbct/arm2x86_mul.h"
  742. #include "dbct/arm2x86_test.h"
  743. #include "dbct/arm2x86_other.h"
  744. #include "dbct/arm2x86_coproc.h"
  745. #include "dbct/tb.h"
  746. #endif
  747. //AJ2D--------------------------------------------------------------------------
  748. //AJ2D--------------------------------------------------------------------------
  749. #define SKYEYE_OUTREGS(fd) { fprintf ((fd), "R %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,C %x,S %x,%x,%x,%x,%x,%x,%x,M %x,B %x,E %x,I %x,P %x,T %x,L %x,D %x,",\
  750. state->Reg[0],state->Reg[1],state->Reg[2],state->Reg[3], \
  751. state->Reg[4],state->Reg[5],state->Reg[6],state->Reg[7], \
  752. state->Reg[8],state->Reg[9],state->Reg[10],state->Reg[11], \
  753. state->Reg[12],state->Reg[13],state->Reg[14],state->Reg[15], \
  754. state->Cpsr, state->Spsr[0], state->Spsr[1], state->Spsr[2],\
  755. state->Spsr[3],state->Spsr[4], state->Spsr[5], state->Spsr[6],\
  756. state->Mode,state->Bank,state->ErrorCode,state->instr,state->pc,\
  757. state->temp,state->loaded,state->decoded);}
  758. #define SKYEYE_OUTMOREREGS(fd) { fprintf ((fd),"\
  759. RUs %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,\
  760. RF %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,\
  761. RI %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,\
  762. RS %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,\
  763. RA %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,\
  764. RUn %x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x\n",\
  765. state->RegBank[0][0],state->RegBank[0][1],state->RegBank[0][2],state->RegBank[0][3], \
  766. state->RegBank[0][4],state->RegBank[0][5],state->RegBank[0][6],state->RegBank[0][7], \
  767. state->RegBank[0][8],state->RegBank[0][9],state->RegBank[0][10],state->RegBank[0][11], \
  768. state->RegBank[0][12],state->RegBank[0][13],state->RegBank[0][14],state->RegBank[0][15], \
  769. state->RegBank[1][0],state->RegBank[1][1],state->RegBank[1][2],state->RegBank[1][3], \
  770. state->RegBank[1][4],state->RegBank[1][5],state->RegBank[1][6],state->RegBank[1][7], \
  771. state->RegBank[1][8],state->RegBank[1][9],state->RegBank[1][10],state->RegBank[1][11], \
  772. state->RegBank[1][12],state->RegBank[1][13],state->RegBank[1][14],state->RegBank[1][15], \
  773. state->RegBank[2][0],state->RegBank[2][1],state->RegBank[2][2],state->RegBank[2][3], \
  774. state->RegBank[2][4],state->RegBank[2][5],state->RegBank[2][6],state->RegBank[2][7], \
  775. state->RegBank[2][8],state->RegBank[2][9],state->RegBank[2][10],state->RegBank[2][11], \
  776. state->RegBank[2][12],state->RegBank[2][13],state->RegBank[2][14],state->RegBank[2][15], \
  777. state->RegBank[3][0],state->RegBank[3][1],state->RegBank[3][2],state->RegBank[3][3], \
  778. state->RegBank[3][4],state->RegBank[3][5],state->RegBank[3][6],state->RegBank[3][7], \
  779. state->RegBank[3][8],state->RegBank[3][9],state->RegBank[3][10],state->RegBank[3][11], \
  780. state->RegBank[3][12],state->RegBank[3][13],state->RegBank[3][14],state->RegBank[3][15], \
  781. state->RegBank[4][0],state->RegBank[4][1],state->RegBank[4][2],state->RegBank[4][3], \
  782. state->RegBank[4][4],state->RegBank[4][5],state->RegBank[4][6],state->RegBank[4][7], \
  783. state->RegBank[4][8],state->RegBank[4][9],state->RegBank[4][10],state->RegBank[4][11], \
  784. state->RegBank[4][12],state->RegBank[4][13],state->RegBank[4][14],state->RegBank[4][15], \
  785. state->RegBank[5][0],state->RegBank[5][1],state->RegBank[5][2],state->RegBank[5][3], \
  786. state->RegBank[5][4],state->RegBank[5][5],state->RegBank[5][6],state->RegBank[5][7], \
  787. state->RegBank[5][8],state->RegBank[5][9],state->RegBank[5][10],state->RegBank[5][11], \
  788. state->RegBank[5][12],state->RegBank[5][13],state->RegBank[5][14],state->RegBank[5][15] \
  789. );}
  790. #define SA1110 0x6901b110
  791. #define SA1100 0x4401a100
  792. #define PXA250 0x69052100
  793. #define PXA270 0x69054110
  794. //#define PXA250 0x69052903
  795. // 0x69052903; //PXA250 B1 from intel 278522-001.pdf
  796. extern void ARMul_UndefInstr (ARMul_State *, ARMword);
  797. extern void ARMul_FixCPSR (ARMul_State *, ARMword, ARMword);
  798. extern void ARMul_FixSPSR (ARMul_State *, ARMword, ARMword);
  799. extern void ARMul_ConsolePrint (ARMul_State *, const char *, ...);
  800. extern void ARMul_SelectProcessor (ARMul_State *, unsigned);
  801. #define DIFF_LOG 0
  802. #define SAVE_LOG 0
  803. #endif /* _ARMDEFS_H_ */