#Nyaux
1 messages · Page 8 of 1
except for him it's over 16 days
me it's over a couple of months
I mean tbf I do kind of spam my thread
A lot more while debugging the allocator bugs
also I'm the same as him in terms of development of my OS, I do it usually near-immediately when I get back from school
although about two weeks ago I got terraria, and I'd played it for every day instead of osdev
anyway enough literring this thread
but half of them are after April 1st 2024
true
how big should the bump allocator be
in pages
gonna allocate one big vmm region for it
idk however big you want it to be
idk how much pages uacpi will need
yeah
just make sure that alloc checks if there is enough room left
keep that around somewhere so you can check and not return bad pointers
return null at the end
and use size elsewhere
if it fails
but his kernel also uses it
oh lol
i mean presumably
yea it does
well im not replacing the allocator for the kernel
just for the
uacpi
well you should also replace it for kernel if it doesnt solve the issue
yea okay i wil
in that case
man that was quick
10 pages is too little
lol
wow
i screwed up a bump allocator
first time it tries to allocate it fails!
impressive
bro corrupted his bump allocator
i screwed up a fkn bump allocator 💀
now thats next level oberrow instability
fair, 40k isnt much
aml execution context alone is 2 pages
this is not 400 mb
what is that then
0.4 mb
oh
it says right there..
runs with 1000 pages
doesnt die anymore?
inb4 out of memory
thats nice
replace the allocator for the entire kernel with a bump
okay
yea same thing
at least it isnt the allocator
seeing as u fucked up even the bump allocator thats very well possible
this is legit all the code
#include "lib/kpanic.h"
#include "main.h"
#include "vmm.h"
#include "drivers/serial.h"
uint64_t base = 0;
uint64_t max_size = 4096 * 10000;
char meow[64];
void bump_init()
{
base = vmm_region_alloc(max_size, NYA_OS_VMM_PRESENT | NYA_OS_VMM_RW);
max_size = base + max_size;
}
void *bump_alloc(size_t size)
{
if (base < max_size && base + align_up(size, 8) < max_size)
{
size_t aligned = align_up(size, 8);
void *result = base;
base += aligned;
return result;
}
else
{
kpanic("Out of Memory!\n", NULL);
return NULL;
}
}
this is the entire file
can u try giving qemu 8 gigs of ram
ok
you need to keep base and offset from the base
currently
you are checking if the address allocated and bumped is < the max size
doesnt fault
what did you change?
ok
this number is in hex?
ok
?
you are setting base to the address of the region you allocate for the heap and then you compare it to the max size you allocate
trying out now
bruh
these bugs are unfathomable
focus
ok
so
ok yeah so definitely not related to the allocator
yea
so probably you're corrupting some uacpi memory somewhere
i replaced every allocation call with the bump allocator too
in the kernel
how would that prevent use-after-free or out-of-bounds
Implement KASAN
i removed every free, i just dont free with the bump. as for out of bounds i make very little allocation calls in the kernel and i've looked over how im using each bit of memory and seems fine
im not doing anything else while uacpi starts
also like
kasan?
kernel address sanitizer
to trace like what each variable contains
in that function where it dies etc
like learn printf debugging
or u even have gdb u can inspect it yourself
i will put printfs everywhere again
enable UACPI_LOG_DEBUG too
okay
UACPI_LOG_TRACE
ok
this might take a while
since im printing every single fkn call
opening in vbox
same thing
addresses being returned look valid
same fault
like
just put afucking printf in the function that prints out absolute path
see what branches its taking
how its ending up with a null
seriously like
ok
how is it not the first thing that you do
because i dont know what you want me to do, im sorry for making you feel frustrated. ill put the printfs into the absolute path now
i want you to visualize the code flow with printfs
you have inspected the abort function before
you see that its ending up with null but you dont know how
yea
now to figure that out you put printfs
to figure out the code flow that leads up to that
okay i will
do that
you're not printing out the absolute path pointer
oh whoops
also there's a uacpi_trace shorthand
huh
so your nanoprintf port is broken somehow
so its not rlly my fault then?
it is
in which way
ok
i can screenshare the code on my screen in #voice-1 if you'd like, or ill provide the pastebin or screenshots, or i can push everything to github for u to see
whatever works best for u
what line is it faulting at in nanoprintf
also why am i not seeing %zu formatted here?
i do not know
here
these are the defaults nanoprintf uses
okay
#define NANOPRINTF_IMPLEMENTATION
#define NANOPRINTF_USE_FIELD_WIDTH_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_PRECISION_FORMAT_SPECIFIERS 0
#define NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS 0
#define NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS 1
#define NANOPRINTF_USE_BINARY_FORMAT_SPECIFIERS 0
#define NANOPRINTF_USE_WRITEBACK_FORMAT_SPECIFIERS 0
#define NANOPRINTF_VISIBILITY_STATIC```
i do this
precision is also needed, uacpi uses that a lot
no, like %.4s
oh nvm
string with up to 4 chars
yeah i just checked the npf code again
they have checks that you dont enable conflicting options
or rather disable options without disabling everything it relies on
but they make sure that if you enable float you enable specifier
so i was misremembering
oh frick u
@surreal path so i think i know what happened
u disabled %zu
and it tries to print #0 in \
but its end up printing #zu in %s where s is 0
because zu never got printed
LMAO
bro
no way it was that
you would have found this out had you actually put printfs in that function first thing
idk how u didnt do that
and instead did all the other shit
next time dont instantly blame my allocator 
i assumed u did the bare minimum debugging
which is fucking printfs in the faulting function
czapek@raptor-wsl:~/source/kernel$ make all
INFO: autodetecting backend as ninja
INFO: calculating backend command to run: /usr/bin/ninja -C /home/czapek/source/kernel/build
ninja: Entering directory `/home/czapek/source/kernel/build'
[3/3] Linking target platform/amd64/kernel
czapek@raptor-wsl:~/source/kernel$ git diff src/main.cpp
diff --git a/src/main.cpp b/src/main.cpp
index a18ce69..db1c388 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,7 @@
#include <lib/print.h>
#include <limine.h>
#include <memory/pmem.h>
+#include <sys/types.h>
#include <system/cpu.h>
using namespace kernel;```
fun
lol urs dont work!
what
pmem: registering physical region 0x4d000-0x9f000, 328 KiB, 82 pages, 4 KiB for PFDB
pmem: registering physical region 0x100000-0x7fdfe000, 2094072 KiB, 523518 pages, 12272 KiB for PFDB
pmem: skipping physical region 0x7ff1d000-0x7ff1e000, too small
pmem: registering physical region 0x100000000-0x180000000, 2097152 KiB, 524288 pages, 12292 KiB for PFDB
phys1: 0x4e000
phys2: 0x4f000
phys3: 0x50000
reached end of _start, halting```
very much works
you mean the PRIXx thingys
with whatever header in your os has size_t
i use stddef
# ifndef __suseconds_t_defined
typedef __suseconds_t suseconds_t;
# define __suseconds_t_defined
# endif```
i love sys/types.h
signed size_t
its legit just stddef
its a completely different type
long
typedef long ssize_t
my eyes
u disabled precision
💀
that is insane
ok
lmfaoo
i hope u learned some debugging lessons from this
then its not in vein
yep
works even with my allocators on vbox
will flash iso to usb and reboot
sec
rebooting
No page fault yet but it’s taking a while
also implement the io helpers lol, its like 4 lines of code
u already have the raw io r/w helpers
what’s the difference between them
read the header
it’s loading it !!!!
things are happening
It’s a lot of stuff tho
Works !!!
Works in real hardware!!!!!!
good job

😭
yea i see what it means now after reading obos's implmentation for it, its simply just an abstraction thingy
yup
i implemented now
i think u also dont call uacpi_initialize_namespace
i dont have events or whatever tf so it doesnt rlly work
lol
also what is a gpe
general purpose event
namespace initialization done
Amazing!
meow
so like, this could mean when you press the power button or smthin thats a gpe?
indeed
ah okay
power button is a fixed event, not a general purpose one
i barely know much about acpi that much to the level yall know 😭
its like 4 lines of code to hook up power button https://wiki.osdev.org/UACPI#Hooking_Up_the_Power_Button
but u must implement register_irq_handler
bruh all I know is "ACPI makes power management go brrr" and "ACPI gives random ah devices that you can't find on PCI"
oh fudge, uhhh
so heres the thing
yea...
i dont have a common stub
then make one
why gsi 9
yeah anyway I got a page table manager to debug
whats on gsi 9
u have the madt table..?
oh right
the common stub?
any idt index u want
ill make a common stub
well i dont actually NEED to. i can use this stub i already have as a common stub in fact!
actually no
i cant
i need the int number
ye
push it urself
how am i gonna "push it myself". this is a common stub, i dont know what interrupt i am in this common stub
use brain
i was about to spoonfeed :^)
lol
bruh
dont
i need to learn not copy code
but really there is only one way to do it
macros and the push instruction
go crazy
you can figure it out
i dont need a common stub as i already have one
i have a register interurpt function
am i fucking dumb
just create the isr stubs
wait
reading ur code @finite summit and why do u push %1-0x20
okay
first 32 numbers are reserved
for the legacy exceptions
yeah
?
you can ignore it
alr
yea i know
oh i think i know why he does that
yea thats smart
then u can like have a common irq handler
and have that handler the irqs
😎
correct?
yes
I say look into my code
and try to see what it does
abstract irq interface is under irq/irq.cpp
if you have any questions you can ping me
alr
bro

line 33 causes a general protecxtion fault now
cause i wanted to add irq to my interrupt frame
@finite summit
pain
should work RIGHT?
wrong !
push everything correctly ! yet it still has the stack get fucked or smthin
wait
why push it twice
you can just call [idt_handlers + %1 * 8] btw
no need to store it in rax first
@finite summitexplain (uintptr_t)(&__b_isr_handler + (i * 32)
i know u aligned all the stubs
but like
u dont know the size of each stub
and im tryna do something similar but the addresses im getting are all wacky
Well all stubs here are pretty much guarenteed to be < than 32 bytes
so with the alignment, that makes all stubs be offset by 32 bytes
i'd recommend you build an array of pointers in assembly
just so you don't have to rely on the fact that each handler is 32 bytes with padding
instead the assembler builds the array for you with all the pointers
hm?
stubs:
dq isr_stub_0
dq isr_stub_1
dq isr_stub_2
; ...
dq isr_stub_255```
except you can do it with some preprocessor magic
?
im sorry what are you confused about?
im thinking second
so ur dq'ing a label
so if u dq a label its just gonna be a pointer to that label?
correct?
the address of that label, yes
oh this is actually much smarter
i mean both ways are valid, but i prefer that one because i rely less on the code padding
ummm
good question
hard to say
without seeing the entire file
also what assembler is that
gas?
nasm
nasm
Look closer
U mean 4:30
3:36 here
it's 21:36 idk what yall mean
we all over the place
in this chat i dont think so
other than @plush hearth
oh i didnt know
he's upside down
i know that andy is an aussie
haha. yes, I'm in Australia
what if they accidentally take off the things on them that make them not fall into space
oh frick u i cant use macros cause nasm hates that

time to write all these out manually
you mistyped
isr_stub_%q maybe
tried
I have spoken to people on discord that actually believe this is true
yeah good luck idk nasm
lol
no, its 11:38 am
There can be some... delusional people on discord to say the least
well not just on discord
but yeah
why cant i use %q 
guess i have no other option but to write all these manually!!!
IT WORKS
IRETQ YOUR SO PRO
😎
i wrote a python script to write the dq's for me
it all works!!!
you are very much welcome
enjoy your objectively better way of making an isr table
username checks out
😭
yes i will!
mister master of interrupts !!!
lmao, I hit the same issue. Although I caught it when I had a few %zus popping up in the logs.
how are u printing it
its a uint64
bro doesnt know how 2s complement works
the heck is that
.
%u is unsigned int
%lu is unsigned long
%ld is signed long
etc
u cant just put a %d there
inb4 using %d
so in this case i need to do lu
oh i was scrolled up
😭
doesnt nanoprintf have __attribute__((format))
idk
nanoprintf may do but the custom wrapper for writing to the screen/serial most likely doesn't

then the compiler will scream at u if u do it wrong
and the compiler can't peek into valist to determine whether format args make sense
anyways i dont know why the irq number is this giant mess
ima figure this out
>>> hex(18446744073709551598)
'0xffffffffffffffee'
sign extended byte 0xee?
do your asm irq stubs do push byte N by any chance
you dont always wanna push the error code
always push a dummy error code in that case
i dont see your whole macro but does it use the exact same one for every exception
no
i have two types of stubs
wait why -0x20
for the ones that push an error code i dont push an error code
push $0
.endif```
you need something like this
0xee+0x20 = 0x10e => 0xe => page fault
cause exceptions 0-32 are reserved
yeah thats correct i didnt see it fully
31
and?
doesnt make sense
just push the interrupt number
no need for -0x20
for whatever reason
He took that from my kernel
cause this is for the like, irq number. i wanna implment something similar to omars implmentation of a irq dispatcher
and I said it was for my irq interface
exposed
yea, i wanna do something similar
thats what i told him lol
and why cant you do that calculation in C?
he has like two separate ones
Because reasons
what reasons
lol
bro cannot run sub rax,0x20 because reasons
and it's supposed to be completely arch-dependant
It takes an interrupt_frame
which is arch-dependant
but has a field that should exist on all archs
intNumber
but you can still do intNumber - 0x20 in your isr can you
No
intNumber not irqNumber
because then it depends on the first 32 vectors being reserved
thats stupid
sounds silly to me
which is x86-specific
anyway
I had a look at your code a few weeks ago does this interrupt dispatcher create these dpc threads you have there?
indeed
thats neat
Except I never got a chance to use them
Because nothing except uACPI could use them
But uACPI needed them to be used in a way that's different than what my kernel does
btw you said you ignore all warnings anyway a while ago, you really shouldnt do that, warnings are emitted for good reasons and you should just take your time to read and fix them if you can
wait it's called vector
i will actually
did I?
fix them warnings
hes talking about me lmao 😭
I had that typed out already but you were faster 🤣
its nyaux thread not obos lol
but you should too if you dont :^)
I have all warnings enabled, just not -Werror to keep compatibility with future GCC versions
In case some future GCC version defines some new warning that my code triggers
ok i do the calculation in C now
learn from this guy :^)
0xe-0x20
yea
you know what happens if you subtract them?
yep
you get a negative result
frame->intnum >= 0x20 ? frame->intnum - 0x20 : idk something
yea i know
yea it is, wait sorry im stupid 💀
give me a second let me think this through
idk why im so slow today
i think its cause i didnt sleep for much
exception 32?
thats not an exception right
its not one of the cpu exception vectors no
sorry im doing a lot of things that are stupid
just let me
think about this
okay heres what im gonna do
you’re gonna print intnum
no
welp
ok wait
i need to think about this very hard
i need to activate my two brain cells

ok
so
we have a global irq dispatcher, right.
void irq_dispatcher(int irq)
{
...
}
okay and this irq dispatcher has an array of function pointers of MAX_IRQ_HANDLERS or smthin
if i want to register an irq
RegisterInterruptHandler(vector, global_irq_dispatacher);
void global_irq_dispatacher(struct interrupt_frame *frame)
{
irq_dispatacher(frame->intnum - 0x20);
}
well im on phone but ill get on pc soon
thanks to huge help from iretq i made the ability to route interrupts and stuff from the ioapic
working on ps2 driver when i get back from store to get bar of choclate
ps2 driver done
again thanks to huge help from iretq for helping me understand a lot of concepts
well um....
vfs now???
nyaux panics if no one consumes the keyboard event buffer and its full

probs should make it clear out the buffer or smthin
pls tell me you dont hardcode ps/2 irqs and io ports
u have literal uacpi to figure that out
oh yeah i forgot about that
@surreal path have fun
implementing the interrupt stuff
for uacpi
:^)
u dont even need that
to find out whether ps/2 exists and where it lives
i mean of course if you have a ACPI impl it's better to use that
qemu micro-pc or whatever doesnt have that i think
it's the proper™️ way of detecting ISA devices
oh i thought that there was a way to ask uacpi to route the irq for you
how could i use uacpi to do that?
wiki finding devices section
that's why i said standard PCs. for example Vinix checks if your hardware is ACPI reduced and refuses to boot
lol
because it hardcodes the resources of ISA devices
is that better?
yeah
i did not know about any better method of detecting standard PCs back then
you cant assume isa exists without checking that
as in, better than checking for ACPI reduced hw
these are separate flags though
so it's not AT_PC, it's IA_PC
hell it's probably wise to check both that, and !reduced
maybe there's some other flag im forgetting idk
after that check it's fine to assume ISA devices are where they are
that's kinda the point of backwards compat luckly
and yeah of course if you have uACPI or something else you should detect them dynamically via ACPI
i am talking for Vinix or other OSes that do not into ACPI
i wonder if there is an acpi way to find out which irq the keyboard uses?
yes!
ofc its unlikely to be != 1
uacpi_get_current_resources()
here:
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
IO (Decode16,
0x0060, // Range Minimum
0x0060, // Range Maximum
0x01, // Alignment
0x01, // Length
)
IO (Decode16,
0x0064, // Range Minimum
0x0064, // Range Maximum
0x01, // Alignment
0x01, // Length
)
IRQ (Edge, ActiveHigh, Exclusive, )
{1}
})
this is a ps/2 _CRS dump from some AML blob
oh that is amazing
oh and i use uacpi_get_current_resources and find the irq resource?
that is so cool
is PNP0303 the id for the ps2 keyboard
yup
lol
here's the entire definition
Device (PS2K)
{
Name (_HID, EisaId ("PNP0303") /* IBM Enhanced Keyboard (101/102-key, PS/2 Mouse) */) // _HID: Hardware ID
Method (_STA, 0, NotSerialized) // _STA: Status
{
If (((PKBD == 0xFF) & (PKBC == 0xFF)))
{
Return (Zero)
}
Return (0x0F)
}
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
IO (Decode16,
0x0060, // Range Minimum
0x0060, // Range Maximum
0x01, // Alignment
0x01, // Length
)
IO (Decode16,
0x0064, // Range Minimum
0x0064, // Range Maximum
0x01, // Alignment
0x01, // Length
)
IRQ (Edge, ActiveHigh, Exclusive, )
{1}
})
how do i use that
wiki doesnt say much about it
and what is this callback for
i dont know, i just want the irq number and port for the keyboard so i can route it
the keyboard has 3 resources
io port 0
io port 1
irq
you iterate the resources uacpi gives u
look at the resource type
if its an io resource u record the io port
if its an irq resource u record the irq
done
oh okay
same for the mouse btw
Device (PS2M)
{
Name (_HID, EisaId ("PNP0F13") /* PS/2 Mouse */) // _HID: Hardware ID
Name (_CRS, ResourceTemplate () // _CRS: Current Resource Settings
{
IRQ (Edge, ActiveHigh, Exclusive, )
{12}
})
u dont have to use that btw
u can just iterate them manually
its just a bit more annoying because they're variable length
ok how do i get the resource
its provided to u in the callback
uacpi_resource_iteration_decision my_callback(void *user, uacpi_resource *resource);
oh
also it's pretty clear what the irq is for, as there is only one and it serves one purpose, but how do you make use of the port io resources? they dont seem to have a description or type or flags or whatever
sorry for a weird question but i dont know how to ask it properly
well you look for a specific device right
aka a ps/2 keyboard
yup
but is it like, i know there are two ports
and i know the first port is the data port?
and for the general kernel resource collision detection u dont care about what they're used for
yeah
the order and types are generally fixed
so i just assume port_io_resources[0] is a data port, and instead of inb(0x60) i do inb(port_io_res[0].port)
you just need to maintain a list of special _HID names for some devices in case the aml does something odd, like say, renaming the device on windows 8 and above 
agreed upon so to speak
yup
lmao yeah
bruh
is there any benefit to doing that opposed to just hardcoding the isa resources?
is there, realistically, hardware out there that deviates?
does windows or linux do that? lol
idk if there's hardware that does that honestly
but technically nothing prevents me from making an emulator that does that
and windows/linux will work there
the technically-correct pc emulator
because they dont hardcode the values
also devices have a _SRS method
sometimes
which allows u to override these
so u could tell the hardware to use a different irq
in that case _CRS will return a different irq every time
is _CRS like a method you call on a resource to get the value of it or whatever
it returns an encoded list of resources consumed/produced by the device at the moment
it faults cause of my callback?
no idea
i dont think it dies in your callback
look at the trace you posted
if (spec->extra_size_for_native)
final_size += spec->extra_size_for_native(spec, data, size);
it dies here
some big memory corruption as usual
offff course
it specifically checks that the function pointer is not null
but then its null somehow
when called
remember the printf technique i taught u
how is it null when called lol
im talking about this place @surreal path
not your code
not that place
i dont know what the callback is in that function ur refering to
final_size += spec->extra_size_for_native(spec, data, size);
yes
what does that mean
thats the callback
you guessed it!
yeah looks like further debugging is required
didnt we already figure that out by looking at the stack trace
it dies when calling that callback
that you just inspected
i dont know but in the stack trace for some reason the rip is 0
like straight up 0
same with the rax
and cr2 is 0
yeah
stack fuckery?
red zone?
-mno-redzone
could be a stack overflow or something
why
your qemu doesn't have popcount i guess
why
-cpu max
ok
or -cpu host
no fault
how did u even get here
-d int
why didnt your kernel catch the invalid opcode
i dont have a handler for it
its a trap so it should've just been an infinite recursion
these functions all have a return value you know
but who cares about compiler warnings
ub?
you dont return anything
ok
ok
its not supposed to go on forever
yea returning it nothing prints
what is it
literally look
ok found it
the return value types are different
now its spamming 0
what did u do
lol
it goes on forever
ok
i see the bug right there
oh
yup
what
think harder
can you show code
ok
static uacpi_resource_iteration_decision ps2_res(void *user, uacpi_resource *resource)
{
if (resource->type == UACPI_RESOURCE_TYPE_IRQ)
{
kprintf("resource irq %d\n", resource->irq);
}
return UACPI_RESOURCE_ITERATION_CONTINUE;
}
static uacpi_ns_iteration_decision found_ps2(void *user, uacpi_namespace_node *node)
{
uacpi_resources *kb_res;
kprintf("Bruh\n");
uacpi_status ret = uacpi_get_current_resources(node, &kb_res);
kprintf("Um\n");
if (uacpi_unlikely_error(ret)) {
kpanic("unable to retrieve Get PS2 resources", NULL);
return UACPI_NS_ITERATION_DECISION_NEXT_PEER;
}
uacpi_for_each_resource(kb_res, ps2_res, NULL);
return UACPI_NS_ITERATION_DECISION_CONTINUE;
}
void ps2_init()
{
uacpi_find_devices(PS2K_PNP_ID, found_ps2, NULL);
for (;;)
{
asm ("hlt");
}
}