I have a couple of questions about the example code in the AM335x TRM (section 3.1.4.2.2) demonstrating the use of a Secure Monitor Call to enable the L2 cache ECC. This is the code:
_enableL2ECC:
STMFD sp!, {r0 - r4} ; save context of R0-R4, which secure monitor call may use
MRC p15, #1, r0, c9, c0, #2 ; Read L2 Cache Auxiliary Control Reg into R0
MOV r1, #0 ; Clear R1
MOVT r1, #0x1020 ; enable mask for ECC (set bits 21 and 28 to enable ECC)
ORR r0, r0, r1 ; OR with original register value
MOV r12, #0x0102 ; setup service ID in R12
MCR p15,#0x0,r1,c7,c5,#6 ; invalidate entire branch predictor array
DSB ; data synchronization barrier operation
ISB ; instruction synchronization barrier operation
DMB ; data memory barrier operation
SMC #1 ; secure monitor call SMC (previously SMI)
LDMFD sp!, {r0 - r4} ; after returning from SMC, restore R0-R4
MOV pc, lr ; return
My questions are:
- The code uses register r12, yet this isn't saved nor restored at the start/end of the code. Is this an error?
- In the MCR command used to invalidate the branch predictor array, does register r1 serve any purpose? Does its value matter?
Thanks.