• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/core/techModels/libsim-panalyzer/armdefs.h

00001 /*  armdefs.h -- ARMulator common definitions:  ARM6 Instruction Emulator.
00002     Copyright (C) 1994 Advanced RISC Machines Ltd.
00003  
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or
00007     (at your option) any later version.
00008  
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013  
00014     You should have received a copy of the GNU General Public License
00015     along with this program; if not, write to the Free Software
00016     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
00017 
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 
00021 #define FALSE 0
00022 #define TRUE 1
00023 #define LOW 0
00024 #define HIGH 1
00025 #define LOWHIGH 1
00026 #define HIGHLOW 2
00027 
00028 #ifndef __STDC__
00029 typedef char *VoidStar;
00030 #endif
00031 
00032 typedef unsigned long ARMword;  /* must be 32 bits wide */
00033 typedef struct ARMul_State ARMul_State;
00034 
00035 typedef unsigned ARMul_CPInits (ARMul_State * state);
00036 typedef unsigned ARMul_CPExits (ARMul_State * state);
00037 typedef unsigned ARMul_LDCs (ARMul_State * state, unsigned type,
00038                              ARMword instr, ARMword value);
00039 typedef unsigned ARMul_STCs (ARMul_State * state, unsigned type,
00040                              ARMword instr, ARMword * value);
00041 typedef unsigned ARMul_MRCs (ARMul_State * state, unsigned type,
00042                              ARMword instr, ARMword * value);
00043 typedef unsigned ARMul_MCRs (ARMul_State * state, unsigned type,
00044                              ARMword instr, ARMword value);
00045 typedef unsigned ARMul_CDPs (ARMul_State * state, unsigned type,
00046                              ARMword instr);
00047 typedef unsigned ARMul_CPReads (ARMul_State * state, unsigned reg,
00048                                 ARMword * value);
00049 typedef unsigned ARMul_CPWrites (ARMul_State * state, unsigned reg,
00050                                  ARMword value);
00051 
00052 struct ARMul_State
00053 {
00054   ARMword Emulate;              /* to start and stop emulation */
00055   unsigned EndCondition;        /* reason for stopping */
00056   unsigned ErrorCode;           /* type of illegal instruction */
00057   ARMword Reg[16];              /* the current register file */
00058   ARMword RegBank[7][16];       /* all the registers */
00059   ARMword Cpsr;                 /* the current psr */
00060   ARMword Spsr[7];              /* the exception psr's */
00061   ARMword NFlag, ZFlag, CFlag, VFlag, IFFlags;  /* dummy flags for speed */
00062 #ifdef MODET
00063   ARMword TFlag;                /* Thumb state */
00064 #endif
00065   ARMword Bank;                 /* the current register bank */
00066   ARMword Mode;                 /* the current mode */
00067   ARMword instr, pc, temp;      /* saved register state */
00068   ARMword loaded, decoded;      /* saved pipeline state */
00069   unsigned long NumScycles, NumNcycles, NumIcycles, NumCcycles, NumFcycles;     /* emulated cycles used */
00070   unsigned long NumInstrs;      /* the number of instructions executed */
00071   unsigned NextInstr;
00072   unsigned VectorCatch;         /* caught exception mask */
00073   unsigned CallDebug;           /* set to call the debugger */
00074   unsigned CanWatch;            /* set by memory interface if its willing to suffer the
00075                                    overhead of checking for watchpoints on each memory
00076                                    access */
00077   unsigned MemReadDebug, MemWriteDebug;
00078   unsigned long StopHandle;
00079 
00080   unsigned char *MemDataPtr;    /* admin data */
00081   unsigned char *MemInPtr;      /* the Data In bus */
00082   unsigned char *MemOutPtr;     /* the Data Out bus (which you may not need */
00083   unsigned char *MemSparePtr;   /* extra space */
00084   ARMword MemSize;
00085 
00086   unsigned char *OSptr;         /* OS Handle */
00087   char *CommandLine;            /* Command Line from ARMsd */
00088 
00089   ARMul_CPInits *CPInit[16];    /* coprocessor initialisers */
00090   ARMul_CPExits *CPExit[16];    /* coprocessor finalisers */
00091   ARMul_LDCs *LDC[16];          /* LDC instruction */
00092   ARMul_STCs *STC[16];          /* STC instruction */
00093   ARMul_MRCs *MRC[16];          /* MRC instruction */
00094   ARMul_MCRs *MCR[16];          /* MCR instruction */
00095   ARMul_CDPs *CDP[16];          /* CDP instruction */
00096   ARMul_CPReads *CPRead[16];    /* Read CP register */
00097   ARMul_CPWrites *CPWrite[16];  /* Write CP register */
00098   unsigned char *CPData[16];    /* Coprocessor data */
00099   unsigned char const *CPRegWords[16];  /* map of coprocessor register sizes */
00100 
00101   unsigned EventSet;            /* the number of events in the queue */
00102   unsigned long Now;            /* time to the nearest cycle */
00103   struct EventNode **EventPtr;  /* the event list */
00104 
00105   unsigned Exception;           /* enable the next four values */
00106   unsigned Debug;               /* show instructions as they are executed */
00107   unsigned NresetSig;           /* reset the processor */
00108   unsigned NfiqSig;
00109   unsigned NirqSig;
00110 
00111   unsigned abortSig;
00112   unsigned NtransSig;
00113   unsigned bigendSig;
00114   unsigned prog32Sig;
00115   unsigned data32Sig;
00116   unsigned lateabtSig;
00117   ARMword Vector;               /* synthesize aborts in cycle modes */
00118   ARMword Aborted;              /* sticky flag for aborts */
00119   ARMword Reseted;              /* sticky flag for Reset */
00120   ARMword Inted, LastInted;     /* sticky flags for interrupts */
00121   ARMword Base;                 /* extra hand for base writeback */
00122   ARMword AbortAddr;            /* to keep track of Prefetch aborts */
00123 
00124   const struct Dbg_HostosInterface *hostif;
00125 
00126   int verbose;                  /* non-zero means print various messages like the banner */
00127 };
00128 
00129 #define ResetPin NresetSig
00130 #define FIQPin NfiqSig
00131 #define IRQPin NirqSig
00132 #define AbortPin abortSig
00133 #define TransPin NtransSig
00134 #define BigEndPin bigendSig
00135 #define Prog32Pin prog32Sig
00136 #define Data32Pin data32Sig
00137 #define LateAbortPin lateabtSig
00138 
00139 /***************************************************************************\
00140 *                        Types of ARM we know about                         *
00141 \***************************************************************************/
00142 
00143 /* The bitflags */
00144 #define ARM_Fix26_Prop   0x01
00145 #define ARM_Nexec_Prop   0x02
00146 #define ARM_Debug_Prop   0x10
00147 #define ARM_Isync_Prop   ARM_Debug_Prop
00148 #define ARM_Lock_Prop    0x20
00149 
00150 /* ARM2 family */
00151 #define ARM2    (ARM_Fix26_Prop)
00152 #define ARM2as  ARM2
00153 #define ARM61   ARM2
00154 #define ARM3    ARM2
00155 
00156 #ifdef ARM60                    /* previous definition in armopts.h */
00157 #undef ARM60
00158 #endif
00159 
00160 /* ARM6 family */
00161 #define ARM6    (ARM_Lock_Prop)
00162 #define ARM60   ARM6
00163 #define ARM600  ARM6
00164 #define ARM610  ARM6
00165 #define ARM620  ARM6
00166 
00167 
00168 /***************************************************************************\
00169 *                   Macros to extract instruction fields                    *
00170 \***************************************************************************/
00171 
00172 #define BIT(n) ( (ARMword)(instr>>(n))&1)       /* bit n of instruction */
00173 #define BITS(m,n) ( (ARMword)(instr<<(31-(n))) >> ((31-(n))+(m)) )      /* bits m to n of instr */
00174 #define TOPBITS(n) (instr >> (n))       /* bits 31 to n of instr */
00175 
00176 /***************************************************************************\
00177 *                      The hardware vector addresses                        *
00178 \***************************************************************************/
00179 
00180 #define ARMResetV 0L
00181 #define ARMUndefinedInstrV 4L
00182 #define ARMSWIV 8L
00183 #define ARMPrefetchAbortV 12L
00184 #define ARMDataAbortV 16L
00185 #define ARMAddrExceptnV 20L
00186 #define ARMIRQV 24L
00187 #define ARMFIQV 28L
00188 #define ARMErrorV 32L           /* This is an offset, not an address ! */
00189 
00190 #define ARMul_ResetV ARMResetV
00191 #define ARMul_UndefinedInstrV ARMUndefinedInstrV
00192 #define ARMul_SWIV ARMSWIV
00193 #define ARMul_PrefetchAbortV ARMPrefetchAbortV
00194 #define ARMul_DataAbortV ARMDataAbortV
00195 #define ARMul_AddrExceptnV ARMAddrExceptnV
00196 #define ARMul_IRQV ARMIRQV
00197 #define ARMul_FIQV ARMFIQV
00198 
00199 /***************************************************************************\
00200 *                          Mode and Bank Constants                          *
00201 \***************************************************************************/
00202 
00203 #define USER26MODE 0L
00204 #define FIQ26MODE 1L
00205 #define IRQ26MODE 2L
00206 #define SVC26MODE 3L
00207 #define USER32MODE 16L
00208 #define FIQ32MODE 17L
00209 #define IRQ32MODE 18L
00210 #define SVC32MODE 19L
00211 #define ABORT32MODE 23L
00212 #define UNDEF32MODE 27L
00213 
00214 #define ARM32BITMODE (state->Mode > 3)
00215 #define ARM26BITMODE (state->Mode <= 3)
00216 #define ARMMODE (state->Mode)
00217 #define ARMul_MODEBITS 0x1fL
00218 #define ARMul_MODE32BIT ARM32BITMODE
00219 #define ARMul_MODE26BIT ARM26BITMODE
00220 
00221 #define USERBANK 0
00222 #define FIQBANK 1
00223 #define IRQBANK 2
00224 #define SVCBANK 3
00225 #define ABORTBANK 4
00226 #define UNDEFBANK 5
00227 #define DUMMYBANK 6
00228 
00229 /***************************************************************************\
00230 *                  Definitons of things in the emulator                     *
00231 \***************************************************************************/
00232 
00233 extern void ARMul_EmulateInit (void);
00234 extern ARMul_State *ARMul_NewState (void);
00235 extern void ARMul_Reset (ARMul_State * state);
00236 extern ARMword ARMul_DoProg (ARMul_State * state);
00237 extern ARMword ARMul_DoInstr (ARMul_State * state);
00238 
00239 /***************************************************************************\
00240 *                Definitons of things for event handling                    *
00241 \***************************************************************************/
00242 
00243 extern void ARMul_ScheduleEvent (ARMul_State * state, unsigned long delay,
00244                                  unsigned (*func) ());
00245 extern void ARMul_EnvokeEvent (ARMul_State * state);
00246 extern unsigned long ARMul_Time (ARMul_State * state);
00247 
00248 /***************************************************************************\
00249 *                          Useful support routines                          *
00250 \***************************************************************************/
00251 
00252 extern ARMword ARMul_GetReg (ARMul_State * state, unsigned mode,
00253                              unsigned reg);
00254 extern void ARMul_SetReg (ARMul_State * state, unsigned mode, unsigned reg,
00255                           ARMword value);
00256 extern ARMword ARMul_GetPC (ARMul_State * state);
00257 extern ARMword ARMul_GetNextPC (ARMul_State * state);
00258 extern void ARMul_SetPC (ARMul_State * state, ARMword value);
00259 extern ARMword ARMul_GetR15 (ARMul_State * state);
00260 extern void ARMul_SetR15 (ARMul_State * state, ARMword value);
00261 
00262 extern ARMword ARMul_GetCPSR (ARMul_State * state);
00263 extern void ARMul_SetCPSR (ARMul_State * state, ARMword value);
00264 extern ARMword ARMul_GetSPSR (ARMul_State * state, ARMword mode);
00265 extern void ARMul_SetSPSR (ARMul_State * state, ARMword mode, ARMword value);
00266 
00267 /***************************************************************************\
00268 *                  Definitons of things to handle aborts                    *
00269 \***************************************************************************/
00270 
00271 extern void ARMul_Abort (ARMul_State * state, ARMword address);
00272 #define ARMul_ABORTWORD 0xefffffff      /* SWI -1 */
00273 #define ARMul_PREFETCHABORT(address) if (state->AbortAddr == 1) \
00274                                         state->AbortAddr = (address & ~3L)
00275 #define ARMul_DATAABORT(address) state->abortSig = HIGH ; \
00276                                  state->Aborted = ARMul_DataAbortV ;
00277 #define ARMul_CLEARABORT state->abortSig = LOW
00278 
00279 /***************************************************************************\
00280 *              Definitons of things in the memory interface                 *
00281 \***************************************************************************/
00282 
00283 extern unsigned ARMul_MemoryInit (ARMul_State * state,
00284                                   unsigned long initmemsize);
00285 extern void ARMul_MemoryExit (ARMul_State * state);
00286 
00287 extern ARMword ARMul_LoadInstrS (ARMul_State * state, ARMword address,
00288                                  ARMword isize);
00289 extern ARMword ARMul_LoadInstrN (ARMul_State * state, ARMword address,
00290                                  ARMword isize);
00291 extern ARMword ARMul_ReLoadInstr (ARMul_State * state, ARMword address,
00292                                   ARMword isize);
00293 
00294 extern ARMword ARMul_LoadWordS (ARMul_State * state, ARMword address);
00295 extern ARMword ARMul_LoadWordN (ARMul_State * state, ARMword address);
00296 extern ARMword ARMul_LoadHalfWord (ARMul_State * state, ARMword address);
00297 extern ARMword ARMul_LoadByte (ARMul_State * state, ARMword address);
00298 
00299 extern void ARMul_StoreWordS (ARMul_State * state, ARMword address,
00300                               ARMword data);
00301 extern void ARMul_StoreWordN (ARMul_State * state, ARMword address,
00302                               ARMword data);
00303 extern void ARMul_StoreHalfWord (ARMul_State * state, ARMword address,
00304                                  ARMword data);
00305 extern void ARMul_StoreByte (ARMul_State * state, ARMword address,
00306                              ARMword data);
00307 
00308 extern ARMword ARMul_SwapWord (ARMul_State * state, ARMword address,
00309                                ARMword data);
00310 extern ARMword ARMul_SwapByte (ARMul_State * state, ARMword address,
00311                                ARMword data);
00312 
00313 extern void ARMul_Icycles (ARMul_State * state, unsigned number,
00314                            ARMword address);
00315 extern void ARMul_Ccycles (ARMul_State * state, unsigned number,
00316                            ARMword address);
00317 
00318 extern ARMword ARMul_ReadWord (ARMul_State * state, ARMword address);
00319 extern ARMword ARMul_ReadByte (ARMul_State * state, ARMword address);
00320 extern void ARMul_WriteWord (ARMul_State * state, ARMword address,
00321                              ARMword data);
00322 extern void ARMul_WriteByte (ARMul_State * state, ARMword address,
00323                              ARMword data);
00324 
00325 extern ARMword ARMul_MemAccess (ARMul_State * state, ARMword, ARMword,
00326                                 ARMword, ARMword, ARMword, ARMword, ARMword,
00327                                 ARMword, ARMword, ARMword);
00328 
00329 /***************************************************************************\
00330 *            Definitons of things in the co-processor interface             *
00331 \***************************************************************************/
00332 
00333 #define ARMul_FIRST 0
00334 #define ARMul_TRANSFER 1
00335 #define ARMul_BUSY 2
00336 #define ARMul_DATA 3
00337 #define ARMul_INTERRUPT 4
00338 #define ARMul_DONE 0
00339 #define ARMul_CANT 1
00340 #define ARMul_INC 3
00341 
00342 extern unsigned ARMul_CoProInit (ARMul_State * state);
00343 extern void ARMul_CoProExit (ARMul_State * state);
00344 extern void ARMul_CoProAttach (ARMul_State * state, unsigned number,
00345                                ARMul_CPInits * init, ARMul_CPExits * exit,
00346                                ARMul_LDCs * ldc, ARMul_STCs * stc,
00347                                ARMul_MRCs * mrc, ARMul_MCRs * mcr,
00348                                ARMul_CDPs * cdp,
00349                                ARMul_CPReads * read, ARMul_CPWrites * write);
00350 extern void ARMul_CoProDetach (ARMul_State * state, unsigned number);
00351 
00352 /***************************************************************************\
00353 *               Definitons of things in the host environment                *
00354 \***************************************************************************/
00355 
00356 extern unsigned ARMul_OSInit (ARMul_State * state);
00357 extern void ARMul_OSExit (ARMul_State * state);
00358 extern unsigned ARMul_OSHandleSWI (ARMword instr, ARMul_State * state, ARMword number);
00359 extern ARMword ARMul_OSLastErrorP (ARMul_State * state);
00360 
00361 extern ARMword ARMul_Debug (ARMul_State * state, ARMword pc, ARMword instr);
00362 extern unsigned ARMul_OSException (ARMul_State * state, ARMword vector,
00363                                    ARMword pc);
00364 extern int rdi_log;
00365 
00366 /***************************************************************************\
00367 *                            Host-dependent stuff                           *
00368 \***************************************************************************/
00369 
00370 #ifdef macintosh
00371 pascal void SpinCursor (short increment);       /* copied from CursorCtl.h */
00372 # define HOURGLASS           SpinCursor( 1 )
00373 # define HOURGLASS_RATE      1023       /* 2^n - 1 */
00374 #endif
00375 
00376 extern void ARMul_UndefInstr      (ARMul_State *, ARMword);
00377 extern void ARMul_FixCPSR         (ARMul_State *, ARMword, ARMword);
00378 extern void ARMul_FixSPSR         (ARMul_State *, ARMword, ARMword);
00379 extern void ARMul_ConsolePrint    (ARMul_State *, const char *, ...);
00380 extern void ARMul_SelectProcessor (ARMul_State *, unsigned);

Generated on Fri Oct 22 2010 11:02:18 for SST by  doxygen 1.7.1