| |||
| Home > Debug > Debugging systems with energy management capabilities > Operating system support | |||
The OS Save and Restore Registers enable an operating system to save the debug registers before power down and to recover them after power up. The debugger and the debug monitor are prevented from accessing the debug registers from the time the OS starts saving the registers through power down, until they are restored after power up. This behavior minimizes the possibility of race conditions and therefore, increases the chances that the debug agent is able to resynchronize successfully after the OS completes the restore.
Example 12.30 shows the sequence on power down of an operating system.
Example 12.30. OS debug register save sequence
; On entry, r0 points to a block of memory to save the debug registers.
SaveDebugRegisters
PUSH {r4, lr}
MOV r4, r0 ; save pointer
; Step 1. Set the OS Lock Access Register (OSLAR).
BL GetDebugRegisterBase ; returns base in R0
LDR r1, =0xC5ACCE55
STR r1, [r0, 0x300] ; write OSLAR
; Step 2. Get the number of words to save.
LDR r1, [r0, 0x308] ; OSSRR returns size on first read
; Step 3. Loop reading words from the OSSRR.
1 LDR r2, [r0, 0x308] ; load a word of data
STR r2, [r4], 4 ; push onto the save stack
SUBS r1, r1, 1
BNE%B1 ; loop
; Step 4. Return the pointer to the first word not written and
; leave the OSLAR set because no further changes are required.
MOV r0, r4
POP {r4, pc}
Example 12.31 shows the sequence on power up of an operating system.
Example 12.31. OS debug register restore sequence
; On entry, r0 points to a block of saved debug registers.
RestoreDebugRegisters
PUSH {r4, lr}
MOV r4, r0 ; save pointer
; Step 1. Get the number of words saved.
BL GetDebugRegisterBase ; returns base in R0
LDR r1, [r0, 0x308] ; OSSRR returns size on first read
; Step 2. Loop writing words from the OSSRR.
1 LDR r2, [r4], 4 ; load a word from the save stack
STR r2, [r0, 0x308] ; store a word of data
SUBS r1, r1, 1
BNE%B1 ; loop
; Step 3. Clear the OS Lock Access Register (OSLAR).
LDR r1, =0xC5ACCE55
STR r1, [r0, 0x300] ; write OSLAR
; Step 4. Return the pointer to the first word not written.
MOV r0, r4
POP {r4, pc}
When the OSLAR is cleared, a debug event is triggered if the OS unlock catch bit is set to 1. This can be useful for a debugger to restart a debugging session.