|
1 // Copyright (c) 1997-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 the License "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 // e32\common\arm\cdes8.cia |
|
15 // |
|
16 // |
|
17 |
|
18 #include <e32cia.h> |
|
19 #include "../common.h" |
|
20 |
|
21 #define __FIXED_POINT_64BIT_DIV10__ |
|
22 |
|
23 #if defined(__DES8_MACHINE_CODED__) || defined(__EABI__) |
|
24 |
|
25 GLREF_C void Des8PanicBadDesType(); |
|
26 GLREF_C void Des8PanicPosOutOfRange(); |
|
27 |
|
28 #endif |
|
29 |
|
30 #ifdef __DES8_MACHINE_CODED__ |
|
31 |
|
32 GLREF_C void Des8PanicLengthNegative(); |
|
33 GLREF_C void Des8PanicMaxLengthNegative(); |
|
34 GLREF_C void Des8PanicLengthOutOfRange(); |
|
35 GLREF_C void Des8PanicDesOverflow(); |
|
36 GLREF_C void Des8PanicDesIndexOutOfRange(); |
|
37 |
|
38 __NAKED__ EXPORT_C const TUint8 *TDesC8::Ptr() const |
|
39 // |
|
40 // Return a pointer to the buffer. |
|
41 // |
|
42 { |
|
43 asm("ldr r1, [r0], #4 "); |
|
44 asm("cmp r1, #0x50000000 "); |
|
45 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
46 asm("eor r1, r1, r1, lsr #1 "); |
|
47 asm("msr cpsr_flg, r1 "); |
|
48 asm("addcs r0, r0, #4 "); |
|
49 asm("ldrle r0, [r0] "); |
|
50 asm("addeq r0, r0, #4 "); |
|
51 __JUMP(,lr); |
|
52 } |
|
53 |
|
54 #ifndef __EABI_CTORS__ |
|
55 __NAKED__ EXPORT_C TPtrC8::TPtrC8() |
|
56 // |
|
57 // Default constructor |
|
58 // |
|
59 { |
|
60 asm("mov r1, #0x10000000 "); // type=EPtrC, length=0 |
|
61 asm("mov r2, #0 "); // ptr=NULL |
|
62 asm("stmia r0, {r1,r2} "); |
|
63 __JUMP(,lr); |
|
64 } |
|
65 |
|
66 __NAKED__ EXPORT_C TPtrC8::TPtrC8(const TDesC8& /*aDes*/) |
|
67 // |
|
68 // Constructor |
|
69 // |
|
70 { |
|
71 asm("ldr r2, [r1], #4 "); // r2 = type/length |
|
72 asm("bic r3, r2, #0xF0000000"); // r3 = length |
|
73 asm("orr r3, r3, #0x10000000"); // r3 = EPtrC + length |
|
74 asm("cmp r2, #0x50000000 "); |
|
75 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
76 asm("eor r2, r2, r2, lsr #1 "); |
|
77 asm("msr cpsr_flg, r2 "); |
|
78 asm("addcs r1, r1, #4 "); |
|
79 asm("ldrle r1, [r1] "); |
|
80 asm("addeq r1, r1, #4 "); // r1 = aDes.Ptr() |
|
81 asm("str r3, [r0] "); |
|
82 asm("str r1, [r0, #4] "); |
|
83 __JUMP(,lr); |
|
84 } |
|
85 |
|
86 __NAKED__ EXPORT_C TPtrC8::TPtrC8(const TUint8* /*aString*/) |
|
87 // |
|
88 // Constructor |
|
89 // |
|
90 { |
|
91 asm("mov r2, r1 "); // save aString pointer |
|
92 asm("1: "); |
|
93 asm("ldrb r3, [r1], #1 "); |
|
94 asm("cmp r3, #0 "); |
|
95 asm("bne 1b "); // loop until we reach zero terminator |
|
96 asm("sub r1, r1, r2 "); // r1 = length + 1 |
|
97 asm("sub r1, r1, #1 "); // r1 = length |
|
98 asm("orr r1, r1, #0x10000000 "); // r1=EPtrC + length |
|
99 asm("stmia r0, {r1, r2} "); // store type/length and ptr fields |
|
100 __JUMP(,lr); |
|
101 } |
|
102 |
|
103 __NAKED__ EXPORT_C TPtrC8::TPtrC8(const TUint8* /*aBuf*/,TInt /*aLength*/) |
|
104 // |
|
105 // Constructor |
|
106 // |
|
107 { |
|
108 asm("orrs r2, r2, #0x10000000 "); |
|
109 asm("strpl r2, [r0] "); |
|
110 asm("strpl r1, [r0, #4] "); |
|
111 __JUMP(pl,lr); |
|
112 asm("b " CSM_Z23Des8PanicLengthNegativev); |
|
113 } |
|
114 |
|
115 __NAKED__ EXPORT_C TPtr8::TPtr8(TUint8* /*aBuf*/,TInt /*aMaxLength*/) |
|
116 // |
|
117 // Constructor |
|
118 // |
|
119 { |
|
120 asm("cmp r2, #0 "); |
|
121 asm("movpl r3, r1 "); |
|
122 asm("movpl r1, #0x20000000 "); // length=0, EPtr |
|
123 asm("stmplia r0, {r1,r2,r3} "); |
|
124 __JUMP(pl,lr); |
|
125 asm("b " CSM_Z26Des8PanicMaxLengthNegativev); |
|
126 } |
|
127 |
|
128 __NAKED__ EXPORT_C TPtr8::TPtr8(TUint8* /*aBuf*/,TInt /*aLength*/,TInt /*aMaxLength*/) |
|
129 // |
|
130 // Constructor |
|
131 // |
|
132 { |
|
133 asm("cmp r2, #0 "); // check length>=0 |
|
134 asm("cmpge r3, r2 "); // if so, check maxlength>=length |
|
135 asm("movge r12, r1 "); |
|
136 asm("orrge r2, r2, #0x20000000 "); // r2 = length + EPtr |
|
137 asm("stmgeia r0, {r2,r3,r12} "); |
|
138 __JUMP(ge,lr); |
|
139 asm("cmp r2, #0 "); |
|
140 asm("bmi " CSM_Z23Des8PanicLengthNegativev); |
|
141 asm("cmp r3, #0 "); |
|
142 asm("bmi " CSM_Z26Des8PanicMaxLengthNegativev); |
|
143 asm("b " CSM_Z25Des8PanicLengthOutOfRangev); |
|
144 } |
|
145 |
|
146 __NAKED__ EXPORT_C TPtr8::TPtr8(TBufCBase8& /*aLcb*/,TInt /*aMaxLength*/) |
|
147 // |
|
148 // Constructor |
|
149 // |
|
150 { |
|
151 asm("mov r3, r1 "); |
|
152 asm("ldr r1, [r3] "); |
|
153 asm("bic r1, r1, #0xF0000000 "); // r1=aLcb.Length() |
|
154 asm("cmp r1, r2 "); // check against maxlength |
|
155 asm("orrle r1, r1, #0x40000000 "); // r1=aLcb.Length() + EBufCPtr |
|
156 asm("stmleia r0, {r1,r2,r3} "); |
|
157 __JUMP(le,lr); |
|
158 asm("b " CSM_Z25Des8PanicLengthOutOfRangev); |
|
159 } |
|
160 |
|
161 __NAKED__ EXPORT_C TBufCBase8::TBufCBase8() |
|
162 // |
|
163 // Constructor |
|
164 // |
|
165 { |
|
166 asm("mov r1, #0 "); |
|
167 asm("str r1, [r0] "); |
|
168 __JUMP(,lr); |
|
169 } |
|
170 |
|
171 __NAKED__ EXPORT_C TBufCBase8::TBufCBase8(const TUint8* /*aString*/,TInt /*aMaxLength*/) |
|
172 // |
|
173 // Constructor |
|
174 // |
|
175 { |
|
176 asm("mov r3, r1 "); // save aString pointer |
|
177 asm("1: "); |
|
178 asm("ldrb r12, [r3], #1 "); |
|
179 asm("cmp r12, #0 "); |
|
180 asm("bne 1b "); // loop until we reach zero terminator |
|
181 asm("sub r3, r3, r1 "); // r3 = length + 1 |
|
182 asm("sub r3, r3, #1 "); // r3 = length (+EBufC) |
|
183 asm("cmp r3, r2 "); // check against max length |
|
184 asm("bgt " CSM_Z25Des8PanicLengthOutOfRangev); |
|
185 asm("stmfd sp!, {r0,lr} "); // save registers for function call |
|
186 asm("str r3, [r0], #4 "); // save length/type field, r0->buffer |
|
187 asm("mov r2, r3 "); // length into r2 for function call |
|
188 asm("bl memmove "); |
|
189 __POPRET("r0,"); |
|
190 } |
|
191 |
|
192 __NAKED__ EXPORT_C TBufCBase8::TBufCBase8(const TDesC8& /*aDes*/,TInt /*aMaxLength*/) |
|
193 // |
|
194 // Constructor |
|
195 // |
|
196 { |
|
197 asm("ldr r3, [r1], #4 "); // r3 = type/length |
|
198 asm("bic r12, r3, #0xF0000000"); // r12 = length |
|
199 asm("cmp r12, r2 "); // compare with maxlength |
|
200 asm("bgt " CSM_Z25Des8PanicLengthOutOfRangev); |
|
201 asm("cmp r3, #0x50000000 "); |
|
202 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
203 asm("eor r3, r3, r3, lsr #1 "); |
|
204 asm("msr cpsr_flg, r3 "); |
|
205 asm("addcs r1, r1, #4 "); |
|
206 asm("ldrle r1, [r1] "); |
|
207 asm("addeq r1, r1, #4 "); // r1 = aDes.Ptr() |
|
208 asm("stmfd sp!, {r0,lr} "); // save registers for function call |
|
209 asm("str r12, [r0], #4 "); // store length/type, r0->buffer |
|
210 asm("mov r2, r12 "); // length into r2 for function call |
|
211 asm("bl memmove "); |
|
212 __POPRET("r0,"); |
|
213 } |
|
214 #endif |
|
215 |
|
216 __NAKED__ EXPORT_C void TBufCBase8::Copy(const TUint8* /*aString*/,TInt /*aMaxLength*/) |
|
217 // |
|
218 // Copy from a string. |
|
219 // |
|
220 { |
|
221 asm("mov r3, r1 "); // save aString pointer |
|
222 asm("1: "); |
|
223 asm("ldrb r12, [r3], #1 "); |
|
224 asm("cmp r12, #0 "); |
|
225 asm("bne 1b "); // loop until we reach zero terminator |
|
226 asm("sub r3, r3, r1 "); // r3 = length + 1 |
|
227 asm("sub r3, r3, #1 "); // r3 = length (+EBufC) |
|
228 asm("cmp r3, r2 "); // check against max length |
|
229 asm("bgt " CSM_Z25Des8PanicLengthOutOfRangev); |
|
230 asm("str r3, [r0], #4 "); // save length/type field, r0->buffer |
|
231 asm("mov r2, r3 "); // length into r2 for function call |
|
232 asm("b memmove "); |
|
233 } |
|
234 |
|
235 __NAKED__ EXPORT_C void TBufCBase8::Copy(const TDesC8& /*aDes*/,TInt /*aMaxLength*/) |
|
236 // |
|
237 // Copy from a descriptor. |
|
238 // |
|
239 { |
|
240 asm("ldr r3, [r1], #4 "); // r3 = type/length |
|
241 asm("bic r12, r3, #0xF0000000"); // r12 = length |
|
242 asm("cmp r12, r2 "); // compare with maxlength |
|
243 asm("bgt " CSM_Z20Des8PanicDesOverflowv); |
|
244 asm("cmp r3, #0x50000000 "); |
|
245 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
246 asm("eor r3, r3, r3, lsr #1 "); |
|
247 asm("msr cpsr_flg, r3 "); |
|
248 asm("addcs r1, r1, #4 "); |
|
249 asm("ldrle r1, [r1] "); |
|
250 asm("addeq r1, r1, #4 "); // r1 = aDes.Ptr() |
|
251 asm("str r12, [r0], #4 "); // store length/type, r0->buffer |
|
252 asm("mov r2, r12 "); // length into r2 for function call |
|
253 asm("b memmove "); |
|
254 } |
|
255 |
|
256 #ifndef __EABI_CTORS__ |
|
257 __NAKED__ EXPORT_C TBufBase8::TBufBase8(TInt /*aMaxLength*/) |
|
258 { |
|
259 asm("mov r2, #0x30000000 "); // EBuf + zero length |
|
260 asm("str r2, [r0] "); |
|
261 asm("str r1, [r0, #4] "); |
|
262 __JUMP(,lr); |
|
263 } |
|
264 |
|
265 __NAKED__ EXPORT_C TBufBase8::TBufBase8(TInt /*aLength*/, TInt /*aMaxLength*/) |
|
266 { |
|
267 asm("cmp r1, #0 "); // check length>=0 |
|
268 asm("cmpge r2, r1 "); // if so, check maxlength>=length |
|
269 asm("orrge r1, r1, #0x30000000 "); // r1=length + EBuf |
|
270 asm("stmgeia r0, {r1,r2} "); // store length/type and maxlength fields |
|
271 __JUMP(ge,lr); |
|
272 asm("cmp r2, #0 "); |
|
273 asm("bmi " CSM_Z26Des8PanicMaxLengthNegativev); |
|
274 asm("b " CSM_Z25Des8PanicLengthOutOfRangev); |
|
275 } |
|
276 |
|
277 __NAKED__ EXPORT_C TBufBase8::TBufBase8(const TUint8* /*aString*/, TInt /*aMaxLength*/) |
|
278 { |
|
279 asm("mov r12, r1 "); // save aString pointer |
|
280 asm("1: "); |
|
281 asm("ldrb r3, [r1], #1 "); |
|
282 asm("cmp r3, #0 "); |
|
283 asm("bne 1b "); // loop until we reach zero terminator |
|
284 asm("sub r1, r1, r12 "); // r1 = length + 1 |
|
285 asm("sub r1, r1, #1 "); // r1 = length |
|
286 asm("cmp r1, r2 "); // compare to max length |
|
287 asm("bgt " CSM_Z25Des8PanicLengthOutOfRangev); // length too big, so panic |
|
288 asm("orr r1, r1, #0x30000000 "); // if length<=max, r1=EBuf + length |
|
289 asm("stmfd sp!, {r0,lr} "); // save registers for function call |
|
290 asm("stmia r0!, {r1, r2} "); // store type/length and max length fields, r0->buffer |
|
291 asm("bic r2, r1, #0xf0000000 "); // r2=length |
|
292 asm("mov r1, r12 "); // r12=aString |
|
293 asm("bl memmove "); |
|
294 __POPRET("r0,"); |
|
295 } |
|
296 |
|
297 __NAKED__ EXPORT_C TBufBase8::TBufBase8(const TDesC8& /*aDes*/, TInt /*aMaxLength*/) |
|
298 { |
|
299 asm("ldr r3, [r1], #4 "); // r3 = type/length |
|
300 asm("bic r12, r3, #0xF0000000"); // r12 = length |
|
301 asm("cmp r12, r2 "); // compare with maxlength |
|
302 asm("bgt " CSM_Z25Des8PanicLengthOutOfRangev); |
|
303 asm("cmp r3, #0x50000000 "); |
|
304 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
305 asm("eor r3, r3, r3, lsr #1 "); |
|
306 asm("msr cpsr_flg, r3 "); |
|
307 asm("addcs r1, r1, #4 "); |
|
308 asm("ldrle r1, [r1] "); |
|
309 asm("addeq r1, r1, #4 "); // r1 = aDes.Ptr() |
|
310 asm("stmfd sp!, {r0,lr} "); // save registers for function call |
|
311 asm("orr r12, r12, #0x30000000 "); // add EBuf type field |
|
312 asm("str r12, [r0], #4 "); // store length/type, r0->max length |
|
313 asm("str r2, [r0], #4 "); // store max length, r0->buffer |
|
314 asm("bic r2, r12, #0xf0000000 "); // length into r2 for function call |
|
315 asm("bl memmove "); |
|
316 __POPRET("r0,"); |
|
317 } |
|
318 #endif |
|
319 |
|
320 __NAKED__ EXPORT_C void TDes8::SetLength(TInt /*aLength*/) |
|
321 // |
|
322 // Set the length of the descriptor, checking the length is O.K. |
|
323 // |
|
324 { |
|
325 asm("ldmia r0, {r2,r3} "); // r2=length/type, r3=maxlength |
|
326 asm("cmp r1, r3 "); // check aLength against maxlength and for -ve values |
|
327 asm("bhi " CSM_Z20Des8PanicDesOverflowv); |
|
328 asm("and r2, r2, #0xF0000000 "); // r2=type field |
|
329 asm("cmp r2, #0x40000000 "); // check for EBufCPtr |
|
330 asm("orr r2, r2, r1 "); // r2=type + new length |
|
331 asm("str r2, [r0] "); // store new length |
|
332 __JUMP(ne,lr); |
|
333 asm("ldr r2, [r0, #8] "); // r2=pointer to TBufCBase |
|
334 asm("str r1, [r2] "); // update length of TBufCBase |
|
335 __JUMP(,lr); |
|
336 } |
|
337 |
|
338 __NAKED__ EXPORT_C void TDes8::SetMax() |
|
339 // |
|
340 // Set the length to MaxLength(). |
|
341 // |
|
342 { |
|
343 asm("ldmia r0, {r1,r2} "); // r1=length/type, r2=maxlength |
|
344 asm("and r1, r1, #0xF0000000 "); // r1=type field |
|
345 asm("cmp r1, #0x40000000 "); // check for EBufCPtr |
|
346 asm("orr r1, r1, r2 "); // r1=type field + maxlength |
|
347 asm("str r1, [r0] "); // store new length |
|
348 __JUMP(ne,lr); |
|
349 asm("ldr r1, [r0, #8] "); // r1 = pointer to TBufCBase |
|
350 asm("str r2, [r1] "); // update length of TBufCBase |
|
351 __JUMP(,lr); |
|
352 } |
|
353 |
|
354 __NAKED__ EXPORT_C void TDes8::Copy(const TUint8* /*aString*/) |
|
355 // |
|
356 // Copy a string to this descriptor. |
|
357 // |
|
358 { |
|
359 asm("mov r2, r1 "); // r2=aString |
|
360 asm("1: "); |
|
361 asm("ldrb r3, [r2], #1 "); |
|
362 asm("cmp r3, #0 "); |
|
363 asm("bne 1b "); // loop until zero terminator reached |
|
364 asm("sub r2, r2, r1 "); |
|
365 asm("sub r2, r2, #1 "); // r2=length of string |
|
366 asm("ldmia r0, {r3,r12} "); // r3=type/length of this, r12=maxlength |
|
367 asm("cmp r2, r12 "); // compare new length against maxlength |
|
368 asm("bgt " CSM_Z20Des8PanicDesOverflowv); |
|
369 asm("cmp r3, #0x50000000 "); |
|
370 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
371 asm("and r3, r3, #0xF0000000 "); // r3=type of this |
|
372 asm("orr r3, r3, r2 "); // r3=new type/length |
|
373 asm("str r3, [r0], #4 "); // store it |
|
374 asm("eor r3, r3, r3, lsr #1 "); |
|
375 asm("msr cpsr_flg, r3 "); |
|
376 asm("addcs r0, r0, #4 "); |
|
377 asm("ldrle r0, [r0] "); |
|
378 asm("streq r2, [r0], #4 "); // if EBufCPtr, update length of TBufCBase, r0=Ptr() |
|
379 asm("b memmove "); |
|
380 } |
|
381 |
|
382 __NAKED__ EXPORT_C void TDes8::Copy(const TUint8* /*aBuf*/,TInt /*aLength*/) |
|
383 // |
|
384 // Copy the aLength characters to the descriptor. |
|
385 // |
|
386 { |
|
387 asm("ldmia r0, {r3,r12} "); // r3=type/length of this, r12=maxlength |
|
388 asm("cmp r2, r12 "); // compare new length against maxlength |
|
389 asm("bhi " CSM_Z20Des8PanicDesOverflowv); // Des8Panic if >MaxLength or -ve |
|
390 asm("cmp r3, #0x50000000 "); |
|
391 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
392 asm("and r3, r3, #0xF0000000 "); // r3=type of this |
|
393 asm("orr r3, r3, r2 "); // r3=new type/length |
|
394 asm("str r3, [r0], #4 "); // store it |
|
395 asm("eor r3, r3, r3, lsr #1 "); |
|
396 asm("msr cpsr_flg, r3 "); |
|
397 asm("addcs r0, r0, #4 "); |
|
398 asm("ldrle r0, [r0] "); |
|
399 asm("streq r2, [r0], #4 "); // if EBufCPtr, update length of TBufCBase, r0=Ptr() |
|
400 asm("b memmove "); |
|
401 } |
|
402 |
|
403 __NAKED__ EXPORT_C void TDes8::Copy(const TDesC8& /*aDes*/) |
|
404 // |
|
405 // Copy a descriptor to this descriptor. |
|
406 // |
|
407 { |
|
408 asm("ldr r3, [r1], #4 "); // r3 = type/length of aDes |
|
409 asm("bic r12, r3, #0xF0000000"); // r12 = aDes.length |
|
410 asm("ldr r2, [r0, #4] "); // r2=this.maxlength |
|
411 asm("cmp r12, r2 "); // compare with maxlength |
|
412 asm("bgt " CSM_Z20Des8PanicDesOverflowv); |
|
413 asm("ldr r2, [r0] "); // get type of this |
|
414 asm("cmp r2, #0x50000000 "); // check both descriptor types |
|
415 asm("cmpcc r3, #0x50000000 "); |
|
416 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
417 asm("and r2, r2, #0xF0000000 "); |
|
418 asm("orr r2, r12, r2 "); // r2=new type/length of this |
|
419 asm("str r2, [r0], #4 "); // store it |
|
420 asm("eor r3, r3, r3, lsr #1 "); |
|
421 asm("msr cpsr_flg, r3 "); |
|
422 asm("addcs r1, r1, #4 "); |
|
423 asm("ldrle r1, [r1] "); |
|
424 asm("addeq r1, r1, #4 "); // r1 = aDes.Ptr() |
|
425 asm("eor r2, r2, r2, lsr #1 "); |
|
426 asm("msr cpsr_flg, r2 "); |
|
427 asm("addcs r0, r0, #4 "); |
|
428 asm("ldrle r0, [r0] "); |
|
429 asm("streq r12, [r0], #4 "); // if EBufCPtr, update length of TBufCBase, r0=Ptr() |
|
430 asm("mov r2, r12 "); // length into r2 for function call |
|
431 asm("b memmove "); |
|
432 } |
|
433 |
|
434 #ifndef __KERNEL_MODE__ |
|
435 __NAKED__ EXPORT_C TPtr8 TDes8::LeftTPtr(TInt /*aLength*/) const |
|
436 // |
|
437 // Extract the left portion of the descriptor. |
|
438 // |
|
439 { |
|
440 // On entry r0=return store ptr, r1=this, r2=aLength |
|
441 // Return TPtr8 ([r0]=length/type,[r0,#4]=maxLength,[r0,#8]=Ptr) |
|
442 asm("ldr r3, [r1], #4 "); // r3=this.length/type |
|
443 asm("cmp r2, #0 "); // check aLength>=0 |
|
444 asm("blt Des8PanicPosOutOfRange__Fv "); // if not panic |
|
445 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
446 asm("cmp r2, r12 "); // limit aLength to Length() |
|
447 asm("movgt r2, r12 "); |
|
448 asm("cmp r3, #0x50000000 "); // check type() <= 4 |
|
449 asm("bcs Des8PanicBadDesType__Fv "); // if not, panic |
|
450 asm("eor r3, r3, r3, lsr #1 "); |
|
451 asm("msr cpsr_flg, r3 "); |
|
452 asm("addcs r1, r1, #4 "); |
|
453 asm("ldrle r1, [r1] "); |
|
454 asm("addeq r1, r1, #4 "); // r1=this.Ptr() |
|
455 asm("mov r3, r1 "); // r3=this.Ptr() |
|
456 asm("orr r1, r2, #0x20000000 "); // r1=aLength + EPtr |
|
457 asm("stmia r0, {r1-r3} "); |
|
458 __JUMP(,lr); |
|
459 } |
|
460 |
|
461 __NAKED__ EXPORT_C TPtr8 TDes8::RightTPtr(TInt /*aLength*/) const |
|
462 // |
|
463 // Extract the right portion of the descriptor. |
|
464 // |
|
465 { |
|
466 // On entry r0=return store ptr, r1=this, r2=aLength |
|
467 // Return TPtr8 ([r0]=length/type,[r0,#4]=maxLength,[r0,#8]=Ptr) |
|
468 asm("ldr r3, [r1], #4 "); // r3=this.length/type |
|
469 asm("cmp r2, #0 "); // check aLength>=0 |
|
470 asm("blt Des8PanicPosOutOfRange__Fv "); // if not, panic |
|
471 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
472 asm("cmp r2, r12 "); // limit aLength to Length() |
|
473 asm("movgt r2, r12 "); |
|
474 asm("cmp r3, #0x50000000 "); // check type() <= 4 |
|
475 asm("bcs Des8PanicBadDesType__Fv "); |
|
476 asm("eor r3, r3, r3, lsr #1 "); |
|
477 asm("msr cpsr_flg, r3 "); |
|
478 asm("addcs r1, r1, #4 "); |
|
479 asm("ldrle r1, [r1] "); |
|
480 asm("addeq r1, r1, #4 "); // r1=this.Ptr() |
|
481 asm("add r3, r1, r12 "); // r3=this.Ptr()+Length() |
|
482 asm("orr r1, r2, #0x20000000 "); // r1=aLength + EPtr |
|
483 asm("sub r3, r3, r2 "); // r3=Ptr()+Length()-aLength |
|
484 asm("stmia r0, {r1-r3} "); |
|
485 __JUMP(,lr); |
|
486 } |
|
487 |
|
488 __NAKED__ EXPORT_C TPtr8 TDes8::MidTPtr(TInt /*aPos*/) const |
|
489 // |
|
490 // Extract the middle portion of the descriptor. |
|
491 // |
|
492 { |
|
493 // On entry r0=return store ptr, r1=this, r2=aPos |
|
494 // Return TPtr8 ([r0]=length/type,[r0,#4]=maxLength,[r0,#8]=Ptr) |
|
495 asm("ldr r3, [r1], #4 "); // r3=this.length/type |
|
496 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
497 asm("cmp r2, #0 "); // check aPos>=0 |
|
498 asm("cmpge r12, r2 "); // if so check Length()>=aPos |
|
499 asm("blt Des8PanicPosOutOfRange__Fv "); |
|
500 asm("cmp r3, #0x50000000 "); // check type() <= 4 |
|
501 asm("bcs Des8PanicBadDesType__Fv "); |
|
502 asm("eor r3, r3, r3, lsr #1 "); |
|
503 asm("msr cpsr_flg, r3 "); |
|
504 asm("addcs r1, r1, #4 "); |
|
505 asm("ldrle r1, [r1] "); |
|
506 asm("addeq r1, r1, #4 "); // r1=this.Ptr() |
|
507 asm("add r3, r1, r2 "); // r3=this.Ptr()+aPos |
|
508 asm("sub r2, r12, r2 "); // r2=Length()-aPos (=newMaxLen) |
|
509 asm("orr r1, r2, #0x20000000 "); // r1=Length()-aPos + EPtr (=newLen/Type) |
|
510 asm("stmia r0, {r1-r3} "); |
|
511 __JUMP(,lr); |
|
512 } |
|
513 |
|
514 __NAKED__ EXPORT_C TPtr8 TDes8::MidTPtr(TInt /*aPos*/,TInt /*aLength*/) const |
|
515 // |
|
516 // Extract the middle portion of the descriptor. |
|
517 // |
|
518 { |
|
519 // On entry r0=return store ptr, r1=this, r2=aPos, r3=aLength |
|
520 // Return TPtr8 ([r0]=length/type,[r0,#4]=maxLength,[r0,#8]=Ptr) |
|
521 asm("str r4, [sp, #-4]! "); // save r4 |
|
522 asm("ldr r12, [r1], #4 "); // r12=this.length/type |
|
523 asm("mov r4, r1 "); |
|
524 asm("cmp r12, #0x50000000 "); // check valid descriptor type |
|
525 asm("bcs Des8PanicBadDesType__Fv "); |
|
526 asm("eor r12, r12, r12, lsr #1 "); |
|
527 asm("msr cpsr_flg, r12 "); |
|
528 asm("ldr r12, [r1, #-4] "); |
|
529 asm("addcs r4, r4, #4 "); |
|
530 asm("ldrle r4, [r4] "); |
|
531 asm("bic r12, r12, #0xF0000000 "); // r12=Length() |
|
532 asm("addeq r4, r4, #4 "); // r4=this.Ptr() |
|
533 asm("cmp r2, #0 "); // check aPos>=0 |
|
534 asm("subge r12, r12, r2 "); // if so, r12=Length()-aPos |
|
535 asm("cmpge r12, r3 "); // and check Length()-aPos>=aLength |
|
536 asm("orrge r1, r3, #0x20000000 "); // if so, r1=aLength + EPtr |
|
537 asm("addge r3, r4, r2 "); // and r3=this.Ptr()+aPos |
|
538 asm("bicge r2, r1, #0xF0000000 "); // and r2=aLength |
|
539 asm("stmgeia r0, {r1-r3} "); |
|
540 asm("ldrge r4, [sp], #4 "); |
|
541 __JUMP(ge,lr); |
|
542 asm("b Des8PanicPosOutOfRange__Fv "); |
|
543 } |
|
544 #endif |
|
545 |
|
546 __NAKED__ EXPORT_C const TUint8 &TDesC8::AtC(TInt /*anIndex*/) const |
|
547 // |
|
548 // Return a reference to the character in the buffer. |
|
549 // |
|
550 { |
|
551 asm("ldr r2, [r0], #4 "); // r2=length/type |
|
552 asm("bic r3, r2, #0xF0000000 "); // r3=length |
|
553 asm("cmp r2, #0x50000000 "); |
|
554 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
555 asm("eor r2, r2, r2, lsr #1 "); |
|
556 asm("msr cpsr_flg, r2 "); |
|
557 asm("addcs r0, r0, #4 "); |
|
558 asm("ldrle r0, [r0] "); |
|
559 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
560 asm("cmp r1, #0 "); // check index>=0 |
|
561 asm("cmpge r3, r1 "); // if so, check Length()>index |
|
562 asm("addgt r0, r0, r1 "); // return value = this.Ptr()+index |
|
563 __JUMP(gt,lr); |
|
564 asm("b " CSM_Z27Des8PanicDesIndexOutOfRangev); |
|
565 } |
|
566 |
|
567 __NAKED__ EXPORT_C TInt TDesC8::Locate(TChar /*aChar*/) const |
|
568 // |
|
569 // Locate character aChar in the descriptor. |
|
570 // |
|
571 { |
|
572 asm("ldr r2, [r0], #4 "); // r2=length/type |
|
573 asm("cmp r2, #0x50000000 "); |
|
574 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
575 asm("bics r3, r2, #0xF0000000 "); // r3=length |
|
576 asm("mvneq r0, #0 "); // if length=0, not found |
|
577 __JUMP(eq,lr); |
|
578 asm("eor r2, r2, r2, lsr #1 "); |
|
579 asm("msr cpsr_flg, r2 "); |
|
580 asm("addcs r0, r0, #4 "); |
|
581 asm("ldrle r0, [r0] "); |
|
582 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
583 asm("add r3, r3, r0 "); // r3=ptr+length |
|
584 asm("add r12, r0, #1 "); // r12=ptr+1 |
|
585 asm("1: "); |
|
586 asm("ldrb r2, [r0], #1 "); // r2=*r0++ |
|
587 asm("cmp r1, r2 "); // is r1=match char? |
|
588 asm("cmpne r0, r3 "); // if not, is r0=r3 (end pointer) |
|
589 asm("bne 1b "); |
|
590 asm("cmp r1, r2 "); // did we find char? |
|
591 asm("subeq r0, r0, r12 "); // if we did, return value = r0-ptr-1 |
|
592 asm("mvnne r0, #0 "); // else return value =-1 |
|
593 __JUMP(,lr); |
|
594 } |
|
595 |
|
596 __NAKED__ EXPORT_C TInt TDesC8::LocateReverse(TChar /*aChar*/) const |
|
597 // |
|
598 // Locate character aChar in the descriptor in reverse. |
|
599 // |
|
600 { |
|
601 asm("ldr r2, [r0], #4 "); // r2=length/type |
|
602 asm("cmp r2, #0x50000000 "); |
|
603 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
604 asm("bics r3, r2, #0xF0000000 "); // r3=length |
|
605 asm("mvneq r0, #0 "); // if length=0, not found |
|
606 __JUMP(eq,lr); |
|
607 asm("eor r2, r2, r2, lsr #1 "); |
|
608 asm("msr cpsr_flg, r2 "); |
|
609 asm("addcs r0, r0, #4 "); |
|
610 asm("ldrle r0, [r0] "); |
|
611 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
612 asm("sub r0, r0, #1 "); // r0=Ptr-1 |
|
613 asm("1: "); |
|
614 asm("ldrb r2, [r0, r3] "); // r2=Ptr[r3-1] |
|
615 asm("cmp r1, r2 "); // is r1=match char? |
|
616 asm("subnes r3, r3, #1 "); // if not, decrement char count |
|
617 asm("bne 1b "); |
|
618 asm("cmp r1, r2 "); // did we find match char? |
|
619 asm("subeq r0, r3, #1 "); // if we did, return value = r3-1 |
|
620 asm("mvnne r0, #0 "); // else return value =-1 |
|
621 __JUMP(,lr); |
|
622 } |
|
623 |
|
624 #ifndef __KERNEL_MODE__ |
|
625 __NAKED__ EXPORT_C TInt TDesC8::CompareF(const TDesC8& /*aDes*/) const |
|
626 // |
|
627 // Compare a descriptor to this descriptor folded. |
|
628 // |
|
629 { |
|
630 asm("ldr r12, 1f "); |
|
631 asm("b comparebody "); |
|
632 asm("1: "); |
|
633 asm(".word " CSM_ZN3Mem8CompareFEPKhiS0_i); |
|
634 } |
|
635 |
|
636 __NAKED__ EXPORT_C TInt TDesC8::CompareC(const TDesC8& /*aDes*/) const |
|
637 // |
|
638 // Compare a descriptor to this descriptor collated. |
|
639 // |
|
640 { |
|
641 asm("ldr r12, 1f "); |
|
642 asm("b comparebody "); |
|
643 asm("1: "); |
|
644 asm(".word " CSM_ZN3Mem8CompareCEPKhiS0_i); |
|
645 } |
|
646 #endif |
|
647 |
|
648 __NAKED__ EXPORT_C TInt TDesC8::Compare(const TDesC8& /*aDes*/) const |
|
649 // |
|
650 // Compare a descriptor to this descriptor. |
|
651 // |
|
652 { |
|
653 asm("ldr r12, 1f "); |
|
654 asm("comparebody: "); |
|
655 asm("mov r2, r1 "); // r2=&aDes |
|
656 asm("ldr r3, [r0], #4 "); // r3=this.length/type |
|
657 asm("cmp r3, #0x50000000 "); |
|
658 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
659 asm("bic r1, r3, #0xF0000000 "); // r1=this.Length() |
|
660 asm("eor r3, r3, r3, lsr #1 "); |
|
661 asm("msr cpsr_flg, r3 "); |
|
662 asm("addcs r0, r0, #4 "); |
|
663 asm("ldrle r0, [r0] "); |
|
664 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
665 asm("ldr r3, [r2], #4 "); // r3=aDes.length/type |
|
666 asm("cmp r3, #0x50000000 "); |
|
667 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
668 asm("eor r3, r3, r3, lsr #1 "); |
|
669 asm("msr cpsr_flg, r3 "); |
|
670 asm("ldr r3, [r2, #-4] "); |
|
671 asm("bic r3, r3, #0xF0000000 "); // r3=aDes.Length() |
|
672 asm("addcs r2, r2, #4 "); |
|
673 asm("ldrle r2, [r2] "); |
|
674 asm("addeq r2, r2, #4 "); // r2=aDes.Ptr() |
|
675 __JUMP(,r12); |
|
676 |
|
677 asm("1: "); |
|
678 asm(".word memcompare "); |
|
679 } |
|
680 #endif // __DES8_MACHINE_CODED__ |
|
681 |
|
682 #if defined(__DES8_MACHINE_CODED__) && !defined(__EABI__) |
|
683 __NAKED__ EXPORT_C TPtrC8 TDesC8::Left(TInt /*aLength*/) const |
|
684 // |
|
685 // Extract the left portion of the descriptor. |
|
686 // |
|
687 { |
|
688 // On entry r0=this, r1=aLength |
|
689 // Return TPtrC8 in r0,r1 |
|
690 asm("ldr r3, [r0], #4 "); // r3=this.length/type |
|
691 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
692 asm("cmp r1, #0 "); // check aLength>=0 |
|
693 asm("blt " CSM_Z22Des8PanicPosOutOfRangev); // if not panic |
|
694 asm("cmp r1, r12 "); // else limit aLength to Length() |
|
695 asm("movgt r1, r12 "); |
|
696 asm("cmp r3, #0x50000000 "); |
|
697 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
698 asm("eor r3, r3, r3, lsr #1 "); |
|
699 asm("msr cpsr_flg, r3 "); |
|
700 asm("addcs r0, r0, #4 "); |
|
701 asm("ldrle r0, [r0] "); |
|
702 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
703 asm("orr r2, r1, #0x10000000 "); // r2=aLength + EPtrC |
|
704 asm("mov r1, r0 "); // r1=result ptr |
|
705 asm("mov r0, r2 "); // r0=result type/length |
|
706 __JUMP(,lr); |
|
707 } |
|
708 |
|
709 __NAKED__ EXPORT_C TPtrC8 TDesC8::Right(TInt /*aLength*/) const |
|
710 // |
|
711 // Extract the right portion of the descriptor. |
|
712 // |
|
713 { |
|
714 // On entry r0=this, r1=aLength |
|
715 // Return TPtrC8 in r0,r1 |
|
716 asm("ldr r3, [r0], #4 "); // r3=this.length/type |
|
717 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
718 asm("cmp r1, #0 "); // check aLength>=0 |
|
719 asm("blt " CSM_Z22Des8PanicPosOutOfRangev); // if not, panic |
|
720 asm("cmp r1, r12 "); // else limit aLength to Length() |
|
721 asm("movgt r1, r12 "); |
|
722 asm("cmp r3, #0x50000000 "); |
|
723 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
724 asm("eor r3, r3, r3, lsr #1 "); |
|
725 asm("msr cpsr_flg, r3 "); |
|
726 asm("addcs r0, r0, #4 "); |
|
727 asm("ldrle r0, [r0] "); |
|
728 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
729 asm("add r3, r0, r12 "); // r3=this.Ptr()+len |
|
730 asm("orr r0, r1, #0x10000000 "); // r0=aLength + EPtrC |
|
731 asm("sub r1, r3, r1 "); // r1=Ptr()+len-aLength |
|
732 __JUMP(,lr); |
|
733 } |
|
734 |
|
735 __NAKED__ EXPORT_C TPtrC8 TDesC8::Mid(TInt /*aPos*/) const |
|
736 // |
|
737 // Extract the middle portion of the descriptor. |
|
738 // |
|
739 { |
|
740 // On entry r0=this, r1=aPos |
|
741 // Return TPtrC8 in r0,r1 |
|
742 asm("ldr r3, [r0], #4 "); // r3=this.length/type |
|
743 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
744 asm("cmp r1, #0 "); // check aPos>=0 |
|
745 asm("cmpge r12, r1 "); // if so check Length()>=aPos |
|
746 asm("blt " CSM_Z22Des8PanicPosOutOfRangev); |
|
747 asm("cmp r3, #0x50000000 "); |
|
748 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
749 asm("eor r3, r3, r3, lsr #1 "); |
|
750 asm("msr cpsr_flg, r3 "); |
|
751 asm("addcs r0, r0, #4 "); |
|
752 asm("ldrle r0, [r0] "); |
|
753 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
754 asm("sub r2, r12, r1 "); // r2=len-aPos |
|
755 asm("add r1, r0, r1 "); // r1=this.Ptr()+aPos |
|
756 asm("orr r0, r2, #0x10000000 "); // r0=aLength + EPtrC |
|
757 __JUMP(,lr); |
|
758 } |
|
759 |
|
760 __NAKED__ EXPORT_C TPtrC8 TDesC8::Mid(TInt /*aPos*/,TInt /*aLength*/) const |
|
761 // |
|
762 // Extract the middle portion of the descriptor. |
|
763 // |
|
764 { |
|
765 // On entry r0=this, r1=aPos, r2=aLength |
|
766 // Return TPtrC8 in r0,r1 |
|
767 asm("ldr r12, [r0], #4 "); // r12=this.length/type |
|
768 asm("cmp r12, #0x50000000 "); // check valid descriptor type |
|
769 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
770 asm("eor r12, r12, r12, lsr #1 "); |
|
771 asm("msr cpsr_flg, r12 "); |
|
772 asm("ldr r12, [r0, #-4] "); |
|
773 asm("bic r12, r12, #0xF0000000 "); // r12=Length() |
|
774 asm("addcs r0, r0, #4 "); |
|
775 asm("ldrle r0, [r0] "); |
|
776 asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
777 asm("cmp r1, #0 "); // check aPos>=0 |
|
778 asm("subge r12, r12, r1 "); // if so, r12=Length()-aPos |
|
779 asm("cmpge r12, r2 "); // and check Length()-aPos>=aLength |
|
780 asm("addge r1, r1, r0 "); // if so, r1=Ptr()+aPos |
|
781 asm("orrge r0, r2, #0x10000000 "); // and r0 = aLength + EPtrC |
|
782 __JUMP(ge,lr); |
|
783 asm("b " CSM_Z22Des8PanicPosOutOfRangev); |
|
784 } |
|
785 #endif // defined(__DES8_MACHINE_CODED__) && !defined(__EABI__) |
|
786 |
|
787 #ifdef __DES8_MACHINE_CODED__ |
|
788 |
|
789 // Here are the __EABI__ compliant versions of the above |
|
790 #ifdef __EABI__ |
|
791 |
|
792 __NAKED__ EXPORT_C TPtrC8 TDesC8::Left(TInt /*aLength*/) const |
|
793 // |
|
794 // Extract the left portion of the descriptor. |
|
795 // |
|
796 { |
|
797 // On entry r0=return store ptr, r1=this, r2=aLength |
|
798 // Return TPtrC8 ([r0]=length/type,[r0,#4]=Ptr) |
|
799 asm("ldr r3, [r1], #4 "); // r3=this.length/type |
|
800 asm("cmp r2, #0 "); // check aLength>=0 |
|
801 asm("blt Des8PanicPosOutOfRange__Fv "); // if not panic |
|
802 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
803 asm("cmp r2, r12 "); // limit aLength to Length() |
|
804 asm("movgt r2, r12 "); |
|
805 asm("cmp r3, #0x50000000 "); // check type() <= 4 |
|
806 asm("bcs Des8PanicBadDesType__Fv "); // if not, panic |
|
807 asm("eor r3, r3, r3, lsr #1 "); |
|
808 asm("msr cpsr_flg, r3 "); |
|
809 asm("addcs r1, r1, #4 "); |
|
810 asm("ldrle r1, [r1] "); |
|
811 asm("addeq r1, r1, #4 "); // r1=this.Ptr() |
|
812 asm("mov r3, r1"); // r3=this.Ptr() |
|
813 asm("orr r1, r2, #0x10000000 "); // r1=aLength + EPtrC |
|
814 asm("stmia r0, {r1,r3} "); |
|
815 __JUMP(,lr); |
|
816 } |
|
817 |
|
818 __NAKED__ EXPORT_C TPtrC8 TDesC8::Right(TInt /*aLength*/) const |
|
819 // |
|
820 // Extract the right portion of the descriptor. |
|
821 // |
|
822 { |
|
823 // On entry r0=return store ptr, r1=this, r2=aLength |
|
824 // Return TPtrC8 ([r0]=length/type,[r0,#4]=Ptr) |
|
825 asm("ldr r3, [r1], #4 "); // r3=this.length/type |
|
826 asm("cmp r2, #0 "); // check aLength>=0 |
|
827 asm("blt Des8PanicPosOutOfRange__Fv "); // if not, panic |
|
828 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
829 asm("cmp r2, r12 "); // limit aLength to Length() |
|
830 asm("movgt r2, r12 "); |
|
831 asm("cmp r3, #0x50000000 "); // check type() <= 4 |
|
832 asm("bcs Des8PanicBadDesType__Fv "); |
|
833 asm("eor r3, r3, r3, lsr #1 "); |
|
834 asm("msr cpsr_flg, r3 "); |
|
835 asm("addcs r1, r1, #4 "); |
|
836 asm("ldrle r1, [r1] "); |
|
837 asm("addeq r1, r1, #4 "); // r3=this.Ptr() |
|
838 asm("add r3, r1, r12 "); // r3=this.Ptr()+Length() |
|
839 asm("orr r1, r2, #0x10000000 "); // r1=aLength + EPtrC |
|
840 asm("sub r3, r3, r2 "); // r3=Ptr()+Length()-aLength |
|
841 asm("stmia r0, {r1,r3} "); |
|
842 __JUMP(,lr); |
|
843 } |
|
844 |
|
845 __NAKED__ EXPORT_C TPtrC8 TDesC8::Mid(TInt /*aPos*/) const |
|
846 // |
|
847 // Extract the middle portion of the descriptor. |
|
848 // |
|
849 { |
|
850 // On entry r0=return store ptr, r1=this, r2=aPos |
|
851 // Return TPtrC8 ([r0]=length/type,[r0,#4]=Ptr) |
|
852 asm("ldr r3, [r1], #4 "); // r3=this.length/type |
|
853 asm("bic r12, r3, #0xF0000000 "); // r12=this.Length() |
|
854 asm("cmp r2, #0 "); // check aPos>=0 |
|
855 asm("cmpge r12, r2 "); // if so check Length()>=aPos |
|
856 asm("blt Des8PanicPosOutOfRange__Fv "); |
|
857 asm("cmp r3, #0x50000000 "); // check type() <= 4 |
|
858 asm("bcs Des8PanicBadDesType__Fv "); |
|
859 asm("eor r3, r3, r3, lsr #1 "); |
|
860 asm("msr cpsr_flg, r3 "); |
|
861 asm("addcs r1, r1, #4 "); |
|
862 asm("ldrle r1, [r1] "); |
|
863 asm("addeq r1, r1, #4 "); // r1=this.Ptr() |
|
864 asm("add r3, r1, r2 "); // r3=this.Ptr()+aPos |
|
865 asm("sub r2, r12, r2 "); // r2=Length()-aPos (=newMaxLen) |
|
866 asm("orr r1, r2, #0x10000000 "); // r1=Length()-aPos + EPtrC (=newLen/Type) |
|
867 asm("stmia r0, {r1,r3} "); |
|
868 __JUMP(,lr); |
|
869 } |
|
870 |
|
871 __NAKED__ EXPORT_C TPtrC8 TDesC8::Mid(TInt /*aPos*/,TInt /*aLength*/) const |
|
872 // |
|
873 // Extract the middle portion of the descriptor. |
|
874 // |
|
875 { |
|
876 // On entry r0=return store ptr, r1=this, r2=aPos, r3=aLength |
|
877 // Return TPtrC8 ([r0]=length/type,[r0,#4]=Ptr) |
|
878 asm("ldr r12, [r1], #4 "); // r12=this.length/type |
|
879 asm("cmp r12, #0x50000000 "); // check valid descriptor type |
|
880 asm("bcs Des8PanicBadDesType__Fv "); |
|
881 asm("eor r12, r12, r12, lsr #1 "); |
|
882 asm("msr cpsr_flg, r12 "); |
|
883 asm("ldr r12, [r1, #-4] "); |
|
884 asm("addcs r1, r1, #4 "); |
|
885 asm("ldrle r1, [r1] "); |
|
886 asm("bic r12, r12, #0xF0000000 "); // r12=Length() |
|
887 asm("addeq r1, r1, #4 "); // r1=this.Ptr() |
|
888 asm("cmp r2, #0 "); // check aPos>=0 |
|
889 asm("subge r12, r12, r2 "); // if so, r12=Length()-aPos |
|
890 asm("cmpge r12, r3 "); // and check Length()-aPos>=aLength |
|
891 asm("addge r2, r1, r2 "); // if so r2=this.Ptr()+aPos |
|
892 asm("orrge r1, r3, #0x10000000 "); // and r1=aLength + EPtrC |
|
893 asm("stmgeia r0, {r1,r2} "); |
|
894 __JUMP(ge,lr); |
|
895 asm("b Des8PanicPosOutOfRange__Fv "); |
|
896 } |
|
897 #endif |
|
898 |
|
899 __NAKED__ EXPORT_C void TDes8::Zero() |
|
900 // |
|
901 // Zero the buffer. |
|
902 // |
|
903 { |
|
904 asm("ldr r1, [r0] "); // r1=length/type |
|
905 asm("and r1, r1, #0xF0000000 "); // r1=type field, zero length |
|
906 asm("cmp r1, #0x40000000 "); // check for EBufCPtr |
|
907 asm("str r1, [r0] "); // store zero length |
|
908 __JUMP(ne,lr); |
|
909 asm("ldr r2, [r0, #8] "); // r2 = pointer to TBufCBase |
|
910 asm("mov r1, #0 "); |
|
911 asm("str r1, [r2] "); // update length of TBufCBase |
|
912 __JUMP(,lr); |
|
913 } |
|
914 |
|
915 #ifndef __KERNEL_MODE__ |
|
916 __NAKED__ EXPORT_C void TDes8::ZeroTerminate() |
|
917 // |
|
918 // Zero terminate at Length(). |
|
919 // |
|
920 { |
|
921 // Fall through to PtrZ below... |
|
922 } |
|
923 |
|
924 __NAKED__ EXPORT_C const TUint8 *TDes8::PtrZ() |
|
925 // |
|
926 // Return a pointer to a 0 terminated string. |
|
927 // |
|
928 { |
|
929 asm("ldmia r0, {r1,r2} "); // r1=length/type, r2=maxlength |
|
930 asm("bic r3, r1, #0xF0000000 "); // r3=Length(); |
|
931 asm("cmp r3, r2 "); // check Length()<MaxLength() |
|
932 asm("bge " CSM_Z20Des8PanicDesOverflowv); |
|
933 asm("cmp r1, #0x50000000 "); |
|
934 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
935 asm("eor r1, r1, r1, lsr #1 "); |
|
936 asm("msr cpsr_flg, r1 "); |
|
937 asm("add r0, r0, #4 "); |
|
938 asm("addcs r0, r0, #4 "); |
|
939 asm("ldrle r0, [r0] "); |
|
940 asm("addeq r0, r0, #4 "); // r0=Ptr() |
|
941 asm("mov r2, #0 "); |
|
942 asm("strb r2, [r0, r3] "); // Ptr()[Length()]=0; |
|
943 __JUMP(,lr); |
|
944 } |
|
945 #endif |
|
946 |
|
947 __NAKED__ EXPORT_C void TDes8::Append(TChar /*aChar*/) |
|
948 // |
|
949 // Add a character at the end of the string. |
|
950 // |
|
951 { |
|
952 asm("ldmia r0, {r2,r3} "); // r2=length/type, r3=maxlength |
|
953 asm("bic r12, r2, #0xF0000000 "); // r12=Length(); |
|
954 asm("cmp r12, r3 "); // check Length()<MaxLength() |
|
955 asm("bge " CSM_Z20Des8PanicDesOverflowv); |
|
956 asm("cmp r2, #0x50000000 "); |
|
957 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
958 asm("add r2, r2, #1 "); // increment length by 1 |
|
959 asm("str r2, [r0] "); // store new length |
|
960 asm("eor r2, r2, r2, lsr #1 "); |
|
961 asm("msr cpsr_flg, r2 "); |
|
962 asm("add r2, r0, #4 "); // r2=this+4 |
|
963 asm("addcs r2, r2, #4 "); |
|
964 asm("ldrle r2, [r2] "); |
|
965 asm("addeq r3, r12, #1 "); // if EBufCPtr, r3=Length()+1 |
|
966 asm("streq r3, [r2], #4 "); // and update length of TBufCBase, r2=Ptr() |
|
967 asm("strb r1, [r2, r12] "); // Ptr()[Length()]=aChar; |
|
968 __JUMP(,lr); |
|
969 } |
|
970 |
|
971 __NAKED__ EXPORT_C void TDes8::Append(const TDesC8& /*aDes*/) |
|
972 // |
|
973 // Append a descriptor to this descriptor. |
|
974 // |
|
975 { |
|
976 asm("ldr r3, [r1], #4 "); // r3=aDes.length/type |
|
977 asm("cmp r3, #0x50000000 "); |
|
978 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
979 asm("bics r2, r3, #0xF0000000 "); // r2=aDes.Length() |
|
980 __JUMP(eq,lr); |
|
981 asm("eor r3, r3, r3, lsr #1 "); |
|
982 asm("msr cpsr_flg, r3 "); |
|
983 asm("addcs r1, r1, #4 "); |
|
984 asm("ldrle r1, [r1] "); |
|
985 asm("addeq r1, r1, #4 "); // r1=aDes.Ptr() |
|
986 asm("b appendbody "); // use following routine for rest of job |
|
987 } |
|
988 |
|
989 __NAKED__ EXPORT_C void TDes8::Append(const TUint8* /*aBuf*/,TInt /*aLength*/) |
|
990 // |
|
991 // Append aLength from aBuf characters to the descriptor. |
|
992 // |
|
993 { |
|
994 asm("cmp r2, #0 "); // check aLength>=0 |
|
995 __JUMP(eq,lr); |
|
996 asm("blt " CSM_Z23Des8PanicLengthNegativev); |
|
997 asm("appendbody: "); |
|
998 asm("ldmia r0, {r3,r12} "); // r3=type/length, r12=maxlength |
|
999 asm("cmp r3, #0x50000000 "); |
|
1000 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
1001 asm("bic r3, r3, #0xF0000000 "); // r3=Length() |
|
1002 asm("sub r12, r12, r3 "); // r12=MaxLength-Length |
|
1003 asm("cmp r2, r12 "); // check aLength<=(MaxLength-Length) |
|
1004 asm("bgt " CSM_Z20Des8PanicDesOverflowv); |
|
1005 asm("ldr r12, [r0] "); |
|
1006 asm("add r12, r12, r2 "); // new length/type field |
|
1007 asm("str r12, [r0], #4 "); // store it |
|
1008 asm("eor r12, r12, r12, lsr #1 "); |
|
1009 asm("msr cpsr_flg, r12 "); |
|
1010 asm("addcs r0, r0, #4 "); |
|
1011 asm("ldrle r0, [r0] "); |
|
1012 asm("ldreq r12, [r0] "); // fetch length from TBufCBase |
|
1013 asm("addeq r12, r12, r2 "); // add aLength |
|
1014 asm("streq r12, [r0], #4 "); // update length of TBufCBase, r0=Ptr() |
|
1015 asm("add r0, r0, r3 "); // r0=Ptr()+Length() |
|
1016 asm("b memmove "); |
|
1017 } |
|
1018 |
|
1019 __NAKED__ EXPORT_C void TDes8::FillZ() |
|
1020 // |
|
1021 // Fill the descriptor with 0. |
|
1022 // |
|
1023 { |
|
1024 asm("ldr r2, [r0] "); // r2=length/type |
|
1025 asm("cmp r2, #0x50000000 "); |
|
1026 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
1027 asm("bic r1, r2, #0xF0000000 "); // r1=Length() |
|
1028 asm("eor r2, r2, r2, lsr #1 "); |
|
1029 asm("msr cpsr_flg, r2 "); |
|
1030 asm("add r0, r0, #4 "); |
|
1031 asm("addcs r0, r0, #4 "); |
|
1032 asm("ldrle r0, [r0] "); |
|
1033 asm("addeq r0, r0, #4 "); // r0=Ptr() |
|
1034 asm("b memclr "); |
|
1035 } |
|
1036 |
|
1037 __NAKED__ EXPORT_C void TDes8::Fill(TChar /*aChar*/) |
|
1038 // |
|
1039 // Fill the descriptor with aChar. |
|
1040 // |
|
1041 { |
|
1042 asm("ldr r3, [r0] "); // r3=length/type |
|
1043 asm("cmp r3, #0x50000000 "); |
|
1044 asm("bcs " CSM_Z19Des8PanicBadDesTypev); |
|
1045 asm("bic r2, r3, #0xF0000000 "); // r2=Length() |
|
1046 asm("eor r3, r3, r3, lsr #1 "); |
|
1047 asm("msr cpsr_flg, r3 "); |
|
1048 asm("add r0, r0, #4 "); |
|
1049 asm("addcs r0, r0, #4 "); |
|
1050 asm("ldrle r0, [r0] "); |
|
1051 asm("addeq r0, r0, #4 "); // r0=Ptr() |
|
1052 asm("b memset "); // memset(Ptr(),aChar,Length()) |
|
1053 } |
|
1054 #endif //__DES8_MACHINE_CODED__ |
|
1055 |
|
1056 #ifdef __DES_MACHINE_CODED__ |
|
1057 __NAKED__ GLDEF_C TInt __DoConvertNum(TUint /*aVal*/, TRadix /*aRadix*/, TUint /*aA*/, TUint8*& /*aDest*/) |
|
1058 { |
|
1059 asm("ldr ip, [r3] "); // ip = aDest |
|
1060 asm("cmp r1, #16 "); |
|
1061 asm("beq do_convert_hex "); |
|
1062 asm("cmp r1, #10 "); |
|
1063 asm("beq do_convert_dec "); |
|
1064 #ifdef __KERNEL_MODE__ |
|
1065 asm("mov r0, #%a0" : : "i" ((TInt)EInvalidRadix)); |
|
1066 asm("b " CSM_Z5Panic9TCdtPanic); |
|
1067 #else // !__KERNEL_MODE__ |
|
1068 asm("cmp r1, #2 "); |
|
1069 asm("beq do_convert_bin "); |
|
1070 asm("cmp r1, #8 "); |
|
1071 asm("beq do_convert_oct "); |
|
1072 asm("do_convert_any: "); |
|
1073 asm("stmfd sp!, {r4-r8,lr} "); |
|
1074 asm("mov r5, r1 "); // save radix |
|
1075 asm("and r6, r2, #0xff "); |
|
1076 asm("sub r6, r6, #10 "); // save aA - 10 |
|
1077 asm("mov r4, ip "); // r4 = aDest |
|
1078 asm("mov r7, r3 "); // save &aDest |
|
1079 asm("mov r8, r2"); // save aA |
|
1080 asm("1: "); |
|
1081 asm("mov r1, r5 "); // r1 = radix |
|
1082 #ifndef __EABI__ |
|
1083 asm(".extern __umodsi3 "); |
|
1084 asm("bl __umodsi3 "); // do division, quotient->r3, rem->r0 |
|
1085 asm("mov r1, r0"); // move to make regs same as EABI function |
|
1086 asm("mov r0, r3"); |
|
1087 #else //__EABI__ |
|
1088 asm(".extern __aeabi_uidivmod "); |
|
1089 asm("bl __aeabi_uidivmod "); // do division, quotient->r0, rem->r1 |
|
1090 #endif //__EABI__ |
|
1091 asm("cmp r1, #9 "); |
|
1092 asm("addhi r1, r1, r6 "); // r1 = (r1 > 9) ? (r1 + (aA - 10)) : r1 + '0' |
|
1093 asm("addls r1, r1, #0x30 "); |
|
1094 asm("tst r8, #0x100 "); |
|
1095 asm("strneh r1, [r4, #-2]! "); // *--r4 = (TUint16)r1 |
|
1096 asm("streqb r1, [r4, #-1]! "); // *--r4 = (TUint8)r1 |
|
1097 asm("movs r1, r0 "); // new aVal into r1 |
|
1098 asm("bne 1b "); |
|
1099 asm("ldr ip, [r7] "); // ip can be scratched by __aeabi_uidivmod |
|
1100 asm("str r4, [r7] "); // aDest = r4 |
|
1101 asm("sub r0, ip, r4 "); // return aDest - r4 |
|
1102 __POPRET("r4-r8,"); |
|
1103 |
|
1104 asm("do_convert_bin: "); |
|
1105 asm("mov r2, r2, lsl #22 "); // aA bit 8 into bit 30 |
|
1106 asm("adds r2, r2, r2 "); // set V flag = aA bit 8 |
|
1107 asm("1: "); |
|
1108 asm("movs r0, r0, lsr #1 "); // aVal>>=1, bit 0 into carry, V unaffected |
|
1109 asm("mov r1, #0x30 "); // r1 = '0' |
|
1110 asm("adc r1, r1, #0 "); // add in carry |
|
1111 asm("strvsh r1, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1112 asm("strvcb r1, [ip, #-1]! "); // else store 8 bits |
|
1113 asm("bne 1b "); // loop back if aVal still nonzero |
|
1114 asm("ldr r1, [r3] "); // r1 = original aDest |
|
1115 asm("str ip, [r3] "); // aDest = ip |
|
1116 asm("sub r0, r1, ip "); // return aDest - ip |
|
1117 __JUMP(,lr); |
|
1118 |
|
1119 asm("do_convert_oct: "); |
|
1120 asm("mov r2, r2, lsl #22 "); // aA bit 8 into bit 30 |
|
1121 asm("adds r2, r2, r2 "); // set V flag = aA bit 8 |
|
1122 asm("1: "); |
|
1123 asm("and r1, r0, #7 "); // r1 = aVal & 7 |
|
1124 asm("movs r0, r0, lsr #3 "); // aVal>>=3, set Z accordingly, V unaffected |
|
1125 asm("add r1, r1, #0x30 "); // r1 += '0' |
|
1126 asm("strvsh r1, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1127 asm("strvcb r1, [ip, #-1]! "); // else store 8 bits |
|
1128 asm("bne 1b "); // loop back if aVal still nonzero |
|
1129 asm("ldr r1, [r3] "); // r1 = original aDest |
|
1130 asm("str ip, [r3] "); // aDest = ip |
|
1131 asm("sub r0, r1, ip "); // return aDest - ip |
|
1132 __JUMP(,lr); |
|
1133 #endif //__KERNEL_MODE__ |
|
1134 |
|
1135 asm("do_convert_hex: "); |
|
1136 asm("mov r1, r2, lsl #22 "); // aA bit 8 into r1 bit 30 |
|
1137 asm("adds r1, r1, r1 "); // set V flag = aA bit 8 |
|
1138 asm("and r2, r2, #0xff "); |
|
1139 asm("sub r2, r2, #0x40 "); |
|
1140 asm("1: "); |
|
1141 asm("and r1, r0, #15 "); // r1 = aVal & 15 |
|
1142 asm("add r1, r1, #0x36 "); // r1 += '0'+6 |
|
1143 asm("tst r1, #0x40 "); |
|
1144 asm("subeq r1, r1, #6 "); |
|
1145 asm("addne r1, r1, r2 "); |
|
1146 asm("movs r0, r0, lsr #4 "); // aVal>>=4, V unaffected |
|
1147 asm("strvsh r1, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1148 asm("strvcb r1, [ip, #-1]! "); // else store 8 bits |
|
1149 asm("bne 1b "); // loop back if aVal still nonzero |
|
1150 asm("ldr r1, [r3] "); // r1 = original aDest |
|
1151 asm("str ip, [r3] "); // aDest = ip |
|
1152 asm("sub r0, r1, ip "); // return aDest - ip |
|
1153 __JUMP(,lr); |
|
1154 |
|
1155 asm("do_convert_dec: "); |
|
1156 asm("and r2, r2, #0x100 "); // mask all bits of aA except bit 8 |
|
1157 asm("orr r3, r3, r2, lsr #8 "); // r3 bit 0 = aA bit 8 |
|
1158 asm("1: "); |
|
1159 asm("sub r1, r0, #10 "); // divide aVal by 10, r0=quotient, r1=remainder |
|
1160 asm("sub r0, r0, r0, lsr #2 "); |
|
1161 asm("add r0, r0, r0, lsr #4 "); |
|
1162 asm("add r0, r0, r0, lsr #8 "); |
|
1163 asm("add r0, r0, r0, lsr #16 "); |
|
1164 asm("mov r0, r0, lsr #3 "); |
|
1165 asm("add r2, r0, r0, lsl #2 "); |
|
1166 asm("subs r1, r1, r2, lsl #1 "); |
|
1167 asm("addpl r0, r0, #1 "); |
|
1168 asm("addmi r1, r1, #10 "); |
|
1169 asm("add r1, r1, #0x30 "); // add '0' to remainder |
|
1170 asm("tst r3, #1 "); // test aA bit 8 |
|
1171 asm("strneh r1, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1172 asm("streqb r1, [ip, #-1]! "); // else store 8 bits |
|
1173 asm("teq r0, #0 "); |
|
1174 asm("bne 1b "); // loop back if aVal still nonzero |
|
1175 asm("bic r3, r3, #1 "); |
|
1176 asm("ldr r1, [r3] "); // r1 = original aDest |
|
1177 asm("str ip, [r3] "); // aDest = ip |
|
1178 asm("sub r0, r1, ip "); // return aDest - ip |
|
1179 __JUMP(,lr); |
|
1180 } |
|
1181 |
|
1182 __NAKED__ GLDEF_C TInt __DoConvertNum(TUint64 /*aVal*/, TRadix /*aRadix*/, TUint /*aA*/, TUint8*& /*aDest*/) |
|
1183 { |
|
1184 asm("ldr ip, [sp] "); // ip = &aDest |
|
1185 asm("cmp r2, #16 "); |
|
1186 asm("beq do_convert_hex64 "); |
|
1187 asm("cmp r2, #10 "); |
|
1188 asm("beq do_convert_dec64 "); |
|
1189 #ifdef __KERNEL_MODE__ |
|
1190 asm("mov r0, #%a0" : : "i" ((TInt)EInvalidRadix)); |
|
1191 asm("b " CSM_Z5Panic9TCdtPanic); |
|
1192 #else // !__KERNEL_MODE__ |
|
1193 asm("cmp r2, #2 "); |
|
1194 asm("beq do_convert_bin64 "); |
|
1195 asm("cmp r2, #8 "); |
|
1196 asm("beq do_convert_oct64 "); |
|
1197 asm("stmfd sp!, {r4-r8,lr} "); |
|
1198 asm("ldr r4, [ip] "); // r4 = aDest |
|
1199 asm("mov r5, r2 "); // save radix |
|
1200 asm("and r6, r3, #0xff "); // r6 = aA & 0xff |
|
1201 asm("sub r6, r6, #10 "); // save a - 10 |
|
1202 asm("mov r7, ip "); // save &aDest |
|
1203 asm("mov r8, r3"); // save aA |
|
1204 asm("teq r1, #0 "); // aVal > 0xffffffffu |
|
1205 asm("beq 2f "); |
|
1206 asm("1: "); |
|
1207 asm("mov r3, #0 "); |
|
1208 asm("mov r2, r5 "); // r3:r2 = radix |
|
1209 #ifndef __EABI__ |
|
1210 asm("stmfd sp!, {r4-r6} "); // push the registers that are scratched by UDiv01 |
|
1211 asm(".extern UDiv01 "); |
|
1212 asm("bl UDiv01 "); // do division, quotient->r5:r4, rem->r6:r3 |
|
1213 asm("mov r0, r4"); // move to make regs same as EABI function |
|
1214 asm("mov r1, r5"); |
|
1215 asm("mov r2, r3"); |
|
1216 asm("mov r3, r6"); |
|
1217 asm("ldmfd sp!, {r4-r6} "); // pop the registers that are scratched by UDiv01 |
|
1218 #else //__EABI__ |
|
1219 asm(".extern __aeabi_uldivmod "); |
|
1220 asm("bl __aeabi_uldivmod "); // do division, quotient->r1:r0, rem->r3:r2 |
|
1221 #endif //__EABI__ |
|
1222 asm("cmp r2, #9 "); |
|
1223 asm("addhi r2, r2, r6 "); // r2 = (r2>9) ? r2+aA-10 : r2+'0' |
|
1224 asm("addls r2, r2, #0x30 "); |
|
1225 asm("tst r8, #0x100 "); |
|
1226 asm("strneh r2, [r4, #-2]! "); // *--r4 = (TUint16)r2 |
|
1227 asm("streqb r2, [r4, #-1]! "); // *--r4 = (TUint8)r2 |
|
1228 asm("teq r1, #0 "); // new aVal > 0xffffffffu |
|
1229 asm("bne 1b "); |
|
1230 asm("2: "); |
|
1231 asm("mov r2, r8 "); // r2 = aA |
|
1232 asm("ldr r1, [r7] "); // r1 = aDest |
|
1233 asm("mov r3, r7 "); // r3 = &aDest |
|
1234 asm("sub r6, r1, r4 "); // r6 = aDest - r4 |
|
1235 asm("mov r1, r5 "); // r1 = radix |
|
1236 asm("str r4, [r3] "); // aDest = r4 |
|
1237 asm("mov ip, r4 "); // ip = aDest |
|
1238 asm("bl do_convert_any "); |
|
1239 asm("add r0, r0, r6 "); // r0 += r6 |
|
1240 __POPRET("r4-r8,"); |
|
1241 |
|
1242 asm("do_convert_bin64: "); |
|
1243 asm("mov r2, ip "); // r2 = &aDest |
|
1244 asm("ldr ip, [ip] "); // ip = aDest |
|
1245 asm("mov r3, r3, lsl #22 "); // aA bit 8 into bit 30 |
|
1246 asm("adds r3, r3, r3 "); // set V flag = aA bit 8 |
|
1247 asm("teq r1, #0 "); // if (aVal <= 0xffffffffu) |
|
1248 asm("moveq r1, ip "); // r1 = orig. aDest in second half |
|
1249 asm("beq 2f "); // branch to second half of the loop |
|
1250 asm("1: "); |
|
1251 asm("movs r0, r0, lsr #1 "); // aVal >>= 1, bit 0 into carry, V unaffected |
|
1252 asm("mov r3, #0x30 "); // r3 = '0' |
|
1253 asm("adc r3, r3, #0 "); // add in carry |
|
1254 asm("strvsh r3, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1255 asm("strvcb r3, [ip, #-1]! "); // else store 8 bits |
|
1256 asm("bne 1b "); // loop back if (aVal & 0xffffffffu) still nonzero |
|
1257 asm("ldr r0, [r2] "); // r0 = original aDest |
|
1258 asm("subvc r0, r0, #32 "); // r0 = end of buffer for first word (8-bit descriptor) |
|
1259 asm("subvs r0, r0, #64 "); // r0 = end of buffer for first word (16-bit descriptor) |
|
1260 asm("teq ip, r0 "); // don't pad if we have already emitted 32 bits |
|
1261 asm("beq finish_bin_zero_pad "); |
|
1262 asm("bin_zero_pad: "); |
|
1263 asm("mov r3, #0x30 "); // r3 = '0' |
|
1264 asm("bin_zero_pad_loop: "); |
|
1265 asm("strvsh r3, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1266 asm("strvcb r3, [ip, #-1]! "); // else store 8 bits |
|
1267 asm("teq ip, r0 "); |
|
1268 asm("bne bin_zero_pad_loop "); // loop back if padding not complete |
|
1269 asm("finish_bin_zero_pad: "); |
|
1270 asm("addvc r0, r0, #32 "); // r0 = original aDest |
|
1271 asm("addvs r0, r0, #64 "); // r0 = original aDest |
|
1272 asm("mov r3, r1 "); |
|
1273 asm("mov r1, r0 "); |
|
1274 asm("mov r0, r3 "); // r1 = orig aDest, r0 = aVal >> 32 |
|
1275 asm("2: "); |
|
1276 asm("movs r0, r0, lsr #1 "); // aVal >>= 1, bit 0 into carry, V unaffected |
|
1277 asm("mov r3, #0x30 "); // r3 = '0' |
|
1278 asm("adc r3, r3, #0 "); // add in carry |
|
1279 asm("strvsh r3, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1280 asm("strvcb r3, [ip, #-1]! "); // else store 8 bits |
|
1281 asm("bne 2b "); // loop back if aVal still nonzero |
|
1282 asm("str ip, [r2] "); // aDest = ip |
|
1283 asm("sub r0, r1, ip "); // return aDest - ip |
|
1284 __JUMP(,lr); |
|
1285 |
|
1286 asm("do_convert_oct64: "); // Convert as 31 + 33 bits when > 32 bits |
|
1287 asm("mov r2, ip "); // r2 = &aDest |
|
1288 asm("ldr ip, [ip] "); // ip = aDest |
|
1289 asm("mov r3, r3, lsl #22 "); // aA bit 8 into bit 30 |
|
1290 asm("adds r3, r3, r3 "); // set V flag = aA bit 8 |
|
1291 asm("teq r1, #0 "); // if (aVal <= 0xffffffffu) |
|
1292 asm("moveq r1, ip "); // r1 = orig. aDest in second half |
|
1293 asm("beq 3f "); // branch to second half of the loop |
|
1294 asm("and r3, r0, #7 "); // r3 = aVal & 7 |
|
1295 asm("mov r0, r0, lsr #3 "); // aVal>>=3, set Z accordingly, V unaffected |
|
1296 asm("orr r0, r0, r1, lsl #29 "); // note we now have the bottom 33 bits in r0:r3[2:0] |
|
1297 asm("ands r0, r0, #0x3fffffff "); // and the top 31 bits in r1 |
|
1298 asm("mov r1, r1, lsr #1 "); |
|
1299 asm("add r3, r3, #0x30 "); // r3 += '0' |
|
1300 asm("strvsh r3, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1301 asm("strvcb r3, [ip, #-1]! "); // else store 8 bits |
|
1302 asm("beq 2f "); |
|
1303 asm("1: "); |
|
1304 asm("and r3, r0, #7 "); // r3 = aVal & 7 |
|
1305 asm("movs r0, r0, lsr #3 "); // aVal>>=3, set Z accordingly, V unaffected |
|
1306 asm("add r3, r3, #0x30 "); // r3 += '0' |
|
1307 asm("strvsh r3, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1308 asm("strvcb r3, [ip, #-1]! "); // else store 8 bits |
|
1309 asm("bne 1b "); // loop back if (aVal & 0xffffffff) still nonzero |
|
1310 asm("2: "); |
|
1311 asm("ldr r0, [r2] "); // r0 = original aDest |
|
1312 asm("subvc r0, r0, #11 "); // r0 = end of buffer for first word (8-bit descriptor) |
|
1313 asm("subvs r0, r0, #22 "); // r0 = end of buffer for first word (16-bit descriptor) |
|
1314 asm("teq ip, r0 "); // don't pad if we have already emitted 32 bits |
|
1315 asm("beq finish_oct_zero_pad "); |
|
1316 asm("oct_zero_pad: "); |
|
1317 asm("mov r3, #0x30 "); // r3 = '0' |
|
1318 asm("oct_zero_pad_loop: "); |
|
1319 asm("strvsh r3, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1320 asm("strvcb r3, [ip, #-1]! "); // else store 8 bits |
|
1321 asm("teq ip, r0 "); |
|
1322 asm("bne oct_zero_pad_loop "); // loop back if padding not complete |
|
1323 asm("finish_oct_zero_pad: "); |
|
1324 asm("addvc r0, r0, #11 "); // r0 = original aDest |
|
1325 asm("addvs r0, r0, #22 "); // r0 = original aDest |
|
1326 asm("mov r3, r0 "); |
|
1327 asm("mov r0, r1 "); |
|
1328 asm("mov r1, r3 "); // r1 = orig aDest, r0 = aVal >> 32 |
|
1329 asm("3: "); |
|
1330 asm("and r3, r0, #7 "); // r3 = aVal & 7 |
|
1331 asm("movs r0, r0, lsr #3 "); // aVal>>=3, set Z accordingly, V unaffected |
|
1332 asm("add r3, r3, #0x30 "); // r3 += '0' |
|
1333 asm("strvsh r3, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1334 asm("strvcb r3, [ip, #-1]! "); // else store 8 bits |
|
1335 asm("bne 3b "); // loop back if aVal still nonzero |
|
1336 asm("str ip, [r2] "); // aDest = ip |
|
1337 asm("sub r0, r1, ip "); // return aDest - ip |
|
1338 __JUMP(,lr); |
|
1339 |
|
1340 #endif //__KERNEL_MODE__ |
|
1341 |
|
1342 asm("do_convert_hex64: "); |
|
1343 asm("ldr ip, [ip] "); // ip = aDest |
|
1344 asm("mov r2, r3, lsl #22 "); // aA bit 8 into r2 bit 30 |
|
1345 asm("adds r2, r2, r2 "); // set V flag = aA bit 8 |
|
1346 asm("and r3, r3, #0xff "); // aA = aA & 0xff |
|
1347 asm("teq r1, #0 "); // if (aVal <= 0xffffffffu) |
|
1348 asm("sub r3, r3, #0x40 "); // bias by ('0' + 16) either way => r3 = aA - ('0' + 16) |
|
1349 asm("moveq r1, ip "); // r1 = orig. aDest in second half |
|
1350 asm("beq 2f "); // branch to second half of the loop |
|
1351 asm("1: "); |
|
1352 asm("and r2, r0, #0xf "); // r2 = aVal & 0xf |
|
1353 asm("add r2, r2, #0x36 "); // r2 += ('0' + 6) |
|
1354 asm("tst r2, #0x40 "); // if ((aVal & 0xf) > 9) |
|
1355 asm("addne r2, r2, r3 "); // r2 = (aVal & 0xf) + (aA - 10) |
|
1356 asm("subeq r2, r2, #6 "); // r2 = (aVal & 0xf) + '0' |
|
1357 asm("movs r0, r0, lsr #4 "); // aVal>>=4, V unaffected |
|
1358 asm("strvsh r2, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1359 asm("strvcb r2, [ip, #-1]! "); // else store 8 bits |
|
1360 asm("bne 1b "); // loop back if (aVal & 0xffffffffu) still nonzero |
|
1361 asm("ldr r0, [sp] "); // r0 = &aDest |
|
1362 asm("ldr r2, [r0] "); // r2 = original aDest |
|
1363 asm("subvc r0, r2, #8 "); // r0 = end of buffer for first word (8-bit descriptor) |
|
1364 asm("subvs r0, r2, #16 "); // r0 = end of buffer for first word (16-bit descriptor) |
|
1365 asm("teq ip, r0 "); // don't pad if we have already emitted 32 bits |
|
1366 asm("beq finish_hex_zero_pad "); |
|
1367 asm("hex_zero_pad: "); |
|
1368 asm("mov r2, #0x30 "); // r3 = '0' |
|
1369 asm("hex_zero_pad_loop: "); |
|
1370 asm("strvsh r2, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1371 asm("strvcb r2, [ip, #-1]! "); // else store 8 bits |
|
1372 asm("teq ip, r0 "); |
|
1373 asm("bne hex_zero_pad_loop "); // loop back if padding not complete |
|
1374 asm("finish_hex_zero_pad: "); |
|
1375 asm("addvc r0, r0, #8 "); // r0 = original aDest |
|
1376 asm("addvs r0, r0, #16 "); // r0 = original aDest |
|
1377 asm("mov r2, r0 "); |
|
1378 asm("mov r0, r1 "); |
|
1379 asm("mov r1, r2 "); // r1 = orig aDest, r0 = aVal >> 32 |
|
1380 asm("2: "); |
|
1381 asm("and r2, r0, #0xf "); // r2 = aVal & 0xf |
|
1382 asm("add r2, r2, #0x36 "); // r2 += '0'+6 |
|
1383 asm("tst r2, #0x40 "); |
|
1384 asm("subeq r2, r2, #6 "); // r2 = (aVal & 0xf) + '0' |
|
1385 asm("addne r2, r2, r3 "); // r2 = (aVal & 0xf) + (aA - 10) |
|
1386 asm("movs r0, r0, lsr #4 "); // aVal>>=4, V unaffected |
|
1387 asm("strvsh r2, [ip, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1388 asm("strvcb r2, [ip, #-1]! "); // else store 8 bits |
|
1389 asm("bne 2b "); // loop back if aVal still nonzero |
|
1390 asm("ldr r2, [sp] "); // r2 = &aDest |
|
1391 asm("sub r0, r1, ip "); // return aDest - ip |
|
1392 asm("str ip, [r2] "); // aDest = ip |
|
1393 __JUMP(,lr); |
|
1394 |
|
1395 #ifndef __FIXED_POINT_64BIT_DIV10__ |
|
1396 |
|
1397 asm("do_convert_dec64: "); // As generic case, except can save one reg as radix known |
|
1398 asm("stmfd sp!, {r4-r6,lr} "); |
|
1399 asm("ldr r4, [ip] "); // r4 = aDest |
|
1400 asm("mov r5, ip "); // save &aDest |
|
1401 asm("mov r6, r3"); // save aA |
|
1402 asm("teq r1, #0 "); // aVal > 0xffffffffu |
|
1403 asm("beq 2f "); |
|
1404 asm("1: "); |
|
1405 asm("mov r3, #0 "); |
|
1406 asm("mov r2, #10 "); // r3:r2 = radix |
|
1407 #ifndef __EABI__ |
|
1408 asm("stmfd sp!, {r4-r6} "); // push the registers that are scratched by UDiv01 |
|
1409 asm(".extern UDiv01 "); |
|
1410 asm("bl UDiv01 "); // do division, quotient->r5:r4, rem->r6:r3 |
|
1411 asm("mov r0, r4"); // move to make regs same as EABI function |
|
1412 asm("mov r1, r5"); |
|
1413 asm("mov r2, r3"); |
|
1414 asm("mov r3, r6"); |
|
1415 asm("ldmfd sp!, {r4-r6} "); // pop the registers that are scratched by UDiv01 |
|
1416 #else //__EABI__ |
|
1417 asm(".extern __aeabi_uldivmod "); |
|
1418 asm("bl __aeabi_uldivmod "); // do division, quotient->r1:r0, rem->r3:r2 |
|
1419 #endif //__EABI__ |
|
1420 asm("add r2, r2, #0x30 "); // add '0' to remainder |
|
1421 asm("tst r6, #0x100 "); |
|
1422 asm("strneh r2, [r4, #-2]! "); // *--r4 = (TUint16)r2 |
|
1423 asm("streqb r2, [r4, #-1]! "); // *--r4 = (TUint8)r2 |
|
1424 asm("teq r1, #0 "); // new aVal > 0xffffffffu |
|
1425 asm("bne 1b "); |
|
1426 asm("2: "); |
|
1427 asm("mov r2, r6 "); // r2 = aA |
|
1428 asm("ldr r1, [r5] "); // r1 = original aDest |
|
1429 asm("mov r3, r5 "); // r3 = &aDest |
|
1430 asm("sub r6, r1, r4 "); // r6 = original aDest - r4 |
|
1431 asm("mov r1, #10 "); // r1 = radix |
|
1432 asm("str r4, [r3] "); // aDest = r4 |
|
1433 asm("mov ip, r4 "); // ip = aDest |
|
1434 asm("bl do_convert_dec "); |
|
1435 asm("add r0, r0, r6 "); // r0 += r6 |
|
1436 __POPRET("r4-r6,"); |
|
1437 |
|
1438 #else //__FIXED_POINT_64BIT_DIV10__ |
|
1439 |
|
1440 asm("do_convert_dec64: "); // Be extra cunning by doing fixed-point arithmetic using only shifts, adds and subtracts |
|
1441 asm("stmfd sp!, {r4-r7,lr} "); // - avoids costs of potentially inefficient calls to __aeabi_uldivmod |
|
1442 asm("mov r4, r3 "); // r4 = aA |
|
1443 asm("ldr r5, [ip] "); // r5 = aDest |
|
1444 asm("teq r1, #0 "); // aVal > 0xffffffffu |
|
1445 asm("beq 2f "); |
|
1446 asm("1: "); |
|
1447 asm("subs r2, r0, #10 "); // divide aVal by 10, r1:r0=quotient, r3:r2=remainder |
|
1448 asm("sbc r3, r1, #0 "); |
|
1449 asm("mov r6, r0, lsr #2 "); // NB: 0.8 rounded to 64 bits is: |
|
1450 asm("orr r6, r6, r1, lsl #30 "); // 0.11001100110011001100110011001100110011001100110011001100110011 |
|
1451 asm("subs r0, r0, r6 "); |
|
1452 asm("sbc r1, r1, r1, lsr #2 "); // quotient -= quotient >> 2 (0.11) |
|
1453 asm("mov r6, r0, lsr #4 "); |
|
1454 asm("orr r6, r6, r1, lsl #28 "); |
|
1455 asm("adds r0, r0, r6 "); |
|
1456 asm("adc r1, r1, r1, lsr #4 "); // quotient += quotient >> 4 (0.110011) |
|
1457 asm("mov r6, r0, lsr #8 "); |
|
1458 asm("orr r6, r6, r1, lsl #24 "); |
|
1459 asm("adds r0, r0, r6 "); |
|
1460 asm("adc r1, r1, r1, lsr #8 "); // quotient += quotient >> 8 (0.11001100110011) |
|
1461 asm("mov r6, r0, lsr #16 "); |
|
1462 asm("orr r6, r6, r1, lsl #16 "); |
|
1463 asm("adds r0, r0, r6 "); |
|
1464 asm("adc r1, r1, r1, lsr #16 "); // quotient += quotient >> 16 (0.110011001100110011001100110011) |
|
1465 asm("adds r0, r0, r1 "); |
|
1466 asm("adc r1, r1, #0 "); // quotient += quotient >> 32 (0.11001100110011001100110011001100110011001100110011001100110011) |
|
1467 asm("mov r0, r0, lsr #3 "); |
|
1468 asm("orr r0, r0, r1, lsl #29 "); |
|
1469 asm("mov r1, r1, lsr #3 "); // quotient >>= 3 0.1 == (0.00011001100110011001100110011001100110011001100110011001100110011) |
|
1470 asm("mov r7, r1, lsl #2 "); // use r7:r6 as a temp |
|
1471 asm("orr r7, r7, r0, lsr #30 "); |
|
1472 asm("mov r6, r0, lsl #2 "); // r7:r6 = quotient << 2 == 4 * |aVal/10| |
|
1473 asm("adds r6, r6, r0 "); |
|
1474 asm("adc r7, r7, r1 "); // r7:r6 += quotient == 5 * |aVal/10| |
|
1475 asm("mov r7, r7, lsl #1 "); |
|
1476 asm("orr r7, r7, r6, lsr #31 "); |
|
1477 asm("mov r6, r6, lsl #1 "); // r7:r6 <<= 1 == 10 * |aVal/10| |
|
1478 asm("subs r2, r2, r6 "); |
|
1479 asm("sbcs r3, r3, r7 "); // r3:r2 = aVal - (10 * |aVal/10|) == remainder |
|
1480 asm("bpl fix_quotient "); |
|
1481 asm("adds r2, r2, #10 "); |
|
1482 asm("adc r3, r3, #0 "); // fix remainder |
|
1483 asm("b fix_end "); |
|
1484 asm("fix_quotient: "); |
|
1485 asm("adds r0, r0, #1 "); |
|
1486 asm("adc r1, r1, #0 "); // increment quotient |
|
1487 asm("fix_end: "); |
|
1488 asm("add r2, r2, #0x30 "); // add '0' to remainder |
|
1489 asm("tst r4, #0x100 "); // test aA bit 8 |
|
1490 asm("strneh r2, [r5, #-2]! "); // if aA bit 8 set, store 16 bits |
|
1491 asm("streqb r2, [r5, #-1]! "); // else store 8 bits |
|
1492 asm("teq r1, #0 "); |
|
1493 asm("bne 1b "); // loop back if new aVal > 0xffffffffu |
|
1494 asm("2: "); |
|
1495 asm("mov r2, r4 "); // r2 = aA |
|
1496 asm("ldr r1, [ip] "); // r1 = original aDest |
|
1497 asm("mov r3, ip "); // r3 = &aDest |
|
1498 asm("sub r6, r1, r5 "); // r6 = original aDest - r5 |
|
1499 asm("str r5, [r3] "); // aDest = r5 |
|
1500 asm("mov r1, #10 "); // r1 = radix |
|
1501 asm("mov ip, r5 "); // ip = aDest |
|
1502 asm("bl do_convert_dec "); |
|
1503 asm("add r0, r0, r6 "); // r0 += r6 |
|
1504 __POPRET("r4-r7,"); |
|
1505 |
|
1506 #endif //__FIXED_POINT_64BIT_DIV10__ |
|
1507 |
|
1508 } |
|
1509 |
|
1510 #endif //__DES_MACHINE_CODED__ |