Hardware-Assisted Breakpoints

by Dmitri Leman





Listing One



; SetDebugControlAndStatus writes (optionally) to 

; Debug Control and Status Register (DCSR)

; and returns the original value of DCSR.

; parameters: 

;   r0: flags to be set or reset in DCSR.

;   r1: mask - flags to be modified in DCSR, the rest is preserved.

; return value: 

;   value of DCSR before the modification



    EXPORT    |SetDebugControlAndStatus|

|SetDebugControlAndStatus| PROC

    stmdb   sp!, {r2,lr}   ; save registers

    mrc     p14, 0, r2, c10, c0, 0 ; read DCSR to r2

    and     r0, r0, r1     ; r0 = r0 & r1 - clear flags not in mask

    bic     r1, r2, r1     ; r1 = r2 & ~r1 - leave flags not in mask

    orr     r0, r0, r1     ; r0 = r0 | r1 - combine flags

    cmp     r0, r2         ; compare new with original

    mcrne   p14, 0, r0, c10, c0, 0 ; write DCSR if flags have changed

    mov     r0, r2         ; prepare to return the original flags

    ldmia   sp!, {r2,pc}   ; restore the registers and return 











1



