author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 11:08:29 +0300 | |
changeset 247 | d8d70de2bd36 |
parent 109 | b3a1d9898418 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 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 |
// |
|
15 |
||
16 |
#define INCLUDED_FROM_ASM |
|
17 |
||
18 |
#include <e32cia.h> |
|
19 |
#include <arm_mem.h> |
|
20 |
#include "xdefs.h" |
|
21 |
||
22 |
#ifdef _DEBUG |
|
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] "); |
|
28 |
#else |
|
29 |
#define ASM_KILL_LINK(rp,rs) |
|
30 |
#endif |
|
31 |
||
32 |
#ifdef _DEBUG |
|
33 |
extern "C" void __FaultIpcClientNotNull(); // defined in ckernel.cpp |
|
34 |
#endif |
|
35 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
36 |
#ifdef _DEBUG |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
37 |
__NAKED__ TInt DoThreadReadAndParseDesHeader(DThread* aThread, const TAny* aSrc, TDesHeader& aDest) |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
38 |
#else |
0 | 39 |
__NAKED__ TInt DThread::ReadAndParseDesHeader(const TAny* aSrc, TDesHeader& aDest) |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
40 |
#endif |
0 | 41 |
{ |
42 |
ASM_ASSERT_PAGING_SAFE; |
|
43 |
// save state including 'this', aSrc and sDest. Double word aligns the stack |
|
44 |
// which is required to call c++ functions. |
|
45 |
asm("stmdb sp!, {r0-r2, r4-r8, r10, lr} "); |
|
46 |
||
47 |
// Register use this method: |
|
48 |
// r0 = 'this' until iIpcClient set. |
|
49 |
// r1 = aSrc until read_and_parse_des_header_local. |
|
50 |
// r2 = aDest until read_and_parse_des_header_local. |
|
51 |
// r4 = target process |
|
52 |
// r5 = current nthread |
|
53 |
// r6 = scheduler. |
|
54 |
// r7 = current process |
|
55 |
// r8 = orig ttbr0 |
|
56 |
// r10 = os asid of current process. |
|
57 |
||
58 |
// Open a reference on the target process's os asid as we will be switching to |
|
59 |
// it so it can't be allowed to be freed and/or reused. |
|
60 |
asm("ldr r4, [r0, #%a0]" : : "i" _FOFF(DThread,iOwningProcess)); // r4->target process |
|
61 |
asm("bl " CSM_ZN5NKern13ThreadEnterCSEv); // First enter a critical section so can't leak os asid reference. |
|
62 |
asm("mov r0, r4"); // r0 = target process ('this' for TryOpenOsAsid() below). |
|
63 |
asm("bl " CSM_ZN16DMemModelProcess13TryOpenOsAsidEv); |
|
64 |
// Check a reference could be opened on target process's os asid, failed if r0 < 0. |
|
65 |
asm("cmp r0, #0"); |
|
66 |
asm("bmi readParseDesHeader_ExitErr"); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
asm("mov r10, r0"); // r10 = os asid of current process |
0 | 68 |
|
69 |
asm("ldmia sp!, {r0-r2}"); // r0 = this, r1 = aSrc, r2 = aDest |
|
70 |
||
71 |
__ASM_CLI(); // disable all interrupts |
|
72 |
#ifdef __SMP__ |
|
73 |
GET_RWNO_TID(,r6); // r6->TSubScheduler |
|
74 |
asm("ldr r7, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace)); // r7->current process |
|
75 |
asm("ldr r5, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); // r5->current NThreadBase |
|
76 |
#else |
|
77 |
asm("ldr r6, __TheScheduler "); // r6->TheScheduler |
|
78 |
asm("ldr r7, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace)); // r7->current process |
|
79 |
asm("ldr r5, [r6, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r5->current NThreadBase |
|
80 |
#endif |
|
81 |
||
82 |
// set TheCurrentThread->iIpcClient to this (r0) thread |
|
83 |
#ifdef _DEBUG |
|
84 |
asm("ldr r12, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread))); |
|
85 |
asm("teq r12, #0 "); |
|
86 |
asm("bne __FaultIpcClientNotNull "); |
|
87 |
#endif |
|
88 |
asm("str r0, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread))); |
|
89 |
||
90 |
// switch address space to process r4... |
|
91 |
asm("mrc p15, 0, r8, c2, c0, 0 "); // r8 = original TTBR0 |
|
92 |
asm("ldr r0, [r4, #%a0]" : : "i" _FOFF(DMemModelProcess,iPageDir)); // r0->target process page directory |
|
93 |
asm("and lr, r8, #%a0" : : "i" ((TInt)KTTBRExtraBitsMask)); // lr = TTBR0 extra bits |
|
94 |
asm("orr r0, r0, lr "); // r0 = target process page directory + extra bits |
|
95 |
||
96 |
__ASM_SET_ADDRESS_SPACE(r10,r0,lr); |
|
97 |
#ifdef __SMP__ |
|
98 |
asm("str r4, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace)); |
|
99 |
#else |
|
100 |
asm("str r4, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace)); |
|
101 |
#endif |
|
102 |
asm("str r4, [r5, #%a0]" : : "i" _FOFF(NThread,iAddressSpace)); |
|
103 |
__ASM_STI(); // enable all interrupts |
|
104 |
||
105 |
// read and parse descriptor header, r1=aSrc, r2=aDest |
|
106 |
asm("bl read_and_parse_des_header_local"); // defined in e32/kernel/arm/cipc.cia |
|
107 |
||
108 |
// restore address space to process r7... |
|
109 |
asm("ldr r12, [r7, #%a0]" : : "i" _FOFF(DMemModelProcess,iOsAsid)); // r12 = current process ASID |
|
110 |
||
111 |
__ASM_CLI(); // disable all interrupts |
|
112 |
__ASM_SET_ADDRESS_SPACE(r12,r8,lr); |
|
113 |
#ifdef __SMP__ |
|
114 |
GET_RWNO_TID(,r6); // r6->TSubScheduler |
|
115 |
asm("str r7, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace)); |
|
116 |
#else |
|
117 |
asm("str r7, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace)); |
|
118 |
#endif |
|
119 |
asm("str r7, [r5, #%a0]" : : "i" _FOFF(NThread,iAddressSpace)); |
|
120 |
__ASM_STI(); // enable all interrupts |
|
121 |
||
122 |
// set TheCurrentThread->iIpcClient to NULL again |
|
123 |
asm("mov r12, #0 "); |
|
124 |
asm("str r12, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread))); |
|
125 |
||
126 |
// close the reference on the target process's os asid. |
|
127 |
asm("mov r6, r0"); // r6 = return value from read_and_parse_des_header_local |
|
128 |
asm("mov r0, r4"); // r0 = target process |
|
129 |
asm("bl " CSM_ZN16DMemModelProcess11CloseOsAsidEv); |
|
130 |
||
131 |
// finished... |
|
132 |
asm("bl " CSM_ZN5NKern13ThreadLeaveCSEv); // Os asid reference closed so leave critical section. |
|
133 |
asm("mov r0, r6"); // r0 = return value from read_and_parse_des_header_local. |
|
134 |
__POPRET("r4-r8, r10, "); // Restore the state and return. |
|
135 |
||
136 |
// exit with error... |
|
137 |
asm("readParseDesHeader_ExitErr:"); |
|
138 |
asm("bl " CSM_ZN5NKern13ThreadLeaveCSEv); // Os asid reference not open so leave critical section. |
|
139 |
asm("mov r0, #%a0" : : "i" ((TInt)KErrBadDescriptor)); |
|
140 |
asm("add sp, sp, #12"); // pop r0-r2 off the stack. |
|
141 |
__POPRET("r4-r8, r10, "); // Restore the state and return. |
|
142 |
||
143 |
#ifndef __SMP__ |
|
144 |
asm("__TheScheduler: "); |
|
145 |
asm(".word TheScheduler "); |
|
146 |
#endif |
|
147 |
} |
|
148 |