Running Huge Program Images

Let’s say that I have a program with 200M lines and the compiled form doesn’t fit in the Flash on the chip (let’s say it’s 30MB). This means that you need to use an external program memory device (like the EMX modules etc). Is it possible (technologically, if not currently) to use an SD card as that storage?

Yes you can read .pe files from SD card.

But I don’t think you can execute code from SD…

Yes, you can run program from SD as long as it is not using Gadgeteer libraries. This because of pin reservations at startup.

You can load and execute code. Doesn’t matter where it came from.

For 30MB of code?

There’s several Skewworks examples for running external apps. At least one of which is in CodeShare

@ kurtnelle - tell more about these 30Mb of code?

I’m actually trying to rule something out. Computer Science 101: For code to execute it must be in memory. Operating systems implement Virtual Memory to get around memory limitations of past and present systems using storage as a swap file location. Given that the ARM chips and the .NETMF are newer technologies, I am wondering if they built anything that more advanced that that in the last few (10) years.

I guess I’m trying to ask: Does .NETMF have a Virtual Memory feature :slight_smile:

Pitty, kewlio.

“Executing code from SD” does NOT mean “loading code from SD into RAM and executing it from RAM”. Windows can’t execute code from a hard drive, either. It loads the code from the hard drive into RAM and executes it from there.

So, no to your original question (cannot execute code directly from SD) and no to your other question, there is no virtual memory in .NETMF. You could certainly approximate something like virtual memory by storing some variables somewhere when you needed other variables to be in memory, and move them around like that, but there’s nothing built in.

In your case, however, you’re running code. You can’t swap code in and out like that, at least not at the NETMF level. If you were running native code, you probably could implement something rudimentary, but it’d probably be ugly, brittle, and slow.

What you’re missing is called an “MMU”, or “Memory Management Unit”. Cortex-M processors don’t have one. Cortex-A processors do. It’s the piece of hardware that manages all the virtual-to-physical address mapping.

The AT91SAM9R in the Hydra has this MMU. That’s why it can run Linux, for example. NETMF doesn’t take advantage of it, though.

Pyxis One used a virtual CPU to get around this. I loaded each instruction from the uSD and used file seeks to deal with JUMPs. Depending on what you’re doing you might be able to implement a similar solution in RLP or even Managed NETMF

MMU there we go. At some point they will support it.

@ Skewworks (is that a name of a company?) I thought about doing that because the program in question is really just controlling the machine, so high performance code is not required.

Yes Skewworks is Skewworks, Inc.
Pyxis One is free and open-source; it was developed for Arduino years ago. The compiler is closed source by the VCPU that ran it is open: Pyxis - Skewworks

Right, I guess they merged in the ucLinux stuff some time ago. Still, running without an MMU imposes some limitations. You can’t, for example, run Ubuntu on your Cortex-M0 regardless of how much memory it has.

Certainly not; furthermore, adding an MMU costs performance, so unless you need it, you don’t really want it.

Right tool for the job, and all that.

If you have a NETMF board with 64MB NOR flash connected to it’s address bus and the NETMF is set up to do XIP(eXecute In Place) then yes, you can run a program from flash without copying it to ram.

NOR flash looks like readonly RAM and is fully random accessable, like RAM. But it can’t be written to without first erasing, so it is sortof like ROM.

The Cerberus’s NETMF and program runs directly from flash, without being copied to ram, but it only have 1MB flash.

So it CAN be done, but, at this time, you will have to design your own main board.

Although NAND flash is cheaper and larger, it is not Random Accessable, and can’t be used for XIP.

@ Errol, So only random access memory types can be used directly with a NETMF chip (currently) and unless something fantastic comes along…

eXecute in Place. Will remember that.

Yes, only random access devices.

Else, imagine you are running a program directly from a hard drive. You read one instruction from the disk, but the disk works in 512byte blocks, so you must read one block of 512 bytes at a time. Then you realise that the current instruction that you just read is a JUMP/BRANCH/GOTO/IF statement. Now you throw away the rest of the 512 bytes, and you go find the new block containing the next instruction and you load that block.

You will wait for ever to run a program. Disks and NAND flash is fast when reading sequential blocks. They are really bad when you jump around a lot.

I’m sure that the NETMF porting kit makes provision for drivers for other types of storage, but anything that doesn’t do random access is unusable for XIP.

NETMF is a special case, it’s like Skewwork’s virtual CPU. It could run programs from anywhere, assuming you’re willing to take the performance hit, as Errol said.