os/boardsupport/emulator/emulatorbsp/wpdpack/include/memory_t.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2  * Copyright (c) 2001 - 2005 NetGroup, Politecnico di Torino (Italy)
     3  * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
     4  * All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions
     8  * are met:
     9  *
    10  * 1. Redistributions of source code must retain the above copyright
    11  * notice, this list of conditions and the following disclaimer.
    12  * 2. Redistributions in binary form must reproduce the above copyright
    13  * notice, this list of conditions and the following disclaimer in the
    14  * documentation and/or other materials provided with the distribution.
    15  * 3. Neither the name of the Politecnico di Torino, CACE Technologies 
    16  * nor the names of its contributors may be used to endorse or promote 
    17  * products derived from this software without specific prior written 
    18  * permission.
    19  *
    20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    31  *
    32  */
    33 
    34 #ifndef __memory_t
    35 #define __memory_t
    36 
    37 #define		uint8	UCHAR
    38 #define		int8	CHAR
    39 #define		uint16	USHORT
    40 #define		int16	SHORT
    41 #define		uint32	ULONG
    42 #define		int32	LONG
    43 #define		uint64	ULONGLONG
    44 #define		int64	LONGLONG
    45 
    46 /*memory type*/
    47 typedef struct __MEM_TYPE
    48 {
    49 	uint8 *buffer;
    50 	uint32 size;
    51 }  MEM_TYPE, *PMEM_TYPE;
    52 
    53 #define LONG_AT(base,offset) (*(int32*)((uint8*)base+(uint32)offset))
    54 
    55 #define ULONG_AT(base,offset) (*(uint32*)((uint8*)base+(uint32)offset))
    56 
    57 #define SHORT_AT(base,offset) (*(int16*)((uint8*)base+(uint32)offset))
    58 
    59 #define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
    60 
    61 __inline int32 SW_LONG_AT(void *b, uint32 c)
    62 {
    63 	return	((int32)*((uint8 *)b+c)<<24|
    64 		 (int32)*((uint8 *)b+c+1)<<16|
    65 		 (int32)*((uint8 *)b+c+2)<<8|
    66 		 (int32)*((uint8 *)b+c+3)<<0);
    67 }
    68 
    69 
    70 __inline uint32 SW_ULONG_AT(void *b, uint32 c)
    71 {
    72 	return	((uint32)*((uint8 *)b+c)<<24|
    73 		 (uint32)*((uint8 *)b+c+1)<<16|
    74 		 (uint32)*((uint8 *)b+c+2)<<8|
    75 		 (uint32)*((uint8 *)b+c+3)<<0);
    76 }
    77 
    78 __inline int16 SW_SHORT_AT(void *b, uint32 os)
    79 {
    80 	return ((int16)
    81 		((int16)*((uint8 *)b+os+0)<<8|
    82 		 (int16)*((uint8 *)b+os+1)<<0));
    83 }
    84 
    85 __inline uint16 SW_USHORT_AT(void *b, uint32 os)
    86 {
    87 	return ((uint16)
    88 		((uint16)*((uint8 *)b+os+0)<<8|
    89 		 (uint16)*((uint8 *)b+os+1)<<0));
    90 }
    91 
    92 __inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
    93 {
    94 	*((uint8*)dst+0)=*((uint8*)&src+3);
    95 	*((uint8*)dst+1)=*((uint8*)&src+2);
    96 	*((uint8*)dst+2)=*((uint8*)&src+1);
    97 	*((uint8*)dst+3)=*((uint8*)&src+0);
    98 
    99 }
   100 
   101 #ifdef WIN_NT_DRIVER
   102 
   103 #define ALLOCATE_MEMORY(dest,type,amount) \
   104 	  (dest)=ExAllocatePoolWithTag(NonPagedPool,sizeof(type)*(amount), '0TWA');
   105 #define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
   106 	{ \
   107 		(dest)=ExAllocatePoolWithTag(NonPagedPool,sizeof(type)*(amount), '1TWA'); \
   108 		if ((dest)!=NULL) \
   109 			RtlZeroMemory((dest),sizeof(type)*(amount)); \
   110 	}	
   111 
   112 #define FREE_MEMORY(dest) ExFreePool(dest);
   113 #define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
   114 #define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
   115 
   116 #else
   117 
   118 #define ALLOCATE_MEMORY(dest,type,amount) \
   119 	  (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
   120 #define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
   121 	  (dest)=(type*)GlobalAlloc(GPTR, sizeof(type)*(amount));
   122 
   123 #define FREE_MEMORY(dest) GlobalFree(dest);
   124 #define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
   125 #define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
   126 
   127 
   128 #endif /*WIN_NT_DRIVER*/
   129 
   130 
   131 
   132 #endif 
   133