#Nyaux
1 messages Β· Page 43 of 1
Embedded devs love crappy proprietary solutions to already solved problems
Don't you love it when microcontroller XYZ implements the RISC-V PLIC spec but not the standard address space layout for it?
for controllers that expose a window into the config space:
- configure the pcie controller to show you the config space of the function you want to show to the os
- have mcfg point to the window, and say that only 1 function is available there
- the os will see the device you wanted to show as XXXX:00:00.0
Because I've seen that one too.
this is what uefi for the rpi5 does btw
Hmm but how, you would still have to make sure the entire space is mapped at some address
for windows support
apparently not even original solutions to already solved problems, just copy and paste existing solutions and change them ever so slightly to fuck people over :^)
So u would only show one device at a time?
Yeah like why
Microcontrollers are like this all the time and it frustrates me (an embedded dev as a hobby) to no end.
one function even, so multifunction stuff like gpus also doesn't work
wait i need to impl a way to exit a thread
like
destroy the thread
from ze queue
Well that would be useful for more than just using uACPI in your kernel
yea
That's why I kinda don't wanna invest into the aarch64 version of the kernel if I start making one, it just sucks and u have to have 9999999 drivers per chip
will ask in #schedulers
Maybe if I can get my hands on like an aarch64 framework or something
Idk if that has a sane board
framework is riscv
I think
besides x86
just support qemu virt board and nothing else 
Even better, less memory caching garbage problems to worry about
raspberry pi
or one single random version of the rpi
and a lot of proprietary garbage
yeah
with risc-v there's no good hardware
(from what I gathered at least)
I also want something physical for my RISC-V port
But I have a bunch of raspberry pi s
So pmOS ARM port???
usb on the pi5 is just xhci iirc? but it's on their weird rp1 chip which has everything smushed into one pcie function at different offsets into the pci bar
I see much more value in supporting my old abandoned laptops than a pi, at least those have a proper GPU and their own screens and stuff
though it's kinda remedied by the fact that everyone support them
Pi4 is xhci, pi5 is proprietary stuff iirc
no pi5 also has a xhci
no it's also xhci
Sweats in already comitted to doing ARM port for BadgerOS
its a dwc3 tho so no public official specs for that
like all bsds and a bunch of small operating systems
Ah ok then
yeah but you don't really need any of the device mode stuff for the usb-a ports
so it's fine
Also wtf is that latter part
and a lot of "let's do baremetal dev" kinds off tutorials/things
Nah I know you are passionate when it comes to this stuff 
so for the rpi5 they moved a bunch of peripherals off of the main soc onto a second chip (a la southbridge) that's connected over pcie, and that chip is a custom design, so ofc it only has one pcie function with a large bar that has the mmio regions of all the peripherals in it
it would be interesting to make a device mode driver tho 
the way you're supposed to discover the individual pieces is with acpi/dtb
or just hardcode them if you find a pci device with their vendor:device ids
Least scuffed embedded design
look for device nodes with specific _HID and _CID values
like not native
well acpi is only available if you use the uefi firmware for it
And _ADR
and that's unofficial to begin with
at least the rp1 has some docs available (although they're still the preliminary ones with some details missing)
and what's fun is that it has some arm microcontroller cores that you can run code on :^)
The southbridge?
yeah
Damn
and the arm core has access to all the peripherals, including a dma peripheral, so you can program the southbridge to dma to the host ram or whatever
So dma would be just code in the sb doing a manual memcpy?
it has an actual dma controller too
Ah
but yeah the host physical memory window is mapped into the rp1 address space too
i think the dma peripheral is generic and you just point it to the host ram window for dma across pcie
but this is unrelated to things like xhci etc (although ig you could point xhci into the internal rp1 ram instead of host ram?)
yes
Ah
ah but the arm cores don't have access to it
because the 32-bit addr space is too small so it doesn't fit along with all the peripherals
What? In the RP1?
That's just silly
or well, not to the full space, afaics there is an ATU window thats 1G (which i assume is programmed to point somewhere into the host address space)
There's probably a register to change the window.
I think the host cpu is called an AP
And in x86 land an AP is something else
Basically just any cores started by bsp
this seems about right
you select which 1G chunk you want to look at
and program that into ATU_REGION
since the direct window is 512G in size, the ATU window is 1G in size, and ATU_REGION is 9 bits long
(1<<9 = 512)
Actually calling something an application processor is pretty common (in the MCU space at least) for whatever the developer and/or end user is supposed to program.
Yeah name collisions as per usual
Always.
It gets to a point where I sometimes do a double-take going "this thing doesn't contain XYZ, does it?"
unfortunately i don't have an rpi5 so i can't test
Ye
Like calling the shitty single-level "page table" that ESP32s have for their memory-mapped FLASH an "MMU".
Lol
That made me do a double-take because I was convinced they hadn't had an MMU.
Lo and behold, they didn't, in fact, have an MMU in the sense any programmer would reasonably understand it.
Its hard to come up with original names for things ig
Names are hard indeed
I have come up with a completely original name for a project exactly once to date.
Badger?
Nobody had named a RISC-V CPU "Boa RISC-V" before I did.
No that's surprisingly common
You have your own cpu?
Oh yes.
I have made quite a few by now.
Did you run it on an FPGA?
that means good risc v in portuguese
The CPUs I made before RISC-V were all custom ISAs (and therefor the disadvantage of not having a toolchain).
Yep. Got it going at 25MHz max.
I know more ticks now that could make it faster but I haven't properly started another CPU project since.
It supports hardware atomics too, which I'm very pleased with.
Very cool
I posted about it in #risc-v back when it was actually a recent thing.
So keep your eyes on there occasionally if you want to hear of the next oneβ’οΈ.
Yee
But this is getting off-topic
I try to respect channel's topics and this one's topic is your hobby OS
currently waiting on monkous to respond about me trying to understand his scheduler desgn
in #schedulers ofc
heres what im going to impl
i will add states to threads like running, ready, zombie
u can create a new thread its ref count will be initally 1, because someone in the freelist is referencing it
thread does thing, maybe later down the line thread might have something more then 1 because idk thread communication idfk how that works
if this new thread calls exit_thread()
it will decrement its ref count and put it in the zombie queue
the reaper thread will check if its ref count is 0
if it is free the resource
is this a good way to impl exiting threads
anyone know?
:(
??
afaict its alright
okokok
somehow ive corrupted the stack???
i was cleaning up the scheduler code
stack is corrupted??
cant even look at ze stack
thanks gdb
ummmm
srry what
π
does this look corrupt
i think it looks corrupt
uhhh
wheres my fucking
thing
bro
wait hold on
what in the fuckj
oh nvm
You've asked to remind you to fix your sleep schedule
Go to sleep now
i cant
sorry
i somehow fucking corrupted the stack
it seems
nvm?
i did not?
okay
oaky
okay
i have found something out
after getting preempted while ur in a thread
something happens and the return address is gone
wtf
???
so it just stops executing thread code in its entirity
isn't it 3am for you?
yea
i tried already
try again
is this supposed to happen
like
what
what happened
you aren't pushing/popping the correct number of values?
i should be
yea thats the return address
into kentry
not into kentry
rather
into return_from_kernel_in_new_thread
umm what the sigma
yea thats not right
i have no clue
whats causing this stack corruption
wtfff
no idea whats going on lol
i LITERARLY
just
functioned out the queue crap
π
on github ig
it panics with why am i here
for some reason
only one core panics as well
and timer interrupts are still firing
idfk whats going
on
@surreal path hello my sweetie human π
hey
im going to sleep i tried debugging this for a good bit but no 1 im way too tired no 2 im already out of ideas π
night
yes go sleep π‘
nvm it works now??
tf
weirddd
nvm not anymore
wtfff
now its not anymore??
@flat nymph
is this UB
i lit barely change the sched
it works
then i change it a little
it doesnt

It's potentially normal?
If you enable interrupts in kernel
Nyaux whats the current ec status
well
i couldnt tell u
cause the fucking scheduler killed itself
but if i can get the scheduler working
and i can get things like blocking and exiting threads complete
we will have a more stable ec driver
kinda was debugging this then took a break
but
i swear to god
read the source urself even
the interrupts ARE dsiabled
π
i just send
on EOI
one*
thats insane
and then somehow the stack gets corrupted
and idfk whats going on
bru
yes f indeed
i think its a bug when exting out of a thread
exitingg*
as in
2nd preemption
cause ive seen it enter kentry
once
then some shit happened
idfk
ive been banging my head out
trying to debug this
chat this is so fucking weird
Like sometimes
it just decides
im gonna get stuck in send eoi somehow
and get preempted and then send another eoi and then get preempted
and make my iretq return address be send eoi
and sometimes
stack corrupting after 2nd preemption

@flat nymph no way ur awake

i think i will ask for help in #schedulers or something
now I COULD do that
or sleep
ill do it first
Sleep
nahh
Why wouldn't I be
exactlyyy
i dont know whats going on either
Maybe it's not switching stacks as it should idk
im wtfing as well
no it is
i checked with gdb
something fucky is going on
and all i did was cleanup the queueing code a little bit
Make sure you don't use the whatever mechanism there is to switch to a different stack on interrupt
i didnt even touch the context switching
wdym
wdym, rsp0?
i still am switching out rsp0
whats wrong with that
even tried adding dummy bogus shit just to make the stack 16 byte aligned
which changed
NOTHING
i didnt even
change the thread struct
i just
changed the queuing
thats it
im so confused
it was probably always broken and u just did something that revealed the bug
maybe
but the question is
what IS that bug

@flat nymph
i didnt change anything
it should work
This looks normal idk
You do sti though it shouldn't matter
iretq would ideally do that for you
Not ideally
yep
It's noop
Yeah because it doesn't do anything
yea so im cooked
because
i have no idea whats going on and my eyes look like bags rn
literal bags lmao
Sleep!!!!!
Ask someone smarter 

thats why i asked in #schedulers
It's like 11am in his timezone
i didnt sleep since
Ya ok grandpa lets get you back to bed
indeed
You enable interrupts right before you do send_eoi()
Thet's why it returns to it
I.e. it's working as expected
when you are sleeping
sigma
im so fucking screwed chat
fair
that sworse

im sorry ur experiencing that
okay disabling all other cpus doesnt change the behavior
but itll be easier to debug now
stack looks like this
And ubsan doesn't catch it
values of stack pointer rn
it seems like it never rets into return_from_kernel_into_new_thread
not only that
but the timer doesnt seem to fire anymore

i think i know why
i am overwriting the new threads stack
with the interrupt context
And if I add -fsanitize=undefined
and because i changed my thread run queue into a double linked list
with the thread pointing to itself
this makes sense
@flat nymph how do i fix this, i wanna fix this without doing some hacky idea
Fix what
Where's the code
Ugh how are you overwriting it?
look here
on first context switch it thinks we were previously running an old thread
because something is in the runqueue
and the next pointer points to itself
u understand?
solved it
It was stack overflow
laura is poop
cringe opinion tbh
@bleak cedar hi
mishavkov
happy new year
@molten grotto happy new year
everyone else in the thread
happy new year
happy new year for you too! where I live it was already an hour ago
π
fair
happy new year though
thanks
npnp
Happy new year! (It was 9 hours ago for me)
im still a good 9 hours away
@kind root happy new years
also ec works great on my laptop
so theres that
reason its iffy on other laptops is because i stilll need to impl scheduler things like blocking
im working on it
happy new years!
Happy new years
Great to hear
theres no brightness control events so im thinking that has to do with something else, also it seems like the sensors are routed through the ec
there is lid close and lid open
Which
idk i just read the executed aml method
hold on while i dump my dsdt
Which sensors

ummm i dont know how to dump it in windows
i will reboot to linux i suppose
lol
gives me an error
Which
acpidump just works
Yup
did bro open it in notepad
Yeah probably
no i didnt
ok
iyea works now
@kind root maybe u can read it for me, im not the best when it comes to understanding aml
Im on my phone about to go sleep in 10 minutes
What is it that youre trying to understand
Scopes and such
What do u mean when u say sensors
i kept getting peridoic spam
for sensors
idk
found it
its in SSDTs
GHID
whats that
Method _HID calls it
that exists
On your screenshot
INTC10A0
Is the PNP ID of that sensor
He has like a bunch of them
aahhhh okay so why is the ec getting events from it
Because some new values come in probably
i was basing it off the fact it gets passed _UID which is SEN2, so it should return INTC10A1
what
but i dt understand it fully so
You can grep the Linux source for that PNP ID
okok
To see which device it is and what it does
inb4 not in linux
it isnt in linux actually
You are correct for that specific screenshot
ah okay
i thought i was being retarded
lmao
turns out i can still follow simple control flow
Intel(R) Innovation Platform Framework Manager
Lmfao
here
This is some device specific proprietary controller basically
Yeah as u can see its for thermals
fair
When do you get this notify?
Temperature changes I guess
yea
So it asks to re read
anyways before i do anything im gonna add some cpu id instructions
as well
as fixing up the scheduler even more
@glossy walrus BTW a non integer _UID example 
"Strong typing? What's that?"
Well technically its allowed to be either string or integer
But yeah idk why they allow that
IMO its stupid
Clearly the word sensor there is redundant
In the grand scheme of things it's not even close to the worst thing in standardsβ’οΈ for modern computers.
True
Kinda
Just make sure it either works or dont enable at all
How's the scheduler going so far?
uhhh so well currently i added a current_thread ptr much like in obos
threads now have states
and well
i have a zombie thread thing
but i didnt impl the reaper thread yet
first
i need to cleanup the queueing evne more
next
i need to impl KCexit_thread()
then
i need to impl the reaper thread
plug that all in into uacpi for schedule work and such
and yea
What I did in BadgerOS is have one thread called "housekeeping" for doing these kinds of simple tasks that have to be deferred to a different thread.
I use it for both the reaping of individual threads as well as processes.
and when the scheduler gets to it, it cleans up the thread
it will check if the current threads in the zombie queues ref count is 0
if it is
couldnt the scheduler do this
clean up resources
or is it a thread for perf reasons
What's the refcount for?
perf reasons
For the thread handle?
Yes but this could induce latency
for the thread yes
yeah
Couldn't you, in that case, have a custom free function for your refcount ptr and have said function add your thread to a "to-be-reaped" list?
That seems more efficient than checking all threads in the system to me.
ah, ill put moving this into a thread on todo β€οΈ
^
good point
thanks for that
I'm only speculating but it does make sense
Yeah freeing large tasks can be expensive
BadgerOS' model is slightly different in that threads have a numeric handle, even in the kernel, so I don't have a need for refcount pointers.
And also it has a join/detach model.
Which is what causes thread cleanup in BadgerOS.
Based object-based model
yep
BadgerOS uses numeric handles quite a lot, actually.
All of which in sorted arrays so it can be binary-searched.
wdym by this
Handles that could be pointers (e.g. a file handle or a thread handle) are numeric instead and the pointers (or structs if they're small enough) are stored in an array, sorted by ID.
You use ids rather than pointers, so every attempt to access the object can be checked
Oh sorry I didn't see you were tying
You basically read my mind :P
I'm in your head :p
maybe ill do this in nyaux later down the line
The join/detach model does that.
mind explaining that one :p
In #1153085124959809616, a thread that stops will be put in the "exited" state until a thread_join() is called with its ID. Threads can also be thread_detach()'ed if you're not interested in the event.
The latter case instructs the scheduler to clean up as soon as the thread exits (i.e. immediately add it to the reaping queue).
When a thread enters the reaping queue, it is officially dead and all that remains is the memory allocated to it (stack and thread control block).
Its ID becomes invalid at that time.
I'd do it sooner rather than later if you intend to, otherwise you'll have a lot of raw pointer accesses to replace
Definitely
I used to have raw pointers for things that now use integer handles.
And even with the few occurrences of the thread API actually being used back when the scheduler re-write started, I had to edit dozens of files just to comply with the new API.
hi
just realized something
so basically if i am to kill a thread with the reaper
what about the process
will that ALSO be refcounted?
???
and if its 0 free the process
something along those lines
okok thanks
if the last thread of a process exits, the process is dead
invalid meaning its removed from the list of threads?
Yup
seems pretty readable from a quick look
one thing I noticed is that u use a lot of atomic fns
well
seems like we've encountered a bug
it seems that trying to free the kernel stack
one of the addresses given to invlpg
is not a physical address
so there is a bug
in the vmm

no wait
thats normal right
wait
invlpg takes a virtual address?
tlb is keyed by the virtual page not the physical page
you do something wrong != there's ub
why do u call everything ub lol
i don't think you know what ub is
ub is undefined behavior
also, you have ubsan meaning most of the dumb ub your code would cause is caught
the fact your ubsan isn't fatal is another thing but oh well
ubsan isn't perfect
but you'=d have to royally screw up if it's something ubsan doesnt catch
read: your code poop go figure out whats fucking up ur stack
put a breakpoint at the ret
and check if the return address if correct
okok
maybe ur literally unmapping ur code
and the invlpg runs fine
but then it flushes taht entry out of the tlb
well the invlpg does run fine
and it dies lol? idfk
yeah no shit
but if u flush that page out of the tlb
and its now unmapped
how is the ret gonna run?
what kind of a pf do you get
on that ret
non presnet
and what is that?
0x0
hold on
not a real address
holding
good job
i told u
why are u unmapping ur stack lmaop
its in the hhdm
why would u unmap that
How did you manage to unmap your stack?
im trying unmap the thread in the reaper queue
dont touch the hhdm bruh
only unmap memory you mapped first
Yeah, anything in HHDM memory shouldn't get unmapped
yes
Do you even allocate the thread a stack?
woah
thats cool
Or are you using the one limine gives you?
yes
i allocate 2 stacks
for reaper thread and the test thread
im trying to exit
whjy would a reaper thread reap itself
fix that
i will check if it is doing that
How do you allocate the stacks?
hold on
Why not just with your vma?
it does use the vmm
It would be faster
no @thorn bramble this assertion passes fine
only thing thats unmapped?
yes
0xffff800d4020c000 < 0xffff800d4020ff38 < 0xffff800d40210000
True
nvm
i can see the register dump
how do u know its a bug
what is it
im assuming u know what it is
if u say its a bug lol
i dont know the exact bug but something to do with this if statement i think when creating regions
i could possibly be having overlapping regions
to verify this i will print all regions in the vmm on the pagemap
whats wrong with it
idk nothing i guess lol
vmm regions here
just wondering why ur doing that + page size
yea do u see anything wrong with this @thorn bramble
but kvmm_region_alloc looks fine regardless
maybe a little bit suboptimal
but fine regardless
okay
im joking
anyway the kernel stack being unmapped is the one being used by the reaper thread
like
lol
idk what to tell u
ur looking in the wrong place
figure out why its trying to unmap that stack
oh i see
??
u set kernel_stack_base to stack + stack size
so when u go to free the thread's stack
u actually free the region after
maybe
not sure
but like
thats waht you do with reaper thread stack at least
u set both base and ptr to the end of the stack
kernel_stack_base should be the base of the allocated region
kernel_stack_ptr should be base + size i guess
i know how to fix this
did it work after u fixed that?
hold on
well dont thank me yet then lol
i wanna go to sleep and dont really feel like cloning and building nyaux
oh no
did it free a kernel stack?
i believe so yes
well i hope it worked lol
ur vague description of the current state of doings makes it hard to tell
but yw i guess
lfg
4 for u
sleep schedule not found
yea U need to sleep
ahahahhassdhuawshsdjaudqahjwesiikaeqfgjae
HAHAHAHAA
FUNNY
HAHAHA
KILL ME
FUNNY
godo night
goodnight
good job
yesss!
fixing nyaux one bug at a time

It might be through the keyboard?
maybe
(maybe I should fix the pmOS keyboard driver)
lol u should
now i will abstract the scheduler a bit
clean up thread creating code
like seriously gotta clean that up
also fix the queueing code i forgot
but BEFORE that
ima add cpu id instruction and print out cpu manufactor

My kernel does the same
Refcounts are obnoxious
Why have them in threads, when they're either alive or not
I also have that 
You can easily avoid HHDM mapping issues by not using HHDM in your kernel 
is this sarcastic?
This is half-sarcastic, but I have to tell everyone that I'm not using HHDM
cringe
With threads you have a lot of questions, like what does hold a refcount and what doesn't
Like you have a queue of ready threads, do you hold refcount for that, or maybe you use something similar to std::shared_ptr and use that for linked lists, but then it becomes obnoxious, and what if a thread dies and someone holds a reference to it, etc.
I dont use it anywhere but the VMM
so I can swap out the impl relatively easily
guess whos
fucking lpaotp
laptop* broke?
mine!!!
okay so i was trying nobara some linux distro
wow i just crashed
okay
so bascially i ran it right, then it froze and then the screen got all glitched
and then the display was off
and it wouldnt come back
idk what linux did maybe it messed with the nvidia GSP firmware in a way that bricked it
to be fair this nobara distro claimed to have patches around nvidia
so i suspect they might have something to do with this
that or my laptop croaked out from too much osdev

anyways im using the family computer rn. my dad said when he wakes up he will take a look at it
or well
take a look at the fact that i even opened the laptop and disconnected its battery and cmos to which it did NOT fix it
am i even gonna get a new laptop
it cost fucking 2000 euro
i dont think he will buy a new one
he could try to get it repaired
but it would take weeks
and i already used the warnenity
im fucked
im royally fucked rn chat
how do u fucking
mess up a driver this bad
to the point of bricking the GPU
π
