author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 4 | 56f325a607ea |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1994-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 |
// e32\kernel\arm\cutils.cia |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
//#define __EARLY_DEBUG__ |
|
19 |
//#define __NE1__ |
|
20 |
//#define __MI920__ |
|
21 |
//#define __BOOTLDRIN__ |
|
22 |
//#define __MCOT__ |
|
23 |
||
24 |
#include <e32cia.h> |
|
25 |
#include <arm_mem.h> |
|
26 |
#include "nk_cpu.h" |
|
27 |
#include <kernel/kern_priv.h> |
|
28 |
#include <kernel/cache.h> |
|
29 |
||
30 |
#if defined(__MEMMODEL_MOVING__) || defined(__MEMMODEL_MULTIPLE__) |
|
31 |
#include <mmubase.h> |
|
32 |
#endif |
|
33 |
||
34 |
#ifdef __SMP__ |
|
35 |
__NAKED__ TUint __arm_cpu_number() |
|
36 |
{ |
|
37 |
asm("mrc p15, 0, r0, c0, c0, 5 "); |
|
38 |
asm("and r0, r0, #15 "); |
|
39 |
__JUMP(,lr); |
|
40 |
} |
|
41 |
#endif |
|
42 |
||
43 |
#ifdef __EARLY_DEBUG__ |
|
44 |
__NAKED__ void DebugOutputChar(TUint) |
|
45 |
// |
|
46 |
// Early debug print code - must hack this for the particular platform. |
|
47 |
// We assume bootstrap trace has already initialised the port. |
|
48 |
// |
|
49 |
{ |
|
50 |
#if defined(__MISA__) |
|
51 |
// Brutus debug print code. |
|
52 |
asm("ldr r1, __UartBase "); |
|
53 |
asm("wait_tx_rdy: "); |
|
54 |
asm("ldr r2, [r1, #0x20] "); |
|
55 |
asm("tst r2, #0x04 "); |
|
56 |
asm("beq wait_tx_rdy "); |
|
57 |
asm("str r0, [r1, #0x14] "); |
|
58 |
__JUMP(,lr); |
|
59 |
asm("__UartBase: "); |
|
60 |
asm(".word 0x63001000 "); |
|
61 |
#elif defined(__MAWD__) |
|
62 |
// S5mx debug print code. |
|
63 |
asm("ldr r1, __UartBase "); |
|
64 |
asm("wait_tx_rdy: "); |
|
65 |
asm("ldr r2, [r1, #0x10] "); |
|
66 |
asm("tst r2, #0x20 "); |
|
67 |
asm("bne wait_tx_rdy "); |
|
68 |
asm("str r0, [r1, #0x00] "); |
|
69 |
__JUMP(,lr); |
|
70 |
asm("__UartBase: "); |
|
71 |
asm(".word 0x63000700 "); |
|
72 |
#elif defined(__SAWD__) |
|
73 |
// S5mx debug print code. |
|
74 |
asm("ldr r1, __UartBase "); |
|
75 |
asm("wait_tx_rdy: "); |
|
76 |
asm("ldr r2, [r1, #0x10] "); |
|
77 |
asm("tst r2, #0x20 "); |
|
78 |
asm("bne wait_tx_rdy "); |
|
79 |
asm("str r0, [r1, #0x00] "); |
|
80 |
__JUMP(,lr); |
|
81 |
asm("__UartBase: "); |
|
82 |
asm(".word 0x80000700 "); |
|
83 |
#elif defined(__MI920__) || defined(__NI1136__) || defined(__BOOTLDRIN__) |
|
84 |
// Integrator debug print code. |
|
85 |
asm("ldr r1, __UartBase "); |
|
86 |
asm("wait_tx_rdy: "); |
|
87 |
asm("ldr r2, [r1, #0x18] "); |
|
88 |
asm("tst r2, #0x20 "); |
|
89 |
asm("bne wait_tx_rdy "); |
|
90 |
asm("str r0, [r1, #0x00] "); |
|
91 |
__JUMP(,lr); |
|
92 |
asm("__UartBase: "); |
|
93 |
#if defined(__MI920__) |
|
94 |
asm(".word 0x63006000 "); |
|
95 |
#elif defined(__NI1136__) |
|
96 |
asm(".word 0xc6006000 "); |
|
97 |
#elif defined(__BOOTLDRIN__) |
|
98 |
asm(".word 0x16000000 "); |
|
99 |
#endif |
|
100 |
#elif 0 |
|
101 |
//#elif defined(__NI1136__) |
|
102 |
// Use debug comms channel |
|
103 |
// asm("mov r1, #0x1000 "); |
|
104 |
// asm("mcr p14, 0, r1, c0, c1, 0 "); |
|
105 |
// asm("1: "); |
|
106 |
// asm("mrc p14, 0, r15, c0, c1, 0 "); // read comm channel flags into CPSR |
|
107 |
// asm("bcs 1b "); // wait for space |
|
108 |
// asm("mcr p14, 0, r0, c0, c5, 0 "); // output character |
|
109 |
// __JUMP(,lr); |
|
110 |
asm("mov r1, #0xc3000000 "); |
|
111 |
asm("add r1, r1, #0xc000 "); |
|
112 |
asm("str r0, [r1, #0x20] "); |
|
113 |
__JUMP(,lr); |
|
114 |
#elif defined(__MCOT__) |
|
115 |
// Lubbock debug print code. |
|
116 |
asm("ldr r1, __UartBase "); |
|
117 |
asm("1: "); |
|
118 |
asm("ldr r2, [r1, #0x14] "); |
|
119 |
asm("tst r2, #0x20 "); |
|
120 |
asm("beq 1b "); |
|
121 |
asm("str r0, [r1, #0x00] "); |
|
122 |
__JUMP(,lr); |
|
123 |
asm("__UartBase: "); |
|
124 |
asm(".word 0x63001000 "); |
|
125 |
#elif defined(__IS_OMAP1610__) || defined(__IS_OMAP1510__) |
|
126 |
// omap 1510 and 1610 debug print code. |
|
127 |
// N.B. Could also use JTAG DCC code from Arm::DebugOutJTAG() |
|
128 |
asm("ldr r1, __UartBase "); |
|
129 |
asm("1: "); |
|
130 |
asm("ldrb r2, [r1, #0x14] "); |
|
131 |
asm("tst r2, #0x20 "); |
|
132 |
asm("beq 1b "); |
|
133 |
asm("strb r0, [r1, #0x00] "); |
|
134 |
__JUMP(,lr); |
|
135 |
asm("__UartBase: "); |
|
136 |
#if defined(__MEMMODEL_DIRECT__) |
|
137 |
asm(".word 0xFFFB0000 "); // Physical for single |
|
138 |
#else |
|
139 |
asm(".word 0x630B0000 "); // Virtual for normal |
|
140 |
#endif |
|
141 |
#elif defined(__NE1__) |
|
142 |
asm("ldr r1, __SuperPageAddress "); |
|
143 |
asm("adr r2, __UartBase "); |
|
144 |
asm("ldr r1, [r1] "); |
|
145 |
asm("ldr r1, [r1, #%a0]" : : "i" _FOFF(TSuperPage,iDebugPort)); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
146 |
asm("and r1, r1, #255 "); |
0 | 147 |
asm("cmp r1, #0 "); |
148 |
asm("ldrne r2, [r2, #4] "); |
|
149 |
asm("ldreq r2, [r2, #0] "); |
|
150 |
asm("1: "); |
|
151 |
asm("ldr r3, [r2, #0x14] "); // LSR |
|
152 |
asm("tst r3, #0x20 "); |
|
153 |
asm("beq 1b "); |
|
154 |
asm("str r0, [r2, #0x00] "); // THR |
|
155 |
__JUMP(,lr); |
|
156 |
asm("__UartBase: "); |
|
157 |
#if defined(__MEMMODEL_DIRECT__) |
|
158 |
asm(".word 0x18034000 "); |
|
159 |
asm(".word 0x18034400 "); |
|
160 |
#else |
|
161 |
asm(".word 0xc6000000 "); |
|
162 |
asm(".word 0xc6000400 "); |
|
163 |
#endif |
|
164 |
asm("__SuperPageAddress: "); |
|
165 |
asm(".word SuperPageAddress "); |
|
166 |
#elif defined(__REALVIEW__) |
|
167 |
// RealView platform debug print code. |
|
168 |
asm("ldr r1, __SuperPageBase "); |
|
169 |
asm("ldr r1, [r1] "); |
|
170 |
asm("ldr r1, [r1, #%a0] " : : "i" _FOFF(TSuperPage,iDebugPort)); |
|
171 |
asm("cmp r1, #%a0 " : : "i" ((TInt)KNullDebugPort)); |
|
172 |
asm("bxeq lr "); // debug output supressed |
|
173 |
asm("adr r2, __UartBase "); |
|
174 |
asm("ldr r1, [r2] "); |
|
175 |
asm("1: "); |
|
176 |
asm("ldr r2, [r1, #0x18] "); // check status Tpl011::KHoFlags |
|
177 |
asm("tst r2, #0x20 "); // compare to Tpl011::KFlagTxFifoFull |
|
178 |
asm("bne 1b "); // if transmit data full, wait |
|
179 |
asm("str r0, [r1] "); // store to data register Tpl011::KHoData |
|
180 |
asm("bx lr "); |
|
181 |
asm("__SuperPageBase: "); |
|
182 |
asm(".word %a0 " : : "i" ((TInt)&SuperPageAddress)); |
|
183 |
asm("__UartBase: "); |
|
184 |
asm(".word 0xc6004000 "); |
|
185 |
#endif |
|
186 |
} |
|
187 |
#endif |
|
188 |
||
189 |
__NAKED__ EXPORT_C TInt Arm::DebugOutJTAG(TUint /*aChar*/) |
|
190 |
{ |
|
191 |
#if defined(__CPU_ARM920T__) || defined(__CPU_ARM720T__) || defined(__CPU_ARM926J__) |
|
192 |
asm("mov r2, #0x100000 "); // timeout |
|
193 |
asm("1: "); |
|
194 |
asm("mrc p14, 0, r1, c0, c0, 0 "); // get debug comms control register |
|
195 |
asm("tst r1, #2 "); // test W bit (1=busy) |
|
196 |
asm("subnes r2, r2, #1 "); // if busy, decrement timeout |
|
197 |
asm("bne 1b "); // if busy and not timed out, loop |
|
198 |
asm("tst r1, #2 "); |
|
199 |
asm("mcreq p14, 0, r0, c1, c0, 0 "); // if not busy, output value |
|
200 |
asm("moveq r0, #0 "); // and return KErrNone |
|
201 |
asm("movne r0, #%a0" : : "i" ((TInt)KErrTimedOut)); // else return KErrTimedOut |
|
202 |
#elif defined(__CPU_ARM1020T__) |
|
203 |
asm("mov r2, #0x100000 "); // timeout |
|
204 |
asm("1: "); |
|
205 |
asm("mrc p14, 0, r1, c0, c1, 0 "); // get DSCR |
|
206 |
asm("movs r1, r1, lsl #25 "); // test WE bit (1=empty) - set N flag if empty |
|
207 |
asm("subpls r2, r2, #1 "); // if busy, decrement timeout |
|
208 |
asm("bpl 1b "); // if busy and not timed out, loop |
|
209 |
asm("cmp r1, #0 "); |
|
210 |
asm("mcrmi p14, 0, r0, c0, c5, 0 "); // if not busy, output value |
|
211 |
asm("movmi r0, #0 "); // and return KErrNone |
|
212 |
asm("movpl r0, #%a0" : : "i" ((TInt)KErrTimedOut)); // else return KErrTimedOut |
|
213 |
#elif defined(__CPU_ARM1136__) || defined(__CPU_ARM1176__) |
|
214 |
asm("mov r2, #0x100000 "); // timeout |
|
215 |
asm("1: "); |
|
216 |
asm("mrc p14, 0, r15, c0, c1, 0 "); // test DSCR, wDTRfull->C flag (1=full) |
|
217 |
asm("subcss r2, r2, #1 "); // if busy, decrement timeout |
|
218 |
asm("bcs 1b "); // if busy and not timed out, loop |
|
219 |
asm("mrc p14, 0, r15, c0, c1, 0 "); // test DSCR, wDTRfull->C flag (1=full) |
|
220 |
asm("mcrcc p14, 0, r0, c0, c5, 0 "); // if not busy, output value |
|
221 |
asm("movcc r0, #0 "); // and return KErrNone |
|
222 |
asm("movcs r0, #%a0" : : "i" ((TInt)KErrTimedOut)); // else return KErrTimedOut |
|
223 |
#else |
|
224 |
asm("mov r0, #%a0" : : "i" ((TInt)KErrNotSupported)); |
|
225 |
#endif |
|
226 |
__JUMP(,lr); |
|
227 |
} |
|
228 |
||
229 |
__NAKED__ EXPORT_C TInt Arm::DebugInJTAG(TUint32& /*aRxData*/) |
|
230 |
{ |
|
231 |
#if defined(__CPU_ARM920T__) || defined(__CPU_ARM720T__) || defined(__CPU_ARM926J__) |
|
232 |
asm("mrc p14, 0, r2, c0, c0, 0 "); // get debug comms control register |
|
233 |
asm("tst r2, #1 "); // test R bit (1=data available) |
|
234 |
asm("mrcne p14, 0, r2, c1, c0, 0 "); // get RX data |
|
235 |
asm("strne r2, [r0] "); // store RX data |
|
236 |
asm("movne r0, #0 "); // return KErrNone |
|
237 |
asm("moveq r0, #%a0" : : "i" ((TInt)KErrNotReady)); // if no data available return KErrNotReady |
|
238 |
#elif defined(__CPU_ARM1020T__) |
|
239 |
asm("mrc p14, 0, r2, c0, c1, 0 "); // get DSCR |
|
240 |
asm("tst r2, #0x80 "); // test RF bit (1=full) |
|
241 |
asm("mrcne p14, 0, r2, c0, c5, 0 "); // get RX data |
|
242 |
asm("strne r2, [r0] "); // store RX data |
|
243 |
asm("movne r0, #0 "); // return KErrNone |
|
244 |
asm("moveq r0, #%a0" : : "i" ((TInt)KErrNotReady)); // if no data available return KErrNotReady |
|
245 |
#elif defined(__CPU_ARM1136__) || defined(__CPU_ARM1176__) |
|
246 |
asm("mrc p14, 0, r15, c0, c1, 0 "); // test DSCR, rDTRfull->Z flag (1=full) |
|
247 |
asm("mrceq p14, 0, r2, c0, c5, 0 "); // get RX data |
|
248 |
asm("streq r2, [r0] "); // store RX data |
|
249 |
asm("moveq r0, #0 "); // return KErrNone |
|
250 |
asm("movne r0, #%a0" : : "i" ((TInt)KErrNotReady)); // if no data available return KErrNotReady |
|
251 |
#else |
|
252 |
asm("mov r0, #%a0" : : "i" ((TInt)KErrNotSupported)); |
|
253 |
#endif |
|
254 |
__JUMP(,lr); |
|
255 |
} |
|
256 |
||
257 |
__NAKED__ void KPrintf(const char*, ...) |
|
258 |
{ |
|
259 |
asm("b " CSM_ZN4Kern6PrintfEPKcz); |
|
260 |
} |
|
261 |
||
262 |
__NAKED__ TInt A::CallSupervisorFunction(TSupervisorFunction, TAny*) |
|
263 |
// |
|
264 |
// Execute an F32 function in supervisor mode - might be THUMB. |
|
265 |
// |
|
266 |
{ |
|
267 |
asm("mov r2, r0 "); // r2=function ptr |
|
268 |
asm("mov r0, r1 "); // r0=argument |
|
269 |
__JUMP(,r2); // call function in correct mode |
|
270 |
} |
|
271 |
||
272 |
#if defined (__DES8_MACHINE_CODED__) |
|
273 |
/** |
|
274 |
Checks whether the specified name is a valid DObject full name. |
|
275 |
||
276 |
A name is deemed to be invalid, if it contains an asterisk or a question |
|
277 |
mark. |
|
278 |
||
279 |
@param aName Name to check. |
|
280 |
||
281 |
@return KErrNone, if valid; |
|
282 |
KErrBadName, if invalid. |
|
283 |
*/ |
|
284 |
#ifndef __KERNEL_MODE__ |
|
285 |
#error "TDesC is not 8-bit as __KERNEL_MODE__ is not defined (see e32cmn.h)" |
|
286 |
#endif |
|
287 |
__NAKED__ EXPORT_C TInt Kern::ValidateFullName(const TDesC& /*aName*/) |
|
288 |
// |
|
289 |
// Check for * or ? in descriptor, return KErrBadName if found |
|
290 |
// |
|
291 |
{ |
|
292 |
asm("ldr r2, [r0], #4 "); // r2=length/type |
|
293 |
asm("cmp r2, #0x50000000 "); |
|
294 |
asm("mvncs r0, #%a0" : : "i" (~KErrBadDescriptor)); |
|
295 |
__JUMP(cs,lr); |
|
296 |
asm("bics r3, r2, #0xF0000000 "); // r3=length |
|
297 |
asm("moveq r0, #0 "); // if length=0, return KErrNone |
|
298 |
__JUMP(eq,lr); |
|
299 |
asm("eor r2, r2, r2, lsr #1 "); |
|
300 |
asm("msr cpsr_flg, r2 "); |
|
301 |
asm("addcs r0, r0, #4 "); |
|
302 |
asm("ldrle r0, [r0] "); |
|
303 |
asm("addeq r0, r0, #4 "); // r0=this.Ptr() |
|
304 |
asm("ValidateFullName_1: "); |
|
305 |
asm("ldrb r1, [r0], #1 "); // r1=*r0++ |
|
306 |
asm("cmp r1, #0x20 "); // is it < 0x20 ? |
|
307 |
asm("rsbhss r2, r1, #0x7f "); // if not, compare 0x7f with char |
|
308 |
asm("bls ValidateFullName_2 "); // if char < 0x20 or char >= 0x7f, error |
|
309 |
asm("cmp r1, #'*' "); // is it * |
|
310 |
asm("cmpne r1, #'?' "); // if not, is it ? |
|
311 |
asm("subnes r3, r3, #1 "); // if neither of these, decrement length |
|
312 |
asm("bne ValidateFullName_1 "); |
|
313 |
||
314 |
asm("ValidateFullName_2: "); // About to return so did we |
|
315 |
asm("cmp r3, #0 "); // reach the end of string? |
|
316 |
asm("moveq r0, #0 "); // if we did, return KErrNone |
|
317 |
asm("mvnne r0, #%a0" : : "i" (~KErrBadName)); // else return KErrBadName |
|
318 |
__JUMP(,lr); |
|
319 |
} |
|
320 |
#endif |
|
321 |
||
322 |
||
323 |
/** |
|
324 |
Default implementation for Kern::NanoWait, which waits for the specified time. |
|
325 |
||
326 |
@param aInterval The time to wait in nanoseconds. |
|
327 |
*/ |
|
328 |
__NAKED__ void K::DoNanoWait(TUint32 /*aInterval*/) |
|
329 |
{ |
|
330 |
asm("ldr r1, __NanoWaitCal "); |
|
331 |
asm("ldr r1, [r1] "); // r1=PP::NanoWaitCal |
|
332 |
||
333 |
asm(".align 8"); // to make the 'nanowait_loop' start on a cache line |
|
334 |
asm("nanowait_loop: "); |
|
335 |
asm("subs r0, r0, r1 "); |
|
336 |
asm("bhi nanowait_loop "); |
|
337 |
__JUMP(,lr); |
|
338 |
||
339 |
asm("__NanoWaitCal: "); |
|
340 |
asm(".word " CSM_ZN2PP11NanoWaitCalE ); |
|
341 |
} |
|
342 |
||
343 |
__NAKED__ void A::StartCrashDebugger(const TAny*, TInt) |
|
344 |
{ |
|
345 |
USER_MEMORY_GUARD_OFF(,r0,r0); // let crash debugger have unfettered access to user memory |
|
346 |
asm("ldr r0, __MonitorEntryPoint "); |
|
347 |
asm("ldmia r0, {r1-r3} "); // r1 = debugger entry point |
|
348 |
asm("mvn r0, r2 "); |
|
349 |
asm("cmp r1, r0 "); // r2 = complement of r1 if valid |
|
350 |
asm("moveq r12, r1, lsr #2 "); |
|
351 |
asm("muleq r0, r12, r2 "); // r3 = (r1*r2/4)MOD 2^32 if valid |
|
352 |
asm("cmpeq r3, r0 "); |
|
353 |
__JUMP(ne,lr); // if debugger entry point invalid, return |
|
354 |
#ifdef __SMP__ |
|
355 |
GET_RWNO_TID(,r0); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
356 |
asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iRegs)); // pass in address of stored registers |
0 | 357 |
#else |
358 |
asm("ldr r0, __TheScheduler "); |
|
359 |
asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TScheduler,i_Regs)); // pass in address of stored registers |
|
360 |
#endif |
|
361 |
__JUMP(,r1); // jump to monitor |
|
362 |
// if it returns, return from this function and reboot |
|
363 |
||
364 |
asm("__MonitorEntryPoint: "); |
|
365 |
asm(".word " CSM_ZN2PP17MonitorEntryPointE); |
|
366 |
} |
|
367 |
||
368 |
||
369 |
/** Increments atomically a counter that's initially positive |
|
370 |
||
371 |
It checks the previous CPU mode and if it's User, it only applies user permissions when accessing aValue. |
|
372 |
It doesn't increment if aValue is negative or zero. |
|
373 |
||
374 |
@param aValue Reference to the counter to increment |
|
375 |
@return Previous value of counter |
|
376 |
||
377 |
********** NO GOOD ON SMP **************** |
|
378 |
||
379 |
*/ |
|
380 |
EXPORT_C __NAKED__ TInt Kern::KUSafeInc(TInt& /*aValue*/) |
|
381 |
{ |
|
382 |
ASM_ASSERT_PAGING_SAFE |
|
383 |
asm("mrs ip, cpsr "); |
|
384 |
INTS_OFF_1(r2, ip, INTS_ALL_OFF); |
|
385 |
asm("mrs r3, spsr "); // check caller's mode |
|
386 |
asm("mov r1, r0 "); // address into r1 |
|
387 |
asm("tst r3, #0x0f "); // test for user mode |
|
388 |
asm("bne 1f "); // branch if not |
|
389 |
INTS_OFF_2(r2, ip, INTS_ALL_OFF); // interrupts off |
|
390 |
USER_MEMORY_GUARD_OFF(,r2,r2); |
|
391 |
asm("ldrt r0, [r1] "); // r0=original value, only allow user permissions |
|
392 |
asm("cmp r0, #0 "); |
|
393 |
asm("addgt r2, r0, #1 "); |
|
394 |
asm("strgtt r2, [r1] "); // if original value >0, increment |
|
395 |
USER_MEMORY_GUARD_ON(,r2,r2); |
|
396 |
asm("msr cpsr, ip "); // restore interrupts |
|
397 |
__JUMP(,lr); |
|
398 |
asm("1: "); |
|
399 |
INTS_OFF_2(r2, ip, INTS_ALL_OFF); // interrupts off |
|
400 |
asm("ldr r0, [r1] "); // r0=original value |
|
401 |
asm("cmp r0, #0 "); |
|
402 |
asm("addgt r2, r0, #1 "); |
|
403 |
asm("strgt r2, [r1] "); // if >0, increment |
|
404 |
asm("msr cpsr, ip "); // restore interrupts |
|
405 |
__JUMP(,lr); |
|
406 |
} |
|
407 |
||
408 |
/** Decrements atomically a counter that's initially positive |
|
409 |
||
410 |
It checks the previous CPU mode and if it's User, it only applies user permissions when accessing aValue. |
|
411 |
It doesn't decrement if aValue is negative or zero. |
|
412 |
||
413 |
@param aValue Reference to the counter to decrement |
|
414 |
@return Previous value of counter |
|
415 |
||
416 |
********** NO GOOD ON SMP **************** |
|
417 |
||
418 |
*/ |
|
419 |
EXPORT_C __NAKED__ TInt Kern::KUSafeDec(TInt& /*aValue*/) |
|
420 |
{ |
|
421 |
ASM_ASSERT_PAGING_SAFE |
|
422 |
asm("mrs ip, cpsr "); |
|
423 |
INTS_OFF_1(r2, ip, INTS_ALL_OFF); |
|
424 |
asm("mrs r3, spsr "); // check caller's mode |
|
425 |
asm("mov r1, r0 "); // address into r1 |
|
426 |
asm("tst r3, #0x0f "); // test for user mode |
|
427 |
asm("bne 1f "); // branch if not |
|
428 |
INTS_OFF_2(r2, ip, INTS_ALL_OFF); // interrupts off |
|
429 |
USER_MEMORY_GUARD_OFF(,r2,r2); |
|
430 |
asm("ldrt r0, [r1] "); // r0=original value, only allow user permissions |
|
431 |
asm("subs r2, r0, #1 "); // decrement |
|
432 |
asm("strget r2, [r1] "); // update if result >=0 |
|
433 |
USER_MEMORY_GUARD_ON(,r2,r2); |
|
434 |
asm("msr cpsr, ip "); // restore interrupts |
|
435 |
__JUMP(,lr); |
|
436 |
asm("1: "); |
|
437 |
INTS_OFF_2(r2, ip, INTS_ALL_OFF); // interrupts off |
|
438 |
asm("ldr r0, [r1] "); // r0=original value |
|
439 |
asm("subs r2, r0, #1 "); // decrement |
|
440 |
asm("strge r2, [r1] "); // update if result >=0 |
|
441 |
asm("msr cpsr, ip "); // restore interrupts |
|
442 |
__JUMP(,lr); |
|
443 |
} |
|
444 |
||
445 |
#ifdef __HANDLES_MACHINE_CODED__ |
|
446 |
EXPORT_C __NAKED__ DObject* DThread::ObjectFromHandle(TInt /*aHandle*/) |
|
447 |
{ |
|
448 |
// r0=this, r1=aHandle |
|
449 |
asm("adds ip, r1, r1 "); // check for special handle (bit 31 set => special) |
|
450 |
asm("bcs 2f "); // if not, N flag indicates local handle |
|
451 |
asm("ldrpl ip, [r0, #%a0]" : : "i" _FOFF(DThread,iOwningProcess)); // if not local, ip=aThread->iOwningProcess |
|
452 |
asm("addmi ip, r0, #%a0" : : "i" _FOFF(DThread,iHandles)); // if local, ip=&aThread->iHandles |
|
453 |
asm("addpl ip, ip, #%a0" : : "i" _FOFF(DProcess,iHandles)); // if not, ip=&aThread->iOwningProcess->iHandles |
|
454 |
||
455 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
456 |
asm("stmfd sp!, {r0,r1,ip,lr} "); // save r0, r1, ip and lr |
|
457 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
458 |
asm("bl _ZN9RObjectIx15AcquireReadLockEv") // call RObjectIx::AquireReadLock |
|
459 |
asm("ldmfd sp!, {r0,r1,ip,lr} "); // restore r0, r1, ip and lr |
|
460 |
#else |
|
461 |
// system lock is held |
|
462 |
#endif |
|
463 |
||
464 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
465 |
// TODO: If handle lookup protected only by RW spin lock, must take a reference on the object |
|
466 |
// (__HANDLES_USE_RW_SPIN_LOCK__ is not supported or even finished) |
|
467 |
#endif |
|
468 |
||
469 |
asm("mov r3, r1, lsl #17 "); // r3=r1<<17 = index(aHandle)<<17 |
|
470 |
asm("mov r1, r1, lsl #2 "); // r1=instance(Handle)<<18 |
|
471 |
asm("ldr r0, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iCount)); // r0=iCount |
|
472 |
asm("ldr ip, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iSlots)); // ip=iSlots |
|
473 |
asm("subs r0, r0, r3, lsr #17 "); // r0 = iCount - index(aHandle) - 1 |
|
474 |
asm("ldrge r2, [ip, r3, lsr #14]! "); // if count-1>=index, r2=pS->uniqueID:pS->instance, ip=iSlots+index(Handle)=pS ... |
|
475 |
asm("ldrge r0, [ip, #4] "); // ... and r0 = pointer to DObject ... |
|
476 |
asm("andge r0, r0, #%a0" : : "i" (RObjectIx::EObjRObjMask)); // r0 = (pointer & EObjRObjMask); |
|
477 |
asm("eorge r1, r1, r2, lsl #18 "); // ... and check if instance(aHandle)<<18 == pS->(uid:instance)<<18 |
|
478 |
asm("movges r1, r1, lsr #18 "); |
|
479 |
asm("movne r0, #0"); // ... else r0 = 0 |
|
480 |
||
481 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
482 |
asm("stmfd sp!, {r0,ip,lr} "); // save r0, ip and lr |
|
483 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
484 |
asm("bl _ZN9RObjectIx15ReleaseReadLockEv") // call RObjectIx::ReleaseReadLock |
|
485 |
asm("ldmfd sp!, {r0,ip,lr} "); // restore r0, ip and lr |
|
486 |
#else |
|
487 |
// system lock is held, nothing to do |
|
488 |
#endif |
|
489 |
||
490 |
// r0 now either 0(EBadHandle) or valid pointer... |
|
491 |
__JUMP(,lr); |
|
492 |
||
493 |
asm("1: "); |
|
494 |
asm("mov r0, #0 "); // if wrong, bad handle |
|
495 |
__JUMP(,lr); |
|
496 |
||
497 |
asm("2: "); // r12=handle<<1 (valid values are ffff0000 and ffff0002) |
|
498 |
asm("bic ip, ip, #0x10000 "); // clear 'no close' flag |
|
499 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
500 |
asm("cmp ip, #0x10000000 "); |
|
501 |
asm("blo dobj_pseudo_5 "); // if handle<0x88000000, it's an IPC client thread pseudo handle |
|
502 |
#endif |
|
503 |
asm("ldr r0, __TheScheduler "); |
|
504 |
asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r0->current NThread |
|
505 |
asm("adds ip, ip, #0x20000 "); // valid values now 0 and 2 |
|
506 |
asm("ldreq r0, [r0, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); |
|
507 |
__JUMP(eq,lr); // if handle = ffff8000, return TheCurrentThread->iOwningProcess |
|
508 |
asm("cmp ip, #2 "); // otherwise, handle = ffff8001 ? |
|
509 |
asm("subeq r0, r0, #%a0" : : "i" _FOFF(DThread,iNThread)); |
|
510 |
__JUMP(eq,lr); // if so, return TheCurrentThread |
|
511 |
asm("b 1b "); // else bad handle |
|
512 |
||
513 |
asm("badobjectfault: "); |
|
514 |
asm("mov r0, #%a0" : : "i" (EBadObjectType)); |
|
515 |
asm("b " CSM_ZN1K5FaultENS_6TFaultE); |
|
516 |
} |
|
517 |
||
518 |
||
519 |
/** |
|
520 |
Returns the kernel object that the given handle refers. |
|
521 |
||
522 |
The handle passed is looked up in the thread's handles collection if the handle is local or |
|
523 |
in the thread's owner process' collection otherwise. If aHandle is negative or not found in |
|
524 |
the thread's or process' collection then NULL is returned. |
|
525 |
Two special handle values KCurrentThreadHandle and KCurrentProcessHandle can be used to get |
|
526 |
a pointer to the current thread and the current process. |
|
527 |
||
528 |
aType is used to ensure that the object referred by the handle is of desired type. |
|
529 |
If the type of the object referred by aHandle is different from aType then NULL is returned. |
|
530 |
If aType is negative, the type of the object is ignored and no type checking is done. |
|
531 |
If aType is positive and greater than the maximum number of object types (ENumObjectTypes) |
|
532 |
the kernel will fault. |
|
533 |
||
534 |
@param aThread The thread that owns the handle passed. |
|
535 |
@param aHandle Handle to the object to be returned. |
|
536 |
@param aType TObjectType parameter specifying the type of the object referred by the handle. |
|
537 |
||
538 |
@return Pointer to the DObject referred by the handle or NULL if the handle is not |
|
539 |
found in the thread's handles collection. |
|
540 |
||
541 |
@pre Call in a thread context. |
|
542 |
@pre Can be used in a device driver. |
|
543 |
||
544 |
@see TObjectType |
|
545 |
@see DThread::ObjectFromHandle() |
|
546 |
*/ |
|
547 |
EXPORT_C __NAKED__ DObject* Kern::ObjectFromHandle(DThread* /*aThread*/, TInt /*aHandle*/, TInt /*aType*/) |
|
548 |
{ |
|
549 |
ASM_CHECK_PRECONDITIONS(MASK_NOT_ISR|MASK_NOT_IDFC); |
|
550 |
||
551 |
// r0=aThread, r1=aHandle, r2=aType (-1=any, 0=thread, etc.) |
|
552 |
asm("add r3, r2, #1 "); |
|
553 |
asm("cmp r3, #%a0" : : "i" ((TInt)ENumObjectTypes)); |
|
554 |
asm("bhi badobjectfault "); // invalid object type |
|
555 |
// fall through |
|
556 |
} |
|
557 |
||
558 |
EXPORT_C __NAKED__ DObject* DThread::ObjectFromHandle(TInt /*aHandle*/, TInt /*aType*/) |
|
559 |
{ |
|
560 |
// r0=this, r1=aHandle, r2=aType (-1=any, 0=thread, etc.) |
|
561 |
asm("adds ip, r1, r1 "); // check for special handle (bit 31 set => special) |
|
562 |
asm("bcs 2f "); // if not, N flag indicates local handle |
|
563 |
asm("ldrpl ip, [r0, #%a0]" : : "i" _FOFF(DThread,iOwningProcess)); // if not local, ip=aThread->iOwningProcess |
|
564 |
asm("addmi ip, r0, #%a0" : : "i" _FOFF(DThread,iHandles)); // if local, ip=&aThread->iHandles |
|
565 |
asm("addpl ip, ip, #%a0" : : "i" _FOFF(DProcess,iHandles)); // if not, ip=&aThread->iOwningProcess->iHandles |
|
566 |
||
567 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
568 |
asm("stmfd sp!, {r0-r2,ip,lr} "); // save r0-r2, ip and lr |
|
569 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
570 |
asm("bl _ZN9RObjectIx15AcquireReadLockEv") // call RObjectIx::AquireReadLock |
|
571 |
asm("ldmfd sp!, {r0-r2,ip,lr} "); // restore r0-r2, ip and lr |
|
572 |
#else |
|
573 |
// system lock is held |
|
574 |
#endif |
|
575 |
||
576 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
577 |
// TODO: If handle lookup protected only by RW spin lock, must take a reference on the object |
|
578 |
#endif |
|
579 |
||
580 |
asm("mov r3, r1, lsl #17 "); // r3=r1<<17 = index(aHandle)<<17 |
|
581 |
asm("mov r1, r1, lsl #2 "); // r1=instance(Handle)<<18 |
|
582 |
asm("ldr r0, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iCount)); // r0=iCount |
|
583 |
asm("ldr ip, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iSlots)); // ip=iSlots |
|
584 |
asm("mov r1, r1, lsr #18 "); // r1=instance(Handle) |
|
585 |
asm("cmp r0, r3, lsr #17 "); // compare iCount with index(aHandle) |
|
586 |
asm("ldrgt r0, [ip, r3, lsr #14]! "); // if count>index, r0=pS->uniqueID:pS->instance, ip=iSlots+index(Handle)=pS |
|
587 |
asm("ble 1f "); // if count<=index, bad handle |
|
588 |
asm("adds r3, r2, #1 "); // r3=0 if any type of object is ok, r3=UID if not |
|
589 |
asm("biceq r0, r0, r2, lsl #14 "); // if it is, (r2 therefore -1) clear top 18 bits of r0 |
|
590 |
asm("orr r1, r1, r3, lsl #14 "); // r1=aUniqueID(bits14-19):instance(Handle)(bits0-13) |
|
591 |
asm("mov r0, r0, lsl #12 "); // only interested in comparing lower 20 bits... |
|
592 |
asm("mov r1, r1, lsl #12 "); |
|
593 |
asm("cmp r0, r1 "); // check instance, and unique ID if necessary |
|
594 |
asm("ldreq r0, [ip, #4] "); // if OK return pointer to DObject |
|
595 |
asm("movne r0, #0"); // else r0 = 0 |
|
596 |
asm("andeq r0, r0, #%a0" : : "i" (RObjectIx::EObjRObjMask)); // r0 = (pointer & EObjRObjMask); |
|
597 |
||
598 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
599 |
asm("stmfd sp!, {r0,ip,lr} "); // save r0, ip and lr |
|
600 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
601 |
asm("bl _ZN9RObjectIx15ReleaseReadLockEv") // call RObjectIx::ReleaseReadLock |
|
602 |
asm("ldmfd sp!, {r0,ip,lr} "); // restore r0, ip and lr |
|
603 |
#else |
|
604 |
// system lock is held, nothing to do |
|
605 |
#endif |
|
606 |
||
607 |
// r0 now either 0(EBadHandle) or valid pointer... |
|
608 |
__JUMP(,lr); |
|
609 |
||
610 |
asm("1: "); |
|
611 |
asm("mov r0, #0 "); // if wrong, bad handle |
|
612 |
__JUMP(,lr); |
|
613 |
||
614 |
asm("2: "); // r12=handle<<1 (valid values are fffx0000 and fffx0002, x=e or f) |
|
615 |
asm("bic ip, ip, #0x10000 "); // clear 'no close' flag |
|
616 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
617 |
asm("cmp ip, #0x10000000 "); |
|
618 |
asm("blo 4f "); // if handle<0x88000000, it's an IPC client thread pseudo handle |
|
619 |
#endif |
|
620 |
asm("ldr r0, __TheScheduler "); |
|
621 |
asm("add ip, ip, #0x20000 "); // valid values now 0 and 2 |
|
622 |
asm("cmp r2, #1 "); // r2=container number or -1 if any object OK |
|
623 |
asm("ldrle r0, [r0, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r0->current NThread |
|
624 |
asm("bgt 1b "); // if type is neither thread nor process nor any, bad handle |
|
625 |
asm("beq 3f "); // skip check for KCurrentThreadHandle if process required |
|
626 |
asm("cmp ip, #2 "); // handle = ffff8001 ? |
|
627 |
asm("subeq r0, r0, #%a0" : : "i" _FOFF(DThread,iNThread)); |
|
628 |
__JUMP(eq,lr); // if so, return TheCurrentThread |
|
629 |
asm("cmn r2, #1 "); // r2=-1 means any type of object will do |
|
630 |
asm("bne 1b "); |
|
631 |
asm("3: "); |
|
632 |
asm("cmp ip, #0 "); // handle = ffff8000 ? |
|
633 |
asm("ldreq r0, [r0, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); |
|
634 |
__JUMP(eq,lr); // if so, return TheCurrentThread->iOwningProcess |
|
635 |
asm("b 1b "); // else bad handle |
|
636 |
||
637 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
638 |
asm("4: "); |
|
639 |
asm("cmp r2, #0 "); // type must be thread or any |
|
640 |
asm("bgt 1b "); // if not, bad handle |
|
641 |
||
642 |
asm("dobj_pseudo_5: "); |
|
643 |
asm("add r1, r0, #%a0" : : "i" _FOFF(DThread,iNThread)); // r1->iNThread |
|
644 |
asm("stmfd sp!, {r4,lr} "); |
|
645 |
asm("bl do_lookup_thread_pseudo "); |
|
646 |
asm("bcc 6f "); // skip if bad handle |
|
647 |
asm("cmp ip, #%a0" : : "i" ((TInt)RMessage2::EDisConnect)); // else check iFunction != RMessage2::EDisConnect |
|
648 |
asm("ldrne r0, [r0, #%a0]" : : "i" _FOFF(RMessageK,iClient)); |
|
649 |
asm("moveq r0, #0 "); |
|
650 |
asm("6: "); |
|
651 |
asm("ldmfd sp!, {r4,pc} "); |
|
652 |
#endif |
|
653 |
} |
|
654 |
||
655 |
||
656 |
/** |
|
657 |
Returns the kernel object that the given handle refers. |
|
658 |
||
659 |
The handle passed is looked up in the thread's handles collection if the handle is local or |
|
660 |
in the thread's owner process' collection otherwise. If aHandle is negative or not found in |
|
661 |
the thread's or process' collection then NULL is returned. |
|
662 |
Two special handle values KCurrentThreadHandle and KCurrentProcessHandle can be used to get |
|
663 |
a pointer to the current thread and the current process. |
|
664 |
||
665 |
aType is used to ensure that the object referred by the handle is of desired type. |
|
666 |
If the type of the object referred by aHandle is different from aType then NULL is returned. |
|
667 |
If aType is negative, the type of the object is ignored and no type checking is done. |
|
668 |
If aType is positive and greater than the maximum number of object types (ENumObjectTypes) |
|
669 |
the kernel will fault. |
|
670 |
||
671 |
@param aThread The thread that owns the handle passed. |
|
672 |
@param aHandle Handle to the object to be returned. |
|
673 |
@param aType TObjectType parameter specifying the type of the object referred by the handle. |
|
674 |
@param aAttr Returns the attributes for this object. |
|
675 |
||
676 |
@return Pointer to the DObject referred by the handle or NULL if the handle is not |
|
677 |
found in the thread's handles collection. |
|
678 |
||
679 |
@pre Call in a thread context. |
|
680 |
@pre Can be used in a device driver. |
|
681 |
||
682 |
@see TObjectType |
|
683 |
@see DThread::ObjectFromHandle() |
|
684 |
*/ |
|
685 |
EXPORT_C __NAKED__ DObject* Kern::ObjectFromHandle(DThread* /*aThread*/, TInt /*aHandle*/, TInt /*aType*/, TUint& /*aAttr*/) |
|
686 |
{ |
|
687 |
ASM_CHECK_PRECONDITIONS(MASK_NOT_ISR|MASK_NOT_IDFC); |
|
688 |
||
689 |
// r0=aThread, r1=aHandle, r2=aType (-1=any, 0=thread, etc.), r3=&aAttr |
|
690 |
asm("add r2, r2, #1 "); // compare against 0 to ENumObjectTypes |
|
691 |
asm("cmp r2, #%a0" : : "i" ((TInt)ENumObjectTypes)); |
|
692 |
asm("sub r2, r2, #1 "); // revert the adjustment (quicker than save/restore of used register) |
|
693 |
asm("bhi badobjectfault "); // invalid object type |
|
694 |
// fall through |
|
695 |
} |
|
696 |
||
697 |
EXPORT_C __NAKED__ DObject* DThread::ObjectFromHandle(TInt /*aHandle*/, TInt /*aObjType*/, TUint& /*aAttr*/) |
|
698 |
{ |
|
699 |
// r0=this, r1=aHandle, r2=aType (-1=any, 0=thread, etc.), r3=&aAttr |
|
700 |
asm("stmfd sp!, {r3}"); // save r3 |
|
701 |
asm("adds ip, r1, r1 "); // check for special handle (bit 31 set => special) |
|
702 |
asm("bcs 2f "); // if not, N flag indicates local handle |
|
703 |
asm("ldrpl ip, [r0, #%a0]" : : "i" _FOFF(DThread,iOwningProcess)); // if not local, ip=aThread->iOwningProcess |
|
704 |
asm("addmi ip, r0, #%a0" : : "i" _FOFF(DThread,iHandles)); // if local, ip=&aThread->iHandles |
|
705 |
asm("addpl ip, ip, #%a0" : : "i" _FOFF(DProcess,iHandles)); // if not, ip=&aThread->iOwningProcess->iHandles |
|
706 |
||
707 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
708 |
asm("stmfd sp!, {r0-r2,ip,lr} "); // save r0-r2, ip and lr |
|
709 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
710 |
asm("bl _ZN9RObjectIx15AcquireReadLockEv") // call RObjectIx::AquireReadLock |
|
711 |
asm("ldmfd sp!, {r0-r2,ip,lr} "); // restore r0-r2, ip and lr |
|
712 |
#else |
|
713 |
// system lock is held |
|
714 |
#endif |
|
715 |
||
716 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
717 |
// TODO: If handle lookup protected only by RW spin lock, must take a reference on the object |
|
718 |
#endif |
|
719 |
||
720 |
asm("mov r3, r1, lsl #17 "); // r3=r1<<17 = index(aHandle)<<17 |
|
721 |
asm("mov r1, r1, lsl #2 "); // r1=instance(Handle)<<18 |
|
722 |
asm("ldr r0, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iCount)); // r0=iCount |
|
723 |
asm("ldr ip, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iSlots)); // ip=iSlots |
|
724 |
asm("mov r1, r1, lsr #18 "); // r1=instance(Handle) |
|
725 |
asm("cmp r0, r3, lsr #17 "); // compare iCount with index(aHandle) |
|
726 |
asm("ldrgt r0, [ip, r3, lsr #14]! "); // if count>index, r0=pS->uniqueID:pS->instance, ip=iSlots+index(Handle)=pS |
|
727 |
asm("ble 1f "); // if count<=index, bad handle |
|
728 |
asm("adds r3, r2, #1 "); // r3=0 if any type of object is ok, r3=UID if not |
|
729 |
asm("biceq r0, r0, r2, lsl #14 "); // if it is, (r2 therefore -1) clear top 18 bits of r0 |
|
730 |
asm("orr r1, r1, r3, lsl #14 "); // r1=aUniqueID(bits14-19):instance(Handle)(bits0-13) |
|
731 |
asm("mov r0, r0, lsl #12 "); // only interested in comparing lower 20 bits... |
|
732 |
asm("mov r1, r1, lsl #12 "); |
|
733 |
asm("cmp r0, r1 "); // check instance, and unique ID if necessary |
|
734 |
asm("ldreq r0, [ip, #4] "); // if OK return pointer to DObject |
|
735 |
asm("movne r0, #0"); // else r0 = 0 |
|
736 |
asm("mov r2, r0"); // r2 = 0 or pointer(bits2-31):flags(bits0-1) |
|
737 |
asm("andeq r0, r0, #%a0" : : "i" (RObjectIx::EObjRObjMask)); // r0 = (pointer & EObjRObjMask); |
|
738 |
||
739 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
740 |
asm("stmfd sp!, {r0,r2,ip,lr}"); // save r0, r2, ip and lr |
|
741 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
742 |
asm("bl _ZN9RObjectIx15ReleaseReadLockEv") // call RObjectIx::ReleaseReadLock |
|
743 |
asm("ldmfd sp!, {r0,r2,ip,lr}"); // restore r0, r2, ip and lr |
|
744 |
#else |
|
745 |
// system lock is held, nothing to do |
|
746 |
#endif |
|
747 |
||
748 |
asm("ldmfd sp!, {r3}"); // restore r3 (r3=&aAttr) |
|
749 |
asm("cmp r0, #0"); // if r0!=0 |
|
750 |
asm("ldrne r1, [ip]"); // r1=attributes:pS->uniqueID:pS->instance |
|
751 |
asm("movne r1, r1, lsr #20"); // r1=attributes(bits0-11) |
|
752 |
asm("orrne r1, r1, r2, lsl #31 "); // r1=resv_flag(bit31):attributes(bits0-11) |
|
753 |
asm("strne r1, [r3] "); // aAttr=resv_flag(bit31):attributes(bits0-11) |
|
754 |
||
755 |
// r0 now either 0(EBadHandle) or valid pointer... |
|
756 |
__JUMP(,lr); |
|
757 |
||
758 |
asm("1: "); |
|
759 |
asm("add sp, sp, #4"); // pop and discard r3 (not used) |
|
760 |
asm("mov r0, #0 "); // if wrong, bad handle |
|
761 |
__JUMP(,lr); |
|
762 |
||
763 |
asm("2: "); // r12=handle<<1 (valid values are fffx0000 and fffx0002, x=e or f) |
|
764 |
asm("bic ip, ip, #0x10000 "); // clear 'no close' flag |
|
765 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
766 |
asm("cmp ip, #0x10000000 "); |
|
767 |
asm("blo 4f "); // if handle<0x88000000, it's an IPC client thread pseudo handle |
|
768 |
#endif |
|
769 |
asm("ldr r0, __TheScheduler "); |
|
770 |
asm("add ip, ip, #0x20000 "); // valid values now 0 and 2 |
|
771 |
asm("cmp r2, #1 "); // r2=container number or -1 if any object OK |
|
772 |
asm("ldrle r0, [r0, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r0->current NThread |
|
773 |
asm("bgt 1b "); // if type is neither thread nor process nor any, bad handle |
|
774 |
asm("beq 3f "); // skip check for KCurrentThreadHandle if process required |
|
775 |
asm("cmp ip, #2 "); // handle = ffff8001 ? |
|
776 |
asm("subeq r0, r0, #%a0" : : "i" _FOFF(DThread,iNThread)); |
|
777 |
asm("add sp, sp, #4"); // pop and discard r3 (not used) |
|
778 |
__JUMP(eq,lr); // if so, return TheCurrentThread |
|
779 |
asm("cmn r2, #1 "); // r2=-1 means any type of object will do |
|
780 |
asm("bne 1b "); |
|
781 |
asm("3: "); |
|
782 |
asm("cmp ip, #0 "); // handle = ffff8000 ? |
|
783 |
asm("ldreq r0, [r0, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); |
|
784 |
asm("add sp, sp, #4"); // pop and discard r3 (not used) |
|
785 |
__JUMP(eq,lr); // if so, return TheCurrentThread->iOwningProcess |
|
786 |
asm("b 1b "); // else bad handle |
|
787 |
||
788 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
789 |
asm("4: "); |
|
790 |
asm("cmp r2, #0 "); // type must be thread or any |
|
791 |
asm("bgt 1b "); // if not, bad handle |
|
792 |
||
793 |
asm("add sp, sp, #4"); // pop and discard r3 (not used) |
|
794 |
asm("add r1, r0, #%a0" : : "i" _FOFF(DThread,iNThread)); // r1->iNThread |
|
795 |
asm("stmfd sp!, {r4,lr} "); |
|
796 |
asm("bl do_lookup_thread_pseudo "); |
|
797 |
asm("bcc 6f "); // skip if bad handle |
|
798 |
asm("cmp ip, #%a0" : : "i" ((TInt)RMessage2::EDisConnect)); // else check iFunction != RMessage2::EDisConnect |
|
799 |
asm("ldrne r0, [r0, #%a0]" : : "i" _FOFF(RMessageK,iClient)); |
|
800 |
asm("moveq r0, #0 "); |
|
801 |
asm("6: "); |
|
802 |
asm("ldmfd sp!, {r4,pc} "); |
|
803 |
#endif |
|
804 |
} |
|
805 |
||
806 |
__NAKED__ DObject* K::ObjectFromHandle(TInt /*aHandle*/) |
|
807 |
// |
|
808 |
// Look up an object in the current thread/process handles array |
|
809 |
// Panic on bad handle |
|
810 |
// Enter and leave with system locked |
|
811 |
// |
|
812 |
{ |
|
813 |
// r0=aHandle |
|
814 |
asm("ldr r1, __TheScheduler "); |
|
815 |
asm("adds ip, r0, r0 "); // check for special handle (bit 31 set => special) |
|
816 |
asm("ldr r1, [r1, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r1->current NThread |
|
817 |
asm("bcs 2f "); // if not, N flag indicates local handle |
|
818 |
asm("ldrpl ip, [r1, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); // if not local, ip=aThread->iOwningProcess |
|
819 |
asm("addmi ip, r1, #%a0" : : "i" (_FOFF(DThread,iHandles)-_FOFF(DThread,iNThread))); // if local, ip=¤t Thread->iHandles |
|
820 |
asm("addpl ip, ip, #%a0" : : "i" _FOFF(DProcess,iHandles)); // if not, ip=¤t Thread->iOwningProcess->iHandles |
|
821 |
||
822 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
823 |
asm("stmfd sp!, {r0,r1,ip,lr} "); // save r0, r1, ip and lr |
|
824 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
825 |
asm("bl _ZN9RObjectIx15AcquireReadLockEv") // call RObjectIx::AquireReadLock |
|
826 |
asm("ldmfd sp!, {r0,r1,ip,lr} "); // restore r0, r1, ip and lr |
|
827 |
#else |
|
828 |
// system lock is held |
|
829 |
#endif |
|
830 |
||
831 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
832 |
// TODO: If handle lookup protected only by RW spin lock, must take a reference on the object |
|
833 |
#endif |
|
834 |
||
835 |
asm("mov r3, r0, lsl #17 "); // r3=r0<<17 = index(aHandle)<<17 |
|
836 |
asm("mov r1, r0, lsl #2 "); // r1=instance(Handle)<<18 |
|
837 |
asm("ldr r0, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iCount)); // r0=iCount |
|
838 |
asm("ldr ip, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iSlots)); // ip=iSlots |
|
839 |
asm("subs r0, r0, r3, lsr #17 "); // r0 = iCount - index(aHandle) - 1 |
|
840 |
asm("ldrge r2, [ip, r3, lsr #14]! "); // if count-1>=index, r2=pS->uniqueID:pS->instance, ip=iSlots+index(Handle)=pS ... |
|
841 |
asm("ldrge r0, [ip, #4] "); // ... and r0 = pointer to DObject ... |
|
842 |
asm("andge r0, r0, #%a0" : : "i" (RObjectIx::EObjRObjMask)); // r0 = (pointer & EObjRObjMask); |
|
843 |
asm("eorge r1, r1, r2, lsl #18 "); // ... and check if instance(aHandle)<<18 == pS->(uid:instance)<<18 |
|
844 |
asm("movges r1, r1, lsr #18 "); |
|
845 |
asm("movne r0, #0"); // ... else r0 = 0 |
|
846 |
||
847 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
848 |
asm("stmfd sp!, {r0,ip,lr} "); // save r0, ip and lr |
|
849 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
850 |
asm("bl _ZN9RObjectIx15ReleaseReadLockEv") // call RObjectIx::ReleaseReadLock |
|
851 |
asm("ldmfd sp!, {r0,ip,lr} "); // restore r0, ip and lr |
|
852 |
#else |
|
853 |
// system lock is held, nothing to do |
|
854 |
#endif |
|
855 |
||
856 |
asm("cmp r0, #0 "); // check if this is a valid pointer |
|
857 |
__JUMP(ne,lr); // if OK, return pointer to DObject |
|
858 |
||
859 |
asm("1: "); // if wrong, bad handle |
|
860 |
asm("mov r0, #%a0" : : "i" (EBadHandle)); |
|
861 |
asm("b " CSM_ZN1K18PanicCurrentThreadEi); |
|
862 |
||
863 |
asm("2: "); // r12=handle<<1 (valid values are fffx0000 and fffx0002, x=e or f) |
|
864 |
asm("bic ip, ip, #0x10000 "); // clear 'no close' flag |
|
865 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
866 |
asm("cmp ip, #0x10000000 "); |
|
867 |
asm("blo 3f "); // if handle<0x88000000, it's an IPC client thread pseudo handle |
|
868 |
#endif |
|
869 |
asm("adds ip, ip, #0x20000 "); // valid values now 0 and 2 |
|
870 |
asm("ldreq r0, [r1, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); |
|
871 |
__JUMP(eq,lr); // if handle = ffff8000, return TheCurrentThread->iOwningProcess |
|
872 |
asm("cmp ip, #2 "); // otherwise, handle = ffff8001 ? |
|
873 |
asm("subeq r0, r1, #%a0" : : "i" _FOFF(DThread,iNThread)); |
|
874 |
__JUMP(eq,lr); // if so, return TheCurrentThread |
|
875 |
asm("b 1b "); // else bad handle |
|
876 |
||
877 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
878 |
asm("k_pseudo_4: "); |
|
879 |
asm("cmp r1, #0 "); // type must be thread or any |
|
880 |
asm("bgt 1b "); // if not, panic |
|
881 |
asm("mov r1, r2 "); // r1->current NThread |
|
882 |
||
883 |
asm("3: "); |
|
884 |
asm("stmfd sp!, {r4,lr} "); |
|
885 |
asm("bl do_lookup_thread_pseudo "); |
|
886 |
asm("bcc 1b "); // panic if bad |
|
887 |
asm("cmp ip, #%a0" : : "i" ((TInt)RMessage2::EDisConnect)); // else check iFunction != RMessage2::EDisConnect |
|
888 |
asm("ldrne r0, [r0, #%a0]" : : "i" _FOFF(RMessageK,iClient)); |
|
889 |
asm("ldmnefd sp!, {r4,pc} "); |
|
890 |
asm("b 1b "); |
|
891 |
#endif |
|
892 |
} |
|
893 |
||
894 |
__NAKED__ DObject* K::ObjectFromHandle(TInt /*aHandle*/, TInt /*aType*/) |
|
895 |
// |
|
896 |
// Look up an object of specific type in the current thread/process handles array |
|
897 |
// Panic on bad handle |
|
898 |
// Enter and leave with system locked |
|
899 |
// |
|
900 |
{ |
|
901 |
// r0=aHandle, r1=aType (-1=any, 0=thread, etc.) |
|
902 |
asm("ldr r2, __TheScheduler "); |
|
903 |
asm("adds ip, r0, r0 "); // check for special handle (bit 31 set => special) |
|
904 |
asm("ldr r2, [r2, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r2->current NThread |
|
905 |
asm("bcs 2f "); // if not, N flag indicates local handle |
|
906 |
asm("ldrpl ip, [r2, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); // if not local, ip=aThread->iOwningProcess |
|
907 |
asm("addmi ip, r2, #%a0" : : "i" (_FOFF(DThread,iHandles)-_FOFF(DThread,iNThread))); // if local, ip=&aThread->iHandles |
|
908 |
asm("addpl ip, ip, #%a0" : : "i" _FOFF(DProcess,iHandles)); // if not, ip=&aThread->iOwningProcess->iHandles |
|
909 |
||
910 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
911 |
asm("stmfd sp!, {r0,r1,ip,lr} "); // save r0, r1, ip and lr |
|
912 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
913 |
asm("bl _ZN9RObjectIx15AcquireReadLockEv") // call RObjectIx::AquireReadLock |
|
914 |
asm("ldmfd sp!, {r0,r1,ip,lr} "); // restore r0, r1, ip and lr |
|
915 |
#else |
|
916 |
// system lock is held |
|
917 |
#endif |
|
918 |
||
919 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
920 |
// TODO: If handle lookup protected only by RW spin lock, must take a reference on the object |
|
921 |
#endif |
|
922 |
||
923 |
asm("mov r3, r0, lsl #17 "); // r3=r0<<17 = index(aHandle)<<17 |
|
924 |
asm("mov r2, r0, lsl #2 "); // r2=instance(Handle)<<18 |
|
925 |
asm("ldr r0, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iCount)); // r0=iCount |
|
926 |
asm("ldr ip, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iSlots)); // ip=iSlots |
|
927 |
asm("mov r2, r2, lsr #18 "); // r2=instance(Handle) |
|
928 |
asm("cmp r0, r3, lsr #17 "); // compare iCount with index(aHandle) |
|
929 |
asm("ldrgt r0, [ip, r3, lsr #14]! "); // if count>index, r0=pS->uniqueID:pS->instance, ip=iSlots+index(Handle)=pS |
|
930 |
asm("ble 1f "); // if count<=index, bad handle |
|
931 |
asm("adds r3, r1, #1 "); // r3=0 if any type of object is ok, r3=UID if not |
|
932 |
asm("biceq r0, r0, r1, lsl #14 "); // if it is, (therefore r1=-1) clear top 18 bits of r0 |
|
933 |
asm("orr r2, r2, r3, lsl #14 "); // r2=aUniqueID(bits14-19):instance(Handle)(bits0-13) |
|
934 |
asm("mov r0, r0, lsl #12 "); // only interested in comparing lower 20 bits... |
|
935 |
asm("mov r2, r2, lsl #12 "); |
|
936 |
asm("cmp r0, r2 "); // check instance, and unique ID if necessary |
|
937 |
asm("ldreq r0, [ip, #4] "); // if OK return pointer to DObject |
|
938 |
asm("movne r0, #0"); // else r0 = 0 |
|
939 |
asm("andeq r0, r0, #%a0" : : "i" (RObjectIx::EObjRObjMask)); // r0 = (pointer & EObjRObjMask); |
|
940 |
||
941 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
942 |
asm("stmfd sp!, {r0,ip,lr} "); // save r0, ip and lr |
|
943 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
944 |
asm("bl _ZN9RObjectIx15ReleaseReadLockEv") // call RObjectIx::ReleaseReadLock |
|
945 |
asm("ldmfd sp!, {r0,ip,lr} "); // restore r0, ip and lr |
|
946 |
#else |
|
947 |
// system lock is held, nothing to do |
|
948 |
#endif |
|
949 |
||
950 |
asm("cmp r0, #0 "); // check if this is a valid pointer |
|
951 |
__JUMP(ne,lr); // if OK, return pointer to DObject |
|
952 |
||
953 |
asm("1: "); // if wrong, bad handle |
|
954 |
asm("mov r0, #%a0" : : "i" (EBadHandle)); |
|
955 |
asm("b " CSM_ZN1K18PanicCurrentThreadEi); |
|
956 |
||
957 |
asm("2: "); // r12=handle<<1 (valid values are fffx0000 and fffx0002, x=e or f) |
|
958 |
asm("bic ip, ip, #0x10000 "); // clear 'no close' flag |
|
959 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
960 |
asm("cmp ip, #0x10000000 "); |
|
961 |
asm("blo k_pseudo_4 "); // if handle<0x88000000, it's an IPC client thread pseudo handle |
|
962 |
#endif |
|
963 |
asm("adds ip, ip, #0x20000 "); // valid values now 0 and 2 |
|
964 |
asm("cmp r1, #1 "); // r1=container number or -1 if any object OK |
|
965 |
asm("bgt 1b "); // if type is neither thread nor process nor any, bad handle |
|
966 |
asm("beq 3f "); // skip check for KCurrentThreadHandle if process required |
|
967 |
asm("cmp ip, #2 "); // handle = ffff8001 ? |
|
968 |
asm("subeq r0, r2, #%a0" : : "i" _FOFF(DThread,iNThread)); |
|
969 |
__JUMP(eq,lr); // if so, return TheCurrentThread |
|
970 |
asm("cmn r1, #1 "); // r1=-1 means any type of object will do |
|
971 |
asm("bne 1b "); |
|
972 |
asm("3: "); |
|
973 |
asm("cmp ip, #0 "); // handle = ffff8000 ? |
|
974 |
asm("ldreq r0, [r2, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); |
|
975 |
__JUMP(eq,lr); // if so, return TheCurrentThread->iOwningProcess |
|
976 |
asm("b 1b "); // else bad handle |
|
977 |
} |
|
978 |
||
979 |
__NAKED__ DObject* K::ObjectFromHandle(TInt /*aHandle*/, TInt /*aObjType*/, TUint& /*aAttr*/) |
|
980 |
// |
|
981 |
// Look up an object of specific type in the current thread/process handles array |
|
982 |
// Panic on bad handle |
|
983 |
// Enter and leave with system locked |
|
984 |
// |
|
985 |
{ |
|
986 |
// r0=aHandle, r1=aObjType (-1=any, 0=thread, etc.), r2=&aAttr |
|
987 |
asm("stmfd sp!, {r2}"); // save r2 |
|
988 |
asm("ldr r2, __TheScheduler "); |
|
989 |
asm("adds ip, r0, r0 "); // check for special handle (bit 31 set => special) |
|
990 |
asm("ldr r2, [r2, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r2->current NThread |
|
991 |
asm("bcs 2f "); // if not, N flag indicates local handle |
|
992 |
asm("ldrpl ip, [r2, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); // if not local, ip=aThread->iOwningProcess |
|
993 |
asm("addmi ip, r2, #%a0" : : "i" (_FOFF(DThread,iHandles)-_FOFF(DThread,iNThread))); // if local, ip=&aThread->iHandles |
|
994 |
asm("addpl ip, ip, #%a0" : : "i" _FOFF(DProcess,iHandles)); // if not, ip=&aThread->iOwningProcess->iHandles |
|
995 |
||
996 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
997 |
asm("stmfd sp!, {r0,r1,ip,lr} "); // save r0, r1, ip and lr |
|
998 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
999 |
asm("bl _ZN9RObjectIx15AcquireReadLockEv") // call RObjectIx::AquireReadLock |
|
1000 |
asm("ldmfd sp!, {r0,r1,ip,lr} "); // restore r0, r1, ip and lr |
|
1001 |
#else |
|
1002 |
// system lock is held |
|
1003 |
#endif |
|
1004 |
||
1005 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
1006 |
// TODO: If handle lookup protected only by RW spin lock, must take a reference on the object |
|
1007 |
#endif |
|
1008 |
||
1009 |
asm("mov r3, r0, lsl #17 "); // r3=r0<<17 = index(aHandle)<<17 |
|
1010 |
asm("mov r2, r0, lsl #2 "); // r2=instance(Handle)<<18 |
|
1011 |
asm("ldr r0, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iCount)); // r0=iCount |
|
1012 |
asm("ldr ip, [ip, #%a0]" : : "i" _FOFF(RObjectIx,iSlots)); // ip=iSlots |
|
1013 |
asm("mov r2, r2, lsr #18 "); // r2=instance(Handle) |
|
1014 |
asm("cmp r0, r3, lsr #17 "); // compare iCount with index(aHandle) |
|
1015 |
asm("ldrgt r0, [ip, r3, lsr #14]! "); // if count>index, r0=pS->uniqueID:pS->instance, ip=iSlots+index(Handle)=pS |
|
1016 |
asm("ble 1f "); // if count<=index, bad handle |
|
1017 |
asm("adds r3, r1, #1 "); // r3=0 if any type of object is ok, r3=UID if not |
|
1018 |
asm("biceq r0, r0, r1, lsl #14 "); // if it is, (therefore r1=-1) clear top 18 bits of r0 |
|
1019 |
asm("orr r2, r2, r3, lsl #14 "); // r2=aUniqueID(bits14-19):instance(Handle)(bits0-13) |
|
1020 |
asm("mov r0, r0, lsl #12 "); // only interested in comparing lower 20 bits... |
|
1021 |
asm("mov r2, r2, lsl #12 "); |
|
1022 |
asm("cmp r0, r2 "); // check instance, and unique ID if necessary |
|
1023 |
asm("ldreq r0, [ip, #4] "); // if OK return pointer to DObject |
|
1024 |
asm("movne r0, #0"); // else r0 = 0 |
|
1025 |
asm("mov r3, r0"); // r3=0 or pointer(bits2-31):flags(bits0-1) |
|
1026 |
asm("andeq r0, r0, #%a0" : : "i" (RObjectIx::EObjRObjMask)); // r0 = (pointer & EObjRObjMask); |
|
1027 |
||
1028 |
#ifdef __HANDLES_USE_RW_SPIN_LOCK__ |
|
1029 |
asm("stmfd sp!, {r0,r3,ip,lr} "); // save r0, r3, ip and lr |
|
1030 |
asm("mov r0, ip "); // move RObjectIx this(ip) to r0 |
|
1031 |
asm("bl _ZN9RObjectIx15ReleaseReadLockEv") // call RObjectIx::ReleaseReadLock |
|
1032 |
asm("ldmfd sp!, {r0,r3,ip,lr} "); // restore r0, r3, ip and lr |
|
1033 |
#else |
|
1034 |
// system lock is held, nothing to do |
|
1035 |
#endif |
|
1036 |
||
1037 |
asm("ldmfd sp!, {r2}"); // restore r2 (r2=&aAttr) |
|
1038 |
asm("cmp r0, #0"); // if r0!=0 |
|
1039 |
asm("ldrne r1, [ip]"); // r1=attributes:pS->uniqueID:pS->instance |
|
1040 |
asm("movne r1, r1, lsr #20"); // r1=attributes(bits0-11) |
|
1041 |
asm("orrne r1, r1, r3, lsl #31 "); // r1=resv_flag(bit31):attributes(bits0-11) |
|
1042 |
asm("strne r1, [r2] "); // aAttr=resv_flag(bit31):attributes(bits0-11) |
|
1043 |
||
1044 |
__JUMP(ne,lr); // return pointer to DObject |
|
1045 |
||
1046 |
asm("1: "); // if wrong, bad handle |
|
1047 |
asm("mov r0, #%a0" : : "i" (EBadHandle)); |
|
1048 |
asm("b " CSM_ZN1K18PanicCurrentThreadEi); |
|
1049 |
||
1050 |
asm("2: "); // r12=handle<<1 (valid values are fffx0000 and fffx0002, x=e or f) |
|
1051 |
asm("add sp, sp, #4"); // pop and discard r2 (not used) |
|
1052 |
asm("bic ip, ip, #0x10000 "); // clear 'no close' flag |
|
1053 |
#ifdef __OBSOLETE_V1_IPC_SUPPORT__ |
|
1054 |
asm("cmp ip, #0x10000000 "); |
|
1055 |
asm("blo k_pseudo_4 "); // if handle<0x88000000, it's an IPC client thread pseudo handle |
|
1056 |
#endif |
|
1057 |
asm("adds ip, ip, #0x20000 "); // valid values now 0 and 2 |
|
1058 |
asm("cmp r1, #1 "); // r1=container number or -1 if any object OK |
|
1059 |
asm("bgt 1b "); // if type is neither thread nor process nor any, bad handle |
|
1060 |
asm("beq 3f "); // skip check for KCurrentThreadHandle if process required |
|
1061 |
asm("cmp ip, #2 "); // handle = ffff8001 ? |
|
1062 |
asm("subeq r0, r2, #%a0" : : "i" _FOFF(DThread,iNThread)); |
|
1063 |
__JUMP(eq,lr); // if so, return TheCurrentThread |
|
1064 |
asm("cmn r1, #1 "); // r1=-1 means any type of object will do |
|
1065 |
asm("bne 1b "); |
|
1066 |
asm("3: "); |
|
1067 |
asm("cmp ip, #0 "); // handle = ffff8000 ? |
|
1068 |
asm("ldreq r0, [r2, #%a0]" : : "i" (_FOFF(DThread,iOwningProcess)-_FOFF(DThread,iNThread))); |
|
1069 |
__JUMP(eq,lr); // if so, return TheCurrentThread->iOwningProcess |
|
1070 |
asm("b 1b "); // else bad handle |
|
1071 |
} |
|
1072 |
#endif |
|
1073 |
||
1074 |
/** Returns the current state of interrupts |
|
1075 |
||
1076 |
@param aRequest indicates which state of interrupts should be returned |
|
1077 |
||
1078 |
@return if aRequest is ETrue, function returns ETrue if interrupts are enabled and EFalse otherwise |
|
1079 |
if aRequest is EFalse, function returns ETrue if interrupts are disabled and EFalse otherwise |
|
1080 |
*/ |
|
1081 |
__NAKED__ TBool InterruptsStatus(TBool) |
|
1082 |
{ |
|
1083 |
asm("cmp r0, #0 "); |
|
1084 |
asm("beq check_interrupts_disabled "); |
|
1085 |
//check that ints are enabled |
|
1086 |
asm("mrs r0, cpsr "); |
|
1087 |
asm("ands r0, r0, #%a0 " : : "i" ((TInt)KAllInterruptsMask)); |
|
1088 |
asm("moveq r0,#1"); |
|
1089 |
asm("movne r0,#0"); |
|
1090 |
__JUMP(,lr); |
|
1091 |
asm("check_interrupts_disabled: "); |
|
1092 |
asm("mrs r0, cpsr "); |
|
1093 |
asm("and r0, r0, #%a0 " : : "i" ((TInt)KAllInterruptsMask)); |
|
1094 |
asm("cmp r0, #%a0 " : : "i" ((TInt)KAllInterruptsMask)); |
|
1095 |
asm("moveq r0,#1"); |
|
1096 |
asm("movne r0,#0"); |
|
1097 |
__JUMP(,lr); |
|
1098 |
} |
|
1099 |
||
1100 |
extern "C" EXPORT_C __NAKED__ void pagecpy(TAny* /*aTrg*/, const TAny* /*aSrc*/) |
|
1101 |
{ |
|
1102 |
// Source and destination 4k page aligned (and thus cache aligned) |
|
1103 |
// Fixed copy size of 4k |
|
1104 |
// - easy as pie |
|
1105 |
asm("mov r2, #12 "); |
|
1106 |
// fall through to fastcpy |
|
1107 |
} |
|
1108 |
||
1109 |
extern "C" __NAKED__ void fastcpy(TAny* /*aTrg*/, const TAny* /*aSrc*/, TUint8 /*aPower*/) |
|
1110 |
{ |
|
1111 |
asm("stmfd sp!, {r4-r9} "); |
|
1112 |
asm("mov ip, #-1 "); |
|
1113 |
asm("mvn ip, ip, lsl r2 "); |
|
1114 |
asm("pagecpy_loop: "); |
|
1115 |
PLD_ioff(1, 32); |
|
1116 |
PLD_ioff(1, 64); |
|
1117 |
asm("ldmia r1!, {r2-r9} "); |
|
1118 |
asm("stmia r0!, {r2-r9} "); |
|
1119 |
asm("ldmia r1!, {r2-r9} "); |
|
1120 |
asm("tst r1, ip "); |
|
1121 |
asm("stmia r0!, {r2-r9} "); |
|
1122 |
asm("bne pagecpy_loop "); |
|
1123 |
asm("ldmfd sp!, {r4-r9} "); |
|
1124 |
__JUMP(,lr); |
|
1125 |
||
1126 |
||
1127 |
asm("__TheScheduler: "); |
|
1128 |
asm(".word TheScheduler "); |
|
1129 |
} |
|
1130 |
||
1131 |
#if defined(__MEMMODEL_MOVING__) || defined(__MEMMODEL_MULTIPLE__) |
|
1132 |
__NAKED__ TInt MmuBase::MoveKernelStackPage(DChunk* /*aChunk*/, TUint32 /*aOffset*/, TPhysAddr /*aOld*/, |
|
1133 |
TPhysAddr& /*aNew*/, TUint /*aBlockZoneId*/, TBool /*aBlockRest*/) |
|
1134 |
{ |
|
1135 |
// Switch to a safe stack then call the regular MoveKernelPage |
|
1136 |
||
1137 |
asm("mov ip, sp "); |
|
1138 |
asm("ldr sp, [r0, #%a0]" : : "i" _FOFF(MmuBase,iAltStackBase)); // r0=this |
|
1139 |
asm("stmfd sp!, {ip,lr} "); |
|
1140 |
asm("ldr lr, [ip, #8] "); |
|
1141 |
asm("str lr, [sp, #-8]! "); |
|
1142 |
asm("ldr lr, [ip, #4] "); |
|
1143 |
asm("str lr, [sp, #-4]! "); |
|
1144 |
asm("ldr lr, [ip] "); |
|
1145 |
asm("str lr, [sp, #-4]! "); |
|
1146 |
asm("bl " CSM_ZN3Mmu14MoveKernelPageEP6DChunkmmRmji); |
|
1147 |
asm("ldmfd sp, {r1,r2,r3,ip,sp,pc} "); |
|
1148 |
} |
|
1149 |
#endif |
|
1150 |
||
1151 |
__NAKED__ TInt K::FloatingPointSystemId(TUint32& /*aSysId*/) |
|
1152 |
{ |
|
1153 |
#if __CPU_HAS_VFP |
|
1154 |
VFP_FMRX(,1,VFP_XREG_FPSID); |
|
1155 |
asm("str r1, [r0] "); |
|
1156 |
asm("mov r0, #0 "); |
|
1157 |
#else |
|
1158 |
asm("mov r0, #%a0 " : : "i" ((TInt)KErrNotSupported)); |
|
1159 |
#endif |
|
1160 |
__JUMP(,lr); |
|
1161 |
} |
|
1162 |
||
1163 |
#ifdef __CLIENT_REQUEST_MACHINE_CODED__ |
|
1164 |
||
1165 |
__NAKED__ void TServerMessage::CallbackFunc(TAny* aData, TUserModeCallbackReason aReason) |
|
1166 |
{ |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1167 |
// r0 -> TServerMessage object (this is derived from TClientRequest) |
0 | 1168 |
// r1 == reason code: 0 => run, 1 => cancel |
1169 |
||
1170 |
asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(TClientRequest, iResult)); |
|
1171 |
asm("teq r1, #%a0" : : "i" (EUserModeCallbackRun)); |
|
1172 |
asm("teqeq r3, #0"); // iResult == KErrNone |
|
1173 |
asm("bne clientRequestCallback2"); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1174 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1175 |
asm("stmfd sp!, {r0, r4-r7, lr}"); |
0 | 1176 |
asm("ldr ip, [r0, #%a0]" : : "i" _FOFF(TServerMessage, iMessagePtr)); |
1177 |
asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TServerMessage, iMessageData)); |
|
1178 |
asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(RMessageK, iFunction)); |
|
1179 |
asm("ldr r7, [r0, #%a0]" : : "i" _FOFF(RMessageK, iSession)); |
|
1180 |
||
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1181 |
// If the message is not a disconnect, load the arguments from the message. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1182 |
// If it is a disconnect, set all message arguments (r2-r5) to 0 instead. |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1183 |
asm("cmn r1, #%a0" : : "i" (-RMessage2::EDisConnect)); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1184 |
asm("moveq r2, #0"); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1185 |
asm("addne r2, r0, #%a0" : : "i" _FOFF(RMessageK, iMsgArgs.iArgs)); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1186 |
asm("moveq r3, #0"); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1187 |
// HARDCODED(RMessageK)- this assumes KMaxMessageArguments is 4 |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1188 |
asm("ldmneia r2, {r2-r5}"); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1189 |
asm("moveq r4, #0"); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1190 |
asm("moveq r5, #0"); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1191 |
asm("mov r6, #0"); |
0 | 1192 |
asm("ldr r7, [r7, #%a0]" : : "i" _FOFF(DSession, iSessionCookie)); |
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1193 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1194 |
asm("cmp r6, #1"); // ensure Z flag is clear |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1195 |
USER_MEMORY_GUARD_OFF(,lr,lr); |
0 | 1196 |
// HARDCODED(RMessage2)- this assumes the layout of the first 8 words of this structure |
1197 |
asm(".global __magic_address_svr_accept_1 "); |
|
1198 |
asm("__magic_address_svr_accept_1: "); // this instruction is magically immune from exceptions |
|
1199 |
asm("strt r0, [ip], #4"); |
|
1200 |
asm(".global __magic_address_svr_accept_2 "); |
|
1201 |
asm("__magic_address_svr_accept_2: "); // this instruction is magically immune from exceptions |
|
1202 |
asm("strnet r1, [ip], #4"); |
|
1203 |
asm(".global __magic_address_svr_accept_3 "); |
|
1204 |
asm("__magic_address_svr_accept_3: "); // this instruction is magically immune from exceptions |
|
1205 |
asm("strnet r2, [ip], #4"); |
|
1206 |
asm(".global __magic_address_svr_accept_4 "); |
|
1207 |
asm("__magic_address_svr_accept_4: "); // this instruction is magically immune from exceptions |
|
1208 |
asm("strnet r3, [ip], #4"); |
|
1209 |
asm(".global __magic_address_svr_accept_5 "); |
|
1210 |
asm("__magic_address_svr_accept_5: "); // this instruction is magically immune from exceptions |
|
1211 |
asm("strnet r4, [ip], #4"); |
|
1212 |
asm(".global __magic_address_svr_accept_6 "); |
|
1213 |
asm("__magic_address_svr_accept_6: "); // this instruction is magically immune from exceptions |
|
1214 |
asm("strnet r5, [ip], #4"); |
|
1215 |
asm(".global __magic_address_svr_accept_7 "); |
|
1216 |
asm("__magic_address_svr_accept_7: "); // this instruction is magically immune from exceptions |
|
1217 |
asm("strnet r6, [ip], #4"); |
|
1218 |
asm(".global __magic_address_svr_accept_8 "); |
|
1219 |
asm("__magic_address_svr_accept_8: "); // this instruction is magically immune from exceptions |
|
1220 |
asm("strnet r7, [ip], #4"); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1221 |
USER_MEMORY_GUARD_ON(,lr,lr); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1222 |
|
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1223 |
asm("ldmfd sp!, {r0, r4-r7, lr}"); |
0 | 1224 |
asm("mov r1, #%a0" : : "i" (EUserModeCallbackRun)); |
1225 |
asm("mov r3, #0" ); |
|
1226 |
asm("b clientRequestCallback2"); |
|
1227 |
} |
|
1228 |
||
1229 |
__NAKED__ void TClientRequest::CallbackFunc(TAny* /*aData*/, TUserModeCallbackReason /*aReason*/) |
|
1230 |
{ |
|
1231 |
// parameters: |
|
1232 |
// r0 -> this |
|
1233 |
// r1 == reason code |
|
1234 |
// locals: |
|
1235 |
// r2 == old status |
|
1236 |
// r3 == result |
|
1237 |
||
1238 |
asm("clientRequestCallback:"); |
|
1239 |
asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(TClientRequest, iResult)); |
|
1240 |
asm("clientRequestCallback2:"); |
|
1241 |
asm("stmfd sp!, {r0, r1, r3, lr} "); |
|
1242 |
#ifdef _DEBUG |
|
1243 |
ASM_CHECK_PRECONDITIONS(MASK_THREAD_CRITICAL); |
|
1244 |
#endif |
|
1245 |
asm("mov ip, #%a0" : : "i" ((TInt)KRequestPending)); |
|
1246 |
asm("str ip, [r0, #%a0]" : : "i" _FOFF(TClientRequest, iResult)); |
|
1247 |
asm("mov r1, #%a0" : : "i" ((TInt)KClientRequestFlagClosing)); |
|
1248 |
asm("add r0, r0, #%a0 " : : "i" _FOFF(TClientRequest, iStatus)); |
|
1249 |
asm("bl __e32_atomic_and_ord32 "); |
|
1250 |
asm("mov r2, r0 "); |
|
1251 |
asm("ldmfd sp!, {r0, r1, r3, lr} "); |
|
1252 |
||
1253 |
#ifdef _DEBUG |
|
1254 |
asm("teq r2, #0"); |
|
1255 |
asm("tstne r2, #%a0" : : "i" ((TInt)KClientRequestFlagInUse)); |
|
1256 |
asm("moveq r0, #%a0" : : "i" (K::EClientRequestCallbackInWrongState)); |
|
1257 |
asm("bleq " CSM_ZN1K5FaultENS_6TFaultE); |
|
1258 |
#endif |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1259 |
|
0 | 1260 |
USER_MEMORY_GUARD_OFF(,r12,r12); |
1261 |
asm("bic r12, r2, #%a0 " : : "i" ((TInt)KClientRequestFlagMask)); |
|
1262 |
asm("teq r12, #%a0 " : : "i" ((TInt)KClientRequestNullStatus)); |
|
1263 |
asm("teqne r1, #%a0" : : "i" (EUserModeCallbackCancel)); |
|
1264 |
asm(".global __magic_address_client_request_callback "); |
|
1265 |
asm("__magic_address_client_request_callback: "); // this instruction is magically immune from exceptions |
|
1266 |
asm("strnet r3, [r12]"); |
|
1267 |
USER_MEMORY_GUARD_ON(,r12,r12); |
|
1268 |
asm("tst r2, #%a0" : : "i" ((TInt)KClientRequestFlagClosing)); |
|
1269 |
asm("bne " CSM_ZN4Kern9AsyncFreeEPv); |
|
1270 |
__JUMP(,lr); |
|
1271 |
} |
|
1272 |
#endif |
|
1273 |
||
1274 |
#ifdef __REQUEST_COMPLETE_MACHINE_CODED__ |
|
1275 |
||
1276 |
#ifndef __MEMMODEL_FLEXIBLE__ |
|
1277 |
__NAKED__ EXPORT_C void Kern::RequestComplete(DThread* /*aThread*/, TRequestStatus*& /*aStatus*/, TInt /*aReason*/) |
|
1278 |
{ |
|
1279 |
ASM_CHECK_PRECONDITIONS(MASK_THREAD_STANDARD); |
|
1280 |
ASM_ASSERT_DATA_PAGING_SAFE; // Assembler version needs paging check, c++ version calls RawWrite which checks already |
|
1281 |
||
1282 |
ASM_DEBUG2(KernRequestComplete,r0,lr); |
|
1283 |
||
1284 |
asm("stmfd sp!, {r0-r2,lr} "); |
|
1285 |
asm("bl " CSM_ZN5NKern10LockSystemEv); |
|
1286 |
asm("ldmfd sp!, {r0-r2,lr} "); |
|
1287 |
asm("ldr r3, [r1] "); |
|
1288 |
asm("teq r3, #0 "); |
|
1289 |
asm("beq " CSM_ZN5NKern12UnlockSystemEv); |
|
1290 |
asm("mov r12, #0 "); |
|
1291 |
asm("str r12, [r1] "); // aStatus=NULL |
|
1292 |
asm("b _asm_RequestComplete "); // call into DThread::RequestComplete with r3 == status ptr |
|
1293 |
} |
|
1294 |
#endif |
|
1295 |
||
1296 |
__NAKED__ EXPORT_C void Kern::RequestComplete(TRequestStatus*& /*aStatus*/, TInt /*aReason*/) |
|
1297 |
{ |
|
1298 |
ASM_CHECK_PRECONDITIONS(MASK_KERNEL_UNLOCKED | MASK_INTERRUPTS_ENABLED | MASK_NOT_ISR | MASK_NOT_IDFC); |
|
1299 |
||
1300 |
asm("mov r12, #0 "); |
|
1301 |
#ifdef __CPU_ARM_HAS_LDREX_STREX |
|
1302 |
asm("1: "); |
|
1303 |
LDREX( 2, 0); // read |
|
1304 |
STREX( 3, 12, 0); // write |
|
1305 |
asm("teq r3, #0 "); // success? |
|
1306 |
asm("bne 1b "); // no! |
|
1307 |
#else |
|
1308 |
asm("swp r2, r12, [r0] "); |
|
1309 |
#endif |
|
1310 |
asm("ldr r3, __TheScheduler "); |
|
1311 |
asm("teq r2, #0 "); // clear zero flag if address is not null |
|
1312 |
USER_MEMORY_GUARD_OFF(,r0,r0); |
|
1313 |
asm(".global __magic_address_kern_request_complete "); |
|
1314 |
asm("__magic_address_kern_request_complete: "); // this instruction is magically immune from exceptions |
|
1315 |
asm("strnet r1, [r2] "); |
|
1316 |
USER_MEMORY_GUARD_ON(,r0,r0); |
|
1317 |
__JUMP( eq, lr); // return if address zero or store failed |
|
1318 |
asm("ldr r0, [r3, #%a0]" : : "i" _FOFF(TScheduler,iCurrentThread)); // r0->current NThread |
|
1319 |
asm("b " CSM_ZN5NKern19ThreadRequestSignalEP7NThread); |
|
1320 |
} |
|
1321 |
||
1322 |
#endif |
|
1323 |
||
1324 |
extern "C" __NAKED__ TInt read_and_parse_des_header_local(TAny* aUnused, TAny* aDesPtr, TDesHeader& aOut) |
|
1325 |
{ |
|
1326 |
asm("mov r0, r1 "); |
|
1327 |
asm("mov r1, r2 "); |
|
1328 |
// fall through |
|
1329 |
} |
|
1330 |
||
1331 |
/** |
|
1332 |
Read the header of a user-side descriptor in the current process, parse it, and populate a |
|
1333 |
TDesHeader with the result. |
|
1334 |
||
1335 |
@param aDesPtr The descriptor for which information is to be fetched. |
|
1336 |
@param aOut On return, set to the parsed contents of the descriptor header. |
|
1337 |
||
1338 |
@return KErrNone if successful, or one of the system-wide error codes. |
|
1339 |
||
1340 |
@pre Interrupts must be enabled. |
|
1341 |
@pre Kernel must be unlocked. |
|
1342 |
@pre No fast mutex can be held. |
|
1343 |
@pre Call in a thread context. |
|
1344 |
@pre Can be used in a device driver. |
|
1345 |
*/ |
|
1346 |
__NAKED__ TInt K::USafeReadAndParseDesHeader(TAny* aDesPtr, TDesHeader& aOut) |
|
1347 |
{ |
|
1348 |
// r0 -> user-side descriptor |
|
1349 |
// r1 -> parsed header out |
|
1350 |
||
1351 |
asm("stmfd sp!, {lr} "); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1352 |
USER_MEMORY_GUARD_OFF(,lr,lr); |
0 | 1353 |
|
1354 |
// set condition codes to 'hi' condition (unless we're reading a null pointer) |
|
1355 |
asm("cmp r0, #0"); |
|
1356 |
||
1357 |
// read first word of descriptor... |
|
1358 |
asm(".global __magic_address_readdesheader1 "); |
|
1359 |
asm("__magic_address_readdesheader1: "); // this instruction is magically immune from exceptions |
|
1360 |
asm("ldrhit r2, [r0], #4"); // WILL SET Z FLAG AND MODIFY R12 IF EXCEPTION OCCURS |
|
1361 |
||
1362 |
// r12 = length of this descriptor type... |
|
1363 |
asm("adrhi r12, LengthLookup"); |
|
1364 |
asm("ldrhib r12, [r12, r2, lsr #28]"); |
|
1365 |
asm("cmphi r12, #0"); // set zero flag for invalid descriptor type |
|
1366 |
// r3 = 2nd word of descriptor (if it is 8 bytes or more in size)... |
|
1367 |
asm("cmphi r12, #7"); |
|
1368 |
asm(".global __magic_address_readdesheader2 "); |
|
1369 |
asm("__magic_address_readdesheader2: "); // this instruction is magically immune from exceptions |
|
1370 |
asm("ldrhit r3, [r0], #4"); // WILL SET Z FLAG AND MODIFY R12 IF EXCEPTION OCCURS |
|
1371 |
||
1372 |
// r12 = 3rd word of descriptor (if it is 12 bytes or more in size)... |
|
1373 |
asm("cmphi r12, #11"); |
|
1374 |
asm(".global __magic_address_readdesheader3 "); |
|
1375 |
asm("__magic_address_readdesheader3: "); // this instruction is magically immune from exceptions |
|
1376 |
asm("ldrhit r12, [r0], #4"); // WILL SET Z FLAG AND MODIFY R12 IF EXCEPTION OCCURS |
|
1377 |
||
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1378 |
USER_MEMORY_GUARD_ON(,lr,lr); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1379 |
asm("beq bad_descriptor "); // Z flag set here if we took an exception |
0 | 1380 |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1381 |
asm("eor lr, r2, r2, lsr #1 "); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1382 |
asm("msr cpsr_flg, lr "); |
0 | 1383 |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1384 |
// r12 == header_in[2] |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1385 |
asm("movcc r12, r3 "); // r12 = header_in[1] if EBufC, EPtrC |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1386 |
asm("movgt r12, r0 "); // r12 = pointer to word after header if EBufC, EBuf |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1387 |
asm("addeq r12, r12, #4 "); // r12 += sizeof(TDesC) if EBufCPtr |
0 | 1388 |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1389 |
// r3 == header_in[1] |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1390 |
// r3 = KErrBadDescriptor if EBufC, EPtrC |
0 | 1391 |
asm("mvncc r3, #%a0" : : "i" (~TDesHeader::KConstMaxLength)); |
1392 |
||
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1393 |
// r0 is an aligned pointer |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1394 |
asm("moveq r0, r12 "); // r0 = pointer to des data if EBufCPtr |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1395 |
asm("tst r0, #3 "); // if (type == EBufCPtr && ((TUint)p & 3) != 0) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1396 |
asm("bne bad_descriptor "); // return KErrBadDescriptor; |
0 | 1397 |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1398 |
asm("bic lr, r2, #0xf0000000 "); |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1399 |
asm("cmp lr, r3 "); // if (len > max) |
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1400 |
asm("bhi bad_descriptor "); // return KErrBadDescriptor; |
0 | 1401 |
|
1402 |
asm("stmia r1, {r2,r3,r12}"); |
|
1403 |
asm("mov r0, #0 "); |
|
1404 |
__POPRET(""); |
|
1405 |
||
1406 |
asm("bad_descriptor: "); |
|
1407 |
asm("mvn r0, #%a0" : : "i" (~KErrBadDescriptor)); |
|
1408 |
__POPRET(""); |
|
1409 |
||
1410 |
asm("LengthLookup:"); |
|
1411 |
asm(".byte 4,8,12,8,12,0,0,0,0,0,0,0,0,0,0,0"); |
|
1412 |
} |
|
1413 |
||
1414 |
#ifdef __SMP__ |
|
1415 |
extern TSpinLock BTraceFilter2Lock; |
|
1416 |
||
1417 |
__NAKED__ TBool DBTraceFilter2::Check(TUint32 aUid) |
|
1418 |
{ |
|
1419 |
asm("DBTraceFilter2_Check: "); |
|
1420 |
asm("stmdb sp!, {lr}"); |
|
1421 |
asm("ldr r3, [r0,#%a0]" : : "i" _FOFF(DBTraceFilter2,iNumUids)); |
|
1422 |
asm("add r0, r0, #%a0" : : "i" _FOFF(DBTraceFilter2,iUids)); |
|
1423 |
asm("mov r2, #0"); |
|
1424 |
asm("0:"); |
|
1425 |
asm("cmp r3, r2"); |
|
1426 |
asm("bls 9f"); |
|
1427 |
asm("add r12, r2, r3"); |
|
1428 |
asm("mov r12, r12, asr #1"); |
|
1429 |
asm("ldr lr, [r0, r12, lsl #2]"); |
|
1430 |
asm("cmp r1, lr"); |
|
1431 |
asm("addhi r2, r12, #1"); |
|
1432 |
asm("movlo r3, r12"); |
|
1433 |
asm("bne 0b"); |
|
1434 |
asm("movs r0, #1"); |
|
1435 |
__POPRET(""); |
|
1436 |
asm("9:"); |
|
1437 |
asm("movs r0, #0"); |
|
1438 |
__POPRET(""); |
|
1439 |
} |
|
1440 |
||
1441 |
||
1442 |
__NAKED__ TBool SBTraceData::CheckFilter2(TUint32 aUid) |
|
1443 |
{ |
|
1444 |
asm("btrace_check_filter2:"); |
|
1445 |
// returns r0 = 0 or 1 indicating if trace passed the filter check |
|
1446 |
// returns r2 = trace context id |
|
1447 |
||
1448 |
asm("stmdb sp!, {r4-r8,lr}"); |
|
1449 |
asm("mov r4, r0 "); |
|
1450 |
asm("mov r8, r1 "); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1451 |
asm("mrs lr, cpsr "); |
0 | 1452 |
__ASM_CLI(); |
1453 |
GET_RWNO_TID(,r3); |
|
1454 |
asm("mov r5, #0 "); // r5 = TRUE if critical section entered |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1455 |
asm("and r6, lr, #0x0f "); |
0 | 1456 |
asm("cmp r6, #3 "); |
1457 |
asm("movhi r6, #2 "); // r6 = context ID = 1 for FIQ, 2 for IRQ/ABT/UND/SYS |
|
1458 |
asm("bne 1f "); // branch if not mode_svc |
|
1459 |
asm("ldrb r12, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iInIDFC)); |
|
1460 |
asm("cmp r12, #0 "); |
|
1461 |
asm("bne 1f "); // branch if IDFC |
|
1462 |
asm("ldrb r12, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iKernLockCount)); |
|
1463 |
asm("ldr r6, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
1464 |
asm("cmp r12, #0 "); // kernel locked? |
|
1465 |
asm("bne 1f "); // if so, don't enter CS |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1466 |
asm("msr cpsr, lr "); // restore interrupts |
0 | 1467 |
asm("bl " CSM_ZN5NKern14_ThreadEnterCSEv ); |
1468 |
asm("mov r5, #1 "); |
|
1469 |
asm("b 2f "); |
|
1470 |
||
1471 |
asm("1: "); |
|
4
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1472 |
asm("msr cpsr, lr "); // restore interrupts |
0 | 1473 |
asm("2: "); // r6 = context ID, r5 = TRUE if critical section entered |
1474 |
||
1475 |
// DBTraceFilter2::Open() |
|
1476 |
asm("ldr r0, __BTraceFilter2Lock "); |
|
1477 |
asm("bl " CSM_ZN9TSpinLock11LockIrqSaveEv ); |
|
1478 |
asm("ldr r7, [r4, #%a0]" : : "i" _FOFF(SBTraceData,iFilter2)); |
|
1479 |
asm("cmp r7, #1 "); |
|
1480 |
asm("ldrhi r2, [r7, #%a0]" : : "i" _FOFF(DBTraceFilter2,iAccessCount)); |
|
1481 |
asm("addhi r2, r2, #1 "); |
|
1482 |
asm("strhi r2, [r7, #%a0]" : : "i" _FOFF(DBTraceFilter2,iAccessCount)); |
|
1483 |
asm("mov r1, r0 "); |
|
1484 |
asm("ldr r0, __BTraceFilter2Lock "); |
|
1485 |
asm("bl " CSM_ZN9TSpinLock16UnlockIrqRestoreEi ); |
|
1486 |
asm("cmp r7, #1 "); |
|
1487 |
asm("bls 3f "); |
|
1488 |
||
1489 |
// DBTraceFilter2::Check() |
|
1490 |
asm("mov r0, r7 "); |
|
1491 |
asm("mov r1, r8 "); |
|
1492 |
asm("bl DBTraceFilter2_Check "); |
|
1493 |
asm("mov r8, r0 "); |
|
1494 |
||
1495 |
// DBTraceFilter2::Close() |
|
1496 |
asm("ldr r0, __BTraceFilter2Lock "); |
|
1497 |
asm("bl " CSM_ZN9TSpinLock11LockIrqSaveEv ); |
|
1498 |
asm("ldr r2, [r7, #%a0]" : : "i" _FOFF(DBTraceFilter2,iAccessCount)); |
|
1499 |
asm("ldr r1, __DBTraceFilter2_iCleanupHead"); |
|
1500 |
asm("subs r2, r2, #1"); |
|
1501 |
asm("str r2, [r7, #%a0]" : : "i" _FOFF(DBTraceFilter2,iAccessCount)); |
|
1502 |
asm("ldreq r2, [r1] "); |
|
1503 |
asm("streq r7, [r1] "); |
|
1504 |
asm("streq r2, [r7, #%a0]" : : "i" _FOFF(DBTraceFilter2,iCleanupLink)); |
|
1505 |
asm("mov r1, r0 "); |
|
1506 |
asm("ldr r0, __BTraceFilter2Lock "); |
|
1507 |
asm("bl " CSM_ZN9TSpinLock16UnlockIrqRestoreEi ); |
|
1508 |
asm("mov r7, r8 "); // r7 = result |
|
1509 |
asm("3: "); |
|
1510 |
||
1511 |
// NKern::ThreadLeaveCS() |
|
1512 |
asm("cmp r5, #0"); |
|
1513 |
asm("blne " CSM_ZN5NKern14_ThreadLeaveCSEv ); |
|
1514 |
asm("mov r0, r7 "); // r0 = result |
|
1515 |
asm("mov r2, r6 "); // r2 = context id |
|
1516 |
__POPRET("r4-r8,"); |
|
1517 |
||
1518 |
asm("__DBTraceFilter2_iCleanupHead:"); |
|
1519 |
asm(".word %a0" : : "i" ((TInt)&DBTraceFilter2::iCleanupHead)); |
|
1520 |
asm("__BTraceFilter2Lock: "); |
|
1521 |
asm(".word %a0" : : "i" ((TInt)&BTraceFilter2Lock)); |
|
1522 |
} |
|
1523 |
#endif |
|
1524 |
||
1525 |