First public contribution.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\nkernsmp\arm\ncutils.cia
22 extern TSpinLock BTraceLock;
25 extern TUint32 CrashStateOut;
26 extern SFullArmRegSet DefaultRegSet;
29 //#define __DBG_MON_FAULT__
30 //#define __RAM_LOADED_CODE__
31 //#define __EARLY_DEBUG__
34 #define ASM_KILL_LINK(rp,rs) asm("mov "#rs", #0xdf ");\
35 asm("orr "#rs", "#rs", "#rs", lsl #8 ");\
36 asm("orr "#rs", "#rs", "#rs", lsl #16 ");\
37 asm("str "#rs", ["#rp"] ");\
38 asm("str "#rs", ["#rp", #4] ");
40 #define ASM_KILL_LINK(rp,rs)
43 #ifdef __PRI_LIST_MACHINE_CODED__
44 /** Return the priority of the highest priority item present on a priority list.
46 @return The highest priority present or -1 if the list is empty.
48 EXPORT_C __NAKED__ TInt TPriListBase::HighestPriority()
50 asm("ldr r2, [r0, #4] "); // r2=iPresent MSW
51 asm("ldr r1, [r0, #0] "); // r1=iPresent LSW
52 CLZ(0,2); // r0=31-MSB(r2)
53 asm("subs r0, r0, #32 "); // r0=-1-MSB(r2), 0 if r2=0
54 CLZcc(CC_EQ,0,1); // if r2=0, r0=31-MSB(r1)
55 asm("rsb r0, r0, #31 "); // r0=highest priority
59 /** Find the highest priority item present on a priority list.
60 If multiple items at the same priority are present, return the first to be
61 added in chronological order.
63 @return a pointer to the item or NULL if the list is empty.
65 EXPORT_C __NAKED__ TPriListLink* TPriListBase::First()
67 asm("ldr r2, [r0, #4] "); // r2=iPresent MSW
68 asm("ldr r1, [r0], #8 "); // r1=iPresent LSW, r0=&iQueue[0]
69 CLZ(3,2); // r3=31-MSB(r2)
70 asm("subs r3, r3, #32 "); // r3=-1-MSB(r2), 0 if r2=0
71 CLZcc(CC_EQ,3,1); // if r2=0, r3=31-MSB(r1)
72 asm("rsbs r3, r3, #31 "); // r3=highest priority
73 asm("ldrpl r0, [r0, r3, lsl #2] "); // if r3>=0 list is nonempty, r0->first entry
74 asm("movmi r0, #0 "); // if r3<0 list empty, return NULL
78 /** Add an item to a priority list.
80 @param aLink = a pointer to the item - must not be NULL
82 EXPORT_C __NAKED__ void TPriListBase::Add(TPriListLink* /*aLink*/)
84 asm("ldrb r2, [r1, #8]" ); // r2=priority of aLink
85 asm("add ip, r0, #8 "); // ip=&iQueue[0]
86 asm("ldr r3, [ip, r2, lsl #2]! "); // r3->first entry at this priority
87 asm("cmp r3, #0 "); // is this first entry at this priority?
88 asm("bne pri_list_add_1 "); // branch if not
89 asm("str r1, [ip] "); // if queue originally empty, iQueue[pri]=aThread
90 asm("ldrb ip, [r0, r2, lsr #3]! "); // ip=relevant byte of present mask, r0->same
91 asm("and r2, r2, #7 ");
93 asm("str r1, [r1, #0] "); // aThread->next=aThread
94 asm("orr ip, ip, r3, lsl r2 "); // ip |= 1<<(pri&7)
95 asm("str r1, [r1, #4] "); // aThread->iPrev=aThread
96 asm("strb ip, [r0] "); // update relevant byte of present mask
98 asm("pri_list_add_1: ");
99 asm("ldr ip, [r3, #4] "); // if nonempty, ip=last
100 asm("str r1, [r3, #4] "); // first->prev=aThread
101 asm("stmia r1, {r3,ip} "); // aThread->next=r3=first, aThread->prev=ip=last
102 asm("str r1, [ip, #0] "); // last->next=aThread
107 /** Removes an item from a priority list.
109 @param aLink A pointer to the item - this must not be NULL.
111 EXPORT_C __NAKED__ void TPriListBase::Remove(TPriListLink* /*aLink*/)
113 asm("ldmia r1, {r2,r3} "); // r2=aLink->iNext, r3=aLink->iPrev
114 ASM_KILL_LINK(r1,r12);
115 asm("subs r12, r1, r2 "); // check if more threads at this priority, r12=0 if not
116 asm("bne 1f "); // branch if there are more at same priority
117 asm("ldrb r2, [r1, #%a0]" : : "i" _FOFF(NThread, iPriority)); // r2=thread priority
118 asm("add r1, r0, #%a0" : : "i" _FOFF(TPriListBase, iQueue)); // r1->iQueue[0]
119 asm("str r12, [r1, r2, lsl #2] "); // iQueue[priority]=NULL
120 asm("ldrb r1, [r0, r2, lsr #3] "); // r1=relevant byte in present mask
121 asm("and r3, r2, #7 "); // r3=priority & 7
123 asm("bic r1, r1, r12, lsl r3 "); // clear bit in present mask
124 asm("strb r1, [r0, r2, lsr #3] "); // update relevant byte in present mask
126 asm("1: "); // get here if there are other threads at same priority
127 asm("ldrb r12, [r1, #%a0]" : : "i" _FOFF(NThread, iPriority)); // r12=thread priority
128 asm("add r0, r0, #%a0" : : "i" _FOFF(TPriListBase, iQueue)); // r0=&iQueue[0]
129 asm("str r3, [r2, #4] "); // next->prev=prev
130 asm("ldr r12, [r0, r12, lsl #2]! "); // r12=iQueue[priority], r0=&iQueue[priority]
131 asm("str r2, [r3, #0] "); // and prev->next=next
132 asm("cmp r12, r1 "); // if aThread was first...
133 asm("streq r2, [r0, #0] "); // iQueue[priority]=aThread->next
134 __JUMP(,lr); // finished
138 /** Change the priority of an item on a priority list
140 @param aLink = pointer to the item to act on - must not be NULL
141 @param aNewPriority = new priority for the item
143 EXPORT_C __NAKED__ void TPriListBase::ChangePriority(TPriListLink* /*aLink*/, TInt /*aNewPriority*/)
145 asm("ldrb r3, [r1, #8] "); // r3=old priority
146 asm("stmfd sp!, {r4-r6,lr} ");
148 asm("ldmeqfd sp!, {r4-r6,pc} "); // if old priority=new, finished
149 asm("ldmia r1, {r4,r12} "); // r4=next, r12=prev
150 asm("ldmia r0!, {r6,lr} "); // lr:r6=present mask, r0=&iQueue[0]
151 asm("subs r5, r4, r1 "); // check if aLink is only one at that priority, r5=0 if it is
152 asm("beq change_pri_1 "); // branch if it is
153 asm("ldr r5, [r0, r3, lsl #2] "); // r5=iQueue[old priority]
154 asm("str r4, [r12, #0] "); // prev->next=next
155 asm("str r12, [r4, #4] "); // next->prev=prev
156 asm("cmp r5, r1 "); // was aLink first?
157 asm("streq r4, [r0, r3, lsl #2] "); // if it was, iQueue[old priority]=aLink->next
158 asm("b change_pri_2 ");
159 asm("change_pri_1: ");
160 asm("str r5, [r0, r3, lsl #2] "); // if empty, set iQueue[old priority]=NULL
161 asm("mov r12, #0x80000000 ");
162 asm("rsbs r3, r3, #31 "); // r3=31-priority
163 asm("bicmi lr, lr, r12, ror r3 "); // if pri>31, clear bit is MS word
164 asm("bicpl r6, r6, r12, ror r3 "); // if pri<=31, clear bit in LS word
165 asm("change_pri_2: ");
166 asm("ldr r4, [r0, r2, lsl #2] "); // r4=iQueue[new priority]
167 asm("strb r2, [r1, #8] "); // store new priority
168 asm("cmp r4, #0 "); // new priority queue empty?
169 asm("bne change_pri_3 "); // branch if not
170 asm("str r1, [r0, r2, lsl #2] "); // if new priority queue was empty, iQueue[new p]=aLink
171 asm("mov r12, #0x80000000 ");
172 asm("str r1, [r1, #0] "); // aLink->next=aLink
173 asm("rsbs r2, r2, #31 "); // r2=31-priority
174 asm("str r1, [r1, #4] "); // aLink->prev=aLink
175 asm("orrmi lr, lr, r12, ror r2 "); // if pri>31, set bit is MS word
176 asm("orrpl r6, r6, r12, ror r2 "); // if pri<=31, set bit in LS word
177 asm("stmdb r0!, {r6,lr} "); // store present mask and restore r0
178 asm("ldmfd sp!, {r4-r6,pc} ");
179 asm("change_pri_3: ");
180 asm("ldr r12, [r4, #4] "); // r12->last link at this priority
181 asm("str r1, [r4, #4] "); // first->prev=aLink
182 asm("str r1, [r12, #0] "); // old last->next=aLink
183 asm("stmia r1, {r4,r12} "); // aLink->next=r3=first, aLink->prev=r12=old last
184 asm("stmdb r0!, {r6,lr} "); // store present mask and restore r0
185 asm("ldmfd sp!, {r4-r6,pc} ");
189 __NAKED__ void initialiseState(TInt /*aCpu*/, TSubScheduler* /*aSS*/)
192 __ASM_CLI_MODE(MODE_ABT);
193 asm("str sp, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_AbtStackTop));
195 asm("str r3, [sp, #%a0]" : : "i" _FOFF(SFullArmRegSet, iExcCode));
196 asm("str r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_IrqNestCount));
197 __ASM_CLI_MODE(MODE_UND);
198 asm("str sp, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_UndStackTop));
199 __ASM_CLI_MODE(MODE_FIQ);
200 asm("str sp, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_FiqStackTop));
201 __ASM_CLI_MODE(MODE_IRQ);
202 asm("str sp, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_IrqStackTop));
203 __ASM_CLI_MODE(MODE_SVC);
204 asm("ldr r2, __TheScheduler ");
205 asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(TScheduler, i_ScuAddr));
206 asm("str r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_ScuAddr));
207 asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(TScheduler, i_GicDistAddr));
208 asm("str r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_GicDistAddr));
209 asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(TScheduler, i_GicCpuIfcAddr));
210 asm("str r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_GicCpuIfcAddr));
211 asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(TScheduler, i_LocalTimerAddr));
212 asm("str r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, i_LocalTimerAddr));
219 asm("__TheScheduler: ");
220 asm(".word TheScheduler ");
223 __NAKED__ TUint32 __mpid()
225 asm("mrc p15, 0, r0, c0, c0, 5 ");
229 /** @internalTechnology
231 Called to indicate that the system has crashed and all CPUs should be
232 halted and should dump their registers.
235 __NAKED__ void NKern::NotifyCrash(const TAny* /*a0*/, TInt /*a1*/)
237 asm("stmfd sp!, {r0-r1} "); // save parameters
240 asm("ldreq r0, __SS0 ");
241 asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TSubScheduler,i_Regs));
243 asm("ldreq r0, __DefaultRegs ");
244 asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet, iExcCode));
245 asm("cmp r1, #0 "); // context already saved?
246 asm("bge state_already_saved "); // skip if so
248 asm("bl " CSM_ZN3Arm9SaveStateER14SFullArmRegSet );
249 asm("str r1, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet, iN.iR15));
250 asm("ldmia sp!, {r2-r3} "); // original R0,R1
251 asm("stmia r0, {r2-r3} "); // save original R0,R1
252 asm("add r1, r0, #%a0" : : "i" _FOFF(SFullArmRegSet, iExcCode));
253 asm("mov r4, r0 "); // save pointer to i_Regs
254 asm("stmib r1, {r2-r3} "); // save a0, a1 in iCrashArgs
255 asm("mov r1, #13 "); // r1 = regnum
256 asm("mrs r2, cpsr "); // r2 = mode
257 asm("bl " CSM_ZN3Arm3RegER14SFullArmRegSetim ); // r0 = pointer to exception mode R13
258 asm("str sp, [r0] "); // save correct original value for exception mode R13
259 asm("b state_save_complete ");
261 asm("state_already_saved: ");
262 asm("ldmia sp!, {r2-r3} "); // original R0,R1
263 asm("add r1, r0, #%a0" : : "i" _FOFF(SFullArmRegSet, iExcCode));
264 asm("ldr r4, [r1, #4]! ");
266 asm("stmeqia r1, {r2-r3} "); // save a0, a1 in iCrashArgs, provided iCrashArgs not already set
267 asm("mov r4, r0 "); // save pointer to i_Regs
268 asm("state_save_complete: ");
270 __ASM_CLI_MODE(MODE_FIQ); // mode_fiq, interrupts off
272 asm("ldr r1, __CrashState ");
274 asm("moveq r2, #1 ");
275 asm("streq r2, [r1] ");
276 asm("beq skip_other_cores "); // If subscheduler not yet set, don't bother with other cores
277 asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuMask));
278 asm("ldr r5, [r0, #%a0]" : : "i" _FOFF(TSubScheduler, i_GicCpuIfcAddr));
279 // asm("ldr r4, [r0, #%a0]" : : "i" _FOFF(TSubScheduler,i_Regs));
280 asm("bic sp, sp, #4 "); // align stack to multiple of 8
282 __DATA_MEMORY_BARRIER_Z__(r6);
285 asm("orr r5, r3, r2 ");
286 STREX(12,5,1); // set bit in CrashState for this CPU
289 __DATA_MEMORY_BARRIER__(r6);
290 asm("cmp r3, #0 "); // were we first to crash?
291 asm("beq first_to_crash "); // branch if so
293 // we weren't first to crash, so wait here for a crash IPI
294 // disable all interrupts except for CRASH_IPI
296 asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(TSubScheduler, i_GicCpuIfcAddr));
299 asm("add r1, r1, #1 ");
300 asm("str r1, [r0, #%a0]" : : "i" _FOFF(GicCpuIfc, iPriMask));
301 __DATA_SYNC_BARRIER__(r6);
302 asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(GicCpuIfc, iPriMask));
304 asm("beq 1b "); // loop until priority mask is nonzero
307 __ASM_STI_MODE(MODE_ABT);
309 asm("b 2b "); // loop until we get a CRASH_IPI
311 // This CPU was first to crash
312 asm("first_to_crash: ");
313 asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(TSubScheduler, iScheduler));
314 asm("ldr r7, __CrashStateOut ");
315 asm("ldr r3, [r2, #%a0]" : : "i" _FOFF(TScheduler, iActiveCpus1));
316 asm("str r3, [r7] "); // mask of CPUs pending
317 asm("ldr r5, [r0, #%a0]" : : "i" _FOFF(TSubScheduler, i_GicDistAddr));
318 asm("ldr r1, __CrashIPIWord ");
319 __DATA_SYNC_BARRIER_Z__(r6);
320 asm("str r1, [r5, #%a0]" : : "i" _FOFF(GicDistributor, iSoftIrq)); // send CRASH_IPI to all other CPUs
321 __DATA_SYNC_BARRIER__(r6);
323 asm("skip_other_cores: ");
327 asm("bl NKCrashHandler "); // call NKCrashHandler(0,0,0)
329 __DATA_SYNC_BARRIER__(r6);
332 asm("beq skip_other_cores2 "); // If subscheduler not yet set, don't bother with other cores
333 asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuMask));
336 asm("bic r1, r1, r2 ");
337 STREX(3,1,7); // atomic { CrashStateOut &= ~iCpuMask; }
341 asm("ldr r1, [r7] ");
342 asm("cmp r1, #0 "); // wait for all CPUs to acknowledge
344 asm("adds r6, r6, #1 ");
345 asm("bne 1b "); // if not ACKed after 2^32 iterations give up waiting
347 __DATA_MEMORY_BARRIER_Z__(r0);
349 asm("skip_other_cores2: ");
351 asm("ldr r1, [r4, #%a0] " : : "i" _FOFF(SFullArmRegSet,iN.iR0)); // original R0 = a0 parameter
352 asm("ldr r2, [r4, #%a0] " : : "i" _FOFF(SFullArmRegSet,iN.iR1)); // original R1 = a1 parameter
353 asm("bl NKCrashHandler "); // call NKCrashHandler(1,a0,a1) - shouldn't return
355 // shouldn't get back here
358 asm("__CrashState: ");
359 asm(".word %a0" : : "i" ((TInt)&CrashState));
360 asm("__CrashStateOut: ");
361 asm(".word CrashStateOut ");
362 asm("__CrashIPIWord: ");
363 asm(".word %a0" : : "i" ( (TInt)GIC_IPI_OTHERS(CRASH_IPI_VECTOR) ));
365 asm(".word %a0" : : "i" ((TInt)&TheSubSchedulers[0]));
366 asm("__DefaultRegs: ");
367 asm(".word %a0" : : "i" ((TInt)&DefaultRegSet));
371 #ifdef __USE_BTRACE_LOCK__
372 #define __ASM_ACQUIRE_BTRACE_LOCK(regs) \
373 asm("stmfd sp!, " regs); \
374 asm("ldr r0, __BTraceLock "); \
375 asm("bl " CSM_ZN9TSpinLock11LockIrqSaveEv ); \
376 asm("mov r4, r0 "); \
377 asm("ldmfd sp!, " regs)
379 #define __ASM_RELEASE_BTRACE_LOCK() \
380 asm("stmfd sp!, {r0-r1} "); \
381 asm("ldr r0, __BTraceLock "); \
382 asm("mov r1, r4 "); \
383 asm("bl " CSM_ZN9TSpinLock16UnlockIrqRestoreEi ); \
384 asm("ldmfd sp!, {r0-r1} ")
387 #define __ASM_ACQUIRE_BTRACE_LOCK(regs)
388 #define __ASM_RELEASE_BTRACE_LOCK()
392 __NAKED__ EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
394 asm("stmdb sp!, {r2,r3,r4,lr}");
395 __ASM_ACQUIRE_BTRACE_LOCK("{r0-r1}");
396 asm("ldr r12, __BTraceData");
397 asm("and r2, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
398 asm("mov r3, r1"); // r3 = a1 (ready for call to handler)
399 asm("ldrb r2, [r12, r2, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
400 asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(SBTraceData,iHandler));
406 __ASM_RELEASE_BTRACE_LOCK();
407 __POPRET("r2,r3,r4,");
410 __NAKED__ EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
412 asm("stmdb sp!, {r2,r3,r4,lr}");
413 __ASM_ACQUIRE_BTRACE_LOCK("{r0-r3}");
414 asm("ldr r12, __BTraceData");
415 asm("and r2, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
416 asm("ldr r14, [sp, #16]"); // r14 = aDataSize
417 asm("ldrb r2, [r12, r2, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
418 asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(SBTraceData,iHandler));
423 asm("cmp r14, #%a0" : : "i" ((TInt)KMaxBTraceDataArray));
424 asm("movhi r14, #%a0" : : "i" ((TInt)KMaxBTraceDataArray));
425 asm("orrhi r0, r0, #%a0" : : "i" ((TInt)(BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8))));
426 asm("add r0, r0, r14");
427 asm("subs r14, r14, #1");
428 asm("ldrhs r2, [r3]"); // get first word of aData is aDataSize!=0
429 asm("mov r3, r1"); // r3 = a1 (ready for call to handler)
431 asm("strlo r2, [sp, #4]"); // replace aData with first word if aDataSize is 1-4
436 __ASM_RELEASE_BTRACE_LOCK();
437 __POPRET("r2,r3,r4,");
440 __NAKED__ EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
442 asm("stmdb sp!, {r2,r3,r4,lr}");
443 __ASM_ACQUIRE_BTRACE_LOCK("{r0-r1}");
444 asm("ldr r12, __BTraceData");
445 asm("and r2, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
446 asm("mov r3, r1"); // r3 = a1 (ready for call to handler)
447 asm("ldrb r2, [r12, r2, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
448 asm("mrs r14, cpsr ");
449 asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(SBTraceData,iHandler));
450 asm("cmp r2, #0"); // check category filter
452 asm("beq 0f "); // if category disabled, exit now
454 asm("and r2, r14, #0x0f ");
456 asm("movhi r2, #2 "); // r2 = context ID = 1 for FIQ, 2 for IRQ/ABT/UND/SYS
459 asm("movs r2, r1 "); // r2 = context ID = 0 for early boot, no threads
461 asm("ldrb r2, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iInIDFC));
463 asm("ldreq r2, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread));
464 asm("movne r2, #3 "); // r2 = context ID = 3 for IDFC = NThread pointer for thread
466 asm("msr cpsr, r14 ");
470 __ASM_RELEASE_BTRACE_LOCK();
471 __POPRET("r2,r3,r4,");
474 __NAKED__ EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
476 asm("stmdb sp!, {r2,r3,r4,lr}");
477 __ASM_ACQUIRE_BTRACE_LOCK("{r0-r3}");
478 asm("ldr r12, __BTraceData");
479 asm("and r2, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
480 asm("ldr r14, [sp, #16]"); // r14 = aDataSize
481 asm("ldrb r2, [r12, r2, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
482 asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(SBTraceData,iHandler));
483 asm("cmp r2, #0"); // check category filter
485 asm("beq 0f "); // if category disabled, exit now
487 asm("cmp r14, #%a0" : : "i" ((TInt)KMaxBTraceDataArray));
488 asm("movhi r14, #%a0" : : "i" ((TInt)KMaxBTraceDataArray));
489 asm("orrhi r0, r0, #%a0" : : "i" ((TInt)(BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8))));
490 asm("add r0, r0, r14");
491 asm("subs r14, r14, #1");
492 asm("ldrhs r2, [r3]"); // get first word of aData is aDataSize!=0
493 asm("mov r3, r1"); // r3 = a1 (ready for call to handler)
495 asm("strlo r2, [sp, #4]"); // replace aData with first word if aDataSize is 1-4
497 asm("mrs r14, cpsr ");
499 asm("and r2, r14, #0x0f ");
501 asm("movhi r2, #2 "); // r2 = context ID = 1 for FIQ, 2 for IRQ/ABT/UND/SYS
504 asm("movs r2, r1 "); // r2 = context ID = 0 for early boot, no threads
506 asm("ldrb r2, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iInIDFC));
508 asm("ldreq r2, [r1, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread));
509 asm("movne r2, #3 "); // r2 = context ID = 3 for IDFC = NThread pointer for thread
511 asm("msr cpsr, r14 ");
516 __ASM_RELEASE_BTRACE_LOCK();
517 __POPRET("r2,r3,r4,");
520 __NAKED__ EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
522 asm("stmdb sp!, {r4,lr}");
523 asm("ldr r12, __BTraceData");
524 asm("str lr, [sp, #-4]! "); // PC
525 asm("and r14, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
526 asm("ldrb r14, [r12, r14, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
527 asm("cmp r14, #0"); // check category filter
528 asm("addeq sp, sp, #4 ");
529 asm("moveq r0, #0 ");
530 asm("beq 0f "); // if category disabled, exit now
532 asm("mrs r14, cpsr ");
534 asm("and r12, r14, #0x0f ");
536 asm("movhi r12, #2 "); // r12 = context ID = 1 for FIQ, 2 for IRQ/ABT/UND/SYS
539 asm("cmp r12, #0 "); // r2 = context ID = 0 for early boot, no threads
541 asm("ldrb r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iInIDFC));
543 GET_RWNO_TID(eq,r12);
544 asm("ldreq r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread));
545 asm("movne r12, #3 "); // r12 = context ID = 3 for IDFC = NThread pointer for thread
547 asm("msr cpsr, r14 ");
548 asm("str r12, [sp, #-4]! "); // context ID
549 asm("bl " CSM_ZN6BTrace8DoOutBigEmmPKvimm);
550 asm("add sp, sp, #8");
554 asm("__BTraceLock: ");
555 asm(".word %a0" : : "i" ((TInt)&BTraceLock));
556 asm("__BTraceData: ");
557 asm(".word BTraceData ");
561 __NAKED__ EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
563 // fall through to OutFilteredX...
566 __NAKED__ EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
568 asm("stmdb sp!, {r2,r3,r4,lr}");
569 asm("ldr r12, __BTraceData");
570 asm("and r2, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
571 asm("mov r3, r1"); // r3 = a1 (ready for call to handler)
572 asm("ldrb r2, [r12, r2, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
577 // r0=header, r1=a1=secondary filter UID, r2=unused, r3=a1, r12->SBTraceData
578 // if trace enabled return r0,r1,r3 unmodified, r2=context value r12->handler, Z=0
579 // if trace disabled return r0=0 Z=1
580 asm("bl btrace_check_filter2 ");
582 __ASM_ACQUIRE_BTRACE_LOCK("{r0,r2,r3,r12}");
586 __ASM_RELEASE_BTRACE_LOCK();
588 __POPRET("r2,r3,r4,");
590 asm("btrace_check_filter2: ");
591 asm("stmfd sp!, {r0,r1,r3,r4,r12,lr} ");
593 asm("bl CheckFilter2__11SBTraceDataUl ");
596 asm("mrs r14, cpsr ");
598 asm("and r2, r14, #0x0f ");
600 asm("movhi r2, #2 "); // r2 = context ID = 1 for FIQ, 2 for IRQ/ABT/UND/SYS
603 asm("movs r2, r4 "); // r2 = context ID = 0 for early boot, no threads
605 asm("ldrb r2, [r4, #%a0]" : : "i" _FOFF(TSubScheduler,iInIDFC));
607 asm("ldreq r2, [r4, #%a0]" : : "i" _FOFF(TSubScheduler,iCurrentThread));
608 asm("movne r2, #3 "); // r2 = context ID = 3 for IDFC = NThread pointer for thread
610 asm("msr cpsr, r14 ");
612 asm("ldmfd sp!, {r0,r1,r3,r4,r12,lr} ");
613 asm("moveq r0, #0 ");
614 asm("ldrne r12, [r12, #%a0]" : : "i" _FOFF(SBTraceData,iHandler));
618 __NAKED__ EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
620 // fall through to OutFilteredNX...
623 __NAKED__ EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
625 asm("stmdb sp!, {r2,r3,r4,lr}");
626 asm("ldr r12, __BTraceData");
627 asm("and r2, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
628 asm("ldrb r2, [r12, r2, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
633 // r0=header, r1=a1=secondary filter UID, r2=unused, r3=aData, r12->SBTraceData
634 // if trace enabled return r0,r1,r3 unmodified, r2=context value r12->handler, Z=0
635 // if trace disabled return r0=0 Z=1
636 asm("bl btrace_check_filter2 ");
639 __ASM_ACQUIRE_BTRACE_LOCK("{r0-r3,r11,r12}");
640 asm("ldr r14, [sp, #16] "); // r14 = aDataSize
641 asm("cmp r14, #%a0" : : "i" ((TInt)KMaxBTraceDataArray));
642 asm("movhi r14, #%a0" : : "i" ((TInt)KMaxBTraceDataArray));
643 asm("orrhi r0, r0, #%a0" : : "i" ((TInt)(BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8))));
644 asm("add r0, r0, r14 ");
645 asm("subs r14, r14, #1 ");
646 asm("ldrhs r3, [r3] "); // get first word of aData if aDataSize!=0
648 asm("strlo r3, [sp, #4] "); // replace aData with first word if aDataSize is 1-4
649 asm("mov r3, r1 "); // r3 = a1 (ready for call to handler)
653 __ASM_RELEASE_BTRACE_LOCK();
655 __POPRET("r2,r3,r4,");
658 __NAKED__ EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
660 asm("stmdb sp!, {r4,lr} ");
661 asm("ldr r12, __BTraceData ");
662 asm("stmfd sp!, {r2,lr} "); // save aData, PC
663 asm("and r14, r0, #%a0" : : "i" ((TInt)(0xff<<(BTrace::ECategoryIndex*8))));
664 asm("ldrb r14, [r12, r14, lsr #%a0]" : : "i" ((TInt)(BTrace::ECategoryIndex*8)));
665 asm("cmp r14, #0 "); // check category filter
666 asm("blne btrace_check_filter2 "); // if enabled, check secondary filter
667 asm("addeq sp, sp, #8 ");
668 asm("moveq r0, #0 ");
669 asm("beq 9f "); // if category or secondary filter disabled, exit now
671 asm("ldr r2, [sp, #0] "); // restore aData into r2
672 asm("str r12, [sp, #0] "); // Context ID
673 asm("bl " CSM_ZN6BTrace8DoOutBigEmmPKvimm);
674 asm("add sp, sp, #8 ");
680 /******************************************************************************/
682 /** Save all the ARM registers
686 __NAKED__ void Arm::SaveState(SFullArmRegSet&)
688 asm("stmia r0, {r0-r14}^ "); // save R0-R7, R8_usr-R14_usr
689 asm("str lr, [r0, #60]! "); // save R15
690 asm("mrs r1, cpsr ");
691 asm("str r1, [r0, #4]! "); // save CPSR
692 asm("bic r2, r1, #0x1f ");
693 asm("orr r2, r2, #0xd3 "); // mode_svc, all interrupts off
694 asm("msr cpsr, r2 ");
695 asm("stmib r0!, {r13,r14} "); // save R13_svc, R14_svc
696 asm("mrs r3, spsr ");
697 asm("str r3, [r0, #4]! "); // save SPSR_svc
698 asm("bic r2, r1, #0x1f ");
699 asm("orr r2, r2, #0xd7 "); // mode_abt, all interrupts off
700 asm("msr cpsr, r2 ");
701 asm("stmib r0!, {r13,r14} "); // save R13_abt, R14_abt
702 asm("mrs r3, spsr ");
703 asm("str r3, [r0, #4]! "); // save SPSR_abt
704 asm("bic r2, r1, #0x1f ");
705 asm("orr r2, r2, #0xdb "); // mode_und, all interrupts off
706 asm("msr cpsr, r2 ");
707 asm("stmib r0!, {r13,r14} "); // save R13_und, R14_und
708 asm("mrs r3, spsr ");
709 asm("str r3, [r0, #4]! "); // save SPSR_und
710 asm("bic r2, r1, #0x1f ");
711 asm("orr r2, r2, #0xd2 "); // mode_irq, all interrupts off
712 asm("msr cpsr, r2 ");
713 asm("stmib r0!, {r13,r14} "); // save R13_irq, R14_irq
714 asm("mrs r3, spsr ");
715 asm("str r3, [r0, #4]! "); // save SPSR_irq
716 asm("bic r2, r1, #0x1f ");
717 asm("orr r2, r2, #0xd1 "); // mode_fiq, all interrupts off
718 asm("msr cpsr, r2 ");
719 asm("stmib r0!, {r8-r14} "); // save R8_fiq ... R14_fiq
720 asm("mrs r3, spsr ");
721 asm("str r3, [r0, #4]! "); // save SPSR_fiq
722 asm("bic r2, r1, #0x1f ");
723 asm("orr r2, r2, #0xd3 "); // mode_svc, all interrupts off
724 asm("msr cpsr, r2 ");
735 // monitor mode - skip for now
737 asm("stmib r0!, {r4-r6} "); // R13_mon, R14_mon, SPSR_mon
741 asm("stmib r0!, {r4-r11} ");
742 asm("add r0, r0, #4 "); // r0 = &a.iA
745 asm("mrc p14, 6, r3, c1, c0, 0 ");
749 asm("str r3, [r0], #4 "); // TEEHBR
750 #ifdef __CPU_HAS_COPROCESSOR_ACCESS_REG
755 asm("str r3, [r0], #4 "); // CPACR
757 // skip SCR, SDER, NSACR, PMCR, MVBAR for now
759 asm("stmia r0!, {r4-r8} "); // SCR, SDER, NSACR, PMCR, MVBAR
763 asm("stmia r0!, {r3-r11} "); // r0 = &a.iB[0]
765 // just fill in iB[0]
767 asm("mrc p15, 0, r3, c1, c0, 0 ");
768 asm("str r3, [r0], #4 "); // SCTLR
769 #ifdef __CPU_HAS_ACTLR
770 asm("mrc p15, 0, r3, c1, c0, 1 ");
774 asm("str r3, [r0], #4 "); // ACTLR
775 asm("mrc p15, 0, r3, c2, c0, 0 ");
776 asm("str r3, [r0], #4 "); // TTBR0
777 #ifdef __CPU_HAS_TTBR1
778 asm("mrc p15, 0, r2, c2, c0, 1 ");
779 asm("mrc p15, 0, r3, c2, c0, 2 ");
784 asm("stmia r0!, {r2,r3} "); // TTBR1, TTBCR
785 asm("mrc p15, 0, r3, c3, c0, 0 ");
786 asm("str r3, [r0], #4 "); // DACR
787 #ifdef __CPU_MEMORY_TYPE_REMAPPING
788 asm("mrc p15, 0, r2, c10, c2, 0 ");
789 asm("mrc p15, 0, r3, c10, c2, 1 ");
794 asm("stmia r0!, {r2,r3} "); // PRRR, NMRR
796 asm("mrc p15, 0, r3, c12, c0, 0 ");
800 asm("str r3, [r0], #4 "); // VBAR
801 #if defined(__CPU_SA1) || defined(__CPU_ARM920T) || defined(__CPU_ARM925T) || defined(__CPU_ARMV5T) || defined(__CPU_ARMV6) || defined(__CPU_ARMV7)
802 asm("mrc p15, 0, r3, c13, c0, 0 ");
806 asm("str r3, [r0], #4 "); // FCSEIDR
807 #if defined(__CPU_ARMV6) || defined(__CPU_ARMV7)
808 asm("mrc p15, 0, r3, c13, c0, 1 ");
812 asm("str r3, [r0], #4 "); // CONTEXTIDR
813 #ifdef __CPU_HAS_CP15_THREAD_ID_REG
822 asm("stmia r0!, {r2,r3,r12} "); // RWRWTID, RWROTID, RWNOTID
823 asm("mrc p15, 0, r2, c5, c0, 0 "); // DFSR
824 #ifdef __CPU_ARM_HAS_SPLIT_FSR
825 asm("mrc p15, 0, r3, c5, c0, 1 "); // IFSR
829 asm("stmia r0!, {r2,r3} "); // DFSR, IFSR
831 asm("mrc p15, 0, r2, c5, c1, 0 "); // ADFSR
832 asm("mrc p15, 0, r3, c5, c1, 1 "); // AIFSR
837 asm("stmia r0!, {r2,r3} "); // ADFSR, AIFSR
838 asm("mrc p15, 0, r2, c6, c0, 0 "); // DFAR
839 #ifdef __CPU_ARM_HAS_CP15_IFAR
840 asm("mrc p15, 0, r3, c6, c0, 2 "); // IFAR
844 asm("stmia r0!, {r2,r3} "); // DFAR, IFAR
847 asm("stmia r0!, {r4-r7} ");
848 asm("stmia r0!, {r4-r11} ");
849 #else // __CPU_HAS_MMU
850 asm("stmia r0!, {r4-r11} "); // no MMU so zero fill
851 asm("stmia r0!, {r4-r11} "); // no MMU so zero fill
852 asm("stmia r0!, {r4-r11} "); // no MMU so zero fill
853 asm("stmia r0!, {r4-r11} "); // no MMU so zero fill
854 #endif // __CPU_HAS_MMU
857 asm("stmia r0!, {r4-r11} ");
858 asm("stmia r0!, {r4-r11} ");
859 asm("stmia r0!, {r4-r11} ");
860 asm("stmia r0!, {r4-r11} "); // r0 = &a.iMore[0]
861 asm("add r1, r0, #62*8 "); // r1 = &a.iExcCode
866 // VFPv2 ONLY: FPINST FPINST2
867 // D0-D3 D4-D7 D8-D11 D12-D15
868 // VFPv3 ONLY: D16-D19 D20-D23 D24-D27 D28-D31
871 asm("bic r2, r2, #0x00f00000 ");
873 asm("bic r2, r2, #0xc0000000 "); // mask off ASEDIS, D32DIS
875 asm("orr r2, r2, #0x00500000 "); // enable privileged access to CP10, CP11
877 VFP_FMRX(,2,VFP_XREG_FPEXC); // r2=FPEXC
878 asm("orr r3, r2, #%a0" : : "i" ((TInt)VFP_FPEXC_EN));
879 asm("bic r3, r3, #%a0" : : "i" ((TInt)VFP_FPEXC_EX));
880 VFP_FMXR(,VFP_XREG_FPEXC,3); // enable VFP
881 __DATA_SYNC_BARRIER__(r4);
882 __INST_SYNC_BARRIER__(r4);
883 VFP_FMRX(,3,VFP_XREG_FPSCR); // r3=FPSCR
884 asm("stmia r0!, {r2,r3} "); //
886 VFP_FSTMIADW(CC_AL,0,0,16); // save D0 - D15
887 VFP_FMRX(,3,VFP_XREG_MVFR0);
888 asm("tst r3, #%a0" : : "i" ((TInt)VFP_MVFR0_ASIMD32)); // check to see if all 32 Advanced SIMD registers are present
889 VFP_FSTMIADW(CC_NE,0,16,16); // if so then save D15 - D31 (don't need to check CPACR.D32DIS as it is cleared above)
891 VFP_FMRX(,2,VFP_XREG_FPINST);
892 VFP_FMRX(,3,VFP_XREG_FPINST2);
893 asm("stmia r0!, {r2,r3} "); // FPINST, FPINST2
894 VFP_FSTMIADW(CC_AL,0,0,16); // save D0 - D15
896 #endif // __CPU_HAS_VFP
899 asm("strlo r4, [r0], #4 "); // clear up to end of iMore[61]
901 asm("mov r1, #%a0" : : "i" ((TInt)KMaxTInt));
902 asm("stmia r0!, {r1,r5-r7} "); // iExcCode=KMaxTInt, iCrashArgs[0...2]=0
903 asm("sub r0, r0, #1024 "); // r0 = &a
905 asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iMore[0]));
906 VFP_FMXR(,VFP_XREG_FPEXC,2); // restore FPEXC
907 __DATA_SYNC_BARRIER__(r4);
908 __INST_SYNC_BARRIER__(r4);
909 asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iA.iCPACR));
910 SET_CAR(,r2); // restore CPACR
912 asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iFlags));
913 asm("orr r1, r1, #0xC0 "); // interrupts off
914 asm("msr cpsr, r1 "); // restore CPSR with interrupts off
915 asm("ldmia r0, {r0-r11} "); // restore R4-R11
920 /** Update the saved ARM registers with information from an exception
924 __NAKED__ void Arm::UpdateState(SFullArmRegSet&, TArmExcInfo&)
926 asm("ldr r2, [r1, #%a0]" : : "i" _FOFF(TArmExcInfo, iExcCode));
927 asm("cmp r2, #%a0 " : : "i" ((TInt)EArmExceptionPrefetchAbort));
928 asm("ldmia r1!, {r2,r3,r12} ");
929 asm("streq r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iB[0].iIFAR));
930 asm("strne r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iB[0].iDFAR));
931 asm("streq r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iB[0].iIFSR));
932 asm("strne r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iB[0].iDFSR));
933 asm("str r12, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iSpsrSvc));
934 asm("add r1, r1, #4 ");
935 asm("ldmia r1!, {r2,r3,r12} ");
936 asm("str r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR13Svc));
937 asm("str r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR14Svc));
938 asm("str r12, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR0));
939 asm("ldmia r1!, {r2,r3,r12} ");
940 asm("str r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR1));
941 asm("str r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR2));
942 asm("str r12, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR3));
943 asm("ldmia r1!, {r2,r3,r12} ");
944 asm("str r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR4));
945 asm("str r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR5));
946 asm("str r12, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR6));
947 asm("ldmia r1!, {r2,r3,r12} ");
948 asm("str r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR7));
949 asm("str r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR8));
950 asm("str r12, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR9));
951 asm("ldmia r1!, {r2,r3,r12} ");
952 asm("str r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR10));
953 asm("str r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR11));
954 asm("str r12, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR12));
955 asm("ldmia r1!, {r2,r3,r12} ");
956 asm("str r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR13));
957 asm("str r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR14));
958 asm("str r12, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iExcCode));
959 asm("ldmia r1!, {r2,r3} ");
960 asm("str r2, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iR15));
961 asm("str r3, [r0, #%a0]" : : "i" _FOFF(SFullArmRegSet,iN.iFlags));
966 /** Get a pointer to a stored integer register, accounting for registers which
967 are banked across modes.
969 @param a Pointer to saved register block
970 @param aRegNum Number of register required, 0-15 or -1 (indicates SPSR)
971 @param aMode Bottom 5 bits indicate which processor mode
972 Other bits of aMode are ignored
973 @return Pointer to the required saved register value
977 __NAKED__ TArmReg* Arm::Reg(SFullArmRegSet& /*a*/, TInt /*aRegNum*/, TArmReg /*aMode*/)
979 asm("cmp r1, #8 "); // register number < 8 ?
980 asm("addlo r0, r0, r1, lsl #2 "); // register R0-R7 are not banked
982 asm("cmp r1, #15 "); // register number = 15 ?
983 asm("addeq r0, r0, r1, lsl #2 "); // register R15 not banked
984 asm("movgt r0, #0 "); // no registers > 15
987 asm("movlt r0, #0 "); // no registers < -1
989 asm("and r12, r2, #0x1F ");
990 asm("cmp r12, #0x11 "); // mode_fiq?
991 asm("beq 1f "); // skip if it is
993 asm("addlo r0, r0, r1, lsl #2 "); // register R8-R12 are only banked in mode_fiq
995 asm("cmp r12, #0x10 "); // mode_usr ?
996 asm("cmpne r12, #0x1F "); // if not, mode_sys ?
997 asm("bne 2f "); // skip if neither
999 asm("addlo r0, r0, r1, lsl #2 "); // handle R13_usr, R14_usr
1000 asm("movhs r0, #0 "); // no SPSR in mode_usr or mode_sys
1002 asm("1: "); // mode_fiq, regnum = 8-12
1003 asm("2: "); // exception mode, regnum not 0-12 or 15
1004 asm("cmn r1, #1 "); // regnum = -1 ?
1005 asm("moveq r1, #15 "); // if so, change to 15
1006 asm("sub r1, r1, #13 ");
1007 asm("add r0, r0, r1, lsl #2 "); // add 0 for R13, 4 for R14, 8 for SPSR
1008 asm("cmp r12, #0x16 ");
1009 asm("addeq r0, r0, #12 "); // if mon, add offset from R13Fiq to R13Mon
1010 asm("cmpne r12, #0x11 ");
1011 asm("addeq r0, r0, #32 "); // if valid but not svc/abt/und/irq, add offset from R13Irq to R13Fiq
1012 asm("cmpne r12, #0x12 ");
1013 asm("addeq r0, r0, #12 "); // if valid but not svc/abt/und, add offset from R13Und to R13Irq
1014 asm("cmpne r12, #0x1b ");
1015 asm("addeq r0, r0, #12 "); // if valid but not svc/abt, add offset from R13Abt to R13Und
1016 asm("cmpne r12, #0x17 ");
1017 asm("addeq r0, r0, #12 "); // if valid but not svc, add offset from R13Svc to R13Abt
1018 asm("cmpne r12, #0x13 ");
1019 asm("addeq r0, r0, #%a0" : : "i" _FOFF(SFullArmRegSet, iN.iR13Svc)); // if valid mode add offset to R13Svc
1020 asm("movne r0, #0 ");
1026 /** Restore all the ARM registers
1030 __NAKED__ void Arm::RestoreState(SFullArmRegSet&)
1034 __NAKED__ EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 a0, TUint32 aModuleUid, TUint32 aPc, TUint16 aFormatId, const TAny* aData, TInt aDataSize)
1036 asm("mov r0, #0"); //Kernel side not implemented yet