home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gdb-4.16-base.tgz / gdb-4.16-base.tar / fsf / gdb / sim / arm / armdefs.h < prev    next >
C/C++ Source or Header  |  1995-11-17  |  14KB  |  344 lines

  1. /*  armdefs.h -- ARMulator common definitions:  ARM6 Instruction Emulator.
  2.     Copyright (C) 1994 Advanced RISC Machines Ltd.
  3.  
  4.     This program is free software; you can redistribute it and/or modify
  5.     it under the terms of the GNU General Public License as published by
  6.     the Free Software Foundation; either version 2 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU General Public License
  15.     along with this program; if not, write to the Free Software
  16.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #define FALSE 0
  22. #define TRUE 1
  23. #define LOW 0
  24. #define HIGH 1
  25. #define LOWHIGH 1
  26. #define HIGHLOW 2
  27.  
  28. #ifndef __STDC__
  29. typedef char * VoidStar ;
  30. #endif
  31.  
  32. typedef unsigned long ARMword ; /* must be 32 bits wide */
  33.  
  34. typedef struct ARMul_State ARMul_State ;
  35.  
  36. typedef unsigned ARMul_CPInits(ARMul_State *state) ;
  37. typedef unsigned ARMul_CPExits(ARMul_State *state) ;
  38. typedef unsigned ARMul_LDCs(ARMul_State *state,unsigned type,ARMword instr,ARMword value) ;
  39. typedef unsigned ARMul_STCs(ARMul_State *state,unsigned type,ARMword instr,ARMword *value) ;
  40. typedef unsigned ARMul_MRCs(ARMul_State *state,unsigned type,ARMword instr,ARMword *value) ;
  41. typedef unsigned ARMul_MCRs(ARMul_State *state,unsigned type,ARMword instr,ARMword value) ;
  42. typedef unsigned ARMul_CDPs(ARMul_State *state,unsigned type,ARMword instr) ;
  43. typedef unsigned ARMul_CPReads(ARMul_State *state,unsigned reg,ARMword *value) ;
  44. typedef unsigned ARMul_CPWrites(ARMul_State *state,unsigned reg,ARMword value) ;
  45.  
  46. struct ARMul_State {
  47.    ARMword Emulate ; /* to start and stop emulation */
  48.    unsigned EndCondition ; /* reason for stopping */
  49.    unsigned ErrorCode ; /* type of illegal instruction */
  50.    ARMword Reg[16] ; /* the current register file */
  51.    ARMword RegBank[7][16] ; /* all the registers */
  52.    ARMword Cpsr ; /* the current psr */
  53.    ARMword Spsr[7] ; /* the exception psr's */
  54.    ARMword NFlag, ZFlag, CFlag, VFlag, IFFlags ; /* dummy flags for speed */
  55.    ARMword Bank ; /* the current register bank */
  56.    ARMword Mode ; /* the current mode */
  57.    ARMword instr, pc, temp ; /* saved register state */
  58.    ARMword loaded, decoded ; /* saved pipeline state */
  59.    unsigned long NumScycles,
  60.                  NumNcycles,
  61.                  NumIcycles,
  62.                  NumCcycles,
  63.                  NumFcycles ; /* emulated cycles used */
  64.    unsigned long NumInstrs ; /* the number of instructions executed */
  65.    unsigned NextInstr ;
  66.    unsigned VectorCatch ; /* caught exception mask */
  67.    unsigned CallDebug ; /* set to call the debugger */
  68.    unsigned CanWatch ; /* set by memory interface if its willing to suffer the
  69.               overhead of checking for watchpoints on each memory
  70.               access */
  71.    unsigned MemReadDebug, MemWriteDebug ;
  72.    unsigned long StopHandle ;
  73.  
  74.    unsigned char *MemDataPtr ; /* admin data */
  75.    unsigned char *MemInPtr ; /* the Data In bus */
  76.    unsigned char *MemOutPtr ; /* the Data Out bus (which you may not need */
  77.    unsigned char *MemSparePtr ; /* extra space */
  78.    ARMword MemSize ;
  79.  
  80.    unsigned char *OSptr ; /* OS Handle */
  81.    char *CommandLine ; /* Command Line from ARMsd */
  82.  
  83.    ARMul_CPInits *CPInit[16] ; /* coprocessor initialisers */
  84.    ARMul_CPExits *CPExit[16] ; /* coprocessor finalisers */
  85.    ARMul_LDCs *LDC[16] ; /* LDC instruction */
  86.    ARMul_STCs *STC[16] ; /* STC instruction */
  87.    ARMul_MRCs *MRC[16] ; /* MRC instruction */
  88.    ARMul_MCRs *MCR[16] ; /* MCR instruction */
  89.    ARMul_CDPs *CDP[16] ; /* CDP instruction */
  90.    ARMul_CPReads *CPRead[16] ; /* Read CP register */
  91.    ARMul_CPWrites *CPWrite[16] ; /* Write CP register */
  92.    unsigned char *CPData[16] ; /* Coprocessor data */
  93.    unsigned char const *CPRegWords[16] ;  /* map of coprocessor register sizes */
  94.  
  95.    unsigned EventSet ; /* the number of events in the queue */
  96.    unsigned long Now ; /* time to the nearest cycle */
  97.    struct EventNode **EventPtr ; /* the event list */
  98.  
  99.    unsigned Exception ; /* enable the next four values */
  100.    unsigned Debug ; /* show instructions as they are executed */
  101.    unsigned NresetSig ; /* reset the processor */
  102.    unsigned NfiqSig ;
  103.    unsigned NirqSig ;
  104.  
  105.    unsigned abortSig ;
  106.    unsigned NtransSig ;
  107.    unsigned bigendSig ;
  108.    unsigned prog32Sig ;
  109.    unsigned data32Sig ;
  110.    unsigned lateabtSig ;
  111.    ARMword Vector ; /* synthesize aborts in cycle modes */
  112.    ARMword Aborted ; /* sticky flag for aborts */
  113.    ARMword Reseted ; /* sticky flag for Reset */
  114.    ARMword Inted, LastInted ; /* sticky flags for interrupts */
  115.    ARMword Base ; /* extra hand for base writeback */
  116.    ARMword AbortAddr ; /* to keep track of Prefetch aborts */
  117.  
  118.    const struct Dbg_HostosInterface *hostif;
  119.  
  120.    int verbose; /* non-zero means print various messages like the banner */
  121.  } ;
  122.  
  123. #define ResetPin NresetSig
  124. #define FIQPin NfiqSig
  125. #define IRQPin NirqSig
  126. #define AbortPin abortSig
  127. #define TransPin NtransSig
  128. #define BigEndPin bigendSig
  129. #define Prog32Pin prog32Sig
  130. #define Data32Pin data32Sig
  131. #define LateAbortPin lateabtSig
  132.  
  133. /***************************************************************************\
  134. *                        Types of ARM we know about                         *
  135. \***************************************************************************/
  136.  
  137. /* The bitflags */
  138. #define ARM_Fix26_Prop   0x01
  139. #define ARM_Nexec_Prop   0x02
  140. #define ARM_Debug_Prop   0x10
  141. #define ARM_Isync_Prop   ARM_Debug_Prop
  142. #define ARM_Lock_Prop    0x20
  143.  
  144. /* ARM2 family */
  145. #define ARM2    (ARM_Fix26_Prop)
  146. #define ARM2as  ARM2
  147. #define ARM61   ARM2
  148. #define ARM3    ARM2
  149.  
  150. /* ARM6 family */
  151. #define ARM6    (ARM_Lock_Prop)
  152. #define ARM60   ARM6
  153. #define ARM600  ARM6
  154. #define ARM610  ARM6
  155. #define ARM620  ARM6
  156.  
  157.  
  158. /***************************************************************************\
  159. *                   Macros to extract instruction fields                    *
  160. \***************************************************************************/
  161.  
  162. #define BIT(n) ( (ARMword)(instr>>(n))&1)   /* bit n of instruction */
  163. #define BITS(m,n) ( (ARMword)(instr<<(31-(n))) >> ((31-(n))+(m)) ) /* bits m to n of instr */
  164. #define TOPBITS(n) (instr >> (n)) /* bits 31 to n of instr */
  165.  
  166. /***************************************************************************\
  167. *                      The hardware vector addresses                        *
  168. \***************************************************************************/
  169.  
  170. #define ARMResetV 0L
  171. #define ARMUndefinedInstrV 4L
  172. #define ARMSWIV 8L
  173. #define ARMPrefetchAbortV 12L
  174. #define ARMDataAbortV 16L
  175. #define ARMAddrExceptnV 20L
  176. #define ARMIRQV 24L
  177. #define ARMFIQV 28L
  178. #define ARMErrorV 32L /* This is an offset, not an address ! */
  179.  
  180. #define ARMul_ResetV ARMResetV
  181. #define ARMul_UndefinedInstrV ARMUndefinedInstrV
  182. #define ARMul_SWIV ARMSWIV
  183. #define ARMul_PrefetchAbortV ARMPrefetchAbortV
  184. #define ARMul_DataAbortV ARMDataAbortV
  185. #define ARMul_AddrExceptnV ARMAddrExceptnV
  186. #define ARMul_IRQV ARMIRQV
  187. #define ARMul_FIQV ARMFIQV
  188.  
  189. /***************************************************************************\
  190. *                          Mode and Bank Constants                          *
  191. \***************************************************************************/
  192.  
  193. #define USER26MODE 0L
  194. #define FIQ26MODE 1L
  195. #define IRQ26MODE 2L
  196. #define SVC26MODE 3L
  197. #define USER32MODE 16L
  198. #define FIQ32MODE 17L
  199. #define IRQ32MODE 18L
  200. #define SVC32MODE 19L
  201. #define ABORT32MODE 23L
  202. #define UNDEF32MODE 27L
  203.  
  204. #define ARM32BITMODE (state->Mode > 3)
  205. #define ARM26BITMODE (state->Mode <= 3)
  206. #define ARMMODE (state->Mode)
  207. #define ARMul_MODEBITS 0x1fL
  208. #define ARMul_MODE32BIT ARM32BITMODE
  209. #define ARMul_MODE26BIT ARM26BITMODE
  210.  
  211. #define USERBANK 0
  212. #define FIQBANK 1
  213. #define IRQBANK 2
  214. #define SVCBANK 3
  215. #define ABORTBANK 4
  216. #define UNDEFBANK 5
  217. #define DUMMYBANK 6
  218.  
  219. /***************************************************************************\
  220. *                  Definitons of things in the emulator                     *
  221. \***************************************************************************/
  222.  
  223. extern void ARMul_EmulateInit(void) ;
  224. extern ARMul_State *ARMul_NewState(void) ;
  225. extern void ARMul_Reset(ARMul_State *state) ;
  226. extern ARMword ARMul_DoProg(ARMul_State *state) ;
  227. extern ARMword ARMul_DoInstr(ARMul_State *state) ;
  228.  
  229. /***************************************************************************\
  230. *                Definitons of things for event handling                    *
  231. \***************************************************************************/
  232.  
  233. extern void ARMul_ScheduleEvent(ARMul_State *state, unsigned long delay, unsigned (*func)() ) ;
  234. extern void ARMul_EnvokeEvent(ARMul_State *state) ;
  235. extern unsigned long ARMul_Time(ARMul_State *state) ;
  236.  
  237. /***************************************************************************\
  238. *                          Useful support routines                          *
  239. \***************************************************************************/
  240.  
  241. extern ARMword ARMul_GetReg(ARMul_State *state, unsigned mode, unsigned reg) ;
  242. extern void ARMul_SetReg(ARMul_State *state, unsigned mode, unsigned reg, ARMword value) ;
  243. extern ARMword ARMul_GetPC(ARMul_State *state) ;
  244. extern ARMword ARMul_GetNextPC(ARMul_State *state) ;
  245. extern void ARMul_SetPC(ARMul_State *state, ARMword value) ;
  246. extern ARMword ARMul_GetR15(ARMul_State *state) ;
  247. extern void ARMul_SetR15(ARMul_State *state, ARMword value) ;
  248.  
  249. extern ARMword ARMul_GetCPSR(ARMul_State *state) ;
  250. extern void ARMul_SetCPSR(ARMul_State *state, ARMword value) ;
  251. extern ARMword ARMul_GetSPSR(ARMul_State *state, ARMword mode) ;
  252. extern void ARMul_SetSPSR(ARMul_State *state, ARMword mode, ARMword value) ;
  253.  
  254. /***************************************************************************\
  255. *                  Definitons of things to handle aborts                    *
  256. \***************************************************************************/
  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. /***************************************************************************\
  267. *              Definitons of things in the memory interface                 *
  268. \***************************************************************************/
  269.  
  270. extern unsigned ARMul_MemoryInit(ARMul_State *state,unsigned long initmemsize) ;
  271. extern void ARMul_MemoryExit(ARMul_State *state) ;
  272.  
  273. extern ARMword ARMul_LoadInstrS(ARMul_State *state,ARMword address) ;
  274. extern ARMword ARMul_LoadInstrN(ARMul_State *state,ARMword address) ;
  275.  
  276. extern ARMword ARMul_LoadWordS(ARMul_State *state,ARMword address) ;
  277. extern ARMword ARMul_LoadWordN(ARMul_State *state,ARMword address) ;
  278. extern ARMword ARMul_LoadByte(ARMul_State *state,ARMword address) ;
  279.  
  280. extern void ARMul_StoreWordS(ARMul_State *state,ARMword address, ARMword data) ;
  281. extern void ARMul_StoreWordN(ARMul_State *state,ARMword address, ARMword data) ;
  282. extern void ARMul_StoreByte(ARMul_State *state,ARMword address, ARMword data) ;
  283.  
  284. extern ARMword ARMul_SwapWord(ARMul_State *state,ARMword address, ARMword data) ;
  285. extern ARMword ARMul_SwapByte(ARMul_State *state,ARMword address, ARMword data) ;
  286.  
  287. extern void ARMul_Icycles(ARMul_State *state,unsigned number, ARMword address) ;
  288. extern void ARMul_Ccycles(ARMul_State *state,unsigned number, ARMword address) ;
  289.  
  290. extern ARMword ARMul_ReadWord(ARMul_State *state,ARMword address) ;
  291. extern ARMword ARMul_ReadByte(ARMul_State *state,ARMword address) ;
  292. extern void ARMul_WriteWord(ARMul_State *state,ARMword address, ARMword data) ;
  293. extern void ARMul_WriteByte(ARMul_State *state,ARMword address, ARMword data) ;
  294.  
  295. extern ARMword ARMul_MemAccess(ARMul_State *state,ARMword,ARMword,ARMword,
  296.                   ARMword,ARMword,ARMword,ARMword,ARMword,ARMword,ARMword) ;
  297.  
  298. /***************************************************************************\
  299. *            Definitons of things in the co-processor interface             *
  300. \***************************************************************************/
  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.  
  311. extern unsigned ARMul_CoProInit(ARMul_State *state) ;
  312. extern void ARMul_CoProExit(ARMul_State *state) ;
  313. extern void ARMul_CoProAttach(ARMul_State *state, unsigned number,
  314.                               ARMul_CPInits *init, ARMul_CPExits *exit,
  315.                               ARMul_LDCs *ldc, ARMul_STCs *stc,
  316.                               ARMul_MRCs *mrc, ARMul_MCRs *mcr,
  317.                               ARMul_CDPs *cdp,
  318.                               ARMul_CPReads *read, ARMul_CPWrites *write) ;
  319. extern void ARMul_CoProDetach(ARMul_State *state, unsigned number) ;
  320.  
  321. /***************************************************************************\
  322. *               Definitons of things in the host environment                *
  323. \***************************************************************************/
  324.  
  325. extern unsigned ARMul_OSInit(ARMul_State *state) ;
  326. extern void ARMul_OSExit(ARMul_State *state) ;
  327. extern unsigned ARMul_OSHandleSWI(ARMul_State *state,ARMword number) ;
  328. extern ARMword ARMul_OSLastErrorP(ARMul_State *state) ;
  329.  
  330. extern ARMword ARMul_Debug(ARMul_State *state, ARMword pc, ARMword instr) ;
  331. extern unsigned ARMul_OSException(ARMul_State *state, ARMword vector, ARMword pc) ;
  332. extern int rdi_log ;
  333.  
  334. /***************************************************************************\
  335. *                            Host-dependent stuff                           *
  336. \***************************************************************************/
  337.  
  338. #ifdef macintosh
  339. pascal void SpinCursor(short increment);        /* copied from CursorCtl.h */
  340. # define HOURGLASS           SpinCursor( 1 )
  341. # define HOURGLASS_RATE      1023   /* 2^n - 1 */
  342. #endif
  343.  
  344.