Here's a bit more information about what I want to do, in the hope that it will enable someone to offer a solution.
The following test program puts a RISC-V machine-code program into RAM:
#define WORDALIGNED __attribute__((aligned (8)))
IRAM_ATTR uint8_t MyCode[64] WORDALIGNED = { 0xb5, 0x45, 0x33, 0x05, 0xb5, 0x02, 0x82, 0x80 };
// li a1,13 mul a0,a0,a1 ret
typedef int (*intfn_ptr_type)(int x);
int test (int x) {
// MyCode[0] = 0xb5;
return ((intfn_ptr_type)&MyCode[0])(x);
}
void setup() {
Serial.begin(9600);
delay(5000);
Serial.println(test(11));
Serial.println("End");
}
void loop() {
}
It executes the following RISC-V machine-code program:
li a1,13
mul a0,a0,a1
ret
which multiplies the first parameter, in a0, by 13. Running the program passes the parameter 11 and gives the following output:
143
End
This works fine for machine-code known at compile time, but I want to be able to generate the machine code at run time; for example, by prompting the user for it. You can simulate this by uncommenting the line:
// MyCode[0] = 0xb5;
but this then crashes with the error as mentioned above:
Guru Meditation Error: Core 0 panic'ed (Memory protection fault).
memory type: IRAM0_SRAM
faulting address: 0x40380210
world: 0
operation type: X
Any suggestions welcomed.
Thank you, David