Some examples of possible Option 2 reencoding of some STR variations. Note these need to be used in USER with entry via a Hypercall which stores the return address in
returnPC. The self-modifying code check doesn't account for Codelets being overwritten.
STR R0, [R1, #20]
Code: Select all
.tmp DCD 0,0,0,0,0
.returnPC DCD <JIT instruction address + 4>
.VMbase DCD <base address of VM memory>
.JITcode DCD <JIT code base address>
.JITentry DCD <JIT entry instruction>
.codelet
STR R12, tmp + 4*4
ADR R12, tmp
STMIA R12!, {R1, R9-R11}
LDMIB R12, {R9-R11}
ADD R1, R1, R9
STR R0, [R1, #20]! ;original instruction with writeback
BIC R1, R1, #%11 ;support self-modifiying code
STR R11, [R10, R1] ;overwrite JIT address with JIT entry instruction
LDMDB R12, {R1, R9-R12, PC}
STR R0, [R1, #20]!
Code: Select all
.tmp DCD 0,0,0,0,0
.returnPC DCD <JIT instruction address + 4>
.VMbase DCD <base address of VM memory>
.JITcode DCD <JIT code base address>
.JITentry DCD <JIT entry instruction>
.codelet
STR R12, tmp + 4*4
ADR R12, tmp + 4
STMIA R12!, {R9-R11}
LDMIB R12, {R9-R11}
ADD R1, R1, R9
STR R0, [R1, #20]! ;original instruction
SUB R1, R1, R9
BIC R9, R1, #%11 ;support self-modifiying code
STR R11, [R10, R9] ;overwrite JIT code with JIT entry instruction
LDMDB R12, {R9-R12, PC}
STR R0, [R1], #20
Code: Select all
.tmp DCD 0,0,0,0,0
.returnPC DCD <JIT instruction address + 4>
.VMbase DCD <base address of VM memory>
.JITcode DCD <JIT code base address>
.JITentry DCD <JIT entry instruction>
.codelet
STR R12, tmp + 4*4
ADR R12, tmp + 4
STMIA R12!, {R9-R11}
LDMIB R12, {R9-R11}
ADD R1, R1, R9
STR R0, [R1], #20 ;original instruction
SUB R1, R1, R9
SUB R9, R1, #20 ;remove the post increment
BIC R9, R9, #%11 ;support self-modifiying code
STR R11, [R10, R9] ;overwrite JIT code with JIT entry instruction
LDMDB R12, {R9-R12, PC}