Skip to content

KFS-2

Compare
Choose a tag to compare
@Orycterope Orycterope released this 25 Aug 15:12
· 1351 commits to master since this release

Segmentation and stack dump

Screenshot_20190824_225749

This is the second release of KFS. The main focus around this release has been around supporting segmentation on x86_32.

bypassing supporting segmentation

Since all memory protection in KFS will be handled at the paging level like every OS post 1980s, we don't need segmentation. However, x86 being x86, we can't turn off segmentation. We have to define a GDT that describes segments spanning the whole address space with no offset (base=0x00000000, limit=0xffffffff) to simulate the effect of having no segmentation.

So that's what we do, we define 3 kernel segments (code, data, stack) and 3 userspace segments (code, data, stack), all following the flat memory model.

stack

We define our stack as a big global array that lives in the .bss. The first thing we do when starting KFS is to make esp point to this memory.

We added the print_stack function that takes the current esp and dumps the stack to the screen in a xxd fashion.

screen scrolling

The logger now supports scrolling. When reaching the last line of the screen, the logger will copy the whole content of the video buffer one line up, and finally keep writing to the last line.

panic

Added a kernel panic function. This is the function that will be called when rust detects an overflow, an OOB access, or fails an assert! check.

It will print a distinctive header, and a small message giving more context to the panic.

Screenshot_20190825_170758

How to build

This release is pretty outdated, so we provide a roadmap on how to build it.

reveal build instructions

First, make sure to to checkout the kfs2 tag.

git switch --detach kfs2

Xargo

You need to downgrade your version of xargo to v0.3.11. You must do this outside of your repo as the rust-toolchain file would try to compile it with a non-working rustc.

cd ~
cargo install xargo --force --version 0.3.11
cd -

Cargo.lock and Cargo.toml

Because sunrise developers were so young and innocent at that time, they didn't fully realize the crucial importance of a Cargo.lock in a published project. So they didn't think about including it, and it remained that way for quite a while, until they once tried to checkout an old tag and spent half a day just trying to compile it.

Unfortunately history only goes in one way, and commit logs too ( 👀 ), so we provide a patched Cargo.toml as well as its Cargo.lock as DLC in the release files.

Copy them at the root of your repository, and cargo will now fetch the right versions of our dependencies.

grub-mkrescue

Because sunrise developers were lazy-ass monkeys, busy being high on smoking rolled-up intel-specs pretending it's some kind of psychotrope, they used to let all the hard work of creating an iso image be done by grub-mkrescue, while taking all the credit.

This means that depending on your distro, you might need to install:

  • grub
  • mtools

This went on until Thog joined them and created mkisofs-rs, and effectively rescued them, before they fall victim to 8042 withdrawal, and OD trying to snort an A20 line, while attempting to relieve the crave.

nigthly version

Using rust nightly but not specifying which version was a stupid idea in retrospective. Fix that:

echo "nightly-2018-03-15" > rust-toolchain

Building

Now you should finally be able to build and create the boot iso:

cargo make iso

that was easy ...