Author Topic: Virtual Machines on Microcontrollers (Specifically for ARM)  (Read 6411 times)

0 Members and 1 Guest are viewing this topic.

Offline beeboopbeepTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Hi everyone,

I was wondering if anyone know successful implementation of virtual machines on microcontrollers used in the industry (specifically, for ARM targets). I started thinking about the advantages of having a virtual machine on uCs but to my surprise, I was not able to find any products with VMs on them. Obviously, implementing native code will always be the better solution with regards to having high performance but the processors we have today can easily support a simple VM running bytecode instructions. In addition, ARM uCs with relatively fast clock speed can be bought for a relatively cheap price compared to other 8-bit processors (e.g., an ATmega328p costs ~2 USD whereas STM32L0 can be bought for ~3 USD). This makes me believe that cost would not be a huge factor for not implementing a VM on a uC for getting the advantages. Furthermore, many projects will not require full processing power of the uCs and I believe power consumption with a VM can closely match the power consumption of the same uC running native code (for "most" tasks).

I've also came across a recent dissertation on uCs with VMs in case anyone is interested in further reading about this topic (https://www.researchgate.net/publication/257679030_A_real-time_virtual_machine_implementation_for_small_microcontrollers). The authors in the paper ran the VM performance experiments with an ATxmega128A1 and concluded that having a VM on "small" uCs is a feasible solution to gain the advantages of having a VM in your system.

If you think VM is the right or wrong direction in the near future, and if you can share your thoughts on it, I would greatly appreciate it.

Thank you.
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #1 on: July 15, 2017, 06:57:15 am »
I have to question what you are hoping to accomplish by virtualising the architechture?

If its for scripting, call it an interpreter, if its for cross platform compatibility that should be attacked in the compiler stage.

If you hoping to do things like restricting access, there are generally built in options to prevent escalation, but know that a jtag interface can generally peer inside and see what your actually doing, and may help who your fighting to peel back what your doing.

On my cortex 3 arm i do run 2 scripting language interpreters with a reduced syntax, This was easier for me that bytecode packages, as in the parsing stage i am able to detect errors, write back where they, and it means that all parts of the method is sanitized. It also reduced my R&D time as i only had to edit a text file script on an sd card, rather than recompiling the entire micro's software.
« Last Edit: July 15, 2017, 06:59:31 am by Rerouter »
 

Online ataradov

  • Super Contributor
  • ***
  • Posts: 11238
  • Country: us
    • Personal site
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #2 on: July 15, 2017, 06:57:43 am »
What is your goal?

There are plenty of "experimental VMs" for things like Java and Python. I doubt any of them are actually useful.
Alex
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #3 on: July 15, 2017, 07:08:23 am »
what is the goal? you tipically want a microcontroller to be as close to the hardware as possible
 

Offline beeboopbeepTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #4 on: July 15, 2017, 07:13:18 am »
I am not trying to accomplish anything yet. However, I can imagine developing a higher level language packaged in an IDE (i.e., with heavy use of GUI and reduce low-level coding as much as possible or eliminate it entirely) to program all uCs (platforms) so that anyone without technical background in uCs can program these devices.

The goal would be to get to a certain level of abstraction with regards to programming the uC, to the point where an elementary student can program any uC with interface concepts like 'drag and drop' using a GUI IDE.
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #5 on: July 15, 2017, 07:20:58 am »
oh i see :) that's not a bad idea at all
that reminds me: In high school we studied siemens PLCs, and at the time one of my professors was coding a "ladder style" programming language for pic16/18
 

Offline nfmax

  • Super Contributor
  • ***
  • Posts: 1560
  • Country: gb
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #6 on: July 15, 2017, 07:32:36 am »
The goal would be to get to a certain level of abstraction with regards to programming the uC, to the point where an elementary student can program any uC with interface concepts like 'drag and drop' using a GUI IDE.
Have you come across Node-RED (https://nodered.org/)? It's not exactly what you describe, but it does allow largely graphical programming of Raspberry Pi's and similar systems. The implementation uses JavaScript, running on the V8 engine of NodeJS. This is actually a native-code compiler, rather than a byte code VM, but it is cross platform.
 

Offline beeboopbeepTopic starter

  • Contributor
  • Posts: 31
  • Country: ca
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #7 on: July 15, 2017, 07:51:10 am »
oh i see :) that's not a bad idea at all
that reminds me: In high school we studied siemens PLCs, and at the time one of my professors was coding a "ladder style" programming language for pic16/18

Ladder programming is something I have never came across. I'll take a closer look.


What is your goal?

There are plenty of "experimental VMs" for things like Java and Python. I doubt any of them are actually useful.

There is a recent startup company that I saw which (I'm assuming) uses a customized FreeRTOS for implementing a VM on various uCs in order to allow users to program in Python (https://www.zerynth.com/). Not sure how well they are doing but it seems like a step towards the right direction for people who want to heavily script using various uCs.


The goal would be to get to a certain level of abstraction with regards to programming the uC, to the point where an elementary student can program any uC with interface concepts like 'drag and drop' using a GUI IDE.
Have you come across Node-RED (https://nodered.org/)? It's not exactly what you describe, but it does allow largely graphical programming of Raspberry Pi's and similar systems. The implementation uses JavaScript, running on the V8 engine of NodeJS. This is actually a native-code compiler, rather than a byte code VM, but it is cross platform.

I have not come across this until now and it looks great! I saw the introduction video and an example video of using Node-Red with a Pi and it seems a lot to take in. I'll be looking into this as well.


These may be reasonable examples of using VMs to execute virtualized platform runtimes in ways that are applicable to embedded systems of the general capacity of Cortex-M MCUs that exist (maybe pushing it for CM-0 but certainly some CM-3/4/7 devices are fully capable and these are 'advanced examples'):
https://en.wikipedia.org/wiki/.NET_Micro_Framework
http://www.eluaproject.net/overview

JAZELLE was an integration of an execution environment for JAVA VM bytecodes by ARM MCUs/CPUs:
https://en.wikipedia.org/wiki/Jazelle
https://en.wikipedia.org/wiki/ARM_architecture#Thumb_Execution_Environment_.28ThumbEE.29

The THUMB instruction set supported by many ARM MCUs is a compressed instruction encoding that generally maps to 'full size' ARM instructions so in a way a THUMB capable MCU is executing something like a VM of the THUMB ISA :
https://en.wikipedia.org/wiki/ARM_architecture#Thumb

As far as simpler examples, it wouldn't seem difficult for any MCU to emulate most other simple RISC MCUs.
If you look at the ISA of simple MCUs or RISCish processors like RISC-V, PDP-11, MSP430, 6502, 8032, PIC8/16, ARM, ARM THUMB, MIPS, et. al. it wouldn't be so hard to emulate the register set and instructions and handle the memory space 'virtually' etc.

If you look at the LLVM compiler that is commonly used these days it basically virtualizes ANY target platform that complies to a loose set of 'essential features' in the sense that it takes intermetiate representation 'IR' "VM" code that is platform independent and maps IR into the actual ISA by a thin platform dependent code generation layer.  So similarly one could even abstractly describe an ISA and have a translator implement the meta-ISA indirectly by the rules of the abstract ISA description language and then run it.

That all gets down to the fact that all Turing machines are equivalent if their implementation / programming capability is 'Turing complete' so the differences in how a particular machine implementation works is just a detail:
https://en.wikipedia.org/wiki/Universal_Turing_machine
https://en.wikipedia.org/wiki/Turing_machine

You could come up with some amusing TM mappings of arbirtary ISAs and cross simulate them that way.


I'll have a look at these links.

Thank you everyone for the info!
 

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3461
  • Country: it
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #8 on: July 15, 2017, 08:35:37 am »
Ladder programming is something I have never came across. I'll take a closer look.

oh, it's just a visual programming environment for industrial PLCs, makes sense where you mostly want to do logic, interconnect blocks
 

Offline voltsandjolts

  • Supporter
  • ****
  • Posts: 2299
  • Country: gb
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #9 on: July 15, 2017, 08:37:34 am »
This isn't a virtual machine implementation but does allow easy graphical programming of a microcontroller in an educational environment.
Using Arduino means there is a wide range of hardware ready to go.

Scratch is an open graphical programming language.
Scratch for Arduino (with IDE):
http://s4a.cat/

Nice student lab doc:
http://scratched.gse.harvard.edu/resources/expand-scratch-environment-microcontroller

Scratch:
https://scratch.mit.edu/
https://en.wikipedia.org/wiki/Scratch_(programming_language)
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #10 on: July 15, 2017, 07:32:58 pm »
Ladder programming is something I have never came across. I'll take a closer look.

oh, it's just a visual programming environment for industrial PLCs, makes sense where you mostly want to do logic, interconnect blocks

It is usually a graphical approach to creating machine control systems.  Each rung of the ladder has a number of inputs combined in some way to create an output.  Electrical control systems rarely use a 'schematic' representation of the logic but rather this ladder approach because it is simpler to understand (you're usually only looking at a single rung) and, in the old days, it was easier to draw.

Note in the following page how the 'graphics' looks a lot like ASCII art.  This is what was used in the very early days.

https://en.wikipedia.org/wiki/Ladder_logic
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: us
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #11 on: July 15, 2017, 07:51:34 pm »
National Instrument LabView has been used as a graphical programming platform for Lego Robotics for a very long time.

http://k12lab-support-pages.s3.amazonaws.com/lvbasichome1.html

Just pick up an element, place it on the page and wire it in.

MatLab has a nice interface to Arduino as well as some kind of interaction with ARM processors which I have not tried.  The Arduino add-on supports, among other things, the WiFi Shield.  Networking right out of a simulation!

It is possible to interface real world gadgets (sensors, switches, knobs and dials) with MatLab SimuLink simulations.  Very cool!

Still, I don't quite understand why somebody would write a byte-code interpreter for an embedded processor.  Unless, the interpreter was a separate contract using some documentation of how the byte codes would be interpreted but the byte code stream itself of unavailable (for any of several reasons).

Many Pascal implementations have used Niklaus Wirth's original P-code implementation.  Certainly the original P4 implementation as well as the UCSD Pascal implementation and others.  It was easier to get the compiler to emit P-codes and just leave the interpretation scheme to the run time interpreter.  This made the system quite portable.  Write an interpreter and you're up and running.
 

Offline IanB

  • Super Contributor
  • ***
  • Posts: 11859
  • Country: us
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #12 on: July 15, 2017, 09:52:23 pm »
I am not trying to accomplish anything yet. However, I can imagine developing a higher level language packaged in an IDE (i.e., with heavy use of GUI and reduce low-level coding as much as possible or eliminate it entirely) to program all uCs (platforms) so that anyone without technical background in uCs can program these devices.

The goal would be to get to a certain level of abstraction with regards to programming the uC, to the point where an elementary student can program any uC with interface concepts like 'drag and drop' using a GUI IDE.

I think the goal here would be less of a VM and more of a hardware abstraction layer (HAL)? If you abstract away the details of the hardware you can have a generic programming environment that can work on a variety of different hardware platforms. The Arduino system might be considered an example of this.
 

Offline julian1

  • Frequent Contributor
  • **
  • Posts: 733
  • Country: au
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #13 on: July 15, 2017, 11:40:30 pm »
Microsoft have been working on virtualizing X86 on ARM for some time, http://www.zdnet.com/article/microsofts-x86-on-arm64-emulation-a-windows-10-redstone-3-fall-2017-deliverable/

There is even a future patent dispute with Intel looming if they can't work out an agreement, https://news.ycombinator.com/item?id=14318406

As for programming using visual metaphors, that's been a thing for a while,

https://en.wikipedia.org/wiki/Visual_programming_language

It's arguable GUI based filesystems, GUI client DB apps to manage relational structures, and GUI template wizards in IDEs, are all examples.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6719
  • Country: nl
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #14 on: July 16, 2017, 12:21:10 am »
There's less LoC's of architecture specific code which has to be preserved on microcontrollers and less focus on performance.

If you want security domains then simply creating a sandbox using a "safe" programming language is good enough, also has the advantage that you are using a non retarded language so the security within the domain is vastly increased as well.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: Virtual Machines on Microcontrollers (Specifically for ARM)
« Reply #15 on: July 16, 2017, 10:56:14 pm »
I gather that when you say "VM", you don't mean "ARM on ARM" style VMs, but instead just some arbitrary byteCode based abstraction?
Where do you want to draw the line between "VM" and "Interpreter" ?  There are lots of interpreters for microcontrollers - BASIC, Python, Lua, Forth...  I'm not sure which ones have "pre-compile to bytecode", but it's probably not uncommon.  PICAxe seems like it would be close...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf