#Nyaux
1 messages ยท Page 33 of 1
sigma !
following proper limine spec for a very similar hhdm
its before default
no it shouldnt
and he can map it after
๐คท
no im not doing that
it should be mapped
i think yea
nvm it dies when
trying to mmio the hpet
yay :)
yea
first write
Temporary map user 
mappings still overlap
imagine unconditionally mapping 4GiB
mappings are still overlapping
@flat nymph is that bad?
im not mapping gib
4 gib
it still dies trying to access mmio as expected btw
lmao
i mean okay
Maybe I've been looking at the wrong values
mapped 0xffff800007c00000 to 0xffff800007e00000 : from phys 0x7c00000 to 0x7e00000
Why are you mapping size 0?
oh weird
i do not know
im js following memory mappings blindly
not a valid return address
that is the hpets address???
OH WAIT THAT MAKES SENSE
Also this is kinda inconsistent vmm(x86_64)(): mapped 0xffff800000000000 to 0xffff800000200000 : from phys 0x0 to 0x200000
vmm(x86_64)(): mapped 0xffff800000000000 to 0xffff800000200000 : from phys 0x0 to 0x200000
vmm(x86_64)(): mapped 0xffff800000000000 to 0xffff800000800000 : from phys 0x0 to 0x800000
?
yea i dont know
this is weird
and page fault handler is dying very weirdly
i dont know at all
But like don't print what you're mapping
for (uint64_t i = 0; i != memmap_request.response->entry_count; i += 1) {
struct limine_memmap_entry *entry = memmap_request.response->entries[i];
switch (entry->type) {
case LIMINE_MEMMAP_FRAMEBUFFER: {
uint64_t disalign = entry->base % MIB(2);
entry->base = align_down(entry->base, MIB(2));
uint64_t page_amount =
align_up(entry->length + disalign, MIB(2)) / MIB(2);
for (uint64_t j = 0; j != page_amount; j++) {
map2mb(take->root, entry->base + (j * MIB(2)),
hhdm_request.response->offset + entry->base + (j * MIB(2)),
PRESENT | RWALLOWED | WRITETHROUGH | PATBIT2MB);
}
kprintf("vmm(x86_64)(): mapped 0x%lx to 0x%lx : from "
"phys 0x%lx to 0x%lx\n",
hhdm_request.response->offset + entry->base,
hhdm_request.response->offset + entry->base +
(page_amount * MIB(2)),
entry->base, entry->base + (page_amount * MIB(2)));
hhdm_pages += page_amount;
break;
}
case LIMINE_MEMMAP_BAD_MEMORY: {
break;
}
case LIMINE_MEMMAP_RESERVED: {
break;
}
default: {
uint64_t disalign = entry->base % MIB(2);
entry->base = align_down(entry->base, MIB(2));
uint64_t page_amount =
align_up(entry->length + disalign, MIB(2)) / MIB(2);
for (uint64_t j = 0; j != page_amount; j++) {
map2mb(take->root, entry->base + (j * MIB(2)),
hhdm_request.response->offset + entry->base + (j * MIB(2)),
PRESENT | RWALLOWED);
}
kprintf(
"vmm(x86_64)(): mapped 0x%lx to 0x%lx : from phys 0x%lx to 0x%lx\n",
hhdm_request.response->offset + entry->base,
hhdm_request.response->offset + entry->base + (page_amount * MIB(2)),
entry->base, entry->base + (page_amount * MIB(2)));
hhdm_pages += page_amount;
break;
}
}
}
hhdm_pages = (hhdm_pages * MIB(2)) / 4096;
Walk over the page tables and print the contents
this is what i do
ill use gdb pt dump as im lazy
anyways not doing the stacktrace doesnt kill nyaux
so
commenting out the stacktrace for now
ummm
cr2 is completely wrong
NOT QUESTIONING IT
js gonna
do as u asked
that is the mappings
first address
second
third
4th
(gdb) pt -walk 0xffffffff80001000
Page table walk for VA = 0xffffffff80001000
CR3 = 0x3a6d000
PML4[511] = 0x3a6c000 | Flags 0x027
PDP[510] = 0x3a6b000 | Flags 0x027
PD[0] = 0x3a6a000 | Flags 0x027
PT[1] = 0x1fe2000 | Flags 0x021
5th
(gdb) pt -walk 0xffffffff80087000
Page table walk for VA = 0xffffffff80087000
CR3 = 0x3a6d000
PML4[511] = 0x3a6c000 | Flags 0x027
PDP[510] = 0x3a6b000 | Flags 0x027
PD[0] = 0x3a6a000 | Flags 0x027
PT[135] = 0x2068000 | Flags 0x021
6th
and now
7th
(gdb) pt -walk 0xffffffff80095000
Page table walk for VA = 0xffffffff80095000
CR3 = 0x3a6d000
PML4[511] = 0x3a6c000 | Flags 0x027
PDP[510] = 0x3a6b000 | Flags 0x027
PD[0] = 0x3a6a000 | Flags 0x027
PT[149] = 0x2076000 | Flags 0x003
@flat nymph
nyaux master poopcode win
ummmmmmm i guess? from what it looks like?
tho some entries look weird
i think
well the third one looks fine
flags look correct tho which is good
The problem is still that you're likely looking for UB that only happens on specific hardware and not qemu. So it's likely you wont find it in qemu
Since the UB works in your favor in qemu
want me to prove u wrong by getting nyaux to load
on my laptop
if the 4gib meme was the actual problem
ill be happy
@flat nymph u still busy?
Yes

have you been able to reproduce the issue in qemu or some vm
before you have done that or are able to debug on your laptop, you are just taking shots in the dark
not saying you wont hit anything but seems like a very tedious process
no
and yea it kind of makes sense why it dies now.
a lot of overrlapping entries
a LOT
and no idea how to fix this

I dont really see any overlap
I mean sure u are mapping the same regions many times but thats not overlap
unless they are meant to be unique virtually too
yea ig
but then
i dont know whats going on then
i removed the unconditally 4gib mapping
which breaks all mmio, and nyaux symbol loading for some reason
still doesnt want to load

the hhdm 4gig mapping?
yea, before i map the memory map i would unconditally map the above 4gib region
yeah thats fine
now obviously would be nice to optimize it with 4 x 1gig mappings but thats an optimization u can do later
can u link those messages
well technically thats correct, you might not need it
interesting
on qemu it really shouldnt be necessary
as long as the memory map is mapped
real hardware is dodgier so that 4gib mapping is nice
yeaa
So do you have any clue what goes wrong on real hardware
no
Well lets start there then, how far along do you get
can you show what code you use to print those.. things?
to switching cr3
like what is overlapping
yea
kk
map memory?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
ill js
give u the entire function
yes map the memory map
your problem is that you're assuming every entry has 2MiB aligned base and length
from a quick look at the very least
yeap
but i have the disalign and i add it?
only doing 2mb mappings
that won't work
so what do i do
map 4kib pages
no
or lose the alignment
you can ceil the base and floor the end
but you are wasting memory
actually hold on
im dumb, you cant do that
#define FOUR_KIB (4*1024)
#define TWO_MIB (2*1024*1024)
#define ONE_GIB (1*1024*1024*1024)
while (length >= FOUR_KIB) {
if (is_aligned(addr, ONE_GIB) && length >= ONE_GIB) {
map_1gib(...);
addr += ONE_GIB;
length -= ONE_GIB;
} else if (is_aligned(addr, TWO_MIB) && length >= TWO_MIB) {
map_2mib(...);
addr += TWO_MIB;
length -= TWO_MIB;
} else {
map_4kib(...);
addr += FOUR_KIB;
length -= FOUR_KIB;
}
}```
now, you can probably clean that up a little bit
but this is necessary
you cant just round down an entry and map it as 2mib page lol
yeah was about to say
the memory entry has clear boundaries
btw this answers why u needed the 4gib mapping
mapping the entries failed because u were doing it on unaligned boundaries but the 4gib mapping was aligned
honestly prolly the only reason this works on qemu is because the entries are all or mostly below 4gib
here, i updated the code so it's a bit more C-like
can i steal ur is aligned function
i dont know how to do basic math 
#define is_aligned(value, align) (((value) & ((align) - 1)) == 0)
assuming align is a power of 2
thanks
i wrote it in this discord chat, this should probably be some sort of a function so it's properly typed
okay
made this function
bool is2mibaligned(uint64_t addr, uint64_t length) {
if (is_aligned(addr, MIB(2)) && length >= MIB(2)) {
return true;
} else {
return false;
}
}
you did not need a function to specifically check that but sure yeah
if (is2mibaligned(entry->base, entry->length)) {
uint64_t disalign = entry->base % MIB(2);
entry->base = align_down(entry->base, MIB(2));
uint64_t page_amount =
align_up(entry->length + disalign, MIB(2)) / MIB(2);
for (uint64_t j = 0; j != page_amount; j++) {
map2mb(take->root, entry->base + (j * MIB(2)),
hhdm_request.response->offset + entry->base + (j * MIB(2)),
PRESENT | RWALLOWED | WRITETHROUGH | PATBIT2MB);
}
kprintf("vmm(x86_64)(): mapped 0x%lx to 0x%lx : from "
"phys 0x%lx to 0x%lx\n",
hhdm_request.response->offset + entry->base,
hhdm_request.response->offset + entry->base +
(page_amount * MIB(2)),
entry->base, entry->base + (page_amount * MIB(2)));
hhdm_pages += page_amount;
} else {
uint64_t disalign = entry->base % 4096;
entry->base = align_down(entry->base, 4096);
uint64_t page_amount =
align_up(entry->length + disalign, 4096) / 4096;
for (uint64_t j = 0; j != page_amount; j++) {
map(take->root, entry->base + (j * 4096),
hhdm_request.response->offset + entry->base + (j * 4096),
PRESENT | RWALLOWED | WRITETHROUGH | PATBIT4096);
}
}
i do an if statement
if its aligned
map with 2mib
if not
wtf is this
4kib
do not do this disalign bullshit anymore
oh no
dont apologize
no aligning down as well
nope
okay
this is better now
im scared qookie is typing a long paragraph
am i about to be cooked
sure yeah that looks better
pray for me iretq
progress = 0
while (progress < size) {
if (size - progress >= 2M && !(base + progress & (2M - 1))) {
map_2M_page(addr)
progress += 2M;
} else {
map_4K_page(addr);
progress+= 4K;
}
}```
^
basically the same except more complicated 



so close
uh huh
yea idk why that is failing

its just like changing that 2mib entry into a bunch of smaller 4kib ones
so why is it failing

oh thanks ubsan
store to null pointer of type uint64
whats the null poninter exactly tho
???
im confused
is it guy[j]????
he should be valid tho
cr2 is 0x0

all guy is is just ```C
uint64_t *guy = (uint64_t *)((uint64_t)pmm_alloc());
oh
we ran out of memory

come on like why am i running out of memory
should i be running out of memory
???
do yall know
uint64_t page_amount = align_up(entry->length, 4096) / 4096;
for (uint64_t j = 0; j != page_amount; j++) {
map(take->root, entry->base + (j * 4096),
hhdm_request.response->offset + entry->base + (j * 4096),
PRESENT | RWALLOWED);
}
kprintf("vmm(x86_64)(): mapped 0x%lx to 0x%lx : from "
"phys 0x%lx to 0x%lx\n",
hhdm_request.response->offset + entry->base,
hhdm_request.response->offset + entry->base +
(page_amount * 4096),
entry->base, entry->base + (page_amount * 4096));
hhdm_pages += page_amount;
thats the logic
fun so we ran out of memory trying to map the memory map
:)

yea no idea if i should be running out of memory in the first place
this is on qemus default ram
me rn
likely no
at least with full 2mb pages for the hhdm
I meant to reply to the "if i should be running out of memory in the first place"
ohhh
yea
so no idea whats going on

help
with what
i dont get why im running out of memory
pmm issue
no its not
the pmm is fine
its so simple
it cant have an issue
its like 73 lines of code lmao
add more RAM then
qemus default ram is 256mb
i should not be taking that much ram
hm
with what you have issue
it's taking up that much RAM while doing what exactly?
mapping the memory map
what?
yea
fine
are you mapping the HHDM or smth?
mhm
he mapping hhdm
did you try using larger pages for the HHDM? that'll be faster during translation misses anyways
ofc i am
i used before
but now because of alignment
4k pages forever
i have to use 4096 byte pages if they arent aligned to 2 MiB
because of real hw issue
ya? that sounds about right
if real hw crashing, it's vm issue
memory leak somewhere?
no
skill issue
then somewhere you're overcommitting pages, I'd say
try to make your vmm cleaner
deal with it 
presumably in the mapping functions
please make code cleaner like this
https://github.com/sys-q/quackOS/blob/main/src%2Fsource%2Fkernel%2Fmm%2Fvmm.c
x86_64 OS. Contribute to sys-q/quackOS development by creating an account on GitHub.
the mapping functions are fine
like they shouldnt be overcommiting memory
im js asking for ONE page
i see that we all have different definitions of "clean code"
wait why pte shift is 48
48 bit virtual addressing
exactly
dont u see the shift -= 9
mhm
what mhm means
yes
isn't this pml4 shift
by shifting the virtual address right by 39 bits you put the 9 bits used to index the page table at bit 0
so (va >> 39) & 0x1ff gives you the index
and think about users

about "copypasters" and mishakov
no deal with the readablity

okay but seriously i need a break im too frustrated
Valid, take your time 
im back and im not feelings happy rn
with nyaux fucking running out of memory
๐ก
time to read the code line by line ig
char by char
lmao
maybe your pmm is pooped
bit by bit
little != working
I can write an abomination on just a single line
I am on phone
and? u can join on ur phone lol
I hear some monkey in voice
yes
finally
is this your bf ?
I think the opposite
๐ญ
okay this girl im cooking with
i got the rizz with her
tho she has a strong irish acent
omg
classic if true return true else return false
i realized the problem
When you're paid by lines of code
IT WORKED
NYAUX WORKED
ON MY LAPTOP
TEST IT YALL
EVERYONE ONE OF YOU
@kind root my laptop has kinda weird aml
that needs a reboot and a spare flash drive
weird aml or your unimplemented kernel api
even on like other kernels
weird aml of course
what are the errors
im sure its because some didnt impl some things in uacpi
try pmos on it
k
or just send a screenshot of what errors u get
acer predator trition PT14-51
i didnt take any
๐ญ
but i swear @kind root i saw no errors
my laptop has a ec controller
cool!
so whats weird about it lol
yep
anyways
now
we fixed all the bugs we encountered before doing the scheduler
its time for the scheduler
tomorrow we will



my code yeah?
looks fine
only thing i can think of is the macro doing some weird implicit narrowing but like idk looks fine to me
idk if i can do any development today
wsl has stopped working
and
i rebooted
and tried wsl --shutdown
and stuff
and it wont work

i mean obviously i will get development done today
i js
need to figure out this windows skill issue
github js said i have "free access to copilot"
lmao like i care
i do too for some reason
same
Everyone has it now
It might be a problem form my side, tho it doesn't work :/
Neither bios nor uefi
thats an old iso
hi omar, I'm omar
can u try this?
also whats ur cpu
AMD E-350D iirc
It's a random mini PC I've got lying around
Yup it is
when was rep stosb and friends introduced into the instruction set @molten grotto
i suspect its that instruction
they have always been there
since when
i feel like its probs because im relying on something thats quite new
causing it to page fault
as it doesnt page fault on most hw
could be popcount if it crashes at uacpi
and when was that introduced
oh
also idk why would it page fault and not ud or whatever
Well, seems like it works-ish :D
oh it works
yay
nvm
we are all good
nyaux is not UBing thankfully
i should change that panic message to
32 bit hpet buddy
because i dont support a 32 bit hpet lol
no change it to
"NyauxKC does not support 32-bit HPETs"
because it took me a good second or two to realize what you meant
the panic message sounds like you only support 32-bit HPETs
yeah
for example in obos:
if (!(timer->timerConfigAndCapabilities & (1<<5)))
OBOS_Panic(OBOS_PANIC_DRIVER_FAILURE, "HPET Timer is not a 64-bit timer.");
uacpi_status uacpi_kernel_handle_firmware_request(uacpi_firmware_request* req)
{
switch (req->type)
{
case UACPI_FIRMWARE_REQUEST_TYPE_BREAKPOINT:
break;
case UACPI_FIRMWARE_REQUEST_TYPE_FATAL:
OBOS_Debug("Firmware requested fatal error. Panicking.\n");
OBOS_Panic(OBOS_PANIC_FATAL_ERROR,
"Your bios fucked up, so now you have to deal with the consequences, also known as possible data loss. Firmware Error Code: 0x%016x, argument: %016lx\n",
req->fatal.code, req->fatal.arg);
break;
default:
break;
}
return UACPI_STATUS_OK;
}```
I should remake that panic message
Disabled the HPET from the bios because I can
lol
It's a thing lol
crazy
"Your firmware shat itself, so now obos will shit itself. Firmware Error Code: 0x%016x, argument: %016lx\n"
lool
my wsl is broken
i cant fix it
time to nuke wsl install?
nuked it and it got solved
I think a lot of people disable it because "it makes games lag"
nyaux confirmed not for gaming because it uses hpet
bruh
Idk I think (supposedly) Windows uses it wrong and it's slow/broken on AMD or something
I've been arguing about it with my friend a couple of months ago
Who also insisted on me using Windows optimizers
oof ๐ญ๐
the hpet is pretty slow
i got sick today
๐ญ ๐
my sister gave me a throat infection
so ima do a coin flip, if a girl txts me within 2 hours ill work on scheduler
if no
not today
@edgy pilot give me a link
it would take me the same amount of time as you to go and look for it
or "go to file"
on github
smh
lmao my luck, i grepped for 2 of the ubsan functions that linux doesn't implement
qookie@selenium ~/projects/mlibc/linux-6.1.8 ฮป rg __ubsan_handle_nonnull_arg
qookie@selenium ~/projects/mlibc/linux-6.1.8 ฮป rg __ubsan_handle_vla_bound_not_positive
qookie@selenium ~/projects/mlibc/linux-6.1.8 ฮป
hmm I have never encountered those
i've seen __ubsan_handle_vla_bound_not_positive get triggered in the wild (not in managarm, but in foot on linux)
FOUND IT
lol
I think I found it as well
๐ญ
wait
I found it
Can nyaux get more stars than Linux
no
why
I'll star it whenever it runs doom
Then yeah u have my conditions
What
wait it doesnt need pci??
is there a spec i can read
kk
Look at pmos as an example
I don't really know what embedded controllers are
microcontrollers
Just abstraction over firmware state
Get/set a byte
whats firmware state
translation: just some retarted ACPI thing
what is it used for
some retarted ACPI thing
thing which makes your computer go wroom wroom when you press buttons on its case
Like fan on/off, temperature of something, feature on off, current os, etc
?
what button do you mean
power button (sometimes)
wait i set the current os running in firmware state???
how to do this
On laptops it's battery, lid, chargers, fans and other stuff
He means that EC may ask you to run certain AML as a response to an event, which may be a power button press
ah
Not u, the aml
wait does uacpi automatically do this for me or?
Yes
how
magic
It tells aml you're windows 11
๐ญ
(which I am)
๐ญ ๐ญ ๐ญ
((nvm that's an insult to obos))
and what if you told aml ur nyaux
it becomes sad
It would proceed to off itself
about equal stability-wise
what is that used for
Mostly backwards compat checks
no but really though
although idk, windows 11 is really bad on my PCs
it's stuttery and laggy?
E.g. some devices are not reported entirely, some pretend to be something else, extra init taken care of by aml, etc
Even Linux tells ACPI it's Windows
ik
Everything is crashing all the times
okay
It doesn't ask for nyaux, it queries specific os names
so just bad design?
Yeah
if I tell acpi I'm windows 12 do I get access to the secret windwos build
like windows or linux?
yes
Yes
It assumes oldest os
Its often untested code too, because they mostly test newest stuff
how long does it take to implment a EC controller driver
Like an hour
That's a single function
Ask mishakov for assistance he recently implemented one that works well
@flat nymph
@surreal path
Dont blind ping
๐ญ
Just ask when you have questions lol
okay lol
Needs one copy per each undefined reference 
good night @edgy pilot
why is linux bit shiffting data alignment by 1
why is linux doing that lol
anyone know?
the alignment is stored as log_2 of the value
1<<x is the same as 2**x and 2**log_2(x)=x
It's quite easy once you see it
Yes
okay
the alignment is always a power of 2, so instead of storing 2**x as a number you can just store x since getting the alignment from that is simple
If you have 100.000 and move the point 1 right, you get 1000.00, which is multiplying by 10
Is the same with 0b100 to 0b1000
You multiply by 2
why are u multipling it by 2
? whats the purpose
I.e. what you study at school
They give you log2(alignment)
Soy you convert it back by doing 2^value
added this
Why are you shifting it right?
sorry
mistake
there
no need to do this anymore
actually ill js remove what i js added
wth is that indentation
this is for v2
This is the same as if (data->alignment)
since linux doesnt shift it
oh
didnt i take this from u
fix it
I don't have sanitizers
hold on
i mean it's a pretty simple pattern for the compiler to figure out and optimize anyway
oh yeah this
Yeah, except that the code becomes unreadable when it's full of stuff like this
ill js copy what linux does
the compiler knows that in (1<<x)-1 x is in [0,64) so the only value of x for which this is true is 0
Although if Nyaux just gets rewritten every few months...
and nuke the entire file
it wont
im sticking to this
here's the managarm one for reference btw :^) https://github.com/managarm/managarm/blob/master/kernel/thor/generic/ubsan.cpp
Maybe I'll steal it later 
not always
Or optimizes shit out and you get insane bugs 
yeah
My kernel doesn't have framebuffer output so there is nowhere to complain to about UB (sanitizers) 
okay i did what linux does for v1
ish
im js gonna follow up with what linux is doing and if there is any missing functions reference the linux functions for them
nvm linux is missing some clang functions???
not even managarm does it?
the hell
wait does it really
that's wild
yea because firmware developers started putting in buggy and untested code paths in aml for linux
so now linux no longer says it's linux
im taking obos's ubsan im too sick for this
you mean sortix' ubsan, right
yea
huh???
it has a complete type
bro
oh right
nvm
well clang compilers
it works perfectly on debug build
oh waits
its running at o2
think
yea it is
i ran nyaux on o3
it worked fine???
less goo
??
nyaux on clang???
worked perfectly?
even on -Ofast??
damn
well nyaux runs on clang
:)
on tcg
gcc
-O2
oh
on clang
this happens
I will never understand how nyaux has more "committed memory" than obos when it doesn't do half as much
ubsan says nothing
idk what to do
it said it foudn it
and didnt return it?
bro what
so
why is the if statement succeding
omg
gcc
im stupid
and gcc didnt catch this
yay im sticking to clang
:)
slightly better
with clang
gcc probs generated the call
to return the value
or smthin
meanwhile an ignorant nyaux, just a mere hour or two ago:
infy we hate clang am i right or am i right
yes
๐ญ
ummm
on kvm???
thats
38k
wtf
hitting 43k
@finite summit
whats the highest obos has
with or without bump allocator?
without
no
no, I'm not telling you

no swapping?
i have a vmm


soon โข๏ธ
we have spinlocks
*almost no


not until you get pci

also:
[uACPI][INFO]: successfully loaded 1 AML blob, 1704 ops in 8ms (avg 199539/s)```
I got this on my other pc
dman nvm
with the scheduler disabled on uacpi init
i submit
idk why, but everything I do on this pc is magically 10x faster
tf is proxima
ah
Only qemu counts lol
Oh wait that is qemu I think?
Which cpu
It is
Intel i5 4570
i dont think that matters much
man im so sick
ugh
i took a bunch of medience
earlier
still sick
this is legit cringe
how tf am i gonna work on nyaux like this

just don't
i believe what ilobilo was trying to say is just don't be sick
tbh i work on projects better when I'm sick
bru
do you like the pain
the constant coughing
do u like
that
nah not that
coughing is pain
but like
when i'm calling in sick to school
with a fever or something
or a runny nose
or diarrhea
it's fun
especially diarrhea
can't
you
people
type
messages
on
a
single
line?
it's
very
annoying
to
read
this
way

sorry but this is how my brain works
i cannot type a full sentence
wait i just
did
instead of pressing send, imagine that you did and continue typing
ok i
it's not hard
yea but seriously i enjoy when i need to run to the bathroom immediately because it acts as a deadline
nyauxmaster
next time you get diarrhea please try this. i guarantee you it will work wonders
ok
i set myself a goal and i award myself with a bathroom break and if i can't do it until i shit myself, that's a punishment
yea this is about doing projects with diarrhea
omg pastafarian
R'amen brother
