The Merlin Engine - full speed ahead

Although the blog has been extremely quiet, we have been really busy at work. As mentioned in our last post, we were going to release the original Merlin Engine source code. However, as we had a requirement for a new Virtual Machine (VM) for another project, we took the key design learnings from Merlin and built a completely new VM, designed from the ground up to support processors with limited RAM and the emerging many-core processors such as the XMOS XCORE and the Adapteva Epiphany. These many-core processors have as little as 32KB of RAM for programs and data, meaning that the VM Instruction Set Architecture (ISA) and memory-map must be as compact as possible.

Once our tests are complete, it will be released on GitLab under the MIT Open Source license and will be free to use and modify for any application, whether personal, academic or commercial.

The Merlin Engine has benefited from our research and work on the Osiris VM over the last couple of years but the design has also been strongly influenced by the need to provide support for parallel many-core programming languages such as ePython. It has also been designed to be easily tailored - many-core processors, such as the 1024 core Epiphany V, require new programming paradigms, where different VMs could be deployed to run applications at scale e.g. some cores may run an integer only VM, some may run VMs that only perform I/O operations on behalf of the other core VMs.

Although the Merlin Engine is designed to support high-level programming languages, the bytecode instruction set is supported by an assembler for the development of new opcodes and for regression testing. For the brave, it could also be used for developing applications / libraries...

The Merlin Engine supports, and has been tested on, the following processors:

  • x86 (16/32 & 64bit) - gcc, clang / LLVM, Watcom C, Borland C++
  • ARM7TDMI (32bit), ARMv6Z (32bit), ARMv7-A (32bit), ARMv8-A (32/64bit) - gcc
  • SPARC v9 (64bit) - gcc
  • MIPS (32bit) - gcc
  • Adapteva Epiphany III (32bit) - gcc / e-gcc
  • NXP 68K/Coldfire (32bit) - CodeWarrior
  • Zilog Z80 (8bit) - sdcc

Octane is currently focussing on Merlin Engine development and its integration with Osiris, with planned updates including:

  • Vectored interrupt support
  • Parallel collective operations - similar to those in ePython, MPI and MapReduce

We would like to thank Steven James at Perfect Consulting for his continued collaboration on the design and implementation of Osiris and the Merlin Engine.

Octane - a boost for development

Octane is excited to reveal that we have been working closely with Perfect Consulting on a couple of projects, including the next version of Osiris. Perfect's founder, Steven James, has extensive commercial experience in implementing programming languages and has worked for TopSpeed / Borland and MicroFocus writing compilers. It's fantastic to be working with Steven again - it has been over 20 years since we developed the beta of Merlin, a children's visual programming language for floor robots. We will release the Merlin Engine source code soon, once we have it compiling cleanly using modern compilers as it's a nice example of simple, elegant and efficient code that merges high-level source code with assembly language. Steven's GSFORTH strongly influenced the design of the Merlin Engine and you can find his latest version here.

 


Merlin screenshot

Merlin was renamed Montage after feedback from teachers who were concerned about a programming language for children that was promoting wizards and hence witchcraft! (The tools were originally called "spells".) How things have changed post Harry Potter...

The next version of Osiris will have a new, modular pipeline compiler that will also target a new virtual machine designed in partnership with Perfect Consulting. Not only will this version create even smaller ROM images than the current C-based library but will also enable the debugging and patching of compiled Osiris programs on the hardware board directly - greatly reducing the time to market for Osiris-based solutions.

2015 has been an exciting year for Octane and even more is in store for 2016!

Thanks for the memory... Crafting a better runtime

The key design goal of Osiris is to support embedded and Internet of Things (IoT) applications running on a number of different microcontroller families e.g. ARM Cortex-M3/M4 and AVR. We have been very busy over the last couple of months redesigning and reimplementing the Osiris runtime library and memory model in order to reduce the size of the compiled application binaries and their memory (RAM) footprint from that originally used by its Sun workstation-based predecessor Anubis. Although Anubis applications could run quite successfully on ARM Cortex-based boards, the challenge of dramatically reducing the size of Osiris applications and their memory footprint was raised when we were asked if Osiris could produce applications for the Intel MCS-51 (better known as the 8051/8052) family of 8 bit microcontrollers

Although the main focus of Osiris development has been for the 32 bit ARM Cortex-M series using the LLVM compiler toolkit, we have also been working in the background on a version for the modern 8 bit AVR microcontroller family using the C compiler backend...


On track and forging ahead

It's been a really busy month but we have now reached an important milestone ahead of time - Osiris is now self-hosting! This means that the compiler is written in Osiris and executes on top of the runtime library. Now the compiler will run on any platform that the Osiris runtime library is ported to and is no longer dependent on an installation of the Java Virtual Machine (JVM).

The process of creating a self-hosting compiler (just like Java, Python, C++ ,TypeScript etc.) is known as bootstrapping. It involved modifying a version of the Osiris compiler to include features found in PS-algol (e.g. structures and the pntr type) to create a new version of the language that was able to compile the original Anubis compiler (all c. 2500 lines of it...) The original Anubis compiler couldn't be used directly because there wasn't a freely available PS-algol or S-algol compiler that could deal with its size or the language features that it used. This meant transcoding, by hand, the compiler from PS-algol to Java to give the first working Osiris compiler - a process that took just over two weeks.

Although features were added to the original Java-based Anubis compiler, and some of the language semantics were changed to create Osiris, it was always planned to drop this version a later stage in favour of a self-hosted one. It has been a balance between continuing to add functionality to a legacy compiler and building one that was reliable enough to bootstrap the original Anubis compiler. Late last week we reached this point and it was time to move forwards with a self-hosted compiler. The modifications to the Osiris compiler and runtime support library, plus the bootstrapping of the Anubis compiler, took just three days. Over the next week it will be brought up to exactly the same specification as the current Java-based Osiris compiler.

Now that we have the planned self-hosted compiler, we can forge ahead with the support for LLVM IR code generation. This will replace the current C intermediate code and compilation phase and will allow us to create a single compiler binary that can target a number of processor platforms (ARM, x86/x64 etc.), making the distribution of the offline Osiris toolkit much easier. It will also enable Osiris applications to integrate more seamlessly with those written in C++ using the new ARM DS-5 toolkit. As the current Java-based compiler can also target JavaScript we are able to run the new self-hosted compiler in the browser or node.js. We will retain this target in the new compiler to allow us to deliver an online Osiris IDE that targets ARM Cortex-M3/4 boards.

In the next post, I'll compare the C and LLVM code generation, and the new optimised Osiris memory model.


A new programming language for the IoT

Osiris has been developed from the Anubis programming language, originally designed by Richard Loxely (Gibbs), Andrew Tindale and myself in 1991 at the University of St. Andrews. Osiris is targeted at delivering applications for the Internet of Things (IoT) running on boards based on the ARM Cortex-M platform.


Features:

  • Object-Oriented (OO): simple, yet powerful class-based model:
    • All class data items are private
    • Methods can be public (called interface procedures) or protected (default)
    • There no access modifiers to allow data items to be made public or protected - enforcing data encapsulation and good OO programming practice
    • Supports single inheritance and interfaces - unlike Java, all classes can be inherited as interfaces by subclasses
  • Simple: easy to read syntax and consistent semantic model means it's quick to learn and master
  • Powerful: fully block-structured with features like nested procedures / methods, first-class functions (including closures), lazy object instantiation and recursive class definitions (to support data structures like linked lists etc.)
  • Resilient: statically type checked and safe memory access - references are implicit and handled by Osiris itself, there are no null pointer exceptions because there are no explicit pointers and all items are declared with a value - classes and methods cannot be abstract
  • Lightweight: designed from the ground up to be compact - ARM Cortex-M boards have limited memory resources e.g. 256KB RAM. There is no virtual machine overhead and the Anubis object-oriented model has been re-designed for Osiris for simple, deterministic and efficient memory management
  • High Performance: applications execute at native code performance levels - the generated C code has been designed to allow modern C compilers to optimise the executable code and the object-oriented model has been written to reduce the overheads associated with method calls
  • Portable: the environment can be run on any platform supporting Java 5 (and above) and[update] a C99-compliant C compiler (including gcc, clang, tcc and ARM Keil MDK). It currently supports bare metal ARM Cortex-M3/M4[update], Keil RTX, Linux (x86/x64 and ARM), OS X 10.4-10.10 (x86/x64 & PowerPC) and Microsoft Windows Vista,7,8 & 10 (x86/x64)
  • Secure: the remote code update mechanism that is currently in development will enable simple, reliable and secure updates to IoT applications running in the field...


ARM Microcontroller Design Contest

We are really excited that our proposal for the ARM Microcontroller Design Contest has been shortlisted from a large number of applicants from across the world. Time is tight as all the selected projects must complete and submit by June 30th but it's great to have a challenge to keep the mind focussed...

Our project, based on the Freescale FRDM-K64F, will enable reliable and secure code updates to boards running in the field - no restarts / reboots required. The updates will be sent using MQTT, a lightweight and reliable publish and subscribe messaging protocol, that is rapidly becoming the standard for the Internet of Things (IoT). The traditional methods of updating the software (firmware) have become simple when you have physical access to the board but they are generally difficult or impossible to use when the device is in situ e.g in a cupboard, on a bridge or (literally) in a field. The project will enable these firmware updates to be made via number of network technologies (Ethernet, WiFi, 3/4G, Bluetooth, Xbee etc.) by leveraging the dynamic executable code storage and retrieval (persistence) technology underpinning Osiris - making it much easier for the maker community to maintain ARM Cortex-M based solutions once they have been deployed.

As all projects must be Open Source and will be posted on the ARM website to download, you'll be able to see how we got on for yourself after June 30th. In the meantime, check back regularly for updates on our progress.


Welcome to our blog

We're having a great time here at Octane - this year is our 21st anniversary and we're celebrating with a new website and a return to our roots. Whether in the office or in our lab, we're hard at work having fun - sweating the difficult stuff and learning new things.

We have a couple of projects underway at present and you will be able to follow their progress on this blog but for now, we'll leave you with a short background to Osiris.

Last year we made the decision to return to our passion for embedded solutions development and are working with another company to deliver the software for their range of digitally controlled guitar amplifiers and effects...