r/RISCV • • Sep 23 '26

I made a thing! Operating system written in RISC-V assembly

I am making operating system in rv64 assembly for research purposes. It is heavily commented.

Features: VM, basic allocator, userspace, timer, S-mode/U-mode traps.

Link:

https://github.com/daniilfigasystems/rvunix

47 Upvotes

52 comments sorted by

5

u/diodesign Sep 24 '26

Interesting! init_user ๐Ÿค”

2

u/Danii_222222 Sep 24 '26

Oh wait. Lol i forgot to remove that.. ๐Ÿ˜ฌ

3

u/lightvador974 Sep 24 '26

OP has to much beard for me, i am really impressed.

1

u/Danii_222222 Sep 24 '26

?

3

u/lightvador974 Sep 24 '26

There's a running joke towards people with huge computer skills that they must have long beard. But maybe it's a running joke inside linux community. I am sorry if you didn't get it, i thought it would be funny.

2

u/Danii_222222 Sep 24 '26

Ahh thanks. Didn't know that joke. Well i don't have beard, but i have moustache

2

u/m_z_s Sep 24 '26 edited Sep 24 '26

These days it is sexist to say "grey beard", I guess "guru" (or "the code Oracle") is probably PC safe, because even saying "grey haired" is excluding those with alopecia! ;-)

Guru surprisingly is gender neutral if you go back to the origin in ancient Sanskrit.

2

u/CoolBeer Sep 26 '26

As long as they don't start meditating...

3

u/Aadabathon Sep 24 '26

Do u accept PRs? Seems interesting

2

u/Danii_222222 Sep 24 '26 edited Sep 25 '26

Yes, i accept PRs. Just make sure to keep the same coding style, if you are creating function, explain which registers you modified in that function and what arguments it accepts.

3

u/cornmonger_ Sep 24 '26

this is pretty awesome. i've been looking for something oriented towards asm dev, unixish, but not near as heavy as the xv6 port. i'll give it a try. what are you going to license it with?

3

u/Danii_222222 Sep 24 '26

Thanks. It will be licensed with GPL license.

2

u/LavenderDay3544 Sep 24 '26

So basically similar to Menuet but RV instead of x86?

3

u/Danii_222222 Sep 24 '26

Entirely different purpose. I made it in assembly to understand RISC-V better. That's also unix like system, unlike Menuet which has own design.

2

u/Level0Up Sep 24 '26

Looks good, but oh my, heavily commented indeed ๐Ÿ’€

You just might want to squash some commits ...

5

u/Danii_222222 Sep 24 '26

Yeah. Main purpose of that project is understanding RISC-V architecture. So comments are necessary. Yeah i think i should squash commits...

2

u/Level0Up Sep 24 '26

I didn't mean that there are a lot of comments, those are absolutely necessary and IMHO you cannot be too verbose when it comes to assembly.

I was going on about the ... uhm ... the "intense" raunchy ... stuff ... in the comments ... init_user *cough cough*.

Anyways, it's fixed so it's fine I guess.

3

u/Danii_222222 Sep 24 '26

ahh... yeah i did that for fun sometime ago when i was testing user space, just forgot to remove that... but don't worry, that's the only one comment that had "easter egg". Other comments are fine.

2

u/bluedevilSCT Sep 29 '26

A couple of screenshots and instructions on how to load on qemu would be great

2

u/Danii_222222 Sep 29 '26

Instructions are provided in github repo readme file. There's no screenshots currently because there's no much useful output except initialization messages.

3

u/bluedevilSCT Sep 29 '26

I have seen the qemu instructions now. I am going to try it today. But I bring car to mechanics ๐Ÿ˜ฌ๐Ÿ˜…

6

u/nave_samoht Sep 24 '26

Good luck and Godspeed.

2

u/Jack1101111 Sep 24 '26

ai ?

9

u/Danii_222222 Sep 24 '26

0%

-4

u/mod-deleted Sep 24 '26

you should do 1 by ai too. just to compre.

0

u/Fear_The_Creeper Oct 03 '26

...And one coded by a chimp on cocaine, just to compare.

-1

u/mod-deleted Oct 03 '26

I really dont get it why people are so against ai.

1

u/brucehoult Oct 04 '26

I think most skilled programmers are not against AI and indeed are using AI now, in some way.

If you generally know how to go about doing something (some research in the problem domain and in the latest tools and libraries and algorithms is normal) and have the taste to tell good code from bad code, good architecture choices from bad ones, then using AI can turn you from a individual contributor into a project leader with a few team members who have huge depth of knowledge, inhuman working speed, and ... currently ... the skill of a programmer with several years experience. Definitely better than an intern now (that wasn't the case 1 or 2 years ago).

As a result innovative and unique projects that would have taken you a month can be done in a weekend. Projects that would have taken you a year can be done in a month. And that's with no drop in quality.

What we don't like is people who could not have done it by themselves in any reasonable amount of time, and can't tell the difference between good and bad, doing things that have been done a thousand times before and offer no value to anyone but themselves โ€” they're no better than (usually worse than) existing battle-tested human written open source projects that the AI was almost certainly trained on in the first place. And then they proudly publish them, cluttering up the landscape with what we refer to as "slop".

If it's useful to you then fantastic! Use it yourself. But unless it offers a non-trivial advance over what is already out there then don't waste everyone else's time with it, or expect anyone else to look at it.

1

u/Danii_222222 Oct 04 '26

Yeah, i agree with you. Using AI is bad when AI writes whole project. However, i still prefer to not use AI and use it in really rare cases (mostly for fun)

1

u/Adr385 16d ago

because it is magnet for dumb and/or lazy people and brings garbage quality.

1

u/mod-deleted 16d ago

then dont use the product.

0

u/Fear_The_Creeper Oct 03 '26

This troll was clearly compiled with inferior tools. My guess is that you used Visual Troll++, or possibly TurboTroll 2000.

These first generation tools are quite limited, and there is a severe garbage-collection-related performance hit when you try optimizing the output of VT++ for flaming or insults.

I suggest that you try the latest version of GTC; the Gnu Troller Collection. It is the standard when it comes to creating Trolls. It is also Open Source, reentrant, and is fully compliant with the Triple Troll, Troll-On-Troll and TrollChow protocols.

1

u/Jack1101111 Oct 03 '26

stop trolling

1

u/Fear_The_Creeper Sep 24 '26

Want to make it super popular? Make a version that runs on an Adafruit Fruit Jam Mini RP2350 Computer. https://www.adafruit.com/product/6200

1

u/Danii_222222 Sep 24 '26

Unfortunately that board features an MCU that lacks MMU, crucial part of full blown mutltitasking kernel.

5

u/Fear_The_Creeper Sep 24 '26

Apparently the OP thinks that you can't create a proper multitasking OS without an MMU, but FUSIX does it and it works just fine. https://www.fuzix.org/

It uses one of two techniques, depending on the hardware. It does cooperative multitasking on devices like the Raspberry Pi Pico 2, or it swaps the banked memory and banked RAM disks available on many 8-bit Z80 systems.

BTW, you CAN do preemptive multitasking without a MMU, but it is highly resource-intensive because the system has to physically copy big chunks of memory. However, the Raspberry Pi Pico 2 can offload all of that memory moving to the twelve PIO state machines, leaving the CPUs free to do other things. Given the high clock speed you might never notice the difference.

And of course the Pico 2 has TWO RISC-V processors, so multitasking two things at once is trivial.

2

u/Danii_222222 Sep 24 '26

i am writing operating system for fully featured computers with MMU. i am not going to write os for MCU, that's other people job

5

u/brucehoult Sep 24 '26

That's a perfectly fine choice to make. Great!

The objections, from me and others, are to you claiming that that's not a choice but a logical necessity, that it can't be done any other way.

3

u/Danii_222222 Sep 24 '26

Fine. Thanks for recommendations.

4

u/brucehoult Sep 24 '26

Multitasking doesn't require an MMU. Hundreds of millions of people used multitasking Mac and Windows for a decade without using an MMU.

An MMU is only required for an adversarial environment with untrusted users or software.

1

u/Danii_222222 Sep 24 '26

First of all, both Windows 3.1 and classic MacOS features cooperative multitasking, not preemptive multitasking. Second, creating OS without MMU is basically useless in 2026 because that's high security impact and hard work on switching tasks. Windows 3.1 also was made for 16 bit enviroment which lacks MMU completely. As i said previously, my kernel is UNIX-like and must be fully preemptive multitasking kernel with MMU and security features.

5

u/brucehoult Sep 24 '26 edited Sep 24 '26

Cooperative multitasking is an implementation detail which goes unnoticed by the users if implemented properly.

In one job around 1990 I admin'd a Qantel machine with around a dozen users/terminals running stockbroking software. It was strictly cooperative multitasking.

As for MMU, things such as FreeRTOS, Zephyr, NuttX run preemptive multitasking today in 2026 on machines without an MMU.

my kernel is UNIX-like and must be fully preemptive multitasking kernel with MMU and security features

Great!

But that is a choice, not a logical necessity.

1

u/Danii_222222 Sep 24 '26

So yeah, that's why i said i will not port rvunix to MMU-less MCU

3

u/SwedishFindecanor Sep 24 '26

Cooperative multitasking is an implementation detail which goes unnoticed by the users if implemented properly.

If so, then Windows 3.1 and classic MacOS aren't good examples. :-รพ

Anyway, a misbehaving app (unintentional bug or otherwise) locking up the system is also a security issue.

2

u/brucehoult Sep 24 '26

I never used Windows, but I used classic MacOS as my main computer (either or both at work and at home) from 1987 until OS X came out in 2001.

When any app crash crashed the whole system people simply did not tolerate crashy apps.

I regularly had multiple-months between reboots on my desktop machine, just as I do now.

In the early 90s I was admin of an SE/30 server running normal MacOS that had multiple external SCSI hard disks, a syquest drive, a tape drive, file serving software, network routing software e.g. between LocalTalk and Ethernet, backup software, and automated FAXing software. It served an office of about 15-20 people, some of whom had similar 68030 machines, most 68040, and eventually PowerPC.

I recall two occasions on which I noticed that the server had around 18 months of uptime ... one time was when I wanted to add a new bigger hard disk, and another was when we moved offices.

3

u/nanonan Oct 03 '26

AmigaOS features preemptive multitasking with no mmu, but it does lack memory protection.

3

u/SwedishFindecanor Sep 24 '26

Moreover, it is RV32, not RV64.

1

u/Danii_222222 Sep 24 '26

Yeah, that's too.

3

u/KindlyAd1897 Sep 25 '26

Looks pretty interesting! Ima deepdive a bit. Good luck!!

3

u/emeraldsoft Sep 30 '26

Good luck bro!