繁体   English   中英

在代码中引用放置在 RAM 中的部分,导致 linker 错误 [Lc036]

[英]Refering in code to section placed in RAM, cause linker error [Lc036]

STM8,IAR 编译器。

我试图将可变中断向量表(IVT)放在 RAM( ram_ivt_sectionRAM_IVT )中,从 0x00 地址开始。

先决条件:硬件入口点( base_ivt_sectionIVT_TO_RAM块)已被替换并重定向到此 RAM 地址。

所以,我有下一个代码:

Header.h ===========================================
#define MCU_INTERRUPT_VECTORS_COUNT     (32)

typedef void (__interrupt *interrupt_handler_t)(void);

typedef struct {
    int8_t value;
    int8_t unused_byte;
    interrupt_handler_t handler;
}interrupt_vector_t;

extern interrupt_vector_t ram_ivt[MCU_INTERRUPT_VECTORS_COUNT];

Source.c ===========================================
#include "header.h"

extern void __iar_program_start(void);
extern void __iar_unhandled_exception(void);

__interrupt void CallUnhandledException(void) { __iar_unhandled_exception(); }
__interrupt void CallResetHandler(void) { __iar_program_start(); }

interrupt_vector_t ram_ivt[MCU_INTERRUPT_VECTORS_COUNT] @".ram_ivt_sector" = {
    {0x82, 0x00, CallResetHandler},
    {0x82, 0x00, CallUnhandledException},
    {0x82, 0x00, CallUnhandledException},
    ... repeats 32 times.

 Main.c ===========================================
#include "header.h"

int main( void ) {
    __enable_interrupt();
    __trap();
}

它工作正常。 在陷阱上,程序陷入未处理的异常。 但是,当我尝试修改或读取表格时

Main.c ===========================================
    #include "header.h"

    int main( void ) {

    volatile void* a = &ram_ivt[1].handler;
    // Or
    ram_ivt[1].handler = 0;

    __enable_interrupt();
    __trap();
}

项目在 linker 阶段停止构建,但出现错误:

Error[Lc036]: no block or place matches the pattern "rw data section .ram_ivt_sector in ram_ivt.o symbols: [ram_ivt]" 

Linker 文件://////////////////////////////////////// /////////////////

define symbol __RAM_IVT__      = 0x000000;

//  Memory regions
define memory with size             = 16M;

define region TinyData              = [from 0x00 to 0xFF];
define region NearData              = [from 0x0000 to 0x0FFF];  
define region NearFuncCode          = [from 0x8000 to 0x9000];

define block CSTACK with size           = _CSTACK_SIZE  {};
define block HEAP  with size            = _HEAP_SIZE {};
define block IVT_TO_RAM with size       = 0x80, alignment = 1  { ro section .base_ivt_section };
define block RAM_IVT with size          = 0x80, alignment = 1  { rw section .ram_ivt_section };
define block INTVEC with size           = 0x80, alignment = 1  { ro section .intvec };

// Initialization
initialize by copy { rw section .iar.dynexit,
                     rw section .near.bss,
                     rw section .near.data,
                     rw section .near_func.textrw,
                     rw section .tiny.bss,
                     rw section .tiny.data,
                     ro section .tiny.rodata };

initialize by copy with packing = none { section __DLIB_PERTHREAD };

do not initialize  { rw section .near.noinit,
                     rw section .tiny.noinit,
                     rw section .vregs };

// Keep 
keep { rw section .ram_ivt_section };

// Placement
place at address mem: __RAM_IVT__       {   block RAM_IVT };

place in TinyData                       {   rw section .vregs,
                                            rw section .tiny.bss,
                                            rw section .tiny.data,
                                            rw section .tiny.noinit,
                                            rw section .tiny.rodata };

place in NearData                       {   block HEAP,
                                            rw section __DLIB_PERTHREAD,
                                            rw section .iar.dynexit,
                                            rw section .near.bss,
                                            rw section .near.data,
                                            rw section .near.noinit,
                                            rw section .near_func.textrw };                   
place at end of NearData                {   block CSTACK };

                                  
place at start of NearFuncCode          {   block IVT_TO_RAM };
place in NearFuncCode                   {   block INTVEC,
                                            ro section __DLIB_PERTHREAD_init,       
                                            ro section .iar.init_table,
                                            ro section .init_array,
                                            ro section .near.data_init,
                                            ro section .near.rodata,
                                            ro section .near_func.text,
                                            ro section .near_func.textrw_init,
                                            ro section .tiny.data_init,
                                            ro section .tiny.rodata_init };

这是interrupt_vector_t ram_ivt[MCU_INTERRUPT_VECTORS_COUNT] @".ram_ivt_sector" ram_ivt_sector必须是ram_ivt_section中的语法错误

谢谢@KoynovStas。

暂无
暂无

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

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