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.

[参考译文] TMS320F28386S:复位堆栈指针和 PC

Guru**** 2386610 points
请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1195172/tms320f28386s-resetting-the-stack-pointer-and-pc

器件型号:TMS320F28386S

我正在将代码从闪存复制到 RAM、在复制代码后、我希望重置堆栈指针。

从能够了解 cmd 文件中设置的地址的正在运行的程序中执行此操作的首选方法是什么?

我看到过类似这样的东西、但我不知道如何在 cmd 文件中指定地址集。

_asm ("MOV SP、#_stack;");

要分支到新位置、是否会使用函数指针、分支还是 PC 寄存器加载?

我按如下方式设置 cmd 文件:

SECTIONS
{
   codestart        : > BEGIN

   kernel_section : //>> FLASH5 | FLASH6 | FLASH7 | FLASH8 | FLASH9 | FLASH11 | FLASH12
   {
		flash_kernel_c28x_dual_ex1_boot_cpu1.obj(.text)
		flash_kernel_c28x_dual_ex1_erase_cpu1.obj(.text)
		flash_kernel_c28x_dual_ex1_sci_boot_cpu1.obj(.text)
		flash_kernel_c28x_dual_ex1_sci_flash_kernel_cpu1.obj(.text)
		flash_kernel_c28x_dual_ex1_sci_get_function_cpu1.obj(.text)
		flash_kernel_c28x_dual_ex1_verify_cpu1.obj(.text)

   }    LOAD >> FLASH5,// | FLASH6 | FLASH7 | FLASH8 | FLASH9 | FLASH11 | FLASH12,
        RUN >> RAMLS0 | RAMLS1 | RAMLS2 |RAMLS3,
        LOAD_START(RamfuncsLoadStart),
        LOAD_SIZE(RamfuncsLoadSize),
        LOAD_END(RamfuncsLoadEnd),
        RUN_START(RamfuncsRunStart),
        RUN_SIZE(RamfuncsRunSize),
        RUN_END(RamfuncsRunEnd),
        ALIGN(4)

   .text            : >>RAMGS1 | RAMGS2 | RAMGS3 | RAMGS4
   .cinit           : > RAMM0
   .switch          : > RAMM0
   .reset           : > RESET,    TYPE = DSECT /* not used, */

   .stack           : > RAMM1
#if defined(__TI_EABI__)
   .bss            : > RAMGS5
   .data           : > RAMGS5
   .const          : > RAMGS5
   .init_arry      : > RAMM0
   .sysmem         : > RAMGS5
#else
   .pinit           : > RAMM0
   .ebss            : > RAMGS5
   .econst          : > RAMGS5
   .esysmem         : > RAMGS5
#endif

   Filter_RegsFile  : > RAMGS5

#ifdef __TI_COMPILER_VERSION__
    #if __TI_COMPILER_VERSION__ >= 15009000
       .TI.ramfunc      : > RAMGS5
    #else
       ramfuncs         : > RAMGS5
    #endif
#endif

   MSGRAM_CPU1_TO_CPU2 > CPU1TOCPU2RAM_0, type=NOINIT
   MSGRAM_CPU1_TO_CPU2_COPY_TO_M1_RAM > CPU1TOCPU2RAM_1, type=NOINIT
   MSGRAM_CPU2_TO_CPU1 > CPU2TOCPU1RAM, type=NOINIT
   MSGRAM_CPU_TO_CM   > CPUTOCMRAM, type=NOINIT
   MSGRAM_CM_TO_CPU   > CMTOCPURAM, type=NOINIT



    /* The following section definition are for SDFM examples */
   Filter1_RegsFile : > RAMGS10,	 fill=0x1111
   Filter2_RegsFile : > RAMGS11,	 fill=0x2222
   Filter3_RegsFile : > RAMGS12,	 fill=0x3333
   Filter4_RegsFile : > RAMGS13,     fill=0x4444
   Difference_RegsFile : >RAMGS14, 	 fill=0x3333

}

谢谢、

John

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尊敬的 John:

    您可以使用指令 MOV SP、#0将 SP 值设置为0。

    [引用 userid="152282" URL"~/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1195172/tms320f28386s-resetting-the-stack-pointer-and-pc "]

    要分支到新位置、是否会使用函数指针、分支还是 PC 寄存器加载?

    [/报价]

    分支指令可能是理想的。 使用指针的函数调用也起作用。 在这种情况下、返回地址会存储在堆栈中。 我认为这在你的情况下是不可取的。

    此致、

    Veena

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢您发帖。 我尝试了

    _asm ("MOV SP、#_stack;");

    因为我不想使用硬编码值。 此行会显示有关创建标签的错误。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    John、

    [引用 userid="152282" URL"~/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/1195172/tms320f28386s-resetting-the-stack-pointer-and-pc/4507587 #4507587"]_asm ("MOV SP、#_stack;");

    _asm (" MOV SP、#_stack;");

    我想你需要在 MOV 之前有一个空间。

    此致、Santosh

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    谢谢。 谁会猜到这一点?

    我仍然不知道如何通过编程方式获取 在 cmd 文件中为 RAMM1设置的位置值、以用于此 MOV 语句。

    .stack          :> RAMM1

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    哦、好的、所有汇编指令都应该有前面的空格。 通常在第1列添加标签。

    我认为这是一种通用的汇编编码实践。_stack 是编译器添加的符号、指示栈存储器的起始地址。 您也可以使用 start()获取 任何自定义段的起始地址

    SectionName:> RAMM1,start (符号名称)

    此致、

    Veena  

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢您的回复。

    我的程序是否可以通过某种方式访问编译器生成的符号_stack?

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    是的、您可以添加以下 asm 指令-  

    _asm (" .global __stack");

    这与 C 中变量的 extern 声明类似

    此致、

    Veena