Writing A RISC-V OS From Scratch

If you read Japanese, you might have seen the book “Design and Implementation of Microkernels” by [Seiya Nuda]. An appendix covers how to write your own operating system for RISC-V in about 1,000 lines of code. Don’t speak Japanese? An English version is available free on the Web and on GitHub.

The author points out that the original Linux kernel wasn’t much bigger (about 8,500 lines). The OS allows for paging, multitasking, a file system, and exception handling. It doesn’t implement interrupt handling, timers, inter-process communication, or handling of multiple processors. But that leaves you with something to do!

The online book covers everything from booting using OpenSBI to building a command line shell. Honestly, we’d have been happier with some interrupt scheme and any sort of crude way to communicate and synchronize across processes, but the 1,000 line limit is draconian.

Since the project uses QEMU as an emulation layer, you don’t even need any special hardware to get started. Truthfully, you probably won’t want to use this for a production project, but for getting a detailed understanding of operating systems or RISC-V programming, it is well worth a look.

If you want something more production-ready, you have choices. Or, stop using an OS at all.

Programming Ada: Atomics And Other Low-Level Details

Especially within the world of multi-threaded programming does atomic access become a crucial topic, as multiple execution contexts may seek to access the same memory locations at the same time. Yet the exact meaning of the word ‘atomic’ is also essential here, as there is in fact not just a single meaning of the word within the world of computer science. One type of atomic access refers merely to whether a single value can be written or read atomically (e.g. reading or writing a 32-bit integer on a 32-bit system versus a 16-bit system), whereas atomic operations are a whole other kettle of atomic fish.

Until quite recently very few programming languages offered direct support for the latter, whereas the former has been generally something that either Just Worked™ if you know the platform you are on, or could often be checked fairly trivially using the programming language’s platform support headers. For C and C++ atomic operations didn’t become supported by the language itself until C11 and C++11 respectively, previously requiring built-in functions provided by the toolchain (e.g. GCC intrinsics).

In the case of Ada there has been a reluctance among the language designers to add support for atomic operations to the language, with the (GNU) toolchain offering the same intrinsics as a fallback. With the Ada 2022 standard there is now direct support in the System.Atomic_Operations library, however.

Continue reading “Programming Ada: Atomics And Other Low-Level Details”

2024 Brought Even More Customization To Boxes.py

If you have access to a laser cutter, we sincerely hope you’re aware of boxes.py. As the name implies, it started life as a Python tool for generating parametric boxes that could be assembled from laser-cut material, but has since become an invaluable online resource for all sorts of laser projects. Plus, you can still use it for making boxes.

But even if you’ve been using boxes.py for awhile, you might not know it was actually an entry in the Hackaday Prize back in 2017. Creator [Florian Festi] has kept up with the project’s Hackaday.io page all this time, using it as a sort of development blog, and his recent retrospective on 2024 is a fascinating read for anyone with an eye towards hot photonic action.

Continue reading “2024 Brought Even More Customization To Boxes.py”

Minecraft In…COBOL?

When you think of languages you might read about on Hackaday, COBOL probably isn’t one of them. The language is often considered mostly for business applications and legacy ones, at that. The thing is, there are a lot of legacy business applications out there, so there is still plenty of COBOL. Not only is it used, but it is still improved, too. So [Meyfa] wanted to set the record straight and created a Minecraft server called CobolCraft.

The system runs on GnuCOBOL and has only been tested on Linux. There are a few limitations, but nothing too serious. The most amazing thing? Apparently, [Meyfa] had no prior COBOL experience before starting this project!

Continue reading Minecraft In…COBOL?”

Faster Integer Division With Floating Point

Multiplication on a common microcontroller is easy. But division is much more difficult. Even with hardware assistance, a 32-bit division on a modern 64-bit x86 CPU can run between 9 and 15 cycles. Doing array processing with SIMD (single instruction multiple data)  instructions like AVX or NEON often don’t offer division at all (although the RISC-V vector extensions do). However, many processors support floating point division. Does it make sense to use floating point division to replace simpler division? According to [Wojciech Mula] in a recent post, the answer is yes.

The plan is simple: cast the 8-bit numbers into 32-bit integers and then to floating point numbers. These can be divided in bulk via the SIMD instructions and then converted in reverse to the 8-bit result. You can find several code examples on GitHub.

Continue reading “Faster Integer Division With Floating Point”

Better C Strings, Simply

If you program in C, strings are just in your imagination. What you really have is a character pointer, and we all agree that a string is every character from that point up until one of the characters is zero. While that’s simple and useful, it is also the source of many errors. For example, writing a 32-byte string to a 16-byte array or failing to terminal a string with a zero byte. [Thasso] has been experimenting with a different way to represent strings that is still fairly simple but helps keep things straight.

Like many other languages, this setup uses counted strings and string buffers. You can read and write to a string buffer, but strings are read-only. In either case, there is a length for the contents and, in the case of the buffer, a length for the entire buffer.

Continue reading “Better C Strings, Simply”

Pixel mashup with Wasm-4 logo and retro graphics

WASM-4: Retro Game Dev Right In Your Browser

Have you ever dreamt of developing games that run on practically anything, from a modern browser to a microcontroller? Enter WASM-4, a minimalist fantasy console where constraints spark creativity. Unlike intimidating behemoths like Unity, WASM-4’s stripped-back specs challenge you to craft games within its 160×160 pixel display, four color palette, and 64 KB memory. Yes, you’ll curse at times, but as every tinkerer knows, limitations are the ultimate muse.

Born from the WebAssembly ecosystem, this console accepts “cartridges” in .wasm format. Any language that compiles to WebAssembly—be it Rust, Go, or AssemblyScript—can build games for it. The console’s emphasis on portability, with plans for microcontroller support, positions it as a playground for minimalist game developers. Multiplayer support? Check. Retro vibes? Double-check.

Entries from a 2022’s WASM-4 Game Jam showcase this quirky console’s charm. From pixel-perfect platformers to byte-sized RPGs, the creativity is staggering. One standout, “WasmAsteroids,” demonstrated real-time online multiplayer within these confines—proof that you don’t need sprawling engines to achieve cutting-edge design. This isn’t just about coding—it’s about coding smart. WASM-4 forces you to think like a retro engineer while indulging in modern convenience.

WASM-4 is a playground for anyone craving pure, unadulterated experimentation. Whether you’re a seasoned programmer or curious hobbyist, this console has the tools to spark something great.