gila/docs/STATE_OF_DEVELOPMENT.md
August 2e626a33d1
Some checks failed
Continuous Integration / Check (push) Failing after 1m1s
Continuous Integration / Clippy (push) Failing after 59s
Mess with Userboot loading
2026-11-10 04:41:08 +00:00

90 lines
4.7 KiB
Markdown

# State Of Development
This file will serve as a living journal of what I'm working on with regards
to the project, so I can step away from it and come back to it without having
to figure out what I was doing from commit messages alone.
## 2026-10-08: TSS Descriptor Weirdness
Loading the TSS selector into the Task Register was causing endless general
protection faults, which seemed... odd. Turns out, I was performing some bad
encoding when generating the TSS descriptor in the GDT, as well as loading
the bytes in the wrong order. Fixing the descriptor generation code and
swapping the bytes was enough to fix the GPFs. Now, the kernel makes it to
usermode, before triple faulting due to page faults. This is probably because
I put the stack in a bogus, unmapped address.
The next issue to work on will be paging and memory allocation. I need to
allocate memory to load and start the initial process, and to do that, I
need to finalize how I want process page mappings to be stored. It has to
align with Gila's capability model. After that, I can write some basic
syscalls, and compile a very minimal binary to test running processes.
## 2026-10-11: Capability Data Structures
Starting to design the shape of capability structures. Using a doubly linked
list allows easy tracking of derived capabilities, but presents ownership
issues. I can't think of anything smarter than using raw addresses to denote
where capabilities are, so those are used as our references. We use null
checking and convert these pointers into `Option<&mut Capability>` whenever
possible to uphold safety.
The capability's fields allow a hierarchical structure for components and
capabilities, and in the future, user processes can create capabilities to
resources that aren't managed by the kernel.
## 2026-11-08: Cross Compilation Considerations
No further work has been done on actually bringing up the kernel on x86_64.
However, I'm considering how I want to add support for ARM down the road. Most
ARM SBCs do not support UEFI, so the stopgap solution I've arrived at is to
use Das U-Boot as an intermediate layer between the firmware and Limine.
U-Boot supports the EFI protocols necessary to load and run Limine as far as I
can tell, so by merely supplying `-bios u-boot.bin` to QEMU allows us to boot
an unmodified multiarch ISO.
I think I will have to backtrack on my choice to include the component system
in the kernel proper. Too much additional accounting info would be required.
It would be more responsible to handle this in userspace and come up with a
different protection mechanism for userspace capabilities.
Lastly, I want to figure out a way to make the kernel's capability
representation a little more... *robust*, I guess. More idiomatic Rust. Using
raw pointers everywhere feels sloppy. Maybe this is a good application of
`PhantomData<T>`?
## 2026-11-09: Capability management refinement
I decided to use `Pin<&mut Capability>` for the derivation tree pointers. This
makes a lot of sense, considering the capabilities aren't supposed to move
around in memory.
For capabilities representing memory ranges, we can use a "buddy" system:
52 bits of a 64-bit pointer are used to refer to the base address of the range.
6 of the remaining 12 bits can be used to represent the number of pages in the
range. If we call this 6-bit value n, then the number of pages represented by
the capability can be defined as 2^n. Access rights can be encoded in the final
6 bits. We can represent any number of pages using binary partitioning, which
results in multiple range capabilities of unique page counts that are powers of
two.
For page type capabilities, we can do something similar, except we use all 12
low bits for access rights. Keeping all capability types the same size allows
for convenient storage of capabilities in an array, as enum variants with
associated types. Boom!!!
Userboot will regrettably need to be moved to a different crate altogether, so
it might be wise to turn this repo back into a workspace. This is because the
same `build.rs` file gets used for both Userboot and the kernel, which causes
Userboot to be linked as a static, non-relocatable executable, to be loaded at
`0xffffffff80000000`. We cannot remap this address range, because it belongs to
the kernel, which must be loaded at all times to allow for interrupt handling.
There are a few ways I could fix this:
- Compile and link Userboot as a relocatable ELF, which necessitates adding an
ELF parser+loader to the kernel. I dislike this option.
- Compile and link Userboot with a different load address, which I can remap
via paging. By compiling the binary with a load address of `0x1000`, it would
be possible to map it to a clean address space that does not collide with the
kernel. Loading at `0x0` is impossible due to nullptr detection.