Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

physmem.hh

Go to the documentation of this file.
00001 /***********************************************************************
00002 * File: physmem.hh
00003 * Purpose: Define the PHYSMEM_HANDLE class which creates objects that represent
00004 *  a portable interface to sections of physical memory.
00005 * NOTES:
00006 *  On some platforms accessing a block of physical memory is a simple as
00007 * intitializing a pointer and then dereferencing it, but accessing specific
00008 * sections of extended memory under DOS or Windows requires changing the
00009 * descriptor tables and therefore circumventing protected mode security.
00010 * Other platforms require the use of mmap on memory device files to choose
00011 * a section of memory mapped IO.
00012 ***********************************************************************/
00013 
00014 #ifndef PHYSMEM_HH
00015 #define PHYSMEM_HH
00016 
00017 #include "rcs_defs.hh"          /* _Windows, RCS_FAR, EXTERN_C_STD_HEADERS */
00018 
00019 #ifdef  EXTERN_C_STD_HEADERS
00020 extern "C"
00021 {
00022 #endif
00023 
00024 #ifndef UNDER_CE
00025 #include <stddef.h>             /* size_t */
00026 #endif
00027 
00028 #ifdef EXTERN_C_STD_HEADERS
00029 }
00030 #endif
00031 
00032 
00033 #ifdef USE_BIT3
00034 #ifndef USING_BIT3
00035 #define USING_BIT3
00036 #endif
00037 #endif
00038 
00039 #ifdef USING_BIT3
00040 #ifndef USE_BIT3
00041 #define USE_BIT3
00042 #endif
00043 #endif
00044 
00045 
00046 #ifdef WIN16
00047 #include <windows.h>            /* LPBYTE, WORD */
00048 typedef LPBYTE LOCAL_ADDRESS_TYPE;
00049 #else
00050 typedef char RCS_FAR *LOCAL_ADDRESS_TYPE;
00051 #endif
00052 
00053 #if defined(WIN32) && !defined(gnuwin32)
00054 #if defined(WIN32) && !defined(USE_OLD_WINSOCK)
00055 /* Lame problem if windows.h is included before winsock2.h many redefined
00056  compiler errors result. */
00057 #include <winsock2.h>
00058 #endif
00059 #include <windows.h>            /* HANDLE */
00060 #include "mapmem.h"             /* PHYSICAL_MEMORY_INFO */
00061 #include "gpioctl.h"            /* GENPORT_WRITE_INPUT */
00062 #endif
00063 
00064 #if defined(USE_BIT3) && defined(WIN32)
00065 #include "btapi.h"
00066 #endif
00067 
00068 /* ADDRESS TYPE MACROS --
00069 * Under Windows Pass one of these as the _address_code for
00070 * PHYSMEM_HANDLE */
00071 #define NT_ISA_MEM_ADDRESS      ((long) 1)
00072 #define NT_ISA_IO_ADDRESS       ((long) 2)
00073 
00074 class RCS_EXPORT PHYSMEM_HANDLE
00075 {
00076 public:
00077   PHYSMEM_HANDLE ();            /* Constructor for blank handle. */
00078 #if defined(USE_BIT3) && defined(WIN32)
00079   PHYSMEM_HANDLE (bt_desc_t _btd, unsigned long _btd_offset, long _size,
00080                   int _swap_mode);
00081 #endif
00082 
00083   /* Constructor to access memory starting at _physical_address, for _size
00084      bytes. Some platform implementations distinguish between various types of
00085      addresses using the address code. */
00086     PHYSMEM_HANDLE (unsigned long _physical_address,
00087                     long _address_code, long _size);
00088 
00089     virtual ~ PHYSMEM_HANDLE ();        /* Destructor */
00090 
00091   long offset;                  /* Operations read and write work use offset */
00092   long size;
00093   int read (void *_to, long _read_size);        /* Read _read_size bytes and store */
00094   /* at _to */
00095   int write (void *_from, long _write_size);    /* Write _write_size bytes */
00096   /* using data at _from */
00097 
00098   void set_to_ptr (void *_ptr, long size);      /* Use the physical memory at _ptr. */
00099 
00100   long address_code;            /* Platform specific address type code. */
00101   /* (See vme.h for VXWORKS) */
00102 
00103   void memsetf (long offset, char _byte, long _memset_size);
00104   int clear_memory ();
00105   int valid ();
00106   int isvalid;
00107   char *temp_buf;
00108   unsigned long physical_address;
00109   LOCAL_ADDRESS_TYPE local_address;
00110 protected:
00111 #ifdef VXWORKS
00112   char RCS_FAR *bus_address;
00113 #endif
00114 #ifdef WIN16
00115   WORD selector;
00116 #endif
00117 #if defined(WIN32) && !defined(gnuwin32)
00118   HANDLE hMapMemDriver;
00119   HANDLE hGenPortDriver;
00120   PHYSICAL_MEMORY_INFO pmi;
00121   GENPORT_WRITE_INPUT gpwi;
00122   WORD ioport;
00123   int read_from_genport (void *, long);
00124   int read_dword_from_genport (DWORD *, ULONG);
00125   int read_word_from_genport (WORD *, ULONG);
00126   int read_byte_from_genport (BYTE *, ULONG);
00127   int write_to_genport (void *, long);
00128   int write_dword_to_genport (DWORD, ULONG);
00129   int write_word_to_genport (WORD, ULONG);
00130   int write_byte_to_genport (BYTE, ULONG);
00131 #endif
00132 
00133 #ifdef lynxosPC
00134   char smem_name[40];
00135 #endif
00136 
00137 public:
00138 
00139 #if defined(USE_BIT3) && defined(WIN32)
00140     bt_desc_t btd;
00141   unsigned long btd_offset;
00142   int swap_mode;
00143   bt_msec_t bt_lock_timeout;
00144   int bt_use_lock;
00145   bt_error_t bt_status;         /* Mirror API return value */
00146 #endif
00147   int using_bit3;
00148   double total_bytes_moved;
00149   int enable_byte_counting;
00150 };
00151 
00152 #endif

Generated on Sun Dec 2 15:56:51 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001