Skip to content

Using ARM Memory Barrier in Symbian OS

Today I have been digging the methods toΒ  to make a gpSP( I think this is the best GBA emulator) port to Symbian OS.Thanks to the Exophase for developing this wonderful piece of software and for ZodTTD for the awesome ARM port! The gpSP is running “generated” ARM binary in the ARM processor’s memory, so the Memory Barrier has to be used. The next problem is to get the code running on the ARM under Symbian OS.
The ARM9 reference manual tells this about Memory Barrier.

Whenever code is treated as data, for example self-modifying code, or loading code into
memory, then a sequence of instructions called an Instruction Memory Barrier (IMB)
operation must be used to ensure consistency between the data and instruction streams
processed by the ARM926EJ-S processor.
Usually the instruction and data streams are considered to be completely independent
by the ARM926EJ-S processor memory system, and any changes in the data side are
not automatically reflected in the instruction side. For example if code is modified in
main memory then the ICache might contain stale entries. To remove these stale entries
part or all of the ICache must be invalidated.

In Symbian OS the Kernel should take care about ICache invalidation. The Symbian has User library for user side interaction with the Kernel. If we want to generate our own code and run it in specific memory are, we have to first tell to the kernel to threat this area as code. The code example for doing this is below.

RChunk codechunk;
TInt error = codechunk.CreateLocalCode(codechunk_size,codechunk_siz);
void* codechunk_ptr = codechunk.Base();

Now the codechunk is created. The ARM documentation told that ICache must be invalidated before executing the code. The Symbian should take care for invalidating the ICache, when IMB_Range is called.

void CLEAR_INSN_CACHE(void* code, int size)
User::IMB_Range( code, (void*)(code + size));


  1. Fredrik says:

    A Symbian port of gpsp sounds lovely!

  2. Psy says:

    The image output is going to be a problem though. This is not so crucial on systems with higher resolutions but 240×160 on phones with 320×240+ screens is going to be either too small or too ugly. Is it even possible to do some relatively fast stretching using direct drawing or even OpenGL ES?

    • Summeli says:

      Yes, the image output might be an issue. For 5.0 phones we can nicely to 2x scaling, and keep the original aspect ratio. Currently I’m just hoping that it looks decent on 320×240 resolution πŸ˜‰
      I’m still far away from a working port, so there might be some really nasty blocking points left.

  3. khan4251 says:

    Nintendo DS has 252×192 on 3′ screens so it would not be problem to see 240×180 on 2,4′ or 2,6′
    If you want to see try download timed version of vbag emulator from vampent website.

  4. Psy says:

    Ehh… hello?! That’s the issue. About one third of the screen will be black and the screens on phones are way smaller than the DS/GBA ones already. A visible area with size of about 1.6β€² is even smaller that the Game boy Micro screen (and even that was bad for the eyes). It’s tiny and tires the eyes when centered or huge and ugly when stretched. It just feels wrong here.
    I just want to know if there is a way to stretch while still maintaining the original aspect ratio either by using direct drawing or OpenGL ES (and how heavy that would be if possible).

  5. khan4251 says:

    I thinkOpenGL is way too blured ,on snes it looks normal but with less pixels of gba it will looks worser.

  6. khan4251 says:

    But still i would like to see it with OpenGL due a performance boost.

  7. Evangellium says:

    On the antsnes i didnt see any performance boost with OpenGL. I use an n95.

  8. khan4251 says:

    Don’t expect much boost sometimes even 1 frame more is much.
    Also it depends which games you are playing.

  9. Benny-Danny says:

    Great job on the antSnes btw.
    About the screen size and the graphics, I use vbagx on my n95 8GB, fullscreen, playing games like Final Fantasy.. It doesn’t look so ugly in fullscreen mode as you think…
    It would be great if someone can port that emulator, or someway that we can have gameshark cheats…

  10. Roy D. says:

    So… how is Antsnes going? is there any update..
    keep on the good work!!

  11. Iscar says:

    “The article you have posted is superb!
    There are so many informative information. This is very knowledgeable article.
    Thank you!”

  12. […] can create memory partitions for dynamic recompilation with CreateLocalCode and IMB_Range deal, as I wrote few moths ago.Β  The problem is the way how Symbian OS maps the memory. The pointer to the dynamic code area is […]

  13. Coolguy says:

    Hi Summeli,
    Is there any different to use this aPI for Nokia N97 ? Seems its not working for N97, or S60 5th edition

Leave a Reply