Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\klib\arm\ckdes8.cia
20 #include <kernel/kernel.h>
22 #ifdef __DES8_MACHINE_CODED__
24 GLREF_C void KUDesInfoPanicBadDesType();
25 GLREF_C void KUDesSetLengthPanicBadDesType();
26 GLREF_C void KUDesSetLengthPanicOverflow();
27 GLREF_C void Des8PanicBadDesType();
30 Gets information about the specified descriptor.
32 If the current thread is a user thread, i.e. if the mode in spsr_svc is 'User',
33 then the descriptor is read using user mode privileges.
35 @param aSrc The descriptor for which information is to be fetched.
36 @param aLength On return, set to the length of the descriptor.
37 @param aMaxLength On return, set to the maximum length of the descriptor,
38 or 1 if the descriptor is not writable.
40 @return Address of first byte in descriptor.
42 @panic KERN-EXEC 33, if aSrc is not a valid descriptor type.
44 @pre Do not call from User thread if in a critical section.
45 @pre Interrupts must be enabled.
46 @pre Kernel must be unlocked.
47 @pre No fast mutex can be held.
48 @pre Call in a thread context.
49 @pre Can be used in a device driver.
51 EXPORT_C __NAKED__ const TUint8* Kern::KUDesInfo(const TDesC8& /*aSrc*/, TInt& /*aLength*/, TInt& /*aMaxLength*/)
53 // Get information about a user descriptor
56 ASM_CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX);
57 ASM_ASSERT_DATA_PAGING_SAFE // todo: should this be ASM_ASSERT_PAGING_SAFE?
60 asm("tst ip, #0x0f "); // test for user or supervisor
61 USER_MEMORY_GUARD_OFF(eq,r12,r12);
62 asm("ldreqt r3, [r0], #4 "); // if user r3=type/len
63 USER_MEMORY_GUARD_ON(eq,r12,r12);
64 asm("bne 1f "); // branch if supervisor
65 asm("bic ip, r3, #0xf0000000 "); // ip=length
66 asm("str ip, [r1] "); // store length
67 asm("mvn ip, #0 "); // ip=max length=-1 if not writeable
68 asm("cmp r3, #0x50000000 ");
69 asm("bcs " CSM_Z24KUDesInfoPanicBadDesTypev);
70 asm("eor r3, r3, r3, lsr #1 ");
71 asm("msr cpsr_flg, r3 ");
72 USER_MEMORY_GUARD_OFF(,r1,r1);
73 asm("ldrcst ip, [r0], #4 "); // if writeable ip=max length and r0+=4
74 asm("mov r1, r0 "); // NB can't use ldrlet r0, [r0] - see ARM ARM
75 asm("ldrlet r0, [r1] "); // if pointer, r0=pointer field
76 USER_MEMORY_GUARD_ON(,r1,r1);
79 asm("str ip, [r2] "); // store max length
80 asm("addeq r0, r0, #4 "); // if BufCPtr, step r0 past TBufC length
84 asm("ldr r3, [r0], #4 "); // r3=type/len
85 asm("bic ip, r3, #0xf0000000 "); // ip=length
86 asm("str ip, [r1] "); // store length
87 asm("mvn ip, #0 "); // ip=max length=-1 if not writeable
88 asm("cmp r3, #0x50000000 ");
89 asm("bcs " CSM_Z24KUDesInfoPanicBadDesTypev);
90 asm("eor r3, r3, r3, lsr #1 ");
91 asm("msr cpsr_flg, r3 ");
92 asm("ldrcs ip, [r0], #4 "); // if writeable ip=max length and r0+=4
93 asm("ldrle r0, [r0] "); // if pointer, r0=pointer field
99 Sets the length of the specified descriptor.
101 If the current thread is a user thread, i.e. if the mode in spsr_svc is 'User',
102 then the length is written using user mode privileges.
104 @param aDes The descriptor.
105 @param aLength The new descriptor length.
107 @panic KERN-EXEC 34, if aDes is not a modifiable descriptor type.
108 @panic KERN-EXEC 35, if aLength is longer that the maximum length of aDes.
110 @pre Do not call from User thread if in a critical section.
111 @pre Interrupts must be enabled.
112 @pre Kernel must be unlocked.
113 @pre No fast mutex can be held.
114 @pre Call in a thread context.
115 @pre Can be used in a device driver.
117 @post The length of aDes is equal to aLength.
118 @post If aDes is a TPtr type then its maximum length is equal its new length.
120 EXPORT_C __NAKED__ void Kern::KUDesSetLength(TDes8& /*aDes*/, TInt /*aLength*/)
122 // Set the length of a user descriptor, checking the length is O.K.
125 ASM_CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX);
126 ASM_ASSERT_DATA_PAGING_SAFE
128 asm("mrs ip, spsr ");
129 asm("tst ip, #0x0f ");
130 asm("bne " CSM_ZN5TDes89SetLengthEi);
131 USER_MEMORY_GUARD_OFF(,r12,r12);
132 asm("ldrt r2, [r0], #4 "); // r2=length/type, r0->maxlength
133 asm("ldrt r3, [r0], #-4 "); // r3=maxlength, r0->length/type
134 asm("and r2, r2, #0xf0000000 "); // r2=type field
135 asm("cmp r2, #0x20000000 "); // check for writeable descriptor
136 USER_MEMORY_GUARD_ON(cc,r12,r12);
137 asm("bcc " CSM_Z29KUDesSetLengthPanicBadDesTypev);
138 asm("cmp r1, r3 "); // check length
139 USER_MEMORY_GUARD_ON(hi,r12,r12);
140 asm("bhi " CSM_Z27KUDesSetLengthPanicOverflowv);
141 asm("cmp r2, #0x40000000 "); // check for EBufCPtr
142 asm("orr r2, r2, r1 "); // r2=type + new length
143 asm("strt r2, [r0], #8 "); // store new length, r0->ptr if EBufCPtr
144 USER_MEMORY_GUARD_ON(ne,r12,r12);
145 __JUMP(ne,lr); // if not EBufCPtr finished
146 asm("ldrt r2, [r0] "); // r2=pointer to TBufCBase
147 asm("strt r1, [r2] "); // update length of TBufCBase
148 USER_MEMORY_GUARD_ON(,r12,r12);
154 Checks whether the specified name is a valid Kernel-side object name.
156 A name is invalid, if it contains non-ascii characters, or any of
157 the three characters: "*", "?", ":".
159 @param aName The name to be checked.
161 @return KErrNone, if the name is valid; KErrBadName, if the name is invalid.
163 @pre Calling thread can be either in a critical section or not.
164 @pre Interrupts must be enabled.
165 @pre Kernel must be unlocked.
166 @pre No fast mutex can be held.
167 @pre Call in a thread context.
168 @pre Can be used in a device driver.
170 #ifndef __KERNEL_MODE__
171 #error "TDesC is not 8-bit as __KERNEL_MODE__ is not defined (see e32cmn.h)"
173 __NAKED__ EXPORT_C TInt Kern::ValidateName(const TDesC& /*aName*/)
175 // Check for : * or ? in descriptor, return KErrBadName if found
178 ASM_CHECK_PRECONDITIONS(MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX);
180 asm("ldr r2, [r0], #4 "); // r2=length/type
181 asm("cmp r2, #0x50000000 ");
182 asm("bcs " CSM_Z19Des8PanicBadDesTypev );
183 asm("bics r3, r2, #0xF0000000 "); // r3=length
184 asm("moveq r0, #0 "); // if length=0, return KErrNone
186 asm("eor r2, r2, r2, lsr #1 ");
187 asm("msr cpsr_flg, r2 ");
188 asm("addcs r0, r0, #4 ");
189 asm("ldrle r0, [r0] ");
190 asm("addeq r0, r0, #4 "); // r0=this.Ptr()
192 asm("ldrb r1, [r0], #1 "); // r1=*r0++
193 asm("cmp r1, #0x20 "); // is it < 0x20 ?
194 asm("rsbhss r2, r1, #0x7f "); // if not, compare 0x7f with char
195 asm("bls 2f "); // if char < 0x20 or 0x7f <= char, error
196 asm("cmp r1, #'*' "); // is it *
197 asm("cmpne r1, #':' "); // if not, is it :
198 asm("cmpne r1, #'?' "); // if not, is it ?
199 asm("subnes r3, r3, #1 "); // if none of these, decrement length
202 asm("cmp r3, #0 "); // reached end of string?
203 asm("moveq r0, #0 "); // if we did, return KErrNone
204 asm("mvnne r0, #%a0" : : "i" (~KErrBadName)); // else return KErrBadName
208 extern "C" EXPORT_C __NAKED__ TInt memicmp(const TAny* /*aLeft*/, const TAny* /*aRight*/, TUint /*aLength*/)
210 // r0 = aLeft, r1 = aRight, r2 = aLength
211 asm("str r4, [sp, #-4]! ");
212 asm("add r2, r2, #1 ");
215 asm("subs r2, r2, #1 ");
216 asm("ldrneb r3, [r0], #1 ");
218 asm("ldrb r4, [r1], #1 ");
219 asm("orr ip, r3, #0x20 ");
220 asm("cmp ip, #0x61 ");
221 asm("rsbcss ip, ip, #0x7a ");
222 asm("eors ip, r3, r4 ");
223 asm("andcss ip, ip, #0xdf ");
225 asm("orrcs r3, r3, #0x20 ");
226 asm("cmp r4, #0x41 ");
227 asm("rsbcss ip, r4, #0x5a ");
228 asm("orrcs r4, r4, #0x20 ");
229 asm("subs r0, r3, r4 ");
231 asm("moveq r0, #0 ");
232 asm("ldr r4, [sp], #4 ");