Ok... Look, you all go way over my head fast. So for this thread, maybe consider how you'd explain it to your dumb cousin who just happened to ask a question you are interested in

In terms of ARM Cortex M4:
I have a project where I need the micro to perform some code quickly but I don't yet know what that code is. External source.
The last time I asked this many people directed me towards remote code execution, interpreters like Forth, or towards a DSL. The issue with a DSL I may need to do things tomorrow I didn't think of today, so that means firmware updates and version-hell, I self-limited to NOT LOGIC IN MY DSL, and about a week later saw a spot I could really use a loop. The problem with scripting or interpretive languages like Forth or eLua is they have almost no serious support with active communities, all years out of date at best for a turnkey solution. Python can do it, but it's really heavy and includes a ton of things I don't want to do.
The pro of remote code execution is that I should rarely need firmware updates for small changes, I can have any logical or C method available to me at any time, and it's a lot lighter than the other options as it's just all native ARM code, no extra layers of translation. It really simplifies the interaction too as I just need to provide the correct bytestring, there won't be any extra work to interpret and pack.
The questions I have with remotely executing code:
- If I send a pre-compiled byte string to my device and execute in RAM, can I call functions from the original flash on demand? Freely switch from my RAM code to my Flash code and return back? Does the micro care where instructions are actually located?
- Obviously the issue would be if there was a function Foo(uint8_t) in flash, and I want to call it from my RAM code I need to know where it's located explicitly. This is a job for the linker and libraries right? What if I want to possibly move things around between two hardware versions of code, does it become a job for a _SVC? Is there a "safe" way to do this other than to ALWAYS locate this function at a specific address no matter what?
- I know this is dangerous, allowing remote code. I can do my best by encrypting the byte string before transit and only decrypt on chip, but are there any other good practices? CRC or better yet sign the string? Assigning the Memory Protection Unit to only allow RAM code to access specific regions? It might be difficult, but maybe a simple ARM instruction interpreter that checks the string for commands that I don't allow like reading from X memory or any writing to flash?
I know some of this is really basic, but I've never had to do anything like this yet.
Thanks! You guys are great.