1 |
145 |
lanttu |
/*
|
2 |
|
|
* Copyright (c) 2010, Mentor Graphics Corporation
|
3 |
|
|
* All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
7 |
|
|
*
|
8 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
9 |
|
|
* this list of conditions and the following disclaimer.
|
10 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
11 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
12 |
|
|
* and/or other materials provided with the distribution.
|
13 |
|
|
* 3. Neither the name of the <ORGANIZATION> nor the names of its contributors
|
14 |
|
|
* may be used to endorse or promote products derived from this software
|
15 |
|
|
* without specific prior written permission.
|
16 |
|
|
*
|
17 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
18 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
21 |
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
22 |
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
23 |
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
24 |
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
25 |
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
26 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
28 |
|
|
*/
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
#include <openmcapi.h>
|
33 |
|
|
|
34 |
|
|
/*************************************************************************
|
35 |
|
|
*
|
36 |
|
|
* FUNCTION
|
37 |
|
|
*
|
38 |
|
|
* mcapi_get64
|
39 |
|
|
*
|
40 |
|
|
* DESCRIPTION
|
41 |
|
|
*
|
42 |
|
|
* This function takes a memory area and an offset into the area. At
|
43 |
|
|
* this offset, 64bits will be read and returned in the target
|
44 |
|
|
* hardware byte order.
|
45 |
|
|
*
|
46 |
|
|
* INPUTS
|
47 |
|
|
*
|
48 |
|
|
* unsigned char *ptr Pointer to the start of the memory area.
|
49 |
|
|
* unsigned int offset Offset into memory area to get the 64bits
|
50 |
|
|
* from.
|
51 |
|
|
*
|
52 |
|
|
* OUTPUTS
|
53 |
|
|
*
|
54 |
|
|
* unsigned long The 64bits that were read.
|
55 |
|
|
*
|
56 |
|
|
************************************************************************/
|
57 |
|
|
unsigned long long mcapi_get64(unsigned char *ptr, unsigned int offset)
|
58 |
|
|
{
|
59 |
|
|
unsigned char *p = ptr + offset;
|
60 |
|
|
|
61 |
|
|
return ((unsigned long long)p[0] << 56) +
|
62 |
|
|
((unsigned long long)p[1] << 48) +
|
63 |
|
|
((unsigned long long)p[2] << 40) +
|
64 |
|
|
((unsigned long long)p[3] << 32) +
|
65 |
|
|
((unsigned long long)p[4] << 24) +
|
66 |
|
|
((unsigned long long)p[5] << 16) +
|
67 |
|
|
((unsigned long long)p[6] << 8) +
|
68 |
|
|
(unsigned long long)p[7];
|
69 |
|
|
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/*************************************************************************
|
73 |
|
|
*
|
74 |
|
|
* FUNCTION
|
75 |
|
|
*
|
76 |
|
|
* mcapi_put64
|
77 |
|
|
*
|
78 |
|
|
* DESCRIPTION
|
79 |
|
|
*
|
80 |
|
|
* This function takes a memory area and an offset into the area. At
|
81 |
|
|
* this offset, 64bits will be written in network byte order.
|
82 |
|
|
*
|
83 |
|
|
* INPUTS
|
84 |
|
|
*
|
85 |
|
|
* unsigned char *ptr Pointer to the start of the memory area.
|
86 |
|
|
* unsigned int offset Offset into memory area to get the 64bits
|
87 |
|
|
* from.
|
88 |
|
|
* unsigned long value 64bits to be written to memory
|
89 |
|
|
*
|
90 |
|
|
* OUTPUTS
|
91 |
|
|
*
|
92 |
|
|
* None
|
93 |
|
|
*
|
94 |
|
|
*************************************************************************/
|
95 |
|
|
void mcapi_put64(unsigned char *ptr, unsigned int offset, unsigned long long value)
|
96 |
|
|
{
|
97 |
|
|
unsigned char *p = ptr + offset;
|
98 |
|
|
|
99 |
|
|
*p++ = (unsigned char)(value >> 56);
|
100 |
|
|
*p++ = (unsigned char)(value >> 48);
|
101 |
|
|
*p++ = (unsigned char)(value >> 40);
|
102 |
|
|
*p++ = (unsigned char)(value >> 32);
|
103 |
|
|
*p++ = (unsigned char)(value >> 24);
|
104 |
|
|
*p++ = (unsigned char)(value >> 16);
|
105 |
|
|
*p++ = (unsigned char)(value >> 8);
|
106 |
|
|
*p = (unsigned char)value;
|
107 |
|
|
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
/*************************************************************************
|
111 |
|
|
*
|
112 |
|
|
* FUNCTION
|
113 |
|
|
*
|
114 |
|
|
* mcapi_get32
|
115 |
|
|
*
|
116 |
|
|
* DESCRIPTION
|
117 |
|
|
*
|
118 |
|
|
* This function takes a memory area and an offset into the area. At
|
119 |
|
|
* this offset, 32bits will be read and returned in the target
|
120 |
|
|
* hardware byte order.
|
121 |
|
|
*
|
122 |
|
|
* INPUTS
|
123 |
|
|
*
|
124 |
|
|
* unsigned char *ptr Pointer to the start of the memory area.
|
125 |
|
|
* unsigned int offset Offset into memory area to get the 32bits
|
126 |
|
|
* from.
|
127 |
|
|
*
|
128 |
|
|
* OUTPUTS
|
129 |
|
|
*
|
130 |
|
|
* unsigned long The 32bits that were read.
|
131 |
|
|
*
|
132 |
|
|
************************************************************************/
|
133 |
|
|
unsigned long mcapi_get32(unsigned char *ptr, unsigned int offset)
|
134 |
|
|
{
|
135 |
|
|
unsigned char *p = ptr + offset;
|
136 |
|
|
|
137 |
|
|
return ((unsigned long)p[0] << 24) +
|
138 |
|
|
((unsigned long)p[1] << 16) +
|
139 |
|
|
((unsigned long)p[2] << 8) +
|
140 |
|
|
(unsigned long)p[3];
|
141 |
|
|
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
/*************************************************************************
|
145 |
|
|
*
|
146 |
|
|
* FUNCTION
|
147 |
|
|
*
|
148 |
|
|
* mcapi_put32
|
149 |
|
|
*
|
150 |
|
|
* DESCRIPTION
|
151 |
|
|
*
|
152 |
|
|
* This function takes a memory area and an offset into the area. At
|
153 |
|
|
* this offset, 32bits will be written in network byte order.
|
154 |
|
|
*
|
155 |
|
|
* INPUTS
|
156 |
|
|
*
|
157 |
|
|
* unsigned char *ptr Pointer to the start of the memory area.
|
158 |
|
|
* unsigned int offset Offset into memory area to get the 32bits
|
159 |
|
|
* from.
|
160 |
|
|
* unsigned long value 32bits to be written to memory
|
161 |
|
|
*
|
162 |
|
|
* OUTPUTS
|
163 |
|
|
*
|
164 |
|
|
* None
|
165 |
|
|
*
|
166 |
|
|
*************************************************************************/
|
167 |
|
|
void mcapi_put32(unsigned char *ptr, unsigned int offset, unsigned long value)
|
168 |
|
|
{
|
169 |
|
|
unsigned char *p = ptr + offset;
|
170 |
|
|
|
171 |
|
|
*p++ = (unsigned char)(value >> 24);
|
172 |
|
|
*p++ = (unsigned char)(value >> 16);
|
173 |
|
|
*p++ = (unsigned char)(value >> 8);
|
174 |
|
|
*p = (unsigned char)value;
|
175 |
|
|
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
/*************************************************************************
|
179 |
|
|
*
|
180 |
|
|
* FUNCTION
|
181 |
|
|
*
|
182 |
|
|
* mcapi_get16
|
183 |
|
|
*
|
184 |
|
|
* DESCRIPTION
|
185 |
|
|
*
|
186 |
|
|
* This function takes a memory area and an offset into the area. At
|
187 |
|
|
* this offset, 16bits will be read and returned in the target
|
188 |
|
|
* hardware byte order.
|
189 |
|
|
*
|
190 |
|
|
* INPUTS
|
191 |
|
|
*
|
192 |
|
|
* unsigned char *ptr Pointer to the start of the memory area.
|
193 |
|
|
* unsigned int offset Offset into memory area to get the 32bits
|
194 |
|
|
* from.
|
195 |
|
|
*
|
196 |
|
|
* OUTPUTS
|
197 |
|
|
*
|
198 |
|
|
* unsigned short The 16bits that were read.
|
199 |
|
|
*
|
200 |
|
|
************************************************************************/
|
201 |
|
|
unsigned short mcapi_get16(unsigned char *ptr, unsigned int offset)
|
202 |
|
|
{
|
203 |
|
|
unsigned char *p = ptr + offset;
|
204 |
|
|
|
205 |
|
|
return (unsigned short)((p[0] << 8) + p[1]);
|
206 |
|
|
|
207 |
|
|
}
|
208 |
|
|
|
209 |
|
|
/*************************************************************************
|
210 |
|
|
*
|
211 |
|
|
* FUNCTION
|
212 |
|
|
*
|
213 |
|
|
* mcapi_put16
|
214 |
|
|
*
|
215 |
|
|
* DESCRIPTION
|
216 |
|
|
*
|
217 |
|
|
* This function takes a memory area and an offset into the area. At
|
218 |
|
|
* this offset, 16bits will be written in network byte order.
|
219 |
|
|
*
|
220 |
|
|
* INPUTS
|
221 |
|
|
*
|
222 |
|
|
* unsigned char *ptr Pointer to the start of the memory area.
|
223 |
|
|
* unsigned int offset Offset into memory area to get the 32bits
|
224 |
|
|
* from.
|
225 |
|
|
* unsigned short value 16bits to be written to memory
|
226 |
|
|
*
|
227 |
|
|
* OUTPUTS
|
228 |
|
|
*
|
229 |
|
|
* None
|
230 |
|
|
*
|
231 |
|
|
************************************************************************/
|
232 |
|
|
void mcapi_put16(unsigned char *ptr, unsigned int offset, unsigned short value)
|
233 |
|
|
{
|
234 |
|
|
unsigned char *p = ptr + offset;
|
235 |
|
|
|
236 |
|
|
*p++ = (unsigned char)(value >> 8);
|
237 |
|
|
*p = (unsigned char)value;
|
238 |
|
|
|
239 |
|
|
}
|