#Nyaux

1 messages ยท Page 24 of 1

surreal path
#

my dad gonna be hella mad if i dont get a good grade, the exam is like tomorrow as well

#

๐Ÿ˜ญ

#

also while i was at school i was thinking about how the memory corruption is happening

#

i think its cause of my memset, like either i dont memset at all or i memset the wrong length writing zero's to locations i shouldnt

#

i would test this but

#

again

#

exams

surreal path
#

shhh

#

dont tell my dad im awake but

#

@finite summit

#

found the problem

#

lol

finite summit
#

I will text him rn

surreal path
finite summit
#

isn't his name mohamad

surreal path
finite summit
#

I tried

#

anyway

rigid fable
finite summit
#

w h a t

rigid fable
#

iykyk

finite summit
#

I don't

rigid fable
#

"Arab dad gets robbed"

#

and no it's not a name of that kind of vid on a sketchy site

#

idk why I thought of that but whatever

finite summit
#

oh that

surreal path
#

@finite summit fixed memory corruption bug but my iterator not working

#

causing infinite loop and pmm to die

thorn bramble
#

go to SLEEP!!!

surreal path
#

NO

#

im SO CLOSE

#

i acn feel it

thorn bramble
#

ur in Big Trouble young Man

surreal path
thorn bramble
#

what even is the problem

surreal path
#

iterator not working

thorn bramble
#

with your allocator or whatever

#

yeah but

surreal path
#

i fixed the memory corruption

#

it was

thorn bramble
#

iterators Do Work

surreal path
#

cause i didnt memset

surreal path
thorn bramble
#

ur just doing something wrong

surreal path
thorn bramble
#

u know how iterators work right?

surreal path
#

yea

#

its my implementation at fault most likely

thorn bramble
#

show

#

wait

surreal path
#
struct holder_type2(Option<NonNull<slab_header>>);
impl Iterator for holder_type2 {
    type Item = NonNull<slab_header>;
    fn next(&mut self) -> Option<Self::Item> {
        let mut start = self.0;
        unsafe {
            if start.is_none() {
                return None;
            }
            if (*start.unwrap().as_ptr()).next_slab.is_some() {
                start = (*start.unwrap().as_ptr()).next_slab;
            }
            return Some(start.unwrap())
        }
    }
    
}
thorn bramble
#

you implemented your own iterator?

surreal path
#

yea

#

no

#

like

#

implemented the trait

thorn bramble
#

me when holder_type2

#

peak rust

surreal path
#

it wont let me do it

#

on the actual value lmao

thorn bramble
#

yeah it is wrong but

#

in on phone

surreal path
#

how

thorn bramble
#

ur returning the wrong thing

#

ur doing start=next

#

and returning start

#

so ur returning next

#

u need to do self=next

#

yk

surreal path
#

oh

thorn bramble
#

yea u know

#

ok cool

#

gl

surreal path
#

new issue

#

someone is overwriting my slab thing

#

i feel like its how i calculate the objects

#

this is what i currently do

#

let obj_amount = (4096 - size_of::<slab_header>()) / size;

#

slab header just looks like this

#
#[derive(Debug)]
#[repr(C)]
struct slab_header {
    obj_size: usize,
    next_slab: holder_type2,
    freelist: holder_type,
}
#

holder type is simply a tuple struct

#

struct holder_type2(Option<NonNull<slab_header>>);

#

struct holder_type(Option<NonNull<um>>);

thorn bramble
#

holder_type

surreal path
#

i dont have a choice

#

i cant type alias

#

i cant do anything, iterator wants a type that came from the crate

#

and im not reimplementing option its just easier to have a holder type

#

anyways i will pull out debugger

#

after i take a big shit

surreal path
#

just so yall know

#

ive been trying to work on the slab allocator in userspace

#

this has been true hell

#

and even in userspace

#

its still

#

hell

#

even with ALL THE TOOLS

#

THE DEBUGGERS

#

even the fucking disassembly

#

i am

#

dying

#

of actual obos

#

curse

#

expect worse

#

@finite summit this is the nyaux curse

surreal path
#

if u say skill issue rn

rigid fable
#

Award you get when starting your own curse

surreal path
#

real

rigid fable
#

like my env is a mess

#

so consequently I do not make anything useful, thus no right to say skill issue (it is ๐Ÿ˜‰)

#

jk

surreal path
#

so close

#

cr2=18 so

#

null deref ig

#

@finite summit at least we are closer

#

welp

#

im going sleep

#

i got closer

#

today

#

but

#

thats yk

#

i may spend months getting a non buggy allocator to work lmao

#

but i dont care

#

i dont care if this project takes months or years

#

i dont intend on abandoning it ever again

#
fn pop(&mut self) -> Option<NonNull<um>> {
        match core::mem::replace(&mut self.freelist.0, None) {
            Some(t) => {
                self.freelist.0 = unsafe {(*t.as_ptr()).next.0};
                
                Some(t)
            },
            None => {
                None
            }
        }
    }
#

core::mem::replace is goated btw

#

no one diffs me

#

debugger giving me no dice

#

it doesnt see the rip as something idfk

#

i dont think its my slab allocator tbh

#

i ran a for loop 10000's of times in userspace and it ran just fine

#

if anythings its prob the vmm

#

but maybe im wrong

#

who knows

#

i should sleep

#

but i cant stop thinking

#

about the issue

#

its 2am

#

my sleep schedule is so fucked

#

time to rewrite vmm in userspace am i right or am i right!!!

#

nah that wont solve anything

#

i actually have

#

zero idea

#

whats going on

#

thats the full code of my userspace slab allocator, its the same as the kernel one expect well. userspace

#

woahhh no way

#

nyauxmaster using lifetimes

#

???

#

@thorn bramble isnt that crazy???

#

nyauxmaster using iterators and lifetimes????

#

core::mem::replace???

#

crazy.

#

had the longest 2 hour back and fourth with the rust community lmao

#

for me to actually

#

implement a sane allocator

#

anyways gn see yall tmrw

silk wind
#

How about rewriting the slab allocator from the ground?

surreal path
#

but im so close

surreal path
#

@kind root

#

does it look like memory corruption to you

#

yes or no

#

its a null deref

#

im unsure whats going

kind root
#

i mean

#

ur crashing in the allocator or something?

surreal path
#

no

surreal path
surreal path
#

here

kind root
#

whats on those lines

surreal path
#

sec

kind root
#

yeah u are probably

#

zeroing unrelated memory

surreal path
thorn bramble
#

zeroing memory you shouldn't be zeroing

kind root
#

yeah

#

so some uacpi context becomes zeroed

surreal path
kind root
#

then it does thing->member

surreal path
#

is ite because on alloc()

#

and alloc_zeroed()

#

i always zero my slab memory

#

?

#

as well as my vmm memory

#

is that bad

kind root
#

no

#

the problem is you zero random memory

surreal path
kind root
#

probably because your allocator gets corrupted somehow

surreal path
#

so

#

this as well

#

this is fine

#

as well as this

#

so

#

i dont know

#

whats going on

#

thats all the memsets

kind root
#

thats not the bug

surreal path
#

oh

kind root
#

not the zeroing itself

#

is just that your allocator returns random garbage or previously allocated address

#

so u zero it as you should and as a side effect overwrite something

surreal path
#

YOUR RIGHT

#

whoops

#

caps lock

#

okay ima

#

figure this out

#

i could do this in userspace contain a hashmap of all allocated addresses, if the returned allocated address has the address in the hashmap itll panic

#

@kind root good idea?

#

i think userspace debugging is so useful

kind root
#

yup

#

i do this for uacpi sized frees mode debugging

#

aka making sure that uacpi frees the exact number of bytes that it allocates

surreal path
#

gothca

surreal path
#

@kind root

#

i wrote the tet

#

test

#

it succeded

#

both in

#

release and dev mode

#

thats the entire test

#
if self.hashmap.get(&y.as_ptr().addr()).is_some() {
                        panic!("What the Hell.");
                    }
                    self.hashmap.insert(y.as_ptr().addr(), j.obj_size);
                     return Some(y.as_ptr().cast::<u8>());
#
if let Some(t) = self.hashmap.get(&addr.addr()) {
                assert_eq!(*t, self.size);
                self.hashmap.remove(&addr.addr());
            }
#

this is on free

#

@kind root

#

so it cannot be my slab allocator

#

may it potienally be my

#

vmm region allocator?

kind root
#

Either that or your test sucks

#

Maybe

surreal path
#

my test doesnt suck cause

#

i use a hashmap

#

in this

surreal path
#

@kind root rewrite vmm region allocator in userspace meme

#

fun

finite summit
#

sure, why not?

surreal path
#

yea lets do it

cinder plinth
#

I should rewrite tinyvmem

#

it kinda sucks

surreal path
#

yea u should

cinder plinth
#

it works it just leaks memory meme

surreal path
#

in userspace

#

or is that impossible

#

memmap

#

or

#

mmap

cinder plinth
#

What

#

I guess you could but you couldn't load the pagetable

surreal path
#

but ill do it anyway

#

@kind root we found are issue

finite summit
#

***our

surreal path
#

our issue

#

:)

#

soviet union real

finite summit
#

OUR

issue

surreal path
#

OUR

issue

#

anyways me go fixfix

surreal path
#

okay

#

figured it out

#

its llvm

#

optizing out

#

my shit

#

yea the vmm region allocator using a Vector isnt a great idea

#

i will rewrite that part i suppose

surreal path
#

FINALLY

#

LOOK AT THIS SHIT

#

FINALLY FUCKING FINALLY

#

@finite summit

#

LOOK AT THIS SHIT

#

FINALLY

#

i rewrote the entire

#

vmm allocator

#

that was hell

surreal path
#

@kind root

#

WHY IS UD2

#

BEING CALLED

#

CAUSING AN INVALID OPCODE EXCEPTION

#

ITS NOT EVEN MY MEMORY

#

LIKE

#

MY ALLOCATORS FINE

#

WHY IS IT

#

Ud2

#

ing

#

NVM

#

PRO RUST DEVS

#

TOLD ME

#

to use

#

with_exposed_addr

#

to get the provence from the ptr back

#

ez

#

we are offically

#

out.

#

of nyaux hell

#

fr this time.

kind root
rigid fable
edgy pilot
#

nyaux running wayland when

kind root
#

then chrome the day after tomorrow

sleek gazelle
#

the day after that is gnome

rigid fable
#

maybe gnome before chrome?

surreal path
#

im so tired

#

ugh

#

i slept all day

#

fuck

surreal path
#

im gonna

#

do SMP first surprisingly, then maybe the scheduler -> then timers -> then a driver abstraction interface maybe

#

@elder shoal u should've done this with astral meme

surreal path
#

no more spagthati code

elder shoal
#

I did I just never did proper debugging and it got too annoying to run with smp cuz of my bad tlb shootdowns

#

but now after I rewrite the scheduler smp should be a net positive (wow incredible)

surreal path
#

huh

#

๐Ÿ˜ก

elder shoal
#

behind you

surreal path
#

oh shi

surreal path
#

and store data about the CPU's without using dumb ah static variables

#

well tbh does the CPU struct rlly need to be mutable?

#

and how does this fit in with um

#

scheduing

#

tons of questions

#

im gonna have a think about this

surreal path
#

guys

#

would this be funny

#

if i bought this

edgy pilot
#

no

surreal path
#

why

edgy pilot
#

why would it

surreal path
#

๐Ÿ˜ก

#

anyways

surreal path
#

i think this would be useful

#

oberrow and me were chatting abt it

#

about having a dynamic driver loading thingy

#

i think this is a good idea to implement

edgy pilot
#

it definitely is

#

you could also do a stack trace with the symbol table

surreal path
#

yea

#

very fun :)

surreal path
#

i reintroduced a mutex into the slab allocator

#

and it deadlocks here

#

because uacpi holds the lock

#

towards this

#

and well

#

yea

#

i dont think it matters if it has a lock or no

#

to be honest

elder shoal
#

rust ๐Ÿฆ€ will make sure the code is blazingly ๐Ÿ”ฅ fast ๐Ÿš€ and safe rust for you

surreal path
surreal path
#

I HAVE BEEEN ASLEEP

#

FOR

#

FUCK

#

๐Ÿ˜ญ

surreal path
#

little weird

haughty kite
#

the magic is 0x7f ELF

surreal path
haughty kite
#

also have you considered using a library for doing elf parsing

#

it is 100% guaranteed to not crash and burn

surreal path
surreal path
#

๐Ÿ˜ก

haughty kite
#

just wanted to point that out

surreal path
#

im trusting limine isnt giving me a wrong ptr to the kernel file

#

cause i love limine !

surreal path
#

guys look

#

@kind root look omg

#

so pro

#

lovely

kind root
#

what is this

surreal path
#

dont u love it!

#

i even stored it in a hashmap

#

and i used the Once<T> primitive for storing it, no static mut muheheheh

kind root
#

no need for a hash map thats a giant overkill

#

store in flat array and use binary search to find address

surreal path
#

nah hashmap easy ๐Ÿ˜Ž

#

i COULD store it in a vec

#

and do that

#

but

#

nah

#

im just

#

built different like that

#

anyways now this is done

#

stack trace ig !

kind root
#

but i mean

surreal path
#

truly letsgo

#

i might use btreemap

#

actually

#

for .range

#

then i can find out the function

#

easy

wicked loom
#

make sure you don't hard rely on it in case someone stripped the kernel

#

(i invite you to try and see what happens by stripping the kernel yourself)

surreal path
#

yea i know ive put it as an Option<T>

finite summit
#

I just say don't strip kernel or kernel no work

#

:(

finite summit
haughty kite
surreal path
haughty kite
#
while (!addr in hashmap) addr -= 1;
surreal path
#

wait u can do that??

#

wait

#

no im confused now lmao

kind root
#

hes just saying its stupid

#

to use a hash map

surreal path
#

yea

#

i used a btreemap instead

haughty kite
#

could just use a list

#

and binary search

finite summit
#

or array

surreal path
#

does it matter

haughty kite
#

and get like a 1 bajillion percent performance gain

kind root
surreal path
#

lit check how fast btreemap

#

is

#

swear bro

finite summit
#

I use an rb-tree since symbol lookup by name is used a lot in the driver loader

haughty kite
#

but also loading drivers is pretty cold so a bruteforce search isnt bad either

cinder plinth
#

yeah lookup by name is fine

#

with hashmap

kind root
#

by what name if ur doing a backtrace

finite summit
cinder plinth
#

you're not

#

which is why you use binary search

finite summit
#

I start at the first symbol in the rb-tree up until the last

#

until I find it

#

not fast

surreal path
kind root
surreal path
#

oh

#

wait

#

fuck

haughty kite
#

(read: a massive lie)

kind root
#

against go?

haughty kite
#

but anyway getting tracebacks is cold

surreal path
finite summit
#

populating the symbols is slow af

cinder plinth
#

I don't lookup symbols

finite summit
surreal path
#

i might abstract the elf loading a bit

kind root
cinder plinth
cinder plinth
surreal path
#

lmaooo

surreal path
#

th

#

o

finite summit
surreal path
#

nyaux is getting dynamic drivers

#

just like OBOS

cinder plinth
finite summit
#

:(

surreal path
finite summit
#

hey! I have two syscalls

haughty kite
surreal path
#

exactly !!!!

haughty kite
#

macos doesnt have them

finite summit
surreal path
#

cause its a microkernel

cinder plinth
#

i'm doing the macOS approach

#

unironically

surreal path
#

why

haughty kite
#

i want to do it

#

its very neat

kind root
#

whats the macos appraoch

cinder plinth
#

its nice

haughty kite
#

and security

surreal path
#

yea

haughty kite
#

in userspace

cinder plinth
#

i'll also have my own plist file format meme

haughty kite
#

then sign it all together

kind root
#

chicken egg?

haughty kite
kind root
#

how do i load at runtime

surreal path
#

chicken egg

#

chicken egg egg chicken

haughty kite
cinder plinth
kind root
#

then thats just a normal static module?

haughty kite
surreal path
#

wait

#

lemme check

#

smthin

haughty kite
cinder plinth
#

but yeah is json a good idea

#

or bson

haughty kite
#

like you can go (kernel + kexts) -> kernelcache

cinder plinth
#

maybe

kind root
#

wdym

cinder plinth
#

bson would be better probs

#

like

surreal path
cinder plinth
#

authors write json files then "compile" them

haughty kite
#

you just cant do it at runtime

finite summit
#

now if you'll excuse me, I must fix syscalls

haughty kite
kind root
surreal path
kind root
#

yeah thats bs

haughty kite
#

the last part of the diagram is not how it works

#

at all

surreal path
#

ohhhhh

#

yea right

cinder plinth
#

TIL having a posix layer in userspace == hybrid

surreal path
#

ah i see

#

what do yall think i should design nyaux's kernel approach

haughty kite
#

you should make a working one

surreal path
#

okay yea true

haughty kite
#

and not tear down more code

kind root
#

make it to userspace

surreal path
#

okay

kind root
#

with an actual kernel

surreal path
#

ill just add driver loading

kind root
#

thats not a speedrun

surreal path
#

okay

surreal path
cinder plinth
#

i need to redo my iokit thing

surreal path
#

and then

cinder plinth
#

devkit i called it I think

surreal path
#

timers

#

and then a scheduler

finite summit
surreal path
#

will do

#

im gonna abstract a lot of things

#

and

#

make them actually usable

#

wait could u run x11 on macos

#

is there a way to like

#

remove aqua

#

and carbon and coco

#

idfk

cinder plinth
surreal path
#

and i believe

#

linux kernel is a monolitic kernel

#

wait

#

i have an idea

#

like ill give nyaux dyanmic driver loading

#

okay this is way off in the future but

#

buuuuuut

#

i could have like

#

a package manager to get drivers

#

and then

#

yea yk what i mean

finite summit
#

by default

surreal path
#

but waittttttt ugh

#

noooo

#

cause like

#

idfk thats for future me to figure out

#

lets just work on THE STACK TRACES !!!!!!!!!

cinder plinth
#

ok bson might not be stupid

#

I shall implement it in my new library โ„ข๏ธ

surreal path
cinder plinth
#

json

#

but

#

binary

surreal path
#

oh i see

#

cool !

cinder plinth
#

it's used by mongodb

#

was made by them too

surreal path
#

i see !

surreal path
#

LOOK

#

WE GOT A STACK TRACE

#

!!!!

#

smp time?

surreal path
#

lol this is so cute

edgy pilot
surreal path
#

so thats what we doing

edgy pilot
#

better to have multiple CPUs and have your scheduler support them from the beginning

surreal path
#

okay good point

edgy pilot
#

so you don't have to modify it later

surreal path
#

yea

#

ill do timers -> smp

#

then yk

kind root
surreal path
#

:3

#

okay anyways ill be live streaming

#

if anyone wants to join

edgy pilot
surreal path
#

bru

#

๐Ÿ’€

surreal path
#

๐Ÿ˜ก

edgy pilot
#

eepy

#

2:36

surreal path
#

:c

edgy pilot
#

oh I just noticed VCs are numbered from 0 :D

surreal path
#

why is uacpi::reboot not working infy

#

@kind root

#

just asking

finite summit
#

skill issue

surreal path
#

bru

kind root
#

did u implement io write

surreal path
#

yes

finite summit
#

it probably works for me

kind root
#

are u using -M q35

surreal path
#

yea

kind root
#

then yeah skill issue

surreal path
#

what

kind root
#

whats the status code

surreal path
#

it didnt give a status code

#

lmao

kind root
#

huh

surreal path
#

yea

kind root
#

didnt give how

finite summit
#

it returns a uacpi_status

kind root
#

lmao

finite summit
#

in C

kind root
#

it just decided

#

no i wont return it

surreal path
#

no it returned ok

#

or whatever

kind root
#

then your io write is broken

surreal path
#

WAIT

#

nvm

finite summit
#

@kind root
it says in uacpi_prepare_for_sleep_state

Must be caled with interrupts ENABLED.

#

do they need to be enabled? or is it just preferable

kind root
#

they need to be

#

it might wait for SCI in the AML

finite summit
#

so GPEs should be unmasked

kind root
#

it might do shit like Wait(EVENT, 0xFFFF)

surreal path
#
unsafe fn raw_io_read(&self, addr: uacpi::IOAddr, byte_width: u8) -> Result<u64, uacpi::Status> {
        if byte_width.is_power_of_two() == false {return Err(uacpi::Status::InvalidArgument);};
        match byte_width {
            1 => {
                let value: u8;
                core::arch::asm!("in al, dx", out("al") value, in("dx") addr.as_u64());
                Ok(value as u64)
            },
            2 => {
                let value: u16;
                core::arch::asm!("in ax, dx", out("ax") value, in("dx") addr.as_u64());
                Ok(value as u64)
            }
            4 => {
                let value: u32;
                core::arch::asm!("in eax, dx", out("eax") value, in("dx") addr.as_u64());
                Ok(value as u64)
            }, 
            _ => {
                return Err(uacpi::Status::InvalidArgument);
            }
        }
    }
#

thats what my raw_io_read is

kind root
#

did u mask them?

finite summit
#

no

#

well yes

#

because my IRQs are broken

kind root
#

theyre unmasked by default

#

anyways this shouldnt matter for 99% of hw

finite summit
#

ok

kind root
#

maybe not 99% but like 95

finite summit
#

since syscall handlers run at IRQL_DISPATCH

finite summit
#

and I'm making a Sys_Shutdown

surreal path
#
unsafe fn raw_io_write(&self, addr: uacpi::IOAddr, byte_width: u8, val: u64) -> Result<(), uacpi::Status> {
        if !byte_width.is_power_of_two() {return Err(uacpi::Status::InvalidArgument);};
        match byte_width {
            1 => {
                core::arch::asm!("out dx, al", in("al") val as u8, in("dx") addr.as_u64() as u16, options(nomem, nostack, preserves_flags));
                return Ok(());
            },
            2 => {
                core::arch::asm!("out dx, al", in("ax") val as u16, in("dx") addr.as_u64() as u16, options(nomem, nostack, preserves_flags));
                return Ok(());
            },
            4 => {
                core::arch::asm!("out dx, eax", in("dx") addr.as_u64() as u16, in("eax") val as u32, options(nomem, nostack, preserves_flags));
                return Ok(());
            },
            8 => {
                return Err(uacpi::Status::InvalidArgument);
            }
            _ => {
                return Err(uacpi::Status::InvalidArgument);
            }

        }
        
    }
#

thats what i do

kind root
#

i mean

#

i have no idea what this is doing

surreal path
#
unsafe fn io_write(
            &self,
            handle: uacpi::Handle,
            offset: usize,
            byte_width: u8,
            val: u64,
        ) -> Result<(), uacpi::Status> {
            let ok = handle.as_u64();
            let ok = core::ptr::with_exposed_provenance_mut::<IOthingy>(ok as usize);
            println!("{:?}", *ok);
            self.raw_io_write((*ok).base, byte_width, val)
            
    }
kind root
#

im not good at rust

#

add a printf to see what its writing where

surreal path
#

okay

#
0x0
#

this is the init

#

its not printing

#

anything

#

after uacpi succed init

kind root
#

its writing to io port 0?

surreal path
#

ill add more printf

surreal path
kind root
#

yeah thats already bogus

surreal path
#

sec

kind root
#

wait u realize

#

io_write writes at an ofset

surreal path
#

yea

kind root
#

to the port it has mapped

#

via io_map

#

u do take that mapping into account?

surreal path
#

is len an offset

kind root
#

offset is offset

surreal path
#

io map has len

#

no offset

kind root
#

thats just bounds

surreal path
#

ohhh i see right

#

one sec

#

i think i fixed it

#

well now its writing

#

still no reboot tho

#

oh wait

#

i see qemu to

#

--no-reboot

#

YEP

#

@kind root it reboots

#

fun!

kind root
surreal path
finite summit
edgy pilot
elder shoal
#

look at the top of the qemu screen

#

wait

#

oops my chat was way up there

surreal path
#

yea ๐Ÿ˜ญ

#

anyways reading spec on hpet

#

implmenting it

elder shoal
#

if you dont care about real hardware just yet (and plan on only testing on kvm) you can do kvm clock

surreal path
#

no

#

i actually care about real hardware

finite summit
#

especially on real hw

kind root
#

on real hw u have invariant tsc

#

in vm u have kvm clock

surreal path
finite summit
#

"high presicion" my ass

surreal path
#

so i have to use invariant tsc

#

i see

finite summit
#

my fireworks test on real hw using the hpet was running at <1 fps

#

as opposed to qemu+hpet running at an acceptable pace

kind root
#

u calibrate against hpet or acpi timer or pit

surreal path
#

but isnt the hpet inaccurate

finite summit
surreal path
#

okay

finite summit
#

but not accurate enough to use for like. anything else.

kind root
#

hpet is accurate

#

it just needs careful handling

elder shoal
#

and its slow as shit

kind root
#

on real hw it might take a huge amount of time to respond or return random garbage

#

depending on bus load

finite summit
#

well it's not inaccurate

#

it's just slow af

surreal path
#

yea i get you

kind root
#

linux does retries for reading it

#

with backoff and stuff

surreal path
#

and im guessing

#

that after u calibrate invarient tsc

#

u can use it to calibrate the lapic timer?

kind root
#

lapic has a mode where it works with tsc as the counter

surreal path
#

wdym

finite summit
#

you calibrate the invariant tsc and/or lapic timer using the hpet/acpi timer -> pit if neither of those exist

#

then you use the lapic timer in invariant tsc mode to get timer IRQs

kind root
#

some notes on hpet

finite summit
#

rdtsc

elder shoal
#

HPETs are a complete disaster.

kind root
#

yeah this is funny

elder shoal
#
 * That's perfectly fine. HPET is a piece of hardware designed by committee
 * and the only reasons why it is still in use on modern systems is the
 * fact that it is impossible to reliably query TSC and CPU frequency via
 * CPUID or firmware.
 *
 * If HPET is functional it is useful for calibrating TSC, but this can be
 * done via PMTIMER as well which seems to be the last remaining timer on
 * X86/INTEL platforms that has not been completely wreckaged by feature
 * creep.
 *
 * In theory HPET support should be removed altogether, but there are older
 * systems out there which depend on it because TSC and APIC timer are
 * dysfunctional in deeper C-states.
 *
 * It's only 20 years now that hardware people have been asked to provide
 * reliable and discoverable facilities which can be used for timekeeping
 * and per CPU timer interrupts.
 *
 * The probability that this problem is going to be solved in the
 * foreseeable future is close to zero, so the kernel has to be cluttered
 * with heuristics to keep up with the ever growing amount of hardware and
 * firmware trainwrecks. Hopefully some day hardware people will understand
 * that the approach of "This can be fixed in software" is not sustainable.
 * Hope dies last...
 */
finite summit
#

if it exists

#

which it only does on newer hardware

surreal path
#

got you

finite summit
#

no no

#

shit brain fart

#

timers on amd64 suck

surreal path
#

if they suck

#

then what do u use

finite summit
#

my kernel's timekeeping is shit

#

I need to revisit that on amd64

surreal path
#

i will need to cast the hpet to a *mut u8 before i add anything right?

#

???

finite summit
#

idk maybe

#

idk rust

surreal path
#

it fails

#

why is my hpet

#

not 64 bit

kind root
#

Back to the same issue KEKW

surreal path
kind root
#

U had this same issue before

#

Of reading hpet stuff in a bogus way

surreal path
#

show me the message

#

oh wait i think i remember

surreal path
#

the variable h

kind root
#

#1230349543623757845 message

surreal path
#

im doing .read()

kind root
#

Idk what ur doing

#

But u have the same issue somehow lol

surreal path
#

lol

surreal path
#

i did 1 << 13

#

thats wrong

#

lmao

#

๐Ÿ˜ญ

kind root
#

Why

surreal path
#

it was

#

to rust for some reason

kind root
#

What's the correct way

surreal path
#

1 << 12

kind root
#

Oh

surreal path
#

yea

surreal path
#

okay so the hpet is actually not 64 bit

#

1010100010001010101000001001000

#

count from 0

#

even on kvm

elder shoal
#

idk what qemu youre using becauseo n mine its 64 bit

surreal path
#

i dont think its a bug either

#

address is aligned

elder shoal
#

9.0.2

surreal path
#

everything is correct

elder shoal
#

it was 64 bit on older versions I used so youre doing sdomething wrong

surreal path
#

i lit just printed the address

#

not the address

#

the deref of the register

surreal path
#

its disabled

#

i foudn something

#

its for 7.2.0

#

tho

#

it was closed 6 months ago tho

#

This bug has been fixed in qemu 8.2.1.

#

oh then

#

wtf

#

its not a bug

#

kill me

#

i just figured it out

#

and its the most

#

STUPID

#

bug

#

ever fucking

#

made

#

do yall know what it is?

#

IT POINTED ME TO THE ACTUAL HPET TABLE

#

NOT THE HPET ITSELF

#

๐Ÿ’€

#

letss gooo

#

okay nanoseconds is 8

#

or nvm

#

thats wrong

#

yea that is wrong

#

okay its right now i think

#

10 nanosecond

#

ill just use the lapic timer to be fair

#

lol

#

is easy

#

okay time to calibrate the lapic timer

surreal path
#

okay probs my biggest commit yet

#

anyways

#

its time for scheduling @finite summit

#

!!!

finite summit
#

yay

surreal path
#

first i need smp tho

#

very important !!!

finite summit
#

I mean you can make a smp scheduler without smp

#

you can add smp later on

#

but do smp first

surreal path
#

its fine

#

i do smp

finite summit
#

gl

surreal path
#

thanks

finite summit
#

inb4 nyaux rewrite 3

surreal path
#

no

#

nope

#

nuh uh!

finite summit
#

this time in C

surreal path
#

nopers

rigid fable
#

C? In assembly you mean

surreal path
#

okay lapic is done and smp is kinda done lemme just add 3 cpus

#

works fine

#

now i just make scheduler

#

ez i hope

#

wait

#

a bit

#

gotta make some cpu structs right @finite summit

finite summit
#

indeed

#

have it store the current thread

#

possible a pointer to the CPU's idle thread

#

as well as any other per-cpu scheduler stuff

#

like local run queues

surreal path
#

and where will this cpu struct be stored

#

gs_base?

finite summit
#

yes

#

and don't forget to swapgs if you are coming from usermode

surreal path
#

yea i already have that

#

setup

#

i just need to make the thread struct

#

and process struct

#

and yea

#

then the cpu struct itself

surreal path
finite summit
#

yes

#

you have per-cpu run queues

#

where else would you store them?

surreal path
#

oh and how do i randomly decide when i wanna give threads to another cpu queue or smthin

#

like smthin rlly basic

finite summit
#

if I knew I'd tell you

#

do NOT look at my kernel

#

for scheduler inspiration

surreal path
#

lmao

#

ur scheduler probs rlly bad

#

isnt it

finite summit
#

it's terrible

surreal path
#

damn

#

๐Ÿ˜ญ

finite summit
#

threads starve

#

work is balanced tho

#

but that doesn't matter

#

since threads starve

#

there is world hunger in my kernel

surreal path
#

how'd u get the other cpu structs

#

linked list?

finite summit
#

I have them stored in a linear array

#

they're only allocated once so you can do that

surreal path
#

yea fair

rigid fable
#

the next one is gonna be very bad

#

very bad

surreal path
rigid fable
#

hey you are not the one with the long standing curse

surreal path
#

i did for like

#

3 months

#

with memory management

#

๐Ÿ’€

rigid fable
#

jfc (does this exist?) which part of the mm was hard to make

surreal path
#

idk a lot of rust skill issues it was

#

but i got through em now

#

:)

rigid fable
#

what fucking problems does discors have? It blacks out every now and then for no reason

surreal path
#

idk ๐Ÿ˜ญ

rigid fable
surreal path
#

slab allocator, vmm

#

@finite summit i have an idea

#

one sec lemme pull up microshit paint

finite summit
#

then

#
Kernel Panic on CPU 1 in thread 10, owned by process 2. Reason: OBOS_PANIC_EXCEPTION. Information on the crash is below:
Page fault at 0xffffffff8000dd88 in kernel-mode while to write page at 0x0000000000000000, which is unpresent. Error code: 2
Register dump:
        RDI: 0xffffff0000023ea0, RSI: 0x0000000000000000, RBP: 0xffffffff80328ff0
        RSP: 0xffffffff80328f68, RBX: 0xffffffff80028a92, RDX: 0x0000000000000000
        RCX: 0x0000000000000000, RAX: 0x0000000000000000, RIP: 0xffffffff8000dd88
         R8: 0x0000000000000000,  R9: 0x0000000000000000, R10: 0x27235311250fd7ed
        R11: 0x0000000400000000, R12: 0x0000000000000000, R13: 0x0000000000000000
        R14: 0x0000000000000000, R15: 0x0000000000000000, RFL: 0x0000000000210282
         SS: 0x0000000000000010,  DS: 0x0000000000000000,  CS: 0x0000000000000008
        CR0: 0x0000000080010011, CR2: 0x0000000000000000, CR3: 0x0000000000006000
        CR4: 0x0000000000000020, CR8: 0x0000000000000000, EFER: 0x0000000000000d01```
surreal path
#

the blocks represent threads @finite summit

#

on each task switch every thread is put into the next cpu queue and trickles down