繁体   English   中英

为什么hvc使Undefined指令异常?

[英]Why does hvc make Undefined instruction exception?

我正在用ARMv7-A汇编语言编写程序。 我想使用Virtualization Extension并在不安全的环境中使用处理器模式PL2。

因此,我使用hvc指令如下:

  1. 以安全PL1(SVC)模式启动。
  2. 设置MVBAR和VBAR。
  3. 使用smc指令并进入监视模式。
  4. 在监视模式下,将SCR.NS位置1,将HVBAR设置为1,并将异常返回。
  5. 使处理器模式为SVC。
  6. 致电hvc

编码

    .text

    .section .eitbra , "ax"
    // non-secure vector table
    .org    0x00000000
    b   startup_entry       // 00 : reset
    b   default_entry       // 04 : undefined instruction exception
    b   default_entry       // 08 : supervisor call (SVC)
    b   default_entry       // 0C : prefetch abort
    b   default_entry       // 10 : data abort
    nop                     // 14 : (reserved)
    b   default_entry       // 18 : interrupt
    b   default_entry       // 1C : fast interrupt
    .org    0x00000020
    // secure vector table
secure_vector:
    b   startup_entry       // 00 : reset
    b   default_entry       // 04 : undefined instruction exception
    b   default_entry       // 08 : supurvisor call (SVC)
    b   default_entry       // 0C : prefetch abort
    b   default_entry       // 10 : data abort
    nop                     // 14 : (reserved)
    b   default_entry       // 18 : interrupt
    b   default_entry       // 1C : fast interrupt
    .org    0x00000040
hyper_vector:
    // hyper vector table
    nop                     // 00 : reset
    b   default_entry       // 04 : undefined instruction exception
    b   default_entry       // 08 : hyper call from hyper mode
    b   default_entry       // 0C : prefetch abort
    b   default_entry       // 10 : data abort
    b   hyper_entry         // 14 : hyper call from non-secure world (HVC)
    b   default_entry       // 18 : interrupt
    b   default_entry       // 1C : fast interrupt
    .org    0x00000060
monitor_vector:
    // monitor vector table
    nop                     // 00 : (reserved)
    nop                     // 04 : (reserved)
    b   hyper_init          // 08 : monitor call
    b   default_entry       // 0C : prefetch abort
    b   default_entry       // 10 : data abort
    nop                     // 14 : (reserved)
    b   default_entry       // 18 : interrupt
    b   default_entry       // 1C : fast interrupt
    .org    0x00000080

startup_entry:
    // set cpsr
    mov r0, #(PSM_SVC | CPSR_I | CPSR_F)
    msr cpsr, r0

    // set vector base address
    ldr r1, =secure_vector
    mcr p15, 0, r1, c12, c0, 0  // VBAR
    ldr r1, =monitor_vector
    mcr p15, 0, r1, c12, c0, 1  // MVBAR

    // move to monitor mode and restart as non-secure world
    smc #0

  nonsecure_init:
    ldr r1, =_start
    mcr p15, 0, r1, c12, c0, 0  // VBAR
    // set cpsr
    mrs r0, cpsr
    mov r0, #(PSM_SVC | CPSR_I | CPSR_F)
    msr cpsr, r0

    // hyper call test
    hvc #0

    b default_entry


hyper_init:
    mrc p15, 0, r0, c1, c1, 0   //read scr
    orr r0, r0, #1  // set NS bit
    mcr p15, 0, r0, c1, c1, 0   //set scr
    mrs r0, cpsr

    ldr r0, =hyper_vector
    mcr p15, 4, r0, c12, c0, 0  // HVBAR
    movs pc, lr

hyper_entry:
    ldr sp, =_stack_start+0x50
    eret
default_entry:
    nop
    mrs r0, cpsr
    nop
    wfi
    b default_entry

但是,在hvc指令中,发生了未定义的指令异常。 此代码是从TWR-LS1021A板(Cortex-A7)上的U-Boot控制台( go命令)调用的。

任何人都知道导致此问题/如何解决的原因吗?

我自己解决。 我没有设置SCR.HCE位。 如果未设置此位,则即使在非安全PL1模式下, hvc指令也未定义。 设置该位后,发生超级异常。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM