author | mikek |
Fri, 02 Jul 2010 09:53:45 +0100 | |
branch | GCC_SURGE |
changeset 190 | 0d42d469e749 |
parent 184 | 0e2270015475 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2008-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\nkernsmp\arm\ncthrd.cia |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#define __INCLUDE_NTHREADBASE_DEFINES__ |
|
19 |
||
20 |
#include <arm.h> |
|
21 |
#include <e32cia.h> |
|
22 |
||
23 |
#undef iDfcState |
|
24 |
#define iDfcState i8816.iHState16 |
|
25 |
||
26 |
extern "C" void send_accumulated_resched_ipis(); |
|
27 |
||
28 |
/****************************************************************************** |
|
29 |
* Thread |
|
30 |
******************************************************************************/ |
|
31 |
extern "C" __NAKED__ void __StartThread() |
|
32 |
{ |
|
33 |
// On entry: |
|
34 |
// R0->TSubScheduler, R1=0, R2=1, R3->current thread |
|
35 |
// R12=resched IPIs |
|
36 |
// Interrupts disabled |
|
37 |
||
38 |
// need to send any outstanding reschedule IPIs |
|
39 |
asm("cmp r12, #0 "); |
|
40 |
asm("blne " CSM_CFUNC(send_accumulated_resched_ipis)); |
|
41 |
#ifdef __USER_MEMORY_GUARDS_ENABLED__ |
|
42 |
asm("ldr r0, [sp, #%a0]" : : "i" _FOFF(SThreadExcStack, iCPSR)); |
|
43 |
asm("tst r0, #0x0f "); |
|
44 |
asm("bne 2f "); |
|
45 |
USER_MEMORY_GUARD_OFF(,r0,r0); |
|
46 |
asm("2: "); |
|
47 |
#endif |
|
48 |
asm("ldmia sp, {r0-r14}^ "); // load initial values for R0-R12, R13_usr, R14_usr |
|
49 |
asm("nop "); // don't access banked register immediately after |
|
50 |
asm("add sp, sp, #64 "); // point to saved PC, CPSR (skip iExcCode) |
|
51 |
asm("adr lr, 1f "); // set lr_svc in case thread returns |
|
52 |
RFEIAW(13); // restore PC and CPSR - jump to thread entry point |
|
53 |
||
54 |
asm("1: "); |
|
55 |
asm("b " CSM_ZN5NKern4ExitEv); // if control returns, call NKern::Exit() |
|
56 |
} |
|
57 |
||
58 |
||
59 |
extern "C" __NAKED__ TInt get_kernel_context_type(TLinAddr /*aReschedReturn*/) |
|
60 |
{ |
|
61 |
asm("adr r1, 9f "); |
|
62 |
asm("mov r3, r0 "); |
|
63 |
asm("mvn r0, #0 "); |
|
64 |
asm("1: "); |
|
65 |
asm("ldr r2, [r1], #4 "); |
|
66 |
asm("add r0, r0, #1 "); |
|
67 |
asm("cmp r2, r3 "); |
|
68 |
asm("beq 2f "); |
|
69 |
asm("cmp r2, #0 "); |
|
70 |
asm("bne 1b "); |
|
71 |
asm("mvn r0, #0 "); |
|
72 |
asm("2: "); |
|
73 |
__JUMP(, lr); |
|
74 |
||
75 |
asm("9: "); |
|
76 |
asm(".word " CSM_CFUNC(__StartThread)); |
|
77 |
asm(".word nkern_unlock_resched_return "); |
|
78 |
asm(".word nkern_preemption_point_resched_return "); |
|
79 |
asm(".word nkern_wfar_resched_return "); |
|
80 |
asm(".word irq_resched_return "); |
|
81 |
asm(".word exec_wfar_resched_return "); |
|
82 |
asm(".word 0 "); |
|
83 |
} |
|
84 |
||
85 |
||
86 |
/** Mark the beginning of an event handler tied to a thread or thread group |
|
87 |
||
88 |
Return the number of the CPU on which the event handler should run |
|
89 |
*/ |
|
90 |
__NAKED__ TInt NSchedulable::BeginTiedEvent() |
|
91 |
{ |
|
92 |
asm("add r1, r0, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
93 |
asm("1: "); |
|
94 |
LDREX(0,1); // r0 = original value of iEventState |
|
95 |
asm("add r2, r0, #%a0" : : "i" ((TInt)EEventCountInc)); |
|
96 |
STREX(3,2,1); |
|
97 |
asm("cmp r3, #0 "); |
|
98 |
asm("bne 1b "); |
|
99 |
__DATA_MEMORY_BARRIER__(r3); |
|
100 |
asm("tst r0, #%a0" : : "i" ((TInt)EEventParent)); |
|
101 |
asm("ldrne r2, [r1, #%a0]" : : "i" (_FOFF(NSchedulable,iParent) - _FOFF(NSchedulable,iEventState))); |
|
102 |
asm("beq bte0 "); // EEventParent not set so don't look at group |
|
103 |
asm("cmp r2, #0 "); |
|
104 |
asm("addne r2, r2, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
105 |
asm("beq bte_bad "); |
|
106 |
asm("cmp r2, r1 "); |
|
107 |
asm("beq bte2 "); // parent not yet updated, use iNewParent |
|
108 |
asm("bte1: "); |
|
109 |
LDREX(0,2); // r0 = original value of iEventState |
|
110 |
asm("add r3, r0, #%a0" : : "i" ((TInt)EEventCountInc)); |
|
111 |
STREX(12,3,2); |
|
112 |
asm("cmp r12, #0 "); |
|
113 |
asm("bne 1b "); |
|
114 |
__DATA_MEMORY_BARRIER__(r12); |
|
115 |
asm("bte0: "); |
|
116 |
asm("and r0, r0, #%a0" : : "i" ((TInt)EEventCpuMask)); |
|
117 |
__JUMP(,lr); // return event CPU |
|
118 |
||
119 |
asm("bte2: "); |
|
120 |
__DATA_MEMORY_BARRIER__(r3); // make sure iNewParent is read after iParent |
|
121 |
asm("ldr r2, [r1, #%a0]" : : "i" (_FOFF(NThreadBase,iNewParent) - _FOFF(NSchedulable,iEventState))); |
|
122 |
asm("cmp r2, #0 "); |
|
123 |
asm("addne r2, r2, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
124 |
asm("bne bte1 "); // iNewParent set so OK |
|
125 |
__DATA_MEMORY_BARRIER__(r3); // make sure iParent is read after iNewParent |
|
126 |
asm("ldr r2, [r1, #%a0]" : : "i" (_FOFF(NSchedulable,iParent) - _FOFF(NSchedulable,iEventState))); |
|
127 |
asm("cmp r2, #0 "); |
|
128 |
asm("addne r2, r2, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
129 |
asm("cmp r2, r1 "); |
|
130 |
asm("bne bte1 "); // iParent now set so OK, otherwise something is wrong |
|
131 |
||
132 |
asm("bte_bad: "); |
|
133 |
__ASM_CRASH(); |
|
134 |
} |
|
135 |
||
136 |
||
137 |
/** Mark the end of an event handler tied to a thread or thread group |
|
138 |
||
139 |
*/ |
|
140 |
__NAKED__ void NSchedulable::EndTiedEvent() |
|
141 |
{ |
|
142 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
143 |
asm("ldr r1, [r0, #%a0]!" : : "i" _FOFF(NSchedulable, iEventState)); |
|
144 |
asm("tst r1, #%a0" : : "i" ((TInt)EEventParent)); |
|
145 |
asm("bne etep0 "); // branch out if EEventParent set |
|
146 |
||
147 |
// r0->NSchedulable::iEventState |
|
148 |
asm("ete1: "); |
|
149 |
LDREX(1,0); |
|
150 |
asm("sub r1, r1, #%a0" : : "i" ((TInt)EEventCountInc)); // decrement event count |
|
151 |
asm("cmp r1, #%a0" : : "i" ((TInt)EEventCountInc)); // check if now zero |
|
152 |
asm("biccc r1, r1, #0xFF "); // if so, mask event CPU ... |
|
153 |
asm("andcc r2, r1, #0x1F00 "); // ... and r2 = thread CPU << 8 ... |
|
154 |
asm("orrcc r1, r1, r2, lsr #8 "); // ... and event CPU = thread CPU |
|
155 |
STREX(12,1,0); |
|
156 |
asm("teq r12, #0 "); // test for success, leave carry alone |
|
157 |
asm("bne ete1 "); // retry if STREX failed |
|
158 |
asm("bcs ete2 "); // if not last tied event, finish |
|
159 |
asm("tst r1, #%a0" : : "i" ((TInt)EDeferredReady)); |
|
160 |
asm("addne r0, r0, #%a0" : : "i" (_FOFF(NSchedulable,i_IDfcMem) - _FOFF(NSchedulable,iEventState))); |
|
161 |
asm("bne " CSM_ZN4TDfc3AddEv ); // if deferred ready, add IDFC to action it |
|
162 |
asm("ete2: "); // ready not deferred so finish |
|
163 |
__JUMP(,lr); |
|
164 |
||
165 |
asm("etep0: "); |
|
166 |
__DATA_MEMORY_BARRIER__(r12); // make sure iParent is read after seeing parent flag set |
|
167 |
asm("ldr r3, [r0, #%a0]" : : "i" (_FOFF(NSchedulable,iParent) - _FOFF(NSchedulable,iEventState))); |
|
168 |
asm("cmp r3, #0 "); |
|
169 |
asm("addne r3, r3, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
170 |
asm("beq ete_bad "); // no parent - shouldn't happen |
|
171 |
asm("cmp r3, r0 "); // parent == this ? |
|
172 |
asm("beq etep1 "); // if so, parent not yet updated so use iNewParent |
|
173 |
||
174 |
asm("etep2: "); |
|
175 |
asm("stmfd sp!, {r0,lr} "); // save this and return address |
|
176 |
asm("mov r0, r3 "); // operate on parent |
|
177 |
asm("bl ete1 "); // update parent state |
|
178 |
asm("ldmfd sp!, {r0,lr} "); |
|
179 |
asm("1: "); |
|
180 |
LDREX(1,0); |
|
181 |
asm("sub r1, r1, #%a0" : : "i" ((TInt)EEventCountInc)); // decrement event count |
|
182 |
STREX(12,1,0); |
|
183 |
asm("cmp r12, #0 "); |
|
184 |
asm("bne 1b "); |
|
185 |
__JUMP(,lr); |
|
186 |
||
187 |
asm("etep1: "); |
|
188 |
__DATA_MEMORY_BARRIER__(r12); // make sure iNewParent is read after iParent |
|
189 |
asm("ldr r3, [r0, #%a0]" : : "i" (_FOFF(NThreadBase,iNewParent) - _FOFF(NSchedulable,iEventState))); |
|
190 |
asm("cmp r3, #0 "); |
|
191 |
asm("addne r3, r3, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
192 |
asm("bne etep2 "); // iNewParent set so OK |
|
193 |
__DATA_MEMORY_BARRIER__(r12); // make sure iParent is read after iNewParent |
|
194 |
asm("ldr r3, [r0, #%a0]" : : "i" (_FOFF(NSchedulable,iParent) - _FOFF(NSchedulable,iEventState))); |
|
195 |
asm("cmp r3, #0 "); |
|
196 |
asm("addne r3, r3, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
197 |
asm("cmp r3, r0 "); |
|
198 |
asm("bne etep2 "); // iParent now set so OK, otherwise something is wrong |
|
199 |
||
200 |
asm("ete_bad: "); |
|
201 |
__ASM_CRASH(); |
|
202 |
} |
|
203 |
||
204 |
||
205 |
/** Check for concurrent tied events when a thread/group becomes ready |
|
206 |
||
207 |
This is only ever called on a lone thread or a group, not on a thread |
|
208 |
which is part of a group. |
|
209 |
||
210 |
Update the thread CPU field in iEventState |
|
211 |
If thread CPU != event CPU and event count nonzero, atomically |
|
212 |
set the ready deferred flag and return TRUE, else return FALSE. |
|
213 |
If event count zero, set event CPU = thread CPU atomically. |
|
214 |
||
215 |
@param aCpu the CPU on which the thread/group is to become ready |
|
216 |
@return TRUE if the ready must be deferred. |
|
217 |
*/ |
|
218 |
__NAKED__ TBool NSchedulable::TiedEventReadyInterlock(TInt /*aCpu*/) |
|
219 |
{ |
|
220 |
asm("add r0, r0, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
221 |
asm("1: "); |
|
222 |
LDREX(2,0); // r2 = original iEventState |
|
223 |
asm("bic r3, r2, #0x1F00 "); // r3 = original iEventState with thread CPU zeroed out |
|
224 |
asm("orr r3, r3, r1, lsl #8 "); // set thread CPU field = aCpu |
|
225 |
asm("cmp r3, #%a0" : : "i" ((TInt)EEventCountInc)); |
|
226 |
asm("bhs 2f "); // branch if event count nonzero |
|
227 |
asm("bic r3, r3, #0xFF "); // else mask event CPU ... |
|
228 |
asm("orr r3, r3, r1 "); // ... and set event CPU = thread CPU = aCpu |
|
229 |
asm("3: "); |
|
230 |
STREX(12,3,0); |
|
231 |
asm("teq r12, #0 "); |
|
232 |
asm("bne 1b "); |
|
233 |
asm("eor r0, r2, r3 "); // r0 = old event state ^ new event state |
|
234 |
asm("and r0, r0, #%a0" : : "i" ((TInt)EDeferredReady)); |
|
235 |
__JUMP(,lr); // return TRUE if we just set EDeferredReady |
|
236 |
||
237 |
// event count is nonzero |
|
238 |
asm("2: "); |
|
239 |
asm("eor r12, r3, r3, lsr #8 "); // r12 bottom 5 bits = thread CPU ^ event CPU |
|
240 |
asm("tst r12, #0x1F "); // thread CPU == event CPU? |
|
241 |
asm("orrne r3, r3, #%a0" : : "i" ((TInt)EDeferredReady)); // if not, set EDeferredReady |
|
242 |
asm("b 3b "); |
|
243 |
} |
|
244 |
||
245 |
||
246 |
/** Check for concurrent tied events when a thread leaves a group |
|
247 |
||
248 |
If event count zero, atomically set the event and thread CPUs to the |
|
249 |
current CPU, clear the parent flag and return TRUE, else return FALSE. |
|
250 |
||
251 |
@return TRUE if the parent flag has been cleared |
|
252 |
@pre Preemption disabled |
|
253 |
*/ |
|
254 |
__NAKED__ TBool NThreadBase::TiedEventLeaveInterlock() |
|
255 |
{ |
|
256 |
GET_RWNO_TID(, r1); // R1->SubScheduler |
|
257 |
asm("ldr r1, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
258 |
asm("add r0, r0, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
259 |
asm("orr r1, r1, r1, lsl #8 "); // event CPU = thread CPU = this CPU, EDeferredReady, EEventParent clear |
|
260 |
asm("1: "); |
|
261 |
LDREX(2,0); |
|
262 |
asm("cmp r2, #%a0" : : "i" ((TInt)EEventCountInc)); // check if event count zero |
|
263 |
asm("bhs 0f "); // if not, finish and return FALSE |
|
264 |
STREX(3,1,0); // else update CPUs and clear parent flag |
|
265 |
// NOTE: Deferred ready flag must have been clear since thread is running |
|
266 |
asm("cmp r3, #0 "); |
|
267 |
asm("bne 1b "); |
|
268 |
__JUMP(,lr); // return TRUE (assumes this!=0) |
|
269 |
asm("0:"); |
|
270 |
asm("mov r0, #0 "); |
|
271 |
__JUMP(,lr); // return FALSE |
|
272 |
} |
|
273 |
||
274 |
||
275 |
/** Check for concurrent tied events when a thread joins a group |
|
276 |
||
277 |
If event count zero, atomically set the parent flag and return TRUE, |
|
278 |
else return FALSE. |
|
279 |
||
280 |
@return TRUE if the parent flag has been set |
|
281 |
@pre Preemption disabled |
|
282 |
*/ |
|
283 |
__NAKED__ TBool NThreadBase::TiedEventJoinInterlock() |
|
284 |
{ |
|
285 |
asm("add r0, r0, #%a0" : : "i" _FOFF(NSchedulable,iEventState)); |
|
286 |
asm("1: "); |
|
287 |
LDREX(1,0); |
|
288 |
asm("cmp r1, #%a0" : : "i" ((TInt)EEventCountInc)); // check if event count zero |
|
289 |
asm("bhs 0f "); // if not, finish and return FALSE |
|
290 |
asm("orr r2, r1, #%a0" : : "i" ((TInt)EEventParent)); // else set parent flag |
|
291 |
STREX(3,2,0); |
|
292 |
asm("cmp r3, #0 "); |
|
293 |
asm("bne 1b "); |
|
294 |
__JUMP(,lr); // return TRUE (assumes this!=0) |
|
295 |
asm("0:"); |
|
296 |
asm("mov r0, #0 "); |
|
297 |
__JUMP(,lr); // return FALSE |
|
298 |
} |
|
299 |
||
300 |
||
301 |
#ifdef __FAST_SEM_MACHINE_CODED__ |
|
302 |
/****************************************************************************** |
|
303 |
* Fast semaphore |
|
304 |
******************************************************************************/ |
|
305 |
||
306 |
/** Waits on a fast semaphore. |
|
307 |
||
308 |
Decrements the signal count for the semaphore and |
|
309 |
removes the calling thread from the ready-list if the semaphore becomes |
|
310 |
unsignalled. Only the thread that owns a fast semaphore can wait on it. |
|
311 |
||
312 |
Note that this function does not block, it merely updates the NThread state, |
|
313 |
rescheduling will only occur when the kernel is unlocked. Generally threads |
|
314 |
would use NKern::FSWait() which manipulates the kernel lock for you. |
|
315 |
||
316 |
@pre The calling thread must own the semaphore. |
|
317 |
@pre No fast mutex can be held. |
|
318 |
@pre Kernel must be locked. |
|
319 |
||
320 |
@post Kernel is locked. |
|
321 |
||
322 |
@see NFastSemaphore::Signal() |
|
323 |
@see NKern::FSWait() |
|
324 |
@see NKern::Unlock() |
|
325 |
*/ |
|
326 |
EXPORT_C __NAKED__ void NFastSemaphore::Wait() |
|
327 |
{ |
|
328 |
ASM_DEBUG1(FSWait,r0); |
|
329 |
||
330 |
GET_RWNO_TID(,r1); |
|
331 |
asm("stmfd sp!, {r4-r7} "); |
|
332 |
asm("ldr r6, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
333 |
asm("mov r3, r0 "); |
|
334 |
asm("mov r2, #%a0" : : "i" ((TInt)NThreadBase::EWaitFastSemaphore << 8)); |
|
335 |
asm("add r7, r6, #%a0" : : "i" _FOFF(NThreadBase, iWaitState)); |
|
336 |
asm("orr r2, r2, #%a0" : : "i" ((TInt)NThreadWaitState::EWtStWaitPending)); |
|
337 |
asm("1: "); |
|
338 |
LDREXD( 4,7); |
|
339 |
STREXD( 12,2,7); |
|
340 |
asm("cmp r12, #0 "); |
|
341 |
asm("bne 1b "); |
|
342 |
asm("str r12, [r7, #%a0]" : : "i" _FOFF(NThreadWaitState, iTimer.iTriggerTime)); |
|
343 |
asm("cmp r4, #0 "); |
|
344 |
asm("bne 0f "); |
|
345 |
||
346 |
__DATA_MEMORY_BARRIER__(r12); |
|
347 |
asm("1: "); |
|
348 |
LDREX( 2,0); // count |
|
349 |
asm("mov r5, r6, lsr #2 "); // thread>>2 |
|
350 |
asm("orr r5, r5, #0x80000000 "); |
|
351 |
asm("subs r4, r2, #1 "); |
|
352 |
asm("movlt r4, r5 "); // if --count<0, r4=(thread>>2)|0x80000000 |
|
353 |
STREX( 12,4,0); |
|
354 |
asm("teq r12, #0 "); |
|
355 |
asm("bne 1b "); |
|
356 |
__DATA_MEMORY_BARRIER__(r12); |
|
357 |
||
358 |
asm("cmp r2, #0 "); // original count zero ? |
|
359 |
asm("bne 2f "); // if yes, don't need to wait |
|
360 |
asm("mov r2, #1 "); |
|
361 |
asm("strb r2, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iRescheduleNeededFlag)); // else we need to reschedule |
|
362 |
asm("ldmfd sp!, {r4-r7} "); |
|
363 |
__JUMP(, lr); |
|
364 |
||
365 |
asm("2: "); |
|
366 |
asm("mov r2, #0 "); |
|
367 |
asm("mov r3, #0 "); |
|
368 |
asm("1: "); |
|
369 |
LDREXD( 4,7); |
|
370 |
STREXD( 12,2,7); |
|
371 |
asm("cmp r12, #0 "); |
|
372 |
asm("bne 1b "); |
|
373 |
asm("tst r4, #%a0" : : "i" ((TInt)(NThreadWaitState::EWtStDead|NThreadWaitState::EWtStWaitActive))); |
|
374 |
asm("bne 0f "); |
|
375 |
asm("ldmfd sp!, {r4-r7} "); |
|
376 |
__JUMP(, lr); |
|
377 |
||
378 |
asm("0: "); |
|
379 |
__ASM_CRASH(); |
|
380 |
} |
|
381 |
||
382 |
||
383 |
/** Waits on a fast semaphore. |
|
384 |
||
385 |
Decrements the signal count for the semaphore |
|
386 |
and waits for a signal if the semaphore becomes unsignalled. Only the |
|
387 |
thread that owns a fast semaphore can wait on it. |
|
388 |
||
389 |
@param aSem The semaphore to wait on. |
|
390 |
||
391 |
@pre The calling thread must own the semaphore. |
|
392 |
@pre No fast mutex can be held. |
|
393 |
||
394 |
@see NFastSemaphore::Wait() |
|
395 |
*/ |
|
396 |
EXPORT_C __NAKED__ void NKern::FSWait(NFastSemaphore* /*aSem*/) |
|
397 |
{ |
|
398 |
ASM_DEBUG1(NKFSWait,r0); |
|
399 |
||
400 |
__ASM_CLI(); // all interrupts off |
|
401 |
GET_RWNO_TID(,r1); |
|
402 |
asm("stmfd sp!, {r4,r5,r11,lr} "); |
|
403 |
asm("ldr r11, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
404 |
asm("mov r2, #%a0" : : "i" ((TInt)NThreadBase::EWaitFastSemaphore << 8)); |
|
405 |
asm("orr r2, r2, #%a0" : : "i" ((TInt)NThreadWaitState::EWtStWaitPending)); |
|
406 |
asm("mov r3, r0 "); |
|
407 |
asm("add r0, r11, #%a0" : : "i" _FOFF(NThreadBase, iWaitState)); |
|
408 |
asm("b nkfswait1 "); |
|
409 |
} |
|
410 |
||
411 |
||
412 |
/** Waits for a signal on the current thread's I/O semaphore. |
|
413 |
||
414 |
@pre No fast mutex can be held. |
|
415 |
@pre Call in a thread context. |
|
416 |
@pre Kernel must be unlocked |
|
417 |
@pre interrupts enabled |
|
418 |
*/ |
|
419 |
EXPORT_C __NAKED__ void NKern::WaitForAnyRequest() |
|
420 |
{ |
|
421 |
ASM_DEBUG0(WFAR); |
|
422 |
||
423 |
__ASM_CLI(); // all interrupts off |
|
424 |
GET_RWNO_TID(,r1); |
|
425 |
asm("stmfd sp!, {r4,r5,r11,lr} "); |
|
426 |
asm("ldr r11, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
427 |
asm("mov r2, #%a0" : : "i" ((TInt)NThreadBase::EWaitFastSemaphore << 8)); |
|
428 |
asm("orr r2, r2, #%a0" : : "i" ((TInt)NThreadWaitState::EWtStWaitPending)); |
|
429 |
asm("add r0, r11, #%a0" : : "i" _FOFF(NThreadBase, iWaitState)); |
|
430 |
asm("add r3, r11, #%a0" : : "i" _FOFF(NThreadBase, iRequestSemaphore)); |
|
431 |
||
432 |
asm("nkfswait1: "); |
|
433 |
asm("1: "); |
|
434 |
LDREXD( 4,0); |
|
435 |
STREXD( 12,2,0); |
|
436 |
asm("cmp r12, #0 "); |
|
437 |
asm("bne 1b "); |
|
438 |
asm("str r12, [r0, #%a0]" : : "i" _FOFF(NThreadWaitState, iTimer.iTriggerTime)); |
|
439 |
asm("cmp r4, #0 "); |
|
440 |
asm("bne 0f "); |
|
441 |
||
442 |
__DATA_MEMORY_BARRIER__(r12); |
|
443 |
asm("1: "); |
|
444 |
LDREX( 2,3); // count |
|
445 |
asm("mov r5, r11, lsr #2 "); // thread>>2 |
|
446 |
asm("orr r5, r5, #0x80000000 "); |
|
447 |
asm("subs r4, r2, #1 "); |
|
448 |
asm("movlt r4, r5 "); // if --count<0, r4=(thread>>2)|0x80000000 |
|
449 |
STREX( 12,4,3); |
|
450 |
asm("teq r12, #0 "); |
|
451 |
asm("bne 1b "); |
|
452 |
__DATA_MEMORY_BARRIER__(r12); |
|
453 |
||
454 |
asm("cmp r2, #0 "); // original count zero ? |
|
455 |
asm("beq 2f "); // if so we must wait |
|
456 |
asm("mov r2, #0 "); |
|
457 |
asm("mov r3, #0 "); |
|
458 |
asm("1: "); |
|
459 |
LDREXD( 4,0); |
|
460 |
STREXD( 12,2,0); |
|
461 |
asm("cmp r12, #0 "); |
|
462 |
asm("bne 1b "); |
|
463 |
asm("tst r4, #%a0" : : "i" ((TInt)(NThreadWaitState::EWtStDead|NThreadWaitState::EWtStWaitActive))); |
|
464 |
asm("bne 0f "); |
|
465 |
__ASM_STI(); |
|
466 |
__POPRET("r4,r5,r11,"); |
|
467 |
||
468 |
asm("0: "); |
|
469 |
__ASM_CRASH(); |
|
470 |
||
471 |
asm("2: "); |
|
472 |
asm("ldmfd sp!, {r4-r5} "); |
|
473 |
asm("mov r2, #1 "); |
|
474 |
asm("str r2, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iKernLockCount)); // else lock the kernel |
|
475 |
__ASM_STI(); |
|
476 |
asm("strb r2, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iRescheduleNeededFlag)); // and set the reschedule flag |
|
477 |
asm("stmfd sp!, {r0,r4-r10} "); |
|
478 |
asm("bl " CSM_ZN10TScheduler10RescheduleEv ); // reschedule |
|
479 |
asm(".global nkern_wfar_resched_return "); |
|
480 |
asm("nkern_wfar_resched_return: "); |
|
481 |
||
482 |
// need to send any outstanding reschedule IPIs |
|
483 |
asm("cmp r12, #0 "); |
|
484 |
asm("blne " CSM_CFUNC(send_accumulated_resched_ipis)); |
|
485 |
__ASM_STI(); |
|
486 |
__POPRET("r0,r4-r11,"); |
|
487 |
||
488 |
asm(".global wait_for_any_request "); |
|
489 |
asm("wait_for_any_request: "); |
|
490 |
asm("add r3, r9, #%a0" : : "i" _FOFF(NThreadBase,iRequestSemaphore)); |
|
491 |
asm("mov r2, #%a0" : : "i" ((TInt)NThreadBase::EWaitFastSemaphore << 8)); |
|
492 |
asm("add r7, r9, #%a0" : : "i" _FOFF(NThreadBase, iWaitState)); |
|
493 |
asm("orr r2, r2, #%a0" : : "i" ((TInt)NThreadWaitState::EWtStWaitPending)); |
|
494 |
asm("1: "); |
|
495 |
LDREXD( 4,7); |
|
496 |
STREXD( 12,2,7); |
|
497 |
asm("cmp r12, #0 "); |
|
498 |
asm("bne 1b "); |
|
499 |
asm("str r12, [r7, #%a0]" : : "i" _FOFF(NThreadWaitState, iTimer.iTriggerTime)); |
|
500 |
asm("cmp r4, #0 "); |
|
501 |
asm("bne 0b "); |
|
502 |
||
503 |
__DATA_MEMORY_BARRIER__(r12); |
|
504 |
asm("1: "); |
|
505 |
LDREX( 0,3); // count |
|
506 |
asm("mov r5, r9, lsr #2 "); // thread>>2 |
|
507 |
asm("orr r5, r5, #0x80000000 "); |
|
508 |
asm("subs r4, r0, #1 "); |
|
509 |
asm("movlt r4, r5 "); // if --count<0, r4=(thread>>2)|0x80000000 |
|
510 |
STREX( 12,4,3); |
|
511 |
asm("teq r12, #0 "); |
|
512 |
asm("bne 1b "); |
|
513 |
__DATA_MEMORY_BARRIER__(r12); |
|
514 |
#ifdef __RECORD_STATE__ |
|
515 |
asm("str r0, [r9, #%a0]" : : "i" _FOFF(NThreadBase,iNThreadBaseSpare6)); |
|
516 |
#endif |
|
517 |
||
518 |
asm("cmp r0, #0 "); // original count zero ? |
|
519 |
asm("beq exec_wfar_wait "); // yes - must wait |
|
520 |
asm("mov r2, #0 "); |
|
521 |
asm("mov r3, #0 "); |
|
522 |
asm("1: "); |
|
523 |
LDREXD( 4,7); |
|
524 |
STREXD( 12,2,7); |
|
525 |
asm("cmp r12, #0 "); |
|
526 |
asm("bne 1b "); |
|
527 |
asm("tst r4, #%a0" : : "i" ((TInt)(NThreadWaitState::EWtStDead|NThreadWaitState::EWtStWaitActive))); |
|
528 |
asm("ldreq r4, [r9, #%a0]" : : "i" _FOFF(NThreadBase,iUserModeCallbacks)); // check for callbacks |
|
529 |
asm("beq exec_wfar_finish "); |
|
530 |
asm("b 0b "); |
|
531 |
} |
|
532 |
||
533 |
||
534 |
/** Signals a fast semaphore. |
|
535 |
||
536 |
Increments the signal count of a fast semaphore by |
|
537 |
one and releases any waiting thread if the semphore becomes signalled. |
|
538 |
||
539 |
Note that a reschedule will not occur before this function returns, this will |
|
540 |
only take place when the kernel is unlocked. Generally threads |
|
541 |
would use NKern::FSSignal() which manipulates the kernel lock for you. |
|
542 |
||
543 |
@pre Kernel must be locked. |
|
544 |
@pre Call either in a thread or an IDFC context. |
|
545 |
||
546 |
@post Kernel is locked. |
|
547 |
||
548 |
@see NFastSemaphore::Wait() |
|
549 |
@see NKern::FSSignal() |
|
550 |
@see NKern::Unlock() |
|
551 |
*/ |
|
552 |
EXPORT_C __NAKED__ void NFastSemaphore::Signal() |
|
553 |
{ |
|
554 |
ASM_DEBUG1(FSSignal,r0); |
|
555 |
||
556 |
asm("mov r1, #1 "); |
|
557 |
asm("fssignal1: "); |
|
558 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
559 |
asm("1: "); |
|
560 |
LDREX( 2,0); // count |
|
561 |
asm("cmp r2, #0 "); |
|
562 |
asm("sublt r3, r1, #1 "); // if count<0, replace with aCount-1 |
|
563 |
asm("addges r3, r2, r1 "); // if count>=0, add aCount |
|
564 |
asm("bvs 0f "); // if overflow, leave alone |
|
565 |
STREX( 12,3,0); |
|
566 |
asm("teq r12, #0 "); |
|
567 |
asm("bne 1b "); |
|
568 |
asm("cmp r2, #0 "); |
|
569 |
asm("movlt r1, r2, lsl #2 "); // if original count<0 r1 = original count<<2 = thread |
|
570 |
asm("blt fs_signal_wake "); |
|
571 |
asm("0: "); |
|
572 |
__JUMP(, lr); // else finished |
|
573 |
||
574 |
asm("fs_signal_wake: "); |
|
575 |
asm("stmfd sp!, {r4-r6,lr} "); |
|
576 |
asm("mov r4, r0 "); |
|
577 |
asm("mov r5, r1 "); |
|
578 |
asm("mov r0, r1 "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
579 |
asm("bl AcqSLock__12NSchedulable "); // CSM needed |
0 | 580 |
asm("add r0, r5, #%a0" : : "i" _FOFF(NThreadBase, iWaitState)); |
581 |
asm("mov r1, #%a0" : : "i" ((TInt)NThreadBase::EWaitFastSemaphore)); |
|
582 |
asm("mov r2, r4 "); |
|
583 |
asm("mov r3, #0 "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
584 |
asm("bl UnBlockT__16NThreadWaitStateUiPvi "); // CSM needed |
0 | 585 |
asm("mov r0, r5 "); |
586 |
asm("ldmfd sp!, {r4-r6,lr} "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
587 |
asm("b RelSLock__12NSchedulable "); // CSM needed |
0 | 588 |
} |
589 |
||
590 |
||
591 |
/** Signals a fast semaphore multiple times. |
|
592 |
||
593 |
@pre Kernel must be locked. |
|
594 |
@pre Call either in a thread or an IDFC context. |
|
595 |
||
596 |
@post Kernel is locked. |
|
597 |
||
598 |
@internalComponent |
|
599 |
*/ |
|
600 |
EXPORT_C __NAKED__ void NFastSemaphore::SignalN(TInt /*aCount*/) |
|
601 |
{ |
|
602 |
ASM_DEBUG2(FSSignalN,r0,r1); |
|
603 |
||
604 |
asm("cmp r1, #0 "); |
|
605 |
asm("bgt fssignal1 "); |
|
606 |
__JUMP(, lr); |
|
607 |
} |
|
608 |
||
609 |
||
610 |
/** Signals the request semaphore of a nanothread several times. |
|
611 |
||
612 |
This function is intended to be used by the EPOC layer and personality |
|
613 |
layers. Device drivers should use Kern::RequestComplete instead. |
|
614 |
||
615 |
@param aThread Nanothread to signal. If NULL, the current thread is signaled. |
|
616 |
@param aCount Number of times the request semaphore must be signaled. |
|
617 |
||
618 |
@pre aCount >= 0 |
|
619 |
||
620 |
@see Kern::RequestComplete() |
|
621 |
*/ |
|
622 |
EXPORT_C __NAKED__ void NKern::ThreadRequestSignal(NThread* /*aThread*/, TInt /*aCount*/) |
|
623 |
{ |
|
624 |
ASM_DEBUG2(NKThreadRequestSignalN,r0,r1); |
|
625 |
||
626 |
asm("cmp r1, #0 "); |
|
627 |
asm("ble 0f "); |
|
628 |
asm("cmp r0, #0 "); |
|
629 |
asm("addne r0, r0, #%a0" : : "i" _FOFF(NThreadBase,iRequestSemaphore)); |
|
630 |
asm("bne nkfssignal1 "); |
|
631 |
__ASM_CLI(); |
|
632 |
GET_RWNO_TID(,r0); |
|
633 |
asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
634 |
asm("add r0, r0, #%a0" : : "i" _FOFF(NThreadBase,iRequestSemaphore)); |
|
635 |
asm("b nkfssignal2 "); |
|
636 |
||
637 |
asm("0: "); |
|
638 |
__JUMP(eq, lr); |
|
639 |
__ASM_CRASH(); |
|
640 |
} |
|
641 |
||
642 |
||
643 |
/** Signals the request semaphore of a nanothread. |
|
644 |
||
645 |
This function is intended to be used by the EPOC layer and personality |
|
646 |
layers. Device drivers should use Kern::RequestComplete instead. |
|
647 |
||
648 |
@param aThread Nanothread to signal. Must be non NULL. |
|
649 |
||
650 |
@see Kern::RequestComplete() |
|
651 |
||
652 |
@pre Interrupts must be enabled. |
|
653 |
@pre Do not call from an ISR |
|
654 |
*/ |
|
655 |
EXPORT_C __NAKED__ void NKern::ThreadRequestSignal(NThread* /*aThread*/) |
|
656 |
{ |
|
657 |
ASM_DEBUG1(NKThreadRequestSignal,r0); |
|
658 |
asm("add r0, r0, #%a0" : : "i" _FOFF(NThreadBase,iRequestSemaphore)); |
|
659 |
||
660 |
/* fall through to FSSignal() ... */ |
|
661 |
} |
|
662 |
||
663 |
||
664 |
/** Signals a fast semaphore. |
|
665 |
||
666 |
Increments the signal count of a fast semaphore |
|
667 |
by one and releases any waiting thread if the semaphore becomes signalled. |
|
668 |
||
669 |
@param aSem The semaphore to signal. |
|
670 |
||
671 |
@see NKern::FSWait() |
|
672 |
||
673 |
@pre Interrupts must be enabled. |
|
674 |
@pre Do not call from an ISR |
|
675 |
*/ |
|
676 |
EXPORT_C __NAKED__ void NKern::FSSignal(NFastSemaphore* /*aSem*/) |
|
677 |
{ |
|
678 |
ASM_DEBUG1(NKFSSignal,r0); |
|
679 |
||
680 |
asm("mov r1, #1 "); |
|
681 |
asm("nkfssignal1: "); |
|
682 |
__ASM_CLI(); |
|
683 |
asm("nkfssignal2: "); |
|
684 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
685 |
asm("1: "); |
|
686 |
LDREX( 2,0); // count |
|
687 |
asm("cmp r2, #0 "); |
|
688 |
asm("sublt r3, r1, #1 "); // if count<0, replace with aCount-1 |
|
689 |
asm("addges r3, r2, r1 "); // if count>=0, add aCount |
|
690 |
asm("bvs 0f "); // if overflow, leave alone |
|
691 |
STREX( 12,3,0); |
|
692 |
asm("teq r12, #0 "); |
|
693 |
asm("bne 1b "); |
|
694 |
asm("cmp r2, #0 "); |
|
695 |
asm("blt 2f "); |
|
696 |
asm("0: "); |
|
697 |
__ASM_STI(); |
|
698 |
__JUMP(, lr); // else finished |
|
699 |
||
700 |
asm("2: "); |
|
701 |
GET_RWNO_TID(,r3); |
|
702 |
asm("mov r1, r2, lsl #2 "); // if original count<0 r1 = original count<<2 = thread |
|
703 |
asm("ldr r12, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iKernLockCount)); |
|
704 |
asm("stmfd sp!, {r4,lr} "); |
|
705 |
asm("add r12, r12, #1 "); // lock the kernel |
|
706 |
asm("str r12, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iKernLockCount)); |
|
707 |
__ASM_STI(); |
|
708 |
asm("bl fs_signal_wake "); // wake up the thread |
|
709 |
asm("ldmfd sp!, {r4,lr} "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
710 |
asm("b " CSM_ZN5NKern6UnlockEv); |
0 | 711 |
} |
712 |
||
713 |
||
714 |
/** Signals a fast semaphore multiple times. |
|
715 |
||
716 |
Increments the signal count of a |
|
717 |
fast semaphore by aCount and releases any waiting thread if the semphore |
|
718 |
becomes signalled. |
|
719 |
||
720 |
@param aSem The semaphore to signal. |
|
721 |
@param aCount The number of times to signal the semaphore. |
|
722 |
||
723 |
@see NKern::FSWait() |
|
724 |
||
725 |
@pre Interrupts must be enabled. |
|
726 |
@pre Do not call from an ISR |
|
727 |
*/ |
|
728 |
EXPORT_C __NAKED__ void NKern::FSSignalN(NFastSemaphore* /*aSem*/, TInt /*aCount*/) |
|
729 |
{ |
|
730 |
ASM_DEBUG2(NKFSSignalN,r0,r1); |
|
731 |
||
732 |
asm("cmp r1, #0 "); |
|
733 |
asm("bgt nkfssignal1 "); |
|
734 |
__JUMP(, lr); |
|
735 |
} |
|
736 |
||
737 |
||
738 |
/** Cancels a wait on a fast semaphore. |
|
739 |
||
740 |
@pre Kernel must be locked. |
|
741 |
@pre Call either in a thread or an IDFC context. |
|
742 |
||
743 |
@post Kernel is locked. |
|
744 |
||
745 |
@internalComponent |
|
746 |
*/ |
|
747 |
__NAKED__ void NFastSemaphore::WaitCancel() |
|
748 |
{ |
|
749 |
asm("mov r1, #1 "); |
|
750 |
/* Fall through ... */ |
|
751 |
} |
|
752 |
||
753 |
/* Fall through ... */ |
|
754 |
#endif |
|
755 |
/* Fall through ... */ |
|
756 |
||
757 |
/** Increment a fast semaphore count |
|
758 |
||
759 |
Do memory barrier |
|
760 |
If iCount >= 0, increment by aCount and return 0 |
|
761 |
If iCount < 0, set count equal to aCount-1 and return (original count << 2) |
|
762 |
||
763 |
Release semantics |
|
764 |
*/ |
|
765 |
__NAKED__ NThreadBase* NFastSemaphore::Inc(TInt /*aCount*/) |
|
766 |
{ |
|
767 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
768 |
asm("1: "); |
|
769 |
LDREX(2,0); // count |
|
770 |
asm("cmp r2, #0 "); |
|
771 |
asm("sublt r3, r1, #1 "); // if count<0, replace with aCount-1 |
|
772 |
asm("addges r3, r2, r1 "); // if count>=0, add aCount |
|
773 |
asm("bvs 0f "); // if overflow leave alone |
|
774 |
STREX(12,3,0); |
|
775 |
asm("teq r12, #0 "); |
|
776 |
asm("bne 1b "); |
|
777 |
asm("0: "); |
|
778 |
asm("cmp r2, #0 "); |
|
779 |
asm("movlt r0, r2, lsl #2 "); // if original count<0, return count<<2 |
|
780 |
asm("movge r0, #0 "); // else return 0 |
|
781 |
__JUMP(,lr); |
|
782 |
} |
|
783 |
||
784 |
||
785 |
/** Decrement a fast semaphore count |
|
786 |
||
787 |
If count > 0, decrement |
|
788 |
If count = 0, set equal to (thread>>2)|0x80000000 |
|
789 |
Return original count |
|
790 |
Full barrier semantics |
|
791 |
*/ |
|
792 |
__NAKED__ TInt NFastSemaphore::Dec(NThreadBase*) |
|
793 |
{ |
|
794 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
795 |
asm("1: "); |
|
796 |
LDREX(2,0); // count |
|
797 |
asm("subs r3, r2, #1 "); |
|
798 |
asm("movlt r3, #0x80000000 "); |
|
799 |
asm("orrlt r3, r3, r1, lsr #2 "); // if --count<0, r3=(thread>>2)|0x80000000 |
|
800 |
STREX(12,3,0); |
|
801 |
asm("teq r12, #0 "); |
|
802 |
asm("bne 1b "); |
|
803 |
__DATA_MEMORY_BARRIER__(r12); |
|
804 |
asm("mov r0, r2 "); // return original count |
|
805 |
__JUMP(,lr); |
|
806 |
} |
|
807 |
||
808 |
/** Reset a fast semaphore count |
|
809 |
||
810 |
Do memory barrier |
|
811 |
If iCount >= 0, set iCount=0 and return 0 |
|
812 |
If iCount < 0, set iCount=0 and return (original count << 2) |
|
813 |
||
814 |
Release semantics |
|
815 |
*/ |
|
816 |
__NAKED__ NThreadBase* NFastSemaphore::DoReset() |
|
817 |
{ |
|
818 |
__DATA_MEMORY_BARRIER_Z__(r3); |
|
819 |
asm("1: "); |
|
820 |
LDREX(2,0); // count |
|
821 |
STREX(12,3,0); // zero count |
|
822 |
asm("teq r12, #0 "); |
|
823 |
asm("bne 1b "); |
|
824 |
asm("cmp r2, #0 "); |
|
825 |
asm("movlt r0, r2, lsl #2 "); // if original count<0, return count<<2 |
|
826 |
asm("movge r0, #0 "); // else return 0 |
|
827 |
__JUMP(,lr); |
|
828 |
} |
|
829 |
||
830 |
||
831 |
#ifdef __NTHREAD_WAITSTATE_MACHINE_CODED__ |
|
832 |
/****************************************************************************** |
|
833 |
* Thread wait state |
|
834 |
******************************************************************************/ |
|
835 |
||
836 |
__NAKED__ void NThreadWaitState::SetUpWait(TUint /*aType*/, TUint /*aFlags*/, TAny* /*aWaitObj*/) |
|
837 |
{ |
|
838 |
asm("stmfd sp!, {r4-r5} "); |
|
839 |
asm("and r2, r2, #%a0" : : "i" ((TInt)EWtStObstructed)); |
|
840 |
asm("and r1, r1, #0xff "); |
|
841 |
asm("orr r2, r2, #%a0" : : "i" ((TInt)EWtStWaitPending)); |
|
842 |
asm("orr r2, r2, r1, lsl #8 "); |
|
843 |
asm("1: "); |
|
844 |
LDREXD( 4,0); |
|
845 |
STREXD( 12,2,0); |
|
846 |
asm("cmp r12, #0 "); |
|
847 |
asm("bne 1b "); |
|
848 |
asm("cmp r4, #0 "); |
|
849 |
asm("bne 0f "); |
|
850 |
asm("ldmfd sp!, {r4-r5} "); |
|
851 |
asm("str r12, [r0, #%a0]" : : "i" _FOFF(NThreadWaitState, iTimer.iTriggerTime)); |
|
852 |
__JUMP(, lr); |
|
853 |
||
854 |
asm("0: "); |
|
855 |
__ASM_CRASH(); |
|
856 |
} |
|
857 |
||
858 |
__NAKED__ void NThreadWaitState::SetUpWait(TUint /*aType*/, TUint /*aFlags*/, TAny* /*aWaitObj*/, TUint32 /*aTimeout*/) |
|
859 |
{ |
|
860 |
asm("stmfd sp!, {r4-r5} "); |
|
861 |
asm("and r2, r2, #%a0" : : "i" ((TInt)EWtStObstructed)); |
|
862 |
asm("and r1, r1, #0xff "); |
|
863 |
asm("orr r2, r2, #%a0" : : "i" ((TInt)EWtStWaitPending)); |
|
864 |
asm("orr r2, r2, r1, lsl #8 "); |
|
865 |
asm("1: "); |
|
866 |
LDREXD( 4,0); |
|
867 |
STREXD( 12,2,0); |
|
868 |
asm("cmp r12, #0 "); |
|
869 |
asm("bne 1b "); |
|
870 |
asm("ldr r12, [sp, #8] "); |
|
871 |
asm("cmp r4, #0 "); |
|
872 |
asm("bne 0f "); |
|
873 |
asm("ldmfd sp!, {r4-r5} "); |
|
874 |
asm("str r12, [r0, #%a0]" : : "i" _FOFF(NThreadWaitState, iTimer.iTriggerTime)); |
|
875 |
__JUMP(, lr); |
|
876 |
||
877 |
asm("0: "); |
|
878 |
__ASM_CRASH(); |
|
879 |
} |
|
880 |
||
881 |
__NAKED__ void NThreadWaitState::CancelWait() |
|
882 |
{ |
|
883 |
asm("mov r12, r0 "); |
|
884 |
asm("mov r2, #0 "); |
|
885 |
asm("mov r3, #0 "); |
|
886 |
asm("1: "); |
|
887 |
LDREXD( 0,12); |
|
888 |
STREXD( 1,2,12); |
|
889 |
asm("cmp r1, #0 "); |
|
890 |
asm("bne 1b "); |
|
891 |
asm("tst r0, #%a0" : : "i" ((TInt)(EWtStDead|EWtStWaitActive))); |
|
892 |
asm("bne 0f "); |
|
893 |
__JUMP(, lr); |
|
894 |
||
895 |
asm("0: "); |
|
896 |
__ASM_CRASH(); |
|
897 |
} |
|
898 |
||
899 |
__NAKED__ TInt NThreadWaitState::DoWait() |
|
900 |
{ |
|
901 |
asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(NThreadWaitState,iTimer.iTriggerTime)); |
|
902 |
asm("1: "); |
|
903 |
LDREXD( 2,0); |
|
904 |
asm("cmp r1, #0 "); |
|
905 |
asm("orrne r2, r2, #%a0" : : "i" ((TInt)EWtStTimeout)); |
|
906 |
asm("tst r2, #%a0" : : "i" ((TInt)EWtStDead)); |
|
907 |
asm("bne 0f "); |
|
908 |
asm("tst r2, #%a0" : : "i" ((TInt)EWtStWaitPending)); |
|
909 |
asm("beq 9f "); |
|
910 |
asm("bic r2, r2, #%a0" : : "i" ((TInt)EWtStWaitPending)); |
|
911 |
asm("orr r2, r2, #%a0" : : "i" ((TInt)EWtStWaitActive)); |
|
912 |
STREXD( 12,2,0); |
|
913 |
asm("cmp r12, #0 "); |
|
914 |
asm("bne 1b "); |
|
915 |
asm("cmp r1, #0 "); |
|
916 |
asm("bne 2f "); |
|
917 |
asm("mov r0, r2, lsr #8 "); |
|
918 |
__JUMP(, lr); |
|
919 |
||
920 |
asm("2: "); |
|
921 |
asm("stmfd sp!, {r2-r4,lr} "); |
|
922 |
asm("mov r4, r0 "); |
|
923 |
asm("add r0, r0, #%a0" : : "i" _FOFF(NThreadWaitState,iTimer)); |
|
924 |
asm("mov r2, #1 "); |
|
925 |
asm("bl " CSM_ZN6NTimer7OneShotEii ); |
|
926 |
asm("ldr r1, [r4, #%a0]" : : "i" _FOFF(NThreadWaitState,iTimer.iNTimerSpare1)); |
|
927 |
asm("cmp r0, #0 "); |
|
928 |
asm("bne 8f "); |
|
929 |
asm("add r1, r1, #1 "); |
|
930 |
asm("str r1, [r4, #%a0]" : : "i" _FOFF(NThreadWaitState,iTimer.iNTimerSpare1)); |
|
931 |
asm("ldmfd sp!, {r2-r4,lr} "); |
|
932 |
asm("mov r0, r2, lsr #8 "); |
|
933 |
__JUMP(, lr); |
|
934 |
||
935 |
asm("0: "); |
|
936 |
asm("mvn r0, #%a0" : : "i" (~KErrDied)); |
|
937 |
__JUMP(, lr); |
|
938 |
asm("9: "); |
|
939 |
asm("mvn r0, #%a0" : : "i" (~KErrGeneral)); |
|
940 |
__JUMP(, lr); |
|
941 |
asm("8: "); |
|
942 |
__ASM_CRASH(); |
|
943 |
} |
|
944 |
||
945 |
__NAKED__ TInt NThreadWaitState::UnBlockT(TUint /*aType*/, TAny* /*aWaitObj*/, TInt /*aReturnValue*/) |
|
946 |
{ |
|
947 |
asm("stmfd sp!, {r4-r6,lr} "); |
|
948 |
asm("mov r6, r2 "); // r6 = aWaitObj |
|
949 |
asm("mov r2, #0 "); |
|
950 |
__DATA_MEMORY_BARRIER__(r2); |
|
951 |
asm("1: "); |
|
952 |
LDREXD( 4,0); // r5:r4 = oldws64 |
|
953 |
asm("cmp r5, r6 "); // does iWaitObj match? |
|
954 |
asm("bne 2f "); // no |
|
955 |
asm("eor r12, r4, r1, lsl #8 "); // does wait type match? |
|
956 |
asm("cmp r12, #%a0" : : "i" ((TInt)EWtStDead)); |
|
957 |
asm("bhs 2f "); // no |
|
958 |
STREXD( 12,2,0); // yes - wait matches - try to write return value |
|
959 |
asm("cmp r12, #0 "); // success? |
|
960 |
asm("bne 1b "); // no - retry |
|
961 |
asm("mov r6, r0 "); |
|
962 |
asm("tst r4, #%a0" : : "i" ((TInt)EWtStTimeout)); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
963 |
asm("blne CancelTimerT__16NThreadWaitState "); // CSM needed |
0 | 964 |
asm("tst r4, #%a0" : : "i" ((TInt)EWtStWaitActive)); |
965 |
asm("beq 0f "); |
|
966 |
asm("ldr r1, [r6, #%a0]" : : "i" (_FOFF(NThreadBase,iPauseCount)-_FOFF(NThreadBase,iWaitState))); |
|
967 |
asm("sub r0, r6, #%a0" : : "i" _FOFF(NThreadBase,iWaitState)); // r0 = Thread() |
|
968 |
asm("movs r1, r1, lsl #16 "); // check if iPauseCount=iSuspendCount=0 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
969 |
asm("andeq r1, r4, #%a0" : : "i" ((TInt)EWtStObstructed)); |
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
970 |
asm("bleq ReadyT__12NSchedulableUi "); // if so, make thread ready // CSM needed |
0 | 971 |
asm("0: "); |
972 |
asm("mov r0, #0 "); |
|
973 |
__POPRET(" r4-r6,"); // return KErrNone |
|
974 |
||
975 |
asm("2: "); |
|
976 |
STREXD( 12,4,0); // no matching wait - write back to check atomicity |
|
977 |
asm("cmp r12, #0 "); // success? |
|
978 |
asm("bne 1b "); // no - retry |
|
979 |
asm("mvn r0, #%a0" : : "i" (~KErrGeneral)); |
|
980 |
__POPRET(" r4-r6,"); // no matching wait - return KErrGeneral |
|
981 |
} |
|
982 |
||
983 |
__NAKED__ TUint32 NThreadWaitState::ReleaseT(TAny*& /*aWaitObj*/, TInt /*aReturnValue*/) |
|
984 |
{ |
|
985 |
asm("stmfd sp!, {r4-r5} "); |
|
986 |
asm("mov r3, r2 "); |
|
987 |
asm("mov r2, #0 "); |
|
988 |
__DATA_MEMORY_BARRIER__(r2); |
|
989 |
asm("1: "); |
|
990 |
LDREXD( 4,0); |
|
991 |
asm("and r2, r4, #%a0" : : "i" ((TInt)EWtStDead)); |
|
992 |
STREXD( 12,2,0); |
|
993 |
asm("cmp r12, #0 "); |
|
994 |
asm("bne 1b "); |
|
995 |
__DATA_MEMORY_BARRIER__(r12); |
|
996 |
asm("str r5, [r1] "); |
|
997 |
asm("tst r4, #%a0" : : "i" ((TInt)EWtStTimeout)); |
|
998 |
asm("bne 2f "); |
|
999 |
asm("mov r0, r4 "); |
|
1000 |
asm("ldmfd sp!, {r4-r5} "); |
|
1001 |
__JUMP(, lr); |
|
1002 |
||
1003 |
asm("2: "); |
|
1004 |
asm("mov r5, lr "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1005 |
asm("bl CancelTimerT__16NThreadWaitState "); // CSM needed |
0 | 1006 |
asm("mov r0, r4 "); |
1007 |
asm("mov lr, r5 "); |
|
1008 |
asm("ldmfd sp!, {r4-r5} "); |
|
1009 |
__JUMP(, lr); |
|
1010 |
} |
|
1011 |
#endif |
|
1012 |
||
1013 |
||
1014 |
#ifdef __FAST_MUTEX_MACHINE_CODED__ |
|
1015 |
/****************************************************************************** |
|
1016 |
* Fast mutex |
|
1017 |
******************************************************************************/ |
|
1018 |
||
1019 |
/** Releases a previously acquired fast mutex. |
|
1020 |
||
1021 |
Generally, threads would use NKern::FMSignal() which manipulates the kernel lock |
|
1022 |
for you. |
|
1023 |
||
1024 |
@pre The calling thread holds the mutex. |
|
1025 |
@pre Kernel must be locked. |
|
1026 |
||
1027 |
@post Kernel is locked. |
|
1028 |
||
1029 |
@see NFastMutex::Wait() |
|
1030 |
@see NKern::FMSignal() |
|
1031 |
*/ |
|
1032 |
EXPORT_C __NAKED__ void NFastMutex::Signal() |
|
1033 |
{ |
|
1034 |
ASM_DEBUG1(FMSignal,r0); |
|
1035 |
#ifdef BTRACE_FAST_MUTEX |
|
1036 |
// BTraceContext4(BTrace::EFastMutex, BTrace::EFastMutexSignal, this); |
|
1037 |
asm("stmfd sp!, {r0,lr} "); |
|
1038 |
asm("mov r1, r0 "); |
|
1039 |
asm("ldr r0, btrace_hdr_fmsignal "); |
|
1040 |
asm("mov r2, #0 "); |
|
1041 |
asm("mov r3, #0 "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1042 |
asm("bl " CSM_ZN6BTrace4OutXEmmmm); |
0 | 1043 |
asm("ldmfd sp!, {r0,lr} "); |
1044 |
#endif |
|
1045 |
GET_RWNO_TID(,r3); |
|
1046 |
asm("mov r12, #0 "); |
|
1047 |
__DATA_MEMORY_BARRIER__(r12); |
|
1048 |
asm("ldr r1, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
1049 |
__ASM_CLI(); |
|
1050 |
asm("1: "); |
|
1051 |
LDREX( 2,0); // r2=aMutex->iHoldingThread |
|
1052 |
asm("cmp r2, r1 "); // anyone else waiting? |
|
1053 |
asm("mov r2, #0 "); |
|
1054 |
asm("bne 2f "); // branch out if someone else waiting |
|
1055 |
STREX( 12,2,0); // else try to clear the holding thread |
|
1056 |
asm("teq r12, #0 "); |
|
1057 |
asm("bne 1b "); |
|
1058 |
asm("str r12, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1059 |
__ASM_STI(); |
|
1060 |
__JUMP(,lr); // mutex released without contention |
|
1061 |
||
1062 |
#ifdef BTRACE_FAST_MUTEX |
|
1063 |
asm("btrace_hdr_fmsignal: "); |
|
1064 |
asm(".word %a0" : : "i" (BTRACE_HEADER_C(8,BTrace::EFastMutex,BTrace::EFastMutexSignal))); |
|
1065 |
#endif |
|
1066 |
||
1067 |
// there is contention |
|
1068 |
asm("2: "); |
|
1069 |
asm("orr r12, r0, #1 "); |
|
1070 |
asm("str r12, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1071 |
__ASM_STI(); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1072 |
asm("b DoSignalL__10NFastMutex "); // CSM needed |
0 | 1073 |
} |
1074 |
||
1075 |
||
1076 |
/** Acquires the System Lock. |
|
1077 |
||
1078 |
This will block until the mutex is available, and causes |
|
1079 |
the thread to enter an implicit critical section until the mutex is released. |
|
1080 |
||
1081 |
@post System lock is held. |
|
1082 |
||
1083 |
@see NKern::UnlockSystem() |
|
1084 |
@see NKern::FMWait() |
|
1085 |
||
1086 |
@pre No fast mutex can be held. |
|
1087 |
@pre Call in a thread context. |
|
1088 |
@pre Kernel must be unlocked |
|
1089 |
@pre interrupts enabled |
|
1090 |
||
1091 |
*/ |
|
1092 |
EXPORT_C __NAKED__ void NKern::LockSystem() |
|
1093 |
{ |
|
1094 |
asm("ldr r0, __SystemLock "); |
|
1095 |
||
1096 |
/* fall through to FMWait() ... */ |
|
1097 |
} |
|
1098 |
||
1099 |
/** Acquires a fast mutex. |
|
1100 |
||
1101 |
This will block until the mutex is available, and causes |
|
1102 |
the thread to enter an implicit critical section until the mutex is released. |
|
1103 |
||
1104 |
@param aMutex The fast mutex to acquire. |
|
1105 |
||
1106 |
@post The calling thread holds the mutex. |
|
1107 |
||
1108 |
@see NFastMutex::Wait() |
|
1109 |
@see NKern::FMSignal() |
|
1110 |
||
1111 |
@pre No fast mutex can be held. |
|
1112 |
@pre Call in a thread context. |
|
1113 |
@pre Kernel must be unlocked |
|
1114 |
@pre interrupts enabled |
|
1115 |
||
1116 |
*/ |
|
1117 |
EXPORT_C __NAKED__ void NKern::FMWait(NFastMutex* /*aMutex*/) |
|
1118 |
{ |
|
1119 |
ASM_DEBUG1(NKFMWait,r0); |
|
1120 |
||
1121 |
__ASM_CLI(); |
|
1122 |
GET_RWNO_TID(,r3); |
|
1123 |
asm("ldr r1, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
1124 |
asm("1: "); |
|
1125 |
LDREX( 2,0); // r2=aMutex->iHoldingThread |
|
1126 |
asm("cmp r2, #0 "); // |
|
1127 |
asm("bne 2f "); // branch out if mutex held |
|
1128 |
STREX( 12,1,0); // else try to set us as holding thread |
|
1129 |
asm("teq r12, #0 "); |
|
1130 |
asm("bne 1b "); |
|
1131 |
asm("str r0, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1132 |
__DATA_MEMORY_BARRIER__(r12); |
|
1133 |
__ASM_STI(); |
|
1134 |
#ifdef BTRACE_FAST_MUTEX |
|
1135 |
// BTraceContext4(BTrace::EFastMutex, BTrace::EFastMutexWait, aMutex); |
|
1136 |
asm("mov r1, r0 "); |
|
1137 |
asm("ldr r0, btrace_hdr_fmwait "); |
|
1138 |
asm("mov r2, #0 "); |
|
1139 |
asm("mov r3, #0 "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1140 |
asm("b " CSM_ZN6BTrace4OutXEmmmm); |
0 | 1141 |
#endif |
1142 |
__JUMP(,lr); // mutex acquired without contention |
|
1143 |
||
1144 |
// there is contention |
|
1145 |
asm("2: "); |
|
1146 |
asm("mov r2, #1 "); |
|
1147 |
asm("str r0, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1148 |
asm("str r2, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iKernLockCount)); |
|
1149 |
__ASM_STI(); |
|
1150 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1151 |
asm("stmfd sp!, {r4,lr} "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1152 |
asm("bl DoWaitL__10NFastMutex "); // CSM needed |
0 | 1153 |
asm("ldmfd sp!, {r4,lr} "); |
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1154 |
asm("b " CSM_ZN5NKern6UnlockEv); |
0 | 1155 |
|
1156 |
asm("__SystemLock: "); |
|
1157 |
asm(".word %a0" : : "i" ((TInt)&TheScheduler.iLock)); |
|
1158 |
#ifdef BTRACE_FAST_MUTEX |
|
1159 |
asm("btrace_hdr_fmwait: "); |
|
1160 |
asm(".word %a0" : : "i" (BTRACE_HEADER_C(8,BTrace::EFastMutex,BTrace::EFastMutexWait))); |
|
1161 |
#endif |
|
1162 |
} |
|
1163 |
||
1164 |
||
1165 |
/** Releases the System Lock. |
|
1166 |
||
1167 |
@pre System lock must be held. |
|
1168 |
||
1169 |
@see NKern::LockSystem() |
|
1170 |
@see NKern::FMSignal() |
|
1171 |
*/ |
|
1172 |
EXPORT_C __NAKED__ void NKern::UnlockSystem() |
|
1173 |
{ |
|
1174 |
asm("ldr r0, __SystemLock "); |
|
1175 |
||
1176 |
/* fall through to FMSignal() ... */ |
|
1177 |
} |
|
1178 |
||
1179 |
/** Releases a previously acquired fast mutex. |
|
1180 |
||
1181 |
@param aMutex The fast mutex to release. |
|
1182 |
||
1183 |
@pre The calling thread holds the mutex. |
|
1184 |
||
1185 |
@see NFastMutex::Signal() |
|
1186 |
@see NKern::FMWait() |
|
1187 |
*/ |
|
1188 |
EXPORT_C __NAKED__ void NKern::FMSignal(NFastMutex* /*aMutex*/) |
|
1189 |
{ |
|
1190 |
ASM_DEBUG1(NKFMSignal,r0); |
|
1191 |
#ifdef BTRACE_FAST_MUTEX |
|
1192 |
// BTraceContext4(BTrace::EFastMutex, BTrace::EFastMutexSignal, this); |
|
1193 |
asm("stmfd sp!, {r0,lr} "); |
|
1194 |
asm("mov r1, r0 "); |
|
1195 |
asm("ldr r0, btrace_hdr_fmsignal "); |
|
1196 |
asm("mov r2, #0 "); |
|
1197 |
asm("mov r3, #0 "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1198 |
asm("bl " CSM_ZN6BTrace4OutXEmmmm); |
0 | 1199 |
asm("ldmfd sp!, {r0,lr} "); |
1200 |
#endif |
|
1201 |
__ASM_CLI(); |
|
1202 |
GET_RWNO_TID(,r3); |
|
1203 |
asm("mov r12, #0 "); |
|
1204 |
__DATA_MEMORY_BARRIER__(r12); |
|
1205 |
asm("ldr r1, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
1206 |
asm("1: "); |
|
1207 |
LDREX( 12,0); // r12=aMutex->iHoldingThread |
|
1208 |
asm("mov r2, #0 "); |
|
1209 |
asm("cmp r12, r1 "); // anyone else waiting? |
|
1210 |
asm("bne 2f "); // branch out if someone else waiting |
|
1211 |
STREX( 12,2,0); // else try to clear the holding thread |
|
1212 |
asm("teq r12, #0 "); |
|
1213 |
asm("bne 1b "); |
|
1214 |
asm("str r12, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1215 |
__ASM_STI(); |
|
1216 |
__JUMP(,lr); // mutex released without contention |
|
1217 |
||
1218 |
// there is contention |
|
1219 |
asm("2: "); |
|
1220 |
asm("stmfd sp!, {r4,lr} "); |
|
1221 |
asm("mov r12, #1 "); |
|
1222 |
asm("orr r4, r0, #1 "); |
|
1223 |
asm("str r12, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iKernLockCount)); |
|
1224 |
asm("str r4, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1225 |
__ASM_STI(); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1226 |
asm("bl DoSignalL__10NFastMutex "); // CSM needed |
0 | 1227 |
asm("ldmfd sp!, {r4,lr} "); |
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1228 |
asm("b " CSM_ZN5NKern6UnlockEv); |
0 | 1229 |
} |
1230 |
||
1231 |
||
1232 |
/** Temporarily releases the System Lock if there is contention. |
|
1233 |
||
1234 |
If there |
|
1235 |
is another thread attempting to acquire the System lock, the calling |
|
1236 |
thread releases the mutex and then acquires it again. |
|
1237 |
||
1238 |
This is more efficient than the equivalent code: |
|
1239 |
||
1240 |
@code |
|
1241 |
NKern::UnlockSystem(); |
|
1242 |
NKern::LockSystem(); |
|
1243 |
@endcode |
|
1244 |
||
1245 |
Note that this can only allow higher priority threads to use the System |
|
1246 |
lock as lower priority cannot cause contention on a fast mutex. |
|
1247 |
||
1248 |
@return TRUE if the system lock was relinquished, FALSE if not. |
|
1249 |
||
1250 |
@pre System lock must be held. |
|
1251 |
||
1252 |
@post System lock is held. |
|
1253 |
||
1254 |
@see NKern::LockSystem() |
|
1255 |
@see NKern::UnlockSystem() |
|
1256 |
*/ |
|
1257 |
EXPORT_C __NAKED__ TBool NKern::FlashSystem() |
|
1258 |
{ |
|
1259 |
// CHECK_PRECONDITIONS(MASK_SYSTEM_LOCKED,"NKern::FlashSystem"); |
|
1260 |
asm("ldr r0, __SystemLock "); |
|
1261 |
||
1262 |
/* fall through to FMFlash() ... */ |
|
1263 |
} |
|
1264 |
||
1265 |
/** Temporarily releases a fast mutex if there is contention. |
|
1266 |
||
1267 |
If there is another thread attempting to acquire the mutex, the calling |
|
1268 |
thread releases the mutex and then acquires it again. |
|
1269 |
||
1270 |
This is more efficient than the equivalent code: |
|
1271 |
||
1272 |
@code |
|
1273 |
NKern::FMSignal(); |
|
1274 |
NKern::FMWait(); |
|
1275 |
@endcode |
|
1276 |
||
1277 |
@return TRUE if the mutex was relinquished, FALSE if not. |
|
1278 |
||
1279 |
@pre The mutex must be held. |
|
1280 |
||
1281 |
@post The mutex is held. |
|
1282 |
*/ |
|
1283 |
EXPORT_C __NAKED__ TBool NKern::FMFlash(NFastMutex* /*aM*/) |
|
1284 |
{ |
|
1285 |
ASM_DEBUG1(NKFMFlash,r0); |
|
1286 |
__ASM_CLI(); |
|
1287 |
GET_RWNO_TID(,r3); |
|
1288 |
asm("ldr r1, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread)); |
|
1289 |
asm("ldrb r2, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iMutexPri)); |
|
1290 |
asm("ldrb r12, [r1, #%a0]" : : "i" _FOFF(NThreadBase,iBasePri)); |
|
1291 |
asm("cmp r2, r12 "); |
|
1292 |
asm("bhs 1f "); // a thread of greater or equal priority is waiting |
|
1293 |
__ASM_STI(); |
|
1294 |
#ifdef BTRACE_FAST_MUTEX |
|
1295 |
// BTraceContext4(BTrace::EFastMutex, BTrace::EFastMutexFlash, aM); |
|
1296 |
asm("mov r1, r0 "); |
|
1297 |
asm("ldr r0, btrace_hdr_fmsignal "); |
|
1298 |
asm("stmfd sp!, {r4,lr} "); |
|
1299 |
asm("mov r2, #0 "); |
|
1300 |
asm("mov r3, #0 "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1301 |
asm("bl " CSM_ZN6BTrace4OutXEmmmm); |
0 | 1302 |
asm("ldmfd sp!, {r4,lr} "); |
1303 |
#endif |
|
1304 |
asm("mov r0, #0 "); |
|
1305 |
__JUMP(,lr); // return FALSE |
|
1306 |
||
1307 |
#ifdef BTRACE_FAST_MUTEX |
|
1308 |
asm("btrace_hdr_fmflash: "); |
|
1309 |
asm(".word %a0" : : "i" (BTRACE_HEADER_C(8,BTrace::EFastMutex,BTrace::EFastMutexFlash))); |
|
1310 |
#endif |
|
1311 |
||
1312 |
asm("1: "); |
|
1313 |
asm("mov r12, #1 "); |
|
1314 |
asm("str r12, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iKernLockCount)); |
|
1315 |
__ASM_STI(); |
|
1316 |
asm("stmfd sp!, {r4,lr} "); |
|
1317 |
asm("mov r4, r0 "); |
|
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1318 |
asm("bl " CSM_ZN10NFastMutex6SignalEv); |
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1319 |
asm("bl " CSM_ZN5NKern15PreemptionPointEv); |
0 | 1320 |
asm("mov r0, r4 "); |
184
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1321 |
asm("bl " CSM_ZN10NFastMutex4WaitEv); |
0e2270015475
Identify (and sometimes fix) remaining uses of old-style GCC name mangling in cia files - Bug 3115
William Roberts <williamr@symbian.org>
parents:
90
diff
changeset
|
1322 |
asm("bl " CSM_ZN5NKern6UnlockEv); |
0 | 1323 |
asm("ldmfd sp!, {r4,lr} "); |
1324 |
asm("mov r0, #1 "); |
|
1325 |
__JUMP(,lr); // return TRUE |
|
1326 |
} |
|
1327 |
#endif |
|
1328 |
||
1329 |
||
1330 |
||
1331 |
/** Check whether a thread holds a fast mutex. |
|
1332 |
If so set the mutex contention flag and return TRUE, else return FALSE. |
|
1333 |
||
1334 |
Called with kernel lock held |
|
1335 |
||
1336 |
@internalComponent |
|
1337 |
*/ |
|
1338 |
__NAKED__ TBool NThreadBase::CheckFastMutexDefer() |
|
1339 |
{ |
|
1340 |
asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1341 |
asm("bics r2, r1, #3 "); // r2 = pointer to mutex if any, r1 bit 0 = flag |
|
1342 |
asm("bne 1f "); |
|
1343 |
asm("mov r0, #0 "); // no mutex - return FALSE |
|
1344 |
__JUMP(,lr); |
|
1345 |
||
1346 |
// iHeldFastMutex points to a mutex |
|
1347 |
asm("1: "); |
|
1348 |
asm("tst r1, #1 "); // test flag |
|
1349 |
asm("beq 2f "); // branch if not being released |
|
1350 |
||
1351 |
// mutex being released |
|
1352 |
asm("3: "); |
|
1353 |
LDREX(3,2); // r3 = m->iHoldingThread |
|
1354 |
asm("sub r3, r3, r0 "); // m->iHoldingThread - this |
|
1355 |
asm("cmp r3, #1 "); |
|
1356 |
asm("bhi 4f "); // if m->iHoldingThread != this or this+1, skip |
|
1357 |
asm("orr r3, r0, #1 "); // if m->iHoldingThread = this or this+1, set m->iHoldingThread = this+1 |
|
1358 |
STREX(12,3,2); |
|
1359 |
asm("teq r12, #0 "); |
|
1360 |
asm("bne 3b "); |
|
1361 |
asm("mov r0, #1 "); // return TRUE |
|
1362 |
__JUMP(,lr); |
|
1363 |
||
1364 |
asm("4: "); |
|
1365 |
asm("mov r3, #0 "); // already released, so set iHeldFastMutex=0 |
|
1366 |
asm("str r3, [r0, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1367 |
asm("0: "); |
|
1368 |
asm("mov r0, #0 "); // no mutex - return FALSE |
|
1369 |
__JUMP(,lr); |
|
1370 |
||
1371 |
// mutex being acquired or has been acquired |
|
1372 |
// if it has been acquired set the contention flag and return TRUE, else return FALSE |
|
1373 |
asm("2: "); |
|
1374 |
LDREX(3,2); // r3 = m->iHoldingThread |
|
1375 |
asm("sub r3, r3, r0 "); // m->iHoldingThread - this |
|
1376 |
asm("cmp r3, #1 "); |
|
1377 |
asm("bhi 0b "); // if m->iHoldingThread != this or this+1, finish and return FALSE |
|
1378 |
asm("orr r3, r0, #1 "); // if m->iHoldingThread = this or this+1, set m->iHoldingThread = this+1 |
|
1379 |
STREX(12,3,2); |
|
1380 |
asm("teq r12, #0 "); |
|
1381 |
asm("bne 2b "); |
|
1382 |
asm("mov r0, #1 "); // return TRUE |
|
1383 |
__JUMP(,lr); |
|
1384 |
||
1385 |
asm("4: "); |
|
1386 |
asm("mov r3, #0 "); // already released, so set iHeldFastMutex=0 |
|
1387 |
asm("str r3, [r0, #%a0]" : : "i" _FOFF(NThreadBase,iHeldFastMutex)); |
|
1388 |
asm("mov r0, #0 "); // no mutex - return FALSE |
|
1389 |
__JUMP(,lr); |
|
1390 |
} |
|
1391 |
||
1392 |
||
1393 |
/****************************************************************************** |
|
1394 |
* IDFC/DFC |
|
1395 |
******************************************************************************/ |
|
1396 |
||
1397 |
/** Transition the state of an IDFC or DFC when Add() is called |
|
1398 |
||
1399 |
0000->008n, 00Cn->00En, all other states unchanged |
|
1400 |
Return original state. |
|
1401 |
||
1402 |
Enter and return with interrupts disabled. |
|
1403 |
*/ |
|
1404 |
__NAKED__ TUint32 TDfc::AddStateChange() |
|
1405 |
{ |
|
1406 |
GET_RWNO_TID(, r1); // r1->SubScheduler |
|
1407 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1408 |
asm("ldr r1, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuNum)); // r1 = current CPU number |
|
1409 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1410 |
asm("1: "); |
|
1411 |
LDREXH(0,3); |
|
1412 |
asm("cmp r0, #0 "); // original state 0000 ? |
|
1413 |
asm("orreq r2, r1, #0x0080 "); // yes -> 008n |
|
1414 |
asm("movne r2, r0 "); // no -> R2=original state ... |
|
1415 |
asm("eorne r12, r0, #0x00C0 "); // ... and R12=original state^00C0 ... |
|
1416 |
asm("cmpne r12, #0x0020 "); // ... and check if result < 0020 (i.e. original==00C0..00DF) |
|
1417 |
asm("addlo r2, r2, #0x0020 "); // 00Cn->00En otherwise leave R2 alone |
|
1418 |
STREXH(12,2,3); |
|
1419 |
asm("cmp r12, #0 "); |
|
1420 |
asm("bne 1b "); |
|
1421 |
__DATA_MEMORY_BARRIER__(r12); |
|
1422 |
__JUMP(,lr); |
|
1423 |
} |
|
1424 |
||
1425 |
/** Transition the state of an IDFC just before running it. |
|
1426 |
||
1427 |
002g->00Cn, 008n->00Cn, 00An->00Cn, XXYY->XX00, XX00->0000 |
|
1428 |
other initial states invalid |
|
1429 |
Return original state |
|
1430 |
||
1431 |
Enter and return with interrupts disabled. |
|
1432 |
*/ |
|
1433 |
__NAKED__ TUint32 TDfc::RunIDFCStateChange() |
|
1434 |
{ |
|
1435 |
GET_RWNO_TID(, r1); // r1->SubScheduler |
|
1436 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1437 |
asm("ldr r1, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuNum)); // r1 = current CPU number |
|
1438 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1439 |
#ifdef _DEBUG |
|
1440 |
asm("str r4, [sp, #-4]! "); |
|
1441 |
asm("ldr r4, __IdleGeneration "); |
|
1442 |
asm("ldrb r4, [r4] "); // r4 = TheScheduler.iIdleGeneration |
|
1443 |
asm("eor r4, r4, #0x0021 "); // r4 = expected state of idle IDFCs |
|
1444 |
#endif |
|
1445 |
asm("1: "); |
|
1446 |
LDREXH(0,3); |
|
1447 |
asm("eor r2, r0, #0x0080 "); |
|
1448 |
asm("cmp r2, #0x0040 "); |
|
1449 |
asm("bhs 2f "); // branch out unless 008n or 00An |
|
1450 |
#ifdef _DEBUG |
|
1451 |
asm("and r2, r0, #0x001F "); |
|
1452 |
asm("cmp r2, r1 "); |
|
1453 |
asm("bne 0f "); // if n!=current CPU number, die |
|
1454 |
#endif |
|
1455 |
asm("orr r2, r1, #0x00C0 "); // 008n->00Cn, 00An->00Cn |
|
1456 |
asm("3: "); |
|
1457 |
STREXH(12,2,3); |
|
1458 |
asm("cmp r12, #0 "); |
|
1459 |
asm("bne 1b "); |
|
1460 |
__DATA_MEMORY_BARRIER__(r12); |
|
1461 |
#ifdef _DEBUG |
|
1462 |
asm("ldr r4, [sp], #4 "); |
|
1463 |
#endif |
|
1464 |
__JUMP(,lr); |
|
1465 |
||
1466 |
asm("2: "); |
|
1467 |
asm("bic r2, r0, #1 "); |
|
1468 |
asm("cmp r2, #0x0020 "); |
|
1469 |
asm("orreq r2, r1, #0x00C0 "); // 002g->00Cn |
|
1470 |
#ifdef _DEBUG |
|
1471 |
asm("bne 4f "); |
|
1472 |
asm("cmp r0, r4 "); |
|
1473 |
asm("bne 0f "); // wrong idle state |
|
1474 |
asm("4: "); |
|
1475 |
#endif |
|
1476 |
asm("beq 3b "); |
|
1477 |
asm("cmp r0, #0x0100 "); // C=1 if XXYY or XX00, C=0 if bad state |
|
1478 |
asm("bic r2, r0, #0x00FF "); // XXYY->XX00, C unchanged |
|
1479 |
asm("tst r0, #0x00FF "); // C unchanged |
|
1480 |
asm("moveq r2, #0 "); // XX00->0000, C unchanged |
|
1481 |
asm("bcs 3b "); // branch to STREX if valid state |
|
1482 |
||
1483 |
asm("0: "); |
|
1484 |
__ASM_CRASH(); // bad state |
|
1485 |
||
1486 |
asm("__IdleGeneration: "); |
|
1487 |
asm(".word %a0 " : : "i" ((TInt)&TheScheduler.iIdleGeneration)); |
|
1488 |
} |
|
1489 |
||
1490 |
/** Transition the state of an IDFC just after running it. |
|
1491 |
||
1492 |
First swap aS->iCurrentIDFC with 0 |
|
1493 |
If original value != this, return 0xFFFFFFFF and don't touch *this |
|
1494 |
Else 00Cn->0000, 00En->008n, 006n->006n, XXCn->XX00, XXEn->XX00, XX6n->XX00, XX00->0000 |
|
1495 |
other initial states invalid |
|
1496 |
Return original state |
|
1497 |
||
1498 |
Enter and return with interrupts disabled. |
|
1499 |
*/ |
|
1500 |
__NAKED__ TUint32 TDfc::EndIDFCStateChange(TSubScheduler* /*aS*/) |
|
1501 |
{ |
|
1502 |
asm("add r1, r1, #%a0" : : "i" _FOFF(TSubScheduler,iCurrentIDFC)); |
|
1503 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1504 |
asm("1: "); |
|
1505 |
LDREX(2,1); |
|
1506 |
asm("subs r2, r2, r0 "); // aS->iCurrentIDFC == this? |
|
1507 |
asm("bne 9f "); // no - bail out immediately |
|
1508 |
STREX(12,2,1); // yes - set aS->iCurrentIDFC=0 |
|
1509 |
asm("cmp r12, #0 "); |
|
1510 |
asm("bne 1b "); |
|
1511 |
||
1512 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1513 |
__DATA_MEMORY_BARRIER__(r12); |
|
1514 |
#ifdef _DEBUG |
|
1515 |
asm("str r4, [sp, #-4]! "); |
|
1516 |
GET_RWNO_TID(, r4); // r4->SubScheduler |
|
1517 |
asm("ldr r4, [r4, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuNum)); // r4 = current CPU number |
|
1518 |
#endif |
|
1519 |
asm("2: "); |
|
1520 |
LDREXH(0,3); // r0 = original DFC state |
|
1521 |
asm("mov r2, #0 "); // r2 = 0 to begin with |
|
1522 |
#ifdef _DEBUG |
|
1523 |
asm("tst r0, #0x00FF "); |
|
1524 |
asm("beq 5f "); |
|
1525 |
asm("eor r12, r0, r4 "); // original state ^ CPU number, should be xxC0, xxE0 or xx60 |
|
1526 |
asm("and r12, r12, #0x00E0 "); |
|
1527 |
asm("cmp r12, #0x00E0 "); |
|
1528 |
asm("cmpne r12, #0x00C0 "); |
|
1529 |
asm("cmpne r12, #0x0060 "); |
|
1530 |
asm("beq 5f "); |
|
1531 |
__ASM_CRASH(); // bad state |
|
1532 |
asm("5: "); |
|
1533 |
#endif |
|
1534 |
asm("bic r12, r0, #0x001F "); |
|
1535 |
asm("cmp r12, #0x00E0 "); |
|
1536 |
asm("bhi 4f "); // branch out if XXYY or XX00 |
|
1537 |
asm("subeq r2, r0, #0x0060 "); // 00En->008n |
|
1538 |
asm("cmp r12, #0x0060 "); |
|
1539 |
asm("moveq r2, r0 "); // 006n->006n, else R2=0 |
|
1540 |
asm("3: "); |
|
1541 |
STREXH(12,2,3); |
|
1542 |
asm("cmp r12, #0 "); |
|
1543 |
asm("bne 2b "); |
|
1544 |
__DATA_MEMORY_BARRIER__(r12); |
|
1545 |
#ifdef _DEBUG |
|
1546 |
asm("ldr r4, [sp], #4 "); |
|
1547 |
#endif |
|
1548 |
__JUMP(,lr); |
|
1549 |
||
1550 |
asm("4: "); |
|
1551 |
asm("tst r0, #0x00FF "); |
|
1552 |
asm("bicne r2, r0, #0x00FF "); // XXYY->XX00, XX00->0000 |
|
1553 |
asm("b 3b "); |
|
1554 |
||
1555 |
asm("9: "); |
|
1556 |
asm("mvn r0, #0 "); // return 0xFFFFFFFF |
|
1557 |
__JUMP(,lr); |
|
1558 |
} |
|
1559 |
||
1560 |
/** Transition the state of an IDFC just after running it. |
|
1561 |
||
1562 |
006n->002g where g = TheScheduler.iIdleGeneration |
|
1563 |
XX6n->XX00 |
|
1564 |
other initial states invalid |
|
1565 |
Return original state |
|
1566 |
||
1567 |
Enter and return with interrupts disabled. |
|
1568 |
*/ |
|
1569 |
__NAKED__ TUint32 TDfc::EndIDFCStateChange2() |
|
1570 |
{ |
|
1571 |
asm("ldr r12, __IdleGeneration "); |
|
1572 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1573 |
#ifdef _DEBUG |
|
1574 |
asm("str r4, [sp, #-4]! "); |
|
1575 |
GET_RWNO_TID(, r4); // r4->SubScheduler |
|
1576 |
asm("ldr r4, [r4, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuNum)); // r4 = current CPU number |
|
1577 |
#endif |
|
1578 |
asm("ldrb r1, [r12] "); // r1 = TheScheduler.iIdleGeneration |
|
1579 |
asm("1: "); |
|
1580 |
LDREXH(0,3); |
|
1581 |
#ifdef _DEBUG |
|
1582 |
asm("eor r12, r0, r4 "); |
|
1583 |
asm("and r12, r12, #0x00FF "); |
|
1584 |
asm("cmp r12, #0x0060 "); // should be 006n or XX6n |
|
1585 |
asm("beq 2f "); |
|
1586 |
__ASM_CRASH(); // if not, die |
|
1587 |
asm("2: "); |
|
1588 |
#endif |
|
1589 |
asm("tst r0, #0xFF00 "); // XX6n or 006n ? |
|
1590 |
asm("orreq r2, r1, #0x0020 "); // 006n->002g |
|
1591 |
asm("bicne r2, r0, #0x00FF "); // XX6n->XX00 |
|
1592 |
STREXH(12,2,3); |
|
1593 |
asm("cmp r12, #0 "); |
|
1594 |
asm("bne 1b "); |
|
1595 |
__DATA_MEMORY_BARRIER__(r12); |
|
1596 |
#ifdef _DEBUG |
|
1597 |
asm("ldr r4, [sp], #4 "); |
|
1598 |
#endif |
|
1599 |
__JUMP(,lr); |
|
1600 |
} |
|
1601 |
||
1602 |
/** Transition the state of a DFC just before moving it from the IDFC queue to |
|
1603 |
its final queue. |
|
1604 |
||
1605 |
002g->0001, 008n->0001, XX2g->XX00, XX8n->XX00, XX00->0000 |
|
1606 |
other initial states invalid |
|
1607 |
Return original state |
|
1608 |
*/ |
|
1609 |
__NAKED__ TUint32 TDfc::MoveToFinalQStateChange() |
|
1610 |
{ |
|
1611 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1612 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1613 |
#ifdef _DEBUG |
|
1614 |
asm("str r4, [sp, #-4]! "); |
|
1615 |
asm("ldr r4, __IdleGeneration "); |
|
1616 |
GET_RWNO_TID(, r1); // r1->SubScheduler |
|
1617 |
asm("ldrb r4, [r4] "); // r4 = TheScheduler.iIdleGeneration |
|
1618 |
asm("ldr r1, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuNum)); // r1 = current CPU number |
|
1619 |
asm("eor r4, r4, #0x0021 "); // r4 = expected state of idle IDFCs |
|
1620 |
asm("orr r1, r1, #0x0080 "); |
|
1621 |
#endif |
|
1622 |
asm("1: "); |
|
1623 |
LDREXH(0,3); |
|
1624 |
#ifdef _DEBUG |
|
1625 |
asm("cmp r0, #0 "); |
|
1626 |
asm("beq 0f "); // 0000 -> die |
|
1627 |
asm("ands r2, r0, #0x00FF "); |
|
1628 |
asm("beq 3f "); // XX00 -> OK |
|
1629 |
asm("cmp r2, r4 "); // 002g ? |
|
1630 |
asm("beq 3f "); // yes -> OK |
|
1631 |
asm("cmp r2, r1 "); // 008n ? |
|
1632 |
asm("beq 3f "); // yes -> OK |
|
1633 |
asm("0: "); |
|
1634 |
__ASM_CRASH(); // otherwise die |
|
1635 |
asm("3: "); |
|
1636 |
#endif |
|
1637 |
asm("bics r2, r0, #0x00FF "); // XXYY->XX00 |
|
1638 |
asm("moveq r2, #0x0001 "); // 002g,008n->0001 |
|
1639 |
asm("beq 2f "); |
|
1640 |
asm("tst r0, #0x00FF "); |
|
1641 |
asm("moveq r2, #0 "); // XX00->0000 |
|
1642 |
asm("2: "); |
|
1643 |
STREXH(12,2,3); |
|
1644 |
asm("cmp r12, #0 "); |
|
1645 |
asm("bne 1b "); |
|
1646 |
__DATA_MEMORY_BARRIER__(r12); |
|
1647 |
#ifdef _DEBUG |
|
1648 |
asm("ldr r4, [sp], #4 "); |
|
1649 |
#endif |
|
1650 |
__JUMP(,lr); |
|
1651 |
} |
|
1652 |
||
1653 |
/** Transition the state of an IDFC when transferring it to another CPU |
|
1654 |
||
1655 |
002g->00Am, 008n->00Am, XXYY->XX00, XX00->0000 |
|
1656 |
other initial states invalid |
|
1657 |
Return original state |
|
1658 |
||
1659 |
Enter and return with interrupts disabled and target CPU's ExIDfcLock held. |
|
1660 |
*/ |
|
1661 |
__NAKED__ TUint32 TDfc::TransferIDFCStateChange(TInt /*aCpu*/) |
|
1662 |
{ |
|
1663 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1664 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1665 |
#ifdef _DEBUG |
|
1666 |
asm("stmfd sp!, {r4-r5} "); |
|
1667 |
asm("ldr r4, __IdleGeneration "); |
|
1668 |
GET_RWNO_TID(, r5); // r5->SubScheduler |
|
1669 |
asm("ldrb r4, [r4] "); // r4 = TheScheduler.iIdleGeneration |
|
1670 |
asm("ldr r5, [r5, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuNum)); // r5 = current CPU number |
|
1671 |
asm("eor r4, r4, #0x0021 "); // r4 = expected state of idle IDFCs |
|
1672 |
asm("orr r5, r5, #0x0080 "); |
|
1673 |
#endif |
|
1674 |
asm("1: "); |
|
1675 |
LDREXH(0,3); |
|
1676 |
#ifdef _DEBUG |
|
1677 |
asm("cmp r0, #0 "); |
|
1678 |
asm("beq 0f "); // 0000 -> die |
|
1679 |
asm("ands r2, r0, #0x00FF "); |
|
1680 |
asm("beq 3f "); // XX00 -> OK |
|
1681 |
asm("cmp r2, r4 "); // 002g ? |
|
1682 |
asm("beq 3f "); // yes -> OK |
|
1683 |
asm("cmp r2, r5 "); // 008n ? |
|
1684 |
asm("beq 3f "); // yes -> OK |
|
1685 |
asm("0: "); |
|
1686 |
__ASM_CRASH(); // otherwise die |
|
1687 |
asm("3: "); |
|
1688 |
#endif |
|
1689 |
asm("bics r2, r0, #0x00FF "); // XXYY->XX00 |
|
1690 |
asm("orreq r2, r1, #0x00A0 "); // 002g,008n->00Am |
|
1691 |
asm("beq 2f "); |
|
1692 |
asm("tst r0, #0x00FF "); |
|
1693 |
asm("moveq r2, #0 "); // XX00->0000 |
|
1694 |
asm("2: "); |
|
1695 |
STREXH(12,2,3); |
|
1696 |
asm("cmp r12, #0 "); |
|
1697 |
asm("bne 1b "); |
|
1698 |
__DATA_MEMORY_BARRIER__(r12); |
|
1699 |
#ifdef _DEBUG |
|
1700 |
asm("ldmfd sp!, {r4-r5} "); |
|
1701 |
#endif |
|
1702 |
__JUMP(,lr); |
|
1703 |
} |
|
1704 |
||
1705 |
/** Transition the state of an IDFC/DFC just before cancelling it. |
|
1706 |
||
1707 |
0000->0000, XX00->ZZ00, xxYY->zzYY |
|
1708 |
Return original state |
|
1709 |
||
1710 |
Enter and return with interrupts disabled. |
|
1711 |
*/ |
|
1712 |
__NAKED__ TUint32 TDfc::CancelInitialStateChange() |
|
1713 |
{ |
|
1714 |
GET_RWNO_TID(,r1); |
|
1715 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1716 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1717 |
asm("ldr r1, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCpuMask)); // r1 = mask of current CPU number |
|
1718 |
||
1719 |
asm("1: "); |
|
1720 |
LDREXH(0,3); |
|
1721 |
asm("cmp r0, #0 "); |
|
1722 |
asm("beq 2f "); // if original state 0000 leave alone |
|
1723 |
asm("orr r2, r0, r1, lsl #8 "); // else set bit 8-15 corresponding to CPU number |
|
1724 |
STREXH(12,2,3); |
|
1725 |
asm("cmp r12, #0 "); |
|
1726 |
asm("bne 1b "); |
|
1727 |
asm("2: "); |
|
1728 |
__DATA_MEMORY_BARRIER__(r12); |
|
1729 |
__JUMP(,lr); |
|
1730 |
} |
|
1731 |
||
1732 |
/** Transition the state of an IDFC/DFC at the end of a cancel operation |
|
1733 |
||
1734 |
XXYY->XX00, XX00->0000 |
|
1735 |
Return original state |
|
1736 |
||
1737 |
Enter and return with interrupts disabled. |
|
1738 |
*/ |
|
1739 |
__NAKED__ TUint32 TDfc::CancelFinalStateChange() |
|
1740 |
{ |
|
1741 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1742 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1743 |
||
1744 |
asm("1: "); |
|
1745 |
LDREXH(0,3); |
|
1746 |
asm("tst r0, #0x00FF "); |
|
1747 |
asm("bicne r2, r0, #0x00FF "); // XXYY->XX00 |
|
1748 |
asm("moveq r2, #0 "); // xx00->0000 |
|
1749 |
STREXH(12,2,3); |
|
1750 |
asm("cmp r12, #0 "); |
|
1751 |
asm("bne 1b "); |
|
1752 |
__DATA_MEMORY_BARRIER__(r12); |
|
1753 |
__JUMP(,lr); |
|
1754 |
} |
|
1755 |
||
1756 |
/** Transition the state of an IDFC or DFC when QueueOnIdle() is called |
|
1757 |
||
1758 |
0000->002g where g = TheScheduler.iIdleGeneration, |
|
1759 |
00Cn->006n, all other states unchanged |
|
1760 |
Return original state. |
|
1761 |
||
1762 |
Enter and return with interrupts disabled and IdleSpinLock held. |
|
1763 |
*/ |
|
1764 |
__NAKED__ TUint32 TDfc::QueueOnIdleStateChange() |
|
1765 |
{ |
|
1766 |
asm("ldr r12, __IdleGeneration "); |
|
1767 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1768 |
asm("ldrb r1, [r12] "); // r1 = TheScheduler.iIdleGeneration |
|
1769 |
__DATA_MEMORY_BARRIER_Z__(r12); |
|
1770 |
asm("1: "); |
|
1771 |
LDREXH(0,3); |
|
1772 |
asm("cmp r0, #0 "); // original state 0000 ? |
|
1773 |
asm("orreq r2, r1, #0x0020 "); // yes -> 002g |
|
1774 |
asm("movne r2, r0 "); // no -> R2=original state ... |
|
1775 |
asm("eorne r12, r0, #0x00C0 "); // ... and R12=original state^00C0 ... |
|
1776 |
asm("cmpne r12, #0x0020 "); // ... and check if result < 0020 (i.e. original==00C0..00DF) |
|
1777 |
asm("sublo r2, r2, #0x0060 "); // 00Cn->006n otherwise leave R2 alone |
|
1778 |
STREXH(12,2,3); |
|
1779 |
asm("cmp r12, #0 "); |
|
1780 |
asm("bne 1b "); |
|
1781 |
__DATA_MEMORY_BARRIER__(r12); |
|
1782 |
__JUMP(,lr); |
|
1783 |
} |
|
1784 |
||
1785 |
||
1786 |
__NAKED__ void TDfc::ResetState() |
|
1787 |
{ |
|
1788 |
asm("add r3, r0, #%a0" : : "i" _FOFF(TDfc,iDfcState)); |
|
1789 |
__DATA_MEMORY_BARRIER_Z__(r2); |
|
1790 |
#ifdef _DEBUG |
|
1791 |
asm("1: "); |
|
1792 |
LDREXH(0,3); |
|
1793 |
asm("cmp r0, #0 "); |
|
1794 |
asm("beq 0f "); // if state already zero, die |
|
1795 |
STREXH(12,2,3); |
|
1796 |
asm("cmp r12, #0 "); |
|
1797 |
asm("bne 1b "); |
|
1798 |
#else |
|
1799 |
asm("strh r2, [r3] "); // __e32_atomic_store_rel16(&iDfcState, 0) |
|
1800 |
#endif |
|
1801 |
__JUMP(,lr); |
|
1802 |
#ifdef _DEBUG |
|
1803 |
asm("0: "); |
|
1804 |
__ASM_CRASH(); |
|
1805 |
#endif |
|
1806 |
} |
|
1807 |
||
1808 |
||
1809 |