sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\klib\arm\ckdes8.cia sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #ifdef __DES8_MACHINE_CODED__ sl@0: sl@0: GLREF_C void KUDesInfoPanicBadDesType(); sl@0: GLREF_C void KUDesSetLengthPanicBadDesType(); sl@0: GLREF_C void KUDesSetLengthPanicOverflow(); sl@0: GLREF_C void Des8PanicBadDesType(); sl@0: sl@0: /** sl@0: Gets information about the specified descriptor. sl@0: sl@0: If the current thread is a user thread, i.e. if the mode in spsr_svc is 'User', sl@0: then the descriptor is read using user mode privileges. sl@0: sl@0: @param aSrc The descriptor for which information is to be fetched. sl@0: @param aLength On return, set to the length of the descriptor. sl@0: @param aMaxLength On return, set to the maximum length of the descriptor, sl@0: or 1 if the descriptor is not writable. sl@0: sl@0: @return Address of first byte in descriptor. sl@0: sl@0: @panic KERN-EXEC 33, if aSrc is not a valid descriptor type. sl@0: sl@0: @pre Do not call from User thread if in a critical section. sl@0: @pre Interrupts must be enabled. sl@0: @pre Kernel must be unlocked. sl@0: @pre No fast mutex can be held. sl@0: @pre Call in a thread context. sl@0: @pre Can be used in a device driver. sl@0: */ sl@0: EXPORT_C __NAKED__ const TUint8* Kern::KUDesInfo(const TDesC8& /*aSrc*/, TInt& /*aLength*/, TInt& /*aMaxLength*/) sl@0: // sl@0: // Get information about a user descriptor sl@0: // sl@0: { sl@0: ASM_CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX); sl@0: ASM_ASSERT_DATA_PAGING_SAFE // todo: should this be ASM_ASSERT_PAGING_SAFE? sl@0: sl@0: asm("mrs ip, spsr "); sl@0: asm("tst ip, #0x0f "); // test for user or supervisor sl@0: USER_MEMORY_GUARD_OFF(eq,r12,r12); sl@0: asm("ldreqt r3, [r0], #4 "); // if user r3=type/len sl@0: USER_MEMORY_GUARD_ON(eq,r12,r12); sl@0: asm("bne 1f "); // branch if supervisor sl@0: asm("bic ip, r3, #0xf0000000 "); // ip=length sl@0: asm("str ip, [r1] "); // store length sl@0: asm("mvn ip, #0 "); // ip=max length=-1 if not writeable sl@0: asm("cmp r3, #0x50000000 "); sl@0: asm("bcs " CSM_Z24KUDesInfoPanicBadDesTypev); sl@0: asm("eor r3, r3, r3, lsr #1 "); sl@0: asm("msr cpsr_flg, r3 "); sl@0: USER_MEMORY_GUARD_OFF(,r1,r1); sl@0: asm("ldrcst ip, [r0], #4 "); // if writeable ip=max length and r0+=4 sl@0: asm("mov r1, r0 "); // NB can't use ldrlet r0, [r0] - see ARM ARM sl@0: asm("ldrlet r0, [r1] "); // if pointer, r0=pointer field sl@0: USER_MEMORY_GUARD_ON(,r1,r1); sl@0: sl@0: asm("2: "); sl@0: asm("str ip, [r2] "); // store max length sl@0: asm("addeq r0, r0, #4 "); // if BufCPtr, step r0 past TBufC length sl@0: __JUMP(,lr); sl@0: sl@0: asm("1: "); sl@0: asm("ldr r3, [r0], #4 "); // r3=type/len sl@0: asm("bic ip, r3, #0xf0000000 "); // ip=length sl@0: asm("str ip, [r1] "); // store length sl@0: asm("mvn ip, #0 "); // ip=max length=-1 if not writeable sl@0: asm("cmp r3, #0x50000000 "); sl@0: asm("bcs " CSM_Z24KUDesInfoPanicBadDesTypev); sl@0: asm("eor r3, r3, r3, lsr #1 "); sl@0: asm("msr cpsr_flg, r3 "); sl@0: asm("ldrcs ip, [r0], #4 "); // if writeable ip=max length and r0+=4 sl@0: asm("ldrle r0, [r0] "); // if pointer, r0=pointer field sl@0: asm("b 2b "); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Sets the length of the specified descriptor. sl@0: sl@0: If the current thread is a user thread, i.e. if the mode in spsr_svc is 'User', sl@0: then the length is written using user mode privileges. sl@0: sl@0: @param aDes The descriptor. sl@0: @param aLength The new descriptor length. sl@0: sl@0: @panic KERN-EXEC 34, if aDes is not a modifiable descriptor type. sl@0: @panic KERN-EXEC 35, if aLength is longer that the maximum length of aDes. sl@0: sl@0: @pre Do not call from User thread if in a critical section. sl@0: @pre Interrupts must be enabled. sl@0: @pre Kernel must be unlocked. sl@0: @pre No fast mutex can be held. sl@0: @pre Call in a thread context. sl@0: @pre Can be used in a device driver. sl@0: sl@0: @post The length of aDes is equal to aLength. sl@0: @post If aDes is a TPtr type then its maximum length is equal its new length. sl@0: */ sl@0: EXPORT_C __NAKED__ void Kern::KUDesSetLength(TDes8& /*aDes*/, TInt /*aLength*/) sl@0: // sl@0: // Set the length of a user descriptor, checking the length is O.K. sl@0: // sl@0: { sl@0: ASM_CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX); sl@0: ASM_ASSERT_DATA_PAGING_SAFE sl@0: sl@0: asm("mrs ip, spsr "); sl@0: asm("tst ip, #0x0f "); sl@0: asm("bne " CSM_ZN5TDes89SetLengthEi); sl@0: USER_MEMORY_GUARD_OFF(,r12,r12); sl@0: asm("ldrt r2, [r0], #4 "); // r2=length/type, r0->maxlength sl@0: asm("ldrt r3, [r0], #-4 "); // r3=maxlength, r0->length/type sl@0: asm("and r2, r2, #0xf0000000 "); // r2=type field sl@0: asm("cmp r2, #0x20000000 "); // check for writeable descriptor sl@0: USER_MEMORY_GUARD_ON(cc,r12,r12); sl@0: asm("bcc " CSM_Z29KUDesSetLengthPanicBadDesTypev); sl@0: asm("cmp r1, r3 "); // check length sl@0: USER_MEMORY_GUARD_ON(hi,r12,r12); sl@0: asm("bhi " CSM_Z27KUDesSetLengthPanicOverflowv); sl@0: asm("cmp r2, #0x40000000 "); // check for EBufCPtr sl@0: asm("orr r2, r2, r1 "); // r2=type + new length sl@0: asm("strt r2, [r0], #8 "); // store new length, r0->ptr if EBufCPtr sl@0: USER_MEMORY_GUARD_ON(ne,r12,r12); sl@0: __JUMP(ne,lr); // if not EBufCPtr finished sl@0: asm("ldrt r2, [r0] "); // r2=pointer to TBufCBase sl@0: asm("strt r1, [r2] "); // update length of TBufCBase sl@0: USER_MEMORY_GUARD_ON(,r12,r12); sl@0: __JUMP(,lr); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Checks whether the specified name is a valid Kernel-side object name. sl@0: sl@0: A name is invalid, if it contains non-ascii characters, or any of sl@0: the three characters: "*", "?", ":". sl@0: sl@0: @param aName The name to be checked. sl@0: sl@0: @return KErrNone, if the name is valid; KErrBadName, if the name is invalid. sl@0: sl@0: @pre Calling thread can be either in a critical section or not. sl@0: @pre Interrupts must be enabled. sl@0: @pre Kernel must be unlocked. sl@0: @pre No fast mutex can be held. sl@0: @pre Call in a thread context. sl@0: @pre Can be used in a device driver. sl@0: */ sl@0: #ifndef __KERNEL_MODE__ sl@0: #error "TDesC is not 8-bit as __KERNEL_MODE__ is not defined (see e32cmn.h)" sl@0: #endif sl@0: __NAKED__ EXPORT_C TInt Kern::ValidateName(const TDesC& /*aName*/) sl@0: // sl@0: // Check for : * or ? in descriptor, return KErrBadName if found sl@0: // sl@0: { sl@0: ASM_CHECK_PRECONDITIONS(MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX); sl@0: sl@0: asm("ldr r2, [r0], #4 "); // r2=length/type sl@0: asm("cmp r2, #0x50000000 "); sl@0: asm("bcs " CSM_Z19Des8PanicBadDesTypev ); sl@0: asm("bics r3, r2, #0xF0000000 "); // r3=length sl@0: asm("moveq r0, #0 "); // if length=0, return KErrNone sl@0: __JUMP(eq,lr); sl@0: asm("eor r2, r2, r2, lsr #1 "); sl@0: asm("msr cpsr_flg, r2 "); sl@0: asm("addcs r0, r0, #4 "); sl@0: asm("ldrle r0, [r0] "); sl@0: asm("addeq r0, r0, #4 "); // r0=this.Ptr() sl@0: asm("1: "); sl@0: asm("ldrb r1, [r0], #1 "); // r1=*r0++ sl@0: asm("cmp r1, #0x20 "); // is it < 0x20 ? sl@0: asm("rsbhss r2, r1, #0x7f "); // if not, compare 0x7f with char sl@0: asm("bls 2f "); // if char < 0x20 or 0x7f <= char, error sl@0: asm("cmp r1, #'*' "); // is it * sl@0: asm("cmpne r1, #':' "); // if not, is it : sl@0: asm("cmpne r1, #'?' "); // if not, is it ? sl@0: asm("subnes r3, r3, #1 "); // if none of these, decrement length sl@0: asm("bne 1b "); sl@0: asm("2: "); sl@0: asm("cmp r3, #0 "); // reached end of string? sl@0: asm("moveq r0, #0 "); // if we did, return KErrNone sl@0: asm("mvnne r0, #%a0" : : "i" (~KErrBadName)); // else return KErrBadName sl@0: __JUMP(,lr); sl@0: } sl@0: sl@0: extern "C" EXPORT_C __NAKED__ TInt memicmp(const TAny* /*aLeft*/, const TAny* /*aRight*/, TUint /*aLength*/) sl@0: { sl@0: // r0 = aLeft, r1 = aRight, r2 = aLength sl@0: asm("str r4, [sp, #-4]! "); sl@0: asm("add r2, r2, #1 "); sl@0: sl@0: asm("1: "); sl@0: asm("subs r2, r2, #1 "); sl@0: asm("ldrneb r3, [r0], #1 "); sl@0: asm("beq 0f "); sl@0: asm("ldrb r4, [r1], #1 "); sl@0: asm("orr ip, r3, #0x20 "); sl@0: asm("cmp ip, #0x61 "); sl@0: asm("rsbcss ip, ip, #0x7a "); sl@0: asm("eors ip, r3, r4 "); sl@0: asm("andcss ip, ip, #0xdf "); sl@0: asm("beq 1b "); sl@0: asm("orrcs r3, r3, #0x20 "); sl@0: asm("cmp r4, #0x41 "); sl@0: asm("rsbcss ip, r4, #0x5a "); sl@0: asm("orrcs r4, r4, #0x20 "); sl@0: asm("subs r0, r3, r4 "); sl@0: asm("0: "); sl@0: asm("moveq r0, #0 "); sl@0: asm("ldr r4, [sp], #4 "); sl@0: __JUMP(,lr); sl@0: } sl@0: #endif sl@0: sl@0: sl@0: sl@0: