2
Bullet Continuous Collision Detection and Physics Library
3
Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
5
This software is provided 'as-is', without any express or implied warranty.
6
In no event will the authors be held liable for any damages arising from the use of this software.
7
Permission is granted to anyone to use this software for any purpose,
8
including commercial applications, and to alter it and redistribute it freely,
9
subject to the following restrictions:
11
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13
3. This notice may not be removed or altered from any source distribution.
16
#include "SpuFakeDma.h"
17
#include <LinearMath/btScalar.h> //for btAssert
18
//Disabling memcpy sometimes helps debugging DMA
26
void* cellDmaLargeGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
29
#if defined (__SPU__) || defined (USE_LIBSPE2)
30
cellDmaLargeGet(ls,ea,size,tag,tid,rid);
33
return (void*)(ppu_address_t)ea;
37
void* cellDmaSmallGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
39
#if defined (__SPU__) || defined (USE_LIBSPE2)
40
mfc_get(ls,ea,size,tag,0,0);
43
return (void*)(ppu_address_t)ea;
50
void* cellDmaGetReadOnly(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
52
#if defined (__SPU__) || defined (USE_LIBSPE2)
53
cellDmaGet(ls,ea,size,tag,tid,rid);
56
return (void*)(ppu_address_t)ea;
61
///this unalignedDma should not be frequently used, only for small data. It handles alignment and performs check on size (<16 bytes)
62
int stallingUnalignedDmaSmallGet(void *ls, uint64_t ea, uint32_t size)
67
ATTRIBUTE_ALIGNED16(char tmpBuffer[32]);
70
char* localStore = (char*)ls;
74
///make sure last 4 bits are the same, for cellDmaSmallGet
75
uint32_t last4BitsOffset = ea & 0x0f;
76
char* tmpTarget = tmpBuffer + last4BitsOffset;
78
#if defined (__SPU__) || defined (USE_LIBSPE2)
80
int remainingSize = size;
82
//#define FORCE_cellDmaUnalignedGet 1
83
#ifdef FORCE_cellDmaUnalignedGet
84
cellDmaUnalignedGet(tmpTarget,ea,size,DMA_TAG(1),0,0);
86
char* remainingTmpTarget = tmpTarget;
87
uint64_t remainingEa = ea;
91
switch (remainingSize)
99
mfc_get(remainingTmpTarget,remainingEa,remainingSize,DMA_TAG(1),0,0);
105
//spu_printf("unaligned DMA with non-natural size:%d\n",remainingSize);
108
if (remainingSize > 16)
111
if (remainingSize >8)
114
if (remainingSize >4)
117
if (remainingSize >2)
119
mfc_get(remainingTmpTarget,remainingEa,actualSize,DMA_TAG(1),0,0);
120
remainingSize-=actualSize;
121
remainingTmpTarget+=actualSize;
122
remainingEa += actualSize;
126
#endif//FORCE_cellDmaUnalignedGet
129
char* mainMem = (char*)ea;
130
//copy into final destination
133
memcpy(tmpTarget,mainMem,size);
135
for ( i=0;i<size;i++)
137
tmpTarget[i] = mainMem[i];
143
cellDmaWaitTagStatusAll(DMA_MASK(1));
145
//this is slowish, perhaps memcpy on SPU is smarter?
146
for (i=0; btLikely( i<size );i++)
148
localStore[i] = tmpTarget[i];
154
#if defined (__SPU__) || defined (USE_LIBSPE2)
157
int cellDmaLargeGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
159
char* mainMem = (char*)ea;
160
char* localStore = (char*)ls;
163
memcpy(localStore,mainMem,size);
165
for (uint32_t i=0;i<size;i++)
167
localStore[i] = mainMem[i];
173
int cellDmaGet(void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
175
char* mainMem = (char*)ea;
176
char* localStore = (char*)ls;
178
// printf("mainMem=%x, localStore=%x",mainMem,localStore);
181
memcpy(localStore,mainMem,size);
183
for (uint32_t i=0;i<size;i++)
185
localStore[i] = mainMem[i];
187
#endif //#ifdef USE_MEMCPY
188
// printf(" finished\n");
192
int cellDmaLargePut(const void *ls, uint64_t ea, uint32_t size, uint32_t tag, uint32_t tid, uint32_t rid)
194
char* mainMem = (char*)ea;
195
const char* localStore = (const char*)ls;
197
memcpy(mainMem,localStore,size);
199
for (uint32_t i=0;i<size;i++)
201
mainMem[i] = localStore[i];
203
#endif //#ifdef USE_MEMCPY
210
void cellDmaWaitTagStatusAll(int ignore)