简体   繁体   English

如何确定执行是在线程模式下发生还是异常处于活动状态? (ARMv7-A 架构)

[英]How can I determin if execution takes place in thread mode or if an exception is active? (ARMv7-A architecture)

I am using FreeRTOS on an ARM Cortex A9 CPU und I'm desperately trying to find out if it is possible to determin if the processor is executing a normal thread or an interrupt service routine.我在ARM Cortex A9 CPU 上使用 FreeRTOS,我拼命想知道是否可以确定处理器是在执行普通线程还是中断服务例程。 It is implemented in V7-a architecture.它是在 V7-a 架构中实现的。

I found some promising reference hinting the ICSR register (-> VECTACTIVE bits), but this only exist in the cortex M family.我发现了一些暗示 ICSR 寄存器(-> VECTACTIVE 位)的有希望的参考,但这仅存在于 cortex M 系列中。 Is there a comparable register in the A family as well? A 族也有类似的登记册吗? I tried to read out the processor modes in the current processor status register ( CPSR ), but when read during an ISR I saw that the mode bits indicate supervisor mode rather than IRQ or FIQ mode.我试图读出当前处理器状态寄存器 ( CPSR ) 中的处理器模式,但是在 ISR 期间读取时,我看到模式位指示管理模式而不是 IRQ 或 FIQ 模式。

Looks a lot like there is no way to determine in which state the processor is, but I wanted to ask anyway, maybe I missed something...看起来很像没有办法确定处理器处于哪种状态,但我还是想问一下,也许我错过了什么......

The processor has a pl390 General Interrupt Controller.处理器有一个pl390通用中断控制器。 Maybe it is possible to determine the if an interrupt has been triggered by reading some of it's registers?也许可以通过读取某些寄存器来确定是否触发了中断?

If anybody can give me a clue I would be very greatfull!如果有人能给我一个线索,我会非常高兴!

Thanks!谢谢!

On a Cortex-A processor, when an interrupt handler is triggered , the processor enters IRQ mode, with interrupts disabled. 在 Cortex-A 处理器上,当中断处理程序被触发时,处理器进入 IRQ 模式,中断被禁用。 This is reflected in the state field of CPSR.这体现在 CPSR 的状态字段中。 IRQ mode is not suitable to receive nested interrupts, because if a second interrupt happened, the return address for the first interrupt would be overwritten. IRQ 模式不适合接收嵌套中断,因为如果发生第二个中断,第一个中断的返回地址将被覆盖。 So, if an interrupt handler ever needs to re-enable interrupts, it must switch to supervisor mode first.因此,如果中断处理程序需要重新启用中断,它必须首先切换到管理模式。

Generally, one of the first thing that an operating system's interrupt handler does is to switch to supervisor mode.通常,操作系统的中断处理程序做的第一件事就是切换到管理模式。 By the time the code reaches a particular driver, the processor is in supervisor mode.当代码到达特定驱动程序时,处理器处于管理模式。 So the behavior you're observing is perfectly normal.所以你观察到的行为是完全正常的。

A FreeRTOS interrupt handler is a C function. FreeRTOS 中断处理程序是一个 C 函数。 It runs with interrupts enabled, in supervisor mode.它在启用中断的情况下在主管模式下运行。 If you want to know whether your code is running in the context of an interrupt handler, never call the interrupt handler function directly, and when it calls auxiliary functions that care, pass a variable that indicates who the caller is.如果你想知道你的代码是否在中断处理程序的上下文中运行,千万不要直接调用中断处理程序函数,当它调用关心的辅助函数时,传递一个变量来指示调用者是谁。

void code_that_wants_to_know_who_called_it(int context) {
    if (context != 0)
        // called from an interrupt handler
    else
        // called from outside an interrupt handler
}

void my_handler1(void) {
    code_that_wants_to_know_who_called_it(1);
}
void my_handler2(void) {
    code_that_wants_to_know_who_called_it(1);
}

int main(void) {
    Install_Interrupt(EVENT1, my_handler1);
    Install_Interrupt(EVENT2, my_handler1);
    code_that_wants_to_know_who_called_it(0);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ARMv7-A架构实现出现IRQ异常时如何计算LR值 - How to calculate the LR value when ARMv7-A architecture implementation takes an IRQ exception 如何在ARMV4i架构上模拟Windows CE 5.0 - How to emulate Windows CE 5.0 on ARMV4i architecture 为什么 ARMv7-A 在从缓存中刷新堆栈指针时会崩溃 - Why ARMv7-A crashes when flushing the stack pointer from the cache ld无法为架构armv7映射文件errno = 22 - ld can't map file errno=22 for architecture armv7 Mac上的iOS模拟器是运行i386架构,而不是armv7? - iOS simulator on mac is running i386 architecture, not armv7? 如何在ARMv8中将ERET转换为相同的异常级别? - How to ERET to the same exception level in ARMv8? 如何将armv6 / armv7架构更改为armv6会影响我的iPad应用程序?是否会出现性能/稳定性损失? - How does changing armv6/armv7 architecture to armv6 affect my iPad app? Will there be performance/stability losses? 当我尝试在 Armv8 程序集中分配数组时执行冻结 - Execution freezes when I try to allocate Array in Armv8 assembly 当前的执行模式/异常级别等是什么? - what is the current execution mode/exception level, etc? 如何在armv7中使用ELR_Hyp从hyp模式切换回svc模式 - how to switch back to svc mode from hyp mode using ELR_Hyp in armv7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM