How to flush instruction cache?

,

I'm working on a JIT and I'd like to be able to flush icache. I've tried writing a 0 to ICIALLU (at address 0xE000EF50) and I've also tried the STM32CubeF7 library's InvalidateICache(). However, all methods I've tried result in the device crashing. I'm not sure what to do at this point except to execute 4kb of nops.

Right, we don't provide direct access to system registers. I'll file a feature request for a cache-flushing function on the C API. My first though was nah, that's too niche, but now I really want to see what you can do with JIT code. :slight_smile:

I'll try and get that into the 2.0.0 release!

3 Likes

Thank you so much! I hope not to disappoint :slight_smile:

1 Like

Excuse me, I'm doing the same now. Am I understanding it correctly - all heap-allocated memory is rwx? I mean that I should not specially map-protect it. Am I right?

@Dave, @NaOH :pray:

I believe that is right.

Please note, that because the Playdate operates exclusively in THUMB mode, pointers to instructions (i.e. function pointers) always have the lowest bit set. In other words, they point to one byte after the instructions begin; and if you jump to/call arbitrary code, you need the address (ptr|1) instead.

@NaOH

I believe that is right.

Thank you, that's great!

Please note,..

Yup, I know, thanks!
STM32F746 as well as STM32H7B0 operates only in T32 mode. And that's true for ops like BX only which can switch execution modes.