#uACPI - a portable and easy-to-integrate ACPI implementation

1 messages ยท Page 51 of 1

vast kestrel
#

sleep :^)

jaunty fox
#

netbsd is having membar_producer/consumer() for these

fiery turtle
#

well these are from netbsd right

#

they arent part of the C memory model

#

like as far as I understand, anything not adhearing to the C model works only because of implementation details

vast kestrel
#

basically

#

and I guess technically if you choose std=gnuXX it could decide on a different memory model

#

but I doubt it is ever formalized lol

flat badge
#

i mean, adding a r-r and w-w barrier for seqlocks is probably fine

#

like netbsd does according to the docs

#

but for the majority of the code i'd stick to the C11 memory model

#

as it's the de-facto standard now

#

also, it makes sense, it can be implemented efficiently and it was actually designed around existing implementations instead of just growing over time (as the linux model did)

#

if Linux was started today, it'd also use mostly the C11 model

fiery turtle
#

thanks for the link

#

is netbsd available on bootlin?

#

damn i think not

#

it only has freebsd

#

ok lol netbsd just compiles it to a no-op on x86

#

whats interesting is i dont see a compiler barrier being inserted there

#

or is function call itself considered a compiler barrier?

#

ARM does DMBST

#

but also no compiler barrier

#

very strange

flat badge
#

actually on aarch64 there is no difference between r-rw and r-r

#

afaict

#

it's both dmb ld isn't it?

#

@loud ice ^

fiery turtle
#

is function call considered a compiler barrier?

jaunty fox
flat badge
#

or i guess dmb ishld

fiery turtle
#

does netbsd not do LTO?

#

although assembly cant be ltoed probably

flat badge
#

the easiest compiler barrier is asm volatile ("" : : : "memory");

fiery turtle
jaunty fox
#

lto is not very popular for kernels

fiery turtle
#

no C code at all

flat badge
#

but i'd argue that you shouldn't rely on compiler barrier anyway except for very specific stuff (such as per-CPU atomics maybe)

jaunty fox
#

it's pure poison to observability and debuggability

fiery turtle
#

or a non-inline function call i guess

flat badge
#

yes that's true

fiery turtle
#

but it gives u free 5-10% perf usually out of nowhere

flat badge
#

that's probably also why the C11 model has no equivalent of r-r and w-w

fiery turtle
#

its also very easy to make a mistake with r-r

#

like u have to actually understand what you're doing insanely well

flat badge
#

yeah r-r and w-w don't compose very well with stuff around it

#

since they do not establish transitive orderings with other accesses

fiery turtle
#

thats why smp_rb and friends suck

flat badge
#

like, for a acquire-release pair on the same var, you can be sure that everything since it doesn't escape it

#

but that can't be emulated with r-r and w-w

fiery turtle
#

like im sure that there are a lot of places in linux drivers using smp_rb expecting r-rw

#

which it is on a lot of arches as well

torpid root
fiery turtle
#

probably very few people writing simple drivers understand the diff at all

flat badge
#

the most cursed assumption of the linux model is that plain accesses are atomic if aligned properly

fiery turtle
#

WRITE_ONCE trl

#

the building block of linux

loud ice
fiery turtle
#

i mean for production builds why not LTO

#

free points and you're not gonna be debugging it

jaunty fox
loud ice
#

because developers are bad at writing code lol

vast kestrel
#

^^

loud ice
#

but linux is not, and windows has special handling from msvc because of their UB

fiery turtle
#

wdym linux is not? depends on the distro

#

u can enable it

loud ice
#

you can?

#

ok damn

fiery turtle
#

ofc

loud ice
#

nvm then

fiery turtle
#

linux has supported lto since forever

vast kestrel
#

the build system supports it

loud ice
#

i would assume that it breaks

#

because its linux lol

vast kestrel
#

I think the perf increase is minimal in real world benchmarks

fiery turtle
#

nah they managed to make it work

loud ice
#

okay neat

fiery turtle
#

but yeah

vast kestrel
#

at least for most common drivers

jaunty fox
#

i am influenced by bryan cantrill's philosophy around performance engineering

loud ice
#

on x86 its a compiler fence

#

on arm you dont want a fence you want a consume ordering

jaunty fox
#

he couldn't stand things like -fomit-frame-pointer because it impeded observability

fiery turtle
#

ever since 5.12

fiery turtle
loud ice
# loud ice on arm you dont want a fence you want a consume ordering

aka ```c
uint64_t magic_zero(uint64_t input) {
uint64_t output;
asm("eor %w[out], %w[in], %w[in]"
: [out] "=r"(output)
: [in] "r"(input));
return output;
}
uint64_t dependent_load_after(_Atomic(uint64_t)* ptr, uint64_t previous_load_result) {
return atomic_load_explicit(ptr + magic_zero(previous_load_result), memory_order_relaxed);
}

fiery turtle
#

consume got deprecated for a reason trl

#

every compiler promoted it to acquire

loud ice
jaunty fox
#

it's useful for RCU and other techniques

loud ice
#

yeah

jaunty fox
#

there you can usually tolerate simply assurance that dependencies are respected, and full acquire is a worse penalty to pay

hollow elm
fiery turtle
#

well cppref says deprecated in c++26

fiery turtle
loud ice
loud ice
fiery turtle
#

browsers are hard

loud ice
#

except with better names and comments and types

jaunty fox
#

@fiery turtle will ultra os use rcu/smr techniques?

fiery turtle
#

i mean ofc, how can u avoid RCU in a serious kernel

flat badge
jaunty fox
#

dragonfly is replicating or partitioning state between cores, to great effect

flat badge
#

Managarm's kernel doesn't use RCU yet

fiery turtle
#

what is SMR btw?

flat badge
#

we will at some point introduce RCU though

left orbit
#

shingled magnetic recording

loud ice
flat badge
#

since the handle -> descriptor maps are quite costly without RCU

loud ice
#

it's also not a serious kernel

fiery turtle
loud ice
flat badge
#

just need to find somebody to implement it who doesn't have IP conflicts

jaunty fox
# fiery turtle what is SMR btw?

both a general term for the approach of 'safe memory reclamation' (i.e. what you have to do when you want to do lockess things but haven't a tracing GC) as well as a sometimes term for a specific implementation of the approach invented in freebsd and now also used in macos and cpython

loud ice
#

split it into 100 tables

#

and then lock each one

slim panther
fiery turtle
#

yeah first i need to get over the log ring and then implement the rest of the kernel LULW

flat badge
jaunty fox
#

but no reclamation mechanism yet

vast kestrel
#

I have a friend who made a toy rcu implementation on his own, using the membarrier syscall

jaunty fox
vast kestrel
fiery turtle
#

there's also a syscall which makes it possible to detect when you have been preempted iirc?

jaunty fox
#

it's expired now

fiery turtle
#

to do userspace spinlocks

#

or wahtever

fiery turtle
#

yeah that

vast kestrel
#

on preemption it moves your rip to a pre-configured place or something alike

#

so you can handle a preemption path

jaunty fox
#

it worked nicely for me because i am accustomed to working at dispatch IPL which is straightforwardly equivalent to a Classic RCU read section. but if i had to do threaded RCU i would be in a more dificult position since i think Sleeping RCU is still under patent

vast kestrel
#

my friend used the membarrier to force a fence on the other threads of the process without the reader needing a hw fence

hollow grotto
#

Maybe the patent has already expired

loud ice
#

or the engineers decided that if they implement it quickly enough the legal team cant stop them trl

#

or they licensed it

jaunty fox
#

of note IBM granted that liburcu is allowed to use sleeping RCU and be under LGPL

#

so in principle you could work with that and share your modifications to liburcu alone

#

and paul mckenney himself is the instigator in chief of the project to put something which exposes an interface very like Sleeping RCU into C++'s standard, so implementations will soon multiply

loud ice
#

the lgpl isnt very clear

#

but the wording may imply that the patent license is granted for everyone

chrome crow
jaunty fox
#

legally it's just a mess, terrible

#

the basic rule is how much financial clout you can bring determines how much they mean anything

loud ice
#

kinda vaguely

#

which makes this even more complicated

jaunty fox
#

and the only observable effects of that whole rotten system is a nice numerical KPI that makes managers happy and vast amounts of terrible wastes of time in courts litigating by unpleasant firms

loud ice
#

i suspect IBM wont sue you though

jaunty fox
#

it would be complete subversion of the licence

loud ice
#

the LGPL has a (kinda bad) patent grant clause

#

the question is how that works together with ship of theseusing the library

jaunty fox
loud ice
#

i mean its ms

#

so

#

given that ms used it i suspect ms legal said its fine

#

which means they think that either ibm wont sue, they have a licensing deal or they do not infringe

lucid sleet
trim frost
#

is it normal to get 1M more uacpi points withOUT -M q35 on qemu?

#

i thought that made the os faster

left orbit
#

see the amount of opcodes it has to process

#

the average amount of opcodes/s also depends on what kind of opcodes it's running

#

if you try it on real hw you will notice that it's probably much slower

#

because it's running ops which are just more expensive than what's in qemu's q35 machine aml

trim frost
#

got it

#

so i should trust -M q35 more

left orbit
#

trust with what?

fiery ice
#

what is this function used for?

left orbit
#

if you want to compare some arbitrary number against other kernels then yes, use q35

#

but ops/s are in no way a performance measure

left orbit
#

what more do you need?

slim panther
#

shouldn't the kernel already know that though?

fiery ice
#

yeah

#

via limine you can get it

slim panther
#

or is this kernel_api?

left orbit
#

it's kernel api bro

fiery ice
#

kernel_api

slim panther
#

bro

left orbit
#

is it not?

#

it's literally prefixed with kernel

slim panther
#

if this is kernel api then you're supposed to fill it in

#

lmfaooo

fiery ice
#

with?

slim panther
#

the rsdp?

left orbit
#

read the COMMENT

#

please

slim panther
#

what kinda question is that

fiery ice
#

set the pointer to the rsdp?

slim panther
#

rtfm

left orbit
#

infy did NOT spend his time writing documentation just for people to not read it

#

๐Ÿ˜ญ

fiery turtle
#

And I thought I had good comments for the kernel api ๐Ÿ’€ KEKW

left orbit
#

it is good tho

slim panther
#

it is

left orbit
#

or at least sufficient

trim frost
fiery ice
#

i just needed a confirmation

fiery ice
left orbit
#

of course it's not 10 lines of information describing how every bit of that output variable should be set

fiery turtle
#

Lmfao

left orbit
#

but "put RSDP there" should be enough

slim panther
fiery turtle
#

Use the C assignment operator

#

Or a return expression

#

To propagate an integer value to uacpi

fiery turtle
slim panther
#

nah i think if you set the rsdp to garbage it just complains that it cant find correct signatures

fiery turtle
#

True

trim frost
left orbit
# trim frost

this assumes you have proper exception handling set up

#

which apparently is a lot to ask from many people in this server

fiery turtle
#

So it didn't crash in fact

slim panther
#

panic!

trim frost
left orbit
#

ah true yeah

fiery turtle
#

Imagine handling errors

#

Just assert everything

slim panther
#

real

#

i totally don't do that

trim frost
#

assert dominance

slim panther
#

okay i actually don't panic

#

i just error

trim frost
#

why does it start with uacpi_status_?

slim panther
#

bindgen

trim frost
#

i use bindgen too

slim panther
#

show your script

trim frost
slim panther
#

prepend_enum_name

#

there it is

fiery turtle
#

x86 is not reduced hw tho

fiery turtle
slim panther
#

it's gated

slim panther
fiery turtle
#

Prepend

slim panther
#

it's default

#

i didn't know about it

fiery turtle
#

Ah

#

All public facing api is already prepended so

#

And even internal api that has global visibility

#

I try my best not to pollute namespaces

trim frost
slim panther
trim frost
#

it has the reduced hardware thing

slim panther
#

reduced hw is cringe

trim frost
#

idek what it does

#

:]

#

what does it do

#

holy flashbang

slim panther
fiery turtle
#

how do u even get it to load namespace and stuff

slim panther
#

bro

#

it's a feature

fiery turtle
#

that code doesnt exist in barebones mode

slim panther
#

conditional compilation

trim frost
#

learn rust bruh

#

smh

#

also i didnt write that, shinribo did

fiery turtle
#

Ah ok

#

Didn't see the if

slim panther
#

ok i removed the stuff

#

no more prepended names

trim frost
#

show proof or didnt happen

torpid root
slim panther
trim frost
#

remove-talc?

slim panther
#

yes

trim frost
#

why

slim panther
#

shit

fiery turtle
#

also im gonna have my 9950x3D soon so ill probably start doing measurements for the leaderboards myself

slim panther
#

you can't do real phys allocations with talc

trim frost
#

what do you use instead? or did you make your own

slim panther
#

my own

torpid root
#

why use talc when you can write your own allocator, find out frigg is way faster and switch to it

slim panther
#

fuck dependencies

fiery turtle
#

then find out proxima is faster and use that trl

slim panther
#

i don't want to make a lib os

trim frost
#

yeah write your own bootloader

slim panther
trim frost
#

scratch that make your own cpu and motherboard so everything is ur own

torpid root
slim panther
fiery turtle
trim frost
#

dont have to depend on anyones microcode

slim panther
fiery turtle
#

same speed

torpid root
fiery turtle
trim frost
#

then how is proxima so fast

torpid root
#

magic

fiery turtle
#

if u reuse memory fast u get it pre-cached

#

which is fast af

torpid root
fiery turtle
#

which uacpi does a lot

#

so it suffers from bump allocator memory coldness

slim panther
#

actually, i haven't looked into it, what allocators does proxima use

#

for page + malloc

trim frost
#

or just divide the time given to uacpi by 10 and you will have 10x the ops/s

fiery turtle
#

very simple slab

#

but it needs a struct page

fiery turtle
slim panther
#

based

#

i strive to be that

torpid root
fiery turtle
#

100-150 ns per allocation

trim frost
#

i like how frigg uses mdbook

slim panther
#

good software

torpid root
trim frost
#

should i make frigg bindings?

torpid root
#

no

fiery turtle
#

just make your own allocator ffs

trim frost
#

couldnt be me

torpid root
fiery turtle
#

i cant because im gonna be stealing proxima's design trl

torpid root
trim frost
#

sometimes i make bindings

fiery turtle
#

Ask chatgpt to convert frigg into rust

trim frost
torpid root
#

lmao

torpid root
trim frost
#

well you use flanterm and uacpi too, i just make it accessible in rust

mortal yoke
#

also you can't really make good bindings for frigg anyway because its header only with templates

slim panther
#

imagine using flanterm

trim frost
slim panther
#

my own

trim frost
#

couldnt build your os

#

errors

slim panther
#

wdym errors

fiery turtle
#

Errors

slim panther
#

works for me

#

what's the error then

trim frost
#

worked my os for me too but turns out it didnt on lld 20

#

hold up

trim frost
#

also what does your build script do? because i feel like im compiling llvm

slim panther
#

take a wild guess

#

wait what build script

trim frost
#

bootsrap

slim panther
#

ah

#

yes

torpid root
slim panther
#

that literally compiles llvm

#

need that shit for bindgen sadly

trim frost
#

no you dont

slim panther
#

how so

trim frost
#

i use bindgen without it bruh

slim panther
#

wdym

trim frost
#

its just a build-dependency

#

clone my repo

slim panther
#

bindgen requires libclang

trim frost
#

you dont have to build it yourself

torpid root
#

I always read binder instead

slim panther
#

and debian builds are retarded

trim frost
#

i use arch btw

slim panther
#

matters how?

#

ever heard of a container

trim frost
#

yes

fiery turtle
trim frost
#

right?

slim panther
loud ice
#

arch best distro

fiery turtle
trim frost
#

what the hell are super reactions

#

they are ugly

slim panther
#

reactions but with effects

#

and money

fiery ice
#

what changes between sleep and stall?

slim panther
#

stall = blocking
sleep = do something else

#

i thnk

fiery ice
#

i'll put a stall on both for now

#

since i only have that implemented

frank canopy
#

sleep is like a thread sleep i think

#

or is allowed to be

trim frost
#

i do busyloop on both

#

one is just msec while the other is usec

torpid root
#

stall is just spin-pause
sleep is thread sleep

frank canopy
#

stall is meant to be a busyloop yeah

fiery ice
#

can i pass a spinlock to this?

loud ice
slim panther
#

mutexes are not spinlocks

fiery ice
#

oof

frank canopy
#

i think some people try but yeah no not the same

trim frost
#

what do you do

torpid root
#

mutex blocks the thread instead of spinning

trim frost
#

since no_std

loud ice
trim frost
#

im aware

loud ice
#

also i wouldnt use them

slim panther
#

i'll make my own locks

fiery ice
#

but uACPI is not running on a thread for me

slim panther
#

it should

#

there are functions to spawn worker threads

trim frost
fiery ice
#

my uacpi will prob run in the main core

#

for now

trim frost
#

@slim panther

frank canopy
#

i run uacpi and all that stuff on the main thread

slim panther
#

actually yes it's fucked

trim frost
#

when it takes 10 minutes to build a kernel that isnt linux, you know something is wrong

slim panther
#

well that's not the kernel

#

it's a whole userspace

trim frost
#

still

slim panther
#

okay fixed it

trim frost
#

mine took 14 seconds lol

slim panther
#

well no offense but you probably don't have that many programs then

trim frost
#

ik

slim panther
#

try now

left orbit
#

menix kernel takes like 5 seconds to build

slim panther
#

he was talking about bootstrap

left orbit
#

ur probably building full or a part of the distro

#

yeah

#

i know

trim frost
#

why am i building linux-headers

left orbit
#

if ur userspace takes 14 seconds to build then idk what kind of userspace it is

#

because mlibc wants them

#

if you enable the linux option

slim panther
#

like reboot, mount and so on

fiery ice
#

what is ctx here?

slim panther
#

it literally says in the comment

fiery ice
#

ctx is passed to the provided handler

slim panther
#

yes

fiery ice
#

what does that mean

#

what actually is ctx?

slim panther
#

hover over it

trim frost
#

is my cpu cooked chat?

torpid root
fiery ice
#

it's a pointer

torpid root
#

you just pass it along to the function

fiery ice
#

huh?

torpid root
#

what don't you understand?

trim frost
#

this is my weird rusty way to do it

slim panther
fiery ice
#

like, rn my handler is just a pointer to the function

torpid root
#

no

fiery ice
torpid root
#

you make your own handler that calls that function

fiery ice
#

hmm

torpid root
# fiery ice

what do you think that uacpi_handle is doing there?

#

looking pretty?

fiery ice
trim frost
#

wdym?

slim panther
#

confusion

fiery ice
#

so it just installs 1 interrupt handler?

trim frost
#

yeah

fiery ice
#

ohhh

slim panther
#

what else is it supposed to do

fiery ice
#

that helps a lot, thx

fiery ice
slim panther
#

then it would call that twice

#

see how the function has an irq parameter?

fiery ice
#

yes

torpid root
#

technically it should support installing more than one IRQs, but other than SCI, what would uacpi request to install?

slim panther
#

that's one (1) value

fiery ice
#

but from what George is doing won't that get overwritten the next call?

torpid root
#

yes

trim frost
#

yes

torpid root
#

but there won't be a next call

slim panther
#

i think even if so, uacpi wouldn't do it on the same irq

torpid root
#

true

#

unless you just reinitialise

fiery ice
#

yeah but still, George's code won't work anyway

trim frost
#

yeah but the handler_fn and ctx will get overwritten

torpid root
trim frost
#

in my code

fiery ice
slim panther
#

which is fine

fiery ice
#

so it can only actually support 1 irq install

trim frost
#

if it works dont touch it :]

slim panther
#

i have irq local context pointers

torpid root
slim panther
#

so i can just store one ctx per irq

torpid root
#

apparently you can't use a "closure" as a handler in rust

#

because local variable and stuff

trim frost
#

also because of "x86-interrupt" abi

torpid root
#

do it properly without the attribute

fiery ice
#

schedule_work is to create new threads, right?

slim panther
trim frost
#

actually it doesnt really need that

slim panther
#

i don't use x86-interrupt at all

trim frost
#

yeah because x86_64 crate

slim panther
#

wut

trim frost
#

i use x86_64 crate

#

provides basic types

slim panther
#

i dont

trim frost
#

and small instructions

torpid root
#

use os;
kernel::run();

trim frost
#

but i can just use the pointer to a function that doesnt use that abi

#

bruh

#

why is it on by default

fiery ice
#

XD

torpid root
#

not abi

trim frost
#

its rust here

#

:]

slim panther
#

it's a calling convention

#

so arguably an abi

torpid root
#

true dat

loud ice
#

the x86_64 crate is shit

trim frost
#

im aware

loud ice
#

the callconv is also shit

#

but for different reasons

torpid root
#

asm code needed is like 50 lines

#

maybe less if you use macros well enough

trim frost
#

new and improved version

#

wait

#

i gotta change static variables

#

so i wont need them anymore

slim panther
#

does interrupt stack frame even include the gprs?

fiery ice
torpid root
#

I doubt it

torpid root
trim frost
slim panther
#

pic

trim frost
#

yeah

fiery ice
#

k

trim frost
#

..

torpid root
fiery ice
#

XD

trim frost
#

this is what the interruptstackframe is

fiery turtle
fiery ice
#

wait, you can cause a pagefault on command?

slim panther
trim frost
#

i dont need global vars

torpid root
#

you can't do it properly with x86-interrupt

slim panther
#

does x86-interrupt do swapgs?

torpid root
#

no lol

slim panther
#

lmfao

#

so it's really useless

torpid root
#

yes

slim panther
#

me when i corrupt my kernel because a user program tripped a breakpoint

trim frost
gentle peak
#

but if you do that you'll get terrible multi thread scalability

fiery ice
#

only on that core tho

gentle peak
#

because when a thread needs to wait for the lock it spends its entire time slice busy waiting

fiery ice
#
  • rn it is not on a thread
fiery ice
#

is this ok for uACPI mappings?

mortal yoke
#

ah wait nvm, you return the original address

left orbit
#

0b00000011

#

perfect

slim panther
#

c++ grindset

torpid root
#

I get filling with zeros to 2^n digits, but why that many

left orbit
#

why even type it out in binary

#

have constants that you | together

#

so you can actually read the code

fiery ice
#

yeah, ik

north hull
rustic compass
fiery ice
#

should i make it set and return the cpu's rFlags?

trim frost
fiery ice
#

k

trim frost
#

And I've seen others do the same

gentle peak
#

uacpi doesn't care what you return, as far as it's concerned it's an opaque value that gets passed to unlock_spinlock

#

it's intended to be used to re-enable interrupts if lock disabled them

fiery ice
#

why is uacpi passing interrupt hanlders as 32 bit pointers?

fiery ice
mortal yoke
#

how is that a 32-bit pointer?

fiery ice
#

unsigned int is a u32 no?

mortal yoke
#

its the return value of the interrupt handler function

fiery ice
#

hmm

calm latch
#

It's a function pointer

fiery ice
#

so why is it 32 bit?

calm latch
#

It's a pointer to a function that returns error encoded as u32

frank canopy
#

the function it points to returns u32

fiery ice
#

ah

#

ok, now i understood that the val before the pharentesis is

frank canopy
#

unsigned int (*)(void *) means that something of the form unsigned int foo (void*) would be a valid target

fiery ice
#

k, thx

calm latch
#

Though it does use u32 for GSIs... Probably because ACPI says so

frank canopy
#

yeah GSIs are 32 bit

fiery ice
#

huuuh, can i remove that ugly \n?

frank canopy
#

i trim what uacpi gives me to remove it

trim frost
#

i just .replace("\n", "")

#

its ugly asf

frank canopy
#

i use trim but same idea yeah

fiery ice
mortal yoke
# fiery ice gg

do you print a newline in the uacpi print function yourself?

fiery ice
#

i use my printf

calm latch
#

Just don't print newline

fiery ice
#

that auto adds a \n at the end

trim frost
#

yeah uacpi adds its own \n

frank canopy
trim frost
#

and you add your own

#

resulting in double

frank canopy
#

yeah

fiery ice
#

pain

calm latch
fiery ice
#

?

calm latch
#

(I'm doing the same trl)

frank canopy
calm latch
frank canopy
#

zig's log you cant turn off its trailing newline so i have to remove it

#

yeah printf shouldnt have a newline but a log function maybe ig

gentle peak
fiery ice
#

i'll just add a bool to my printf

#

lol

calm latch
fiery ice
#

lol

trim frost
frank canopy
fiery turtle
#

Or just don't insert your own new line

frank canopy
#

zig's log adds a newline so i have to trim and its annoying

fiery ice
frank canopy
#

for regular printf it should probably not add a newline by default, you can make a println or something for that

trim frost
calm latch
#

uACPI 3.0?

fiery turtle
fiery turtle
frank canopy
#

well technically i wouldnt need to because calling the log functions there filters through to my log handler which in a kernel im overriding anyway

#

but the zig convention is no newline in the call to log

calm latch
#

You could make it a define

frank canopy
#

yeah

#

use the weird c thing where you can concat strings by putting them next to each other and conditionally define a thing to either "\n" or nothing

trim frost
#

what is UACPI_FIXED_EVENT_RTC?

calm latch
#

RTC fixed event by uACPI trl

trim frost
#

no shit

#

what is it

frank canopy
#

well the uacpi enum value for the acpi RTC fixed event

#

which i dont know offhand but its in the spec somewhere im sure

#

found it

#

i think this is what that is anyway

trim frost
#

wait so i can run the kernel, set an alarm, then when i rerun at a different time i can execute some code?

fiery ice
#

i think so

fiery turtle
#

No, this is for shutting down your PC

fiery ice
#

ah

fiery turtle
#

And then it starts at the programmed time

trim frost
#

oh

fiery ice
#

doesn't the BIOS and UEFI do that automatically tho?

fiery turtle
#

Do what

fiery ice
#

auto start the pc with the RTC

#

this one overrides that?

frank canopy
#

the event thing lets you easily detect when it starts on alarm

fiery turtle
#

They don't use the rtc to start the PC, no

frank canopy
#

and i think also if it alarms while already on?

fiery turtle
#

Why would they need it

fiery ice
#

lol

fiery turtle
#

?

fiery ice
#

you can set from the uefi panel to start up your pc at a specific time

frank canopy
#

idk if the fixed event triggers after a configured alarm boot actually

#

but the fixed event thing for it lets you call a function of yours when the alarm goes off with the kernel running

fiery turtle
trim frost
#

whats UACPI_FIXED_EVENT_MAX?

frank canopy
#

c convention to say what the highest enum value is

#

if you arent using c, ignore it

fiery turtle
#

Not that it matters that much

frank canopy
#

yeah

#

either way thats deeper in the weeds than i have the knowledge for

fiery turtle
#

I've never tried it personally

fiery ice
#

time to understand what the names are for

frank canopy
#

the first bit is what table it is

#

the bit in parens is the vendor string

fiery ice
#

i meant what are the tables for here

trim frost
#
RSDP (Root System Description Pointer)

The entry point into the ACPI system. It points to either the XSDT or RSDT table, which lists all other ACPI tables.

XSDT (Extended System Description Table)

Contains 64-bit pointers to all other ACPI tables. It's the modern version of RSDT (32-bit).

DSDT (Differentiated System Description Table)

Contains the primary AML (ACPI Machine Language) code used by the OS for managing devices and power. This is where much of the ACPI logic resides.

FACP (Fixed ACPI Description Table)

Provides fixed hardware details like power management timers, control registers, and pointers to FACS and DSDT.

APIC (Advanced Programmable Interrupt Controller table)

Describes the system's interrupt controller configuration. Used for configuring local and I/O APICs for multiprocessor support.

HPET (High Precision Event Timer table)

Details about the HPET hardware, which provides precise timers for event scheduling, replacing older timers like PIT and RTC.

MCFG (Memory-Mapped Configuration Space base address table)

Describes how to access PCI Express configuration space through memory-mapped I/O.

WAET (Windows ACPI Emulated Devices Table)

Optional table for Windows guests in virtual machines; provides hints to improve emulated hardware behavior.

BGRT (Boot Graphics Resource Table)

Contains information about the boot logo displayed by firmware, typically used by Windows to blend the OEM logo during boot.

FACS (Firmware ACPI Control Structure)

Used in conjunction with FACP for power management tasks like S3 resume (sleep/standby states).
fiery ice
#

oh thx

frank canopy
fiery ice
#

well, at least it booted up first try

trim frost
#

mine didnt

#

for like 10+ tries

fiery ice
#

oof

#

(i still have half of the API not filled in) XD

#

i need to move uACPI to a thread first

trim frost
#

multithreading: โŒ
bsp for everything: check

calm latch
#

You can run multiple threads on BSP...

fiery ice
#

this is not handling the power btn

#

i am pressing "power down" on qemu

#

and no message pops up

fiery turtle
#

Skill issue

fiery ice
#

...

fiery turtle
#

Does your kernel get an irq

fiery ice
#

sec

fiery turtle
#

And show your install irq implementation

fiery ice
fiery turtle
#

Did u unmask pic?

fiery ice
#

oh wait

frank canopy
#

and remap for that matter

fiery ice
#

i did not unmask for that one

#

PIC is ready

#

but not unmakes for that one interrupt

#

how can i get back the irq number when i uninstall the handler?

frank canopy
#

the ctx thing

#

well no the out_irq_handle

#

that thing

#

you can put anything arbitrary there

fiery turtle
#

^

fiery ice
#

k

frank canopy
#

i allocate a struct for it and stuff the irq number and handler function pointer in there personally but you can do whatever

fiery ice
#

hmm, pic is unmasked

#

but still no interrupts

#

oh wait

fiery turtle
#

Did u implement io read and write properly

fiery ice
#

i did not add + 0x20

fiery ice
fiery turtle
#

Yes...

#

How is it supposed to do anything

fiery ice
#

idk

#

wiki did not say anything about these for shutting down the system

fiery turtle
#

It didn't say anything about omitting any api either

fiery ice
#

well, time to find how to implement those

fiery turtle
#

Comments

frank canopy
#

on x86 theyre dead simple too which is nice

fiery ice
#

you mean these?

trim frost
#

inb and outb for 8

#

inw and outw for 16

fiery ice
#

yeah

trim frost
#

and idk what it is for 32

fiery ice
#

inl

#

outl

trim frost
#

yeah use those

fiery turtle
#

if it didnt, recheck your code

fiery ice
fiery turtle
#

because your io functions return an error

#

which would be propagated back to you

fiery ice
#

it didn't tho

fiery turtle
#

recheck your code

fiery ice
#

hmm, seems like my OS literally stops before finishing to init uACPI

#

and it seems to stop at the spinlock

#

when locking it

#

or well, it is calling it while the lock is locked

#

hmm, but it's not uACPI's fault

#

seems like a deadlock somewhere

#

found the culprit

#

it was vmm or pmm

#

one of the 2

#

@fiery turtle if i get a Failed to initialize: out of memory

#

which api call should i look at

fiery turtle
#

anything with create

fiery ice
#

but in the kernel_api,?

fiery turtle
#

well obviously

fiery ice
#

maybe the alloc functions?

fiery turtle
#

no

#

doubt its those

#

create_mutex/spinlock/event

fiery ice
#

yeah well

fiery turtle
#

yeah this wont work

fiery ice
#

what do i do with these?

fiery turtle
#

implement

fiery ice
#

f

fiery turtle
#

for event u can return any non-null handle

#

if u want it to be a no-op

#

for mutex u can also return anything non-null, just make sure its not always the same value

#

but this wont work on real hardware of course

frank canopy
#

well it might at first as long as youre strict single threading

calm latch
#

Simple spinlock is like 4 LoC

fiery ice
trim frost
#

you messed something up in the kernel api

#

same thing happened to me

#

idr how i fixed it though

vast kestrel
#

I mean, it seems like you ran out of memory, so your allocator function returns null for whatever reason

trim frost
#

how can i get cpu information other than lapic address from MADT?

vast kestrel
#

Define cpu information

#

Most of the stuff you will find via cpuid (vendor, family, name, topology, etc)

#

And not via acpi

trim frost
vast kestrel
#

The lapics are the thing that represents the different cpus, and you can read the current lapic id via an msr iirc, which is how you know which one is the bsp

#

It should have an entry for each lapic in the system and it's id iirc

trim frost
#

couldnt find where the id is, only the address but ig i can match it to the address i get from msr

vast kestrel
#

There is an entry per cpu, you might be parsing the table wrong if you don't find it

#

The address override can be basically completely ignored and iirc you should only use the msr to access the lapic

gentle peak
fiery ice
#

wtf

#

hmmm, time to find out why my vma finishes the mem

fiery ice
#

but these still remain

vast kestrel
#

Well, print the error code that they return, I am pretty sure every uacpi functions returns an error code

fiery ice
#

i am, but those are printed out by uACPI

vast kestrel
#

Could be you stub or implement incorrectly some Io or pci read/write functions?

fiery ice
#

pci function all return OK status

vast kestrel
fiery ice
#

bc i did not implement them yet

#

could it be bc of that?

vast kestrel
#

Yes it could

#

Especially if you return ok

fiery ice
#

but why is the power button failing to install then

vast kestrel
#

Don't return ok for stubs that have side effects

#

Because it thinks you are writing but it doesn't

fiery ice
#

pwr button is PCI?

vast kestrel
#

No idea, but could be that it needs pci access for it

#

For every stub you have don't return OK if it had a side effect like read/write

#

Return an unimplemented error

#

And then you will know when uacpi calls it and expects it to work

fiery ice
#

lemme try to disable the usb hubs i enabled on qemu

#

nope, still PCI error

#

time to write a PCI driver then

fiery turtle
#

u dont need a pci for power button

#

u need a proper io_read/write

#

which yours isnt i guess

fiery ice
#

i have

fiery turtle
#

show

fiery ice
#

oh wait

#

i am stupid

#

i need to swap data and address

#

oof

vast kestrel
#

Lol

fiery ice
#

and now it works

#

OOF

vast kestrel
#

Nice

fiery ice
#

thx infy

fiery turtle
#

np

fiery ice
#

"works"

#

there could be 2 things:

  1. the handler is not registered correctly
  2. qemu is not using acpi for power down function
fiery turtle
#

ill give u a hint

#

its not 2

fiery ice
#

yeah well, i suspected

#

time to see if it receives the isr at least

#

no irq is being fired

#

oof

#

PICs are unmasked

#

but no interrupt is generated

#

and it's trying to register the interrupt at irq 41

fiery turtle
#

seems wrong

#

SCI is irq 9

fiery ice
#

yeah well it is 9

#

i am adding the 0x20 to it

#

but i may have found the problem

#

no irqs are being fired

#

not even PIT

#

normal interrupts work tho

fiery turtle
#

whats a normal interrupt

fiery ice
#

like 0 to 31

fiery turtle
#

thats called an exception

fiery ice
#

seems like sti wasn't getting called somehow

#

now it works

fiery ice
#

hmm

#

qemu pauses on this instruction

#

prob a crash

#

but no execption is caught by my interrupt handler

#

when uacpi calls the stall function

#

this is my stall function

#

Cr2 is null

fiery ice
#

also, this happens on my laptop

calm latch
fiery ice
#

idk what happens there

#

pause gets called from archPause

calm latch
#

did you turn kvm off?

fiery ice
#

no

#

kvm is on

#

else it's painfully slow to boot

calm latch
#

then it won't log exceptions

fiery ice
#

wdym won't log exceptions?

calm latch
#

how painfully slow

#

my os boots fine

fiery ice
#

5+ minutes

calm latch
#

(I would investigate that)

#

but regardless

mortal yoke
#

what is it doing lol

fiery ice
#

(i am running qemu on wsl)

#

qemu freezes for a bit

calm latch
#

wsl is a vm

fiery ice
#

and then resume

calm latch
#

hyper-v

#

it shouldn't affect performance by much

trim frost
fiery ice
#

idk

calm latch
trim frost
#

doesnt qemu run natively on windows?

fiery ice
#

yes

calm latch
#

Even emulating RISC-V, my OS takes like a few seconds to fully initialize

#

in wsl

fiery ice
#

mine starts instantly too, but qemu freezes for a bit and idk why

calm latch
#

(most of which is printing to screen being slow(

trim frost
fiery ice
#

no

#

the os starts printing and then the whole qemu app freezes

trim frost
#

weird

fiery ice
#

on HyperV it works fine

#

lemme try to boot it up with qemu on windows with no kvm

mortal yoke
fiery ice
#

i map only the entire memmap

#

but like, the OS does execute i think, bc after it unfreezes a bunch of log instantly appear

mortal yoke
#

it's still a good idea to use 2mb pages

fiery ice
#

installing qemu on windows

#

i'll try with no kvm there

slim panther
calm latch
#

Temporary mappings

slim panther
#

no limine?

calm latch
#

With limine

slim panther
#

but the only way to access phys mem is with hhdm ๐Ÿ˜ณ

calm latch
#

I mean my kernel also boots with Hyper

calm latch
slim panther
#

oh yea

#

but that's arguably still using hhdm meme

fiery ice
#

with no kvm on windows it works fine

#

just a bit of graphics lag

mortal yoke
fiery ice
#

(ok no, it froze the app too)

#

but the log kept appearing

#

so it's only graphical

mortal yoke
fiery ice
#

idk why the qemu app just freezes for no reason, while the OS keeps going in the background

#

i cannot press any button in the app

#

any idea why it was crashing there tho?

mortal yoke
#

run it with -d int -no-reboot -no-shutdown without kvm

fiery ice
#

and smm off?

mortal yoke
#

if there is no exception then another thing to check is that interrupts are enabled at the point where you pause nvm I though of hlt lol

fiery ice
#

i do cli before that

#

bc it fails here

#

oof, running with -d int is pain rn

#

i cannot send the shutdown signal

#

i'll add it via code

mortal yoke
fiery ice
#

bc qemu freezes

#

the gui

#

i cannot press any button

calm latch
fiery ice
#

but the OS still runs in the background

calm latch
fiery ice
#

only look at the last one

#

the one before it is the PIT timer

#

maybe

#

ok nope

#

last interrupt is the framebuffer

#

before it RIP points at my terminal

fiery turtle
fiery ice
#

oh, that's PCI?

fiery turtle
fiery ice
fiery turtle
#

Idk, it says unimplemmented, you return it somewhere

fiery turtle
# fiery ice

This error is a result of your unimplemented api

fiery turtle
fiery ice
#

no, i was referring to incompatible AML type

left orbit
#

people refusing to implement the kernel apis is crazy

fiery turtle
left orbit
#

what's the point of a kernel api anyway if people just don't implement it

#

i think you should remove it

fiery ice
#

i still did not create a pci driver

fiery turtle
#

True

fiery ice
#

that's why

fiery turtle
#

Its just annoying when people ask for help but they don't even bother implementing the api and stub most things out

#

Like yes that won't work

#

It exists for a reason

fiery ice