#HazelOS (Formerly Noise-v2)

1 messages ยท Page 2 of 1

simple locust
#

44 branch is also frozen at this point

#

Fedora 42+ has Clang 21.1.8

inner glen
#

ok neat

#

though imStill considering ubuntu 25.10 or 26.04

#

since many projects expect ubuntu

simple locust
#

That's upto you

inner glen
#

but i dont Like gnome

#

so yeah

#

fedora it is

simple locust
inner glen
#

though whats the default fs used in rootfs?

simple locust
#

XFS for server

inner glen
#

for some reason

#

prob just me

inner glen
simple locust
inner glen
#

it should be like rhel where you can choose presets at installation right?

#

or configuration

simple locust
#

There's an installer

inner glen
#

yeah

simple locust
#

or you can go full customization

#

with Fedora minimal

inner glen
#

theres also the fedora everything

#

i prob fine with feodra kde

#

ok thanks for the info

simple locust
inner glen
#

@simple locust oh wow

#

gnome is kinda peak

simple locust
#

But libadwaita is pita

inner glen
#

i replicated macos tahoe

#

quite similar i'd say

inner glen
inner glen
#

heard some controversy about that

simple locust
#

Welcome to the dark side

inner glen
#

fedora is also neat

simple locust
#

Pros: It uses GTK4
Cons: FreeDesktopOrg hates anyone messing with their design

inner glen
#

the first time i see vmware compile and instakll successfully

simple locust
#

Fedora is the best of both worlds

#

Stability + Rolling(ish) releases

inner glen
#

first time trying to do this

simple locust
inner glen
#

now fonts

simple locust
#

SF pro

inner glen
inner glen
#

google fonts?

simple locust
inner glen
#

ok

#

isnt that the apple font?

simple locust
simple locust
#

Use 7z to unarchive it

#

It's around 2 unzips operations iirc

inner glen
#

hmm, my hide top bar is a bit too responsive

#

*panel

simple locust
inner glen
#

ok

#

also arent the fonts in apple dmg format>

simple locust
inner glen
#

or at least

#

compressed using 7z

simple locust
#

I think 7zip just supports dmg format

inner glen
#

ok

#

but how do i even use the font?

#
โžœ  SFProFonts ls
 Distribution           Resources           SFProFonts.pkg
'[HFS+ Private Data]'  'SF Pro Fonts.pkg'  '[TOC].xml'
simple locust
simple locust
inner glen
#

i see

simple locust
#

Then unarchive Payload~

inner glen
#

damn

#

yeah

#

the OTFs are there

#

that is insane

#

never met sth like this

simple locust
#

lol

inner glen
#

also @simple locust is there animations effect on gnome?

#

like the magic land for example

inner glen
#

not bad

#

plus

#

final thing, is there en extension that let me spawn multiple instances of an app?

#

the reason why i used to hate gnome is because of this

#

and i think we have some issues with ptyxis using sf pro rounded regular to

simple locust
#

Classic gnome

#

Have an official extension

#

But not integrate it in the DE

#

Or you can also use ctrl + enter

#

In overview

simple locust
#

Or use firacode or smth

inner glen
#

just gonna use hybrid

#

sf pro rounded for everything

#

and for mono fonts

#

sf mono reg

#

for some reason, im im love with gnome (and fedora)

inner glen
#

ok flatpak kinda sucks for installing ides

simple locust
#

I'm rewriting VMA because it was held together by a chewing gum

simple locust
#

B+ trees weren't worth it

#

Now, I'm back to using RB trees for VMA

#

Also, For the kernel architecture. I'm thinking about keeping Memory Management and Threads/Process creation in kernel space

inner glen
#

๐Ÿ™

simple locust
#

while delegating drivers to userspace

simple locust
inner glen
#

and you are finnally back

#

and @violet wharf is gone

#

btw fedora is peak

simple locust
simple locust
#

lol

inner glen
#

you prob got too

#

for no reason

#

and hes been inactive for a bit of time

simple locust
#

yeah

inner glen
simple locust
simple locust
inner glen
inner glen
inner glen
#

so mysterious lmao

#

currently cooking vfs

#

and later sched to prepare for r0c4 as well as the userspace jump

#

and also migrated to using acpica over uacpi

simple locust
simple locust
#

I forgot that r0c4 was release version

#

So, I had to google it

#

And this came up in the AI overview

inner glen
#

WHAT

inner glen
simple locust
#

lol

#

Btw There's this honeybee in my room

#

The constant buzzing is giving me a headache

inner glen
#

here with a mosquito

#

well if you search aerosync on its own

#

so its a trademark

#

@simple locust also im making yet another PoC kernel #1475806779676823674

simple locust
inner glen
simple locust
#

I feel like chicken-egg problems chase me around all the time

#

Earlier it was with VMA pool allocations

#

Now, when I try to implement vm_object abstraction

#

I need a working slab allocator to get xarray's to work

#

But the slab allocator itself depends on the VMA

simple locust
inner glen
#

my slub allocator doesnt even use any of the vma, just the buddy system

#

vmalloc is a different thing

simple locust
inner glen
#
static struct page *allocate_slab(kmem_cache_t *s, gfp_t flags, int node) {
  struct folio *folio;
  struct page *page;
  void *start;
  void *p;

  if (node == -1)
    node = this_node();

  folio = alloc_pages_node(node, flags, s->order);
  if (!folio)
    return nullptr;

  page = &folio->page;
  start = page_address(page);
  page->slab_cache = s;
  page->objects = (unsigned short)((PAGE_SIZE << s->order) / s->size);
  page->inuse = 0;
  page->frozen = 0;
  page->node = node;
  SetPageSlab(page);
  INIT_LIST_HEAD(&page->list);

  /* Build freelist */
  page->freelist = start;
  for (int i = 0; i < (int)page->objects - 1; i++) {
    p = (char *)start + i * s->size;
    if (s->flags & SLAB_POISON)
      poison_obj(s, p, POISON_FREE);
    set_redzone(s, p);
    set_freelist_next(p, s->offset, (char *)p + s->size);
  }

  /* Last object */
  p = (char *)start + (page->objects - 1) * s->size;
  if (s->flags & SLAB_POISON)
    poison_obj(s, p, POISON_FREE);
  set_redzone(s, p);
  set_freelist_next(p, s->offset, nullptr);

  return page;
}
simple locust
inner glen
#

you are adding another layer of latency for no reason

simple locust
#

alrighty time to use hhdm mappins for heap

#

That also means that I can just remove obj pools from vma/vmm

#

Slab cache could support vma

#

My idea was to remove hhdm mappings

#

entirely

#

but that's no longer possible

inner glen
simple locust
#

These are just a couple of page table entries, should be doable

simple locust
#

Added VM Object abstraction :)

#

Added Transparent Huge Page Promotion

#

to pf_handler

#

Essentially, it merges 512 4KB VM Objects into a single 2MB VM object

simple locust
#

Maybe I should improve the scheduler...

#

The file is so monolithic

simple locust
#

I'll try to run the kernel on real hardware

simple locust
#

It's just a black screen

#

How tf do I debug?

inner glen
#

bruh

#

you have any fb?

simple locust
#

As for fb, I was using a shadow buffer

simple locust
#

Pmm initialization is too slow for RAM above 8 gigs

inner glen
simple locust
#

Just the mapping operation

simple locust
simple locust
# simple locust

The cause:

    if (!is_aligned(phys_end, args.page_size)) {
          phys_end = align_up(phys_end, args.page_size);
    }
#

These 3 lines caused the kernel to crash

#

Anyway I got to fix the pmm issue

#

This is with 12 gigs of RAM

#

Forgot that the kernel doesn't support smp rn

#

Double faulted :<

#

Let's see if I can reproduce this double fault on qemu

#

It can be reproduced on QEMU

#

Thinking about implementing greedy paradigm in PMM init

#

@inner glen wdyt?

simple locust
simple locust
#

Finally managed to improve the performance, and reduce pmm's memory footprint

simple locust
#

Without diving into multithreading, the only way to improve the performance is to explicitly ask the compiler to generate clz/ctz instructions instead of generic implementations

#

Forgot that pattern filling exists

uint64_t page_template = ((uint64_t)idx << 32) | ((uint64_t)PAGE_FLAG_USED << 24);
            uint64_t* map_page     = (uint64_t*)mem_sections[idx].map;
            for (size_t p = 0; p < PAGES_PER_SECTION; ++p) {
                map_page[p] = page_template;
            }
inner glen
inner glen
#

at most just lazy virtual allocation

#

@simple locust also for some interesting reason

#

while aerosync is kind of resource-inefficient

simple locust
inner glen
#

it actually works just on 40M ram with bios and 130M with uefi across vmware, bochs, vbox and qemu

inner glen
#

same here

simple locust
inner glen
inner glen
simple locust
inner glen
#

plus, not to mention i have kaslr support, and its actually limines issue

#

not my kernel's issue

inner glen
#

main allocation method is alloc_pages_node(3)

#

there is some inefficientcies tho

#

especially build_all_zonelists

#

for reference

#
[7] [    1.115385] [aerosync::core::numa] Range [100000000 - 180000000] -> Node 1
[6] [    1.138870] [aerosync::mm::pm] Built zonelists for all nodes.
#

(it used to be 1xx+ ms)

simple locust
#

sched_class refactor is likely working

#

Just a few more tests before pushing it

#

sched_classes are now modular, allowing the kernel to load/unload them at any moment

simple locust
#

"minor changes"

simple locust
#

The thread/process api rewrite is functionally complete

inner glen
simple locust
#

The kernel is fine with 3 CPUs

#

But for some reason, adding an extra cpus causes this error

eager ruin
simple locust
#

ig so

eager ruin
#

if you put proper locking on your kprintf() or whatever it is that outputs text youll at least be able to read the error

#

theres at least one ERROR and one WARN there, i think about VMM and PMM?

simple locust
#

I'm using snprintf with a local stack

#

so, it likely isn't krpintf() bug

#

maybe there's some race condition with KLOG?

simple locust
#

Atleast it managed to boot

#

Still there are some bugs and issues to rectify

#

But it kindof works

#

Tho, I still need to revise my RCU implementation T-T

eager ruin
inner glen
simple locust
#

I haven't changed the code whatsoever

simple locust
#

It feels like I'm rolling a dice whenever I test my kernel

#

This was test 1

#

Subsequent runs:

inner glen
simple locust
#

I'm definitely missing some race condition

#

But where

simple locust
#

The issue was with PCP cache in PMM

#

It was maintaining stale entries

#

I've removed PCP caches so that every allocation goes through the buddy allocator

simple locust
#

Atleast the kernel side managed to boot up

#

Now I need to fix scheduling

inner glen
#

though i see some artifacts?

simple locust
inner glen
#

no i mean this

inner glen
simple locust
#

So, the fb is glitchy

inner glen
simple locust
#

It's just for testing

#

To see if the kernel boots

#

On hardware

inner glen
#

i see

#

still finding a suitable font lmao

simple locust
#

I tested the kernel with 16 smp cores on QEMU

#

My CPU only has 12 cores

simple locust
#

The address is 64-bit aligned

#

And xrstor still GPFs

simple locust
#

Dunno how

simple locust
#

At first I was confused then, I remembered that kernel_log uses spinlock in place

#

Usermode transition :)

simple locust
#

RCU's gp_thread isn't executing

#

idk why

#

scheduler is clearly selecting that thread

#

but still

#

no sign

simple locust
#

Do I even need RCU?

#

Why RCU?

#

What is RCU?

#

How is RCU?

#

Where is RCU?

#

I hate RCU

inner glen
#

๐Ÿ™

simple locust
#

Spinlocks and sequential locks my love โค๏ธ

#

Btw, development is a bit slow as my professors thought it was a good time to mix assignments + Viva :(

#

Also the fact that I'm trying to write a proposal for GSOC

simple locust
#

Not bad

simple locust
#

I should prolly leave signal handling to userspace

simple locust
#

Update: Currently refactoring some subsystems

#

And moving away from ring buffers

simple locust
#

IPC without ring buffer :)

#

Ignore the timing issue, Logger is reading time from TSC

#

Not a tsc issue

#

that's weird

#

maybe something to do with locking and multithreading?

simple locust
#

Thinking about using uint64_t as handle_t. What could go wrong?

#

nvm

#

Too much work

simple locust
#

Not as good as GDT INIT OK!

simple locust
#

There's something wrong with registers

#

left side results in GPF

#

While the right one works properly

simple locust
#

Fork T-T

#

Is it a good idea to force a yield in sys_fork() path?

simple locust
#

Status Update: Refactoring various subsystems for more stability and performance

#

most of my post-smp locks are now qspinlocks or queued rwlocks

#

RCU is still PITA

simple locust
simple locust
#

Threaded interrupts, Baby!

simple locust
#

Forgot about capabilities

#

Major rewrite incoming...

simple locust
#

Alright here's my dumb idea: Kernel only handles the core part in scheduling (context switch, notifying that the thread has expired, etc.) while a userspace service manages the policy work.

For a microkernel, this seems reasonable ig

simple locust
#

Thnx for the reference btw

unborn valley
# simple locust Thnx for the reference btw

i do something similar in my hypervisor, where the hypervisor handles context switching etc, and I have a 'root partition' (trusted vm) that assigns vcpus to scheduling frames, picks their criticality level, and timeslices, it is also responsible for raising/lowering a criticality filter on schedulers.

simple locust
#

First test with Capabilities-based communication

inner glen
simple locust
inner glen
simple locust
#

I forgot that kernel wasn't supposed to allocate on behalf of the user

simple locust
inner glen
#

what design are you targeting?

simple locust
#

And scheduling will be ported to userspace

inner glen
#

sth like Zircon or seL4

simple locust
inner glen
#

also just pure microkernel right?

simple locust
#

Like my IPC is a mix of L4, Zircon and Mach

simple locust
inner glen
#

ah

simple locust
#

Kernel will only provide essential services

#

It's likely that RB trees, Xarray, everything else will be ported to userspace

inner glen
#

honestly

#

i dont really know about microkernels

#

but what made you want to switch?

simple locust
#

But overtime, my focus shifted to adding more features to the kernel

#

and I ignored the fact that kernel wasn't supposed to define the policy

#

only mechanism

inner glen
#

the modules (kexts) control the kernel policy

simple locust
#

Like, at one point, I managed to identify my mistake with sched_classes

#

But that was still too monolithic

#

Rn, my focus is on maturing my capabilities subsystem and slowly port stuff out of the kernel

#

And maybe initialize the root server

simple locust
#

It's gonna be a big rewrite

#

Should've planned in advance

#

Time for a rewrite

#

I'm gonna push the current code and then switch to a new branch

simple locust
#

I hate writing build scripts

#

For me, That's more difficult than getting the actual kernel running

simple locust
#

Too much work ๐Ÿฅ€

#

Back to stabilizing the monolithic kernek

inner glen
simple locust
#

Now, I'll continue the project from its current state

#

With some architectural changes if needed

simple locust
#

Inspired from Zircon, Inroducing Aegis-ID

#

Similar to Zircon's Kernel Object ID (KOID), Aegis generates unique, unpredictable 64-bit IDs for kernel objects without triggering any memory locks

#

Aegis splits the 64-bit integer into two fields

#

Bits 63-56 contains the type tag used to identify the object

#

Whereas the rest are Scrambled Payloads derived (4-round Feistel Scrambler) from a per-cpu counter which is backed by a global counter base

#

Just for future reference, the constants are borrowed from fmix32 of MurmurHash3 (creator: Austin Appleby)

#

To prevent Avalanche effect

#

Actually this scrambling part is fmix32

simple locust
#

My bank account doesn't reflect 1% of that

#

๐Ÿ˜ญ

inner glen
#

also made #1487781250310734005 heard you give up Noise v2 because you were making too much c++ boilerplate

simple locust
simple locust
#

Tbh the main problem isn't with libcpp or template but the functions that is inserted by the compiler

#

You need define a way to call global constructors, and destructors

#

And that way isn't standard, it changes with architecture or abi

#

standard lib issue can be solved but what embedded C++ needs is a common compiler-rt or libstdc++

#

Which can be easily compiled

#

Instead of trying several irons in the fire, figuring out a way to compile and then link that to the kernel executable

#

The biggest hurdle for me was libcpp-abi

#

That thing refused to compile

simple locust
inner glen
eager ruin
simple locust
#

Finally RCU is working

#

This thing too just above 3 months

inner glen
#

i used to not like it

#

but now i do

simple locust
inner glen
simple locust
inner glen
simple locust
#

For better demonstration:

simple locust
#

Somehow my qsbr thread is clashing with RCU thread

inner glen
simple locust
#

If not then I'm gonna happily remove it

inner glen
#

but i dont see it quite often

simple locust
#

This thing is causing issues, Idk how

#

Or why

#

Can't use a debugger because it doesn't work well with interrupts

#

dump_stacktrace() somehow caused GPF

inner glen
inner glen
simple locust
#

Networking is for the userspace to manage

inner glen
inner glen
simple locust
inner glen
#

to test if qsbr is actually working

#

without RCU

#

or it works but breaks rcu?

simple locust
inner glen
#

then its a deeper

#

maybe a chain of problems ๐Ÿ’€

simple locust
#

I think it has something to do with the slab allocator

#

I'll investigate it later on

simple locust
#

And the cycle continues...

inner glen
simple locust
inner glen
#

and you can assign it to allocator wrappers

simple locust
#

Oh

inner glen
#

using concepts

simple locust
#

compile time functions my beloved

simple locust
#

Should I just port this to the userspace? because most of functions used here are already exposed as syscalls

int64_t sys_fork(struct syscall_regs* regs) {
    uint64_t proc_cap, cnode_cap, vspace_cap;

    int64_t err = sys_cap_clone(0, nullptr, regs, &proc_cap, &cnode_cap, &vspace_cap);
    if (err < 0) return err;

    thread_t* curr = smp_current_core()->curr_thread;

    struct capability* cap = cap_lookup(curr->owner->root_cnode, proc_cap, RIGHT_READ);
    process_t* child_proc =
        (process_t*)atomic_load_explicit(&cap->object_ptr, memory_order_acquire);
    uint64_t child_koid = child_proc->kobj.koid;

    cap_close(curr->owner->root_cnode, cnode_cap);
    cap_close(curr->owner->root_cnode, vspace_cap);

    return (int64_t)child_koid;
}
#

fork() now uses Capabilities and related components instead of blindly copying from the parent

simple locust
#

Spent approx 20 mins figuring out why rcu_data was causing a GPF

#

I forgot to memset rcu_data

#

:/

inner glen
simple locust
#

I was doing it wrong

#

POSIX syscalls shouldn't be in the kernel

#

Kernel will only expose native syscalls and the POSIX translation will be handled by a dedicated Userspace service

#

(The Managarm way)

simple locust
#

My approach to syscalls:

There are 4 main categories (as of now): Sched, memory, IPC, Capabilities

#

Each category can hold upto 0x99 syscalls

#

I'm trying to only expose syscalls that are absolutely needed and leaving most work to the userspace

#

Like in spawn_thread() doesn't allocate the user stack, that's on the caller to provide

#

Most creation syscalls would like return their own capabilities, which is the only way userspace can interact with the underlying subsystems

#

process and thread creation would be non-POSIX way, an empty environment will be created for a new process

#

Maybe I would also expose clone() to userspace for supporting fork() in POSIX translation layer

simple locust
inner glen
#

but aerosync wont be worked on anymore (at least until i cant use macos 26 anymore)

inner glen
#

macos 27 is probably gonna release lateer this year or next year

#

but as macos 26 is still recent

#

it would still get updates

#

the only major issue is the web browsers

inner glen
simple locust
#

Oh

inner glen
simple locust
#

Good news: process_create() and thread_spawn() syscalls are working
Bad news: Pagemap is brand new so, I need to figure out a way to map the program into it

#

Pure capabilities only process_create() and thread_spawn() syscalls

simple locust
#

๐Ÿ˜ญ

simple locust
#

Thread/Process cloning

#

This call can optionally create a new process or have two processes share the same memory space

#

Technically, the demonstrated behavior is similar to fork()+execv()

simple locust
#

Non-clone() Process creation and thread spawning

#

I still need to figure out a way to map elf on the run

#

But that'll prolly need a loader microserver

#

rn, I'm just hijacking process_create() to also map the test elf in its vspace

#

In future, I want the microserver to load and map the elf in the new process before thread_spawn() can create the thread

simple locust
#

IPC test :)

#

Rn I'm only working on OS specific library so that it could be used in future userspace programs

inner glen
simple locust
#

Limine provides TSC frequency too, maybe I should Update my tsc function to read from that

#

HPET can now be a userspace driver

#

Most modern x86 cpus already have TSC and LAPIC

#

So, PIT and HPET can be moved to userspace

#

The cutoff could be Nehalem for Intel and family 10h for amd

#

Putting it around ~2008-ish

#

Update: Removed HPET and PIT, thank you Limine

inner glen
simple locust
#

But now that Limine supports tsc frequency requests, I can just fetch it straight from the bootloader

simple locust
#

HPET daemon, which can be used if any program requests it

#

MMIO can be handled via IOMMU

inner glen
#

oh

inner glen
simple locust
simple locust
#

IPC Timers (Key 512 is a periodic timer with 500k ns interval, key 256 is a oneshot timer 2 sec delay)

Ticks count could be low because of snprintf() and write() overhead

#

Somehow TSC time is drifting...

#

With 50k ns interval (it's about 38080 ticks (~1904 ms))

#

Underhood it's just LAPIC in TSC deadline mode

#

Read-Copy-Write ๐Ÿ˜•

inner glen
simple locust
simple locust
#

Any interval below 40000 ns isn't registered by IPC :(

#

Time to implement timer overruns

simple locust
#

Nvm, interrupt/syscall/<insert other random mechanism here> overhead takes about ~35us

#

I'm limited by hardware and physics nooo

#

Now, I need to add some compensation mechanism to the timer

simple locust
simple locust
#

accessing memory is slow

#

sched_cost = 1192 ns

#

hr timer = 40 ns

#

lr timer = 50 ns

#

Where's it wasting the rest ~33.1 us?

simple locust
#

Definitely not the interrupt overhead

#

Because the LAPIC timer isn't periodic

#

I believe it has something to do with scheduler_tick or something

#

Because pprt_notify unblocks a thread, so the kernel needs to call scheduler_tick() before it could switch to userspace

simple locust
#

Managed to bring the minimum time to 10000ns

#

This only effect periodic timers, interesting...

simple locust
#

Wrote new syscall interface for Memory operations

simple locust
#

A syscall would only touch components that aren't explicitly exposed to the user

#

So, vspace_map() couldn't create its own vmo

#

And most operations still depend on the process's capabilities

inner glen
simple locust
#

It's part of system security

#

No process can call restricted operations

simple locust
#

Spent last couple of days working on VMA and Paging

#

and exposing syscalls to userspace

#

Maybe pause and write documentation

#

as most of the syscalls are undocumented

inner glen
#

cool

simple locust
#

My main objective rn is to stabilize the kernel

#

And expose syscalls wherever it's necessary

#

After that I'll start with the root server, and subsequent servers

#

Also, I need to clean up locks as they're a mess rn

#

Maybe a common API for every lock, a lockguard most likely

simple locust
#

I definitely need to write some asm macros

#

maybe I could borrow them from Zircon

simple locust
#

Btw, Exams suck

#

It sucks even more when you travel in 45C and an ongoing heatwave

#

Can't wait for Sunday

simple locust
#

Almost rewrote my build configuration

#

Also wrote a interface for wpkru, just need to add a few flags and expose it as a syscall

simple locust
#

I forgot wpkru is a not a privileged instruction and accidentally introduced a syscall for that too ๐Ÿ’€

simple locust
#

Rewriting my syscall interface

#

switch-cases are too slow

#

I could use arrays but that requires a unified interface for every syscall

#

Unless I trigger UB

inner glen
inner glen
simple locust
#

And it breaks control flow integrity

inner glen
simple locust
# inner glen thats also ub?

I could in theory cast it to a function that takes 6 uint64_t and returns a uint64_t but that's UB and breaks kCFI

simple locust
simple locust
inner glen
#

everything is memory

#

(or is it)

#

also

#

im doing a PoC j4f

simple locust
#

GL

#

I'm still dealing with exams

inner glen
#

a sparc64 kernel targeting the sun4u

simple locust
#

Then 10 days break before I've sem exams

inner glen
#

so much here

simple locust
#

After that, it's a relaxing 3 months break before the next semester starts

simple locust
#

This is what I want to do with my syscalls

#

typedef uint64_t (*syscall_handler_f)(struct interrupt_trapframe*);

#

quick and easy O(1) look up

inner glen
simple locust
inner glen
simple locust
#

It only contains three capabilities: cnode, proc, and vspace

simple locust
#

clone() is as close as it gets to fork()

#

Even then there are some caveats

inner glen
inner glen
#

at first i thought it was NtCreateProcess lmao

simple locust
#

The caller then can use that capability to configure the process

#

like setup the vspace, load executable, create a thread, etc.

#

Everything is explicit

inner glen
#

ah

#

so really just fork and execve routine but more explicit

simple locust
inner glen
#

not from disk but from cpio at least

#

for init

simple locust
#

But yeah it's just fork() + execve() except it doesn't have to iterate VMOs or mark pagetables as CoW

simple locust
#

and have kernel launch directly into it

inner glen
#

btw i now realize macos is not too good for osdev

simple locust
#

Then the root server will handle initialization

inner glen
simple locust
#

directly from the kernel

simple locust
#

Implemented Message queueing. The kernel would wait for the receiver to acknowledge a message before data can be transferred to buffer (max capacity = 64KB)

simple locust
#

I need to update my locks

Because:

  1. They're are non-blocking.
  2. The API is a mess
simple locust
simple locust
#

Quick Update: Rewriting the kernel (back to C++ baby!)

#

Main motivation: The architecture was a mess

#

I switched to capabilities all of a sudden

#

and that messed up a major portion of my codebase

#

PMM's policy was hard-coded in the kernel

#

VMM was a mess

#

It was better to rewrite it than attempt to fix it

#

I've also updated the build configuration

#

Added support for aarch64

#

Segregated different components, and after some quick experience with working on LLVM

#

I've started to appreciate writing documentation along with design notes

#

Rn my plan is to just write the mechanism in kernel space

#

Policy work will be handled by user-space

inner glen
#

everything is a mess

inner glen
simple locust
#

I couldn't bother to write initialization code in assembly

simple locust
#

Note to self: -mno-implicit-float over -mgeneral-regs-only, -mno-x87, -mno-80387

#

for c++ targets

simple locust
#

I hate aarch64

simple locust
#

Don't you love the moment when your code doesn't work the first

#

Then you spend hours debugging

#

With no solution

#

and suddenly at 2:58 pm, your original code magically works

inner glen
#

looking at this im actually thinking porting my latest project to C++

simple locust
simple locust
simple locust
#

Clang has some weird quirks with fpu in x86_64-elf target

#

It would allow float, double, etc. But long double is banned for some reason

#

That caused my build to fail (because libstdc++ has long double targets)

inner glen
inner glen
#

one thing though

#

@simple locust for some reason, when i enabled ubsan (undefined and friends), s390x-ibm-linux-gnu-gcc doesnt get the job done that well

#

while clang does it like it should

simple locust
#

Might have something to do with that

#

Gcc can sometimes default to internal libubsan

simple locust
#

For now, I'm just using Flanterm for logging

#

Because Limine doesn't map mmio in aarch64 :)

simple locust
#

I'm not ready for aarch64

#

I can't get the right tooling setup rn

#

LLVM-libc can't be compiled because it adds SIMD instructions

#

and there's no way to disable it without breaking the build

simple locust
#

There was a reason, I shifted to C from C++

#

And that was my habit of over-abstracting

#

So, Now I've a LogSink abstract class which is inherited by both Flanterm and Uart drivers which registers themselves to the LogManager which provides a static function that dispatches messages to each function.

#

Logger is a per-subsystem modular class, which formats messages via snprintf and then passes that message over to the LogManager

#

Btw, LogManager's messages are also configurable :)

simple locust
#

I missed C++

simple locust
#

Paging is up

inner glen
#

heyy youre back

simple locust
#

I hate to take a short break from working on the kernel because of sem exams

#

But That break did allow me to design the over-abstracted VMM

#

Also, PMM is just a bump allocator :)

#

And VMM doesn't necessarily need a PMM

#

in the kernel

#

Also, @inner glen should I map LIMINE_MEMMAP_RESERVED_MAPPED while mapping HHDM pages?

simple locust
inner glen
simple locust
inner glen
simple locust
inner glen
#

also i think its LIMINE_MEMMAP_RESERVED right?

simple locust
inner glen
inner glen
#

havent updated the header for years

#

and havent touched x86 for a few months now

simple locust
simple locust
inner glen
simple locust
#

Also, Now I understand why Linux prefers static allocations

simple locust
#

ago

#

12.3.1

inner glen
inner glen
#

i think theres a flag that limits your stack usage

simple locust
simple locust
#

or some other area

#

segment

inner glen
simple locust
#

I'm pretty sure I've over-abstracted most of my components lol

inner glen
simple locust
#

I have a Bump allocator for Kernel's PMM

inner glen
simple locust
#

(and I'm pretty sure It'll be disabled in the coming commits)

simple locust
simple locust
#

Page fault when I access SMP request's response wtf

#

smp_logger.debug("smp_request = %p", boot::smp_request.response);

inner glen
simple locust
#

I forgot to mark it as present in page table lol

#

I thought that every page was implicitly present

#

But I must've changed it

inner glen
#

anyways

#

hows the os

simple locust
#

I'm working on SMP

inner glen
inner glen
#

using limine as usual?

simple locust
inner glen
simple locust
inner glen
#

just my thought, you should make a generic layer that the kernel expect

#

and then just plug a loder into

simple locust
#

I started playing Brawl Stars

inner glen
#

like limine gives you hhdm and mb2 does not

simple locust
#

?

simple locust
inner glen
#

without hassle

simple locust
#

Makes sense

inner glen
#

since we cant get everything loader to implement our protocol

simple locust
#

I'll try to design a common interface

inner glen
inner glen
simple locust
inner glen
#

you should map it manually

#

or whatever your kenrel expect

#

not tied to how limine maps it

simple locust
inner glen
simple locust
simple locust
#

but other than that it could be just a getter function

#

Maybe I'll have to implement AP startup code

#

That requires parsing MADT

#

I was hoping to remove that from the kernel

inner glen
inner glen
simple locust
inner glen
simple locust
#

But I'll have to deal with LAPIC

simple locust
#

I just didn't want to include ACPI subcomponent in kernel

inner glen
#

microkernels dont do that

#

?

simple locust
#

Just for fun lol

#

But looking back it's a bad design idea

inner glen
simple locust
inner glen
#

im just a monolithic guy

simple locust
#

Guess what? It's a bad design idea

#

Any malicious process can compromise it

inner glen
#

isnt pcid for improved ctx switch performance or sth

simple locust
#

By the kernel

inner glen
#

@simple locust i just came back from my vacation

#

and talked with claude a bit about kernel designs

#

and it gave me capability-object, transactional, typestate-enforced, modular monolithic kernel

#

a mouthful name it is

#

but it somewhat make sense

#

i mean i could applied this to my kernel, since its a PoC and i dont really care about anything else

#
Capabilities give you what you can touch. Typestate gives you how you're allowed to touch it. Transactions give you when it's committed. They're orthogonal axes of the same resource management problem. A capability without typestate tells you "you can use this object" but not "you can use this object right now in this way". A transaction without typestate doesn't know which state rollback should restore to.
simple locust
#

Tho I wonder how would one counter forgery in a monolithic kernel

simple locust
#

From what I've read about MADT MP Wakeup Mailbox, it is fairly straight forward:

  • Fetch mailbox address from MADT table (Type 16)
  • Find the physical address for higher-half wakeup stub (which loads CR3, and does the rest of the work)
  • Store the target APIC ID
  • Send Wakeup command
simple locust
#

It simplifies AP initialization

#

You don't need to jump from real mode -> protected mode -> long mode

inner glen
#

oh

simple locust
#

On second thought, I am going back to Limine only initialization

#

It's just way too complicated

simple locust
inner glen
#

for example i just realized if i switched to C++ modules ninja would be the only option for cmake

#

(theres vs22+ but who even use visual studio to build this stuff)

simple locust
#

Well there's nothing to support

inner glen
#

and no plans either actually

#

neither the fancy FASTBuild nor Xcode

#

and despite its been since C++20 or so, Bazel just literally have "working" modules support

#

meson still experimental

simple locust
#

oh

inner glen
#

cmake probably best for cross platform, but not flawless ofc

inner glen
simple locust
#

It does

#

But I haven't worked with Modules in large projects atp

inner glen
#

my kernel used modules from a-z, no problem

#

in fact it was great

#

BUT

simple locust
inner glen
#

c++ is still dumb asf, no where as good as rust use

simple locust
#

Same with Libc++ (it doesn't support freestanding environment)

#

When Clang was designed for portability

inner glen
simple locust
inner glen
#

just a bit more

inner glen
simple locust
#

I hate summers

#

I just want to lay somewhere cold and be as unproductive as ever

#

Anyway, Wrote LAPIC subcomponent for the kernel

#

It took me a couple of weeks. But I think I've managed to make it as optimal as possible

#

Found some quirks in SDM but it was worth it

inner glen
#

ayy youre back

simple locust
#

And cursing summer heat

inner glen
#

fair point

inner glen
#

asia?

simple locust
#

South Asia

inner glen
#

its like 39 40 c here at midday

simple locust
#

I don't think I will be getting relief anytime soon

#

Monsoon is delayed, and the weather department is predicting 90% less rain due to El Nino

simple locust
#

Thinking about writing a code patcher for the kernel

inner glen
simple locust
inner glen
#

wait wait

#

so

#

a self changing kernel?

#

cant quite get that

simple locust
#

So, I want to replace those rdmsr instruction with rdgsbase if the CPU supports it

#

Same with serialize

inner glen
#

isnt that just an if statement

simple locust
#

I want to ensure the lowest latency possible

inner glen
simple locust
#

in interrupt path

inner glen
#

so it is still self modifying

simple locust
#

sort of

inner glen
#

or just be like microslop

#

or an annoying company that demands you have a good enough cpu

simple locust
#

I'm demanding a CPU which was released after 2008

inner glen
#

thats kinda old

#

just 5 years after x64 bcomes a thing

simple locust
#

maybe

#

I want it to look something like this:

ALTERNATIVE( \
        .L_manual_loop:          \
            movb (%rsi), %al   ; \
            movb %al, (%rdi)   ; \
            inc %rsi           ; \
            inc %rdi           ; \
            dec %rcx           ; \
            jnz .L_manual_loop , \
        rep movsb              , \
        FEATURE_ERMS_MEMCPY      \
    )
#

@inner glen

#

rep movsb would be stored in a separate elf section

#

And the patcher could just jump in and patch it out at boot

#

It took me a while to design it

inner glen
#

i didnt even know that is possible

#

very cool

simple locust
#

Yay!

inner glen
#

sounds very safe to me

simple locust
#

I hope so

#

atleast

inner glen
#

oh wait

#

linux already done it

#

oh i understand why the macro is named ALTERNATIVE now

simple locust
#

It creates an alias for the physical address of that instruction page and applies changes directly to it

inner glen
#

oh you are right

#

now maybe i will think about this

#

currently im just abusing [[unlikely]]

#
inline auto stckf() noexcept -> u64 {
        u64 tod{0};
        static bool checked{false};
        static bool has_stckf{false};
        if (!checked) {
            u64 fac{0};
            register u64 r0 __asm__("0") = 0;
            register u64 r1 __asm__("1") = reinterpret_cast<u64>(&fac);
            __asm__ volatile(
                "   .insn   s,0xb2b00000,0(%[addr])\n"
                :
                : [addr] "a" (r1), "d" (r0)
                : "cc", "memory"
            );
            has_stckf = (fac & (1ULL << (63U - 25U))) != 0;
            checked = true;
        }
        if (has_stckf) [[likely]] {
            __asm__ volatile("stckf %0" : "=Q" (tod) :: "cc", "memory");
        } else {
            __asm__ volatile("stck %0" : "=Q" (tod) :: "cc", "memory");
        }
        return tod;
    }
#

for example this piece of code

#

and a hundred more

#

well, at least this one isnt called in hot paths

simple locust
#

A branch condition

simple locust
#
  ALT_BEGIN
    movl $MSR_GS_BASE, %ecx
    rdmsr
    testl %edx, %edx
  ALT_REPL 64
    rdgsbaseq %rax
    testq %rax, %rax
  ALT_END
#

This one looks much cleaner

#

@inner glen what do u think?

inner glen
#

lgtm

#

does it work though what i care

simple locust
#

I figured that if those double-quotes are used for just putting instructions in the correct section

#

It would be better to just break it down into 3 different macros

#

than limit myself from using other macros in the code

inner glen
#

you mean the linux one?

simple locust
#

I don't remember tbh

#

I also updated my patcher to accurately calculate RIP relative addresses

#

And Kinda wrote a x86-64 decoder ;-;

inner glen
#

๐Ÿฅ€

simple locust
#

It's just full of magic numbers

inner glen
#

i thought your kernel is C?

simple locust
inner glen
#

i am also stuck with c++ now

simple locust
#

I'm designing it so delicately

inner glen
# simple locust

for me it feels like a switch with fallthrough cases looks better

simple locust
#

My first design of LAPIC used separate X2APIC and XAPIC transport structs as templates

simple locust
inner glen
#

but like

case N: // what this is
simple locust
#

Like this is the smallest function in the decoder

inner glen
#

bit more expressive if you are not planning to use enums

#

or defines

inner glen
simple locust
#

This functions only checks if the instruction is ModR/M

#

There's another which calculates its displacement

#

etc

inner glen
#

please no reinvent qemu in kernel space

simple locust
#

It was necessary for fixing up some instructions in Patcher

#

like RIP-relative addressing

inner glen
#

are you doing it a lot though?

#

or just several area

simple locust
#

Future proofing rn

inner glen
#

fair point

simple locust
#

Maybe I'll expand it to compiler generated code sometime in the future

#

Just for eliminating branching

inner glen
#

classic you

#

optimizations

#

love it

simple locust
#

Optimizations are the best

#

part of programming

inner glen
#

every instruction

simple locust
#

I think my FRED subsystem is ready to be tested

#

Just need to figure out how to get intel's simulator to work with my build configuration

inner glen
#

ah simics

inner glen
#

oh lmao this is the first time i compiled your os

#

the only issue is i use https

#

so please fix it if you can with the cpm thing @simple locust which is cool

#

your build configuration works like autoconf

#

and is not autoconf so much better

simple locust
inner glen
#

vrey nice

simple locust
inner glen
#

its more versitile

#

or

#

you just fall back

simple locust
#

On it ๐Ÿซก

simple locust
#

So, apparently KVM can reject MSR reads/writes

#

AMD's P-state MSR: 0xC0010064 is one such MSR which can be rejected by the hypervisor

inner glen
simple locust
inner glen
simple locust
#

But they may provide useful data

#

like TSC clock rate

inner glen
#

oh

#

and stuff like vmware tools or vbox guest additions drivers

simple locust
#

Tho I need to confirm if the rate matches with the one reported by Limine's TSC freq request

inner glen
#

accelerate stuff

inner glen
#

or just use them all

simple locust