#Nyaux

1 messages ยท Page 23 of 1

hollow goblet
#

I tried writing a kernel in C++ before

#

it was also fun

#

it was fun for different reasons tho

#

it was fun to like, implement String and shit from scratch

edgy pilot
#

I implemented whole std::string from scratch

#

with sso and stuff

#

(I don't remember exactly but I think I copied some stuff from libc++ libstdc++ and msvc++)

hollow goblet
#

i copied serenity's array stuff (those stuff are pretty simple, their String is much more complicated) and String was just a glorified array of characters with helper shit

unkempt relic
#

modern gcc, you just --disabled-hosted-libstdcxx or something like htat

#

and it will just work

flat nymph
#

I'm just planning to use libstdc++ for that in my kernel

unkempt relic
#

i will be using exceptions in this mock kernel i am putting together to make fun of hackernews

flat nymph
edgy pilot
#

I haven't encountered any bugs yet

#

you just need freestanding-cxx-headers and <memory> with std::allocator implemented

surreal path
#

yea we are doing c++

#

if that doesnt work C

edgy pilot
#

I suggest you do at least some userspace C++ first

flat nymph
#

You can just look at how I'm doing it and do it the other way around meme

surreal path
#

actually nah

#

C

flat nymph
#

boring

cinder plinth
#

how is that a problem

finite summit
#

because I said it is

molten grotto
#

eh

#

they are fine

finite summit
#

if you know what you're doing yeah

molten grotto
#

just don't allocate any memory in them if you are going to run them before you have an allocator

thorn bramble
#

what

#

the rfuck

#

am i reading

thorn bramble
finite summit
#

say you initialzie the allocator in there

finite summit
#

but also allocate memory in another global constructor

molten grotto
finite summit
#

you might assume a specific order

edgy pilot
thorn bramble
#

that

flat nymph
#

I don't know how they work, but I assumed it's just a pointer to a static table at the beginning of the object

molten grotto
cinder plinth
#

I've never had to worry about vtables

#

idk why you're making such a big deal

finite summit
#

yeah I just took some random thing

thorn bramble
edgy pilot
molten grotto
#

I just chose the option of not allocating memory in them as you usually don't need to

flat nymph
cinder plinth
#

I don't use global constructors

thorn bramble
#

i was confused at first too

cinder plinth
#

I use frg::manual_box

thorn bramble
#

vtables are fine too

#

like everything is fine

#

u just need to know

#

the fucking language

molten grotto
#

but for things like the log eh

thorn bramble
#

jsut use constexpr/consteval constructors ๐Ÿ’ฏ

flat nymph
#

Global constructors are absolutely fine

thorn bramble
#

consteval operator new/delete coming to a c++26 near you soon

cinder plinth
flat nymph
cinder plinth
#

like

#

they dont do anything

thorn bramble
#

yeah no they dont do anything on their own

cinder plinth
#

apart from maybe being slower

edgy pilot
cinder plinth
thorn bramble
#

you can do it manually in C

edgy pilot
cinder plinth
#

yes

thorn bramble
#

or you can ask the language to do it for you using virtual

cinder plinth
#

but virtual functions will be slower to call

edgy pilot
thorn bramble
edgy pilot
#

yes

thorn bramble
#

it's necessary for stuff liek vfs anyway

molten grotto
#

they have one more indirection vs inlining the vtable inside the object

edgy pilot
cinder plinth
#

yes but in any C++ program where you need absolute performance you shouldnt use virtual classes

thorn bramble
#

yeah sure but we are talking about a hobby kernel

cinder plinth
#

yes

thorn bramble
#

the performance hit is basically non existent

cinder plinth
#

yea ofc

#

like i said

#

they're irrelevant

#

when doing osdev

edgy pilot
#

my vfs was basically just virtual functions

#

every part of it

median goblet
cinder plinth
#

yeah mine is just a bunch of virtual classes

median goblet
#

so its like calling a function pointer

median goblet
#

its Not That Bad

cinder plinth
#

I never said it was

median goblet
#

you should really start worrying about performance of trivial things like this, only when you can't do anything else to optimize your stuff

cinder plinth
#

"It's not a performance problem until you can prove it."

edgy pilot
#

inline call isn't a call

molten grotto
edgy pilot
#

its like 2.1 times slower than a regular call

elder shoal
#

just dont do oop and have a giant switch statement ez

molten grotto
edgy pilot
#

genious

cinder plinth
#

it's not an issue unless you're calling those functions millions of time per second

edgy pilot
#

and you'll probably never do that in a hobby kernel

cinder plinth
#

"A virtual function call first needs to load the vtable pointer from the object. This can result in a data cache miss. Then it loads the function pointer from the vtable which can result in another data cache miss. Then it calls the function which can result in an instruction cache miss like a non-virtual function."

#

nowadays it's def not an issue

median goblet
cinder plinth
#

for 1. hobby kernels and 2. fast cpus

flat nymph
edgy pilot
#

?

molten grotto
cinder plinth
median goblet
molten grotto
#

yeah that's why I said with a small number of cases

cinder plinth
#

"The time it takes to call a virtual member function is a few clock cycles more than it takes to
call a non-virtual member function, provided that the function call statement always calls the
same version of the virtual function. If the version changes then you may get a misprediction
penalty of 10 - 20 clock cycles. The rules for prediction and misprediction of virtual function
calls is the same as for switch statements,"

flat nymph
cinder plinth
#

what is final

flat nymph
#

final class

#

or function

edgy pilot
#

class that can't be inherited from anymore

cinder plinth
#

what's the point

edgy pilot
#

or a function

cinder plinth
#

can't you just

#

not make a base class

edgy pilot
#

what's the point of override

flat nymph
#

Sometimes not?

edgy pilot
flat nymph
#

Like in some situations I think inheritance is more convenient that having a bunch of unions or whatever

#

and less error-prone

#

But it you store a pointer to the derrived object, then it makes virtual functions free

haughty kite
#

override isn't required though afaik

#

right?

flat nymph
#

clang complains if you don't add it

flat nymph
haughty kite
#

only if you use any override

#

if you dont use any of it it will not complain

molten grotto
#

not using override is bad code anyway

#

it should just be an error tbh

cinder plinth
#

i thought override was needed

haughty kite
#

nop

cinder plinth
#

idk it always complained for me

#

maybe because of -Werror

flat nymph
#

I think gcc doesn't care

cinder plinth
#

I use clang

edgy pilot
#

it's not a warning

#

I use clang too

cinder plinth
#

wha

#

then idk

#

i always get stuff like "overriden function not marked override"

edgy pilot
#

if you use it on at least one method, then it complains

cinder plinth
#

ah

edgy pilot
#
'func' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
surreal path
#

or yk what

#

ill just learn rust properly even if it takes months

#

guess nyaux will be suspended for 2-3 months maybe

#

its sad but

#

its the unfortunate truth

#

i will see you all in 2-3 months

#

and when im back i should be compitent enough to write an os

cinder plinth
#

why do you even want to use rust

#

it sucks for osdev

#

if you still want fancy abstractions use C++

finite summit
green elbow
#

i mean rust is fine for osdev

#

just

#

when you use rust

#

don't fight the borrow checker

#

it's like the defining feature of rust

cinder plinth
green elbow
#

that's also fine

thorn bramble
#

doubly linked list isn't

#

unless you want to spam Rc/Arc

green elbow
#

with unsafe it's fine

thorn bramble
#

or that

finite summit
#

or in C

thorn bramble
#

well, no, it's not exactly fine

#

but yeah whhtever

green elbow
#

well, yeah, but unsafe is simply required in some cases

#

it is also a feature of the language

flat nymph
#

Just use Ada

surreal path
#

ill just use C++ but without most of the C++ features, only like the classes

#

just not rn tho

#

i need to sleep

#

in a few hours ill setup stuff

#

ill get there

#

im a little tired tho

#

night night

flat nymph
#

RAII is great

surreal path
#

NVM IM STAYING WITH RUST

#

I JUST FIGURED OUT THE ISSUE LMAO

#

IM SO STUPID

surreal path
#

pretty much

#

YEP IT ALL WORKS

#

IT PAGE FAULTED

#

AS EXPECTED

#

YAYYAYAYAYAY

elder shoal
#

now do on demand allocation

surreal path
#

mathew dont try to torture me

#

๐Ÿ˜ก

edgy pilot
elder shoal
#

how I do it is on the first page fault on an anonymous range, I map a shared zero page and then do copy on write on it if nescessary

surreal path
#

NVM IT STILL ISNT PAGE FAULTING THAT WAS SOME OTHER BUG

#

WTF

#

WHY WONT IT UNMAP

#

RAHHH

edgy pilot
#

back to C

surreal path
#

NO

#

THIS SEEMS TO BE A LOGIC BUG

#

of some kind

#

switching a dif language wont help

cinder plinth
#

I just allocate it on-demand

surreal path
#

rustc

cinder plinth
#

what

surreal path
#

boo

#

did u get scared

cinder plinth
#

no

surreal path
#

anyways same thing it is UNMAPPING the phys addr

#

still no page fault tho

#

๐Ÿ˜”

edgy pilot
#

check the mapped pages in qemu monitor

surreal path
#

yea thats what im gonna do

flat nymph
#

Are you flushing TLB?

surreal path
#

i am invlpging yea

#

info tlb shows its not mapped

#

i will now not dealloc it and check info tlb again

#

if it is mapped then

#

this is not my problem to deal with

#

could be some rust quirk idfk

finite summit
#

btw info tlb has nothing to do with the tlb

surreal path
#

wym

finite summit
#

it's just printing the mappings page by page

#

as opposed to in a range format when you do info mem

surreal path
#

how do i view the tlb

finite summit
#

that's the neat part

#

you don't

surreal path
#

fun

#

okay this is getting weird

#

even not unmamping it

#

its not showing up

#

umm

#

lol

#

oh wait

#

flags i forgor

#

still not showing up?

#

yea this weird lmao

#

should i even care if unmap works or not

#

i mean

#

im doing everything correct

#
self.unmap(i.base + (f * 0x1000));
                    assert_eq!(
                        None,
                        Self::find_pte(self.rootpagetable as usize, i.base + (f * 0x1000))
                    );
#

ill do something like this to verify

#

if it fails

#

bug

#

if it doesnt

#

idk tlb hates me lol

#

tlb can kiss my booty

#

idc then

#

yea no problems with the assert

#

so it did work

#

just tlb does NOT care

#

๐Ÿ˜ญ

#

why is there no invlpg instruction

#

HELLO

#

RUST???

#

๐Ÿ˜ญ

#

this is dev mode

#

and its like

#

not there

#

yall gotta be kidding me

finite summit
#

make sure the asm thing is volatile or smth

#

idk rust

surreal path
#
Instead of having to explicitly use volatile, volatile is the default and you have to opt-out if you want using pure. This is done to prevent forgetting to use volatile when you need to.
#

does anyone here work with rust no whats going on

finite summit
#

then make an asm function

#

that does invlpg

surreal path
#

good idea

finite summit
#
global invplg
invplg:
    invlpg [rdi]
    ret```
#

taken straight from obos

surreal path
#

yoinky splunky

#

ummm still objdumping no exist

#

WHWHY RUST HATE ME

#

RAHH

#

OKAY YK WHAT I DONT CARE IMA MOVE ON

kind root
#

werent u rewriting it yesterday

surreal path
haughty kite
#

probably because you dont know how to write correct rust code

surreal path
#

stupid me

surreal path
#

๐Ÿ˜ก

kind root
#

yeah thats uh

#

not how that works

finite summit
#

use C

haughty kite
#

yeah

surreal path
#

nah look im just gonna ignore whats going on, rust is not compiling invlpg in but it doesnt rlly matter DOES IT

#

nah

finite summit
#

day n of waiting for nyaux to switch to C

haughty kite
#

it does

#

lol

finite summit
#

it does

surreal path
#

okay look ima see if the rust server knows abt this or whatever

#

is fine

finite summit
#

I should join the rust server

#

say "C better"

#

and leave

kind root
#

day n of waiting for nyaux to burn out because of rust issues and speedrunning os instead of learning it

surreal path
#

i know what im doing

haughty kite
#

its not even speedrunning

finite summit
kind root
#

ur trying to speedrun

haughty kite
kind root
#

but u get stuck every minute

surreal path
finite summit
#

(dunning kruger effect)

surreal path
#

bru

surreal path
#

i understand the concepts of what i need to implement

kind root
#

High level details rather

surreal path
#

and implementation details

#

its just

#

im stupid

#

lol

#

is all

kind root
#

No

surreal path
#

wym no?

#

i know how to implement a gdt and a idt and a vfs and a vmm and a pmm and a scheduler and such

kind root
surreal path
kind root
#

Not learning rust properly, then proceeding to use it for a thing that requires insanely advanced rust knowledge, not researching the component that you're writing and instead doing it willy nilly

kind root
#

Vmm, pmm, scheduler, whatever ur doing right now

surreal path
#

but i do now

#

know*

finite summit
#

moral of the story: use C

haughty kite
#

or learn to program first in general

surreal path
#

um

#

excuse me?

haughty kite
#

the rust safety rules are incredibly complex

finite summit
surreal path
surreal path
#

chat can we just stop trying to roast me into a roasted chicken

#

this is rlly like yall trying to bring down my moral or smthin nooo

edgy pilot
finite summit
#

-# I came into osdev not knowing how to make a linked list, and didn't know a thing about most data structures

surreal path
#

i know how to make a linked list wtf

finite summit
#

I'm saying I didn't know how

#

lol

edgy pilot
# surreal path what

he said

I came into osdev not knowing how to make a linked list, and didn't know a thing about most data structures

finite summit
#

now I do though

surreal path
surreal path
finite summit
#

yes

haughty kite
#

dont worry at least its not rust

finite summit
#

I

haughty kite
#

aka "you cant make a safe doubly linked list" lang

finite summit
#

just work on obos, it's only half cursed

#

at least invlpg works there lol

surreal path
#

thats kinda mean to be honest

haughty kite
#

ok sorry

surreal path
#

thanks

#

look ima ask the rust server abt this and we'll see whats going on

surreal path
# edgy pilot sorry but clearly not enough

maybe there are gaps in my knowledge sure, but im learning them and im improving. im not trying to speedrun im not trying to not learn i am trying to learn and understand to the best i can

hollow goblet
#

@surreal path hi fellow rust osdever

surreal path
#

hi

hollow goblet
#

I just got my basic scheduler working

surreal path
#

nice

hollow goblet
#

sleep is not there yet because I'm still not happy with my timer stuff

surreal path
hollow goblet
#

but otherwise sleep is easyy

surreal path
#

nice !

#

rust server big brain

hollow goblet
#

it is useful

#

check the asm! docs

#

if memory is clobbered llvm/rustc won't reorder or drop anything

surreal path
hollow goblet
#

idk check the docs

#

i know it exists

#

i used it in clang but i don't know the syntax for rust asm!

surreal path
hollow goblet
#

no not that

#

ok let me check the docs

#

worst case, use llvm_asm! maybe they don't have such an option in asm!

#

ok in asm! it is enabled by default

#

ignore everything i said

surreal path
#

bru

hollow goblet
#

unless you pass options(nomem)

finite summit
hollow goblet
#

it does what you want it to do

surreal path
#

and rust still optimized it out lmao

hollow goblet
finite summit
#

rust skill issue

hollow goblet
#

i don't know the issue but i don't think it's a rust skill issue

#

rust's asm! is just a different syntax over llvm's

finite summit
#

why tf would rust optimize out a function call that it knows nothing about

surreal path
#

ask llvm

#

not me

finite summit
#

he said he also used a function call

surreal path
#

yea

#

i did

#

include_asm!

finite summit
#

add it to your build

#

then extern c it

edgy pilot
#

can rust even do that

finite summit
#

I think so

#

@cinder plinth might know, he's the rust compiler, after all

cinder plinth
#

Yeah it's the same as calling c functions I guess

hollow goblet
#

I'VE ALWAYS USED global_asm!(include_str!()) AAAAAA

surreal path
#

srry i mean

hollow goblet
surreal path
#

global_asm

hollow goblet
# hollow goblet yes

idk what's wrong with this server and hate on rust but yea rust has external linking lmao

surreal path
#

i have an idea

cinder plinth
#

It's not hate it's just no one knows it

finite summit
#

I don't hate rust, I despise it /j

hollow goblet
thorn bramble
#

the way everyone uses rust for osdev is shit

surreal path
#

even doing this

#
let mut fake: usize;
                core::arch::asm!(
                    "invlpg [{0}]",
                    "mov {1}, 5",
                    in(reg) va,
                    out(reg) fake,
                    options(nostack)
                );
                println!("{}", fake);
edgy pilot
surreal path
#

rust still optizming it out

edgy pilot
surreal path
#

yea

edgy pilot
#

and no mention of invlpg?

surreal path
#

yep

edgy pilot
#

can you send the binary

surreal path
#

sure

hollow goblet
#

people on the rust server are not bad osdevers

#

there's serious stuff going on there :3

surreal path
#

@edgy pilot

finite summit
#

lemme look at that

cinder plinth
hollow goblet
cinder plinth
#

No idea what that is

finite summit
#

damn no invlpg

cinder plinth
#

Wasn't able here

#

if that's their os

hollow goblet
#

he was here at some point

#

no idea if able is still here

finite summit
thorn bramble
#

not even osdev

hollow goblet
thorn bramble
#
czapek@raptor-wsl:~/wow$ rustc -o test.o test.rs --target x86_64-unknown-none
czapek@raptor-wsl:~/wow$ objdump -d test.o

test.o:     file format elf64-x86-64

czapek@raptor-wsl:~/wow$ cat test.rs
#![no_std]
#![no_main]

pub extern "C" fn _start() -> ! {
        unsafe {
                core::arch::asm!("invlpg [rax]");
        }
        loop {}
}

#[panic_handler]
fn panic_handler(_: &core::panic::PanicInfo) -> ! {
        loop {}
}```
#

what is rustc doing

hollow goblet
#

my and repnop are the only risc-v rust osdevers that I am aware of

thorn bramble
#

or what am i doing...

edgy pilot
thorn bramble
#

yeah im wrong hold up

surreal path
thorn bramble
#

i dont think i can objdump an object file like that

surreal path
#

PageMap::unmap

hollow goblet
edgy pilot
surreal path
#

no

#

dev mode

#

this may be a rustc bug actually

#

to be fair

thorn bramble
#

doubt

hollow goblet
#

this wouldn't be optimised out in dev mode

surreal path
#

idfk ???

finite summit
#

why doesn't unmap exist in my objdump

hollow goblet
#

is invlpg different in at&t and intel syntax?

edgy pilot
thorn bramble
hollow goblet
surreal path
thorn bramble
#

rust asm uses intel syntax

surreal path
#

so optimizations should be disabled

hollow goblet
#

is that correct intel syntax for invlpg

thorn bramble
#

yes

edgy pilot
#

yes

finite summit
thorn bramble
#

invlpg takes a memory operand

surreal path
thorn bramble
#

so [reg] should be fine

edgy pilot
hollow goblet
#

oki

surreal path
#

guess what chat

#

i fixed it

hollow goblet
#

@surreal path can I see your linker script

surreal path
#

now it DOES invlpg

finite summit
#

NyauxKT::PageMap::unmap doesn't exist either

surreal path
hollow goblet
#

what was it

thorn bramble
#
czapek@raptor-wsl:~/sources/zig-kernel$ objdump -d kernel/zig-out/bin/kernel | grep invlpg
ffffffff80000040:       0f 01 3c 25 00 00 00    invlpg 0x0```
#

yay good language

surreal path
#

zig pro

#

so it does invlpg

thorn bramble
#
asm volatile("invlpg 0");```
hollow goblet
finite summit
#

yay good language

surreal path
#

i see why it doesnt page fault lmao

finite summit
#

(assembly)

cinder plinth
surreal path
#

i wrote the pte to be 0

thorn bramble
#

??

surreal path
#

yea stupid ik

thorn bramble
#

?????????????

edgy pilot
surreal path
hollow goblet
#

lmao

surreal path
#

lmao

thorn bramble
#

this guy makes me wanna quit life

hollow goblet
#

yea as normal it's just a human error

surreal path
hollow goblet
thorn bramble
#

ill name drop u on my goodbye note

surreal path
#

๐Ÿ˜ญ

#

โ˜ ๏ธ

hollow goblet
thorn bramble
#

/s

hollow goblet
#

my first osdev attempt was just following phil-opp's blog

thorn bramble
#

same

#

lol

hollow goblet
#

then I wrote stuff for ableos

thorn bramble
#

its kinda shit

finite summit
#

my first osdev attempt was... questionable

surreal path
#

yea

hollow goblet
#

the work done around that community (the rust-osdev github org

thorn bramble
#

its basically like

hollow goblet
#

is not actually bad

thorn bramble
#

"go use this crate lololol"

hollow goblet
#

true but

#

they improved the ecosystem

edgy pilot
hollow goblet
#

like thanks to them x86_64-unknown-none is stabilised

#

they were attempting real mode rust at some point

#

all the ${cpu_architecture} crates are inspired by their x86_64 crate

#

and they are good crates

surreal path
#

wait shouldnt u set the pte to 0? i know this is wrong but i am not understanding WHY its wrong, ur setting everything to 0?

#

including the present bit

#

so shouldnt the mmu not complain

thorn bramble
#

wtf is it complaining about to u

surreal path
#

not complaining

#

as in

#

it shouldnt be mapped anymore

thorn bramble
#

tlb exists

#

but its not mapped anyone

#

but if it exists in the tlb it will still be "mapped"

hollow goblet
#

did you set cr3 if you're creating a new page table

hollow goblet
#

and did you do the invalidation stuff correctly

surreal path
#
pub fn unmap(&self, va: usize) {
        let him = unsafe { Self::find_pte(self.rootpagetable as usize, va) };
        if let Some(h) = him {
            *h = 0;

            unsafe {
                let mut fake: usize;
                core::arch::asm!(
                    "invlpg [{0}]",
                    "mov {1}, 5",
                    in(reg) va,
                    out(reg) fake,
                    options(nostack)
                );
                println!("{}", fake);
            };
        } else {
            println!("not found");
        }
    }
hollow goblet
#

sorry I don't remember x86 enough

thorn bramble
#

; after unsafe block makes me cry

hollow goblet
#

that fake variable makes me cry

surreal path
#

yea so why isnt it unmapping hmmmm

thorn bramble
#

did you verify

#

that

edgy pilot
#

It is unmapping

thorn bramble
#

the INSTRUCTION

edgy pilot
#

probably

thorn bramble
#

is EXECUTED

surreal path
#

i had objdump'd invlpg is executed

hollow goblet
#

you should really learn to use a debugger

thorn bramble
#

wow it magically fixed itself

hollow goblet
#

objdump doesn't tell you it executed

#

it tells you it is in the binary

thorn bramble
#

rustc goated

surreal path
#

ill pull up my debugger

hollow goblet
#

gdb or lldb

surreal path
#

i use gdb

hollow goblet
#

ok

#

i was expecting you to pull up windbg or something

surreal path
#

i know how to use a debugger

edgy pilot
thorn bramble
#

i don't even know how to use a debugger beyond breakpoints and reading memory

surreal path
thorn bramble
#

the totally legit copy of IDA Professional 9.0โ„ข๏ธ

hollow goblet
#

step/stepi/next/nexti/finish/br/delete breakpoints/i/p

edgy pilot
hollow goblet
#

all you need to know tbh

surreal path
#

yep it got executed

#

invlpg did

edgy pilot
#

then what's the problem

surreal path
#

idfk ??

edgy pilot
#

move on

surreal path
#

wdym

#

i need unmap to work

edgy pilot
#

if there's no problem, why are you still debugging it

surreal path
#

if it isnt page faulting

edgy pilot
surreal path
edgy pilot
#

maybe add a sleep() or a few pauses between invlpg and trying to write

surreal path
#

what does that even do

edgy pilot
#

idk maybe it needs some time to think lmao

surreal path
#

ah yes meme

#

okay im not gonna worry and move on

#

im doing everything correct so

#

if the cpu chooses to listen or not

#

not my business

#

anyways gonna add vmm_region_alloc into my global allocator and yea

#

anyways vmm done

kind root
surreal path
#

i love giving ppl brainrot

edgy pilot
surreal path
edgy pilot
#

no

surreal path
#

why

edgy pilot
#

you don't need it yet

thorn bramble
#

why do you need it

surreal path
#

uhhhh

thorn bramble
#

exactly

edgy pilot
#

you don't

surreal path
#

heap stresstest meme

#

lol

thorn bramble
#

that's a good damn point

#

but no

surreal path
#

then what should i do next

edgy pilot
#

interrupts

surreal path
#

i already have

edgy pilot
#

I mean timer and a scheduler

finite summit
#

irq interface

#

for your drivers

edgy pilot
#

no drivers yet lol

surreal path
#

lol

finite summit
#

so?

edgy pilot
#

too early for that

surreal path
finite summit
#

it's too late for a scheduler

#

if I'm being honest

edgy pilot
#

why not

finite summit
thorn bramble
#

the most important part

#

of any kernel

surreal path
#

fair

finite summit
#

a wise man told me to have a scheduler asap when I start my kernel

thorn bramble
#

i started with a memory manager

elder shoal
#

scheduler is what I do after I do memory management

surreal path
#

start with a scheduler

elder shoal
#

you just have to not have the scheduler depend on the memory manager

finite summit
surreal path
#

funny

hollow goblet
thorn bramble
finite summit
#

I didn't have an allocator until a week after I start dev on my current kernel

hollow goblet
#

what my kernel does rn

#

parse fdt

#

scheduler

#

pmm

#

has code for mapping pages but unused

finite summit
#

but I had a scheduler within the first 5 days

thorn bramble
#
pub export fn _start() callconv(.C) noreturn {
    arch.disableInterrupts();
    arch.serial.initialize(0x3f8);

    const hhdm_response = hhdm_request.response.?;
    const kernel_address_response = kernel_address_request.response.?;
    const memory_map_response = memory_map_request.response.?;
    const smp_response = smp_request.response.?;

    bsp_cpu_info = .{
        .arch_cpu = arch.cpu.ArchCpuInfo.init(smp_response.bsp_lapic_id),
        .idle_thread = &bsp_idle_thread,
    };

    bsp_cpu_info_block = .{
        .cpu_info = &bsp_cpu_info,
        .current_thread = &bsp_idle_thread,
    };

    arch.cpu.setCpuInfoBlock(&bsp_cpu_info_block);
    arch.cpu.initializeCpuEarly(&bsp_cpu_info);

    // ...
}```
#

literally what my kernel does at the start

thorn bramble
#

hi

surreal path
#

pull me out

#

i cant breath

thorn bramble
#

nahj u stay in there

surreal path
finite summit
#

what my kernel does at the start is initializes the gdt and idt, then initailizes the scheduler

thorn bramble
#

my walls are paper thin

elder shoal
#

astral does this

void kernel_entry() {
        cpu_set(&bsp_cpu);
        logging_init();
        logging_sethook(arch_e9_putc);
        arch_gdt_reload();
        arch_idt_setup();
        arch_idt_reload();
        dpc_init();
        pmm_init();
        term_init();
        logging_sethook(term_putchar);
        arch_mmu_init();
        vmm_init();
        alloc_init();
        cmdline_parse();
        acpi_early_init();
        arch_apic_init();
        timekeeper_early_init(0);
        cpu_initstate();
        arch_apic_timerinit();
        sched_init();
thorn bramble
#

my initializeCpuEarly sets up gdt and idt

surreal path
#

or the floorboards

thorn bramble
#

after that i initialize my memory manager and start up other cores

finite summit
surreal path
hollow goblet
#
#[no_mangle]
unsafe extern "C" fn _start() -> ! {
    HHDM_OFFSET.store(HHDM_REQUEST.get_response().unwrap().offset() as usize, Ordering::Relaxed);
    crate::memory::alloc::init(INITIAL_KERNEL_HEAP_START, INITIAL_KERNEL_HEAP_SIZE);
    crate::memory::pmm::init(MM_REQUEST.get_response().unwrap().entries());

    // Get a DTB and parse it, then discover devices
    // This also sets the serial console.
    let dtb_response = DTB_REQUEST.get_response().unwrap();
    let dtb = dtb_response.dtb_ptr();
    let fdt = fdt::Fdt::from_ptr(dtb.cast()).unwrap();
    crate::fdt::discover_devices(&fdt);

    log::info!("Hello serial console!");

    // CHECK FOR LIMINE RESPONSES

    log::info!("Initialising hart context");
    // ALLOCATE 4 PAGES FOR KERNEL STACK
    // HART CONTEXT INITIALIZE

    log::info!("Initialising trap handler");
    trap::init();

    log::info!("Initialising scheduler");
    crate::scheduler::init();

    THREAD1 = crate::scheduler::create_kernel_thread(thread1);
    crate::scheduler::create_kernel_thread(thread2);

    log::info!("Enabling interrupts");
    interrupts::enable();

    loop {
        wfi();
    }
}

static mut THREAD1: *mut crate::thread::Thread = core::ptr::null_mut();

fn thread1() {
    log::info!("hello from thread1 :S");
    log::info!("blocking thread1 :O");
    crate::scheduler::block(crate::thread::ThreadState::Paused);
    log::info!("hello again from thread1 :3");
    log::info!("terminating thread1 UwU");
    crate::scheduler::terminate();
}

fn thread2() {
    log::info!("hello from thread2 >:3");
    log::info!("unblocking thread1 from thread2 LoL");
    unsafe {
        crate::scheduler::unblock(THREAD1);
    }
    log::info!("terminating thread2 OwO");
    crate::scheduler::terminate();
}
surreal path
#

dpc*

hollow goblet
elder shoal
surreal path
hollow goblet
surreal path
#
A Deferred Procedure Call (DPC) is a Microsoft Windows operating system mechanism which allows high-priority tasks (e.g. an interrupt handler) to defer required but lower-priority tasks for later execution.
finite summit
#

what it does is it defers code execution until a later point in the kernel at a lower interrupt priority

surreal path
#

i see

finite summit
#

in obos they run at IRQL_DISPATCH

surreal path
#

not very unix like mathew

finite summit
#

when irql goes < IRQL_DISPATCH

thorn bramble
#

linux definitely has an equivalent

finite summit
#
OBOS_NO_UBSAN OBOS_NO_KASAN void Core_LowerIrqlNoThread(irql to)
{
    Core_LowerIrqlNoDPCDispatch(to);
    if (to < IRQL_DISPATCH && CoreS_GetCPULocalPtr())
    {
        CoreS_SetIRQL(IRQL_DISPATCH, to);
        *Core_GetIRQLVar() = IRQL_DISPATCH;
        CoreH_DispatchDPCs();
        *Core_GetIRQLVar() = to;
        CoreS_SetIRQL(to, IRQL_DISPATCH);
    }
}```
surreal path
#

linux is not real unix then

#

๐Ÿ˜ก

thorn bramble
#

its basically a per-cpu work queue

surreal path
#

linux is windows comfirmed

surreal path
hollow goblet
#

this thread is eating my brain

finite summit
# finite summit ```c OBOS_NO_UBSAN OBOS_NO_KASAN void Core_LowerIrqlNoThread(irql to) { Core...
OBOS_NO_UBSAN OBOS_NO_KASAN void CoreH_DispatchDPCs()
{
    // Run pending DPCs on the current CPU.
    for (dpc* cur = LIST_GET_HEAD(dpc_queue, &CoreS_GetCPULocalPtr()->dpcs); cur; )
    {
        dpc* next = LIST_GET_NEXT(dpc_queue, &CoreS_GetCPULocalPtr()->dpcs, cur);
        LIST_REMOVE(dpc_queue, &CoreS_GetCPULocalPtr()->dpcs, cur);
        cur->cpu = nullptr;
        cur->handler(cur, cur->userdata);
        cur = next;
    }
}```
hollow goblet
#

im gonna leave

elder shoal
surreal path
#

DONT LEAVE

#

we have snacks

#

not pro

thorn bramble
hollow goblet
#

don't ping me it makes me follow the thread

surreal path
#

but im a fellow rust user

hollow goblet
#

discord fix your app why can you ping random people and force them to follow the thread

surreal path
#

i will use nixstrap if u stay

finite summit
#

@discord fix

surreal path
#

๐Ÿ˜”

#

we lost a comrade today

hollow goblet
elder shoal
#

tasklets to be more specific it seems

surreal path
hollow goblet
#

yes

surreal path
#

pro gamer

#

๐Ÿ˜Ž

#

blackmail my favourite past time activity

#

anyways

#

time for scheduler

#

or whatever tf

#

ill do that after i eat me hungy

hollow goblet
#

port to nixstrap fr

#

should I release nixstrap

surreal path
#

yes

hollow goblet
#

ok gonna clean shit up

thorn bramble
#

please don't; use nixstrap

#

u dont ev en know fucking nix

#

this guy will never finish a project

#

istg

surreal path
#

chill

#

also how do u know i dont use nix

#

i lit used nixos a bunch of times lmao

#

tf

thorn bramble
#

i still doubt you know nix

surreal path
#

you doubt everything lmao

hollow goblet
hollow goblet
thorn bramble
#

cant wait for the 10 daily pings @ sanana

surreal path
#

what 10 daily pings

#

oh lmao ur talking abt me

thorn bramble
#

oh did i underestimate...

#

my bad

surreal path
#

pinging sanana

thorn bramble
surreal path
#

๐Ÿ˜ก

hollow goblet
#

tho i would not suggest using nixstrap with rust as your first attempt at using nixstrap

#

rust + nix + custom targets and build-std don't really add up well

#

it does work don't get me wrong

#

it takes a bunch of effort

surreal path
#

ok fair

#

hi fadanoid

hollow goblet
#

let's update my disko fork

#

that seemed to work

flat nymph
flat nymph
#

(my kernel still doesn't do tlb invalidation properly)

surreal path
#

oh yeah sorry im taking a break for like until weekend cause school is getting more stressful

#

sorry chat

#

but this is to avoid burn out

kind root
#

cya in two months

surreal path
#

bro

#

๐Ÿ’€

#

infy stop being

#

like actually ur being so fucking mean

#

stop

flat nymph
surreal path
#

its not funny anymore at this point

kind root
#

lol

#

im sorry

surreal path
#

thank you

kind root
#

cya on saturday

surreal path
#

nah friday

#

friday i have no school

#

๐Ÿ˜Ž

magic kernel
#

You got this

plush hearth
wicked loom
#

honestly i back infy on this

#

i bet you're going to disappear for months now

#

it has already happened like 3 times

#

idk why this one would be different

#

prove us wrong, i guess :p

surreal path
surreal path
#

lmao

#

im currently outside rn ill be back in a few hours eta 5pm irish time to work on nyaux

surreal path
#

alright

#

ready to start some work

#

im gonna do the uacpi first because i believe its just better to do so, i know yall disagree but its fine

#

good heap stress test anyway

surreal path
#

okay very fun

#

so after integrated uacpi

#

we got some issues

#

with the heap

#

okay more bugs

#

fun

#

this just happened

#

wtf is going on

#

now

#

lol

#

memory corruption!!

#

even tho im being "safe"

surreal path
#

CR2=ffffffff80001320

#

hmmm

#
fn slab_allocsearch(&mut self) -> Option<usize> {
        let mut h = &mut self.slabs;
        'outer: loop {
            println!("{:?}", h);
            if let Some(fre) = h.as_mut().unwrap().freelist.take() {
                h.as_mut().unwrap().freelist = fre.next.take();
                return Some(fre as *mut KTNode as usize);
            } else {
                if h.as_ref().unwrap().next_slab.is_none() {
                    println!("breaking out");
                    break 'outer;
                } else {
                    println!("{:#?}", h.as_ref().unwrap().next_slab);
                }
                h = &mut h.as_mut().unwrap().next_slab;
            }
        }
        println!("HELLLO???");
        let new = slab_header::init(self.size);

        let o = h.as_mut().unwrap().next_slab.take();
        println!("suc");
        if let Some(g) = o {
            new.next_slab = Some(g);
            h.as_mut().unwrap().next_slab = Some(new);
        } else {
            h.as_mut().unwrap().next_slab = Some(new);
        }
        let gethim = h.as_mut().unwrap().next_slab.take().unwrap();
        println!("{:#?}", gethim.freelist);
        gethim.freelist = gethim.freelist.as_mut().unwrap().next.take();
        let gg = gethim.freelist.as_mut().take().unwrap();
        return Some(*gg as *mut KTNode as usize);
    }
edgy pilot
#

make a scheduler first, then uacpi

surreal path
#

im gonna redo my slab allocator

#

with MaybeUnIt<T>

#
struct slab_header {
...
freelist: MaybeUninit<Option<&'static KTNode>>
...
}
#

because otherwise its ub

#

and the compiler can do whatever the hell it wants

#

it optized prev out

#

causing dumb issue

#

lol

#

thanks to @glossy walrus for the suggestion

#

tho i dont think theres anything wrong with the 'static lifetime

#

the ktnode is going to live for the entirety of the kernel when its in the freelist

surreal path
#

okok my brain is dying

#

trying to figure out how to right this slab allocator properly

#

hmm

#

the mad lads at rust community server told me to use raw pointers

#

in this context it is SAFE

#

Option<NonNull<T>>

#

they told me to do

hollow goblet
#

raw pointers are always safe they obey the same rules as references

#

just you're supposed to uphold those rules instead of the compiler

#

the unsafe part is reading from and writing to the raw pointers

surreal path
#

i get you

hollow goblet
#

sigmas know i'm skibidi now

surreal path
#

lmao

#

i should talk in the rust server more they are so helpful

surreal path
#

slab allocator nearly done

#

just working on the last few functions then

#

we will have slab allocator that isnt UB

#

thanks to the RUST server for guiding me on how to create no UB

surreal path
#
fn slab_allocsearch(&mut self) -> Option<*mut u8> {
        let mut h = &mut self.slabs;
        for i in h.iter_mut() {
            
            unsafe {
                if let Some(friend) = (*i.as_ptr()).freelist {
                    (*i.as_ptr()).freelist = (*friend.as_ptr()).next;
                    return Some(friend.as_ptr().cast::<u8>());
                }
            }
        }
        None
#

this is good rust code according to them lol

surreal path
#

i have tracked down the issue to my slab_header init

#

solved it

#

enabling strict provence is the best thing ive ever done

#

no more UB

#

cause the compiler errors out if theres some ptr to int to ptr cast

#

๐Ÿ˜Ž

#

@finite summit what is ur opinion on this information

surreal path
#

๐Ÿ˜Ž

surreal path
#

fun

#

uacpi page faults on kvm

#

and non kvm runs out of memory

#

why does the curse always follow me

#

why tf is parent 0x0

#

why is out_obj 0x0

#

why is args 0x0

#

wtf

kind root
#

the cause is wrong also

surreal path
#

wdym

kind root
#

LOAD_CAUSE_INIT is whats passed

surreal path
#

UACPI_TABLE_LOAD_CAUSE_LOAD_OP

#

yea

#

wtf is happening

#

UACPI_TABLE_LOAD_CAUSE_INIT

kind root
#

memory corruption

#

probably

#

who knows

surreal path
#

fucking hell

kind root
#

like literally

#

look at uacpi.c:438 there

#

u get bogus args somehow

surreal path
#

yea

#

all the addresses i give to uacpi

#

their sizes too

#

could it be my vmm region

#

i mean

#

it looks fine

#

WHY AM I ALWAYS CURSED

#

RAHHHH

#

changing between dev and release mode doesnt change anything, in tcg it works fine (only runs out of memory cause i didnt make free function yet) but kvm it page faults

#

cr2 is 0

#

as u'd except

surreal path
#

not pro gamer

surreal path
#

still debugging this

#

not fun

#

im losing my mind

kind root
#

I'm used to a lot more verbose debugging sessions

finite summit
#

nyaux thread almost at 23000

surreal path
#

anyways i think i found the function at fault

#

slab_allocsearch is doing something rlly weird

#

i just need to find where

#

and we gucci

surreal path
#

anyways i have school tmrw

#

i must sleep now

#

goodnight chat

steady flume
#

good night nyaux :3

kind root
#

good morning nyaux

#

back to work NOW ๐Ÿ˜ก

surreal path
finite summit
#

Get a laptop and setup rustc

surreal path
#

also

#

school nearly finished but i have tennis practice after this

#

ill be back around 8pm

surreal path
#

im back

surreal path
#

@kind root im back to work

#

im gonna write some unit tests

#

maybe it'll show me whats going on

kind root
#

nice

surreal path
cinder plinth
#

which language are you using now

surreal path
cinder plinth
kind root
surreal path
#

one thing i found out

#

its not an alignment issue

#

i cant get unit tests working

#

so

#

im just gonna ball and not care

#

actually wait

#

i can do something brb

#

wait

#

i will read the source code of linux about this

surreal path
#

@kind root I GOT UNIT TESTS WORKING

surreal path
#

@kind root ```rs
running 1 test
thread 'mem::pmm::h' panicked at src/mem/pmm.rs:348:9:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0xffffffffffffffff
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
error: test failed, to rerun pass --lib

Caused by:
process didn't exit successfully: /home/rayan/NyauxKT/kernel/target/x86_64-unknown-linux-gnu/debug/deps/NyauxKT-207c79480958aa03 (signal: 6, SIGABRT: process abort signal)

look what i found
#
extern crate std;
    extern crate libc;
    assert_eq!(1, 1);
    let data: *mut u8 = unsafe {
        libc::mmap(0 as *mut c_void, 4096, libc::PROT_READ
        | libc::PROT_WRITE, libc::MAP_ANONYMOUS, 0, 0) as *mut u8
    };
    let it = NonNull::new(unsafe {
        data
        as *mut slab_header
    }).unwrap();
    unsafe {
        (*it.as_ptr()).obj_size = 16;
    }
    let obj_amount = (4096 - size_of::<slab_header>()) / 16;
    let start = unsafe {it.add(1).cast::<um>()};
    let mut prev = start;
    for i in 1..obj_amount {
        unsafe {
            let new = start.byte_add(i * 16);
            (*new.as_ptr()).next = None;
            (*prev.as_ptr()).next = Some(new);
            prev = new;
        }
        
    }
    unsafe {
        (*it.as_ptr()).freelist = Some(start);
    }
    unsafe {
        if let Some(friend) = (*it.as_ptr()).freelist {
        (*it.as_ptr()).freelist = (*friend.as_ptr()).next;
        
        let bro = friend.as_ptr().cast::<u8>();
        
    }
    }
#

my test

surreal path
#

i think

#

or maybe i have the wrong thigns to mmap

#

hey: 0xffffffffffffffff

#

oh

#

let data: *mut u8 = unsafe {
libc::mmap(0 as *mut c_void, 4096, libc::PROT_READ
| libc::PROT_WRITE, libc::MAP_ANONYMOUS, 0, 0) as *mut u8
};

#

mmap is giving me

#

0xfff

cinder plinth
#

that's just -1

#

so it failed

surreal path
#

why???

#

๐Ÿ˜”

#

WHY TF DID IT FAIL

#

๐Ÿ˜ญ

#

nvm i solved it

#

it works fine

#

@kind root

#

it failed !

kind root
#

congrats

surreal path
#

fun right

#

im trying to attach a debugger

surreal path
#

well another step closer @kind root

#

we can debug this further tomrw

#

i have to sleep i have school

kind root
#

Good luck

frigid cliff
thorn bramble
#

h

surreal path
#

๐Ÿ˜ญ

#

i had to go sleep after

surreal path
#

chat i dont think i can code today i have an exam to study for