ARM64 Exception vectors

来源:互联网 发布:网络诈骗5000元判缓刑 编辑:程序博客网 时间:2024/06/05 19:14
ARM64 异常向量即 Exception vectors
参见源D1.10.2描述。
When the PE takes an exception to an Exception level that is using AArch64, execution is forced to an address thatis the exception vector for the exception. The exception vector exists in a vector table at the Exception level theexception is taken to.
当PE发生异常在某一个异常级别时候,执行被强制跳转到一个地址即异常向量地址处。异常向量存在异常向量表中。每当异常发生时,自动跳转到异常向量中执行。A vector table occupies a number of consecutive word-aligned addresses in memory, starting at the vector baseaddress.
一个异常向量一般位于内存中,并且这些异常向量有个基地址,叫做VBA。Each Exception level has an associated Vector Base Address Register (VBAR), that defines the exception baseaddress for the table at that Exception level.
每个异常级别都有一个VBAR,即保存异常向量表基地址。通过此基地址,我们找到异常向量。
由于ARM64有四个异常级别,显然有四个VBAR。
 
对于每种异常级别来说,当异常发生时,PE能识别的异常种类如下:
— Synchronous exception.  同步异常— SError. 系统error— IRQ.   普通中断— FIQ.   快速中断
当异常发生时,我们必须能获取一些状态信息,比如当前PE所处的EL。如EL1,EL0等。
根据异常级别我们需要给出使用的SP,以及其他一些寄存器等。
我们看下面一些数据描述:
Exception taken from                   Offset for exception type
                        Synchronous :IRQ or vIRQ :FIQ or vFIQ :SError or vSError
Current Exception level with SP_EL0     0x000   :0x080           :0x100        :    0x180
 
Current Exception level with SP_ELx, x>0   0x200 :0x280            : 0x300     :    0x380
 
Lower Exception level, 
where the implemented levelimmediately lower than the target level   0x400 : 0x480           : 0x500       :0x580
is using AArch64
 
Lower Exception level, where the 
implemented levelimmediately lower than the target level  0x600 : 0x680            : 0x700 :     0x780
is using AArch32.a
 
其实对于reset复位来说,ARM64定义了一个特殊的复位向量,这个值保存到RVBAR_ELx中,x是每种异常级别对应一个RVBAR寄存器。这样的话,通过
配置RVBAR_ELx寄存器,可以让复位时运行一个特殊的向量,或者干脆就让从某个地址开始运行。
 
从ARM64来看,复位reset后,处理器处于最高优先级级别。并且,复位后只能是处于最高异常级别,所以,如果实现了EL3,则复位一定跳转到EL3中。
这样从最高优先级开始运行。
这样的话,如果没有实现EL3,那就是EL2,或者EL1。但总不能EL0吧。
RVBAR_EL1:
  RVBAR_EL1 is a 64-bit register;
  Bits [63:0] 复位地址
     Reset Address. The IMPLEMENTATION DEFINED address that execution starts from after reset whenexecuting in 64-bit state. Bits[1:0] of this register are 00, as this address must be aligned, and theaddress must be within the physical address size supported by the PE.
     四字节对其,并且物理可寻址。
To access the RVBAR_EL1:MRS <Xt>, RVBAR_EL1 ; Read RVBAR_EL1 into Xt
 
与此类似的还有:
RVBAR_EL2, Reset Vector Base Address Register (if EL3 not implemented)
RVBAR_EL3, Reset Vector Base Address Register (if EL3 implemented)
 
 
根据以上信息,我们可以得到一些更有用的信息:
1. 每个处理器运行级别下异常发生时跳转是不一样的。EL0是以0x80为偏移。
2. 如果要实现异常处理中断函数,必须考虑每个异常基地址问题。
3. 硬件约束导致软件想扩展异常是不可能的。
根据上面信息,ARM64在Linux内核中定义的向量表如下:

 .text

/* * Exception vectors. */

 .align 11ENTRY(vectors) ventry el1_sync_invalid  // Synchronous EL1t ventry el1_irq_invalid   // IRQ EL1t ventry el1_fiq_invalid   // FIQ EL1t ventry el1_error_invalid  // Error EL1t

 ventry el1_sync   // Synchronous EL1h ventry el1_irq    // IRQ EL1h ventry el1_fiq    // FIQ EL1h ventry el1_error_invalid  // Error EL1h

 ventry el0_sync   // Synchronous 64-bit EL0 ventry el0_irq    // IRQ 64-bit EL0 ventry el0_fiq    // FIQ 64-bit EL0 ventry el0_error_invalid  // Error 64-bit EL0

#ifdef CONFIG_COMPAT ventry el0_sync_compat   // Synchronous 32-bit EL0 ventry el0_irq_compat   // IRQ 32-bit EL0 ventry el0_fiq_compat   // FIQ 32-bit EL0 ventry el0_error_invalid_compat // Error 32-bit EL0#else ventry el0_sync_invalid  // Synchronous 32-bit EL0 ventry el0_irq_invalid   // IRQ 32-bit EL0 ventry el0_fiq_invalid   // FIQ 32-bit EL0 ventry el0_error_invalid  // Error 32-bit EL0#endifEND(vectors)

可以看到,向量表基地址是2^11即低11位为0,说明按照2048字节对齐。
每个向量采用的对齐方式,这里ventry实现如下:
/* * Vector entry */  .macro ventry label .align 7 b \label .endm可以看到,这样的话,每个向量是2^7即128字节对齐,低7位为0.
这个跟上面硬件约束0x000:0x080:0x100:0x180向对应。
并且可以发现,不同PE级别的异常异常向量地址是连续增加的,这样便于软件设计。
这样的话,vector也就是一个数组。每个元素按照0x80对齐。
所以,这个vectors中每个元素不能乱动,打乱顺序。
并且,对于硬件给出的偏移地址来说,这些地址都是基于同一个VBA来说的,这样的话,每个
VBAR.ELx应该是同一个值。这又简化了软件设计,因为我们只需要把一个VBA设置到不同的
VBAR.el0,VBAR.el1,,VBAR.el2,,VBAR.el3中即可。
如果是EL0中发生异常,那么就偏移小些,前面四个即可。如果EL1则有简单偏移。
 
更进一步我们可以看到,不管哪种异常,reset导致的是最高优先级异常。至于reset从哪里运行,则由RVBAR控制。可以了解平台实现。
 
 
 
 
 
  
 
 
 
0 0