$ cat ~/devlog/wallos-user-mode.md
WallOS v0.6.1 - User mode & others
Since the last devlog, I've a decent amount of progress in terms of user mode, including a complete VMM rewrite.
VMM
The VMM itself is pretty "unremarkable", at least in terms of implementation. It's mostly just a "fully featured" VMM as one would expect.
The VMM supports:
- Demand Paging
- Per-task address spaces
- Direct Map of RAM
- Copy On Write
- Kernel Virtual Arena (with hopes to maybe add a small vmalloc in the future)
- Backing Objects (so things like files can be mmap'd)
- NX, PCID, and SMAP/SMEP support.
- VMM Stat tracking
- 4KB/2MB/1GB Page support
- TLB shootdowns
There is still a lot of "jank" in the VMM, but most of the "modern" interface is cleaned up significantly. Most of the other kernel subsystems were built with the assumption of 2MB pages, and I didn't really want to spend another week or two chasing down bug associated with that. I have left in most of the support required for the assumptions made elsewhere in the kernel (marking the functions deprecated, as a reminder), and will clean them up "eventually".
Something else to note is that I completely swapped both the VMM and PMM to be completely in C, rather than C++. Them being written in C++ was something left over from the very start of the kernel, and virtually nothing in the kernel uses C++ anymore. I will slowly clean up the remaining C++ as I touch those systems in the future, and will continue to "support" C++ in the kernel, but I have little desire to write C++ in the kernel anymore.
The VMM is (obviously) x86_64 exclusive as is, and will likely need a heavy bit of abstraction later on when I decide to try to port WallOS to another architecture, but that's a problem for the future. I partially designed it with the thought that I would want it abstracted eventually, but also only half cared about it, so some semblance of portability is there in the interface.
User Mode
The scheduling update (last devlog) technically supported (and I successfully tested) user mode programs, but they were very limited in capability. The thing holding them back the most was the VMM, which was just discussed.
I have been working mostly on the kernel side of user mode, adding mostly syscalls and syscall related things.
Most recently, I have focused on adding FD and FD tables, letting user mode programs behave mostly as normal, and can use things like printf(), and open/close/read/seek files.
I have simultaneously been working on the mlibc port (updates yet to be committed... I'm bad about remembering to commit). This is mostly just tedious work at this point, adding small wrappers around my implemented syscalls.
ELF Loading
As a bit of a side project, well over a month ago I wrote a small (private) ELF parser.
I have integrated this into WallOS, with the ability to load/run programs using proc in the command line.
The implementation for proc itself has most of the stuff surrounding mapping and loading segments, but will likely eventually be pulled out into a proper interface whenever I add exec/fork.
Other Things
In touching the VMM and syscalls, I've gradually fixed a lot of other subsystems as I've stumbled across them (or just side quests, I get distracted).
Some other random changelog stuff:
- Fixed some bugs in apollo, greatly improving some hot paths in pixel placement and drawing.
- Added support for proper kernel panics with SMP.
- Before, kernel panics with the scheduler on would only stop the CPU that had a panic, the others would continue.
- This includes adding proper a "pink screen of death" to framebuffer mode, since I apparently never did that.
- Cleaned up some bits of cursor handling (and display handling in general).
- Added a few user mode test programs to initrd.
- These require up-to-date mlibc to be able to run properly. I also really need to actually handle proper toolchain building...
- Decently sized change to WallShell (that needs to be ported upstream) that allows for much easier handling of subcommands.
- This also allows for top level commands that were purely "dispatchers" before to now be handled by WallShell directly. This means things like the serial command that only had subcommands don't need to dispatch on their own, WallShell can call the subcommands directly (and automatically handles shrinking argv/argc).
- Added "yield locks". Easier to work around than regular blocking mutexes (I hate how I set up blocking in the scheduler, it needs more thought).
- Yield locks are nice for expected short waits than regular mutexes, and better than wasting CPU cycles busy-waiting.
- Changed how general configuration works.
- All configuration options, for both
makeand the OS in general are now in<proj_root>/config, rather than being in the project root directly. - Also added a "default" configuration for make in
config/make/default.config.mk - In the process of doing this I also cleaned up a few makefile bugs (nothing critical).
- All configuration options, for both
- Added support for
distcc- My laptop builds are very slow (using WSL), which inspired me to get
distccworking. The makefile for it a little ugly, but shouldn't really need to be touched, all configuration is inconfig/make/config.mk.distccworks very in general, cuts my build times on slower systems by roughly 1/2
- My laptop builds are very slow (using WSL), which inspired me to get
- Added some initial support for parsing boot variables
- I want to have some from of serial output only (I have an APU1D that only has serial out), and this was one of the first steps. Needs a lot more thought though.
Known Bugs:
- I found a bug relating to an off-by-one bug in ACPICA. I am several versions behind in my ACPICA port, and will get around to updating this eventually. uACPI works fine (with a few small fixes), and I am choosing to just deal with that right now instead of re-porting ACPICA. uACPI itself is also several versions out of date, but that's another problem for another day, and not very high of a priority.
What's Next?
My main focus right now is getting some more user side support for things. Having a working user mode opens the doors to a lot of things, and I have a lot of ideas about what I want to do.
In no particular order (haven't decided which I want to do first yet):
- WallOS Installer
- Been wanting to be able to install WallOS, from an interactive image, for a while. I in theory have everything I need for this, just need to put it all together in a usable way.
- User mode terminal & TTYs
- Intel HD Audio Driver
- Some form of user mode display management
- Networking (at least basic support)
- Lua Scripting
- I've always wanted some form of "live" scripting in the OS. Lua seems like one of the easiest to implement, and would be useful for creating runnable scripts that don't necessarily need a full terminal environment.
- Port DOOM
- A friend keeps asking when WallOS will run DOOM as a joke, it's going to be one of the first major programs I port.
- Port some small CLI utilities (tree, select things from sbase)