drewdevault,
@drewdevault@fosstodon.org avatar

I needed a break from Real Work, so I'm speedrunning writing a Unix-ish operating system

Day 3

aud,

@drewdevault me, my hobby whiskers twitching: “how would… how would you even start on this? With what the UEFI/bios exposes? Huuuuuh”

drewdevault,
@drewdevault@fosstodon.org avatar

@aud source code:

https://git.sr.ht/~sircmpwn/bunnix

89 commits so fairly easy still to see how it grew

Also consult:

https://wiki.osdev.org/Main_Page

And the Intel/AMD specs and the PCI specs and other specs, lots of reading specs in OS dev

drewdevault,
@drewdevault@fosstodon.org avatar

@aud I also have an EFI bootloader here if you're curious how that works:

https://git.sr.ht/~sircmpwn/hboot

though this is for a different OS project

levitte,
@levitte@mastodon.nu avatar

@drewdevault
Is this separate from Helios?

drewdevault,
@drewdevault@fosstodon.org avatar

@levitte yes

ezpy,
@ezpy@fosstodon.org avatar

@drewdevault Writing in C?

drewdevault,
@drewdevault@fosstodon.org avatar

@ezpy Hare

drewdevault,
@drewdevault@fosstodon.org avatar

Further day 3 progress

drewdevault,
@drewdevault@fosstodon.org avatar

The hacking shall continue until we are self hosting

drewdevault, (edited )
@drewdevault@fosstodon.org avatar

Oh look, an iso

https://files.catbox.moe/o3n1z4.iso

(legacy boot only)

docbibi,
@docbibi@freiburg.social avatar

@drewdevault so bunnix is a standalone endeavour? No external kernel?

drewdevault,
@drewdevault@fosstodon.org avatar

@docbibi yes

drewdevault,
@drewdevault@fosstodon.org avatar

End of day 3

drewdevault,
@drewdevault@fosstodon.org avatar

mood

drewdevault,
@drewdevault@fosstodon.org avatar

Day 4

mort,
@mort@fosstodon.org avatar

@drewdevault Wait you implemented ext4? I assumed that for this kind of project you'd make a baby's first file system style thing like we did in OS class in uni...

drewdevault,
@drewdevault@fosstodon.org avatar

@mort I just vendored lwext4

mort,
@mort@fosstodon.org avatar

@drewdevault Aha! Reasonable.

RL_Dane,
@RL_Dane@fosstodon.org avatar

@drewdevault

Lemme guess, "just a little hobby project, won't ever be as big as MINIX, only supports AT harddisks right now because that's all you have?" 😂

drewdevault,
@drewdevault@fosstodon.org avatar

It can read files from the Linux install on my laptop :D

drewdevault,
@drewdevault@fosstodon.org avatar

End of day 4: ext4 works but needs to be integrated into the filesystem abstraction (which also needs to be fleshed out)

Maybe VFS tomorrow?

drewdevault,
@drewdevault@fosstodon.org avatar

Starting to get lwext4 rigged into the Bunnix filesystem abstraction

drewdevault,
@drewdevault@fosstodon.org avatar

Did anyone else think inodes were black magic when they first got into Unix

dusnm,
@dusnm@fosstodon.org avatar

@drewdevault Of course, just the idea of files having different entries in the FS table, but pointing to the same underlying data on disk is still something I find a little bit like black magic. 😂

lanodan,
@lanodan@queer.hacktivis.me avatar

@drewdevault Heh, not sure when I learned of inodes existence… definitely was a long time ago like 15+ years.

drewdevault,
@drewdevault@fosstodon.org avatar

Work progresses on integrating ext4 with the Bunnix filesystem API

This screenshot brought to you by fs::* rather than lwext4::*

drewdevault,
@drewdevault@fosstodon.org avatar

I have a (shitty) VFS

That's probably it for day 5, I have other things to do today 🙂

drewdevault,
@drewdevault@fosstodon.org avatar

What's probably next is fleshing out the VFS a bit, then getting to userspace and implementing a few syscalls

drewdevault,
@drewdevault@fosstodon.org avatar

Day 7, taking a break to hang out with a friend who's in town, more to come tomorrow

bigkrimpin,
@bigkrimpin@mstdn.party avatar

@drewdevault but Drew, tomorrow is kingsday, you can't miss out on kingsday!

drewdevault,
@drewdevault@fosstodon.org avatar

@bigkrimpin I ain't no fuckin monarchist

drewdevault,
@drewdevault@fosstodon.org avatar

@bigkrimpin ...although sometimes I cosplay as one when it's funny

drewdevault, (edited )
@drewdevault@fosstodon.org avatar

Day 8: let's write a System-V loader and get to userspace

also: don't write a USB driver don't write a USB driver don't write a USB driver

drewdevault,
@drewdevault@fosstodon.org avatar

✓ ELF loader

drewdevault,
@drewdevault@fosstodon.org avatar

✓ Userspace

No user I/O yet though so you have to take my word for it

drewdevault,
@drewdevault@fosstodon.org avatar

Okay, now you don't have to take my word for it

mariusor,
@mariusor@metalhead.club avatar

@drewdevault is this part of Helios, or some exploratory alternative?

drewdevault,
@drewdevault@fosstodon.org avatar

@mariusor just having fun

mariusor,
@mariusor@metalhead.club avatar

@drewdevault is that the secret to get this far this quickly? :)

drewdevault,
@drewdevault@fosstodon.org avatar

Day 8 was all about getting userspace online. We are loading ELF programs, jumping into userspace, and we have working interrupts and syscalls

Day 9 will start implementing more useful syscalls and fleshing out I/O

drewdevault,
@drewdevault@fosstodon.org avatar

There we go. That's probably all for today.

drewdevault,
@drewdevault@fosstodon.org avatar

I confess that I rushed into userspace without a plan, so I have a bit of a mess to figure out once I decide how to actually structure the project properly.

But that aside, I implemented a handful of syscalls today, notably readv, write, and mmap (MAP_ANON only, for allocations)

drewdevault,
@drewdevault@fosstodon.org avatar

Okay, reorganized the source tree to make a lot more sense before we move any further into userspace. Took some inspiration from the BSD layouts, since I intend to ship kernel and userspace as one cohesive project.

drewdevault,
@drewdevault@fosstodon.org avatar

Day 10 is getting fork working (and preemptive multitasking)

Getting there.

drewdevault,
@drewdevault@fosstodon.org avatar

There we go!

drewdevault,
@drewdevault@fosstodon.org avatar

exec works, but there's still some kind of bug in fork+exec

drewdevault,
@drewdevault@fosstodon.org avatar

ayy

drewdevault,
@drewdevault@fosstodon.org avatar

Summary of work up to day 10:

  • AHCI driver
  • MBR and GPT partitions
  • ext4
  • VFS
  • Userspace
  • Preemptive multitasking
  • Syscalls: readv, writev, lseek, close, mmap, munmap, mprotect, fork, execve
drewdevault,
@drewdevault@fosstodon.org avatar

Next up is signals and waitpid? Or openat et al. We shall see.

drewdevault,
@drewdevault@fosstodon.org avatar

Signals are hard. Might do some refactoring instead, particularly with respect to files

mort,
@mort@fosstodon.org avatar

@drewdevault How do you intend on dealing with signals during a blocking syscall? EINTR? Automatic resuming?

drewdevault,
@drewdevault@fosstodon.org avatar

@mort EINTR

drewdevault,
@drewdevault@fosstodon.org avatar

So today is refactoring, particularly for scheduling and file management.

drewdevault,
@drewdevault@fosstodon.org avatar

Nice, that's the bulk of the scheduler refactoring done. No pretty screenshot since there are no user-visible changes, but the short of it is that we can context switch to and from the kernel rather than only to and from userspace.

drewdevault,
@drewdevault@fosstodon.org avatar

(no, I have not set up kernel preemption yet, there are no locks in the kernel and interrupts are always disabled when the kernel is running; as a consequence of that I can only cooperatively context switch the kernel right now)

drewdevault,
@drewdevault@fosstodon.org avatar

Hey my waitqueue implementation worked on the first try

drewdevault,
@drewdevault@fosstodon.org avatar

open syscall works, though it's kind of shitty

drewdevault,
@drewdevault@fosstodon.org avatar

End of day 11:

New syscalls: getpid, getppid, openat

Scheduler refactored, AHCI driver yields while waiting on I/O and handles errors from the block device properly

Some filesystem refactoring done: inodes moved around in the codebase, fs::walk can terminate at the last entry (e.g. for creat(2) or mkdir, etc)

Next up is probably one of the following:

  • Implement console device files
  • finish openat (i.e. flags like O_CREAT, enforce RDONLY etc)
  • inode lifecycle
  • signals/waitpid
drewdevault,
@drewdevault@fosstodon.org avatar

Elaborating a bit: the scheduler can now switch tasks while in the kernel and return to the kernel when the thread wakes up, and accordingly waitqueues have been implemented for this purpose.

The problem with console devices is that their file descriptors are fake, namely they do not store an inode reference. This is problematic for a few reasons, such as (1) Bunnix lacks a device file abstraction generally; (2) files without an inode blocks adding fstat; (3) we can't mount them in /dev.

dimpase,
@dimpase@mathstodon.xyz avatar

@drewdevault interesting OS name... Woont u in Bunnik? 🙂

drewdevault,
@drewdevault@fosstodon.org avatar

@dimpase nee, Bunnix is pas 11 dagen oud! Het heeft geen network, geen shell, geen compiler, etc.

drewdevault,
@drewdevault@fosstodon.org avatar

Day 12 of making a Unix clone

New syscalls: getdents, fexecve

Fleshed out the filesystem implementation via os:: in the Bunnix port of the Hare stdlib

Some more inode refactoring done

(f)execve(2) now populates auxilary vector of new process

Next: stat/fstat/fstatat, respect/enforce open flags and file modes (e.g. O_WRONLY on a file with -w should not work, implement O_DIRECTORY, etc)

drewdevault,
@drewdevault@fosstodon.org avatar

Getting lwext4 to actually write changes to the disk is turning out to be a bit involved

drewdevault,
@drewdevault@fosstodon.org avatar

Spent most of the day failing to get O_CREAT to work on ext4, further investigation tomorrow

drewdevault,
@drewdevault@fosstodon.org avatar

Today's mood

drewdevault,
@drewdevault@fosstodon.org avatar

Answer: turns out it was a bug in the AHCI driver. Took me ages to figure that out.

drewdevault,
@drewdevault@fosstodon.org avatar

Character special device files baby!

drewdevault,
@drewdevault@fosstodon.org avatar

I need to implement an idle task so that the kernel doesn't crash when all processes are blocked, but I don't want to touch the scheduler again

drewdevault,
@drewdevault@fosstodon.org avatar

✓ idle

Hopefully I don't have to touch the scheduler again until SMP

Next up... block special devices. I really need to do signal but blockdevs will let me procrastinate on that

Could do sleep(2) as well

drewdevault,
@drewdevault@fosstodon.org avatar

The scheduler is the biggest time sink so far.

The ext4 bug, by comparison, was annoying in that it took a long time to figure out, but in the end the fix was simple.

Whereas each time I have to work on the scheduler I have to redesign major portions of it and do heaps of rather difficult debugging of non-linear code.

JayT,
@JayT@fosstodon.org avatar

@drewdevault I guess a scheduler is, by definition, lots of nonlinear code?

Its been fun watching your experiment from the sidelines. 🙂👍

drewdevault,
@drewdevault@fosstodon.org avatar

@JayT quite so

drewdevault,
@drewdevault@fosstodon.org avatar

Did nanosleep(2)

drewdevault,
@drewdevault@fosstodon.org avatar

To implement nanosleep I just improved the wait queues a bit until nanosleep could be done in 33 lines of code

drewdevault,
@drewdevault@fosstodon.org avatar

Will probably have to change a bit once I implement signals and have to deal with EINTR

drewdevault,
@drewdevault@fosstodon.org avatar

Call it 32 lines, that assert belongs somewhere else

drewdevault,
@drewdevault@fosstodon.org avatar

Block device files are now mounted, not that you can open them

drewdevault,
@drewdevault@fosstodon.org avatar

Right, now you can open them

drewdevault,
@drewdevault@fosstodon.org avatar

I think that's everything for day 13:

  • O_CREAT support for openat
  • Character and block devices, incl /dev/null, zero, full, and block devices and partitions
  • Populate /dev with devices on boot
  • Add idle task to scheduler
  • New syscall: nanosleep

Next, in no particular order:

  • Flesh out files a bit more (e.g. enforce O_RDONLY)
  • Flesh out filesystem syscalls (mkdir, fstatat, etc)
  • Signals & waitpid
  • pipe(2), dup(2)
  • Start writing a libc
  • Port a shell
f4grx,
@f4grx@chaos.social avatar

@drewdevault why did you choose to implement openat and friends? I was planning to avoid them entirely for my toy system.

drewdevault,
@drewdevault@fosstodon.org avatar

@f4grx they're a better design, using O_DIRECTORY etc, imho. Particularly when it comes to implementing mountpoints. Simplifies things if you don't start from the assumption that you're always walking from the root

drewdevault,
@drewdevault@fosstodon.org avatar

Once I get all of those done, it's time to write a blog post about it and resume other projects!

lanodan,
@lanodan@queer.hacktivis.me avatar

@drewdevault I guess shell written in hare would have made it possible to avoid porting a libc?

drewdevault,
@drewdevault@fosstodon.org avatar

@lanodan I could port rc (and I might) but I'd like to do an ash derivative

mort,
@mort@fosstodon.org avatar

@drewdevault Blog post material driven development

drewdevault,
@drewdevault@fosstodon.org avatar

Ended up with some extra free time tonight and did a couple more syscalls: unlinkat, mkdirat

Remaining filesystem-related syscalls are the stat family of calls, rmdirat (or AT_REMOVEDIR I guess), chmod/chown/chgrp, readlinkat, linkat, symlinkat, and utimensat.

drewdevault,
@drewdevault@fosstodon.org avatar

Implemented a bunch of openat flags this morning: RDONLY/WRONLY/RDWR is now enforced, and O_DIRECTORY, O_APPEND, O_TRUNC, and O_EXCL are now supported

I chose to diverge from POSIX on O_DIRECTORY because I think it's kind of lame, but I could change my mind if this comes back to bite me when I start porting real-world software

mxk,
@mxk@hachyderm.io avatar

@drewdevault O_DIRECTORY even caused lots of discussion in the Filesystem working group of the POSIX standards committee.
Are file descriptiors obtained with O_DIRECTORY useful for sync_fd() in your implementation?

drewdevault,
@drewdevault@fosstodon.org avatar

@mxk what is sync_fd()? Do you mean fsync?

mxk,
@mxk@hachyderm.io avatar

@drewdevault ah, yes, ofc I do 🤦

drewdevault,
@drewdevault@fosstodon.org avatar

@mxk I haven't implemented fsync and presently all writes are committed to disk before write(2) et al returns to userspace, so I'm not sure. I might know more when I get to that.

mxk,
@mxk@hachyderm.io avatar

@drewdevault then I am doubly curious, what did you change about O_DIRECTORY?

drewdevault,
@drewdevault@fosstodon.org avatar

@mxk @bugaevc I made it so that you can only open directories with O_DIRECTORY and they can only be O_RDONLY

mxk,
@mxk@hachyderm.io avatar

@drewdevault @bugaevc okay, yeah, that is reasonable.
I ask, since I can't count the times I had to explain to someone, that O_RDONLY and O_DIRECTORY both are ways to create file descriptors to a directory, but both are fundamentally different in nature.
(And given that nobody checks return values of fsync() this mistake is unlikely to ever be discovered)
Also, reading from directory fds is a mess and shouldn't be supported by any posix system....

bugaevc,
@bugaevc@floss.social avatar

@drewdevault @mxk guess it can be useful — for atomicity, or for reducing the number of file name lookups in find(1)/ftw(3) if readdir returns DT_UNKNOWN — to be able to open() a node first, then fstat it, and if it's a directory do one thing (look up something relative to it with *at()), and do another thing otherwise.

drewdevault,
@drewdevault@fosstodon.org avatar

@bugaevc @mxk I guess that makes sense. We'll see what people are doing in the wild when I start porting software and it trips over this

bugaevc,
@bugaevc@floss.social avatar

@drewdevault wdym about O_DIRECTORY?

drewdevault,
@drewdevault@fosstodon.org avatar

Also implemented an inode cache and reference counting for inodes 😃

drewdevault,
@drewdevault@fosstodon.org avatar

The cache currently serves just to make sure that there is a 1:1 correspondence between inode numbers and inode data structures (so that if several files hold a reference to the same inode they all remain in sync), it does not persist inodes after all references are released... yet. A broader cache system that keeps cached data in unused RAM is planned for the future.

drewdevault,
@drewdevault@fosstodon.org avatar

Signals 🤮

mxk,
@mxk@hachyderm.io avatar

@drewdevault Signals are okay, as long as you offer epoll with signal_fd to tame them!

drewdevault,
@drewdevault@fosstodon.org avatar

waitpid

drewdevault,
@drewdevault@fosstodon.org avatar

many process, much wait

drewdevault,
@drewdevault@fosstodon.org avatar

Okay, about done for today. Summary of day 14 writing a Unix clone:

New syscalls: exit, waitpid

Improvements to openat: enforces read/write mode, supports O_DIRECTORY, O_APPEND, O_TRUNC, O_EXCL, and O_CLOEXEC

Added an inode cache

Optimized the MMU code for fork and process clean-up (still no CoW, though)

And laid some groundwork for signals, which I have been dreading from the start.

https://git.sr.ht/~sircmpwn/bunnix

drewdevault,
@drewdevault@fosstodon.org avatar

initramfs :D

Simon Zeni ported the Helios EFI bootloader to the Bunnix boot protocol last night, so I'm doing some other boot improvements this morning to get EFI support upstreamed

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

EFI w/framebuffer console via GOP

drewdevault,
@drewdevault@fosstodon.org avatar

Left: old thinkpad w/legacy boot
Right: modern starlabs starbook MkIV w/EFI boot

Both booted from the same flash drive :)

drewdevault,
@drewdevault@fosstodon.org avatar

EFI support ended up consuming all of day 15. D&D tonight!

drewdevault,
@drewdevault@fosstodon.org avatar

Day 16: I am porting musl libc to Bunnix

drewdevault,
@drewdevault@fosstodon.org avatar

Wiring up more of stdio.h

drewdevault,
@drewdevault@fosstodon.org avatar

End of day 16:

  • New syscall: fstatat (currently AT_EMPTY_PATH only, i.e. fstat(2) behavior)
  • Serious build system improvements, to add...
  • A sysroot during the build, into which...
  • An early port of musl libc has been installed, including varying degrees of support for stdio, math, complex, ctype, malloc, string, unistd, stat, and more

Unfortunately I'm now fully committed to GNU make, but this build is too complex to really get away with POSIX makefiles.

drewdevault,
@drewdevault@fosstodon.org avatar

Goal for the end of the week is to have a pretty decent C environment with a shell and a decent spread of coreutils ported, probably a bourne shell derivative plus sbase.

I'll port DOOM, too, if all of that is done before Saturday.

drewdevault,
@drewdevault@fosstodon.org avatar

Fleshed out libc a tiny bit more and tried to port some sbase utilities before calling it quits for today

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

Another day, another GCC cross compiler

drewdevault,
@drewdevault@fosstodon.org avatar

"success"

drewdevault,
@drewdevault@fosstodon.org avatar

So, in the morning of day 17, I have three languages running in userspace: Hare, C, and C++

I will keep fleshing out libc and the necessary syscalls until we have a shell. I suspect there is another scheduler bug as well.

Coming up soon: pipe(2), dup(2), fcntl(2)

yrlf,
@yrlf@graz.social avatar

@drewdevault Which STL are you using for C++ in userspace?

drewdevault,
@drewdevault@fosstodon.org avatar

@yrlf libstdc++

lritter,
@lritter@mastodon.gamedev.place avatar

@drewdevault wait, this ain't linux?

drewdevault,
@drewdevault@fosstodon.org avatar

@lritter nope

lritter,
@lritter@mastodon.gamedev.place avatar

@drewdevault you make bootstrapping look so easy :)

drewdevault,
@drewdevault@fosstodon.org avatar

@lritter well, everything is cross-compiled. It's not self-hosting yet

drewdevault,
@drewdevault@fosstodon.org avatar

pipe(2)

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

Day 17 so far:

  • New syscalls: chdir, fchdir, pipe; getpid/getppid removed, replaced with getcreds (also does uid, gid, euid, sid, etc)
  • Mountpoints refactored to live on inodes, all *at (e.g. openat) syscalls finished
  • C++ running in userspace (ugh, needed for a future gcc port)
  • Bunnix target patched into binutils & gcc cross toolchain, proper sysroot set up
  • libc expanded: dirent, getopt, stat, time, plus riggings for the new syscalls (e.g. pipe, getuid)
drewdevault,
@drewdevault@fosstodon.org avatar

Progress towards shell: I have some dash patches that almost build; 11 libc functions remain. These are mostly going to involve shimming out signal-handling functions until I implement them in the kernel.

I have 44 coreutils from sbase building in my sysroot (e.g. grep, sed, od, uniq, etc)

A keyboard driver and console thing for an interactive shell remains to be done in the kernel

drewdevault,
@drewdevault@fosstodon.org avatar

Funnily enough, of all of the syscalls I have left to implement before I can finish porting dash, I suspect getcwd will be the most difficult.

drewdevault,
@drewdevault@fosstodon.org avatar

I think I'll end up having to open(cwd + "/..") in a loop until cwd == ".." to construct the path, or at least something like that

Or add a direntry cache like Linux has, but that would be a fair bit of work

Or, shit, I could just stick a cwd string on the process structure and live with the fact that it breaks if the cwd moves underneath you

drewdevault,
@drewdevault@fosstodon.org avatar

✔️ new syscalls: dup, dup2

drewdevault,
@drewdevault@fosstodon.org avatar

Down to three missing symbols to build this (patched) version of dash: fcntl (with SETFL and SETFD), getgroups, and getcwd

There is a syscall for getgroups, but it's missing in libc.

mort,
@mort@fosstodon.org avatar

@drewdevault New project: userspace utilities collection a la GNU's, but written in Hare, primarily targeting Bunnix?

drewdevault,
@drewdevault@fosstodon.org avatar
mort,
@mort@fosstodon.org avatar

@drewdevault Oh, awesome!

So you have your own kernel on bare metal running your own userspace written in your own programming language, that must be so satisfying. Impressive!

drewdevault,
@drewdevault@fosstodon.org avatar

@mort not quite, hautils does build (in part) for Bunnix but I'm planning to port sbase for now

drewdevault,
@drewdevault@fosstodon.org avatar

Yeah, it turns out that getcwd is a massive bitch to implement

I'm just going to write a shitty/buggy implementation and move on for now

drewdevault,
@drewdevault@fosstodon.org avatar

Day 18

drewdevault,
@drewdevault@fosstodon.org avatar

Day 19 -- going to Utrecht tonight so there's not going to be much

  • dash incorporated into source tree to provide /bin/sh
  • New syscalls: setcreds (provides setuid et al), setgroups, mount
  • libc expanded with support for passwd, groups, shadow, etc, login(1) stuff
  • Bunnix executes /etc/rc on boot as a shell script

I have realized that dash depends on signals to work properly, however, so I will probably have to either get that working or switch to rc.

drewdevault,
@drewdevault@fosstodon.org avatar

I have implemented signals. Poorly.

mariusor,
@mariusor@metalhead.club avatar

@drewdevault as you well know, in order to do something goodly, the initial step is to do it poorly. 🤘

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

Starting to get somewhere

drewdevault,
@drewdevault@fosstodon.org avatar

Things I want to do before calling it A Unix(TM):

  • signal cleanup, flesh out pid 1 a bit, sigwait, fix exit status codes
  • shebangs/binfmt
  • finish porting sbase to add some core utils
  • switch_root to get out of the initramfs environment (for persistent installs, the iso will stay in the initrd)
  • basic tty subsystem with line editing so there's an interactive shell

Maybe an installer if I feel particularly fancy? Also might port doom to it

drewdevault, (edited )
@drewdevault@fosstodon.org avatar

So, on day 20*, the Unix speedrun project has:

  • Memory manager

  • A VFS

  • A bunch of filesystem syscalls

  • fork/exec, preemptive multitasking

  • Signals (sort of)

  • AHCI block devices

  • GPT and MBR partitions

  • ext4 and memfs filesystems

  • null, full, zero character devices

  • pipe(2)

  • A fairly beefy libc

  • EFI and legacy boot support

  • Framebuffer console

  • A port of the dash shell

  • 52 core utilities ported from sbase

  • Technically 21 but I wasn't working on it yesterday

drewdevault,
@drewdevault@fosstodon.org avatar

Might also be fun to make an installer, but this would require:

  • mkfs.ext4 (not that hard)
  • fdisk (somewhat hard)
  • EFI runtime variables (pretty hard)
drewdevault,
@drewdevault@fosstodon.org avatar

Today:

/dev/cons
/dev/kbd

drewdevault,
@drewdevault@fosstodon.org avatar

Here's the whole PS/2 keyboard driver, 42 lines of code: https://git.sr.ht/~sircmpwn/bunnix/tree/master/item/sys/arch/dev/+x86_64/ps2kbd.ha

(plus the generic keyboard driver support code): https://git.sr.ht/~sircmpwn/bunnix/tree/master/item/sys/dev/chr/kbd.ha

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

signals /o\

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

Having some more fun with Bunnix

hexaheximal,
@hexaheximal@mastodon.social avatar

@drewdevault does hare run on non-x86 systems yet? that would be really cool if so

drewdevault,
@drewdevault@fosstodon.org avatar

@hexaheximal it runs on aarch64 and riscv64 as well, though Bunnix has to be ported to each as it's inherently arch-specific

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

(no, it does not work correctly)

drewdevault,
@drewdevault@fosstodon.org avatar

Summarizing day 22:

I fixed signals and the shell works great. So I went on a porting spree. I ported a further 15 core utilities from sbase, which includes ed(1), so now there is a text editor for Bunnix.

The real news, however, is that I somehow managed to port binutils, and you can assemble and link assembly programs on Bunnix now. I also got gcc to compile for Bunnix, but it has some bizzare issues I don't care to debug right now -- I didn't expect to get even that far.

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

I think the definition of "done" for Bunnix is:

  • Has a reasonably comprehensive set of shell utilities
  • Has a working C toolchain
  • Has a working Hare toolchain
  • Can play doom

At least for the "speedrun" purposes, I might work on it more afterwards off and on

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

Finally implemented uname

Today I am trying to flesh out the libc enough to finish porting sbase

whynothugo,
@whynothugo@fosstodon.org avatar

@drewdevault It doesn't make sense to me how fast you hacked this.

It's not just that you need a lot of focus, you really need to know a enough about all the different subsystems too.

drewdevault,
@drewdevault@fosstodon.org avatar

@whynothugo I'll write a blog post about the process when I'm done

drewdevault,
@drewdevault@fosstodon.org avatar

sbase ported!

I added system and popen/pclose added to libc so upstream ed works. Otherwise the only difference from upstream is that cron, cons, logger, nice, renice, time, and tftp were removed. Some stuff builds but doesn't work at runtime, like setsid.

95 tools in /bin now

drewdevault,
@drewdevault@fosstodon.org avatar

Make it 96, added an awk

drewdevault,
@drewdevault@fosstodon.org avatar

So I spent all day fucking around with integrating libvterm into the kernel

But it's not great implementation wise so I'm just going to get abandon it on a branch.

puppygirlhornypost,
@puppygirlhornypost@transfem.social avatar

@drewdevault does bunnix have top yet?

puppygirlhornypost,
@puppygirlhornypost@transfem.social avatar

@drewdevault (sorry for another ping) are you making your own libc for bunnix or are you porting something like musl, uclibc-ng?

drewdevault,
@drewdevault@fosstodon.org avatar

@puppygirlhornypost using a libc based on musl

puppygirlhornypost,
@puppygirlhornypost@transfem.social avatar

@drewdevault what C standard does it target C89, C99, C11? Also if you don't mind answering how did you get GCC compiled on that system? Did you do a compiler bootstrap or are you able to just load the binary. One of my favorite parts of OSDev is watching people bootstrap a compiler, libc to start working on userspace

drewdevault,
@drewdevault@fosstodon.org avatar

@puppygirlhornypost C11. The gcc port does not work natively yet but I added a Bunnix target to gcc and built a cross compiler

puppygirlhornypost,
@puppygirlhornypost@transfem.social avatar

@drewdevault I've been keeping up with this thread a bit, I may have missed it but did you ever say what you were using for binaries? I'm curious now, are you doing https://en.wikipedia.org/wiki/A.out (not for you but for anyone reading) elf, or your own thing? ELF is very interesting https://kevinboone.me/elfdemo.html I love to see people writing programs in ELF. I wanted to ask you earlier about PIE and whether that was something you were planning on implementing. Not any pressure (i know it's just a side project) I just find operating system design very fascinating as a subject.

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

More messing around

drewdevault,
@drewdevault@fosstodon.org avatar

I think tomorrow's goals are:

  1. Implement sbrk (I've been avoiding it) and switch from my buggy malloc to musl's malloc
  2. Get working tcc, binutils, and Hare toolchains, plus make, into the base distribution
drewdevault,
@drewdevault@fosstodon.org avatar

@dalias hot take: malloc-ng should use mmap, not sbrk

drewdevault,
@drewdevault@fosstodon.org avatar

Bunnix says good morning

drewdevault,
@drewdevault@fosstodon.org avatar

Implemented brk(2) so I could drop in malloc-ng from musl (rather than my buggy hand-made malloc), C toolchain is much more stable now

I also implemented clock_gettime as shown in the last screenshot, so make doesn't bitch about the clock anymore.

dalias,
@dalias@hachyderm.io avatar

@drewdevault The only brk it needed was return -ENOSYS...

drewdevault,
@drewdevault@fosstodon.org avatar

@dalias according to my reading it needed it to return the initial break, but not change it, so I just implemented that much.

dalias,
@dalias@hachyderm.io avatar

@drewdevault Errors work too, but great. Glad you didn't spend the effort making it full featured.

drewdevault,
@drewdevault@fosstodon.org avatar

@dalias yeah, on a second reading I see the ENOSYS case. Cheers!

drewdevault,
@drewdevault@fosstodon.org avatar

Got GCC working

(Fixed the readlink issue separately)

g++ also works, but adding libstdc++ to the initrd makes it too big and some stuff breaks. Could run it off of ext4 but there's some issues with the ext4 implementation (namely that binutils depends on lseeking beyond the end of the file to create a hole)

drewdevault,
@drewdevault@fosstodon.org avatar

Just messing around, anyway. I don't intend to ship gcc in the base system (going with tcc instead). I do intend to ship binutils, though, so that you can have a working Hare toolchain, but that'll depend on fixing this lseek issue

drewdevault,
@drewdevault@fosstodon.org avatar

Built out a small system for packaging ports in .tar.gz files and dumping them in /dist, plus a small script to automate their installation -- so I can ship some optional package sets.

First one is "devel", which includes make and tcc.

drewdevault,
@drewdevault@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

Why do these blasted serial ports never generate interrupts

drewdevault,
@drewdevault@fosstodon.org avatar

There we go

katzenmann,
@katzenmann@c3d2.social avatar

@drewdevault What is /dev/cons for?

drewdevault,
@drewdevault@fosstodon.org avatar

@katzenmann write only access to the kernel console

drewdevault,
@drewdevault@fosstodon.org avatar

@katzenmann see /dev/console on Linux

Eventually you'll be able to read the kernel logs ring buffer from it ala dmesg

drewdevault,
@drewdevault@fosstodon.org avatar

Day 24 of building a Unix from scratch

It's official

Video of Doom being played on Bunnix

tippfehlr,
@tippfehlr@fosstodon.org avatar

@drewdevault congrats 🎉

drewdevault,
@drewdevault@fosstodon.org avatar

So, tomorrow-ish I bundle this all up and put it in the base distribution

Today:

  • New syscalls: ioctl, mmap supports mapping files (namely /dev/fb0)
  • Serial TTY
  • VT overhauled, early fbcons split from runtime vt
  • some termios support
  • Framebuffer device (/dev/fb0)
  • Controlling tty (via /dev/tty)

Getting married tomorrow, no further updates for a while 🎉

drewdevault,
@drewdevault@fosstodon.org avatar

My goal was low-key to get doom working before the wedding

lasombra,
@lasombra@fosstodon.org avatar

@drewdevault Congratulations on the wedding, Drew!

🎉 🎉 🎉

jannem,
@jannem@fosstodon.org avatar

@drewdevault
Congratulations! 🎉

Pro tip: don't bring your laptop.

mxk,
@mxk@hachyderm.io avatar

@drewdevault well done!
With the TTY handling you have entered another pretty dark corner of POSIX

tomterl,
@tomterl@fosstodon.org avatar

@drewdevault that's great to hear - congratulations and all the best to you both

whynothugo,
@whynothugo@fosstodon.org avatar

@drewdevault Congratulations to you [both]. I hope you have some beautiful time offline!

whynothugo,
@whynothugo@fosstodon.org avatar

@drewdevault I had a dream last night where one person was playing doom with a keyboard and others insisted that it's meant to be played with a mouse.

Somehow this video triggered more vivid memories of this weird dream. But please do try out Doom with a mouse.

This message courtesy of Morpheus I guess.

orva,
@orva@fosstodon.org avatar

@drewdevault Extra serial serial ports: no interrupts, no task switching, so everything is always very serial!

LordRishav_,
@LordRishav_@fosstodon.org avatar

@drewdevault Seems like Hare is actually a very good system development language by the pace at which you're implementing this kernel.

ttamttam,

@drewdevault os doom% speedrun

blainsmith,
@blainsmith@fosstodon.org avatar

@drewdevault Does this mean you have plans to name something "Daisy" after Doomguy's rabbit?

whynothugo,
@whynothugo@fosstodon.org avatar

@drewdevault Do you really need EFI variables? You can just put your bootloader in esp://EFI/Boot/bootx64.efi. Which is what Asahi does due to a lack of EFI variables on their platform.

drewdevault,
@drewdevault@fosstodon.org avatar

@whynothugo yeah I'll add this

mxk,
@mxk@hachyderm.io avatar

@drewdevault so, you for now are relying on your own libc, since you still would require too many additional syscalls for musl to work?

drewdevault,
@drewdevault@fosstodon.org avatar

@mxk I'm using a fork of musl libc heavily patched to support bunnix

mxk,
@mxk@hachyderm.io avatar

@drewdevault okay, sounds less painful than starting from scratch.

srtcd424,
@srtcd424@mas.to avatar

@drewdevault
Does anyone implement them well?

drewdevault,
@drewdevault@fosstodon.org avatar

@srtcd424 no. But some implementations conform to the spec

piggz,

@drewdevault Dont forgot to
/* TODO fix this later */

mxk,
@mxk@hachyderm.io avatar

@drewdevault does your OS have a global notion of truth in terms of the Mount/Filesystem view, or is it alright connected to the individual process? (In preparation of chroot)
(Just to make getcwd more complicated)

drewdevault,
@drewdevault@fosstodon.org avatar

@mxk the latter

okflo,
@okflo@mastodon.sdf.org avatar

@drewdevault but - can it run doom? ;)

drewdevault,
@drewdevault@fosstodon.org avatar

@okflo oh god now I have to port doom to it

jbowen,
@jbowen@mast.hpc.social avatar

@drewdevault Will the source be made available for folks to gawk at?

drewdevault,
@drewdevault@fosstodon.org avatar
jistr,
@jistr@fosstodon.org avatar

@drewdevault Are there resources that you use or that you'd recommend to someone wanting to learn about these low-level OS topics? Perhaps some books / websites or something like that?

drewdevault,
@drewdevault@fosstodon.org avatar

@jistr osdev wiki and the manuals/specs for the hardware you want to work with

jistr,
@jistr@fosstodon.org avatar

@drewdevault 👍 thank you.

codonell,
@codonell@fosstodon.org avatar
drewdevault,
@drewdevault@fosstodon.org avatar

@codonell I don't think fork is good but I am writing a unix so

codonell,
@codonell@fosstodon.org avatar

@drewdevault Sorry, no judgement here, just wanted to point out an interesting paper I'd read recently only for the first time. And that perhaps might influence how deeply one plumbs fork as an abstraction into the OS.

remenca,
@remenca@mastodont.cat avatar

@drewdevault This seems so very cool. Is there a repo where I can see your progress?

drewdevault,
@drewdevault@fosstodon.org avatar
tippfehlr,
@tippfehlr@fosstodon.org avatar

@drewdevault is taking a break from taking a break

noodlez1232,
@noodlez1232@fosstodon.org avatar

@drewdevault Dude you're amazing. I've been stuck on just memory management in my hobby kernel for like 6 months now (although truthfully like 6 hours I barely get to work on it), and here you are just pumping out a kernel like it's nothing.

drewdevault,
@drewdevault@fosstodon.org avatar

@noodlez1232 I've done this a few times already, experience makes it easier :) and I still struggle with memory management! In a way it's the hardest part imho

drewdevault,
@drewdevault@fosstodon.org avatar

Yes, this is a regex implementation in ring 0

tippfehlr,
@tippfehlr@fosstodon.org avatar

@drewdevault you need a break from work, so you write an operating system to relax 😄

zerodogg,
@zerodogg@fosstodon.org avatar

@drewdevault Okay that sounds really cool (and fun). I'd love to learn more about it at some point :)

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • rosin
  • thenastyranch
  • mdbf
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • Youngstown
  • cisconetworking
  • slotface
  • vwfavf
  • everett
  • Durango
  • kavyap
  • GTA5RPClips
  • megavids
  • khanakhh
  • osvaldo12
  • ngwrru68w68
  • normalnudes
  • anitta
  • ethstaker
  • cubers
  • modclub
  • tacticalgear
  • provamag3
  • Leos
  • tester
  • JUstTest
  • All magazines