Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
640 views
in Technique[技术] by (71.8m points)

arm - TrustZone monitor mode and IFAR, IFSR, DFAR, DFSR

The ARM TrustZone monitor mode can trap aborts in monitor mode. The monitor mode always executes in the secure world or context. How can we know what address and reason caused a fault in the normal world when it traps to the monitor mode instruction abort and data fault vectors?

The IFSR, IFAR, DFSR and DFAR are banked CP15 registers.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is worth noting that only external aborts can be configured to be taken in monitor mode, so MMU access faults will not be trapped.

As for the main question: the state of all Secure/Non-secure banked registers while in monitor mode is controlled by the state of the cp15 Secure Configuration Register NS bit: when it is set, you access Non-secure versions, and when it is clear you access Secure versions.

The following is some inline gcc code which allows any secure world mode to inspect these CP15 registers.

    #define MODE_MONITOR 0x16
    unsigned int mode;
    unsigned int world;
    unsigned int dfar;
    unsigned int dfsr;
    unsigned int ifar;
    unsigned int ifsr;

    asm (" mrs %0, cpsr
"                 /* Save mode. */
         " mrc p15, 0, %1, c1, c1, 0
"
         " orr  %1, %1, #1
"              /* Set NS bit in SCR. */
         " cpsid aif, %6
"                /* To monitor mode... */
         " mcr p15, 0, %1, c1, c1, 0
"
         " mrc p15, 0, %2, c6, c0, 0
"
         " mrc p15, 0, %3, c5, c0, 0
"
         " mrc p15, 0, %4, c6, c0, 2
"
         " mrc p15, 0, %5, c5, c0, 1
"
         " bic  %1, %1, #1
"              /* Clear NS bit in SCR. */
         " mcr  p15, 0, %1, c1, c1, 0
"
         " isb
"
         " msr cpsr, %0
"
         : "=&r" (mode), "=&r" (world),
           "=r"(dfar), "=r"(dfsr),
           "=r"(ifar), "=r"(ifsr)
         : "I" (MODE_MONITOR));
    printf("DFAR: %.8x dfsr: %.8x IFAR: %.8x ifsr: %.8x
",
           dfar, dfsr, ifar, ifsr);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...