|
1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : UdvmMemory.cpp |
|
15 // Part of : SigComp / UDVM |
|
16 // UDVM memory/memory manipulation |
|
17 // Version : 1.0 |
|
18 // |
|
19 |
|
20 |
|
21 |
|
22 #include "Sigcomp.h" |
|
23 #include "Udvm.h" |
|
24 #include "UdvmMemory.h" |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS ============================== |
|
27 |
|
28 void CUdvmMemory::ConstructL(TUint aMemSize) |
|
29 { |
|
30 iMemSize = aMemSize; |
|
31 iMem = new (ELeave)CArrayFixFlat<TUint8>(8); |
|
32 iMem->ResizeL(iMemSize); |
|
33 } |
|
34 |
|
35 CUdvmMemory::CUdvmMemory() |
|
36 { |
|
37 } |
|
38 |
|
39 CUdvmMemory* CUdvmMemory::NewLC(TUint aMemSize) |
|
40 { |
|
41 CUdvmMemory* self= new (ELeave)CUdvmMemory(); |
|
42 CleanupStack::PushL(self); |
|
43 self->ConstructL(aMemSize); |
|
44 return self; |
|
45 } |
|
46 |
|
47 CUdvmMemory* CUdvmMemory::NewL(TUint aMemSize) |
|
48 { |
|
49 CUdvmMemory* self= NewLC(aMemSize); |
|
50 CleanupStack::Pop(); |
|
51 return self; |
|
52 } |
|
53 |
|
54 // Destructor |
|
55 CUdvmMemory::~CUdvmMemory() |
|
56 { |
|
57 delete iMem; |
|
58 } |
|
59 |
|
60 void CUdvmMemory::CheckMemAccessL(TUint aAddr, TUint aSize) const |
|
61 { |
|
62 if ((iFreeMemSize < KMaxUdvmMemorySize) && |
|
63 ((aAddr + aSize) > iFreeMemSize)) |
|
64 { |
|
65 User::Leave(CSigComp::EDecompressionFailure); |
|
66 } |
|
67 } |
|
68 |
|
69 // ---------------------------------------------------------------------------- |
|
70 // CUdvmMemory::WriteMem8L |
|
71 // write byte to UDVM memory |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 |
|
75 void CUdvmMemory::WriteMem8L(TUint aDest, TUint aVal) |
|
76 { |
|
77 |
|
78 CheckMemAccessL(aDest, 1); |
|
79 |
|
80 (*iMem)[aDest] = static_cast<TUint8>(aVal & 0xff); |
|
81 } |
|
82 |
|
83 |
|
84 // ---------------------------------------------------------------------------- |
|
85 // CUdvmMemory::WriteMem16L |
|
86 // write 16-bit word to UDVM memory |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 |
|
90 void CUdvmMemory::WriteMem16L(TUint aDest, TUint aVal) |
|
91 { |
|
92 |
|
93 CheckMemAccessL(aDest, 2); |
|
94 |
|
95 // write 16-bit value in big-endian convention |
|
96 (*iMem)[aDest] = static_cast<TUint8>((aVal >> 8) & 0xff); |
|
97 (*iMem)[(aDest + 1) & KMaxUdvmMemoryMask] = static_cast<TUint8> |
|
98 (aVal & 0xff); |
|
99 } |
|
100 |
|
101 |
|
102 // ---------------------------------------------------------------------------- |
|
103 // CUdvmMemory::ReadMem8L |
|
104 // read byte from UDVM memory |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 |
|
108 TUint8 CUdvmMemory::ReadMem8L(TUint aSrc) const |
|
109 { |
|
110 |
|
111 CheckMemAccessL(aSrc, 1); |
|
112 |
|
113 return static_cast<TUint8>((*iMem)[aSrc]); |
|
114 } |
|
115 |
|
116 |
|
117 // ---------------------------------------------------------------------------- |
|
118 // CUdvmMemory::ReadMem16L |
|
119 // read 16-bit word from UDVM memory |
|
120 // ---------------------------------------------------------------------------- |
|
121 // |
|
122 |
|
123 TUint16 CUdvmMemory::ReadMem16L(TUint aSrc) const |
|
124 { |
|
125 |
|
126 CheckMemAccessL(aSrc, 2); |
|
127 |
|
128 // read 16-bit value in big-endian convention |
|
129 return static_cast<TUint16>(((static_cast<TUint16>((*iMem)[aSrc]) << 8) + |
|
130 static_cast<TUint16>((*iMem)[(aSrc + 1) & KMaxUdvmMemoryMask]))); |
|
131 } |
|
132 |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CUdvmMemory::SetMemL |
|
136 // set block of UDVM memory to value |
|
137 // ---------------------------------------------------------------------------- |
|
138 // |
|
139 |
|
140 void CUdvmMemory::SetMemL(TUint aDest, TUint8 aVal, TUint aSize) |
|
141 { |
|
142 |
|
143 CheckMemAccessL(aDest, aSize); |
|
144 |
|
145 for (TUint i = 0; i < aSize; i++) |
|
146 { |
|
147 (*iMem)[aDest] = aVal; |
|
148 aDest = (aDest + 1) & KMaxUdvmMemoryMask; |
|
149 } |
|
150 } |
|
151 |
|
152 |
|
153 // ---------------------------------------------------------------------------- |
|
154 // CUdvmMemory::CopyToMemL |
|
155 // copy block of data to UDVM memory |
|
156 // ---------------------------------------------------------------------------- |
|
157 // |
|
158 |
|
159 void CUdvmMemory::CopyToMemL(TUint aDest, const TUint8* aSrc, TUint aSize) |
|
160 { |
|
161 |
|
162 CheckMemAccessL(aDest, aSize); |
|
163 |
|
164 for (TUint i = 0; i < aSize; i++) |
|
165 { |
|
166 (*iMem)[aDest] = *aSrc++; |
|
167 aDest = (aDest + 1) & KMaxUdvmMemoryMask; |
|
168 } |
|
169 } |
|
170 |
|
171 |
|
172 // ---------------------------------------------------------------------------- |
|
173 // CUdvmMemory::CopyFromMemL |
|
174 // copy block of data from UDVM memory |
|
175 // ---------------------------------------------------------------------------- |
|
176 // |
|
177 |
|
178 void CUdvmMemory::CopyFromMemL(TUint8* aDest, TUint aSrc, TUint aSize) const |
|
179 { |
|
180 |
|
181 CheckMemAccessL(aSrc, aSize); |
|
182 |
|
183 for (TUint i = 0; i < aSize; i++) |
|
184 { |
|
185 *aDest++ = (*iMem)[aSrc]; |
|
186 aSrc = (aSrc + 1) & KMaxUdvmMemoryMask; |
|
187 } |
|
188 } |
|
189 |
|
190 void CUdvmMemory::InitMemoryL(TUint aMsgSize, TUint aCyclesPerBit) |
|
191 { |
|
192 if (iMemSize <= aMsgSize) |
|
193 { |
|
194 User::Leave(CSigComp::EDecompressionFailure); |
|
195 } |
|
196 |
|
197 iFreeMemSize = iMemSize-aMsgSize; |
|
198 if (iFreeMemSize > KMaxUdvmMemorySize) |
|
199 { |
|
200 iFreeMemSize = KMaxUdvmMemorySize; |
|
201 } |
|
202 |
|
203 WriteMem16L(CUdvm::EMem_UDVM_memory_size, static_cast<TUint16> |
|
204 (iFreeMemSize & KMaxUdvmMemoryMask)); |
|
205 WriteMem16L(CUdvm::EMem_cycles_per_bit, static_cast<TUint16> |
|
206 (aCyclesPerBit)); |
|
207 WriteMem16L(CUdvm::EMem_SigComp_version, KSigCompVersion); |
|
208 SetMemL(CUdvm::EMem_reserved, 0, |
|
209 CUdvm::EMem_scratch_pad-CUdvm::EMem_reserved); |
|
210 SetMemL(CUdvm::EMem_scratch_pad, 0, |
|
211 CUdvm::EMem_registers - CUdvm::EMem_scratch_pad); |
|
212 WriteMem16L(CUdvm::EReg_byte_copy_left, 0x0000); |
|
213 WriteMem16L(CUdvm::EReg_byte_copy_right, 0x0000); |
|
214 WriteMem16L(CUdvm::EReg_input_bit_order, 0x0000); |
|
215 WriteMem16L(CUdvm::EReg_stack_location, 0x0000); |
|
216 SetMemL(CUdvm::EMem_user_area, 0, iFreeMemSize - CUdvm::EMem_user_area); |
|
217 } |
|
218 |
|
219 TUint8* CUdvmMemory::MemoryPtr() |
|
220 { |
|
221 return &iMem->At(0); |
|
222 } |
|
223 |
|
224 TUint CUdvmMemory::MemorySize() const |
|
225 { |
|
226 return iMemSize; |
|
227 } |
|
228 |
|
229 TUint CUdvmMemory::FreeMemorySize() const |
|
230 { |
|
231 return iFreeMemSize; |
|
232 } |
|
233 |