Hi,

I have some questions regarding one aspect of getting code to execute 
from RAM on the STM8.

So far, I have got code to run from RAM through the following procedure:

- Put the function to be executed from RAM in its own C file.
- Use a 'codeseg' pragma to put that code in a separate segment/area.
- Create a function to return the size of that segment (using embedded 
assembly to read 'l_<area>' symbol).
- On startup, use the length to facilitate copying the RAM-executing 
function into an array in memory.
- Set a function pointer to that array, so the in-memory code can be called.

However, one thing occurred to me when writing the code to copy from 
flash to RAM: what happens when using the 'large' memory model? Am I 
correct in thinking that if I have code that casts a function pointer to 
a uint8_t* (or pass it to memcpy), the 'large' 24-bit function pointer 
will be truncated to 16-bits, and it will not be possible to copy a 
function's code if that function resides in flash beyond 32KB?

What is the solution to this?

Ideally, there would be some kind of fmemcpy function that dealt with 
'far' pointers. This is what the docs for ST's SPL instructs Raisonance 
users to use, but I don't think any such thing exists in SDCC's standard 
C library. Would it be possible to write an equivalent in assembly?

Alternatively, can my additional code segment be relocated so that it is 
always within the first 32KB of flash? I guess the linker would need to 
do this?

Regards,
Basil

P.S. Does the 'codeseg' pragma apply only at the file level? That is, it 
applies to all functions, even if declared half-way through the file, or 
you use 'save'/'restore' pragmas? I tried the latter, but all code in 
the file got put in the specified segment, rather than just the function 
wrapped in 'save'/'restore'.

_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to