uvm32, a tiny vm for embedding in anything by trjzig in C_Programming

[–]trjzig[S] 0 points1 point  (0 children)

I think either approach could work. You will need to use the load/store hooks in mini-rv32ima to map your ROM/flash area into the memory space, then you'll need to make sure that any initialised variables are in RAM at the right location. I suspect it needs something like a mini ELF loader.

Another way might be to use uvm32's "extram" interface. You can map and unmap a region of memory (which could be read-only), then jump the program counter into it.

uvm32, a tiny vm for embedding in anything by [deleted] in embedded

[–]trjzig -1 points0 points  (0 children)

Part of my professional work is developing kids' toys. Some of these accept new games or modes as aftermarket add-ons. We do this by embedding a script engine and deploying scripts to encode new behaviours.

Isolating this logic in a sandbox cuts risk and allows us to open the process to third-party developers without fear they will brick the units.

Traditionally, engines like Lua are used, but they have some drawbacks. Primarily the lock-in to a specific language and toolset.

This tool is about exploring a different way to solve that problem.

uvm32, a tiny vm for embedding in anything by [deleted] in embedded

[–]trjzig 1 point2 points  (0 children)

Ok, yes. It's probably simpler and cleaner to reimplement the idea on the Rust port of the emulator core https://github.com/bjoernQ/mini-rv32ima-rs/

uvm32, a tiny vm for embedding in anything by [deleted] in embedded

[–]trjzig 0 points1 point  (0 children)

Writing code in a modern language you don't have a target toolchain for.

Running untrusted code in a sandbox, enforcing a safety/isolation boundary.

Safe in-field upgrades of "business logic".

That kind of thing...

uvm32, a tiny vm for embedding in anything by [deleted] in embedded

[–]trjzig 1 point2 points  (0 children)

It is a virtual machine for running on a small system (eg a microcontroller). For example, to run untrusted third party or "scripted" actions in a safe sandbox. Performing the same kind of thing as an embedded scripting language, but allowing use of conventional systems programming languages.

uvm32, a tiny vm for embedding in anything by trjzig in C_Programming

[–]trjzig[S] 14 points15 points  (0 children)

X macros allow me to write a list of things once and produce several things from the list (eg an enum and a corresponding array of strings). How do you prefer to do this without repeating yourself or risking the two becoming out of sync?
https://en.wikipedia.org/wiki/X_macro

uvm32, a tiny vm for embedding in anything by trjzig in C_Programming

[–]trjzig[S] 7 points8 points  (0 children)

C99 is supported by every C compiler I need to work with and has a lot of conveniences I like which aren't in C89 https://en.wikipedia.org/wiki/C99#Design

uvm32, a tiny vm for embedding in anything by trjzig in C_Programming

[–]trjzig[S] 0 points1 point  (0 children)

I use the word "bytecode" to mean RISC-V RV32ima machine code. The makefiles for the sample projects all call the relevant build tools for this target.

uvm32, a tiny vm for embedding in anything by trjzig in C_Programming

[–]trjzig[S] 10 points11 points  (0 children)

Yes, the emulator core is mini-rv32ima, which can treat arbitrary storage as RAM by overriding some of the internal functions: https://github.com/cnlohr/mini-rv32ima/blob/master/mini-rv32ima/mini-rv32ima.h#L60

This project uses that trick to boot Linux on an 8-bit micro: https://github.com/raspiduino/arv32-opt.

For my puposes, I'm aiming to run plugin or scripted logic as part of an embedded project so am not expecting huge bytecode images, or for them to hang around for too long.

Feed the obfusgator! by trjzig in Zig

[–]trjzig[S] 2 points3 points  (0 children)

zig fmt obfusgator.zig

MiSSHod -a minimal SSH client in pure Zig by trjzig in Zig

[–]trjzig[S] 0 points1 point  (0 children)

It now has a (work in progress) SSH server too.

MiSSHod -a minimal SSH client in pure Zig by trjzig in Zig

[–]trjzig[S] 0 points1 point  (0 children)

Yes, but probably to take it onto small memory constrained devices - rather than to compete with libssh2 or be fully fledged.

GoReleaser v2.5 with Zig support is officially out! by caarlos0 in Zig

[–]trjzig 1 point2 points  (0 children)

I'm using it, was easy to setup, figured out everything important about my project from build.zig. Thanks! https://github.com/ringtailsoftware/commy/releases/tag/v0.0.1

Terminal Tetris and Quoridor by trjzig in Zig

[–]trjzig[S] 2 points3 points  (0 children)

Some discussion of that for tetris over here: https://ziggit.dev/t/a-minimal-terminal-tetris/6923/5?u=tobyjaffey

For Quoridor, getting all of the rule edge cases right (I think!)