sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <e32cia.h>
|
sl@0
|
17 |
#include <arm_mem.h>
|
sl@0
|
18 |
|
sl@0
|
19 |
#ifdef _DEBUG
|
sl@0
|
20 |
#define ASM_KILL_LINK(rp,rs) asm("mov "#rs", #0xdf ");\
|
sl@0
|
21 |
asm("orr "#rs", "#rs", "#rs", lsl #8 ");\
|
sl@0
|
22 |
asm("orr "#rs", "#rs", "#rs", lsl #16 ");\
|
sl@0
|
23 |
asm("str "#rs", ["#rp"] ");\
|
sl@0
|
24 |
asm("str "#rs", ["#rp", #4] ");
|
sl@0
|
25 |
#else
|
sl@0
|
26 |
#define ASM_KILL_LINK(rp,rs)
|
sl@0
|
27 |
#endif
|
sl@0
|
28 |
|
sl@0
|
29 |
|
sl@0
|
30 |
__NAKED__ TInt ThreadDoReadAndParseDesHeader(DThread* aThread, const TAny* aSrc, TUint32* aDest)
|
sl@0
|
31 |
{
|
sl@0
|
32 |
asm("stmdb sp!, {r4-r7, lr} "); // stack unaligned, but we only call assembler
|
sl@0
|
33 |
|
sl@0
|
34 |
#ifdef __SMP__
|
sl@0
|
35 |
GET_RWNO_TID(,r6); // r6->TSubScheduler - can't migrate since we hold system lock
|
sl@0
|
36 |
asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(DThread,iOwningProcess)); // r3->target process
|
sl@0
|
37 |
asm("ldr r4, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace)); // r4->current process
|
sl@0
|
38 |
asm("ldr r5, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); // r5->current NThread
|
sl@0
|
39 |
#else
|
sl@0
|
40 |
asm("ldr r6, __TheScheduler "); // r6->TheScheduler
|
sl@0
|
41 |
asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(DThread,iOwningProcess)); // r3->target process
|
sl@0
|
42 |
asm("ldr r4, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace)); // r4->current process
|
sl@0
|
43 |
asm("ldr r5, [r6, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r5->current NThread
|
sl@0
|
44 |
#endif
|
sl@0
|
45 |
|
sl@0
|
46 |
// set TheCurrentThread->iIpcClient to this thread
|
sl@0
|
47 |
#ifdef _DEBUG
|
sl@0
|
48 |
asm("ldr r12, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread)));
|
sl@0
|
49 |
asm("teq r12, #0 ");
|
sl@0
|
50 |
asm("bne __FaultIpcClientNotNull ");
|
sl@0
|
51 |
#endif
|
sl@0
|
52 |
asm("str r0, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread)));
|
sl@0
|
53 |
|
sl@0
|
54 |
// switch address space to process r3...
|
sl@0
|
55 |
asm("mrc p15, 0, r7, c2, c0, 0 "); // r7 = original TTBR0
|
sl@0
|
56 |
asm("ldr r0, [r3, #%a0]" : : "i" _FOFF(DMemModelProcess,iLocalPageDir)); // r0->target process page directory
|
sl@0
|
57 |
asm("ldr r12, [r3, #%a0]" : : "i" _FOFF(DMemModelProcess,iOsAsid)); // r12 = target ASID
|
sl@0
|
58 |
#ifdef __SMP__
|
sl@0
|
59 |
__ASM_CLI();
|
sl@0
|
60 |
#else
|
sl@0
|
61 |
CPSIDIF; // disable all interrupts
|
sl@0
|
62 |
#endif
|
sl@0
|
63 |
asm("mcr p15, 0, r12, c7, c10, 4 "); // drain write buffer before changing MMU registers (see ARMv6 specs)
|
sl@0
|
64 |
asm("and lr, r7, #%a0" : : "i" ((TInt)KTTBRExtraBitsMask)); // lr = TTBR0 extra bits
|
sl@0
|
65 |
asm("orr lr, lr, r0 "); // target process page directory + extra bits
|
sl@0
|
66 |
UPDATE_PW_CACHING_ATTRIBUTES(,lr); // ERRATUM 1136_317041
|
sl@0
|
67 |
asm("mcr p15, 0, lr, c2, c0, 0 "); // change TTBR0
|
sl@0
|
68 |
asm("mcr p15, 0, r12, c13, c0, 1 "); // change ASID
|
sl@0
|
69 |
|
sl@0
|
70 |
#if defined(__CPU_ARM11MP__)
|
sl@0
|
71 |
// On other platforms, tha ASID change above has already flushed the branch prediction buffers
|
sl@0
|
72 |
asm("mcr p15, 0, r12, c7, c5, 6 "); // flush BTAC
|
sl@0
|
73 |
#endif
|
sl@0
|
74 |
|
sl@0
|
75 |
#ifdef __SMP__
|
sl@0
|
76 |
asm("str r3, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace));
|
sl@0
|
77 |
#else
|
sl@0
|
78 |
asm("str r3, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace));
|
sl@0
|
79 |
#endif
|
sl@0
|
80 |
asm("str r3, [r5, #%a0]" : : "i" _FOFF(NThread,iAddressSpace));
|
sl@0
|
81 |
#ifdef __SMP__
|
sl@0
|
82 |
__ASM_STI();
|
sl@0
|
83 |
#else
|
sl@0
|
84 |
CPSIEIF; // enable all interrupts
|
sl@0
|
85 |
#endif
|
sl@0
|
86 |
// read and parse the descriptor header
|
sl@0
|
87 |
asm("bl read_and_parse_des_header_local"); // defined in e32/kernel/arm/cipc.cia
|
sl@0
|
88 |
|
sl@0
|
89 |
// restore address space to process r4...
|
sl@0
|
90 |
asm("ldr r12, [r4, #%a0]" : : "i" _FOFF(DMemModelProcess,iOsAsid)); // r12 = current process ASID
|
sl@0
|
91 |
#ifdef __SMP__
|
sl@0
|
92 |
__ASM_CLI();
|
sl@0
|
93 |
#else
|
sl@0
|
94 |
CPSIDIF; // disable all interrupts
|
sl@0
|
95 |
#endif
|
sl@0
|
96 |
asm("mcr p15, 0, r12, c7, c10, 4 "); // drain write buffer before changing MMU registers (see ARMv6 specs)
|
sl@0
|
97 |
UPDATE_PW_CACHING_ATTRIBUTES(,r7); // ERRATUM 1136_317041
|
sl@0
|
98 |
asm("mcr p15, 0, r7, c2, c0, 0 "); // restore TTBR0
|
sl@0
|
99 |
asm("mcr p15, 0, r12, c13, c0, 1 "); // restore ASID
|
sl@0
|
100 |
|
sl@0
|
101 |
#if defined(__CPU_ARM11MP__)
|
sl@0
|
102 |
// On other platforms, the ASID change above has already flushed the branch prediction buffers
|
sl@0
|
103 |
asm("mcr p15, 0, r12, c7, c5, 6 "); // flush BTAC
|
sl@0
|
104 |
#endif
|
sl@0
|
105 |
|
sl@0
|
106 |
#ifdef __SMP__
|
sl@0
|
107 |
asm("str r4, [r6, #%a0]" : : "i" _FOFF(TSubScheduler,iAddressSpace));
|
sl@0
|
108 |
#else
|
sl@0
|
109 |
asm("str r4, [r6, #%a0]" : : "i" _FOFF(TScheduler,iAddressSpace));
|
sl@0
|
110 |
#endif
|
sl@0
|
111 |
asm("str r4, [r5, #%a0]" : : "i" _FOFF(NThread,iAddressSpace));
|
sl@0
|
112 |
#ifdef __SMP__
|
sl@0
|
113 |
__ASM_STI();
|
sl@0
|
114 |
#else
|
sl@0
|
115 |
CPSIEIF; // enable all interrupts
|
sl@0
|
116 |
#endif
|
sl@0
|
117 |
|
sl@0
|
118 |
// set TheCurrentThread->iIpcClient to NULL again
|
sl@0
|
119 |
asm("mov r12, #0 ");
|
sl@0
|
120 |
asm("str r12, [r5, #%a0] " : : "i" (_FOFF(DThread, iIpcClient) - _FOFF(DThread, iNThread)));
|
sl@0
|
121 |
|
sl@0
|
122 |
// finished...
|
sl@0
|
123 |
__POPRET("r4-r7,");
|
sl@0
|
124 |
|
sl@0
|
125 |
#ifndef __SMP__
|
sl@0
|
126 |
asm("__TheScheduler: ");
|
sl@0
|
127 |
asm(".word TheScheduler ");
|
sl@0
|
128 |
#endif
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|