Possible to implement MMU functionality in software with GCC?

197 Views Asked by At

I have an ARM Cortex-M0+ MCU (SAML21) that doesn't have a memory management unit or external memory interface, but I would like to use an existing library (libavif + libaom) to manipulate data that doesn't fit in the internal SRAM. In this case, a single uncompressed image frame won't fit in 40kB.

If I were to implement an image compression library myself given these constraints, I would store the image data in a large external RAM chip and access its contents over SPI while compressing the image.

Instead of spending weeks rewriting libaom to access memory through some kind of spi_ram_write/spi_ram_read functions, is there any kind of secret flags/tricks I can use with arm-none-eabi-gcc to get it to replace memory accesses in certain sections of code with function calls (address and data as arguments) like this? This would obviously be incredibly slow, but that's fine for my application.

This is fundamentally the same as this question but I would like to know if it's possible to do in software rather than using linker options and the non-existent MMU.

1

There are 1 best solutions below

6
On

Possible to implement MMU functionality in software with GCC?

In general, to emulate an MMU, before every memory access you'd have to do something like:

    if( data_not_currently_present(fake_address) ) {
          actual_address = fetch_the_data(fake_address);
    } else {
          actual_address = find_the_data(fake_address);
    }

This would destroy performance by a factor of around 1000.

I have an ARM Cortex-M0+ MCU (SAML21) that doesn't have a memory management unit or external memory interface, but I would like to use an existing library (libavif + libaom) to manipulate data that doesn't fit in the internal SRAM.

That's a little like saying you have a bicycle and want to transport 3 tons of rock on the highway. There's 2 choices here: You can call it the wrong CPU for the job, or you can call it the wrong job for the CPU.