36 comments

[ 3.9 ms ] story [ 83.1 ms ] thread
I love rust and it’s fascinating to see what people can do with it. Exciting game and great find.
> 212kB

Rust'll be ready for embedded when it is 512 bytes: https://gitlab.com/pmikkelsen/asm_snake

Arduino UNO has 32kb of RAM, which Rust can target... so maybe good enough for some people
The Atmega 328P that the Uno uses has 2kb of RAM, and 32kb of ROM (technically, writable on boot, but not after you leave the bootloader).
I could be dead wrong, but isn't x86 not an architecture suited for embedded systems?
Most embedded systems running most factories would disagree with you. Embedded x86 is pretty big
but just to be clear, nobody cares about kilobytes there.
Embedded is not a clearly defined concept when it comes to size. When I worked with embedded Linux with a Gigabyte or two of RAM, we used to make the difference to the microcontroller world by calling them embedded embedded.
Embedded systems are a very large range, depending on what kind of performance needs to be embedded. From tiny microcontrollers on one end to what's equivalent to high-end workstations with custom hardware interfaces on the other (and probably talking to smaller controllers).

x86 hasn't been successful in the microcontroller half of things (even though fast microcontrollers beat some x86 options, so it's not a size thing, but there hasn't been a compelling offering), but on the microprocessor side of things it has its uses, primarily but not exclusively towards the high-end nowadays (due to competition by ARM). To add another line to differentiate, x86 without an OS is going to be quite rare nowadays.

Doesn't seem fair to hold a code size contest and not measure the code executed in BIOS calls. Anyone can get ever-smaller code sizes if you just move the code to somewhere outside the region gauged by the test.
For comparison, 212k is roughly the size of DOS 2.x.
The world has evolved. Everybody knows that Rust is better than C or ASM. So a little increase in binary size is good for security.
Couldn't the binary be made smaller with additional compiler options? From what I read in the repository, they weren't going for the smallest size.
Embedded is not just small microcontrollers (re 512 byte being a target), and this is likely not a size-optimized build.
> 212kB

Here's a 11 kB bootable x86-64 version of the game written in C# https://github.com/kant2002/SeeSharpSnake/tree/kant/uefi#run....

There's an accompanying article with a video at the bottom https://codevision.medium.com/running-c-snake-inside-uefi-df....

So I admittedly only skimmed that link very briefly. But... how? I would think the c# runtime alone would balloon this to some astronomical size.

Edit: Got my answer. /p:Mode=CoreRT-NoRuntime, /nostdlib, and a bunch of others.

So how does it work. Where do the standard library functions come from? Where do all the garbage collecting functionality gets loaded from?. Or is it more like pinvoking a reduced external library in C for all needed functionality.
He used a few different techniques.

1. Used CoreRT instead of the standard .NET libraries 2. He avoided using functionality that would use GC in the first place 3. Created his own alternative runtime library w/out GC and exception handling 4. Created a base type library for some of the System functions 5. Re-directed certain functions like Thread.Sleep to smaller implementations in specific libraries.

The blog posting is well worth reading:

https://medium.com/@MStrehovsky/building-a-self-contained-ga...

This is also a very good example that not all languages with GC are created equal, some do provide the mechanisms to do alternative ways of managing resources.
This implementation uses async/await, data structures from Rust's standard library (alloc crate), plus streams and channels (30 dependencies in total), so it's pretty fancy for a "no_std" project.

Bare-bones Rust executables can start at about 3.5KB, and code size increase on top of that is comparable to C or C++. Rust can be a "portable assembler" if you write code in such style. It can also generate lots of code if you lean into generics (same issue as with C++ templates).

Obligatory comment about how an operating system is "system software that manages computer hardware, software resources, and provides common services for computer programs" and not just a program that executes at startup.
Obligatory comment about how you must be great at parties.
Obligatory comment about that this software abstracts away display, memory and interrupt management and provides services for the snake module. Also I like the name snakeos, since it doesn't promise more than it can deliver
I didn't take this comment as derogatory. Instead I see it as a good comment explaining that this example is much more than just "a program that executes at startup"... as it seems some people may have initially thought when glancing at only the start of the github readme page.
"An operating system is a collection of things that don't fit into a language. There shouldn't be one." – Dan Ingalls, in an article in Byte Magazine, 1981
Bootable? Does that mean BIOS legacy? Modern PCs can only boot UEFI binaries.

(Just wondering. Of course nobody would seriosly want to use a modern PC to run that game.)

Do they not still have both modes? I haven't bought a motherboard for a couple of years, but the last few that I have have been both. (And basically I've not known or cared which I used!) Seems an unfortunate backwards compatibility loss if so.
I don't know the details. But legacy boot mode support was supposed to be phased out between 2019 and 2021.

Couldn't quickly find a good reference, here is at least some: https://www.dell.com/support/kbdoc/fi-fi/000151899/no-boot-d...

Edit: UEFI class 3 is the keyword https://en.m.wikipedia.org/wiki/Unified_Extensible_Firmware_...

Class 3 is the progressively lower class which is designed to get users to accept lesser functionality as more "modern" so therefore it must be "better" or something.
> Of course nobody would seriosly want to use a modern PC to run that game.

It's a technology demonstrator. And people run all sorts of tools from USB drives. For example, I recently ran a memory tester from USB.

Is there any memory tester that runs from UEFI?
For projects like this I like it when they go all the way and post the proven IMG file, in this case snakeos.img.

How much space can it take up?

Without that lots of visitors are not going to look much further at it.

If the IMG was there, I would have already tested it on bare metal, if it fit on a floppy that functionality would have been confirmed bare metal too.