_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)
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寄存器为重定位后的中断向量表起始地址。