This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

有关C6713芯片BOOT.asm的问题



今天在看C76713一个工程中的BOOT相关的代码时,发现有以下代码,表示没有看懂是在干嘛,还请高手指点一下。


; ; ======== boot_c671x.s62 ======== ; .title "Flash bootup utility" .option D,T .length 102 .width 140 _text_size .equ 0x0002D120 _text_ld_start .equ 0x90001000 _text_rn_start .equ 0x00001000 .sect ".boot_load" ;地址段定义 .global _boot .global _text_size .global _text_ld_start .global _text_rn_start .ref _c_int00 _boot: ;************************************************************************ ;* DEBUG LOOP - COMMENT OUT B FOR NORMAL OPERATION ;************************************************************************ ;接下来的4行是在干嘛?完全没用? zero B1 _myloop: ; [!B1] B _myloop nop 5 _myloopend: nop ;************************************************************************ ;* CONFIGURE EMIF ;************************************************************************ ;**************************************************************** ; *EMIF_GCTL = EMIF_GCTL_V; ;**************************************************************** mvkl EMIF_GCTL,A4 ;将EMIF全局控制寄存器基地址低16位写入A4寄存器低16位, ;因mvkl带符号位扩展,因此该语句必须先于mvkh || mvkl EMIF_GCTL_V,B4 ;将EMIF全局控制寄存器配置参数低16位写入B4寄存器低16位 mvkh EMIF_GCTL,A4 ;将EMIF全局控制寄存器基地址高16位写入A4寄存器高16位 || mvkh EMIF_GCTL_V,B4 ;将EMIF全局控制寄存器配置参数高16位写入B4寄存器高16位 ;两条指令并行执行 stw B4,*A4 ;将B4值写入A4指向地址存储空间 ;**************************************************************** ; *EMIF_CE1 = EMIF_CE1_V (setup for 8-bit async) ;**************************************************************** mvkl EMIF_CE1,A4 ;将EMIF CE1寄存器地址低16位写入A4寄存器低16位 || mvkl EMIF_CE1_V,B4 ;将EMIF CE1寄存器配置参数低16位写入B4寄存器低16位 ;两条指令并行执行 mvkh EMIF_CE1,A4 ;将EMIF CE1寄存器地址高16位写入A4寄存器高16位 || mvkh EMIF_CE1_V,B4 ;将EMIF CE1寄存器配置参数高16位写入A4寄存器高16位 ;两条指令并行执行 stw B4,*A4 ;将B4值写入A4指向地址存储空间 ;**************************************************************************** ; copy sections ;**************************************************************************** mvkl copyTable, a3 ; load table pointer mvkh copyTable, a3 copy_section_top: ;读取一组table信息 ldw *a3++, b0 ; byte count ldw *a3++, b4 ; load flash start (load) address ldw *a3++, a4 ; ram start address nop 2 ;如b0==0,则跳转到copy_done处开始执行 [!b0] b copy_done ; have we copied all sections? nop 5 ; copy_loop: ldb *b4++,b5 ;从b4地址所在区域读取一字节数据到B5寄存器 sub b0,1,b0 ; decrement counter,B0减1 [ b0] b copy_loop ; b0不为零,则跳转到copy_loop处继续执行. ; 问题:b5只是一个寄存器,这里跳转回copy_loop处, ; 不是等同于直接把b4指向的数据简直的load到b5,然后全部丢掉了?? [!b0] b copy_section_top ;b0==0,则跳转到copy_section_top处执行 ;接下来的三行是想干什么啊? zero a1 ;将a1初始化为0 [!b0] and 3,a3,a1 ;如果b0 ==0, 则将3和a3进行位与操作,赋值到a1 ;为什么现在开始搬移数据到a4指向地址中去?而不是在前面83行之前处开始搬移? stb b5,*a4++ ;将b5寄存器里的值存入到a4指向地址 ;接下来两行没看懂什么意思啊是? [!b0] and -4,a3,a5 ; round address up to next multiple of 4 [ a1] add 4,a5,a3 ; round address up to next multiple of 4 ;**************************************************************************** ; jump to entry point ;**************************************************************************** copy_done: mvkl .S2 _c_int00, B0 ; mvkh .S2 _c_int00, B0 ; b .S2 B0 ;跳转到c_init00入口地址开始执行 nop 5 copyTable: ; count ; flash start (load) address ; ram start (run) address ;; .text .word _text_size .word _text_ld_start .word _text_rn_start ;; end of table .word 0 .word 0 .word 0

调用的c6713_emif.s62文件内容如下:

;
;  ======== c6713_emif.s62 ========
;
            .title  "Flash bootup utility"

; global EMIF symbols defined for the c671x family
            .include        boot_c671x.h62

;EMIF Register Addresses for c671x family  
EMIF_GCTL       .equ  0x01800000  ;EMIF global control
EMIF_CE0        .equ  0x01800008  ;EMIF CE0control
; EMIF Register Values specifically for 6713 DSK
EMIF_GCTL_V     .equ  0x000030E0  ;
EMIF_CE1_V      .equ  0xffffff13  ;EMIF CE1 Flash 8-bit

使用到的头内容如下:

;
;  ======== boot_c671x.h62 ========
;

	.if ($isdefed("BOOT_C671X_") = 0)  ; prevent multiple includes of this file
BOOT_C671X_	.set	1

; EMIF Register Addresses for c671x family         
        .global EMIF_GCTL         ;EMIF global control
        .global EMIF_CE1          ;address of EMIF CE1 control reg.

; EMIF Register Values for c671x family
        .global EMIF_GCTL_V       ;
        .global EMIF_CE1_V        ;EMIF CE1 Flash 8-bit

	.endif		; if BOOT_C671X_ is not defined


以上代码也在附件中。
question.rar
  • 这里要结束指令的delay slots来看,比如下ldb与stb其实是对应的取数与写数的对对操作,但是ldb后有4个delay slot,中间需要4个nop,所以插入了其它一些操作来充分利用了这个空隙。b指令需要5个slot,所以在判断b0为0后可以插入其它一些操作来把a3指针按4字节对齐处理(这里跟boot table 格式有关)。

    关于指令的delay slot请参考文档sprufe8。

    copy_loop:
    ldb *a3++,b5
    sub b0,1,b0 ; decrement counter
    [ b0] b copy_loop ; setup branch if not done
    [!b0] b copy_section_top
    zero a1
    [!b0] and 3,a3,a1
    stb b5,*a4++
    [!b0] and -4,a3,a5 ; round address up to next multiple of 4
    [ a1] add 4,a5,a3 ; round address up to next multiple of 4

  • 所以这段代码的执行流程其实是这样的:

    当执行到 ldb *a3++, b5这行时,因为有四个周期的等待,在这段等待时间内,执行了以下四条语句:

    sub b0,1,b0 ; decrement counter
    [ b0] b copy_loop ; setup branch if not done
    [!b0] b copy_section_top
    zero a1
    [!b0] and 3,a3,a1


    在执行上面语句时,因为执行到了b指令准备跳转,而该指令需要5个周期的等待,因此,在此等待期间又开始执行以下语句:

    stb b5, *a4++

    [!b0] and -4,a3,a5 ; round address up to next multiple of 4
    [ a1] add 4,a5,a3 ; round address up to next multiple of 4


    这样理解的对不对?

  • 另外,代码最顶端中如下三行起什么作用?

    .option D,T

    .length 102

    .width 140

    这三行分别起什么作用?

  • Mecca King 说:

    .option D,T

    .length 102

    .width 140

    这三行分别起什么作用?

    参考文档spru186w table 4-4