#Nyaux

1 messages ยท Page 26 of 1

surreal path
#

where

finite summit
#

you just make them yourself

surreal path
#

bru

finite summit
#

iterators?

#

who needed that.

spice yarrow
#

Making closures in c is weird

finite summit
#
for (size_t i = 0; i < arr.size; i++)
  // do shit
finite summit
#

therefore argument invalid

surreal path
#

i hate dealing with "strings" in C

spice yarrow
#

iterators are way nicer than for loops

surreal path
#

i legit hate

#

it

finite summit
surreal path
#

one of my biggest reasons why i struggle

cinder plinth
spice yarrow
#

You can... you just gotta pass around both a function pointer and a data pointer

#

But it is kinda cursed

surreal path
#

look im just not gonna switch language and keep banging my head againist the wall until everything works

#

even if it takes years

#

because it wont matter what language i use

#

im just a horrible programmer in general

#

plus i havent used C/C++ in a long time

spice yarrow
finite summit
#

I have

surreal path
#

idfk

finite summit
#

I used c++ for the longest time

cinder plinth
#

you didnt do nice rusty C++ iterators

#

I have

#

and they're nice

spice yarrow
#

Rust iterators are amazing

#

It's like a data processing pipeline

cinder plinth
#
    auto v2 = s.iter().rev().collect<std::vector<int>>();
#

๐Ÿ˜‹

finite summit
#

what happens if something crashes in there

#

what would the stack trace be like

cinder plinth
#

depends where

#

but would probs be something like

#

iter::rev() -> Slice::iter() -> main

finite summit
#

anyway, I use C and I will not fall into these language features

spice yarrow
#

there's not a lot of ways stuff can crash in an iterator unless you explicitly use unwrap or something

cinder plinth
#

yeah

#

they cant rlly fail

#

the only thing I could think of is with fixed arrays

#

like

#

well

#

smallvec

#

which is a vector with a fixed limit

finite summit
#

I remain content with my for loop.

spice yarrow
#

I mean smallvec ran out of space is simple enough to figure out

#

Also in rust you don't even need backtraces much, which is why they are disabled by default

cinder plinth
#
Array<int, 10> array;
array.iter().collect<SmallVec<int, 5>>();
#

this'll just panic

#

I could maybe make my Container trait require push_back returns a Result<> but that would break stl containers

thorn bramble
#

lol โ€œiteratorsโ€

#

ur a funny guy

#

silly fella arenโ€™t u

kind root
#

wdym lol

thorn bramble
#

he said that right as he said he hates rust, so i think he expects a bit more than an operator++ wrapper

edgy pilot
#

C++ has ranges

thorn bramble
#

i mean sure, you can probably write some crazy shit with the new views stuff, i havenโ€™t looked into that exactly

#

or ranges..?

edgy pilot
#

same thing

#

they do more stuff

thorn bramble
#

i winder how the codegen is compared to rust iterators :^)

#

iirc they are optimized pretty heavily in rust

thorn bramble
#

eh i cba writing anything more complex in rust and rewriting it in c++ with apis that i dont know lmao

#

especially on phone :โ€™)

edgy pilot
#

write a rust one and I'll provide the C++ version

thorn bramble
#

actually i could just chatgpt that shit

edgy pilot
thorn bramble
#

but yeah ill see once i get on my pc lol

spice yarrow
# edgy pilot write a rust one and I'll provide the C++ version

I really wanna see if you can do this in c++ https://docs.rs/uom/latest/uom/

cinder plinth
#

I don't see why not

#

in fact, it'd probs be easier to do in C++

#

just a bunch of operator overloads

flat nymph
#

Why are they stupid?

cinder plinth
#

they're not but you shouldnt use them most times

edgy pilot
#

yeah just operator overloads

#

something like

Velocity operator/(Distance, Time)
Distance operator*(Time, Velocity)
#

there's already std::chrono for time

#

velocity and distance can be simple classes

cinder plinth
#

yea

spice yarrow
#

It's not that simple, it's generic for every possible si unit

cinder plinth
#

you use concepts then

#

(which are like traits)

edgy pilot
spice yarrow
#
mul<L1, M1, T1, L2, M2, T2>(x: Unit<L1, M1, T1> y<L2, M2, T2>) = Unit<L1 + L2, M1 + M2, T1 + T
2>
edgy pilot
#

that's overcomplicated imo

#

you would do the same thing chrono does

#

just have different constructors for si units in Distance and Velocity classes

#

and use metres and m/s as internal storage

#

then do operations on them

#

and have operator overloads for conversions

#

ezpz

spice yarrow
#

Right, but what if I need to use something like m^3 * kg^-1 * s^-2

#

In my example above, Distance would be an alias for Unit<1, 0, 0> and Velocity would be Unit<1, -1, 0>

spice yarrow
#

okay apparently it's actually really easy

template <int L1, int M1, int T1>
template <int L2, int M2, int T2>
Unit<L1 + L2, M1 + M2, T1 + T2>
Unit<L1, M1, T1>::operator*(Unit<L2, M2, T2> const &other) {
    return Unit<L1 + L2, M1 + M2, T1 + T2>(this->value * other.value);
}
cinder plinth
#

I love templates

#

๐Ÿ˜‹

edgy pilot
#

I don't quite understand what you're doing

spice yarrow
#

I can't store the result of that without either hardcoding a ton of units or creating a generic unit type

edgy pilot
#

oh yeah then have another class Unit

spice yarrow
#

Right, then Distance can just be an alias for Unit<1, 0, 0>

edgy pilot
#

yep

spice yarrow
#

And you can have a distance_from_feet and other functions

edgy pilot
#

or just have every operator overload return numerical values

#

no more need for templates meme

spice yarrow
#

Yeah but then you don't get the automatic dimensional analysis

edgy pilot
#

simple wrapper over a number that stores that extra information

#

I need to try to implement it first to know if it will work or not

surreal path
#

:3

#

anyways ill just debug this problem after i uh

#

finish eating

#

which is gonna be like

#

a while lmao

#

we are outside at kfc!!!

#

imagine

surreal path
#

ummm might not be able to get any work done today :c, dad taking away all my devices cause of me skipping school for osdev

#

๐Ÿ˜”

edgy pilot
#

you shouldn't be skipping school for osdev

#

you shouldn't be skipping school at all, unless your ill

#

or depressed

surreal path
#

im also depressed

#

soo

edgy pilot
#

Personally, I wouldn't be able to work on an os in that case

#

and I am not able to

surreal path
#

i got closer, used .mask instead of .mask_with()

#

seems like a garbage addr

#

.mask does &

#

.mask_with allows u to do whatever operation u want

#

its good we are closer

#

i still have to figure this out tho

#

i got my devices back (yippie!)

#

but my dad is putting a time limit on my laptop for the time being

#

๐Ÿ˜”

surreal path
#

i am determined to make bash run on nyaux one day !!

surreal path
edgy pilot
#

don't skip school

surreal path
rigid fable
tender gorge
#

skip school -> 24 hr osdev mute meme

surreal path
#

lol

#

okay seems valid here

#

found it

#

okay so this bitmask is just wrong, its not

thorn bramble
#

whatever .map_addr is

#

ah smart!

#

let me take the virtual address of the pte

#

i don't think that's how this works man...

surreal path
thorn bramble
#

no?

surreal path
#

okay so whats the issue???

thorn bramble
#

read ur frickin code

#

????????

#

tell me

#

WHAT IT DOES.

surreal path
#

i cast pt

thorn bramble
#

pt = entry.map_addr(|a| a & ...)

surreal path
#

into a *mut u8

thorn bramble
#

what does this do

#

do you know

surreal path
#

yes

thorn bramble
#

what that mask is?

surreal path
#

yes

thorn bramble
#

0x000f_ffff_ffff_f000

#

what is it

surreal path
#

i want to get the next table

elder shoal
thorn bramble
#

what is it masking here

surreal path
#

to get the physical address to the next table

elder shoal
#

:dream:

thorn bramble
#

READ THE ENTRY

surreal path
#

I AM READING THE ENTRY

thorn bramble
#

DONT MASK THE FUCKING PTE POINTER

#

DO YOU EVEN KNOW WHAT MAP_ADDR DOES?

#

RTFM

#

UR CREATING INVALID POINTERS

elder shoal
#

iretq is going joker mode

thorn bramble
#

UR MASKING OUT TOP 12 BITS

#

OFF THE ADDRESS

#

SO IT BECOMES

#

0x000f800000000000

surreal path
#

OKAY THEN WHAT AM I SUPPOSED TO USE

thorn bramble
#

jkoefaKLPFGMWERsjkpgBRKRsKR

#

'GKRSRS

#

adfs

#

sf

#

sorry

#

i told u

#

already

#

Read the PTE.

#

THEN mask.

surreal path
#

OHHH

thorn bramble
#

.

surreal path
#

fucking idiot i am

thorn bramble
#

.

#

.

#

.

#

.

jaunty hingeBOT
#
Anti-spam Message

Possible spam detected for user: wre4sfterwsfd. Please contact a moderator to be unmuted.

surreal path
#

bru

#

๐Ÿ˜ญ

#

someone unmute him

#

@elder shoal

elder shoal
#

.!unmute @thorn bramble

jaunty hingeBOT
#

Unmuted @thorn bramble

thorn bramble
#

I FORGOT THIS DAMN BOT EXISTED

surreal path
#

๐Ÿ˜ญ

elder shoal
#

I feel like yorue gonna have a fucking breakdown at this rate ๐Ÿ˜ญ

thorn bramble
#

Bro has read the docs.

#

bold of you to assume i haven't already had two of those

surreal path
#

okay ill read the docs next time before even using any rust function

#

not just glancing at the vscode

thorn bramble
#

me trying to peacefully go to bed

#

meanwhile:

surreal path
#

๐Ÿ˜ญ ๐Ÿ˜ญ

thorn bramble
#

bro is creating non canonical pointers

#

sorry mods

#

for my subpar behavior

surreal path
#

IT WORKS

#

IT FUCKING WORKS CHAT

#

FUCKING

#

WORKS

thorn bramble
#

who would have thought...

surreal path
#

lets check

#

if the uacpi gdb bug is still there

#

@molten grotto ITS STILL FUCKING

#

DOING THIS

thorn bramble
#

well.. set the kernel api, would you?

#

:)

surreal path
#

I DID

thorn bramble
#

i dont see a reason why this would happen only under gdb

surreal path
surreal path
#

and through gdb i found out it was my vmm

#

so i fixed that

#

and its STILL doing this

thorn bramble
#

does it happen without gdb?

surreal path
#

no

thorn bramble
#

lol

surreal path
#

it runs like

#

perfectly fine

rigid dust
#

wait chat active

surreal path
#

lit perfectly fine

surreal path
rigid dust
#

nothing

#

just looked in

surreal path
#

ok

#

BRO

#

okay nvm

#

it doesnt run fine

#

UB

thorn bramble
#

objdump -d kernel | grep '800002c0:'

#

?

#

u can addr2line that too i guess

#

and figure out what it is

surreal path
#

theres no ub

#

here

#

wtf

#

and addr2lines rip

thorn bramble
#

like u know that

surreal path
#

doesnt taking me anywhere

thorn bramble
#

fun

#

good luck!

surreal path
#

lovely

thorn bramble
#

i mean i cant help much so thats all i can say

surreal path
#

i found where its

#

doing that

#

@kind root

#

do you know whats going on

#

im reading the object dump and like

#

idfk know whats going on

#

ud2 is called a bunch in uacpis own code too

#

the rip points to nothing

#

its my PMM

#

i knew this day would come

edgy pilot
#

don't ghost ping

surreal path
#

sorry

#

SORRY WHAT

#

it ud2s here???

#

fun

#

okay on release

#

it page faults on vmm_region_alloc

#

and on

#

debug

#

it ud2s

#

kill me

#

genuinelly

#

how does this code cause ```rs
let mut store: Option<&mut VMMRegion> = None;
for (idx, i) in self.head.iter_mut().enumerate() {
if store.is_none() {
store = Some(i);
continue;
}
let temp = store.unwrap();

        if i.base.wrapping_sub(temp.base + temp.length)
            >= align_up(size as usize, 4096) as usize + 0x1000
        {
            let new_guy = VMMRegion {
                base: temp.base + temp.length,
                length: align_up(size, 4096),
                flags,
                iskernel: false,
            };

            let amou = align_up(size as usize, 4096) / 4096;
            for i in 0..amou {
                let data = {
                    let o = pmm_alloc().unwrap() as *mut u8;
                    unsafe {
                        o.add(HHDM.get_response().unwrap().offset() as usize)
                            .write_bytes(0, 4096);
                    }

                    o
                };
                self.map(
                    data.addr(),
                    new_guy.base + (i * 0x1000),
                    new_guy.flags.bits(),
                );
            }

            let h = core::ptr::with_exposed_provenance_mut::<u8>(new_guy.base);
            unsafe { h.write_bytes(0, new_guy.length) };

            self.head.push(new_guy);

            return Some(h);
        } else {
            store = Some(i);
            continue;
        }
    }
UB
#

page fault non present of course

#

im losing my mind

#

i wanna die

#

chat

flat nymph
#

Probably just stop sprinkling unsafe everywhere

surreal path
#

๐Ÿ’€

spice yarrow
#

He's right

#

Avoid unsafe where possible

desert haven
#

Wheres the fun in that

#

But they are right

spice yarrow
#

If you're gonna write unsafe everywhere just write c

flat nymph
#

You're kinda supposed to abstract/encapsulate it

silk wind
#

The channel said one ping the inbox says no ping :/

kind root
#

because the message was deleted probably

surreal path
#

i pinged u earlier

surreal path
#

also sorry chat

#

no work for today

#

i feel awful

#

im sick :c

thorn bramble
#

get better

#

and get back on the nyaux grind with a clear mind :^)

desert haven
#

agreed, rest up and take care of yourself first ๐Ÿ™‚

plush hearth
wicked loom
#

he didn't wanna be

plush hearth
#

That makes sense

frigid cliff
#

Works every time

surreal path
#

still sick

#

ill be on that nyaux grind when we no longer sick

#

also theres like a storm going on here

#

lmao

surreal path
#

OKAY WE MIGHT BE ABLE TO GET SOME WORK DONE TMRW

#

IM STARTING TO RECOVER CHAT

#

IM SORRY ITS BEEN NEARLY A WEEK AT THIS POINT

#

ACTUALLY ITS BEEN A FEW DAYS BUT WHATEVS

cinder plinth
#

Nice

surreal path
surreal path
frigid cliff
surreal path
#

sorry chat been sleeping all day will be working after i take another nap

#

my sleep schedule is fgucked

#

๐Ÿ˜ญ ๐Ÿ™

surreal path
#

IM BACKKK

#

LES GOOOO

#

WOKR TIME

#

WHOOHOOOOHOOH

#

NYAUX GRIND

#

!!!!

#

okay

#

i have found two bugs

#

one related to

#

pmm _init

#

clearly some UB

#

and one related to

#

something else

#

bru

kind root
#

Least buggy nyaux snippet

surreal path
#

like wait

#

WHY IS THE CR2

#

FUCKING

#

THIS

#

WTF

kind root
#

Lmao

surreal path
#

oen sec im gonna print the hhdm

#

OKAY THATS SO WEIRd

#

PRINTING THE HDDM MAKES IT FINE

#

BUT WHEN NOT PRINTING

#

IT JUST

#

CRIES?

#

AND DOES SOME GOOFY AH SHIT

#

WTF

#

?????

edgy pilot
#

why not use a simple bitmap

surreal path
#

@kind root all the bugs im going through is most likely coming from the PMM itself

#

i need some kinda of equivent to std::launder

kind root
#

Its called C

surreal path
#

๐Ÿ’€

surreal path
#

okay even after

#

that

#

still getting the HDDM causes a opcode exception

#

fucking hell

#
ffffffff800045d0 <NyauxKT::mem::pmm::pmm_init::{{closure}}>:
ffffffff800045d0:       55                      push   %rbp
ffffffff800045d1:       48 89 e5                mov    %rsp,%rbp
ffffffff800045d4:       48 83 ec 10             sub    $0x10,%rsp
ffffffff800045d8:       48 89 7d f0             mov    %rdi,-0x10(%rbp)
ffffffff800045dc:       48 89 75 f8             mov    %rsi,-0x8(%rbp)
ffffffff800045e0:       48 8b 06                mov    (%rsi),%rax
ffffffff800045e3:       48 8b 38                mov    (%rax),%rdi
ffffffff800045e6:       48 83 c7 10             add    $0x10,%rdi
ffffffff800045ea:       48 c7 c6 00 18 06 80    mov    $0xffffffff80061800,%rsi
ffffffff800045f1:       e8 7a 00 00 00          call   ffffffff80004670 <<limine::memory_map::EntryType as core::cmp::PartialEq>::eq>
ffffffff800045f6:       24 01                   and    $0x1,%al
ffffffff800045f8:       48 83 c4 10             add    $0x10,%rsp
ffffffff800045fc:       5d                      pop    %rbp
ffffffff800045fd:       c3                      ret
ffffffff800045fe:       cc                      int3
#

disassembly looks like tis

#

this

surreal path
#

okay im using a debugger for this

#

rust people say the stack might be getting fucked or smthin

#

OKAY WTF

#

IT WORKS FINE ON GDB

#

yea okay

#

we are switching to C

#

im done

#

@finite summit u happy!!!!

#

nyaux rewrite #13

#

im not joking

#

rust aint for osdev

#

skill issue or not

#

idfk im switching to C, rust is fine as a userspace language but i love C for kernel development

#

๐Ÿ˜ƒ

finite summit
#

Yes

surreal path
#

now im gonna be straight honest its been a while for me with C but

#

im sure this wont be too big of an issue since i kept writing rust C like

#

๐Ÿ’€

#

btw what is a cc runtime

#

????

finite summit
#

Basically

surreal path
#

and libgcc provides what?

edgy pilot
#

"what is libgcc"

#

I was too slow

finite summit
surreal path
#

exception handling???

#

REAL???

#

yo what happened with C24

edgy pilot
#

there is no C24 lmao

#

it's c23

surreal path
#

what happened to it

edgy pilot
#

LMAO

surreal path
#

BRO

edgy pilot
#

they didn't cancel anything lmao

#

google c23

haughty kite
surreal path
#

ehh ill make my own kind of exception handling

#

ez

surreal path
#

okay we are so back

#

im gonna experiment with va lists rqrq in userspace C

#

brb

#

:)

surreal path
#

alr chat

#

compiling gcc

spice yarrow
surreal path
#

okay ive been experimenting with userspace C and ive got to say

#

UNIONS ARE SO FUCKING COOL

#

OMGOMGOGMOMG

#

I LOVE UNIONS

#

@finite summit do u love unions

#

i love unions

finite summit
#

I have used them in like 3 places

#

no more

surreal path
#

why

#

they are so cool

#

๐Ÿ˜ก

finite summit
#

useless

surreal path
#

bru

#

how

finite summit
#

literally no use for them

#

for most cases

surreal path
#

ill give u one use for them meme

#
typedef enum {
  FAIL,
  STRING,
  PTR
  CHAR
  FLOAT,
} Type;

typedef struct {
  Type type;
  union {
  char *str;
  void *ptr;
  char cha;
  float floa;
  }
} result;

result higuys() {
  result hi = {.type = CHAR, .cha = 'H'}
  return hi;
}
#

DONT TELL ME THATS NOT OCOL OBERROW

#

and the size would be like

#

super small cause as u know

#

unions only have one piece of memory and whatever variable u modify in a union changes that piece of memory

#

@finite summit if u dont write code u like ur missing out

finite summit
#

I've done that

#

that's like

#

the only time

surreal path
#

oh fair then otherwise unions are useless

rigid fable
#

finally

rigid fable
surreal path
#

they are funny funny hehehahah

rigid fable
#

thats all

surreal path
#

yea

#

ik

#

and they are cool

#

anyways TIME TO WRITE KERNEL CODE

rigid fable
surreal path
#

@kind root are u happy about this change

rigid fable
#

(and base 1 array indexing)

surreal path
#

ew

#

NAHHHH

#

EWWWWW

rigid fable
#

imagine doing vga_buffer[0] := 65; (or whatever) and it does not work

#

only to figure out it does
mov bx, 0xb7fff
mov al, 0x41
mov [bx], al

#

something like this

#

then I realized it was base 1 indexing

surreal path
rigid fable
#

that's what that assembly does

#

but the thing is, the vga_buffer variable was 0xb8000, for the text mode video memory

#

so index 1 is 0 so 0xb8000 and index 0 is -1 so 0xb7fff

surreal path
#

yo how do i make clangd stop with this goofy ah errors

#

wheres my lsp completeion

#

rahhh

finite summit
#

and given it a compile_commands.json

surreal path
finite summit
surreal path
#

okay how do i write a compile commands

#

what am i supposed to put in there

finite summit
#

there is some tool

#

called bear

#

idk how good it is

#

but it can make one for you

#

or if you're using cmake

surreal path
finite summit
#

you can't

#

there isn't some generic one

#

it is literally a list of all your files

surreal path
#

oh i see

finite summit
#

and how they would be compiled

#

github is being stoobid

surreal path
#

yea bear made one

#

yay

finite summit
#

I think that clangd assumes it is in $(project_root)/build/

surreal path
#

yea it did it

#

:)

finite summit
#

in any case

#

you can tell it what directory it is in

#

and do not put this on the git repo btw

#

--compile-commands-dir=

surreal path
finite summit
#

to clangd

surreal path
#

BEAR

#

OBERROW I AM A BEAR

wicked loom
#

bear is honestly one of the best tools

surreal path
#

ia gree

#

i am green

#

oh right its not in src

#

cool got flanterm and nanoprintf working

#

welp gdt time ez fr

elder shoal
#

nyaux c rewrite?

surreal path
#

yep

elder shoal
#

damn

surreal path
#

got tired of rust

#

the fucking UB shit

#

too much

#

we have been stuck for months with this hsit

#

bug after bug

#

its annoying

#

so like

#

time to actually get a real working operating system

wicked loom
#

based

surreal path
#

exactly

#

ok gdt done

#

idt next lol

#

now on github

#

idt time ig

#

lol

#

wait no actually the first thing im gonna do is extract my symbols for stack traces

#

just gonna translate the code from rust to C

#

should be easy considering i write rust C style

#

wait nvm

#

i need memory

#

so uhh idt first

#

then pmm -> page tables and vmm -> yk the drill

kind root
#

Lol

silver yarrow
edgy pilot
#

I have only used them in two cases:
classes where you can have either stack or dynamic buffer
structs where you want to access either bitfields or entire value

kind root
#

Oberrow L take

flat nymph
#

Why not C++? (instead of C)

surreal path
#

ok chat im gonna sleep some more

#

then we go on nyaux grind

#

chat i may have an addiction to sleeping

#

also my gf is staying over wit me rn and she doesnt want me out of bed rn

surreal path
kind root
#

Also ur like 13

surreal path
#

im 17

#

๐Ÿ’€

kind root
surreal path
#

very epic truly

surreal path
#

๐Ÿ˜ก

#

arent u like 20 somethin

#

idfk

elder shoal
kind root
hollow goblet
#

i miss her

green elbow
#

damn F's in the chat for sanana

kind root
surreal path
#

rip

#

working on IDt

#

IDT

#

just letting yall know

surreal path
#

does anyone have an assert macro i can use in C

#

like how do i get asserts going

#

in C

kind root
#

#define assert(x) do { if (!(x)) die(#x); } while(0)

rigid fable
#

it's literally the Limine template ๐Ÿ’€

#

and why is the gdt ptr struct not in the .h file thonk

surreal path
#

only gdt.c

surreal path
#

wtf

#

theres no assert

surreal path
#

fun my idt dies moment i try calling an interrupt manually

#

0xd

#

error code is 0x2

tawdry mirage
#

why are you rewriting it again

kind root
surreal path
tawdry mirage
#

now it's gonna be c ub instead

surreal path
kind root
surreal path
#

if yall say im gonna make UB

#

thats not even fucking funny

kind root
#

Every c kernel has some sort of ub

surreal path
#

yea but im not gonna make UB thats gonna make it not work

finite summit
#

use ubsan

#

I copy pasted some random kernels implementation

#

(I should probably add in the license now that I think of it)

#

((it was mit iirc))

surreal path
#

okay IDT works now

surreal path
#

or astral

#

or mangarm

#

wait managarm c++

elder shoal
#

managarm asserts the ub away halfmemeleft

surreal path
elder shoal
#

assert(ub == no)

surreal path
#

i will assert the ub way too

#

nyaux == managarm 2

#

@tawdry mirage what is ur opinion on this information

finite summit
#

wrong

#

it's the new windows

surreal path
#

anyone know of a spinlock library or somthin

#

i know barely anything about atomic shit and like

#

lol

cinder plinth
#

spinlocks are trivial

#

you basically just pause the cpu and you check for an atomic bool

spice yarrow
#

just lock.compare_exchange(FREE, HELD) in a loop until it is successful

#

There's more stuff that you can do but that's all that's needed

finite summit
#

use atomic flag

spice yarrow
#

Isn't that a c++ thing?

finite summit
#

note that you should have preemption disabled with syscalls held

finite summit
#

considering I use it in C from stdatomic.h

finite summit
#

*spinlocks

#

lol

#

idk why but when I use lock cmpxchg my syscalls go to shit

#

*spinlocks

#

goddamnit

finite summit
#

since I'm cool and use irqls I can raise the irql to IRQL_DISPATCH to stop scheduler preemption

#

but keep other irqs

#

๐Ÿ˜Ž

spice yarrow
surreal path
#

im not using rust anymore tho

#

lmao

#

this is C

#

didnt u hear the news

finite summit
spice yarrow
cinder plinth
#

based

surreal path
surreal path
cinder plinth
#

congrats

finite summit
#

I'll use clang-format soon, trust

cinder plinth
#

not just clang format

#

its just messy

finite summit
#

meh

#

there is some ifdef

#
irql newIrql = minIrql == IRQL_INVALID ? IRQL_INVALID : Core_GetIrql() < minIrql ? irqlNthrVariant ? Core_RaiseIrqlNoThread(minIrql) : Core_RaiseIrql(minIrql) : IRQL_INVALID;```
#

uh oh

surreal path
#

wtf is this

finite summit
#

dw about it lmao

surreal path
#

this shit makesm e wanna commit rewrite nyaux in assembly

finite summit
#

I am going to remove it since it is... questionable

cinder plinth
#
#define SPINLOCK_INITIALIZER 0

typedef int spinlock_t;

static inline void spinlock_lock(spinlock_t *lock)
{
    while (!__sync_bool_compare_and_swap(lock, 0, 1)) {
#if defined(__x86_64__)
        __asm__ volatile("pause");
#endif
    }
}

static inline void spinlock_unlock(spinlock_t *lock)
{
    __sync_bool_compare_and_swap(lock, 1, 0);
}

@surreal path

#

for free

spice yarrow
surreal path
cinder plinth
#

i didnt write it for you

surreal path
#

ill look up the functions being called here tho

cinder plinth
#

I wrote it a while back (or may have stolen it idk)

#

it's mostly just atomic stuff

surreal path
#

oh then free

cinder plinth
#

__sync_bool_compare_and_swap(lock, 0, 1) means if spinlock == 0, then spinlock = 1 and return 1

spice yarrow
cinder plinth
#

how can it fail

surreal path
#

assert os

#

ASSERT OS

cinder plinth
#

its literally setting a bool

spice yarrow
#

If you try to unlock a lock that's isn't held

cinder plinth
#

yeah but that wouldnt do anything

#

wouldnt break anything

spice yarrow
#

Yeah but if you ever try to do that something has gone very wrong

#

Maybe it's just me but I like to assert anything that's easy to check and shouldn't happen

kind root
#

Linux wont even boot at O0

spice yarrow
spice yarrow
#

Also, I feel like there should be kernels that run with both ubsan and kasan set to fatal

molten grotto
#

it does catch some things like if your stack is not properly aligned

spice yarrow
#

what stuff doesn't it catch?

molten grotto
#

eg. strict aliasing related things

#

and other obscure stuff like that

kind root
#

Aka most scary ub

wicked loom
#

i fear strict aliasing

#

which is why i disable it

molten grotto
#

same even tho its unlikely to cause any issues in practice I definitely do stuff that violates it and it wouldn't be fun to debug some random issues caused by the compiler taking advantage of it

surreal path
#

Sorry chat

#

No Iโ€™m

#

No um osdev for today

finite summit
#

hope all is well

surreal path
kind root
#

Wtf why

edgy pilot
#

bruh

#

why

#

and how

#

so I don't repeat it

surreal path
kind root
tender gorge
#

Hopefully you get the help you need, we're here for you if you want to talk

surreal path
#

look its fine, this isnt the place to talk about such stuff

#

lets just

#

get back on nyaux grind

#

should the pmm have a spinlock

#

its a basic freelist pmm as usual

cinder plinth
#

absolutely not fine, but whatever

#

and yeah you usually want a lock around that

surreal path
#

okay

cinder plinth
#

rule of thumb is if it's going to be accessed by someone else then you lock it

surreal path
#

use the lock

#

okay

cinder plinth
#

yea

#

you're modifying the list

surreal path
#

okay

upbeat turret
#

what did you invoke to trigger da interrupt

#

i wanna test

#

my interrupts

finite summit
#
int 3```
upbeat turret
#

as simply running asm("int $0":::); triple faults

finite summit
#

just maybe

#

your IDT is broken

upbeat turret
#

it's the handler

finite summit
#

so fix the handler

upbeat turret
#

that's broken

#

not the idt

#

the idt loads

finite summit
#

and you know that because you used a debugger to pinpoint that

upbeat turret
#

when i use lidt

finite summit
#

that means nothing

#

the cpu only looks at an idt descriptor when its specific ISR should be called

upbeat turret
#

ik

#

anyway can't fix it rn

#

focused on paging

#

then i'll re-do interrupts

#

oh shit

#

this is no where near related to nyaux

spice yarrow
surreal path
#

do -d int

#

when running qemu

upbeat turret
surreal path
#

do u save ur registers

#

show code

surreal path
#

dw

#

:)

upbeat turret
surreal path
upbeat turret
#

but yeah

#

i do save them

surreal path
#

show code

#

no code = no help

upbeat turret
#

registers rax-r15

surreal path
upbeat turret
#

they get pushed onto the stack

#

hmm one sec

#

lemme see if i can remember

spice yarrow
#

are you not looking at the code right now?

upbeat turret
finite summit
#

miracle debugging

upbeat turret
#

i lost it

finite summit
#

waiting until the code fixes itself

upbeat turret
#

stupid linux mint didnt save

finite summit
#

ewwwwwwwwwwwwww linux mint

#

๐Ÿคข๐Ÿคข๐Ÿคข

#

๐Ÿคฎ

spice yarrow
#

wdym it didn't save?

upbeat turret
#

i can explain

upbeat turret
#

idk

#

i created an idt.c file

spice yarrow
#

if you executed it then it had to have been saved

upbeat turret
#

and it just never saved

#

or idk what happened

surreal path
#

make a new idt

#

then

#

if it triple faults

#

show code

#

:')

upbeat turret
#

sure ig

finite summit
#

linux mint more like linux sour

upbeat turret
#

arch was quite fussy on my machine

spice yarrow
#

I mean the first one was broken, so maybe rewriting will fix it

finite summit
#

skill issue

#

just use debian :^)

upbeat turret
#

anyway

finite summit
#

wait why is my uptime 11 days lol

upbeat turret
#

off to rewriting that idt from memory

surreal path
upbeat turret
#
  • help from the intel sdm and osdev wiki
surreal path
surreal path
finite summit
#

yeah my friend has a gaming laptop

surreal path
#

save ur registers

finite summit
#

I kid you not

#

his laptop starting smoking when he ran linux

spice yarrow
#

wait wtf?

upbeat turret
finite summit
#

it hung at boot

#

for a bit

upbeat turret
#

my pc is beefy

finite summit
#

after spitting some acpi errors

upbeat turret
#

had no problems

finite summit
#

and bluetooth errors

#

then starting smoking (according to him)

#

and takes minutes to boot because of the bluetooth errors

#

after a timeout it boots

spice yarrow
#

I was about to say maybe we could help you with it, but it seems like you've been cursed by the hardware gods

finite summit
surreal path
# surreal path these 2 only
struct regs {
  uint64_t rax, r10, r9, ...
} __attribute__((packed))
void handler(struct regs *frame) {
  kprintf("weee");
}
asm stub handler:
push r9
push r10
push rax
call handler
pop rax
pop r10
pop r9
iretq

its lit this easy

#

also

#

there

#

perfect

#

if u fail this up ur just like me halfmemeright

#

nyaux try not to fail basic ah task

#

frfr

spice yarrow
upbeat turret
surreal path
#

yes

#

and for that

upbeat turret
#

i feel like that's something to capture

surreal path
#

what i do is push a dummy error code

upbeat turret
#

(only with isrs that don't push error codes)

surreal path
#

something like this ^

#

if u use nasm

#

use some nasm macro shanngains

upbeat turret
#

oh yeah

#

i also align the stack

surreal path
#

?

upbeat turret
#

first i save it to rbx

surreal path
#

tf u mean

#

align the stack

upbeat turret
surreal path
#

what

#

...

upbeat turret
#

or do i not need to align

finite summit
#

some abis require aligning the stack

surreal path
upbeat turret
#

hmm

#

idk

finite summit
surreal path
#

u dont need to

upbeat turret
#

i'll try something out

surreal path
#

๐Ÿ˜ก

finite summit
#

x86_64 systemv abi

surreal path
#

I OWN SYSV ABI

finite summit
#

requires stack to be aligned to 16-bytes at call

surreal path
upbeat turret
#

i aligned the stack before calling the int handler

surreal path
#

so theres like no need to check

finite summit
#

I have never done that ever

#

and have not blown up

surreal path
#

^

#

same

#

stack usually is aligned 16 bytes

finite summit
#

but if you do it it's no harm ig

surreal path
#

fr but again

#

im not doing it

#

so u shouldnt either

#

@upbeat turret

finite summit
#

as long as you don't round it down meme

surreal path
upbeat turret
finite summit
#
and rsp, ~16```
surreal path
#

xor rsp

#

9999

#

๐Ÿ’ฅ

upbeat turret
#

lmao

finite summit
#

I love xor

surreal path
#

me too

upbeat turret
#

xor rsp, rsp

#

reverse stack magic trick

surreal path
#

inverts the entire stack

#

funny

finite summit
surreal path
#

0 -> 0
1 -> 0
0 -> 1
0 -> 1

1 bit stack

#

get boom'd

#

๐Ÿ˜ฑ

#

@spice yarrow

#

unwrap in C

#

crazy

#

ik

#

i also have asserts :)

finite summit
#

le very cool

surreal path
#

indeed

#

who needed rust

#

am i right

#

or am i right

finite summit
#

yes

#

you are right

surreal path
#

yes

finite summit
#

rust=๐Ÿคฎ

surreal path
finite summit
finite summit
#

๐Ÿ’€

#

anyway imma go to sleep

#

now

surreal path
#

alr ima work on pmm

#

gn

finite summit
#

(before I sleep, I want to say: don't attempt suicide again though, we'd genuinely be sad if you died)

finite summit
#

(just some examples if you don't believe the last part)

#

anyway gn\

surreal path
#

gn

upbeat turret
#

so far lgtm

#

though in this context, a null IDT would be loaded, the gates need to be set

surreal path
#

0xd? how tf

#

base of entry is 0x1000

#

in pages length is 159

upbeat turret
#

quick question

#

can IRQs be just an ISR that pushes a dummy error code and calls some other handler other than the isr default

#

@surreal path (please beat me up if you don't want to be pinged)

hollow herald
upbeat turret
#

it happened

#
%macro pushr 0
    push rax
    push rcx
    push rdx
    push rbx
    push rsi
    push rdi
    push rsp
    push r8
    push r9
    push r10
    push r11
    push r12
    push r13
    push r14
    push r15
%endmacro

%macro popr 0
    pop r15
    pop r14
    pop r13
    pop r12
    pop r11
    pop r10
    pop r9
    pop r8
    pop rsp
    pop rdi
    pop rsi
    pop rbx
    pop rdx
    pop rcx
    pop rax
%endmacro

extern handleInterrupt
extern handleIrq

%macro isr 1
    global int%1_stub
    int%1_stub:
        push 0
        push %1
        pushr
        mov rdi, rsp
        call handleInterrupt
        popr
        add rsp, 16
        iretq
%endmacro

%macro isr_err 1
    global int%1_stub
    int%1_stub:
        push %1
        pushr
        mov rdi, rsp
        call handleInterrupt
        popr
        add rsp, 16
        iretq
%endmacro

%macro irq 1
    global int%1_stub
    int%1_stub:
        push 0
        push %1
        pushr
        mov rdi, rsp
        call handleIrq
        popr
        add rsp, 16
        iretq
%endmacro

isr 0
#

i've only defined isr 0 for testing purposes

#

i'll define the rest later

spice yarrow
tender gorge
finite summit
#

Oh yeah

upbeat turret
#

this was the last log before it triple faulted

hollow goblet
#

and for some stuff use Atomic* types from core

#

like i store my HHDM in a AtomicUsize

#

which technically is also UB because that doesn't keep the provenance of the HHDM pointer but it's really fine

#

when you're writing a kernel in rust, you are really fine doing stuff that would otherwise be not fine

#

just you keep overdoing it, then expect nothing to do what you want it to do (e.g. memory corruptions

hollow goblet
#

if you can take something from an external dependency, do so and replace it when it isn't exactly what you want