Ruben Valls

Ilegal opcode when runing code in RAM (MCF52233)

Discussion created by Ruben Valls on Dec 18, 2008
Latest reply on Dec 19, 2008 by Ruben Valls
Hi all.
After a few days searching on Internet, I have succesfully learned how to copy functions from ROM to RAM using the directive __declspec. It seems to do its work fine, since it defines a seccion of RAM to place the functions and copy them there.
The problem comes when I execute the functions. It starts fine, but after a while, executes opcodes that are invalid.
I don't know where is the problem, if in the .lcf or in the program. I show you the interesting part of both:
-The LCF:
    .text :    {        . = ALIGN(0x10);        mcf52235_vectors.s (.text)        *(.text)        *(.rodata)     . = ALIGN(0x10);        ___DATA_ROM     = .;    } > rom        .data_bss : AT(___DATA_ROM)    {        ___DATA_RAM     = .;        *(.data)        *(.sdata)                . = ALIGN (0x10);        *(.boot)        . = ALIGN (0x10);                ___DATA_END     = .;        .               = ALIGN(0x10);        ___BSS_START    = .;        *(.sbss)        *(SCOMMON)        *(.bss)        *(COMMON)        ___BSS_END      = .;                .               = ALIGN(0x10);        ___SP_END       = .;        .               = . + (0x800);        ___SP_INIT      = .;        .               = . + (4);        ___HEAP_START   = .;        ___HEAP_END     = ___SRAM + ___SRAM_SIZE;    } > ram

 The boot section is where I have all the functions I want to execute from RAM. I put it between __DATA_RAM and __DATA_END, so the function common_startup copies it from ROM to RAM for me.
-The Program Code:
#pragma define_section bootloader ".boot" far_code__declspec(bootloader) void flash_update_i2c(){ /*Some variable declarations*/        uint32 addr;        uint8 i;        /*Code*/
 addr=0; i=0;

 When It executes the line addr=0 (although it is not the first command it executes in RAM) it fails due to an illegal operator:
-Code mixed C and Assembler:
        ... addr=0;20000528: 00042D40        ori.b    #0x40,d42000052C: FEF8            dc.w     0xfef8                  ; Invalid opcode  i=0;2000052E: 7000            moveq    #0,d020000530: 2D40FEE8        move.l   d0,-280(a6)        ...

 There are some code lines that it executes fine (the lines before addr, i=0, etc) and there are others that it don't execute fine (addr=0, between others).
Why can it be? Bad allignment in the .LCF? It is alligned to 16, like in ROM...
I'm completely lost...
Thanks in advance,
Rubén Valls