uboot-重定位中断向量表 relocate_vectors 函数

 一.  uboot启动流程

_main 函数中,调用完 relocate_code 函数,即执行了uboot重定位后,开始执行relocate_vectors 函数。

本文学习 relocate_vectors 函数,uboot的重定位中断向量表。

二.  重定位中断向量表

_main 函数在 uboot的  /arch/arm/lib/crt0.S 文件中。如下:

	b	relocate_code
here:
/*
 * now relocate vectors
 */
    bl	relocate_vectors

函数 relocate_vectors 用于重定位向量表,此函数定义在文件 relocate.S 中。

代码如下:

27 ENTRY(relocate_vectors)
28
29 #ifdef CONFIG_CPU_V7M
30 /*
31 * On ARMv7-M we only have to write the new vector address
32 * to VTOR register.
33 */
34 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
35 ldr r1, =V7M_SCB_BASE
36 str r0, [r1, V7M_SCB_VTOR]
37 #else
38 #ifdef CONFIG_HAS_VBAR
39 /*
40 * If the ARM processor has the security extensions,
41 * use VBAR to relocate the exception vectors.
42 */
43 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
44 mcr p15, 0, r0, c12, c0, 0 /* Set VBAR */
45 #else
46 /*
47 * Copy the relocated exception vectors to the
48 * correct address
49 * CP15 c1 V bit gives us the location of the vectors:
50 * 0x00000000 or 0xFFFF0000.
51 */
52 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
53 mrc p15, 0, r2, c1, c0, 0 /* V bit (bit[13]) in CP15 c1 */
54 ands r2, r2, #(1 << 13)
55 ldreq r1, =0x00000000 /* If V=0 */
56 ldrne r1, =0xFFFF0000 /* If V=1 */
57 ldmia r0!, {r2-r8,r10}
58 stmia r1!, {r2-r8,r10}
59 ldmia r0!, {r2-r8,r10}
60 stmia r1!, {r2-r8,r10}
61 #endif
62 #endif
63 bx lr
64
65 ENDPROC(relocate_vectors)

29 行,如果定义了 CONFIG_CPU_V7M 的话就执行第 30~36 行的代码,这是 Cortex-M内核单片机执行的语句,因此对于 I.MX6ULL 来说是无效的。
38 行,如果定义了 CONFIG_HAS_VBAR 的话就执行此语句,这个是向量表偏移, Cortex- A7 是支持向量表偏移的。而且,在 .config 里面定义了 CONFIG_HAS_VBAR ,因此会执行这个
分支。
43 行, r0=gd->relocaddr ,也就是重定位后 uboot 的首地址,向量表肯定是从这个地址开 始存放的。
44 行,将 r0 的值写入到 CP15 VBAR 寄存器中,也就是将新的向量表首地址写入到 寄存器 VBAR 中,设置向量表偏移。

总结:

relocate_vectors 函数可以看出,对于 IMX6ULL芯片而言,因为属于 Cortex-A7架构,所以,这个函数中只执行了两行:

#ifdef CONFIG_HAS_VBAR
39 /*
40 * If the ARM processor has the security extensions,
41 * use VBAR to relocate the exception vectors.
42 */
43 ldr r0, [r9, #GD_RELOCADDR] /* r0 = gd->relocaddr */
44 mcr p15, 0, r0, c12, c0, 0 /* Set VBAR */

relocate_vectors 函数主要做的事:设置 VBAR寄存器为重定位后的中断向量表起始地址。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值