On Thu, Jul 14, 2011 at 11:18 AM, Rob Kendrick
<rjek@rjek.com> wrote:
On Thu, Jul 14, 2011 at 10:12:05AM +0300, Bogdan Marinescu wrote:
> > Does that processor have something like the memory protection unit on the
> > arms? �You could easily change the Lua allocator to use your own function
> > that 'allocates' from a protected region and use the fault handler to do the
> > access.
>
> I don't know of any MCU with a MMU.
I first suggested just this technique earlier in the week :) �Larger
STM32s have an MPU (a heavily cut-down MMU) that may be able to do this
paging as you suggest: poor performance may be acceptable if you don't
need to query it often. �
Cortex M3 MPUs don't do any memory translation, they just raise an exception if a memory access is detected at certain programmable address ranges. In fact M3s don't have the concept of "virtual address" so you can't apply the usual VM techniques there. What I did was extremely crazy, I was actually rewriting CPU instructions/changing registers at runtime from the MPU exception handler to force the offending memory access instruction to use another address. Strangely enough it worked for the most part, but you can probably imagine how slow it was. There might be some applications out there that can cope with such poor performance, but I'm willing to bet there aren't that many.
�
Some of NXP's LPC range have a full ARM9-style
MMU that you can use if you want. �Or there's the option of selecting a
MCU with an external memory bus.
Generally speaking, devices based on ARM cores with integrated MMUs run a full-fledged OS (Linux more often than not) and people choose to run Lua directly from Linux for obvious reasons. A MCU with an external memory bus is by far the best option, but they aren't that common and the external bus eats a lot of the GPIOs on the chip which might not be acceptable for some applications.
�
The alternative might be to augment the compiler to generate function
calls for memory accesses, but I suspect this would be the ugliest of
hacks.
I was thinking about modifying Lua to execute memory accesses via proxy (read/write memory) functions, but I stopped. It would be quite a bit of effort and I'd simply be going against the flow here. More and more MCUs with 128k of internal RAM are getting on the market now and the trend is ascending.�
�
Best,
Bogdan