xref: /freebsd/sys/contrib/ncsw/etc/memcpy.c (revision 0aeed3e99367bed5755068d9218cd8041644ff2b)
1*0aeed3e9SJustin Hibbits /* Copyright (c) 2008-2011 Freescale Semiconductor, Inc.
2*0aeed3e9SJustin Hibbits  * All rights reserved.
3*0aeed3e9SJustin Hibbits  *
4*0aeed3e9SJustin Hibbits  * Redistribution and use in source and binary forms, with or without
5*0aeed3e9SJustin Hibbits  * modification, are permitted provided that the following conditions are met:
6*0aeed3e9SJustin Hibbits  *     * Redistributions of source code must retain the above copyright
7*0aeed3e9SJustin Hibbits  *       notice, this list of conditions and the following disclaimer.
8*0aeed3e9SJustin Hibbits  *     * Redistributions in binary form must reproduce the above copyright
9*0aeed3e9SJustin Hibbits  *       notice, this list of conditions and the following disclaimer in the
10*0aeed3e9SJustin Hibbits  *       documentation and/or other materials provided with the distribution.
11*0aeed3e9SJustin Hibbits  *     * Neither the name of Freescale Semiconductor nor the
12*0aeed3e9SJustin Hibbits  *       names of its contributors may be used to endorse or promote products
13*0aeed3e9SJustin Hibbits  *       derived from this software without specific prior written permission.
14*0aeed3e9SJustin Hibbits  *
15*0aeed3e9SJustin Hibbits  *
16*0aeed3e9SJustin Hibbits  * ALTERNATIVELY, this software may be distributed under the terms of the
17*0aeed3e9SJustin Hibbits  * GNU General Public License ("GPL") as published by the Free Software
18*0aeed3e9SJustin Hibbits  * Foundation, either version 2 of that License or (at your option) any
19*0aeed3e9SJustin Hibbits  * later version.
20*0aeed3e9SJustin Hibbits  *
21*0aeed3e9SJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22*0aeed3e9SJustin Hibbits  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23*0aeed3e9SJustin Hibbits  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24*0aeed3e9SJustin Hibbits  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25*0aeed3e9SJustin Hibbits  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26*0aeed3e9SJustin Hibbits  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27*0aeed3e9SJustin Hibbits  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28*0aeed3e9SJustin Hibbits  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29*0aeed3e9SJustin Hibbits  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30*0aeed3e9SJustin Hibbits  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31*0aeed3e9SJustin Hibbits  */
32*0aeed3e9SJustin Hibbits 
33*0aeed3e9SJustin Hibbits 
34*0aeed3e9SJustin Hibbits #include "std_ext.h"
35*0aeed3e9SJustin Hibbits #include "xx_ext.h"
36*0aeed3e9SJustin Hibbits #include "memcpy_ext.h"
37*0aeed3e9SJustin Hibbits 
38*0aeed3e9SJustin Hibbits 
39*0aeed3e9SJustin Hibbits #ifdef CORE_8BIT_ACCESS_ERRATA
40*0aeed3e9SJustin Hibbits static void MY_MY_WRITE_UINT8(uint8_t *addr, uint8_t val)
41*0aeed3e9SJustin Hibbits {
42*0aeed3e9SJustin Hibbits     uint32_t newAddr, newVal;
43*0aeed3e9SJustin Hibbits     newAddr = (uint32_t)addr & ~0x3L;
44*0aeed3e9SJustin Hibbits     switch ((uint32_t)addr%4)
45*0aeed3e9SJustin Hibbits     {
46*0aeed3e9SJustin Hibbits     case (0):
47*0aeed3e9SJustin Hibbits         newVal = GET_UINT32(*(uint32_t*)newAddr);
48*0aeed3e9SJustin Hibbits         newVal = (newVal & 0x00ffffff) | (((uint32_t)val)<<24);
49*0aeed3e9SJustin Hibbits         WRITE_UINT32(*(uint32_t*)newAddr, newVal);
50*0aeed3e9SJustin Hibbits         break;
51*0aeed3e9SJustin Hibbits     case (1):
52*0aeed3e9SJustin Hibbits          newVal = GET_UINT32(*(uint32_t*)newAddr);
53*0aeed3e9SJustin Hibbits         newVal = (newVal & 0xff00ffff) | (((uint32_t)val)<<16);
54*0aeed3e9SJustin Hibbits         WRITE_UINT32(*(uint32_t*)newAddr, newVal);
55*0aeed3e9SJustin Hibbits         break;
56*0aeed3e9SJustin Hibbits     case (2):
57*0aeed3e9SJustin Hibbits         newVal = GET_UINT32(*(uint32_t*)newAddr);
58*0aeed3e9SJustin Hibbits         newVal = (newVal & 0xffff00ff) | (((uint32_t)val)<<8);
59*0aeed3e9SJustin Hibbits         WRITE_UINT32(*(uint32_t*)newAddr, newVal);
60*0aeed3e9SJustin Hibbits         break;
61*0aeed3e9SJustin Hibbits     case (3):
62*0aeed3e9SJustin Hibbits         newVal = GET_UINT32(*(uint32_t*)newAddr);
63*0aeed3e9SJustin Hibbits         newVal = (newVal & 0xffffff00) | val;
64*0aeed3e9SJustin Hibbits         WRITE_UINT32(*(uint32_t*)newAddr, newVal);
65*0aeed3e9SJustin Hibbits         break;
66*0aeed3e9SJustin Hibbits     }
67*0aeed3e9SJustin Hibbits }
68*0aeed3e9SJustin Hibbits 
69*0aeed3e9SJustin Hibbits static uint8_t MY_MY_GET_UINT8(uint8_t *addr)
70*0aeed3e9SJustin Hibbits {
71*0aeed3e9SJustin Hibbits     uint32_t newAddr, newVal=0;
72*0aeed3e9SJustin Hibbits     newAddr = (uint32_t)addr & ~0x3L;
73*0aeed3e9SJustin Hibbits     switch ((uint32_t)addr%4)
74*0aeed3e9SJustin Hibbits     {
75*0aeed3e9SJustin Hibbits     case (0):
76*0aeed3e9SJustin Hibbits         newVal = GET_UINT32(*(uint32_t*)newAddr);
77*0aeed3e9SJustin Hibbits         newVal = (newVal & 0xff000000)>>24;
78*0aeed3e9SJustin Hibbits         break;
79*0aeed3e9SJustin Hibbits     case (1):
80*0aeed3e9SJustin Hibbits         newVal = GET_UINT32(*(uint32_t*)newAddr);
81*0aeed3e9SJustin Hibbits         newVal = (newVal & 0x00ff0000)>>16;
82*0aeed3e9SJustin Hibbits         break;
83*0aeed3e9SJustin Hibbits     case (2):
84*0aeed3e9SJustin Hibbits         newVal = GET_UINT32(*(uint32_t*)newAddr);
85*0aeed3e9SJustin Hibbits         newVal = (newVal & 0x0000ff00)>>8;
86*0aeed3e9SJustin Hibbits         break;
87*0aeed3e9SJustin Hibbits     case (3):
88*0aeed3e9SJustin Hibbits         newVal = GET_UINT32(*(uint32_t*)newAddr);
89*0aeed3e9SJustin Hibbits         newVal = (newVal & 0x000000ff);
90*0aeed3e9SJustin Hibbits         break;
91*0aeed3e9SJustin Hibbits     }
92*0aeed3e9SJustin Hibbits 
93*0aeed3e9SJustin Hibbits     return (uint8_t)newVal;
94*0aeed3e9SJustin Hibbits }
95*0aeed3e9SJustin Hibbits 
96*0aeed3e9SJustin Hibbits #define MY_WRITE_UINT8(addr,val) MY_MY_WRITE_UINT8(&addr,val)
97*0aeed3e9SJustin Hibbits #define MY_GET_UINT8(addr) MY_MY_GET_UINT8(&addr)
98*0aeed3e9SJustin Hibbits #else
99*0aeed3e9SJustin Hibbits #define MY_WRITE_UINT8 WRITE_UINT8
100*0aeed3e9SJustin Hibbits #define MY_GET_UINT8   GET_UINT8
101*0aeed3e9SJustin Hibbits #endif /* CORE_8BIT_ACCESS_ERRATA */
102*0aeed3e9SJustin Hibbits 
103*0aeed3e9SJustin Hibbits 
104*0aeed3e9SJustin Hibbits void * MemCpy32(void* pDst,void* pSrc, uint32_t size)
105*0aeed3e9SJustin Hibbits {
106*0aeed3e9SJustin Hibbits     uint32_t leftAlign;
107*0aeed3e9SJustin Hibbits     uint32_t rightAlign;
108*0aeed3e9SJustin Hibbits     uint32_t lastWord;
109*0aeed3e9SJustin Hibbits     uint32_t currWord;
110*0aeed3e9SJustin Hibbits     uint32_t *p_Src32;
111*0aeed3e9SJustin Hibbits     uint32_t *p_Dst32;
112*0aeed3e9SJustin Hibbits     uint8_t  *p_Src8;
113*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
114*0aeed3e9SJustin Hibbits 
115*0aeed3e9SJustin Hibbits     p_Src8 = (uint8_t*)(pSrc);
116*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
117*0aeed3e9SJustin Hibbits     /* first copy byte by byte till the source first alignment
118*0aeed3e9SJustin Hibbits      * this step is necessary to ensure we do not even try to access
119*0aeed3e9SJustin Hibbits      * data which is before the source buffer, hence it is not ours.
120*0aeed3e9SJustin Hibbits      */
121*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Src8) & 3) && size) /* (pSrc mod 4) > 0 and size > 0 */
122*0aeed3e9SJustin Hibbits     {
123*0aeed3e9SJustin Hibbits         *p_Dst8++ = *p_Src8++;
124*0aeed3e9SJustin Hibbits         size--;
125*0aeed3e9SJustin Hibbits     }
126*0aeed3e9SJustin Hibbits 
127*0aeed3e9SJustin Hibbits     /* align destination (possibly disaligning source)*/
128*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 3) && size) /* (pDst mod 4) > 0 and size > 0 */
129*0aeed3e9SJustin Hibbits     {
130*0aeed3e9SJustin Hibbits         *p_Dst8++ = *p_Src8++;
131*0aeed3e9SJustin Hibbits         size--;
132*0aeed3e9SJustin Hibbits     }
133*0aeed3e9SJustin Hibbits 
134*0aeed3e9SJustin Hibbits     /* dest is aligned and source is not necessarily aligned */
135*0aeed3e9SJustin Hibbits     leftAlign = (uint32_t)((PTR_TO_UINT(p_Src8) & 3) << 3); /* leftAlign = (pSrc mod 4)*8 */
136*0aeed3e9SJustin Hibbits     rightAlign = 32 - leftAlign;
137*0aeed3e9SJustin Hibbits 
138*0aeed3e9SJustin Hibbits 
139*0aeed3e9SJustin Hibbits     if (leftAlign == 0)
140*0aeed3e9SJustin Hibbits     {
141*0aeed3e9SJustin Hibbits         /* source is also aligned */
142*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8);
143*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
144*0aeed3e9SJustin Hibbits         while (size >> 2) /* size >= 4 */
145*0aeed3e9SJustin Hibbits         {
146*0aeed3e9SJustin Hibbits             *p_Dst32++ = *p_Src32++;
147*0aeed3e9SJustin Hibbits             size -= 4;
148*0aeed3e9SJustin Hibbits         }
149*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32);
150*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
151*0aeed3e9SJustin Hibbits     }
152*0aeed3e9SJustin Hibbits     else
153*0aeed3e9SJustin Hibbits     {
154*0aeed3e9SJustin Hibbits         /* source is not aligned (destination is aligned)*/
155*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8 - (leftAlign >> 3));
156*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
157*0aeed3e9SJustin Hibbits         lastWord = *p_Src32++;
158*0aeed3e9SJustin Hibbits         while(size >> 3) /* size >= 8 */
159*0aeed3e9SJustin Hibbits         {
160*0aeed3e9SJustin Hibbits             currWord = *p_Src32;
161*0aeed3e9SJustin Hibbits             *p_Dst32 = (lastWord << leftAlign) | (currWord >> rightAlign);
162*0aeed3e9SJustin Hibbits             lastWord = currWord;
163*0aeed3e9SJustin Hibbits             p_Src32++;
164*0aeed3e9SJustin Hibbits             p_Dst32++;
165*0aeed3e9SJustin Hibbits             size -= 4;
166*0aeed3e9SJustin Hibbits         }
167*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
168*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32) - 4 + (leftAlign >> 3);
169*0aeed3e9SJustin Hibbits     }
170*0aeed3e9SJustin Hibbits 
171*0aeed3e9SJustin Hibbits     /* complete the left overs */
172*0aeed3e9SJustin Hibbits     while (size--)
173*0aeed3e9SJustin Hibbits         *p_Dst8++ = *p_Src8++;
174*0aeed3e9SJustin Hibbits 
175*0aeed3e9SJustin Hibbits     return pDst;
176*0aeed3e9SJustin Hibbits }
177*0aeed3e9SJustin Hibbits 
178*0aeed3e9SJustin Hibbits void * IO2IOCpy32(void* pDst,void* pSrc, uint32_t size)
179*0aeed3e9SJustin Hibbits {
180*0aeed3e9SJustin Hibbits     uint32_t leftAlign;
181*0aeed3e9SJustin Hibbits     uint32_t rightAlign;
182*0aeed3e9SJustin Hibbits     uint32_t lastWord;
183*0aeed3e9SJustin Hibbits     uint32_t currWord;
184*0aeed3e9SJustin Hibbits     uint32_t *p_Src32;
185*0aeed3e9SJustin Hibbits     uint32_t *p_Dst32;
186*0aeed3e9SJustin Hibbits     uint8_t  *p_Src8;
187*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
188*0aeed3e9SJustin Hibbits 
189*0aeed3e9SJustin Hibbits     p_Src8 = (uint8_t*)(pSrc);
190*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
191*0aeed3e9SJustin Hibbits     /* first copy byte by byte till the source first alignment
192*0aeed3e9SJustin Hibbits      * this step is necessary to ensure we do not even try to access
193*0aeed3e9SJustin Hibbits      * data which is before the source buffer, hence it is not ours.
194*0aeed3e9SJustin Hibbits      */
195*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Src8) & 3) && size) /* (pSrc mod 4) > 0 and size > 0 */
196*0aeed3e9SJustin Hibbits     {
197*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, MY_GET_UINT8(*p_Src8));
198*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
199*0aeed3e9SJustin Hibbits         size--;
200*0aeed3e9SJustin Hibbits     }
201*0aeed3e9SJustin Hibbits 
202*0aeed3e9SJustin Hibbits     /* align destination (possibly disaligning source)*/
203*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 3) && size) /* (pDst mod 4) > 0 and size > 0 */
204*0aeed3e9SJustin Hibbits     {
205*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, MY_GET_UINT8(*p_Src8));
206*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
207*0aeed3e9SJustin Hibbits         size--;
208*0aeed3e9SJustin Hibbits     }
209*0aeed3e9SJustin Hibbits 
210*0aeed3e9SJustin Hibbits     /* dest is aligned and source is not necessarily aligned */
211*0aeed3e9SJustin Hibbits     leftAlign = (uint32_t)((PTR_TO_UINT(p_Src8) & 3) << 3); /* leftAlign = (pSrc mod 4)*8 */
212*0aeed3e9SJustin Hibbits     rightAlign = 32 - leftAlign;
213*0aeed3e9SJustin Hibbits 
214*0aeed3e9SJustin Hibbits     if (leftAlign == 0)
215*0aeed3e9SJustin Hibbits     {
216*0aeed3e9SJustin Hibbits         /* source is also aligned */
217*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8);
218*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
219*0aeed3e9SJustin Hibbits         while (size >> 2) /* size >= 4 */
220*0aeed3e9SJustin Hibbits         {
221*0aeed3e9SJustin Hibbits             WRITE_UINT32(*p_Dst32, GET_UINT32(*p_Src32));
222*0aeed3e9SJustin Hibbits             p_Dst32++;p_Src32++;
223*0aeed3e9SJustin Hibbits             size -= 4;
224*0aeed3e9SJustin Hibbits         }
225*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32);
226*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
227*0aeed3e9SJustin Hibbits     }
228*0aeed3e9SJustin Hibbits     else
229*0aeed3e9SJustin Hibbits     {
230*0aeed3e9SJustin Hibbits         /* source is not aligned (destination is aligned)*/
231*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8 - (leftAlign >> 3));
232*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
233*0aeed3e9SJustin Hibbits         lastWord = GET_UINT32(*p_Src32);
234*0aeed3e9SJustin Hibbits         p_Src32++;
235*0aeed3e9SJustin Hibbits         while(size >> 3) /* size >= 8 */
236*0aeed3e9SJustin Hibbits         {
237*0aeed3e9SJustin Hibbits             currWord = GET_UINT32(*p_Src32);
238*0aeed3e9SJustin Hibbits             WRITE_UINT32(*p_Dst32, (lastWord << leftAlign) | (currWord >> rightAlign));
239*0aeed3e9SJustin Hibbits             lastWord = currWord;
240*0aeed3e9SJustin Hibbits             p_Src32++;p_Dst32++;
241*0aeed3e9SJustin Hibbits             size -= 4;
242*0aeed3e9SJustin Hibbits         }
243*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
244*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32) - 4 + (leftAlign >> 3);
245*0aeed3e9SJustin Hibbits     }
246*0aeed3e9SJustin Hibbits 
247*0aeed3e9SJustin Hibbits     /* complete the left overs */
248*0aeed3e9SJustin Hibbits     while (size--)
249*0aeed3e9SJustin Hibbits     {
250*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, MY_GET_UINT8(*p_Src8));
251*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
252*0aeed3e9SJustin Hibbits     }
253*0aeed3e9SJustin Hibbits 
254*0aeed3e9SJustin Hibbits     return pDst;
255*0aeed3e9SJustin Hibbits }
256*0aeed3e9SJustin Hibbits 
257*0aeed3e9SJustin Hibbits void * Mem2IOCpy32(void* pDst,void* pSrc, uint32_t size)
258*0aeed3e9SJustin Hibbits {
259*0aeed3e9SJustin Hibbits     uint32_t leftAlign;
260*0aeed3e9SJustin Hibbits     uint32_t rightAlign;
261*0aeed3e9SJustin Hibbits     uint32_t lastWord;
262*0aeed3e9SJustin Hibbits     uint32_t currWord;
263*0aeed3e9SJustin Hibbits     uint32_t *p_Src32;
264*0aeed3e9SJustin Hibbits     uint32_t *p_Dst32;
265*0aeed3e9SJustin Hibbits     uint8_t  *p_Src8;
266*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
267*0aeed3e9SJustin Hibbits 
268*0aeed3e9SJustin Hibbits     p_Src8 = (uint8_t*)(pSrc);
269*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
270*0aeed3e9SJustin Hibbits     /* first copy byte by byte till the source first alignment
271*0aeed3e9SJustin Hibbits      * this step is necessary to ensure we do not even try to access
272*0aeed3e9SJustin Hibbits      * data which is before the source buffer, hence it is not ours.
273*0aeed3e9SJustin Hibbits      */
274*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Src8) & 3) && size) /* (pSrc mod 4) > 0 and size > 0 */
275*0aeed3e9SJustin Hibbits     {
276*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, *p_Src8);
277*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
278*0aeed3e9SJustin Hibbits         size--;
279*0aeed3e9SJustin Hibbits     }
280*0aeed3e9SJustin Hibbits 
281*0aeed3e9SJustin Hibbits     /* align destination (possibly disaligning source)*/
282*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 3) && size) /* (pDst mod 4) > 0 and size > 0 */
283*0aeed3e9SJustin Hibbits     {
284*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, *p_Src8);
285*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
286*0aeed3e9SJustin Hibbits         size--;
287*0aeed3e9SJustin Hibbits     }
288*0aeed3e9SJustin Hibbits 
289*0aeed3e9SJustin Hibbits     /* dest is aligned and source is not necessarily aligned */
290*0aeed3e9SJustin Hibbits     leftAlign = (uint32_t)((PTR_TO_UINT(p_Src8) & 3) << 3); /* leftAlign = (pSrc mod 4)*8 */
291*0aeed3e9SJustin Hibbits     rightAlign = 32 - leftAlign;
292*0aeed3e9SJustin Hibbits 
293*0aeed3e9SJustin Hibbits     if (leftAlign == 0)
294*0aeed3e9SJustin Hibbits     {
295*0aeed3e9SJustin Hibbits         /* source is also aligned */
296*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8);
297*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
298*0aeed3e9SJustin Hibbits         while (size >> 2) /* size >= 4 */
299*0aeed3e9SJustin Hibbits         {
300*0aeed3e9SJustin Hibbits             WRITE_UINT32(*p_Dst32, *p_Src32);
301*0aeed3e9SJustin Hibbits             p_Dst32++;p_Src32++;
302*0aeed3e9SJustin Hibbits             size -= 4;
303*0aeed3e9SJustin Hibbits         }
304*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32);
305*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
306*0aeed3e9SJustin Hibbits     }
307*0aeed3e9SJustin Hibbits     else
308*0aeed3e9SJustin Hibbits     {
309*0aeed3e9SJustin Hibbits         /* source is not aligned (destination is aligned)*/
310*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8 - (leftAlign >> 3));
311*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
312*0aeed3e9SJustin Hibbits         lastWord = *p_Src32++;
313*0aeed3e9SJustin Hibbits         while(size >> 3) /* size >= 8 */
314*0aeed3e9SJustin Hibbits         {
315*0aeed3e9SJustin Hibbits             currWord = *p_Src32;
316*0aeed3e9SJustin Hibbits             WRITE_UINT32(*p_Dst32, (lastWord << leftAlign) | (currWord >> rightAlign));
317*0aeed3e9SJustin Hibbits             lastWord = currWord;
318*0aeed3e9SJustin Hibbits             p_Src32++;p_Dst32++;
319*0aeed3e9SJustin Hibbits             size -= 4;
320*0aeed3e9SJustin Hibbits         }
321*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
322*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32) - 4 + (leftAlign >> 3);
323*0aeed3e9SJustin Hibbits     }
324*0aeed3e9SJustin Hibbits 
325*0aeed3e9SJustin Hibbits     /* complete the left overs */
326*0aeed3e9SJustin Hibbits     while (size--)
327*0aeed3e9SJustin Hibbits     {
328*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, *p_Src8);
329*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
330*0aeed3e9SJustin Hibbits     }
331*0aeed3e9SJustin Hibbits 
332*0aeed3e9SJustin Hibbits     return pDst;
333*0aeed3e9SJustin Hibbits }
334*0aeed3e9SJustin Hibbits 
335*0aeed3e9SJustin Hibbits void * IO2MemCpy32(void* pDst,void* pSrc, uint32_t size)
336*0aeed3e9SJustin Hibbits {
337*0aeed3e9SJustin Hibbits     uint32_t leftAlign;
338*0aeed3e9SJustin Hibbits     uint32_t rightAlign;
339*0aeed3e9SJustin Hibbits     uint32_t lastWord;
340*0aeed3e9SJustin Hibbits     uint32_t currWord;
341*0aeed3e9SJustin Hibbits     uint32_t *p_Src32;
342*0aeed3e9SJustin Hibbits     uint32_t *p_Dst32;
343*0aeed3e9SJustin Hibbits     uint8_t  *p_Src8;
344*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
345*0aeed3e9SJustin Hibbits 
346*0aeed3e9SJustin Hibbits     p_Src8 = (uint8_t*)(pSrc);
347*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
348*0aeed3e9SJustin Hibbits     /* first copy byte by byte till the source first alignment
349*0aeed3e9SJustin Hibbits      * this step is necessary to ensure we do not even try to access
350*0aeed3e9SJustin Hibbits      * data which is before the source buffer, hence it is not ours.
351*0aeed3e9SJustin Hibbits      */
352*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Src8) & 3) && size) /* (pSrc mod 4) > 0 and size > 0 */
353*0aeed3e9SJustin Hibbits     {
354*0aeed3e9SJustin Hibbits         *p_Dst8 = MY_GET_UINT8(*p_Src8);
355*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
356*0aeed3e9SJustin Hibbits         size--;
357*0aeed3e9SJustin Hibbits     }
358*0aeed3e9SJustin Hibbits 
359*0aeed3e9SJustin Hibbits     /* align destination (possibly disaligning source)*/
360*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 3) && size) /* (pDst mod 4) > 0 and size > 0 */
361*0aeed3e9SJustin Hibbits     {
362*0aeed3e9SJustin Hibbits         *p_Dst8 = MY_GET_UINT8(*p_Src8);
363*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
364*0aeed3e9SJustin Hibbits         size--;
365*0aeed3e9SJustin Hibbits     }
366*0aeed3e9SJustin Hibbits 
367*0aeed3e9SJustin Hibbits     /* dest is aligned and source is not necessarily aligned */
368*0aeed3e9SJustin Hibbits     leftAlign = (uint32_t)((PTR_TO_UINT(p_Src8) & 3) << 3); /* leftAlign = (pSrc mod 4)*8 */
369*0aeed3e9SJustin Hibbits     rightAlign = 32 - leftAlign;
370*0aeed3e9SJustin Hibbits 
371*0aeed3e9SJustin Hibbits     if (leftAlign == 0)
372*0aeed3e9SJustin Hibbits     {
373*0aeed3e9SJustin Hibbits         /* source is also aligned */
374*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8);
375*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
376*0aeed3e9SJustin Hibbits         while (size >> 2) /* size >= 4 */
377*0aeed3e9SJustin Hibbits         {
378*0aeed3e9SJustin Hibbits             *p_Dst32 = GET_UINT32(*p_Src32);
379*0aeed3e9SJustin Hibbits             p_Dst32++;p_Src32++;
380*0aeed3e9SJustin Hibbits             size -= 4;
381*0aeed3e9SJustin Hibbits         }
382*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32);
383*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
384*0aeed3e9SJustin Hibbits     }
385*0aeed3e9SJustin Hibbits     else
386*0aeed3e9SJustin Hibbits     {
387*0aeed3e9SJustin Hibbits         /* source is not aligned (destination is aligned)*/
388*0aeed3e9SJustin Hibbits         p_Src32 = (uint32_t*)(p_Src8 - (leftAlign >> 3));
389*0aeed3e9SJustin Hibbits         p_Dst32 = (uint32_t*)(p_Dst8);
390*0aeed3e9SJustin Hibbits         lastWord = GET_UINT32(*p_Src32);
391*0aeed3e9SJustin Hibbits         p_Src32++;
392*0aeed3e9SJustin Hibbits         while(size >> 3) /* size >= 8 */
393*0aeed3e9SJustin Hibbits         {
394*0aeed3e9SJustin Hibbits             currWord = GET_UINT32(*p_Src32);
395*0aeed3e9SJustin Hibbits             *p_Dst32 = (lastWord << leftAlign) | (currWord >> rightAlign);
396*0aeed3e9SJustin Hibbits             lastWord = currWord;
397*0aeed3e9SJustin Hibbits             p_Src32++;p_Dst32++;
398*0aeed3e9SJustin Hibbits             size -= 4;
399*0aeed3e9SJustin Hibbits         }
400*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(p_Dst32);
401*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(p_Src32) - 4 + (leftAlign >> 3);
402*0aeed3e9SJustin Hibbits     }
403*0aeed3e9SJustin Hibbits 
404*0aeed3e9SJustin Hibbits     /* complete the left overs */
405*0aeed3e9SJustin Hibbits     while (size--)
406*0aeed3e9SJustin Hibbits     {
407*0aeed3e9SJustin Hibbits         *p_Dst8 = MY_GET_UINT8(*p_Src8);
408*0aeed3e9SJustin Hibbits         p_Dst8++;p_Src8++;
409*0aeed3e9SJustin Hibbits     }
410*0aeed3e9SJustin Hibbits 
411*0aeed3e9SJustin Hibbits     return pDst;
412*0aeed3e9SJustin Hibbits }
413*0aeed3e9SJustin Hibbits 
414*0aeed3e9SJustin Hibbits void * MemCpy64(void* pDst,void* pSrc, uint32_t size)
415*0aeed3e9SJustin Hibbits {
416*0aeed3e9SJustin Hibbits     uint32_t leftAlign;
417*0aeed3e9SJustin Hibbits     uint32_t rightAlign;
418*0aeed3e9SJustin Hibbits     uint64_t lastWord;
419*0aeed3e9SJustin Hibbits     uint64_t currWord;
420*0aeed3e9SJustin Hibbits     uint64_t *pSrc64;
421*0aeed3e9SJustin Hibbits     uint64_t *pDst64;
422*0aeed3e9SJustin Hibbits     uint8_t  *p_Src8;
423*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
424*0aeed3e9SJustin Hibbits 
425*0aeed3e9SJustin Hibbits     p_Src8 = (uint8_t*)(pSrc);
426*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
427*0aeed3e9SJustin Hibbits     /* first copy byte by byte till the source first alignment
428*0aeed3e9SJustin Hibbits      * this step is necessarily to ensure we do not even try to access
429*0aeed3e9SJustin Hibbits      * data which is before the source buffer, hence it is not ours.
430*0aeed3e9SJustin Hibbits      */
431*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Src8) & 7) && size) /* (pSrc mod 8) > 0 and size > 0 */
432*0aeed3e9SJustin Hibbits     {
433*0aeed3e9SJustin Hibbits         *p_Dst8++ = *p_Src8++;
434*0aeed3e9SJustin Hibbits         size--;
435*0aeed3e9SJustin Hibbits     }
436*0aeed3e9SJustin Hibbits 
437*0aeed3e9SJustin Hibbits     /* align destination (possibly disaligning source)*/
438*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 7) && size) /* (pDst mod 8) > 0 and size > 0 */
439*0aeed3e9SJustin Hibbits     {
440*0aeed3e9SJustin Hibbits         *p_Dst8++ = *p_Src8++;
441*0aeed3e9SJustin Hibbits         size--;
442*0aeed3e9SJustin Hibbits     }
443*0aeed3e9SJustin Hibbits 
444*0aeed3e9SJustin Hibbits     /* dest is aligned and source is not necessarily aligned */
445*0aeed3e9SJustin Hibbits     leftAlign = (uint32_t)((PTR_TO_UINT(p_Src8) & 7) << 3); /* leftAlign = (pSrc mod 8)*8 */
446*0aeed3e9SJustin Hibbits     rightAlign = 64 - leftAlign;
447*0aeed3e9SJustin Hibbits 
448*0aeed3e9SJustin Hibbits 
449*0aeed3e9SJustin Hibbits     if (leftAlign == 0)
450*0aeed3e9SJustin Hibbits     {
451*0aeed3e9SJustin Hibbits         /* source is also aligned */
452*0aeed3e9SJustin Hibbits         pSrc64 = (uint64_t*)(p_Src8);
453*0aeed3e9SJustin Hibbits         pDst64 = (uint64_t*)(p_Dst8);
454*0aeed3e9SJustin Hibbits         while (size >> 3) /* size >= 8 */
455*0aeed3e9SJustin Hibbits         {
456*0aeed3e9SJustin Hibbits             *pDst64++ = *pSrc64++;
457*0aeed3e9SJustin Hibbits             size -= 8;
458*0aeed3e9SJustin Hibbits         }
459*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(pSrc64);
460*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(pDst64);
461*0aeed3e9SJustin Hibbits     }
462*0aeed3e9SJustin Hibbits     else
463*0aeed3e9SJustin Hibbits     {
464*0aeed3e9SJustin Hibbits         /* source is not aligned (destination is aligned)*/
465*0aeed3e9SJustin Hibbits         pSrc64 = (uint64_t*)(p_Src8 - (leftAlign >> 3));
466*0aeed3e9SJustin Hibbits         pDst64 = (uint64_t*)(p_Dst8);
467*0aeed3e9SJustin Hibbits         lastWord = *pSrc64++;
468*0aeed3e9SJustin Hibbits         while(size >> 4) /* size >= 16 */
469*0aeed3e9SJustin Hibbits         {
470*0aeed3e9SJustin Hibbits             currWord = *pSrc64;
471*0aeed3e9SJustin Hibbits             *pDst64 = (lastWord << leftAlign) | (currWord >> rightAlign);
472*0aeed3e9SJustin Hibbits             lastWord = currWord;
473*0aeed3e9SJustin Hibbits             pSrc64++;
474*0aeed3e9SJustin Hibbits             pDst64++;
475*0aeed3e9SJustin Hibbits             size -= 8;
476*0aeed3e9SJustin Hibbits         }
477*0aeed3e9SJustin Hibbits         p_Dst8 = (uint8_t*)(pDst64);
478*0aeed3e9SJustin Hibbits         p_Src8 = (uint8_t*)(pSrc64) - 8 + (leftAlign >> 3);
479*0aeed3e9SJustin Hibbits     }
480*0aeed3e9SJustin Hibbits 
481*0aeed3e9SJustin Hibbits     /* complete the left overs */
482*0aeed3e9SJustin Hibbits     while (size--)
483*0aeed3e9SJustin Hibbits         *p_Dst8++ = *p_Src8++;
484*0aeed3e9SJustin Hibbits 
485*0aeed3e9SJustin Hibbits     return pDst;
486*0aeed3e9SJustin Hibbits }
487*0aeed3e9SJustin Hibbits 
488*0aeed3e9SJustin Hibbits void * MemSet32(void* pDst, uint8_t val, uint32_t size)
489*0aeed3e9SJustin Hibbits {
490*0aeed3e9SJustin Hibbits     uint32_t val32;
491*0aeed3e9SJustin Hibbits     uint32_t *p_Dst32;
492*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
493*0aeed3e9SJustin Hibbits 
494*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
495*0aeed3e9SJustin Hibbits 
496*0aeed3e9SJustin Hibbits     /* generate four 8-bit val's in 32-bit container */
497*0aeed3e9SJustin Hibbits     val32  = (uint32_t) val;
498*0aeed3e9SJustin Hibbits     val32 |= (val32 <<  8);
499*0aeed3e9SJustin Hibbits     val32 |= (val32 << 16);
500*0aeed3e9SJustin Hibbits 
501*0aeed3e9SJustin Hibbits     /* align destination to 32 */
502*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 3) && size) /* (pDst mod 4) > 0 and size > 0 */
503*0aeed3e9SJustin Hibbits     {
504*0aeed3e9SJustin Hibbits         *p_Dst8++ = val;
505*0aeed3e9SJustin Hibbits         size--;
506*0aeed3e9SJustin Hibbits     }
507*0aeed3e9SJustin Hibbits 
508*0aeed3e9SJustin Hibbits     /* 32-bit chunks */
509*0aeed3e9SJustin Hibbits     p_Dst32 = (uint32_t*)(p_Dst8);
510*0aeed3e9SJustin Hibbits     while (size >> 2) /* size >= 4 */
511*0aeed3e9SJustin Hibbits     {
512*0aeed3e9SJustin Hibbits         *p_Dst32++ = val32;
513*0aeed3e9SJustin Hibbits         size -= 4;
514*0aeed3e9SJustin Hibbits     }
515*0aeed3e9SJustin Hibbits 
516*0aeed3e9SJustin Hibbits     /* complete the leftovers */
517*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(p_Dst32);
518*0aeed3e9SJustin Hibbits     while (size--)
519*0aeed3e9SJustin Hibbits         *p_Dst8++ = val;
520*0aeed3e9SJustin Hibbits 
521*0aeed3e9SJustin Hibbits     return pDst;
522*0aeed3e9SJustin Hibbits }
523*0aeed3e9SJustin Hibbits 
524*0aeed3e9SJustin Hibbits void * IOMemSet32(void* pDst, uint8_t val, uint32_t size)
525*0aeed3e9SJustin Hibbits {
526*0aeed3e9SJustin Hibbits     uint32_t val32;
527*0aeed3e9SJustin Hibbits     uint32_t *p_Dst32;
528*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
529*0aeed3e9SJustin Hibbits 
530*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
531*0aeed3e9SJustin Hibbits 
532*0aeed3e9SJustin Hibbits     /* generate four 8-bit val's in 32-bit container */
533*0aeed3e9SJustin Hibbits     val32  = (uint32_t) val;
534*0aeed3e9SJustin Hibbits     val32 |= (val32 <<  8);
535*0aeed3e9SJustin Hibbits     val32 |= (val32 << 16);
536*0aeed3e9SJustin Hibbits 
537*0aeed3e9SJustin Hibbits     /* align destination to 32 */
538*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 3) && size) /* (pDst mod 4) > 0 and size > 0 */
539*0aeed3e9SJustin Hibbits     {
540*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, val);
541*0aeed3e9SJustin Hibbits         p_Dst8++;
542*0aeed3e9SJustin Hibbits         size--;
543*0aeed3e9SJustin Hibbits     }
544*0aeed3e9SJustin Hibbits 
545*0aeed3e9SJustin Hibbits     /* 32-bit chunks */
546*0aeed3e9SJustin Hibbits     p_Dst32 = (uint32_t*)(p_Dst8);
547*0aeed3e9SJustin Hibbits     while (size >> 2) /* size >= 4 */
548*0aeed3e9SJustin Hibbits     {
549*0aeed3e9SJustin Hibbits         WRITE_UINT32(*p_Dst32, val32);
550*0aeed3e9SJustin Hibbits         p_Dst32++;
551*0aeed3e9SJustin Hibbits         size -= 4;
552*0aeed3e9SJustin Hibbits     }
553*0aeed3e9SJustin Hibbits 
554*0aeed3e9SJustin Hibbits     /* complete the leftovers */
555*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(p_Dst32);
556*0aeed3e9SJustin Hibbits     while (size--)
557*0aeed3e9SJustin Hibbits     {
558*0aeed3e9SJustin Hibbits         MY_WRITE_UINT8(*p_Dst8, val);
559*0aeed3e9SJustin Hibbits         p_Dst8++;
560*0aeed3e9SJustin Hibbits     }
561*0aeed3e9SJustin Hibbits 
562*0aeed3e9SJustin Hibbits     return pDst;
563*0aeed3e9SJustin Hibbits }
564*0aeed3e9SJustin Hibbits 
565*0aeed3e9SJustin Hibbits void * MemSet64(void* pDst, uint8_t val, uint32_t size)
566*0aeed3e9SJustin Hibbits {
567*0aeed3e9SJustin Hibbits     uint64_t val64;
568*0aeed3e9SJustin Hibbits     uint64_t *pDst64;
569*0aeed3e9SJustin Hibbits     uint8_t  *p_Dst8;
570*0aeed3e9SJustin Hibbits 
571*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst);
572*0aeed3e9SJustin Hibbits 
573*0aeed3e9SJustin Hibbits     /* generate four 8-bit val's in 32-bit container */
574*0aeed3e9SJustin Hibbits     val64  = (uint64_t) val;
575*0aeed3e9SJustin Hibbits     val64 |= (val64 <<  8);
576*0aeed3e9SJustin Hibbits     val64 |= (val64 << 16);
577*0aeed3e9SJustin Hibbits     val64 |= (val64 << 24);
578*0aeed3e9SJustin Hibbits     val64 |= (val64 << 32);
579*0aeed3e9SJustin Hibbits 
580*0aeed3e9SJustin Hibbits     /* align destination to 64 */
581*0aeed3e9SJustin Hibbits     while((PTR_TO_UINT(p_Dst8) & 7) && size) /* (pDst mod 8) > 0 and size > 0 */
582*0aeed3e9SJustin Hibbits     {
583*0aeed3e9SJustin Hibbits         *p_Dst8++ = val;
584*0aeed3e9SJustin Hibbits         size--;
585*0aeed3e9SJustin Hibbits     }
586*0aeed3e9SJustin Hibbits 
587*0aeed3e9SJustin Hibbits     /* 64-bit chunks */
588*0aeed3e9SJustin Hibbits     pDst64 = (uint64_t*)(p_Dst8);
589*0aeed3e9SJustin Hibbits     while (size >> 4) /* size >= 8 */
590*0aeed3e9SJustin Hibbits     {
591*0aeed3e9SJustin Hibbits         *pDst64++ = val64;
592*0aeed3e9SJustin Hibbits         size -= 8;
593*0aeed3e9SJustin Hibbits     }
594*0aeed3e9SJustin Hibbits 
595*0aeed3e9SJustin Hibbits     /* complete the leftovers */
596*0aeed3e9SJustin Hibbits     p_Dst8 = (uint8_t*)(pDst64);
597*0aeed3e9SJustin Hibbits     while (size--)
598*0aeed3e9SJustin Hibbits         *p_Dst8++ = val;
599*0aeed3e9SJustin Hibbits 
600*0aeed3e9SJustin Hibbits     return pDst;
601*0aeed3e9SJustin Hibbits }
602*0aeed3e9SJustin Hibbits 
603*0aeed3e9SJustin Hibbits void MemDisp(uint8_t *p, int size)
604*0aeed3e9SJustin Hibbits {
605*0aeed3e9SJustin Hibbits     uint32_t    space = (uint32_t)(PTR_TO_UINT(p) & 0x3);
606*0aeed3e9SJustin Hibbits     uint8_t     *p_Limit;
607*0aeed3e9SJustin Hibbits 
608*0aeed3e9SJustin Hibbits     if (space)
609*0aeed3e9SJustin Hibbits     {
610*0aeed3e9SJustin Hibbits         p_Limit = (p - space + 4);
611*0aeed3e9SJustin Hibbits 
612*0aeed3e9SJustin Hibbits         XX_Print("0x%08X: ", (p - space));
613*0aeed3e9SJustin Hibbits 
614*0aeed3e9SJustin Hibbits         while (space--)
615*0aeed3e9SJustin Hibbits         {
616*0aeed3e9SJustin Hibbits             XX_Print("--");
617*0aeed3e9SJustin Hibbits         }
618*0aeed3e9SJustin Hibbits         while (size  && (p < p_Limit))
619*0aeed3e9SJustin Hibbits         {
620*0aeed3e9SJustin Hibbits             XX_Print("%02x", *(uint8_t*)p);
621*0aeed3e9SJustin Hibbits             size--;
622*0aeed3e9SJustin Hibbits             p++;
623*0aeed3e9SJustin Hibbits         }
624*0aeed3e9SJustin Hibbits 
625*0aeed3e9SJustin Hibbits         XX_Print(" ");
626*0aeed3e9SJustin Hibbits         p_Limit += 12;
627*0aeed3e9SJustin Hibbits 
628*0aeed3e9SJustin Hibbits         while ((size > 3) && (p < p_Limit))
629*0aeed3e9SJustin Hibbits         {
630*0aeed3e9SJustin Hibbits             XX_Print("%08x ", *(uint32_t*)p);
631*0aeed3e9SJustin Hibbits             size -= 4;
632*0aeed3e9SJustin Hibbits             p += 4;
633*0aeed3e9SJustin Hibbits         }
634*0aeed3e9SJustin Hibbits         XX_Print("\r\n");
635*0aeed3e9SJustin Hibbits     }
636*0aeed3e9SJustin Hibbits 
637*0aeed3e9SJustin Hibbits     while (size > 15)
638*0aeed3e9SJustin Hibbits     {
639*0aeed3e9SJustin Hibbits         XX_Print("0x%08X: %08x %08x %08x %08x\r\n",
640*0aeed3e9SJustin Hibbits                  p, *(uint32_t *)p, *(uint32_t *)(p + 4),
641*0aeed3e9SJustin Hibbits                  *(uint32_t *)(p + 8), *(uint32_t *)(p + 12));
642*0aeed3e9SJustin Hibbits         size -= 16;
643*0aeed3e9SJustin Hibbits         p += 16;
644*0aeed3e9SJustin Hibbits     }
645*0aeed3e9SJustin Hibbits 
646*0aeed3e9SJustin Hibbits     if (size)
647*0aeed3e9SJustin Hibbits     {
648*0aeed3e9SJustin Hibbits         XX_Print("0x%08X: ", p);
649*0aeed3e9SJustin Hibbits 
650*0aeed3e9SJustin Hibbits         while (size > 3)
651*0aeed3e9SJustin Hibbits         {
652*0aeed3e9SJustin Hibbits             XX_Print("%08x ", *(uint32_t *)p);
653*0aeed3e9SJustin Hibbits             size -= 4;
654*0aeed3e9SJustin Hibbits             p += 4;
655*0aeed3e9SJustin Hibbits         }
656*0aeed3e9SJustin Hibbits         while (size)
657*0aeed3e9SJustin Hibbits         {
658*0aeed3e9SJustin Hibbits             XX_Print("%02x", *(uint8_t *)p);
659*0aeed3e9SJustin Hibbits             size--;
660*0aeed3e9SJustin Hibbits             p++;
661*0aeed3e9SJustin Hibbits         }
662*0aeed3e9SJustin Hibbits 
663*0aeed3e9SJustin Hibbits         XX_Print("\r\n");
664*0aeed3e9SJustin Hibbits     }
665*0aeed3e9SJustin Hibbits }
666