#Nyaux
1 messages Β· Page 7 of 1
the font is so ugly
you are interested in the main counter register
my eyes
okay
thats offset addr + 0x0f0
ok
acpi_gas?
yes, hpet can technically be used over port io
what
oh
that tells you how to address it
it contains the address_space_id
which you should probably assert that its memory mapped io
because fuck you if your hpet isnt memory mapped
what?
GOOD
yea i see its a structure but what is address_space_id supposed to represent
acpi_hpet *hpet = table;
kassert(hpet->address.address_space_id == ACPI_AS_ID_SYS_MEM);
uintptr_t hpet_base_addr = hpet->address.address;```
the address space
in which the hpet "operates"
i guess
it can be port io
memory mapped io
pci config space
oh so its like an ID that tells you what type of address space it is
oh get u
if you read the code you would have realized
lol
there is literally defines right above that tell you all that
its ok as long as u learn something along the way
dont forget it should be a volatile uint64_t read
also you should try and print the hpet address, make sure it's present and valid
yea i did
i did check if the hpet exists
and checked if it is memory mapped io or not
HPET BASE IN PHYS: FED00000
HPET MAIN COUNTER RN: 0
uint64_t hpet_base = hpet->address.address;
volatile uint64_t poll = *(volatile uint64_t*)(hpet_base + hhdm_request.response->offset + 0x0f0);
serial_print("HPET MAIN COUNTER RN: ");
serial_print(itoa(wow, poll));
serial_print("\n");
asm("cli"); // disable interrupts
for (;;)
{
asm ("hlt");
}
this is what i do
is the main counter register not ticking or somthin?
??
as other people said already, why don't you implement printf?
and then use some trick to redirect either to terminal or "serial" at will
like a debug define ifdef
and even if you want to have separate functions, just do this instead of having to call itoa every time
and if you pass the base to itoa you can easily print hex, dec and binary or whatever you want
its not that big of a deal to me even tho i have nanoprintf and i could just use it, i just prefer using itoa like a cursed manic
Have you verified that the counter is 64 bits
Read the spec or osdev
spec says the register is 64 bits
Ye
cannot he just use cli hlt together instead of having hlt in the loop? Correct me if I am wrong
omg do not halt in this loop
ok ill check
eh
right he just didnt want it to run out of this function
nvm
i thought it was supposed to be the busy loop for calibration
No
oh
Read the wiki page
wiki page just shows the structure
doesnt tell me what register bit width is used for
Scroll ffs lol
oh
There's also a config register
yea i see
That u must check
yea 64 bit
and i see that the config register PROBS has the main counter hlt'd rn
i will check
yea hpet counter is not running
its halted
i will enable and see
WOWIE!!!
thats a timer!!!
it goes VERY fast btw
the main counter
lol
Yes
okay so i have the START of the hpet counter
set the lapic timer to divide by 2
set the inital count to 0xffffffff
do i just do a while loop until lapic timer counter is 0?
okay how do i do that
use the hpet to figure out if the time has already passed or not
if the timer has already passed?
lets say you wait for 10ms
make the hpet wait for 10ms
then you know how many lapic timer ticks are in 10ms
lol
how do u make the hpet wait for 10 ms π
Bro
Think
You have the counter
You have the amount of time it takes to increase by 1
the capabilities register tells you how much time passed every time it ticks
okay
Wtf
bit math
lmao
i dont think that works
even if it did it would be wrong
shift the register value right by 32 and then mask it
thats what im doing
no LMAO
no
yes that is what i said
kk
TIME PER TICK: 10000000
10ns
yep
you can use that to measure time now lol
now im gonna activate the two brain cells in my brain to figure out how to use this 
figure out how much you want to wait
probs 10ms
convert this to a common unit that's big enough
so you can convert both to nanoseconds
1ms is 10000000ns
10 * that
okay
loop while (current hpet - start hpet) * period_in_ns < 10 * that
lol
congratulations your kernel is now 10ms slower
Tbh if we keep spoonfeeding him like that its not gonna get him very far
true
yea dont spoonfeed im trying to understand
let my two brain cells activate
ok i mute thread i go try and understand vmem.pdf

kk
And jm gonna sleep
alr gn
good night
Thank you
npp
i figured out how to do it without any help
now my kernel can successfully wait 10ms
π
you're waiting 100ms
what???
10*10000000
oh
10(ms)*10000000(10ms in ns)
β οΈ
one zero too much
you might want to put a pause in that loop body
alr
or actually you might not
might mess with the calibration process on real hw
idk how the lapic timer frequency changes with power state changes
putting a pause causes the lapic to send an interrupt sometimes
which is VERY weird
what lol
you probably didn't mask it
you should use 4 or 8
ok sure
also mask is bit 16
not 15
bit 15 is reserved
bits 18..17 are the timer mode (one shot, periodic, tsc deadline)
yea i fixed
how did u know that was the issue
is bro in my pc
you sent the code earlier
why is divisor 1 too fast?
honestly idk, it just feels like it 
i love spreading misinformation
but clearly it timed out sometimes, so it is too low
how would any of us know
try setting up a periodic timer with that interval * 10 or something
see if you get an interrupt every 100ms
alr sure
its pretty easy to eyeball 100ms imho
YEA IT FEELS LIKE 100ms!
!!!!
like it feels RIGHT on that dot
wowie!
lets tick every uhh
1 second

no it feels like every second
i actually dont know
i need a stopwatch lmao
yea its doing every second
bruh
oh i calibrated wrong
okay i THINK thats 100ms now
okay it is
cool 
ok what do i do now that i have a timer 
and a "functioning" apic driver
ig
time things
like what time things
i meant time as a verb but that works too
will i hook this up to my scheduler 
wouldnt that be a funny!
well yeah you probably want to use the timer to drive the scheduler
okay
ill make a kernel thread so i can continue executing whatever kernel init code i still need to do
or smthin
wait what else do i need again
i have an interrupt controller now
APIC "driver" (i dont even do anything with the ioapic atm lol)
gdt done, idt done, pmm done, vmm done, acpi tables parsed, not starting up other cpus as im not doing smp FOR THE MOMENT, lapic timer setup, i have a scheduler
a vfs now?
like rn???
have i been doing that much already?
i can go onto a vfs rn????????
what do yall think i should do???
cause i dont know where to go next?
make a printf
bruh
wait i have an idea
im gonna make a sleep function using the hpet

also gonna implement some functions for uacpi ig
difference between stall and sleep is just the format ig?
stall is supposed to be tighter ig
sleeping might involve rescheduling? idk
as in, won't potentially take longer
void uacpi_kernel_stall(uacpi_u8 usec) {
auto now = systemClockSource()->currentNanos();
auto deadline = now + usec * 1000;
while (systemClockSource()->currentNanos() < deadline);
}
void uacpi_kernel_sleep(uacpi_u64 msec) {
KernelFiber::asyncBlockCurrent(
generalTimerEngine()->sleepFor(msec * 1000 * 1000)
);
}
or more like it lets you reschedule
it might be a long lasting sleep
like 30 seconds
you dont want to be stuck doing nothing when that happens
i mean
my lapic timer will be ticking every 10ms
no matter what so
it wont be STUck there
but i mean wasted cpu cycles so early reschedule ig?
something like that i guess
okay made some ksleep function for uacpi and friends
that uses the main counter of the hpet
to like sleep
stall -> busy spin for very few microseconds (up to 255)
sleep -> actually go to sleep, can be up to a second
how do i do that 
spin for very few microseconds
yea but how
tf do i do to spin for a few micro seconds, run a bunch of asm pause instructions in a loop for a bit or smthin?
Uhh wut
U have the hpet counter?
i use the hpet counter as my ksleep
Yup
which means checking if the thread has reached its amount of time in ms, assuming a quantum of 10ms (which is what i do), every time the scheduler ticks and switches to the next thread. if the next thread has reached its amount of time its unblocked
correct?
Yes
okay simple then, just store a structure about the thread state. if its blocked the ms its blocked for will be in the structure and stuff
something like
struct thread_state_t
{
int state; // 0 - ready, 1 - blocked
int ms_if_blocked; // ms its blocked for if blocked
}
is this correct?
you may want to store the time to wake the thread
rather than than how long its going to sleep for, because then you'd also need to know when it went to sleep
okay so store the time to wake the thread
in what unit
??
your kernel your units
milliseconds and nanoseconds are common
or use a type to represent time in some unit-less way
i guess ill store in ns, and use the hpet counter to check if its like.
able to be unblocked or not
correct r4?
there's no single correct way to do this, but this is one way that will work π
i just wanna make sure im doing it in like a way that isnt stupid π
haha yeah fair, nah this sounds fine
time in ns rn + ns to sleep for = ns to wake thread
will use hpet counter (again) to get the current time in ns, im just gonna use hpet counter for everything π
man i love the hpet
so easy
didnt even have to touch the yucky pic
again just making sure, would be a correct way to do this?
?
im unsure if thats correct, ALSO i wanna like make a ps2 keyboard driver or smthin. im guessing i need to read the madt for the ISOs. and then configure the ioapic
yes
ok, will implment this into my scheduler later when i need this
wanna make a ps2 keyboard driver of some kind
i believe irq 1 is the ps2 keyboard
should be gsi 1
cause i think ioapic has the legacy irqs identity mapped unless otherwise specified in a interrupt source override?
guessing im gonna need to keep track of the irqs?
like a table
or smthin?
how should i do this?
Like you want to
i can design that however i want?

we have printf
π±
GUYS THIS IS A BIG ACHIEVEMENT
WOWIE !
PRINTF????
NO MORE CURSED ITOA??
isnt that crazy !
now yall cant mock this os anymore for not having printf cause we finally have a kprintf π€
i assume you're using nanoprintf for it?
yes
good, i don't want to think what a hand-written nyaux printf would look like 
what r u implying 
Lol
uhhh what else
uhhhhhh
o yeah i wanted to start ACTUALLY setting up the ioapic
which is lit not rlly much all i rlly need to do is create a kind of global struct that shows which irq goes to which gsi, initing using the interrupt source overrides, then whenever i want to install a irq handler for that i just lookup this struct table thingy to get the gsi and shit
i think thats how im gonna design it
You could just directly read the ISO too
I dont think itβs necessary to have a seperate table for it
its fineee
dont wanna scan the madt for it each time if theres an iso for an irq each time i want to install a handler
hmm okay, so like an array of iso pointers
Yeah
You can make the table too for sure it just seems unnecessary
Whats the general outline of your todo list atm
What will be the next things you implement
(Btw, I think you have the most comments on any thread π)
π
i dont really know.... my kinda first end goal for the os is to eventually have a unix like userland with doom ported. i dont know where to go im just kinda following mints guide in #curated-resources
Thats a good one yeah
they said vfs next
so maybe after the ps2 kbd driver i will learn what the fuck a vfs is and how to implement one
unless yall got better suggestions on what to do next
i dont know i was like testing threads ig
π
You cannot be calling your function poopXY

im GUESSING that after i init everything, there is no need for a kthread at all or smthin. we just start scheduling and executing processes and then when we syscall thats the only time we go back to the kernel (or if its from an interrupt like a irq handler or smthin)
this is broadly true
you can see the kernel as being like a library that coexists in every process
and the usual pattern on most kernels is that most threads are in userspace and only make occasional excursions into the kernel
interrupts make a slight mess of this analogy but still
so usually threads are in userspace
except for kernel worker threads, those appear in most kernels too
but that's the general principle usually
kernel worker threads? what would those be used for
page replacement, driver duties, that sort of thing
ah okay
been fixing some of my scheduler code
now happening via the lapic timer
π
each thread has a quantum of 10ms cause yea
works rlly well
currently my scheduler is just some simple round robin thing
each thread holds a pointer to the next, if theres no next go back to start of queue
that sort of thing
currently my scheduler treats everything as a separate thread
which was okay but i probs need to change that now for user mode soon
or actually
not
i should treat everything as separate threads
if for some use case i wanted to find what threads belonged to which "processes", i can simply store a process id in each thread
anyways im actually gonna make a proper kpanic
to make debugging easier
print out every register and everything instead of just printing the rip
then ill work on the ps2 driver
π
thats a lot of gsis
is that common?
for an ioapic to handle that many gsis or smth
i think so
im guessing this is smthin with qemu?
run info ioapic
kk
er sorry, info pic
how are you getting the number of pins
reading the ioapic version register
what does | 0xff do
OH
β οΈ
WHOOPS
should've been and
okay cool π
one thing im rlly getting annoyed at is how long it takes for the pmm to init
yea i get it, im storing a freelist node into every fkn page
thats gonna take cycles
but comeon
it takes a whole 3 seconds
3-6
for a 3G
idk how to make this faster
not rlly much i can do
here's what I do
works just fine
I do a freelist on a per-region basis
instead of every page
yea i guess thats why it'd be faster but at that point its more bitmap then freelist
pmm is integrated too deep with the kernel for me to change it, so if i want to do a pmm region freelist kinda thing, i cant rlly cause it'd take too long to refactor everything
but i can see how that would be better overrall
wish i had did that π
does add_region merge adjecent free regions or will you eventually end up with only 1 page long regions
not from a functionality standpoint
actually not even from a performance standpoint
doesnt matter at all
just means the head switches more often
okay well it does at least solve the boot time problem, maybe once i finish this ioapic stuff and before i do a vfs ill refactor my pmm to be like this
cause i really hate waiting 3 seconds everytime i boot a nyaux vm under qemu
yea
on tcg, but even on kvm its the same
vm with 3G
should be faster on kvm
laughs in managarm 
i will test
actually
rn
getting to weston takes 17s in qemu on my laptop
i will boot my laptop to nyaux
its rlly fast until the loading pmm part which is the slow as balls part
everything else is speed tho

I've accidentally wiped my sda drive while trying to dd too many times
ok gonna try booting it
brb
Uh oh
Itβs hanging at vmm init
this is why I needed to make a kpanic function
Iβm gonna try and get nyaux to run real hardware
most likely hanged somewhere here
probs page faulted cause
my display is 1440p
and the background is a 1080p file
yea thats most likely the reason
i need to somehow "resize it"
to fit whatever framebuffer
i have no idea how to do that lmao
You cant
Write a graphics driver
just don't set a background image 4head

but it looks nice !
i need a splash image!!!
!!!!!
what if i just made a really big res image
would there be a way to downsize it
or no
also i'm pretty sure flanterm will just pad the image with black on all the sides if it's too small?
no
it doesnt
sadly
wish it did
I think you're wasting your time
wdym
On useless stuff
yea fair
lemme at least see if nyaux can run on real hardware
tho
at the very least
ill disable splash images
That ain't it?
nah, you have to do it, the canvas is expected to be = width*height
ah my bad
Shouldn't be that hard to extend it to support that probably? Sounds like a convenient feature
^^
yeah i mean, it's not hard to automatically pad, but for that it'd need to know the actual size of the image, and now it only knows of a raw canvas
the user is kind of expected to do all paddings, stretching, shrinking, whatever, on the canvas before passing it to flanterm
if you want fancy stuff like this you're probably going to have better luck using ilobilo's port
of the Limine logic that does this, to be freestanding
i think i just dd'd my drive....
I told ya
you at least had the code committed and pushed, right?
now it's time for you to reinstall gentoo

no wait i got it working
i didnt dd i just
messed up my boot partition
fixed now
π
anyways nyaux page faults here on real hardware for some reason?
that is so weird
im gonna make a stack trace
thing
for debugging
so i can figure this out more
cant gdb step real hardware β οΈ
if you have special equipment you can debug real hardware :^)
now we have a nice stack trace
no i got this π
all i need is me and my stack trace
π π
wait no
this isnt a pro gamer address

wrong image
uhhhh oh right i know why
no still
my brain
π₯
is gone
i dont think thats a valid rbp
to be fair
or maybe it is
did you pass -fno-omit-frame-pointer to the compiler
yep
Ok got the stack trace to work
Gonna debug this now
So I can figure out why itβs doing that on real hardware
okay so line 1040 its faulting
at this line

why hmmmm
(when converting a string arg)
seems like hardware doesnt play well with uhhh printing to serial cause anytime i do a printf using serial it page faults?
if i printf with flanterm ctx
it works fine
on real hardware
(i think)
ill test that rq
Very interesting
why does my pc not like this thing
it hates it for some reason
it page faults with this macro enabled
if i dont have the macro enabled some of the printfs look weird
this thing off
vs on
lemme see if the real hardware boots with it off at leasttt
doesnt boot even with it off
still faulting

faulting here
when it calls uacpi_error
its doing it whenever copying the string, most likely unknown_path is something funky
whatever uacpi has set absolute path to
its doing smthin funky
i believe this is more an issue with uacpi itself
probs doesnt work well with my hardware (this laptop is pretty difficult to support, even for linux)
@kind root might wanna check this out
if someone can try and run nyaux os on their hardware
that would be greatly appreciated
im just going to say that its unlikely uacpi or nanoprintf that are the real cause of the bugs here
for npf you at least only have so many inputs to worry about
more context would be useful here, particular whats the format and what are you passing to this function.
Nah it's not a uACPI issue
Run managarm on that hardware
If it boots its your skill issue
There's no such thing
Iβm not passing anything Iβm just starting uacpi
Iβll try
I canβt give too much context cause itβs only reproducible on hardware
Thatβs different to debug
Then this donβt make any sense
Tf is going on
who knows, a lot of things about your kernel could be broken
itβs only happening on real hardware and ONLY whenever uacpi tries to print or smth
and
Iβll disable tracing and see if it solves
this just means the bug is not reproducable on the simple blob that qemu provides
dump the blob with acpidump -b and feed to the ./test_runner <blob>
or just run managarm
Alr
downloading
this my dsdt.dat (if u can feed it into test runner on ur system that would be quite epic gamer)
im gonna reboot into managarm and test
works in test runner
is there a way to feed a dsdt to qemu
ill try feeding it to nyaux
path to dsdt?
yeah
kk
what difference does it make?
DSDT is only one and is pointed to by FADT
SSDTs are infinite amount
also it wont necessarily work and might crash qemu because it does arbitrary MMIO
that is not present in qemu chipset
oh
it has a hex header
i renamed it in the hex editor but its still too big
how tf am i supposed to actually debug this then 
i cant just keep reflashing nyaux onto the usb and keep rebooting and partitioning it takes too long
yea but i have to reflash the usb everytime with dd and reset the partition
and it takes forever to reboot
im gonna dd managarm's image.xz and try it
wtf
i think it checks for number of make jobs * 2 GB of ram
fkn hell
even trying to get the binary version
gentoo crys
gentutu
yea genbyebye fuck this im switching distros
i think thats what it was called
i know a good distro
its called
windows 11
.
i think i will switch tooooooo arch or smthin
why is it always my kernel 
just use arch lmao
yea i switched to arch
fuck gentoo
all my homies hate gentoo
π€
fr ong
!!!!
π€ π€
anyways gonna boot into managarm and see how it fairs with my hardware, i just hope it also page faults so i know its an issue with my hardware and NOT with the kernel π€
Managarm panics on my hardware too
Itβs 10000% a hardware issue
To verify if this is correct can someone test nyaux on their hardware
If no blue screen itβs def this laptop being so weird
anyone got the time to do so?
please??
i have no other device on my other then this laptop π
this is in userspace so well after uacpi init
yea a ps2 driver
also i dont think managarm has uacpi tracing everything
yea and i have mine to tracing everything
disable trace logs
so thats most likely the issue
yea
it could be your allocator being shit, you running out of stack, you not mapping things correctly
many things to consider
it probs isnt the allocator cause it works on the vm but not on real hardware
- already had my oberrow hell
the real hardware has a much more advanced aml to parse
than the one in qemu
parse + execute, sorry
yea but heres the thing
in this stack trace
one second
im gonna get addr2line
just lemme fix my compiler (cause this is a new system)
where is the cr2
lol
lol
lmao
still im gonna really quick setup my cross compiler
im gonna try 2 things
im gonna disable uacpi tracing full
and im gonna
print out the cr2 in the page fault
if that still happens
Nope, its your kernel issue, as you can see managarm boots fine
bruh
This is just some userspace driver bug
also your dsdt works fine in the userspace runner
Both userspace and real hw apparently
if this is another allocator issue i swear
at least be an issue with printf or smthin simple and not my allocator
Could be anything
okay my page fault screen prints cr2 now
how do i make the stack trace print the line number and c file name of the faulting instruction
i know some stack traces do that
would make it 1 billion times easier to debug real hardware
Write a dwarf parser
dwarf parser?
Elf debug info format
is that difficult to implement, a dwarf parser?
or is it worth using a freestanding library for that
?
then im def using a library
okay this is difficult to get working

this damn libdwarf shi
ugh all i wanna do is just get the functions names from the instruction pointer, like addr2line does
unless that is also part of the dwalf parser, add a sinple disassembler library to have a disassembly on the panic screen
and write out all the general purpose registers
here you probably made two screnshots one afyer eachother, since you can still see the transation effect
im doing something very cursed but i have an idea thanks to this perl script i found
in #resources
well not rlly surprised
time to keep working on that linker script !!!! even tho i never write linker scripts and have zero idea what im doing !!!!
hum

now that doesnt look very epic gamer 

oooo
looking fresh
LOOKOKKKK
OH MY GOD
THIS IS BIG BRAIN
are you using libdwarf or?
he's using this
wtf

this won't tell u the line number
i no need
only the function and byte offset
im too dumb to get libdwarf working anyway
why tf did u make a special phdr for symbols
idk
use the rodata phdr
i removed it anyway after figuring out that was dumb
yea im using rodata now
good
bro never heard of binary search
i havent

the problem is that the rip is pointing the the line number not the beginning of the function
it's because you spam it
pretty sure there's 1000 messages per one thing you implement
yea hey at least i implement things !
at least im understanding what im doing, instead of not understanding and just copying code or smthin like i used to do back in 2020 when i was stupid
i cant get the debugging symbols to work
im not doing this, this is a waste of time
for the time i've been spending trying to get debugging symbols
i probs would have just fixed the issue happening
π
and what i was doing was rlly cursed and dumb
boohoo i have to restart
so what
okay first part of stack trace is this line
second is this?
uh huh
here
next part
very weird
its always faulting at this instruction
when trying to put the absolute path thing into the string
cr2 is 0 when this happens
okay so absolute path is never init'd to something so its not pointing to anywhere
when uacpi_error tries to print out absolute_path
it faults because absolute_path doesnt point to anywhere at all
and this is VERY weird cause clearly <unknown> is there
@kind root what do u think is going on here, why is absolute path pointing to nothing. i know nothing about aml interrupters so probs best to ask u if you can know whats happening
this is unrelated to aml or uacpi
its a bug in your code
corrupting something into oblivion
with the memory is that what ur saying
yeah, even the fact that this gets called
okay
could be your kernel_api impl fucking something up
im reading it
like seriously, you clearly see it gets initialized in every branch
how would this be affected by anything
i dont know, its difficult for me to think rn im tired. im not sure how i can debug this since this is an issue only happening with large aml parsing and since the qemu blob is tiny i cant rlly do much
is there any emulators that have large blobs or anything for uacpi to parse or is their absolutely NOTHING i can do
?
i actually dont know what to fucking do anymore, i stepped through vbox trying to figure it out but i just couldnt
why is my allocator always the problem, why is my code always shitty why cant i just write good fucking code for once in my life
try vinix
Just become a contributor to OBOS 
You can write the code that's simple
while I do all the work
Itβs my fucking allocator as always
my allocator isnβt even that complex yet it ALWAYS has bugs
I just
says YOU, of all people
^
I donβt know what a bump is but I guess Iβll look into it
alloc(size):
result = base
base += size
return result
yeah it's stupid simple
align size to 8 beforehand tho or smth
so you dont hand out unaligned pointers
free doesnt exist
or well, if ptr + size == base then base = ptr, else you cant free 
but there is no point in implementing free for bump
His thread was posted 16 days ago, and has nearly 7000 messages
Mine was posted around august of 2023 I believe
and has 6300 messages
hes just really invested 
I've also put progress in that thread for my kernel over all rewrites but the first
I spend my entire day everyday on my OS, every hour. When I come back from school I instantly open vscode and get working. I really enjoy osdev despite how frustrating it can be sometimes
It makes me really happy seeing me do things like creating a kernel and seeing it actually work
brings me a lot of joy
I donβt rlly have a life outside of school lmao
I hope people can look over this thread one day and perhaps learn from my mistakes and from all the great advice everyone here has given to make nyaux actually possible
for their os
the grinder
Yep! ππͺπ₯

