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.
16 #define INCLUDED_FROM_ASM
23 #define ASM_KILL_LINK(rp,rs) asm("mov "#rs", #0xdf ");\
24 asm("orr "#rs", "#rs", "#rs", lsl #8 ");\
25 asm("orr "#rs", "#rs", "#rs", lsl #16 ");\
26 asm("str "#rs", ["#rp"] ");\
27 asm("str "#rs", ["#rp", #4] ");
29 #define ASM_KILL_LINK(rp,rs)
33 extern "C" void __FaultIpcClientNotNull(); // defined in ckernel.cpp
37 __NAKED__ TInt DThread::ReadAndParseDesHeader(const TAny* aSrc, TDesHeader& aDest)
39 ASM_ASSERT_PAGING_SAFE;
40 // save state including 'this', aSrc and sDest. Double word aligns the stack
41 // which is required to call c++ functions.
42 asm("stmdb sp!, {r0-r2, r4-r8, r10, lr} ");
44 // Register use this method:
45 // r0 = 'this' until iIpcClient set.
46 // r1 = aSrc until read_and_parse_des_header_local.
47 // r2 = aDest until read_and_parse_des_header_local.
48 // r4 = target process
49 // r5 = current nthread
51 // r7 = current process
53 // r10 = os asid of current process.
55 // Open a reference on the target process's os asid as we will be switching to
56 // it so it can't be allowed to be freed and/or reused.
57 asm("ldr r4, [r0, #%a0]" : : "i" _FOFF(DThread,iOwningProcess)); // r4->target process
58 asm("bl " CSM_ZN5NKern13ThreadEnterCSEv); // First enter a critical section so can't leak os asid reference.
59 asm("mov r0, r4"); // r0 = target process ('this' for TryOpenOsAsid() below).
60 asm("bl " CSM_ZN16DMemModelProcess13TryOpenOsAsidEv);
61 // Check a reference could be opened on target process's os asid, failed if r0 < 0.
63 asm("bmi readParseDesHeader_ExitErr");
65 asm("mov r10, r0"); // r10 = os asid of current process
66 asm("ldmia sp!, {r0-r2}"); // r0 = this, r1 = aSrc, r2 = aDest
68 __ASM_CLI(); // disable all interrupts
70 GET_RWNO_TID(,r6); // r6->TSubScheduler
71 asm("ldr r7, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace)); // r7->current process
72 asm("ldr r5, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); // r5->current NThreadBase
74 asm("ldr r6, __TheScheduler "); // r6->TheScheduler
75 asm("ldr r7, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace)); // r7->current process
76 asm("ldr r5, [r6, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r5->current NThreadBase
79 // set TheCurrentThread->iIpcClient to this (r0) thread
81 asm("ldr r12, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread)));
83 asm("bne __FaultIpcClientNotNull ");
85 asm("str r0, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread)));
87 // switch address space to process r4...
88 asm("mrc p15, 0, r8, c2, c0, 0 "); // r8 = original TTBR0
89 asm("ldr r0, [r4, #%a0]" : : "i" _FOFF(DMemModelProcess,iPageDir)); // r0->target process page directory
90 asm("and lr, r8, #%a0" : : "i" ((TInt)KTTBRExtraBitsMask)); // lr = TTBR0 extra bits
91 asm("orr r0, r0, lr "); // r0 = target process page directory + extra bits
93 __ASM_SET_ADDRESS_SPACE(r10,r0,lr);
95 asm("str r4, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace));
97 asm("str r4, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace));
99 asm("str r4, [r5, #%a0]" : : "i" _FOFF(NThread,iAddressSpace));
100 __ASM_STI(); // enable all interrupts
102 // read and parse descriptor header, r1=aSrc, r2=aDest
103 asm("bl read_and_parse_des_header_local"); // defined in e32/kernel/arm/cipc.cia
105 // restore address space to process r7...
106 asm("ldr r12, [r7, #%a0]" : : "i" _FOFF(DMemModelProcess,iOsAsid)); // r12 = current process ASID
108 __ASM_CLI(); // disable all interrupts
109 __ASM_SET_ADDRESS_SPACE(r12,r8,lr);
111 GET_RWNO_TID(,r6); // r6->TSubScheduler
112 asm("str r7, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace));
114 asm("str r7, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace));
116 asm("str r7, [r5, #%a0]" : : "i" _FOFF(NThread,iAddressSpace));
117 __ASM_STI(); // enable all interrupts
119 // set TheCurrentThread->iIpcClient to NULL again
121 asm("str r12, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread)));
123 // close the reference on the target process's os asid.
124 asm("mov r6, r0"); // r6 = return value from read_and_parse_des_header_local
125 asm("mov r0, r4"); // r0 = target process
126 asm("bl " CSM_ZN16DMemModelProcess11CloseOsAsidEv);
129 asm("bl " CSM_ZN5NKern13ThreadLeaveCSEv); // Os asid reference closed so leave critical section.
130 asm("mov r0, r6"); // r0 = return value from read_and_parse_des_header_local.
131 __POPRET("r4-r8, r10, "); // Restore the state and return.
133 // exit with error...
134 asm("readParseDesHeader_ExitErr:");
135 asm("bl " CSM_ZN5NKern13ThreadLeaveCSEv); // Os asid reference not open so leave critical section.
136 asm("mov r0, #%a0" : : "i" ((TInt)KErrBadDescriptor));
137 asm("add sp, sp, #12"); // pop r0-r2 off the stack.
138 __POPRET("r4-r8, r10, "); // Restore the state and return.
141 asm("__TheScheduler: ");
142 asm(".word TheScheduler ");