#Nyaux

1 messages · Page 8 of 1

worldly condor
#

lemme check the message count

#

on the same order of magnitude

finite summit
#

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

worldly condor
#

but half of them are after April 1st 2024

finite summit
#

true

surreal path
#

how big should the bump allocator be

#

in pages

#

gonna allocate one big vmm region for it

thorn bramble
#

idk however big you want it to be

surreal path
#

idk how much pages uacpi will need

thorn bramble
#

me neither

#

just give it 16 pages

#

if its not enough

#

bump it up

#

lol

kind root
#

yeah

thorn bramble
#

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

surreal path
#

something like this i guess

#

then i return result

thorn bramble
#

you can do size = align_up(size, 8)

#

at the start

kind root
#

return null at the end

thorn bramble
#

and use size elsewhere

kind root
#

if it fails

thorn bramble
#

oh yeah that too

#

and if the check fails make sure to panic

kind root
#

nah its fine if it fails

#

he will see a UACPI_STATUS_OUT_OF_MEMORY somewhere

thorn bramble
#

but his kernel also uses it

kind root
#

oh lol

thorn bramble
#

i mean presumably

surreal path
#

yea it does

#

well im not replacing the allocator for the kernel

#

just for the

#

uacpi

thorn bramble
#

well you should also replace it for kernel if it doesnt solve the issue

surreal path
#

yea okay i wil

#

in that case

#

man that was quick

#

10 pages is too little

#

lol

#

i screwed up a bump allocator

#

first time it tries to allocate it fails!

thorn bramble
#

impressive

kind root
surreal path
kind root
#

now thats next level oberrow instability

surreal path
#

4096 * 10 is not 32

kind root
#

bro

#

can you focus

surreal path
#

im trying to

#

oh i know what i did wrong

#

yea 10 pages isnt enough

thorn bramble
#

fair, 40k isnt much

kind root
#

aml execution context alone is 2 pages

surreal path
#

giving it 400mb

kind root
#

this is not 400 mb

surreal path
#

what is that then

kind root
#

0.4 mb

surreal path
#

oh

kind root
#

it says right there..

surreal path
#

runs with 1000 pages

kind root
#

doesnt die anymore?

surreal path
#

no

#

on qemu fine

#

time to test on vbox

kind root
#

try vmware

#

vbox i mean

#

yea

finite summit
#

inb4 out of memory

surreal path
#

still faults

#

not an allocator issue

kind root
#

thats nice

thorn bramble
#

replace the allocator for the entire kernel with a bump

surreal path
surreal path
#

yea same thing

thorn bramble
#

then you are doing something very wrong somewhere else

#

good luck!

surreal path
#

at least it isnt the allocator

kind root
#

seeing as u fucked up even the bump allocator thats very well possible

surreal path
# kind root 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

kind root
#

can u try giving qemu 8 gigs of ram

surreal path
#

ok

kind root
#

then setting the base to 4294967296

#
  • hhdm
#

bypass your region alloc shit

thorn bramble
#

you need to keep base and offset from the base

#

currently

#

you are checking if the address allocated and bumped is < the max size

surreal path
thorn bramble
#

that is so wrong

#

not the reason it doesnt work

#

but its just broken lol

kind root
surreal path
#

doesnt fault

kind root
#

yeah thats not even what i aksed

#

set the base to 4GiB + hhdm

surreal path
#

ok

kind root
#

bypass your region managament

#

and set vbox ram to 8 gigs as well

surreal path
kind root
#

0x100000000

#

this is where the higher memory starts

surreal path
#

ok

surreal path
#

sec

#

ok gave vbox 8gb and did the hhdm thing

thorn bramble
# surreal path ?

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

surreal path
#

trying out now

thorn bramble
#

doesnt that sound stupid?

#

address < size

kind root
#

bruh

thorn bramble
#

not even the right units to compare

#

obvious logic error

kind root
#

these bugs are unfathomable

surreal path
#

im sorry

thorn bramble
#

why are you sorry

#

☠️

kind root
#

focus

thorn bramble
#

exactly

#

fix bug

#

dont apologize

surreal path
#

ok

kind root
surreal path
#

same thing

#

same fault

#

same exact fault

kind root
#

ok yeah so definitely not related to the allocator

surreal path
#

yea

kind root
#

so probably you're corrupting some uacpi memory somewhere

surreal path
#

in the kernel

kind root
#

how would that prevent use-after-free or out-of-bounds

finite summit
#

Implement KASAN

surreal path
surreal path
kind root
#

also like

surreal path
kind root
#

u didnt even put a single printf

#

in uacpi code

finite summit
kind root
#

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

surreal path
kind root
#

enable UACPI_LOG_DEBUG too

surreal path
#

okay

kind root
#

or whatever thats called

#

the log level

surreal path
#

UACPI_LOG_TRACE

kind root
#

DEBUG

#

not trace

surreal path
#

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

kind root
#

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

surreal path
#

ok

kind root
#

how is it not the first thing that you do

surreal path
#

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

kind root
#

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

surreal path
#

yea

kind root
#

now to figure that out you put printfs

#

to figure out the code flow that leads up to that

surreal path
#

okay i will

kind root
#

do that

surreal path
#

this makes zero sense

kind root
#

you're not printing out the absolute path pointer

surreal path
#

oh whoops

kind root
#

also there's a uacpi_trace shorthand

surreal path
kind root
#

so your nanoprintf port is broken somehow

surreal path
#

so its not rlly my fault then?

kind root
#

it is

surreal path
#

in which way

kind root
#

lets see how u implement it

#

i know nothing about nanoprintf

surreal path
#

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

kind root
#

what line is it faulting at in nanoprintf

surreal path
#

this line

#

second

kind root
surreal path
#

these are the defaults nanoprintf uses

thorn bramble
#

large format specifiers

#

enable them

surreal path
#

okay

thorn bramble
#
#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

kind root
#

precision is also needed, uacpi uses that a lot

thorn bramble
#

precision is for floats

#

i think

kind root
#

no, like %.4s

thorn bramble
#

oh nvm

kind root
#

string with up to 4 chars

thorn bramble
#

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

surreal path
#

oh frick u

kind root
#

@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

thorn bramble
#

LMAO

surreal path
#

bro

thorn bramble
#

no way it was that

surreal path
#

is that my fucking issue

#

IS THAT

#

MY MOTHER

#

FUCKING

#

ISSUE

#

bro.

kind root
#

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

thorn bramble
#

this is so funny

#

holy fuck

surreal path
#

next time dont instantly blame my allocator halfmemeright

kind root
#

i assumed u did the bare minimum debugging

#

which is fucking printfs in the faulting function

surreal path
#

bruh

thorn bramble
#

hmm i wonder why it works for me

#

maybe i dont pass -nostdinc

surreal path
kind root
#

just replace it

#

with your types

thorn bramble
#
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

surreal path
#

lol urs dont work!

kind root
#

what

thorn bramble
#
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

surreal path
#

oh

thorn bramble
#

using %zx for all addresses in my kernel

#

seems to work fine

surreal path
thorn bramble
#

its just a types header

#

oh just copy them from your system headers

kind root
#

with whatever header in your os has size_t

surreal path
#

i use stddef

thorn bramble
#
# ifndef __suseconds_t_defined
typedef __suseconds_t suseconds_t;
#  define __suseconds_t_defined
# endif```
#

i love sys/types.h

surreal path
#

who names size_t

#

ssize_t

kind root
#

signed size_t

surreal path
kind root
#

its a completely different type

surreal path
#

well it wants it

#

i dont have

kind root
#

long

surreal path
#

this is the most big brained

kind root
#

typedef long ssize_t

leaden hinge
surreal path
#

works but why does it look like that

#

%.4s

#

oh wait

#

percision

kind root
#

u disabled precision

surreal path
#

sec

kind root
#

bro wasted so much time

#

now try hw

surreal path
#

💀

thorn bramble
#

that is insane

surreal path
#

ok

thorn bramble
#

lmfaoo

surreal path
#

sec

#

lemme try bring BACK my allocators

#

sec

kind root
#

i hope u learned some debugging lessons from this

surreal path
#

i did

#

i learned a lot from this experience

kind root
#

then its not in vein

surreal path
#

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

kind root
#

u already have the raw io r/w helpers

surreal path
#

what’s the difference between them

kind root
#

read the header

thorn bramble
#

raw io is memory, io is port io?

#

i think

#

yea read the header

surreal path
#

it’s loading it !!!!

#

things are happening

#

It’s a lot of stuff tho

#

Works !!!

#

Works in real hardware!!!!!!

thorn bramble
#

good job

kind root
#

nice

#

only 5 hours of debugging

thorn bramble
surreal path
#

😭

surreal path
kind root
#

yup

surreal path
#

i implemented now

kind root
#

i think u also dont call uacpi_initialize_namespace

surreal path
#

no i dont

#

call it?

kind root
#

specifically the initialization section

surreal path
#

i dont have events or whatever tf so it doesnt rlly work

kind root
#

who cares

#

thats a warning, not an error

surreal path
#

ok

kind root
#

lol

surreal path
#

also what is a gpe

kind root
#

thats probably because those are guarded by a mutex

#

and u dont implement that

finite summit
thorn bramble
#

namespace initialization done
Amazing!
meow

surreal path
finite summit
#

indeed

surreal path
#

ah okay

kind root
#

power button is a fixed event, not a general purpose one

finite summit
#

meh same thing

#

potato potato

surreal path
#

i barely know much about acpi that much to the level yall know 😭

kind root
#

but u must implement register_irq_handler

finite summit
surreal path
#

so heres the thing

#

yea...

#

i dont have a common stub

finite summit
#

then make one

surreal path
#

shoot

#

okay

kind root
#

well thats what you do next then

#

how did u even hook up timer ticks

finite summit
#

through a not-common stub

#

probably isr_stub_32

surreal path
#

ok so for a common stub

kind root
#

just redirect gsi 9 to that stub as well

#

via ioapic

surreal path
#

why gsi 9

finite summit
#

yeah anyway I got a page table manager to debug

surreal path
#

whats on gsi 9

kind root
#

thats where acpi interrupt lives

#

the SCI interrupt

surreal path
#

do u have a spec sheet i can read so i can see what gsis go where

#

for future use

kind root
#

u have the madt table..?

surreal path
#

oh right

kind root
#

technically its not fixed to 9

#

but all computers do it that way for some reason

surreal path
kind root
#

any idt index u want

surreal path
#

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

kind root
#

ye

surreal path
#

how tf am i gonna get that

#

cpu doesnt push that on the stack

thorn bramble
#

push it urself

surreal path
#

how am i gonna "push it myself". this is a common stub, i dont know what interrupt i am in this common stub

kind root
#

use brain

thorn bramble
#

i was about to spoonfeed :^)

kind root
#

lol

finite summit
#

bruh

surreal path
thorn bramble
#

i am not

#

dw

surreal path
#

i need to learn not copy code

thorn bramble
#

but really there is only one way to do it

#

macros and the push instruction

#

go crazy

#

you can figure it out

surreal path
#

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

finite summit
#

that's for my abstract irq interface

#

you can ignore it

surreal path
#

okay

kind root
#

for the legacy exceptions

finite summit
#

yeah

surreal path
#

?

finite summit
#

you can ignore it

surreal path
#

alr

kind root
#

0xE - pagefault

#

0x0 - div by zero

#

etc

#

there's 32 of these

surreal path
#

yea i know

kind root
#

so u get it then?

#

it pushes the irq number

#

barring the reserved range of 0..31

surreal path
#

yea thats smart

#

then u can like have a common irq handler

#

and have that handler the irqs

#

😎

#

correct?

kind root
#

yes

surreal path
#

alr epic

#

im gonna implment this rn!!!

finite summit
#

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

surreal path
#

alr

surreal path
#

line 33 causes a general protecxtion fault now

#

cause i wanted to add irq to my interrupt frame

#

@finite summit no pain

#

should work RIGHT?

#

wrong !

#

push everything correctly ! yet it still has the stack get fucked or smthin

thorn bramble
#

why push it twice

thorn bramble
#

no need to store it in rax first

surreal path
#

@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

finite summit
#

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

thorn bramble
#

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

thorn bramble
#
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

surreal path
#

?

thorn bramble
#

im sorry what are you confused about?

surreal path
#

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?

thorn bramble
#

the address of that label, yes

surreal path
#

oh this is actually much smarter

thorn bramble
#

i mean both ways are valid, but i prefer that one because i rely less on the code padding

surreal path
thorn bramble
#

good question

#

hard to say

#

without seeing the entire file

#

also what assembler is that

#

gas?

finite summit
#

nasm

surreal path
#

nasm

kind root
thorn bramble
#

.dq

#

or whatever

#

.quad

#

idk nasm

kind root
#

He's not typing out the name of the label

#

But the macro name

thorn bramble
#

is he not?

#

i thought these were the names of the labels

surreal path
#

oh

#

💀

kind root
#

isr_stub_9

#

Not isr_stub 9

thorn bramble
#

ugh

#

oh dear lord

#

ur right

surreal path
#

i mean its 2am

#

my brain is 💥

kind root
#

U mean 4:30

thorn bramble
#

3:36 here

finite summit
#

it's 21:36 idk what yall mean

thorn bramble
#

we all over the place

surreal path
#

no its 02:36am 😠

#

i control the time

#

😤

finite summit
#

is anyone here upside down

#

?

thorn bramble
#

in this chat i dont think so

finite summit
#

other than @plush hearth

thorn bramble
#

oh i didnt know

finite summit
#

he's upside down

thorn bramble
#

i know that andy is an aussie

plush hearth
finite summit
#

what if they accidentally take off the things on them that make them not fall into space

surreal path
#

oh frick u i cant use macros cause nasm hates that

#

time to write all these out manually

finite summit
#

you mistyped

thorn bramble
#

isr_stub_%q maybe

surreal path
#

tried

plush hearth
thorn bramble
#

yeah good luck idk nasm

surreal path
plush hearth
finite summit
#

There can be some... delusional people on discord to say the least

#

well not just on discord

#

but yeah

surreal path
#

guess i have no other option but to write all these manually!!!

surreal path
#

IT WORKS

#

IRETQ YOUR SO PRO

#

😎

#

i wrote a python script to write the dq's for me

#

it all works!!!

thorn bramble
#

you are very much welcome

#

enjoy your objectively better way of making an isr table

cinder plinth
#

username checks out

surreal path
surreal path
#

mister master of interrupts !!!

desert haven
surreal path
#

bro thats an unsigned int wtf

#

like bro.

kind root
#

how are u printing it

surreal path
#

its a uint64

kind root
#

bro doesnt know how 2s complement works

surreal path
#

the heck is that

kind root
surreal path
#

printf

kind root
#

jesus

#

%d is signed int

surreal path
#

oh

#

💀

kind root
#

%u is unsigned int

#

%lu is unsigned long

#

%ld is signed long

#

etc

#

u cant just put a %d there

tawdry mirage
surreal path
#

so in this case i need to do lu

tawdry mirage
#

oh i was scrolled up

surreal path
#

😭

kind root
#

doesnt nanoprintf have __attribute__((format))

surreal path
#

idk

tawdry mirage
#

nanoprintf may do but the custom wrapper for writing to the screen/serial most likely doesn't

kind root
#

reuse it for your own helper

surreal path
kind root
#

then the compiler will scream at u if u do it wrong

tawdry mirage
#

and the compiler can't peek into valist to determine whether format args make sense

surreal path
#

the fact that i ignore pretty much every compiler warning

surreal path
#

ima figure this out

tawdry mirage
#

sign extended byte 0xee?

#

do your asm irq stubs do push byte N by any chance

surreal path
#

%1-0x20

ionic jetty
surreal path
ionic jetty
#

i dont see your whole macro but does it use the exact same one for every exception

tawdry mirage
surreal path
#

for the ones that push an error code i dont push an error code

hasty sedge
#
        push $0
    .endif```
you need something like this
tawdry mirage
#

0xee+0x20 = 0x10e => 0xe => page fault

surreal path
ionic jetty
ionic jetty
tawdry mirage
cinder plinth
#

just push the interrupt number

#

no need for -0x20

#

for whatever reason

finite summit
#

He took that from my kernel

surreal path
#

cause this is for the like, irq number. i wanna implment something similar to omars implmentation of a irq dispatcher

finite summit
#

and I said it was for my irq interface

ionic jetty
#

exposed

surreal path
#

yea, i wanna do something similar

thorn bramble
cinder plinth
thorn bramble
#

he has like two separate ones

finite summit
cinder plinth
#

literally just

#

irq_dispatch(int-0x20)

ionic jetty
cinder plinth
#

lol

finite summit
#

well

#

the irq dispatcher is hooked directly to the isr stub thing

thorn bramble
#

bro cannot run sub rax,0x20 because reasons

finite summit
#

and it's supposed to be completely arch-dependant

surreal path
#

i can just do that

finite summit
#

It takes an interrupt_frame

#

which is arch-dependant

#

but has a field that should exist on all archs

#

intNumber

ionic jetty
#

but you can still do intNumber - 0x20 in your isr can you

cinder plinth
#

intNumber not irqNumber

finite summit
#

because then it depends on the first 32 vectors being reserved

cinder plinth
#

thats stupid

thorn bramble
#

sounds silly to me

finite summit
#

which is x86-specific

thorn bramble
#

anyway

surreal path
#

yea im changing it

#

if i want the irq number i just, intnum-0x20

#

in c

ionic jetty
#

I had a look at your code a few weeks ago does this interrupt dispatcher create these dpc threads you have there?

finite summit
#

indeed

ionic jetty
#

thats neat

finite summit
#

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

thorn bramble
#

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

finite summit
surreal path
#

fix them warnings

thorn bramble
#

please do

#

-Werror

#

:^)

surreal path
#

hes talking about me lmao 😭

ionic jetty
thorn bramble
#

but you should too if you dont :^)

finite summit
#

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

surreal path
#

ok i do the calculation in C now

thorn bramble
#

learn from this guy :^)

thorn bramble
surreal path
#

yea

thorn bramble
#

you know what happens if you subtract them?

surreal path
#

yep

thorn bramble
#

you get a negative result

cinder plinth
#

frame->intnum >= 0x20 ? frame->intnum - 0x20 : idk something

surreal path
thorn bramble
#

just print intnum

#

no subtraction

cinder plinth
#

yes

#

that

surreal path
#

since i use exception 32 for my lapic timer and scheduler

#

im gonna do 0x21

kind root
#

Why

#

Lapic timer is just normal irq

surreal path
#

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

leaden hinge
#

exception 32?

surreal path
#

thats not an exception right

leaden hinge
#

its not one of the cpu exception vectors no

surreal path
#

sorry im doing a lot of things that are stupid

#

just let me

#

think about this

#

okay heres what im gonna do

thorn bramble
#

you’re gonna print intnum

surreal path
#

no

thorn bramble
#

welp

surreal path
#

why

#

why would i do that?

thorn bramble
#

because thats all you need

#

why subtract anything

surreal path
#

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);
}
thorn bramble
#

wha

#

i mean whatever works for you

#

but sure

surreal path
#

if theres a better design for this

#

tell me

#

i want to learn more and know

thorn bramble
#

well im on phone but ill get on pc soon

surreal path
#

oka

#

okay i get it now

#

thanks iretq

surreal path
#

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

surreal path
#

ps2 driver done

#

again thanks to huge help from iretq for helping me understand a lot of concepts

#

well um....

#

vfs now???

#

trl nyaux panics if no one consumes the keyboard event buffer and its full trl trl

#

probs should make it clear out the buffer or smthin

kind root
#

u have literal uacpi to figure that out

thorn bramble
#

oh yeah i forgot about that

#

@surreal path have fun

#

implementing the interrupt stuff

#

for uacpi

#

:^)

kind root
#

u dont even need that

wicked loom
#

it's fine to hardcode ISA devices IRQs, MMIOs, and ports

#

on standard PCs

kind root
#

to find out whether ps/2 exists and where it lives

wicked loom
#

i mean of course if you have a ACPI impl it's better to use that

kind root
wicked loom
#

it's the proper™️ way of detecting ISA devices

thorn bramble
#

oh i thought that there was a way to ask uacpi to route the irq for you

surreal path
kind root
wicked loom
kind root
#

lol

wicked loom
#

because it hardcodes the resources of ISA devices

kind root
#

theres a AT_PC compliant flag in fadt

#

if u really wanna be pedantic

wicked loom
#

is that better?

kind root
#

yeah

wicked loom
#

i did not know about any better method of detecting standard PCs back then

kind root
#

you cant assume isa exists without checking that

wicked loom
wicked loom
#

these are separate flags though

kind root
#

ye i thought it was just the one

#

guess not

#

bit 0 is enough probably

wicked loom
#

so it's not AT_PC, it's IA_PC

#

hell it's probably wise to check both that, and !reduced

kind root
#

maybe there's some other flag im forgetting idk

wicked loom
#

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

thorn bramble
#

i wonder if there is an acpi way to find out which irq the keyboard uses?

kind root
#

yes!

thorn bramble
#

ofc its unlikely to be != 1

kind root
#

uacpi_get_current_resources()

kind root
#

this is a ps/2 _CRS dump from some AML blob

thorn bramble
#

oh that is amazing

kind root
#

this means IO port 0x60, 0x64, and irq 1

#

uacpi provides a way to retrieve these

thorn bramble
#

oh and i use uacpi_get_current_resources and find the irq resource?

#

that is so cool

kind root
#

yeah

#

theres a uacpi_for_each_resource

surreal path
#

is PNP0303 the id for the ps2 keyboard

thorn bramble
#

acpi is such a bitch

#

but when it works

#

its beautiful

kind root
#

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}
    })
surreal path
#

wiki doesnt say much about it

kind root
#

read code?

#

its trivial

#

u give it a callback

surreal path
#

and what is this callback for

kind root
#

if the function is called

#

for each resource

#

what do you think the callback receives

surreal path
#

i dont know, i just want the irq number and port for the keyboard so i can route it

kind root
#

right

#

u want me to spoonfeed?

surreal path
#

no

#

i want to understand

kind root
#

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

surreal path
#

oh okay

kind root
#

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}
    })
kind root
#

u can just iterate them manually

#

its just a bit more annoying because they're variable length

surreal path
#

ok how do i get the resource

kind root
#

its provided to u in the callback

surreal path
#

oh

#

thats node?

kind root
#

uacpi_resource_iteration_decision my_callback(void *user, uacpi_resource *resource);

surreal path
#

oh

thorn bramble
#

sorry for a weird question but i dont know how to ask it properly

kind root
#

aka a ps/2 keyboard

thorn bramble
#

yup

kind root
#

u know how to use the ports

#

and how many to expect

thorn bramble
#

but is it like, i know there are two ports

#

and i know the first port is the data port?

kind root
#

and for the general kernel resource collision detection u dont care about what they're used for

kind root
#

the order and types are generally fixed

thorn bramble
#

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)

tawdry mirage
kind root
#

agreed upon so to speak

surreal path
thorn bramble
#

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

kind root
#

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

tawdry mirage
#

the technically-correct pc emulator

kind root
#

because they dont hardcode the values

kind root
#

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

surreal path
#

page faulting on this instruction

thorn bramble
kind root
surreal path
kind root
#

no idea

surreal path
kind root
#

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

surreal path
#

offff course

kind root
#

it specifically checks that the function pointer is not null

#

but then its null somehow

#

when called

#

remember the printf technique i taught u

surreal path
#

spec seems to be a valid address

#

data seems to not be null

#

size isnt null

kind root
#

what about the callback

#

pointer

surreal path
kind root
#

how is it null when called lol

kind root
#

not your code

surreal path
#

no this isnt my code

#

this is in uacpI_find_devices

kind root
#

not that place

surreal path
#

i dont know what the callback is in that function ur refering to

kind root
#

final_size += spec->extra_size_for_native(spec, data, size);

surreal path
#

is final_size the callback or what

#

sorry im very confused

kind root
#

bro

#

do u see the circular brackets

surreal path
#

yes

kind root
#

what does that mean

surreal path
#

thats the callback

kind root
#

you guessed it!

surreal path
kind root
#

yeah looks like further debugging is required

surreal path
#

seems like getting the resource

kind root
#

didnt we already figure that out by looking at the stack trace

#

it dies when calling that callback

#

that you just inspected

kind root
#

but the callback is valid

#

so something very funky is going on

surreal path
#

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

kind root
#

yeah

surreal path
#

stack fuckery?

kind root
#

perhaps

#

u disable red zone right?

surreal path
#

red zone?

kind root
#

-mno-redzone

surreal path
#

yea

kind root
#

could be a stack overflow or something

surreal path
#

why

kind root
#

no idea

#

im just guessing

surreal path
#

what

#

thats the "invalid opcode"

kind root
#

your qemu doesn't have popcount i guess

surreal path
#

why

kind root
#

-cpu max

surreal path
#

ok

kind root
#

or -cpu host

surreal path
#

no fault

kind root
surreal path
kind root
#

why didnt your kernel catch the invalid opcode

surreal path
#

i dont have a handler for it

kind root
#

its a trap so it should've just been an infinite recursion

surreal path
#

its spamming zero on the screen

#

when i try to get the irq

kind root
#

these functions all have a return value you know

#

but who cares about compiler warnings

surreal path
#

why is the irq 0

#

when its clearly 1

kind root
#

no idea

#

first fix ub

surreal path
#

ub?

kind root
#

you dont return anything

surreal path
#

0 is 2

kind root
#

and

#

thats not what that irq number is

surreal path
#

ok

kind root
#

fix code

#

return the value that the function expects

surreal path
#

ok

kind root
#

its not supposed to go on forever

surreal path
#

yea returning it nothing prints

kind root
#

thats not the correct enum value

#

for the first function

surreal path
#

what is it

kind root
#

literally look

surreal path
#

ok found it

kind root
#

the return value types are different

surreal path
#

now its spamming 0

kind root
#

what did u do

surreal path
kind root
#

lol

surreal path
#

it goes on forever

kind root
#

like

#

enable fucking compiler warnings

surreal path
#

ok

kind root
#

i see the bug right there

surreal path
kind root
#

yup

surreal path
#

gotta cast it

#

ig

kind root
#

what

surreal path
#

what no

#

ok fixed

kind root
#

think harder

surreal path
#

resource port 257

#

thats the irq?

kind root
#

port?

#

what

surreal path
kind root
#

can you show code

surreal path
#

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");
    }
}