os/kernelhwsrv/kernel/eka/klib/arm/ckdes8.cia
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/klib/arm/ckdes8.cia	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,239 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\klib\arm\ckdes8.cia
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <e32cia.h>
    1.22 +#include <arm.h>
    1.23 +#include <kernel/kernel.h>
    1.24 +
    1.25 +#ifdef __DES8_MACHINE_CODED__
    1.26 +
    1.27 +GLREF_C void KUDesInfoPanicBadDesType();
    1.28 +GLREF_C void KUDesSetLengthPanicBadDesType();
    1.29 +GLREF_C void KUDesSetLengthPanicOverflow();
    1.30 +GLREF_C void Des8PanicBadDesType();
    1.31 +
    1.32 +/**
    1.33 +Gets information about the specified descriptor.
    1.34 +
    1.35 +If the current thread is a user thread, i.e. if the mode in spsr_svc is 'User',
    1.36 +then the descriptor is read using user mode privileges.
    1.37 +
    1.38 +@param aSrc The descriptor for which information is to be fetched.
    1.39 +@param aLength On return, set to the length of the descriptor.
    1.40 +@param aMaxLength On return, set to the maximum length of the descriptor,
    1.41 +                  or 1 if the descriptor is not writable.
    1.42 +
    1.43 +@return Address of first byte in descriptor.
    1.44 +
    1.45 +@panic KERN-EXEC 33, if aSrc is not a valid descriptor type.
    1.46 +
    1.47 +@pre  Do not call from User thread if in a critical section.
    1.48 +@pre  Interrupts must be enabled.
    1.49 +@pre  Kernel must be unlocked.
    1.50 +@pre  No fast mutex can be held.
    1.51 +@pre  Call in a thread context.
    1.52 +@pre  Can be used in a device driver.
    1.53 +*/
    1.54 +EXPORT_C __NAKED__ const TUint8* Kern::KUDesInfo(const TDesC8& /*aSrc*/, TInt& /*aLength*/, TInt& /*aMaxLength*/)
    1.55 +//
    1.56 +// Get information about a user descriptor
    1.57 +//
    1.58 +	{
    1.59 +	ASM_CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX);
    1.60 +	ASM_ASSERT_DATA_PAGING_SAFE		// todo: should this be ASM_ASSERT_PAGING_SAFE?
    1.61 +
    1.62 +	asm("mrs ip, spsr ");
    1.63 +	asm("tst ip, #0x0f ");			// test for user or supervisor
    1.64 +	USER_MEMORY_GUARD_OFF(eq,r12,r12);
    1.65 +	asm("ldreqt r3, [r0], #4 ");	// if user r3=type/len
    1.66 +	USER_MEMORY_GUARD_ON(eq,r12,r12);
    1.67 +	asm("bne 1f ");					// branch if supervisor
    1.68 +	asm("bic ip, r3, #0xf0000000 ");	// ip=length
    1.69 +	asm("str ip, [r1] ");			// store length
    1.70 +	asm("mvn ip, #0 ");				// ip=max length=-1 if not writeable
    1.71 +	asm("cmp r3, #0x50000000 ");
    1.72 +	asm("bcs  " CSM_Z24KUDesInfoPanicBadDesTypev);
    1.73 +	asm("eor r3, r3, r3, lsr #1 ");
    1.74 +	asm("msr cpsr_flg, r3 ");
    1.75 +	USER_MEMORY_GUARD_OFF(,r1,r1);
    1.76 +	asm("ldrcst ip, [r0], #4 ");	// if writeable ip=max length and r0+=4
    1.77 +	asm("mov r1, r0 ");				// NB can't use ldrlet r0, [r0] - see ARM ARM
    1.78 +	asm("ldrlet r0, [r1] ");		// if pointer, r0=pointer field
    1.79 +	USER_MEMORY_GUARD_ON(,r1,r1);
    1.80 +
    1.81 +	asm("2: ");
    1.82 +	asm("str ip, [r2] ");			// store max length
    1.83 +	asm("addeq r0, r0, #4 ");		// if BufCPtr, step r0 past TBufC length
    1.84 +	__JUMP(,lr);
    1.85 +
    1.86 +	asm("1: ");
    1.87 +	asm("ldr r3, [r0], #4 ");		// r3=type/len
    1.88 +	asm("bic ip, r3, #0xf0000000 ");	// ip=length
    1.89 +	asm("str ip, [r1] ");			// store length
    1.90 +	asm("mvn ip, #0 ");				// ip=max length=-1 if not writeable
    1.91 +	asm("cmp r3, #0x50000000 ");
    1.92 +	asm("bcs  " CSM_Z24KUDesInfoPanicBadDesTypev);
    1.93 +	asm("eor r3, r3, r3, lsr #1 ");
    1.94 +	asm("msr cpsr_flg, r3 ");
    1.95 +	asm("ldrcs ip, [r0], #4 ");		// if writeable ip=max length and r0+=4
    1.96 +	asm("ldrle r0, [r0] ");			// if pointer, r0=pointer field
    1.97 +	asm("b 2b ");
    1.98 +	}
    1.99 +
   1.100 +
   1.101 +/**
   1.102 +Sets the length of the specified descriptor.
   1.103 +
   1.104 +If the current thread is a user thread, i.e. if the mode in spsr_svc is 'User',
   1.105 +then the length is written using user mode privileges.
   1.106 +
   1.107 +@param aDes The descriptor.
   1.108 +@param aLength The new descriptor length.
   1.109 +
   1.110 +@panic KERN-EXEC 34, if aDes is not a modifiable descriptor type.
   1.111 +@panic KERN-EXEC 35, if aLength is longer that the maximum length of aDes.
   1.112 +
   1.113 +@pre  Do not call from User thread if in a critical section.
   1.114 +@pre  Interrupts must be enabled.
   1.115 +@pre  Kernel must be unlocked.
   1.116 +@pre  No fast mutex can be held.
   1.117 +@pre  Call in a thread context.
   1.118 +@pre  Can be used in a device driver.
   1.119 +
   1.120 +@post The length of aDes is equal to aLength.
   1.121 +@post If aDes is a TPtr type then its maximum length is equal its new length.
   1.122 +*/
   1.123 +EXPORT_C __NAKED__ void Kern::KUDesSetLength(TDes8& /*aDes*/, TInt /*aLength*/)
   1.124 +//
   1.125 +// Set the length of a user descriptor, checking the length is O.K.
   1.126 +//
   1.127 +	{
   1.128 +	ASM_CHECK_PRECONDITIONS(MASK_NO_CRITICAL_IF_USER|MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX);
   1.129 +	ASM_ASSERT_DATA_PAGING_SAFE
   1.130 +
   1.131 +	asm("mrs ip, spsr ");
   1.132 +	asm("tst ip, #0x0f ");
   1.133 +	asm("bne  " CSM_ZN5TDes89SetLengthEi);
   1.134 +	USER_MEMORY_GUARD_OFF(,r12,r12);
   1.135 +	asm("ldrt r2, [r0], #4 ");			// r2=length/type, r0->maxlength
   1.136 +	asm("ldrt r3, [r0], #-4 ");			// r3=maxlength, r0->length/type
   1.137 +	asm("and r2, r2, #0xf0000000 ");	// r2=type field
   1.138 +	asm("cmp r2, #0x20000000 ");		// check for writeable descriptor
   1.139 +	USER_MEMORY_GUARD_ON(cc,r12,r12);
   1.140 +	asm("bcc  " CSM_Z29KUDesSetLengthPanicBadDesTypev);
   1.141 +	asm("cmp r1, r3 ");					// check length
   1.142 +	USER_MEMORY_GUARD_ON(hi,r12,r12);
   1.143 +	asm("bhi  " CSM_Z27KUDesSetLengthPanicOverflowv);
   1.144 +	asm("cmp r2, #0x40000000 ");		// check for EBufCPtr
   1.145 +	asm("orr r2, r2, r1 ");				// r2=type + new length
   1.146 +	asm("strt r2, [r0], #8 ");			// store new length, r0->ptr if EBufCPtr
   1.147 +	USER_MEMORY_GUARD_ON(ne,r12,r12);
   1.148 +	__JUMP(ne,lr);						// if not EBufCPtr finished
   1.149 +	asm("ldrt r2, [r0] ");				// r2=pointer to TBufCBase
   1.150 +	asm("strt r1, [r2] ");				// update length of TBufCBase
   1.151 +	USER_MEMORY_GUARD_ON(,r12,r12);
   1.152 +	__JUMP(,lr);
   1.153 +  	}
   1.154 +
   1.155 +
   1.156 +/**
   1.157 +Checks whether the specified name is a valid Kernel-side object name.
   1.158 +
   1.159 +A name is invalid, if it contains non-ascii characters, or any of
   1.160 +the three characters: "*", "?", ":".
   1.161 +
   1.162 +@param  aName The name to be checked.
   1.163 +
   1.164 +@return KErrNone, if the name is valid; KErrBadName, if the name is invalid.
   1.165 +
   1.166 +@pre Calling thread can be either in a critical section or not.
   1.167 +@pre Interrupts must be enabled.
   1.168 +@pre Kernel must be unlocked.
   1.169 +@pre No fast mutex can be held.
   1.170 +@pre Call in a thread context.
   1.171 +@pre Can be used in a device driver.
   1.172 +*/
   1.173 +#ifndef __KERNEL_MODE__
   1.174 +#error "TDesC is not 8-bit as __KERNEL_MODE__ is not defined (see e32cmn.h)"
   1.175 +#endif
   1.176 +__NAKED__ EXPORT_C TInt Kern::ValidateName(const TDesC& /*aName*/)
   1.177 +//
   1.178 +// Check for : * or ? in descriptor, return KErrBadName if found
   1.179 +//
   1.180 +	{
   1.181 +	ASM_CHECK_PRECONDITIONS(MASK_INTERRUPTS_ENABLED|MASK_KERNEL_UNLOCKED|MASK_NOT_ISR|MASK_NOT_IDFC|MASK_NO_FAST_MUTEX);
   1.182 +
   1.183 +	asm("ldr r2, [r0], #4 ");			// r2=length/type
   1.184 +	asm("cmp r2, #0x50000000 ");
   1.185 +	asm("bcs " CSM_Z19Des8PanicBadDesTypev );
   1.186 +	asm("bics r3, r2, #0xF0000000 ");	// r3=length
   1.187 +	asm("moveq r0, #0 ");				// if length=0, return KErrNone
   1.188 +	__JUMP(eq,lr);
   1.189 +	asm("eor r2, r2, r2, lsr #1 ");
   1.190 +	asm("msr cpsr_flg, r2 ");
   1.191 +	asm("addcs r0, r0, #4 ");
   1.192 +	asm("ldrle r0, [r0] ");
   1.193 +	asm("addeq r0, r0, #4 ");			// r0=this.Ptr()
   1.194 +	asm("1: ");
   1.195 +	asm("ldrb r1, [r0], #1 ");			// r1=*r0++
   1.196 +	asm("cmp r1, #0x20 ");				// is it < 0x20 ?
   1.197 +	asm("rsbhss r2, r1, #0x7f ");		// if not, compare 0x7f with char
   1.198 +	asm("bls 2f ");						// if char < 0x20 or 0x7f <= char, error
   1.199 +	asm("cmp r1, #'*' ");				// is it *
   1.200 +	asm("cmpne r1, #':' ");				// if not, is it :
   1.201 +	asm("cmpne r1, #'?' ");				// if not, is it ?
   1.202 +	asm("subnes r3, r3, #1 ");			// if none of these, decrement length
   1.203 +	asm("bne 1b ");
   1.204 +	asm("2: ");
   1.205 +	asm("cmp r3, #0 ");					// reached end of string?
   1.206 +	asm("moveq r0, #0 ");				// if we did, return KErrNone
   1.207 +	asm("mvnne r0, #%a0" : : "i" (~KErrBadName));	// else return KErrBadName
   1.208 +	__JUMP(,lr);
   1.209 +	}
   1.210 +
   1.211 +extern "C" EXPORT_C __NAKED__ TInt memicmp(const TAny* /*aLeft*/, const TAny* /*aRight*/, TUint /*aLength*/)
   1.212 +    {
   1.213 +	// r0 = aLeft, r1 = aRight, r2 = aLength
   1.214 +	asm("str r4, [sp, #-4]! ");
   1.215 +	asm("add r2, r2, #1 ");
   1.216 +
   1.217 +	asm("1: ");
   1.218 +	asm("subs r2, r2, #1 ");
   1.219 +	asm("ldrneb r3, [r0], #1 ");
   1.220 +	asm("beq 0f ");
   1.221 +	asm("ldrb r4, [r1], #1 ");
   1.222 +	asm("orr ip, r3, #0x20 ");
   1.223 +	asm("cmp ip, #0x61 ");
   1.224 +	asm("rsbcss ip, ip, #0x7a ");
   1.225 +	asm("eors ip, r3, r4 ");
   1.226 +	asm("andcss ip, ip, #0xdf ");
   1.227 +	asm("beq 1b ");
   1.228 +	asm("orrcs r3, r3, #0x20 ");
   1.229 +	asm("cmp r4, #0x41 ");
   1.230 +	asm("rsbcss ip, r4, #0x5a ");
   1.231 +	asm("orrcs r4, r4, #0x20 ");
   1.232 +	asm("subs r0, r3, r4 ");
   1.233 +	asm("0: ");
   1.234 +	asm("moveq r0, #0 ");
   1.235 +	asm("ldr r4, [sp], #4 ");
   1.236 +	__JUMP(,lr);
   1.237 +	}
   1.238 +#endif
   1.239 +
   1.240 +
   1.241 +
   1.242 +