os/boardsupport/emulator/emulatorbsp/wpdpack/include/memory_t.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/emulator/emulatorbsp/wpdpack/include/memory_t.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,133 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001 - 2005 NetGroup, Politecnico di Torino (Italy)
     1.6 + * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + *
    1.13 + * 1. Redistributions of source code must retain the above copyright
    1.14 + * notice, this list of conditions and the following disclaimer.
    1.15 + * 2. Redistributions in binary form must reproduce the above copyright
    1.16 + * notice, this list of conditions and the following disclaimer in the
    1.17 + * documentation and/or other materials provided with the distribution.
    1.18 + * 3. Neither the name of the Politecnico di Torino, CACE Technologies 
    1.19 + * nor the names of its contributors may be used to endorse or promote 
    1.20 + * products derived from this software without specific prior written 
    1.21 + * permission.
    1.22 + *
    1.23 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.24 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.25 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.26 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    1.27 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    1.28 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    1.29 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    1.30 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    1.31 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    1.32 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    1.33 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.34 + *
    1.35 + */
    1.36 +
    1.37 +#ifndef __memory_t
    1.38 +#define __memory_t
    1.39 +
    1.40 +#define		uint8	UCHAR
    1.41 +#define		int8	CHAR
    1.42 +#define		uint16	USHORT
    1.43 +#define		int16	SHORT
    1.44 +#define		uint32	ULONG
    1.45 +#define		int32	LONG
    1.46 +#define		uint64	ULONGLONG
    1.47 +#define		int64	LONGLONG
    1.48 +
    1.49 +/*memory type*/
    1.50 +typedef struct __MEM_TYPE
    1.51 +{
    1.52 +	uint8 *buffer;
    1.53 +	uint32 size;
    1.54 +}  MEM_TYPE, *PMEM_TYPE;
    1.55 +
    1.56 +#define LONG_AT(base,offset) (*(int32*)((uint8*)base+(uint32)offset))
    1.57 +
    1.58 +#define ULONG_AT(base,offset) (*(uint32*)((uint8*)base+(uint32)offset))
    1.59 +
    1.60 +#define SHORT_AT(base,offset) (*(int16*)((uint8*)base+(uint32)offset))
    1.61 +
    1.62 +#define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
    1.63 +
    1.64 +__inline int32 SW_LONG_AT(void *b, uint32 c)
    1.65 +{
    1.66 +	return	((int32)*((uint8 *)b+c)<<24|
    1.67 +		 (int32)*((uint8 *)b+c+1)<<16|
    1.68 +		 (int32)*((uint8 *)b+c+2)<<8|
    1.69 +		 (int32)*((uint8 *)b+c+3)<<0);
    1.70 +}
    1.71 +
    1.72 +
    1.73 +__inline uint32 SW_ULONG_AT(void *b, uint32 c)
    1.74 +{
    1.75 +	return	((uint32)*((uint8 *)b+c)<<24|
    1.76 +		 (uint32)*((uint8 *)b+c+1)<<16|
    1.77 +		 (uint32)*((uint8 *)b+c+2)<<8|
    1.78 +		 (uint32)*((uint8 *)b+c+3)<<0);
    1.79 +}
    1.80 +
    1.81 +__inline int16 SW_SHORT_AT(void *b, uint32 os)
    1.82 +{
    1.83 +	return ((int16)
    1.84 +		((int16)*((uint8 *)b+os+0)<<8|
    1.85 +		 (int16)*((uint8 *)b+os+1)<<0));
    1.86 +}
    1.87 +
    1.88 +__inline uint16 SW_USHORT_AT(void *b, uint32 os)
    1.89 +{
    1.90 +	return ((uint16)
    1.91 +		((uint16)*((uint8 *)b+os+0)<<8|
    1.92 +		 (uint16)*((uint8 *)b+os+1)<<0));
    1.93 +}
    1.94 +
    1.95 +__inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
    1.96 +{
    1.97 +	*((uint8*)dst+0)=*((uint8*)&src+3);
    1.98 +	*((uint8*)dst+1)=*((uint8*)&src+2);
    1.99 +	*((uint8*)dst+2)=*((uint8*)&src+1);
   1.100 +	*((uint8*)dst+3)=*((uint8*)&src+0);
   1.101 +
   1.102 +}
   1.103 +
   1.104 +#ifdef WIN_NT_DRIVER
   1.105 +
   1.106 +#define ALLOCATE_MEMORY(dest,type,amount) \
   1.107 +	  (dest)=ExAllocatePoolWithTag(NonPagedPool,sizeof(type)*(amount), '0TWA');
   1.108 +#define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
   1.109 +	{ \
   1.110 +		(dest)=ExAllocatePoolWithTag(NonPagedPool,sizeof(type)*(amount), '1TWA'); \
   1.111 +		if ((dest)!=NULL) \
   1.112 +			RtlZeroMemory((dest),sizeof(type)*(amount)); \
   1.113 +	}	
   1.114 +
   1.115 +#define FREE_MEMORY(dest) ExFreePool(dest);
   1.116 +#define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
   1.117 +#define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
   1.118 +
   1.119 +#else
   1.120 +
   1.121 +#define ALLOCATE_MEMORY(dest,type,amount) \
   1.122 +	  (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
   1.123 +#define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
   1.124 +	  (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
   1.125 +
   1.126 +#define FREE_MEMORY(dest) GlobalFree(dest);
   1.127 +#define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
   1.128 +#define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
   1.129 +
   1.130 +
   1.131 +#endif /*WIN_NT_DRIVER*/
   1.132 +
   1.133 +
   1.134 +
   1.135 +#endif 
   1.136 +