The JS Platform

To make trying StahlOS out easier, it can run under unicorn.js in the browser. This is rather slow, but actually works! This is implemented as the js platform, which this page will describe for reference.

Memory Layout

Due to JavaScript's number type not being able to store 64-bit integers, unicorn.js has some strange behavior around large addresses. As a result, things are mapped to an address that's lower than might often be expected.

RAM starts at 0x10000, and is 128MiB (0x8000000 bytes) long. The devicetree gets stored to 0x10000. The kernel is loaded at 0x20000.

A special region of memory is mapped from 0xffff0000 to 0xffffffff. This is the host interface, and is used to communicate between the browser and the kernel.

Host Interface

The host interface acts as a memory-mapped peripheral.

Commands

The main way the kernel communicates with the host interface is by writing a single byte to 0xffff0000. Depending on the value of the byte, this can mean several things:

0x00: Write to the Console

Writes the UTF-8 string whose address is in x0 and whose length is in x1 to the console.

0x01: Panic

Stops emulation permanently, and puts the UI into "panic mode."

0x02: Idle

Stops emulation temporarily, restarting it on the next user input.

User Input

User input is stored in a circular buffer, between addresses 0xffff1000 and 0xffff1fff (inclusive). The offset from 0xffff1000 where the next byte of input will be stored is in the halfword at 0xffff0002.