I am attempting to execute code out of RAM.
I proved the concept by writing a simple LED blinky function and running it out of RAM. I actually got it work on the MCB2300 Dev Board.
My method is as follows - create an array/buffer to allocate some space on the stack (SRAM). The buffer must be large enough for the function and I get the size from the memory map. I then page align the buffer and copy the function into the buffer and execute.
unsigned char codeBuffer[1024]; unsigned char *alignedCodeBuffer = (unsigned char*)( ((int)codeBuffer + 256) & 0xFFFFFF00 ); void (*functionPointer)(void) = (void(*)(void))alignedCodeBuffer; memcpy( (void*)alignedCodeBuffer, (void*)&toggleLed1, sizeof(codeBuffer) - 256 ); VICIntEnClr = 0xFFFFFFFF; //Disable all Interrupts functionPointer();
The problem now is that I moved this code to my real application and I am getting taken to
DAbt_Addr DCD DAbt_Handler
I need my code to have relative addressing. Looking through the disassembly window, I see absolute addressing, or, references to the FLASH address space. Notice the 0x0000D67C.
0x0000D67C E1B01000 MOVS R1,R0 0x0000D680 E2400001 SUB R0,R0,#0x00000001 0x0000D684 1AFFFFFC BNE 0x0000D67C
Am I doing something wrong besides the obvious that it isn't working.
Is there a compiler flag I am missing?
Another possible solution is to replace the BNE instruction with a combination of other assembly instructions to move the PC back a few times.
I figured this out earlier today and furthermore, I found out how to map entire files into RAM rather than FLASH. This solved my issue. I now have a new issue that I am currently typing up. Hopefully you may have some insight on it.
I was able to remap this by using the graphical interface, which I was surprised. Options for the file along with Target options helped immensely.