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

sst/elements/genericProc/ssBackEnd/ssb_memory.h

00001 /*
00002  * memory.h - flat memory space interfaces
00003  *
00004  * This file is a part of the SimpleScalar tool suite written by
00005  * Todd M. Austin as a part of the Multiscalar Research Project.
00006  *  
00007  * The tool suite is currently maintained by Doug Burger and Todd M. Austin.
00008  * 
00009  * Copyright (C) 1994, 1995, 1996, 1997, 1998 by Todd M. Austin
00010  *
00011  * This source file is distributed "as is" in the hope that it will be
00012  * useful.  The tool set comes with no warranty, and no author or
00013  * distributor accepts any responsibility for the consequences of its
00014  * use. 
00015  * 
00016  * Everyone is granted permission to copy, modify and redistribute
00017  * this tool set under the following conditions:
00018  * 
00019  *    This source code is distributed for non-commercial use only. 
00020  *    Please contact the maintainer for restrictions applying to 
00021  *    commercial use.
00022  *
00023  *    Permission is granted to anyone to make or distribute copies
00024  *    of this source code, either as received or modified, in any
00025  *    medium, provided that all copyright notices, permission and
00026  *    nonwarranty notices are preserved, and that the distributor
00027  *    grants the recipient permission for further redistribution as
00028  *    permitted by this document.
00029  *
00030  *    Permission is granted to distribute this file in compiled
00031  *    or executable form under the same conditions that apply for
00032  *    source code, provided that either:
00033  *
00034  *    A. it is accompanied by the corresponding machine-readable
00035  *       source code,
00036  *    B. it is accompanied by a written offer, with no time limit,
00037  *       to give anyone a machine-readable copy of the corresponding
00038  *       source code in return for reimbursement of the cost of
00039  *       distribution.  This written offer must permit verbatim
00040  *       duplication by anyone, or
00041  *    C. it is distributed by someone who received only the
00042  *       executable form, and is accompanied by a copy of the
00043  *       written offer of source code that they received concurrently.
00044  *
00045  * In other words, you are welcome to use, share and improve this
00046  * source file.  You are forbidden to forbid anyone else to use, share
00047  * and improve what you give them.
00048  *
00049  * INTERNET: dburger@cs.wisc.edu
00050  * US Mail:  1210 W. Dayton Street, Madison, WI 53706
00051  *
00052  * $Id: ssb_memory.h,v 1.1.1.1 2006-01-31 16:35:50 afrodri Exp $
00053  *
00054  * $Log: not supported by cvs2svn $
00055  * Revision 1.5  2005/08/16 21:12:55  arodrig6
00056  * changes for docs
00057  *
00058  * Revision 1.4  2004/11/16 04:17:46  arodrig6
00059  * added more documentation
00060  *
00061  * Revision 1.3  2004/08/24 15:43:30  arodrig6
00062  * added 'condem()' to thread. Integrated off-chip dram with conventional processor
00063  *
00064  * Revision 1.2  2004/08/10 22:55:35  arodrig6
00065  * works, except for the speculative stuff, caches, and multiple procs
00066  *
00067  * Revision 1.1  2004/08/05 23:51:44  arodrig6
00068  * grabed files from SS and broke up some of them
00069  *
00070  * Revision 1.4  2000/05/31 01:59:51  karu
00071  * added support for mis-aligned accesses
00072  *
00073  * Revision 1.3  2000/04/11 00:55:56  karu
00074  * made source platform independent. compiles on linux, solaris and ofcourse aix.
00075  * powerpc-nonnative.def is the def file with no inline assemble code.
00076  * manually create the machine.def symlink if compiling on non-aix OS.
00077  * also syscall.c does not compile because the syscalls haven't been
00078  * resourced with diff. flags and names for different operating systems.
00079  *
00080  * Revision 1.2  2000/04/10 23:46:30  karu
00081  * converted all quad to qword. NO OTHER change made.
00082  * the tag specfp95-before-quad-qword is a snapshow before this change was made
00083  *
00084  * Revision 1.1.1.1  2000/03/07 05:15:17  karu
00085  * this is the repository created for my own maintanence.
00086  * created when spec95 (lisp and compress worked).
00087  * compress still had the scanf("%i") problem
00088  * DIFF from the repository I am using alongwith ramdass on /projects
00089  * need to merge the two sometime :-)
00090  *
00091  * Revision 1.1.1.1  2000/02/25 21:02:50  karu
00092  * creating cvs repository for ss3-ppc
00093  *
00094  * Revision 1.6  1998/08/27 15:39:47  taustin
00095  * implemented host interface description in host.h
00096  * added target interface support
00097  * memory module updated to support 64/32 bit address spaces on 64/32
00098  *       bit machines, now implemented with a dynamically optimized hashed
00099  *       page table
00100  * added support for quadword's
00101  * added fault support
00102  * added support for register and memory contexts
00103  *
00104  * Revision 1.5  1997/03/11  01:16:23  taustin
00105  * updated copyright
00106  * long/int tweaks made for ALPHA target support
00107  * major macro reorganization to support CC portability
00108  * mem_valid() added, indicates if an address is bogus, used by DLite!
00109  *
00110  * Revision 1.4  1997/01/06  16:01:24  taustin
00111  * HIDE_MEM_TABLE_DEF added to help with sim-fast.c compilation
00112  *
00113  * Revision 1.3  1996/12/27  15:53:15  taustin
00114  * updated comments
00115  *
00116  * Revision 1.1  1996/12/05  18:50:23  taustin
00117  * Initial revision
00118  *
00119  *
00120  */
00121 
00122 #ifndef SSB_MEMORY_H
00123 #define SSB_MEMORY_H
00124 
00125 #include <stdio.h>
00126 
00127 #include "ssb_host.h"
00128 #include "ssb_misc.h"
00129 #include "ssb_machine.h"
00130 #include "ssb_options.h"
00131 #include "ssb_stats.h"
00132 
00133 /*
00134 int READMASKSLEFT[] = { 0xFFFFFFFF, 0x00FFFFFF, 0x0000FFFF, 0x000000FF };
00135 int WRITEMASKSLEFT[] = { 0xFFFFFFFF, 0xFF000000, 0xFFFF0000, 0xFFFFFF00 };
00136 int WRITEMASKSRIGHT[] = { 0xFFFFFFFF, 0x00FFFFFF, 0x0000FFFF, 0x000000FF };
00137 */
00138 
00139 extern int READMASKSLEFT[];
00140 extern int WRITEMASKSLEFT[];
00141 extern int WRITEMASKSRIGHT[];
00142 
00143 /* number of entries in page translation hash table (must be power-of-two) */
00144 #define MEM_PTAB_SIZE           (32*1024)
00145 #define MEM_LOG_PTAB_SIZE       15
00146 
00147 //: page table entry 
00148 //!SEC:ssBack
00149 struct mem_pte_t {
00150   //: next translation in this bucket 
00151    mem_pte_t *next;
00152   //: virtual page number tag 
00153   md_addr_t tag;                
00154   //: page pointer 
00155   byte_t *page;                 
00156 };
00157 
00158 //: memory object 
00159 //!SEC:ssBack
00160 struct mem_t {
00161   /* memory object state */
00162   //: name of this memory space 
00163   char *name;                           
00164   //: inverted page table 
00165    mem_pte_t *ptab[MEM_PTAB_SIZE];
00166 
00167   /* memory object stats */
00168   //: total number of pages allocated 
00169   counter_t page_count;         
00170   //: total first level page tbl misses 
00171   counter_t ptab_misses;                
00172   //: total page table accesses 
00173   counter_t ptab_accesses;              
00174 };
00175 
00176 /* memory access command */
00177 enum mem_cmd {
00178   Read,                 /* read memory from target (simulated prog) to host */
00179   Write,                /* write memory from host (simulator) to target */
00180   Inject                /* Inject memory into cache */
00181 };
00182 
00183 /* memory access function type, this is a generic function exported for the
00184    purpose of access the simulated vitual memory space */
00185 typedef enum md_fault_type
00186 (*mem_access_fn)( mem_t *mem,   /* memory space to access */
00187                  enum mem_cmd cmd,      /* Read or Write */
00188                  md_addr_t addr,        /* target memory address to access */
00189                  void *p,               /* where to copy to/from */
00190                  int nbytes);           /* transfer length in bytes */
00191 
00192 /*
00193  * virtual to host page translation macros
00194  */
00195 
00196 /* compute page table set */
00197 #define MEM_PTAB_SET(ADDR)                                              \
00198   (((ADDR) >> MD_LOG_PAGE_SIZE) & (MEM_PTAB_SIZE - 1))
00199 
00200 /* compute page table tag */
00201 #define MEM_PTAB_TAG(ADDR)                                              \
00202   ((ADDR) >> (MD_LOG_PAGE_SIZE + MEM_LOG_PTAB_SIZE))
00203 
00204 /* convert a pte entry at idx to a block address */
00205 #define MEM_PTE_ADDR(PTE, IDX)                                          \
00206   (((PTE)->tag << (MD_LOG_PAGE_SIZE + MEM_LOG_PTAB_SIZE))               \
00207    | ((IDX) << MD_LOG_PAGE_SIZE))
00208 
00209 #define MEM_OFFSET(ADDR)        ((ADDR) & (MD_PAGE_SIZE - 1))
00210 /* locate host page for virtual address ADDR, returns NULL if unallocated */
00211 #define MEM_PAGE(MEM, ADDR)                                             \
00212   (/* first attempt to hit in first entry, otherwise call xlation fn */ \
00213    ((MEM)->ptab[MEM_PTAB_SET(ADDR)]                                     \
00214     && (MEM)->ptab[MEM_PTAB_SET(ADDR)]->tag == MEM_PTAB_TAG(ADDR))      \
00215    ? (/* hit - return the page address on host */                       \
00216       (MEM)->ptab_accesses++, \
00217       (MEM)->ptab[MEM_PTAB_SET(ADDR)]->page)                            \
00218    : (/* first level miss - call the translation helper function */     \
00219       mem_translate((MEM), (ADDR))))
00220 
00221 /* compute address of access within a host page */
00222 
00223 /* memory tickle function, allocates pages when they are first written */
00224 #define MEM_TICKLE(MEM, ADDR)                                           \
00225   (!MEM_PAGE(MEM, ADDR)                                                 \
00226    ? (/* allocate page at address ADDR */                               \
00227       mem_newpage(MEM, ADDR))                                           \
00228    : (/* nada... */ (void)0))
00229 
00230 /* memory page iterator */
00231 #define MEM_FORALL(MEM, ITER, PTE)                                      \
00232   for ((ITER)=0; (ITER) < MEM_PTAB_SIZE; (ITER)++)                      \
00233     for ((PTE)=(MEM)->ptab[i]; (PTE) != NULL; (PTE)=(PTE)->next)
00234 
00235 
00236 /*
00237  * memory accessors macros, fast but difficult to debug...
00238  */
00239 
00240 /* safe version, works only with scalar types */
00241 /* FIXME: write a more efficient GNU C expression for this... */
00242 #define MEM_READ(MEM, ADDR, TYPE)                                       \
00243   (MEM_PAGE(MEM, (md_addr_t)(ADDR))                                     \
00244    ? *((TYPE *)(MEM_PAGE(MEM, (md_addr_t)(ADDR)) + MEM_OFFSET(ADDR)))   \
00245    : /* page not yet allocated, return zero value */ 0)
00246 
00247 /* unsafe version, works with any type */
00248 #define __UNCHK_MEM_READ(MEM, ADDR, TYPE)                               \
00249   (*((TYPE *)(MEM_PAGE(MEM, (md_addr_t)(ADDR)) + MEM_OFFSET(ADDR))))
00250 
00251 /* safe version, works only with scalar types */
00252 /* FIXME: write a more efficient GNU C expression for this... */
00253 #define MEM_WRITE(MEM, ADDR, TYPE, VAL)                                 \
00254   (MEM_TICKLE(MEM, (md_addr_t)(ADDR)),                                  \
00255    *((TYPE *)(MEM_PAGE(MEM, (md_addr_t)(ADDR)) + MEM_OFFSET(ADDR))) = (VAL))
00256       
00257 /* unsafe version, works with any type */
00258 #define __UNCHK_MEM_WRITE(MEM, ADDR, TYPE, VAL)                         \
00259   (*((TYPE *)(MEM_PAGE(MEM, (md_addr_t)(ADDR)) + MEM_OFFSET(ADDR))) = (VAL))
00260 
00261 
00262 /* fast memory accessor macros, typed versions */
00263 #if 0
00264 #define MEM_READ_BYTE(MEM, ADDR)        MEM_READ(MEM, ADDR, byte_t)
00265 #define MEM_READ_SBYTE(MEM, ADDR)       MEM_READ(MEM, ADDR, sbyte_t)
00266 #define MEM_READ_HALF(MEM, ADDR)        MEM_READ(MEM, ADDR, half_t)
00267 #define MEM_READ_SHALF(MEM, ADDR)       MEM_READ(MEM, ADDR, shalf_t)
00268 #define MEM_READ_WORD(MEM, ADDR)        MEM_READ(MEM, ADDR, word_t)
00269 #define MEM_READ_SWORD(MEM, ADDR)       MEM_READ(MEM, ADDR, sword_t)
00270 #define MEM_READ_SFLOAT(MEM, ADDR)      MEM_READ(MEM, ADDR, sfloat_t)
00271 #define MEM_READ_DFLOAT(MEM, ADDR)      MEM_READ(MEM, ADDR, dfloat_t)
00272 
00273 #ifdef HOST_HAS_QWORD
00274 #define MEM_READ_QWORD(MEM, ADDR)       MEM_READ(MEM, ADDR, qword_t)
00275 #define MEM_READ_SQWORD(MEM, ADDR)      MEM_READ(MEM, ADDR, sqword_t)
00276 #endif /* HOST_HAS_QWORD */
00277 
00278 #define MEM_WRITE_BYTE(MEM, ADDR, VAL)  MEM_WRITE(MEM, ADDR, byte_t, VAL)
00279 #define MEM_WRITE_SBYTE(MEM, ADDR, VAL) MEM_WRITE(MEM, ADDR, sbyte_t, VAL)
00280 #define MEM_WRITE_HALF(MEM, ADDR, VAL)  MEM_WRITE(MEM, ADDR, half_t, VAL)
00281 #define MEM_WRITE_SHALF(MEM, ADDR, VAL) MEM_WRITE(MEM, ADDR, shalf_t, VAL)
00282 #define MEM_WRITE_WORD(MEM, ADDR, VAL)  MEM_WRITE(MEM, ADDR, word_t, VAL)
00283 #define MEM_WRITE_SWORD(MEM, ADDR, VAL) MEM_WRITE(MEM, ADDR, sword_t, VAL)
00284 #define MEM_WRITE_SFLOAT(MEM, ADDR, VAL) MEM_WRITE(MEM, ADDR, sfloat_t, VAL)
00285 #define MEM_WRITE_DFLOAT(MEM, ADDR, VAL) MEM_WRITE(MEM, ADDR, dfloat_t, VAL)
00286 
00287 #ifdef HOST_HAS_QWORD
00288 #define MEM_WRITE_QWORD(MEM, ADDR, VAL) MEM_WRITE(MEM, ADDR, qword_t, VAL)
00289 #define MEM_WRITE_SQWORD(MEM, ADDR, VAL)        MEM_WRITE(MEM, ADDR, sqword_t, VAL)
00290 #endif /* HOST_HAS_QWORD */
00291 #endif
00292 
00293 #ifdef PPC_SWAP
00294 
00295 #define SWAP_HALF(X)                                                    \
00296   (((((half_t)(X)) & 0xff) << 8) | ((((half_t)(X)) & 0xff00) >> 8))
00297 #define SWAP_WORD(X)    (((word_t)(X) << 24) |                          \
00298                          (((word_t)(X) << 8)  & 0x00ff0000) |           \
00299                          (((word_t)(X) >> 8)  & 0x0000ff00) |           \
00300                          (((word_t)(X) >> 24) & 0x000000ff))
00301 #define SWAP_QWORD(X)   (((qword_t)(X) << 56) |                         \
00302                          (((qword_t)(X) << 40) & ULL(0x00ff000000000000)) |\
00303                          (((qword_t)(X) << 24) & ULL(0x0000ff0000000000)) |\
00304                          (((qword_t)(X) << 8)  & ULL(0x000000ff00000000)) |\
00305                          (((qword_t)(X) >> 8)  & ULL(0x00000000ff000000)) |\
00306                          (((qword_t)(X) >> 24) & ULL(0x0000000000ff0000)) |\
00307                          (((qword_t)(X) >> 40) & ULL(0x000000000000ff00)) |\
00308                          (((qword_t)(X) >> 56) & ULL(0x00000000000000ff)))
00309 #else 
00310 
00311 #define SWAP_HALF(X) (X)
00312 #define SWAP_WORD(X) (X)
00313 #define SWAP_QWORD(X) (X)
00314 
00315 #endif
00316 
00317 #define MD_SWAPH(X)             SWAP_HALF(X)
00318 #define MD_SWAPW(X)             SWAP_WORD(X)
00319 #define MD_SWAPQ(X)             SWAP_QWORD(X)
00320 #define MD_SWAPI(X)             SWAP_WORD(X)
00321 
00322 #define ADDR_REM(ADDR) ((ADDR)%4)
00323 #define LEFTWORD(MEM, ADDR) (MEM_READ(MEM, (ADDR-((ADDR)%4)), word_t) )
00324 #define RIGHTWORD(MEM,ADDR) (MEM_READ(MEM, ((ADDR-((ADDR)%4))+4), word_t) )
00325 
00326 #define MEM_READ_BYTE(MEM, ADDR)        MEM_READ(MEM, ADDR, byte_t)
00327 #define MEM_READ_SBYTE(MEM, ADDR)       MEM_READ(MEM, ADDR, sbyte_t)
00328 /*
00329 #define MEM_READ_HALF(MEM, ADDR)        MD_SWAPH(MEM_READ(MEM, ADDR, half_t))
00330 #define MEM_READ_SHALF(MEM, ADDR)       MD_SWAPH(MEM_READ(MEM, ADDR, shalf_t))
00331 #define MEM_READ_WORD(MEM, ADDR)        MD_SWAPW(MEM_READ(MEM, ADDR, word_t))
00332 #define MEM_READ_SWORD(MEM, ADDR)       MD_SWAPW(MEM_READ(MEM, ADDR, sword_t))
00333 */
00334 
00335 #define MEM_READ_HALF(MEM, ADDR)        ((ADDR%4)==0)?(MEM_READ(MEM, ADDR, half_t)):\
00336                                                                 ((half_t) ( ( (MEM_READ_BYTE(MEM,ADDR) << 8) | \
00337                                                                          (MEM_READ_BYTE(MEM,ADDR+1)) )\
00338                                                                 ))
00339 #define MEM_READ_SHALF(MEM, ADDR)    ((ADDR%4)==0)?(MEM_READ(MEM, ADDR, shalf_t)):\
00340                         ((shalf_t) ( ( (MEM_READ_BYTE(MEM,ADDR) << 8) | \
00341                             (MEM_READ_BYTE(MEM,ADDR+1)) )\
00342                         ))
00343 
00344 #define MEM_READ_WORD(MEM, ADDR) ((ADDR%4)==0)?(MEM_READ(MEM, ADDR, word_t)):\
00345                                                 ((word_t) (( (LEFTWORD(MEM,ADDR) & READMASKSLEFT[ADDR_REM(ADDR)]) << (ADDR_REM(ADDR)*8)) |\
00346                                                         (RIGHTWORD(MEM,ADDR) >> ((4-ADDR_REM(ADDR))*8)) ))
00347 #define MEM_READ_SWORD(MEM, ADDR) ((ADDR%4)==0)?(MEM_READ(MEM, ADDR, sword_t)):\
00348                   ((sword_t) (( (LEFTWORD(MEM,ADDR) & READMASKSLEFT[ADDR_REM(ADDR)]) << (ADDR_REM(ADDR)*8)) |\
00349                      (RIGHTWORD(MEM, ADDR) >> ((4-ADDR_REM(ADDR))*8)) ))
00350 
00351 
00352 #ifdef HOST_HAS_QWORD
00353 #define MEM_READ_QWORD(MEM, ADDR)       MD_SWAPQ( ( (qword_t) (\
00354                         ( ((qword_t) (MEM_READ(MEM, ADDR, word_t))) << 32) |                                    \
00355                         ((MEM_READ(MEM, ADDR+4, word_t)))       \
00356                         ) ) )
00357 #define MEM_READ_SQWORD(MEM, ADDR)      MD_SWAPQ( ( (qword_t) (\
00358          ( ((qword_t) (MEM_READ(MEM, ADDR, word_t))) << 32) |              \
00359          ((MEM_READ(MEM, ADDR+4, word_t)))   \
00360          ) ) )
00361 
00362 #endif /* HOST_HAS_QWORD */
00363 
00364 #define MEM_WRITE_BYTE(MEM, ADDR, VAL)  MEM_WRITE(MEM, ADDR, byte_t, VAL)
00365 #define MEM_WRITE_SBYTE(MEM, ADDR, VAL) MEM_WRITE(MEM, ADDR, sbyte_t, VAL)
00366 /*
00367 #define MEM_WRITE_HALF(MEM, ADDR, VAL)                                  \
00368                                 MEM_WRITE(MEM, ADDR, half_t, MD_SWAPH(VAL))
00369 #define MEM_WRITE_SHALF(MEM, ADDR, VAL)                                 \
00370                                 MEM_WRITE(MEM, ADDR, shalf_t, MD_SWAPH(VAL))
00371 */
00372 #define MEM_WRITE_HALF(MEM, ADDR, VAL) (((ADDR)%4)==0)?MEM_WRITE(MEM, ADDR, half_t, MD_SWAPH(VAL)):\
00373                                                                         (\
00374                                                                                 (MEM_WRITE_BYTE(MEM, ADDR, ((VAL)>>8)) ),\
00375                                                                                 (MEM_WRITE_BYTE(MEM, ((ADDR)+1), ((VAL)&0xFF)) )\
00376                                                                         )
00377 #define MEM_WRITE_SHALF(MEM, ADDR, VAL) (((ADDR)%4)==0)?MEM_WRITE(MEM, ADDR, shalf_t, MD_SWAPH(VAL)):\
00378                            (\
00379                               (MEM_WRITE_BYTE(MEM, ADDR, ((VAL)>>8)) ),\
00380                               (MEM_WRITE_BYTE(MEM, ((ADDR)+1), ((VAL)&0xFF)) )\
00381                            )
00382 
00383 /*
00384 #define MEM_WRITE_WORD(MEM, ADDR, VAL)                                  \
00385                                 MEM_WRITE(MEM, ADDR, word_t, MD_SWAPW(VAL))
00386 #define MEM_WRITE_SWORD(MEM, ADDR, VAL)                                 \
00387                                 MEM_WRITE(MEM, ADDR, sword_t, MD_SWAPW(VAL))
00388 */
00389 #define MEM_WRITE_WORD(MEM, ADDR, VAL) (((ADDR)%4)==0)?\
00390                                                                                 MEM_WRITE(MEM, (ADDR), word_t, MD_SWAPW(VAL)):\
00391                                                                                 (\
00392                                                                                 (\
00393                                                                                 MEM_WRITE(MEM, ((ADDR)-((ADDR)%4)), word_t, ((LEFTWORD(MEM, (ADDR) ) &  WRITEMASKSLEFT[ADDR_REM(ADDR)]) | (VAL >> (ADDR_REM(ADDR)*8))) )        \
00394                                                                                 ),      \
00395                                                                                 (\
00396                                                                                 MEM_WRITE(MEM, ((ADDR)-((ADDR)%4)+4), word_t, ((RIGHTWORD(MEM, (ADDR)) &  WRITEMASKSRIGHT[ADDR_REM(ADDR)]) | (VAL << ((4-ADDR_REM(ADDR))*8))) )                                                                 \
00397                                                                                 )               \
00398                                                                                 )
00399 #define MEM_WRITE_SWORD(MEM, ADDR, VAL) (((ADDR)%4)==0)?\
00400                               MEM_WRITE(MEM, ADDR, sword_t, MD_SWAPW(VAL)):\
00401                               MEM_WRITE_WORD(MEM, ADDR, VAL)
00402  
00403 
00404                                                                                         
00405 
00406 #define MEM_WRITE_SFLOAT(MEM, ADDR, VAL)                                \
00407                                 MEM_WRITE(MEM, ADDR, sfloat_t, MD_SWAPW(VAL))
00408 #define MEM_WRITE_DFLOAT(MEM, ADDR, VAL)                                \
00409                                 MEM_WRITE(MEM, ADDR, dfloat_t, MD_SWAPQ(VAL))
00410 
00411 #ifdef HOST_HAS_QWORD
00412 /*
00413 #define MEM_WRITE_QWORD(MEM, ADDR, VAL)                                 \
00414                                 MEM_WRITE(MEM, ADDR, qword_t, MD_SWAPQ(VAL))
00415 #define MEM_WRITE_SQWORD(MEM, ADDR, VAL)                                \
00416                                 MEM_WRITE(MEM, ADDR, sqword_t, MD_SWAPQ(VAL))
00417 */
00418 #define MEM_WRITE_QWORD(MEM, ADDR, VAL) \
00419                                                                         (MEM_WRITE_WORD(MEM, ADDR, (((qword_t) (VAL))>>32))  , MEM_WRITE_WORD(MEM, ADDR, ((VAL)&0xFFFFFFFF)))
00420 #define MEM_WRITE_SQWORD(MEM, ADDR, VAL) \
00421                                                                         MEM_WRITE_QWORD(MEM, ADDR, VAL)
00422 
00423 #endif /* HOST_HAS_QWORD */
00424 
00425 /* create a flat memory space */
00426 struct mem_t *
00427 mem_create(char *name);                 /* name of the memory space */
00428            
00429 /* translate address ADDR in memory space MEM, returns pointer to host page */
00430 byte_t *
00431 mem_translate( mem_t *mem,      /* memory space to access */
00432               md_addr_t addr);          /* virtual address to translate */
00433 
00434 /* allocate a memory page */
00435 void
00436 mem_newpage( mem_t *mem,                /* memory space to allocate in */
00437             md_addr_t addr);            /* virtual address to allocate */
00438 
00439 /* generic memory access function, it's safe because alignments and permissions
00440    are checked, handles any natural transfer sizes; note, faults out if nbytes
00441    is not a power-of-two or larger then MD_PAGE_SIZE */
00442 enum md_fault_type
00443 mem_access( mem_t *mem,         /* memory space to access */
00444            enum mem_cmd cmd,            /* Read (from sim mem) or Write */
00445            md_addr_t addr,              /* target address to access */
00446            void *vp,                    /* host memory address to access */
00447            int nbytes);                 /* number of bytes to access */
00448 
00449 /* register memory system-specific statistics */
00450 void
00451 mem_reg_stats( mem_t *mem,      /* memory space to declare */
00452                stat_sdb_t *sdb);        /* stats data base */
00453 
00454 /* initialize memory system, call before loader.c */
00455 void
00456 mem_init( mem_t *mem);  /* memory space to initialize */
00457 
00458 /* dump a block of memory, returns any faults encountered */
00459 enum md_fault_type
00460 mem_dump( mem_t *mem,           /* memory space to display */
00461          md_addr_t addr,                /* target address to dump */
00462          int len,                       /* number bytes to dump */
00463          FILE *stream);                 /* output stream */
00464 
00465 
00466 /*
00467  * memory accessor routines, these routines require a memory access function
00468  * definition to access memory, the memory access function provides a "hook"
00469  * for programs to instrument memory accesses, this is used by various
00470  * simulators for various reasons; for the default operation - direct access
00471  * to the memory system, pass mem_access() as the memory access function
00472  */
00473 
00474 /* copy a '\0' terminated string to/from simulated memory space, returns
00475    the number of bytes copied, returns any fault encountered */
00476 enum md_fault_type
00477 mem_strcpy(mem_access_fn mem_fn,        /* user-specified memory accessor */
00478             mem_t *mem,         /* memory space to access */
00479            enum mem_cmd cmd,            /* Read (from sim mem) or Write */
00480            md_addr_t addr,              /* target address to access */
00481            char *s);                    /* host memory string buffer */
00482 
00483 /* copy NBYTES to/from simulated memory space, returns any faults */
00484 enum md_fault_type
00485 mem_bcopy(mem_access_fn mem_fn,         /* user-specified memory accessor */
00486            mem_t *mem,          /* memory space to access */
00487           enum mem_cmd cmd,             /* Read (from sim mem) or Write */
00488           md_addr_t addr,               /* target address to access */
00489           void *vp,                     /* host memory address to access */
00490           int nbytes);                  /* number of bytes to access */
00491 
00492 /* copy NBYTES to/from simulated memory space, NBYTES must be a multiple
00493    of 4 bytes, this function is faster than mem_bcopy(), returns any
00494    faults encountered */
00495 enum md_fault_type
00496 mem_bcopy4(mem_access_fn mem_fn,        /* user-specified memory accessor */
00497             mem_t *mem,         /* memory space to access */
00498            enum mem_cmd cmd,            /* Read (from sim mem) or Write */
00499            md_addr_t addr,              /* target address to access */
00500            void *vp,                    /* host memory address to access */
00501            int nbytes);                 /* number of bytes to access */
00502 
00503 /* zero out NBYTES of simulated memory, returns any faults encountered */
00504 enum md_fault_type
00505 mem_bzero(mem_access_fn mem_fn,         /* user-specified memory accessor */
00506            mem_t *mem,          /* memory space to access */
00507           md_addr_t addr,               /* target address to access */
00508           int nbytes);                  /* number of bytes to clear */
00509 
00510 #endif /* MEMORY_H */

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