System.h

Go to the documentation of this file.
00001 
00146 #include "SystemComponent.h"
00147 #include "TraceEngine.h"
00148 
00149 #if !defined(INCLUDED_SYSTEM_H)
00150 #define INCLUDED_SYSTEM_H
00151 
00152 #define MAX_COMPONENTS  100
00153 
00154 #if defined(PROFILE)
00155 #define PROFILE_FROM      U64(0x8000)
00156 #define PROFILE_TO        U64(0x1a81c0)
00157 #define PROFILE_AFTER     U64(0x200000)
00158 #define PROFILE_BUCKSIZE  16
00159 #define PROFILE_LENGTH    (PROFILE_TO - PROFILE_FROM)
00160 #define PROFILE_INSTS     (PROFILE_LENGTH / 4)
00161 #define PROFILE_BUCKETS   (PROFILE_INSTS / PROFILE_BUCKSIZE)
00162 #define PROFILE_YN(a) \
00163     ((a >= PROFILE_FROM) && (a < PROFILE_TO) && profile_started)
00164 #define PROFILE_BUCKET(a) \
00165   profile_buckets[(a - PROFILE_FROM) / 4 / PROFILE_BUCKSIZE]
00166 #define PROFILE_DO(a)                    \
00167   if((a & (~U64(0x3))) >= PROFILE_AFTER) \
00168     profile_started = true;              \
00169   if(PROFILE_YN(a))                      \
00170   {                                      \
00171     PROFILE_BUCKET(a)++;                 \
00172     profiled_insts++;                    \
00173   }
00174 
00175 extern u64    profile_buckets[PROFILE_BUCKETS];
00176 extern u64    profiled_insts;
00177 extern bool   profile_started;
00178 #endif
00179 #if defined(LS_MASTER) || defined(LS_SLAVE)
00180 extern char*  dbg_strptr;
00181 #endif
00182 
00184 struct SMemoryUser
00185 {
00186   CSystemComponent*   component;  
00187   int                 index;      
00188   u64                 base;       
00189   u64                 length;     
00190 };
00191 
00193 struct SConfig
00194 {
00195   char*   key;    
00196   char*   value;  
00197 };
00198 
00217 class CSystem
00218 {
00219   public:
00220     void          DumpMemory(unsigned int filenum);
00221     char*         PtrToMem(u64 address);
00222     unsigned int  get_memory_bits();
00223     void          RestoreState(const char* fn);
00224     void          SaveState(const char* fn);
00225     u64           PCI_Phys(int pcibus, u32 address);
00226     u64           PCI_Phys_direct_mapped(u32 address, u64 wsm, u64 tba);
00227     u64           PCI_Phys_scatter_gather(u32 address, u64 wsm, u64 tba);
00228     void          interrupt(int number, bool assert);
00229     int           LoadROM();
00230     u64           ReadMem(u64 address, int dsize, CSystemComponent* source);
00231     void          WriteMem(u64 address, int dsize, u64 data,
00232                            CSystemComponent*  source);
00233     void          Run();
00234     int           SingleStep();
00235 
00236     void          init();
00237     void          start_threads();
00238     void          stop_threads();
00239 
00240     int           RegisterMemory(CSystemComponent*  component, int index,
00241                                  u64 base, u64 length);
00242     int           RegisterComponent(CSystemComponent* component);
00243     int           RegisterCPU(class CAlphaCPU* cpu);
00244 
00245     CSystem(CConfigurator* cfg);
00246     void          ResetMem(unsigned int membits);
00247 
00248     CAlphaCPU*    get_cpu(int cpunum) { return acCPUs[cpunum]; };
00249     int           get_cpu_num()       { return iNumCPUs; };
00250 
00251     virtual       ~CSystem();
00252     unsigned int  iNumMemoryBits;
00253 
00254     void          panic(char* message, int flags);
00255 
00256 #define PANIC_NOSHUTDOWN  0
00257 #define PANIC_SHUTDOWN    1
00258 #define PANIC_ASKSHUTDOWN 2
00259 #define PANIC_LISTING     4
00260     void          clear_clock_int(int ProcNum);
00261     u64           get_c_misc();
00262     u64           get_c_dir(int ProcNum);
00263     u64           get_c_dim(int ProcNum);
00264     void          set_c_dim(int ProcNum, u64 value);
00265 
00266     void          cpu_lock(int cpuid, u64 address);
00267     bool          cpu_unlock(int cpuid);
00268     void          cpu_break_lock(int cpuid, CSystemComponent* source);
00269   private:
00270     u64           cchip_csr_read(u32 address, CSystemComponent* source);
00271     void          cchip_csr_write(u32 address, u64 data, CSystemComponent*  source);
00272     u64           pchip_csr_read(int num, u32 address);
00273     void          pchip_csr_write(int num, u32 address, u64 data);
00274     u8            dchip_csr_read(u32 address);
00275     void          dchip_csr_write(u32 address, u8 data);
00276     u8            tig_read(u32 address);
00277     void          tig_write(u32 address, u8 data);
00278 
00279     int           iNumCPUs;
00280     CFastMutex*   cpu_lock_mutex;
00281 
00283     struct SSys_state
00284     {
00285       int cpu_lock_flags;
00286       u64 cpu_lock_address[4];
00287 
00296       struct SSys_tig
00297       {
00298         u8  FwWrite;
00299         u8  HaltA;
00300         u8  HaltB;
00301       } tig;
00302 
00314       struct SSys_cchip
00315       {
00316 
00325         u64 dim[4];
00326 
00355         u64 drir;
00356 
00417         u64 misc;
00418         u64 csc;
00419       } cchip;
00420 
00431       struct SSys_dchip
00432       {
00433         u8  drev;
00434         u8  dsc;
00435         u8  dsc2;
00436         u8  str;
00437       } dchip;
00438 
00454       struct SSys_pchip
00455       {
00456         u64 plat;
00457         u64 perr;
00458         u64 perrmask;
00459         u64 pctl;
00460         u64 wsba[4];
00461         u64 wsm[4];
00462         u64 tba[4];
00463       } pchip[2];
00464 
00465       u32 cf8_address[2];
00466     } state;
00467     void*                 memory;
00468 
00469     //    void * memmap;
00470     int                   iNumComponents;
00471     CSystemComponent*     acComponents[MAX_COMPONENTS];
00472     int                   iNumMemories;
00473     struct SMemoryUser*   asMemories[MAX_COMPONENTS];
00474 
00475     class CAlphaCPU*      acCPUs[4];
00476 
00477     CConfigurator*        myCfg;
00478 
00479     int                   iSingleStep;
00480 
00481 #if defined(IDB)
00482     int                   iSSCycles;
00483 #endif
00484 };
00485 
00486 inline u64 CSystem::get_c_misc()
00487 {
00488   return state.cchip.misc;
00489 }
00490 
00491 inline u64 CSystem::get_c_dir(int ProcNum)
00492 {
00493   return state.cchip.drir & state.cchip.dim[ProcNum];
00494 }
00495 
00496 inline u64 CSystem::get_c_dim(int ProcNum)
00497 {
00498   return state.cchip.dim[ProcNum];
00499 }
00500 
00501 inline void CSystem::set_c_dim(int ProcNum, u64 value)
00502 {
00503   state.cchip.dim[ProcNum] = value;
00504 }
00505 
00506 extern CSystem*   theSystem;
00507 
00508 /* constants for P-Chip CSR's */
00509 #define PCI_PCTL_HOLE       U64(0x0000000000000020) /* <5>     */
00510 #define PCI_PCTL_HOLE_START 0x00080000
00511 #define PCI_PCTL_HOLE_END   0x000fffff
00512 
00513 /* constants for pci-to-phys-address-mapping */
00514 #define PCI_WSM_MASK      U64(0x00000000fff00000)   /* <31:20> */
00515 #define PCI_ADD_MASK      U64(0x00000000000fffff)   /* <19:0>  */
00516 #define PCI_TBA_MASK      U64(0x00000007fff00000)   /* <34:20> */
00517 #define PCI_PTE_ADD_MASK  U64(0x00000000000fe000)   /* <19:13> */
00518 #define PCI_PTE_ADD_SHIFT 10
00519 #define PCI_PTE_TBA_MASK  U64(0x00000007fffffc00)   /* <34:10> */
00520 #define PCI_PTE_MASK      U64(0x00000007ffffe000)   /* <34:13> */
00521 #define PCI_PTE_SHIFT     12
00522 #define PCI_PTE_ADD2_MASK U64(0x0000000000001fff)   /* <12:0>  */
00523 #define PCI_PTE_PEER_BIT  U64(0x0000000090000000)   /* <31,28> */
00524 
00525 #define PHYS_PIO_ACCESS   U64(0x0000080000000000)   /* <43>    */
00526 #endif // !defined(INCLUDED_SYSTEM_H)

SourceForge.net Logo
Project space on SourceForge.net