branch update for HEAD-2003021201
[reactos.git] / drivers / net / packet / memory_t.h
1 /*
2  * Copyright (c) 2001
3  *  Politecnico di Torino.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that: (1) source code distributions
7  * retain the above copyright notice and this paragraph in its entirety, (2)
8  * distributions including binary code include the above copyright notice and
9  * this paragraph in its entirety in the documentation or other materials
10  * provided with the distribution, and (3) all advertising materials mentioning
11  * features or use of this software display the following acknowledgement:
12  * ``This product includes software developed by the Politecnico
13  * di Torino, and its contributors.'' Neither the name of
14  * the University nor the names of its contributors may be used to endorse
15  * or promote products derived from this software without specific prior
16  * written permission.
17  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20  */
21
22 #ifndef __memory_t
23 #define __memory_t
24
25 #define     uint8   UCHAR
26 #define     int8    CHAR
27 #define     uint16  USHORT
28 #define     int16   SHORT
29 #define     uint32  ULONG
30 #define     int32   LONG
31 #define     uint64  ULONGLONG
32 #define     int64   LONGLONG
33
34 /*memory type*/
35 typedef struct __MEM_TYPE
36 {
37     uint8 *buffer;
38     uint32 size;
39 }  MEM_TYPE, *PMEM_TYPE;
40
41 #define LONG_AT(base,offset) (*(int32*)((uint8*)base+(uint32)offset))
42
43 #define ULONG_AT(base,offset) (*(uint32*)((uint8*)base+(uint32)offset))
44
45 #define SHORT_AT(base,offset) (*(int16*)((uint8*)base+(uint32)offset))
46
47 #define USHORT_AT(base,offset) (*(uint16*)((uint8*)base+(uint32)offset))
48
49 #ifdef __GNUC__
50 #define __inline inline
51 #define _USE_SW_FUNCS_
52 #endif
53
54 #ifdef _USE_SW_FUNCS_
55
56 inline int32 SW_LONG_AT(void *b, uint32 c);
57 inline uint32 SW_ULONG_AT(void *b, uint32 c);
58 inline int16 SW_SHORT_AT(void *b, uint32 os);
59 inline uint16 SW_USHORT_AT(void *b, uint32 os);
60 inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src);
61
62 #else /*_USE_SW_FUNCS_*/
63
64 __inline int32 SW_LONG_AT(void *b, uint32 c)
65 {
66     return  ((int32)*((uint8 *)b+c)<<24|
67          (int32)*((uint8 *)b+c+1)<<16|
68          (int32)*((uint8 *)b+c+2)<<8|
69          (int32)*((uint8 *)b+c+3)<<0);
70 }
71
72 __inline uint32 SW_ULONG_AT(void *b, uint32 c)
73 {
74     return  ((uint32)*((uint8 *)b+c)<<24|
75          (uint32)*((uint8 *)b+c+1)<<16|
76          (uint32)*((uint8 *)b+c+2)<<8|
77          (uint32)*((uint8 *)b+c+3)<<0);
78 }
79
80 __inline int16 SW_SHORT_AT(void *b, uint32 os)
81 {
82     return ((int16)
83         ((int16)*((uint8 *)b+os+0)<<8|
84          (int16)*((uint8 *)b+os+1)<<0));
85 }
86
87 __inline uint16 SW_USHORT_AT(void *b, uint32 os)
88 {
89     return ((uint16)
90         ((uint16)*((uint8 *)b+os+0)<<8|
91          (uint16)*((uint8 *)b+os+1)<<0));
92 }
93
94 __inline VOID SW_ULONG_ASSIGN(void *dst, uint32 src)
95 {
96     *((uint8*)dst+0)=*((uint8*)&src+3);
97     *((uint8*)dst+1)=*((uint8*)&src+2);
98     *((uint8*)dst+2)=*((uint8*)&src+1);
99     *((uint8*)dst+3)=*((uint8*)&src+0);
100
101 }
102
103 #endif /*_USE_SW_FUNCS_*/
104
105 #ifdef WIN_NT_DRIVER
106
107 #define ALLOCATE_MEMORY(dest,type,amount) \
108       (dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount));
109 #define ALLOCATE_ZERO_MEMORY(dest,type,amount) \
110     { \
111         (dest)=ExAllocatePool(NonPagedPool,sizeof(type)*(amount)); \
112         if ((dest)!=NULL) \
113             RtlZeroMemory((dest),sizeof(type)*(amount)); \
114     }   
115
116 #define FREE_MEMORY(dest) ExFreePool(dest);
117 #define ZERO_MEMORY(dest,amount) RtlZeroMemory(dest,amount);
118 #define COPY_MEMORY(dest,src,amount) RtlCopyMemory(dest,src,amount);
119
120 #endif /*WIN_NT_DRIVER*/
121
122
123 #endif 
124