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

1 messages · Page 43 of 1

frank canopy
#

and the concepts should translate fine

calm latch
#

It's fine

fiery turtle
#

yeah

#

Nice

frank canopy
#

ill be swapping this to iterator api soon so sent a permalink lol

#

the descending/ascending is clearer and more like what most projects will use i think

fiery turtle
#

Ill probably merge iterator api today

frank canopy
#

cool

calm latch
#

I can try the iterator thing, I have no preference what to use

fiery turtle
#

Especially if @north holly tests the new pr meme

frank canopy
#

what i also might do is create a device object for specifically the _SB namespace and iterate under that

fiery turtle
frank canopy
#

also not merged yet

#

its very good for working in zig and absolutely unnecessary in C

#

because callbacks through C cant propogate zig errors and error tracing

fiery turtle
#

Haiku uses it for c++ for whatever reason

north holly
fiery turtle
#

The what

north holly
#

Yes.

fiery turtle
#

Like school stuff?

north holly
#

yes

fiery turtle
#

Ah

#

Ig ill test myself with astral then

frank canopy
#

if i wasnt busy today id pull in the PR and test that

#

its one cli command to swap over and after that i just need to write binding externs

calm latch
#

What do you need to test?

frank canopy
#

the new iterator api

fiery turtle
#

Just normal operation

frank canopy
#

where you call next instead of giving a callback

fiery turtle
#

That nothing regressrd

#

And yeah the iterator api

frank canopy
#

but im stuck doing (thankfully paying) web dev work today 😭 so no testing new uacpi things

fiery turtle
#

Good for you anyway

north holly
#

if I get the chance I will be testing the iterator api

#

and will be migrating my acpi driver detection to use that

fiery turtle
#

If you just check that nothing in obos regressed that'd be great

fiery turtle
#

So dont do that

north holly
#

worse how

fiery turtle
#

Requires dynamic memory or recursion

north holly
#

nvm

#

I will temporarily change it

#

but revert it after finding it works

#

or doesn't work

fiery turtle
#

Im implementing it because of haiku basically

#

Btw when are you gonna be back

north holly
#

depends

#

I will not elaborate.

fiery turtle
#

Fair

north holly
#

anywhere from a few days to 5 months

fiery turtle
#

50/50 either today or not

north holly
#

yes

frank canopy
fiery turtle
#

Yeah I didn't realize other languages needed it

north holly
#

zig L

left orbit
#

yeah sadly no closures in zig

#

or anonymous functions (without weird syntax at least)

#

you can technically &struct { fn x() void {} }.x but 🤢

frank canopy
#

yeah no

#

the closures is intended because of implicit allocation potential there

#

which any memory management other than declaring a variable (local or global) has to be explicit

#

the lack of anon functions is kinda annoying but i was doing work with java before that lang got them so i easily get used to that

left orbit
#

i mean C doesn't have them either soooo

#

¯_(ツ)_/¯

frank canopy
#

yeah

#

i dont find it too annoying tbh

#

its just that i cant return an error union from a function that returns uacpi_iteration_result or whatever the enum is called

calm latch
#

So do I just run eval on _ADR, _CID, _HID?

#

uacpi_eval_typed

frank canopy
calm latch
#

oh, fun

frank canopy
#

the struct has bools for if things are present and then a field with the thing if it exists its real nice

#

its what i use

calm latch
#

Yeah I guess I'll also do that...

#

Wth

6.1.3 _CLS (Class Code)
This object is used to supply OSPM with the PCI-defined base-class, sub-class and programming interface for a device.
This object is optional. However, it may be useful for loading generic drivers on hardware that is compatible with PCI
-defined device classes, but that is not implemented on the PCI bus (and is therefore enumerated by ACPI.)

frank canopy
#

yeah

#

i think my code might even handle that i dont remember

#

nope apparently i dont

fiery turtle
#

there goes Astral new uACPI integration LULW

slim panther
#

astral has no memmove?

fiery turtle
#

yup

gentle peak
#

pretty sure uacpi-linux doesn't have any of the mem* functions

fiery turtle
#

anyway i just added UACPI_USE_BUILTIN_STRING

fiery turtle
median crest
fiery turtle
#

it's saved

#

dw

left orbit
#

uacpi-linux being uacpi in the linux kernel or uacpi running in userspace?

fiery turtle
#

the latter ofc

left orbit
#

i should get back to the first one :^)

#

if haiku can do it then why cant we

fiery turtle
#

this makes me wonder, shoudl i make it possible for uacpi to export its own impls of vsnprintf and even string as globally available without the uacpi_ prefix

fiery turtle
fiery turtle
gentle peak
fiery turtle
#

just call uacpi_vsnprintf

#

u already have it

left orbit
#

it must be doable and not that bad

median crest
fiery turtle
#

most code could probably be converted with sed

median crest
#

Load bearing uacpi

gentle peak
#

it's still like tens of thousands of changes to call sites, types, method names, parameter ordering, etc

left orbit
#

true true, but it can be done with enough time and will power lmao

gentle peak
#

yeah

#

my main objection is that such a huge effort isn't really worth it unless it has a chance of getting mainlined, and that's not happening unless you add a config option to choose between acpica and uapci, so you essentially have to write your own independent abstraction layer that can be backed by either

fiery turtle
#

basically yeah

#

maybe an abstraction later isnt that expensive

#

since so many osses have it

left orbit
#

i mean i wanted to have a config switch for uacpi from the start tbh

gentle peak
#

expensive almost certainly not, I doubt acpi is in any kind of performance critical path anyway, but it is even more effort

left orbit
#

but it might be a big project lol thats true

gentle peak
#

ah

#

yeah idk

fiery turtle
#

u could just draw inspiration from NTs interface ig

gentle peak
#

I feel like no matter what you do the migration is gonna be the most time consuming part of it

fiery turtle
#

like changing code to call into it?

gentle peak
#

yeah

fiery turtle
#

yeah

left orbit
#

yeah

flat badge
#

Linux maintainers will never merge a compat layer

gentle peak
flat badge
#

If you want to get uacpi into linux, the only reasonable path is probably reimplementing the acpica API on top of uacpi

#

which would probably be ugly af

fiery turtle
fiery turtle
fiery turtle
strong heath
#

you would be if you were up to date on linux happenings

fiery turtle
#

i am

#

this aint rust

#

and different subsystems have different maintainers

flat badge
#

Hardware abstraction layers regularly get rejected in linux

fiery turtle
torpid root
#

uACPICA layer over uACPI :p

flat badge
#

It's not too uncommon that some company wants to merge a driver that's portable across, say, freebsd and linux and it usually results in heated discussion

strong heath
#

yeah im not necessarily talking about rust anything

fiery turtle
#

i mean an acpica interface layer is also possible, most apis are translatable 1:1

strong heath
#

I am talking about the amdgpus of the world being refused to be portable between the OSes so freebsd needs linux compat

flat badge
slim panther
#

stupid

fiery turtle
#

yeah its kinda stupid ngl

#

they dont want anyone other than linux to be viable

left orbit
#

maybe it would be smart to reach out to a maintainer and see if it has a chance to pass?

#

idk

strong heath
#

whatever you do, if you are serious about upstreaming it, you will need to talk it out anyways

torpid root
#

@LinusTorvalds

strong heath
#

so better start at that

fiery turtle
#

looks like these arent intel employees at least

left orbit
#

hey hes polish

#

:^)

strong heath
#

if you are also russian, so you want to clear that up first if you are employed by a russian company

#

unless you want to be in a phoronix article

fiery turtle
fiery turtle
left orbit
#

or at least a very polish sounding last name lol

strong heath
#

im just clearing items of the list

#

better safe than sorry

fiery turtle
#

i think i've talked to him before as well

#

when sending some patches for acpica fixes

#

to the linux mailing list

left orbit
#

so how do you usually reach these people?

strong heath
#

mail

fiery turtle
#

mail, yeah

left orbit
#

like, literally send an email to one from above?

fiery turtle
#

yup

left orbit
#

one of the addresses

#

ah ok

fiery turtle
#

thats how mailing lists work

left orbit
#

fair lol

fiery turtle
#

usually u Cc the mailing list as well, but for inqueries u dont have to

left orbit
#

apparently the guy works at intel and lives in poland

#

from a quick google search lol

fiery turtle
#

ah

strong heath
#

full doxx in preparation of the talks

left orbit
#

:^)

fiery turtle
#

lol

strong heath
#

bring pictures of him cheating on his wife

#

as blackmail

left orbit
#

gotta have the upper hand /s

fiery turtle
#

true

calm latch
fiery turtle
#

more fake bug reports for me to figure out thanks trl

slim panther
#

im guessing then that linux pulls in uacpi sources directly, right?

#

*would pull

fiery turtle
#

yeah

calm latch
#

just let everyone else (haiku, bsds, ros) switch to uacpi

#

then it's gonna be linux's problem that they're the only ones using acpica

slim panther
calm latch
fiery turtle
#

freebsd would be cool as well

strong heath
#

what is a ros

fiery turtle
#

maybe after haiku(?)

calm latch
#

ReactOS

slim panther
#

freebsd mlibc would be cool

strong heath
#

reactos exists? damn

strong heath
#

dont push your luck

fiery turtle
#

reactos is getting better

left orbit
#

freebsd uacpi would be cool

slim panther
#

why

strong heath
#

because freebsd is all into using their own stuff

fiery turtle
#

i wonder if freebsd also calls into acpica directly

calm latch
fiery turtle
#

yeah

strong heath
#

they only dont use their own stuff when they have absolutely no other chance, like, using the AMD drivers

fiery turtle
#

(or acpi)

slim panther
#

turns out writing gpu drivers is fucking painful

#

(who would have guessed)

fiery turtle
#

although there is a BSD that rolled their own acpi

left orbit
#

who would have thought

fiery turtle
#

idk how well that went

calm latch
left orbit
slim panther
left orbit
#

considering you did it solo and it’s better than acpica

fiery turtle
#

true

#

qwinci did as well

left orbit
#

but is it really that high of a bar :^)

slim panther
#

and there's a lot of time and dedication that went into it

left orbit
#

yeah ofc

fiery turtle
#

it only took me 2 years trl

calm latch
left orbit
strong heath
#

you could concievably have the acpi guy on a 10-15 people project

#

just working on that

#

if I had those resources in Ironclad, I would maybe do that

#

because C vs Ada

left orbit
#

formally verified aml interpreter

calm latch
#

and then aml just does while (1) ;

strong heath
#

but 1 out of 15 seems fine use of resources

fiery turtle
#

ah

#

u should advertise how much u pay for ironclad features

#

people assume its probably like 10 euro

strong heath
#

I plan on doing so

#

put some job posting, some bug bounties

fiery turtle
#

yeah

strong heath
#

I also got an announcement to do regarding that on some Ada events

#

to get some eyes on it

fiery turtle
#

nice

fiery turtle
#

and find rare bugs etc

median crest
#

Time to learn ada and put even more bugs in ironclad

#

So you can get even more payouts

#

Business grindset $$$$

strong heath
#

C++ mindset

fiery turtle
strong heath
#

I was one day bored and say in quora that american boats use Ada

#

I like boats

#

so I learned Ada

fiery turtle
#

i had a similar experience but with planes

strong heath
#

where is your Ada uACPI then

fiery turtle
#

apparently all autopilot/fmc software is ada

strong heath
#

yeah pretty much

fiery turtle
#

naah im a c guy

left orbit
#

based

strong heath
#

one of us.... one of us.... one of us....

#

you will one day..... be one of us....

left orbit
#

zig when

strong heath
#

never

fiery turtle
#

ill give it a try i swear lol, ive been wanting to

left orbit
#

been waiting so long nooo

#

i believe 🙏

median crest
#

Write an os in lua because lua is brazilian tech so its the best

fiery turtle
#

maybe ill contribute sometihng to your zig os eventually meme

left orbit
#

yooo that’d be sick

fiery turtle
#

letsgo

slim panther
#

someone needs to pull through with a c# os

strong heath
#

I had one

#

it was aight

left orbit
#

i got a basic scheduler and dispatcher done yesterday :^) so maybe i will work on the io stack today

fiery turtle
#

when new thread, when open source ultrameme

left orbit
#

then a simple acpi and pci drivers for discovering devices

#

soon™️

#

i need a little reorganization of code

#

currently i call into hal for 90% of things that should be in ke lol

#

so it needs a little clean up

fiery turtle
#

ill be waiting

left orbit
#

oh thanks for reminding me i have to write the C api too

#

i want to be able to write drivers in C and C++

slim panther
#

rust api when

#

actually

#

i should make a bindgen for my modules

fiery turtle
#

thats cool

median crest
slim panther
#

C :)

left orbit
#

i mean i get C++ for free if i have a C api

median crest
#

The faces cancel each other so its just :

left orbit
#

so like

#

i’m not gonna make a C++ api but you can still write C++ drivers

slim panther
#

++ :

#

i should switch to meson so i can have native rust build support

mortal yoke
#

I could probably write drivers in rust too, I bet there is some kind of wdk crate out there meme though one bad thing is that there is no native seh support in rust so gl if you pass some garbage pointer to some kernel function and it raises an exception

fiery turtle
#

truue

mortal yoke
# slim panther wdym

well actually most of the kernel functions don't generate any exceptions visible to the outside but you could have smth like ```rust
unsafe fn handle_device_control(device: *mut DEVICE_OBJECT, irp: *mut IRP) {
let slot = IoGetCurrentIrpStackLocation(irp);
if (*slot).RequestorMode == UserMode {
let addr = (*irp).AssociatedIrp.Systembuffer;
// generates STATUS_ACCESS_VIOLATION exception if a kernel mode address/unaligned address is passed
ProbeForRead(addr, 1, 0);
// can generate an exception too if the user address was unmapped/mprotected
(addr as *mut u8).write_volatile(1);
}
}

slim panther
#

oh you mean in NT context

mortal yoke
#

yes lol

slim panther
#

i skipped over the wdk part

#

xd

fiery turtle
#

just released uacpi 2.0

lofty dragon
#

🎉

strong heath
#

okay okay

vale isle
#

we getting to chromium version numbers with this one

lofty dragon
#

<3 semver

median crest
#

The year is 2057. It is the year of the managarm desktop. Uacpi 327492.0.2 is out

fiery turtle
#

lol

slim panther
fiery turtle
#

it's a breaking change technically so i have to bump the major number sad

vale isle
#

y'all know how some projects go like 1.6, 1.7 and then drop the 1 and release 8.0

slim panther
#

imagine mlibc did that 🤯

vale isle
#

like add a new major-major

slim panther
#

at least you do semver (based)

strong heath
#

its better to have a 13.0.1 than having to change half of your code with a major release every 6 months

vale isle
strong heath
#

these people are haters

strong heath
median crest
#

I wouldnt know how to do semver properly for a project like an os

vale isle
strong heath
#

I use semver for Ironclad, I am pre 1.0 though so it didnt really kick in

vale isle
#

:clueless:

fiery turtle
#

when ironclad 1.0

median crest
#

Just call it alpha for all of infnity

vale isle
#

what I plan on doing for my OS is pre-1.0 cargo-flavoured-semver

slim panther
#

i mean at what point is a kernel really 1.0

vale isle
median crest
strong heath
slim panther
#

is factorio portable

strong heath
#

I honestly dont make releases because I am lazy

slim panther
#

i mean the wine version should be

vale isle
median crest
#

Managarm ran factorio

slim panther
#

omega zased

median crest
#

I tried running factorio in astral but it segfaults in wine and the glibc shim

#

💔

fiery turtle
#

fix it 😡

#

i didnt compile the entire astral for no reason

median crest
#

I give you the factorio zip, instructions to enable syscall logging and you do it meme

fiery turtle
#

damn

median crest
#

I like that they give drm free versions if you own the game

#

I was trying to get wow64 working on astral but wine seems to not look in /lib/wine for the dlls for some fuckin reason

fiery turtle
#

whats next on the list for astral atm

hollow elm
#

astral automated teller machine

slim panther
#

steam

vale isle
#

Versions are considered compatible if their left-most non-zero major/minor/patch component is the same. This is different from SemVer which considers all pre-1.0.0 packages to be incompatible.

cargo-flavoured semver is the best

median crest
lofty dragon
fiery turtle
slim panther
#

idk

vale isle
#

ok it needs a noun

median crest
#

Time to shill astral for the higher ups and have it run on the atms

vale isle
#

what's a noun that starts with l

#

related to finance

fiery turtle
#

this is how u know its top quality software

lofty dragon
#

lol

dire owl
#

liability

vale isle
#

lol

dense steppe
#

leverage

severe swift
#

leveraged to my personal risk tolerance

#

(x125 lever on bitcoin shorts on binance)

mortal yoke
# flat badge What's the glibc shim?

the preloadable lib that I made that contains aliases for some functions and overwrites some others like a lot of the pthread functions to make them usable from both libraries compiled against mlibc and from an executable linked against glibc

flat badge
#

Why is that needed?

#

To run closed source linux programs?

mortal yoke
#

yes

slim panther
#

games probably

mortal yoke
#

the thing that I like the most about that thing is the logic used to determine whether the caller was linked against glibc or not troll it uses dladdr1 to get the dynamic section of the caller, gets the symbol versioning information from there and looks if any symbol begins with GLIBC_ (and then if it finds symbol like that and the caller uses pthread_mutex_init etc a special flag in the mutex is set to indicate that the mutex was created from a glibc expecting executable so the other code like pthread_mutex_lock knows to use a different struct layout)

frank canopy
fiery turtle
#

true

frank canopy
#

ive not been doing irp functions until i need them so rn the only thing drivers can do is query properties but i do have a fully working driver stack complete with enumeration and even async completion support

flat badge
mortal yoke
#

well right now it just unconditionally overrides a lot of the pthread functions and the impl for them is basically copied from mlibc with some small differences to make it handle eg. the mutex created by glibc app but locked by some library case

frank canopy
#

anyway time to look at the uacpi 2.0 stuff and see what i can yeet and what changes i can make

#

so defining uacpi_use_builtin_string tells it to not assume builtins?

#

if my reading this is right?

fiery turtle
frank canopy
#

ok

#

weird name for the define but sure

#

the naming confusion between builtin (a thing what starts with __builtin and comes from compiler) and builtin (a thing what is built into uacpi) is confusing

calm latch
#

I think I kinda have an ACPI bus discovery mechanism rust

frank canopy
#

nice

calm latch
#

(now I just need to implement deserialization in C++)

calm latch
calm latch
frank canopy
#

uid is context dependent i think?

#

but yeah tbh i can see why uid would be like the english version of mls for some things

#

only requirement for uid is it must be unique across the same HID/CIDs and must persist across reboots

calm latch
#

But it's the same between multiple objects?

frank canopy
#

yeah thats weird

#

" The _UID must be unique across all devices with either a common _HID or _CID. This is because a device needs to be uniquely identified to the OSPM, which may match on either a _HID or a _CID to identify the device."

#

so idk

#

the pci interrupt link devices are incomprehensible to me and those are the ones im seeing have repeats though

#

so idk on there

#

(also MLS has multiple languages to it so it should be localizable. idk how to access that info though and my kernel doesnt do localization at this point anyway)

fiery turtle
calm latch
#

(It only publishes devices for now)

#

Like now I just gotta write the init server

frank canopy
fiery turtle
#

What part specifically?

frank canopy
#

"Makes uACPI use the builtin versions of mem{cpy,move,set,cmp} instead of relying on the host to provide them." implies it should be using the __builtin if the flag is set to me

#

because thats what the phrase "builtin versions" would be expected to mean, no?

#

and then the end of the docstring on that define says that the compiler might depend on them being available even if the thing is defined which feels like a contradiction

#

how that doc comment reads to me is saying if its defined then uacpi will use the __builtin_memxxx but be aware the compiler might generate dependencies on them even if you define it (which is implied to make uacpi depend on them explicitly so of course theres a dependency on the __builtin_memxxx)

fiery turtle
#

Uacpi doesnt have any config options that are compiler dependent

frank canopy
#

i just dont see how that first sentence implies anything other than forcing the use of __builtin_memxxx

#

which is the opposite of what the define does

fiery turtle
#

Built-in to uacpi, it doesnt say “compiler intrinsic” anywhere tho

#

Im open to suggestions for better wording tho

frank canopy
#

tbh if the intrinsic didnt have builtin in the name itd be less confusing

#

id call it "default implementation" or "uacpi-provided" or something like that personally

#

uacpi-provided is my instinct

#

at least for in the doc string

#

can keep the define name for version compat if the docs make it clear

fiery turtle
#

Yeah thx

vale isle
#

it's deserialized in rust?

calm latch
#

yes

north holly
#

I will update my uacpi one day

fiery turtle
#

do it two day

keen shard
# fiery turtle do it two day

How do you test uACPI? Do you have your own operating system kernel you use it with or do you use some common unix distribution

fiery turtle
#

see tests/

#

i have a userspace port of uacpi

#

that i run against the test suite as well as real hardware blobs

keen shard
#

Does the user space port do all the same stuff just using system calls or how does that work

keen shard
fiery turtle
#

thank you

keen shard
fiery turtle
#

i wanted a fully NIH OS, and ACPI was going to be a big part of that

#

when i started out i didnt know anything about ACPICA's quality

#

i thought it was good since everyone used it

keen shard
#

But that’s fire bro keep it up

#

I’m gonna port it to mine soon

#

I’ve gotten almost all of the deps done

#

I’ll let you know when I do 💯💯💯

fiery turtle
#

letsgo!

keen shard
north holly
keen shard
north holly
#

wrong kernel

#

it dies because of obos regression #844868385737

#

(of the day)

keen shard
#

Yeah I just get the

Wel%co[*{%]*]e to FlqodidococcOS 1.02948293738;8.29382Segmentatjon fault at 0x02938382912728sjskxjdnxiekenjabcdefihatemlifeeucidnejxidodoeen

fiery turtle
dense steppe
#

How is uacpi_kernel_reset_event() used, and is it guaranteed that there is no contention on the semaphore when it is called?

fiery turtle
#

ResetOp from AML

#

no guarantees

dense steppe
#

shit

#

that means I need to actually do stuff, then?

#

should I wake up waiters and tell them the acquire failed?

fiery turtle
#

i wouldnt

#

but tbh id just see what linux does

dense steppe
#

yeah, and it'd overcomplicate stuff

dense steppe
#

and what it does is much easier

fiery turtle
#

what does it do?

dense steppe
#

basically this:

while (trylock (semaphore))
        ;
fiery turtle
#

thats smart

dense steppe
#

for me, sema_lock_timeout (sema, 0) is equivalent to trylock

#

so I can just do that instead

fiery turtle
#

yeah

dense steppe
#

I just discovered a bug in my acpi mutex implementation

fiery turtle
#

almost makes me think reset should be implemented internally be uacpi

dense steppe
#

do you see the bug?

fiery turtle
#

overflow?

dense steppe
#

no

#

it doesn't handle 0xffff

fiery turtle
#

ah right

#

ill get rid of uacpi_kernel_reset_event and just have a loop of uacpi_kernel_wait_for_event(event, 0)

#

how did i not think of that implementation

#

well i didnt because i basically stole acpica's api for events sort of

dense steppe
fiery turtle
#

not sure it matters

dense steppe
#

yeah, it probably doesn't

#

anyway

#

why are the return types of uacpi_kernel_acquire_mutex and uacpi_kernel_wait_for_event inconsistent?

#

the former returns a uacpi_status and the latter returns a uacpi_bool indicating success

#

it just seems strange

fiery turtle
#

good question

#

but tldr is there's nothing uacpi can currently do with an error for wait

#

since events are mostly used for aml

dense steppe
#

makes sense

#

yeah

fiery turtle
#

aborting is probably worse than just not entering the branch that does Wait(...) in aml

dense steppe
#

there's going to be like zero use of semaphores in my kernel besides ACPI that I can think of now

#

lol

fiery turtle
#

but yeah it was a mistake not to convert events alongside mutexes

#

i might do it later for 3.0

fiery turtle
#

not many users of it

dense steppe
#

like everything is either plain mutex or rwmutex

mortal yoke
#

I mean you can use them to implement mutexes

#
uacpi_status uacpi_kernel_acquire_mutex(uacpi_handle mutex, uacpi_u16 timeout) {
    i64 timeout_value = static_cast<i64>(timeout * (NS_IN_MS / 100));
    auto status = KeWaitForSingleObject(
        mutex,
        KWAIT_REASON::Executive,
        KernelMode,
        false,
        timeout != 0xFFFF ? &timeout_value : nullptr);
    return status == STATUS_TIMEOUT ? UACPI_STATUS_TIMEOUT : UACPI_STATUS_OK;
}
void uacpi_kernel_release_mutex(uacpi_handle mutex) {
    auto semaphore = static_cast<KSEMAPHORE*>(mutex);
    KeReleaseSemaphore(semaphore, 0, 1, false);
}
uacpi_bool uacpi_kernel_wait_for_event(uacpi_handle event, uacpi_u16 timeout) {
    return uacpi_kernel_acquire_mutex(event, timeout) == UACPI_STATUS_OK;
}
void uacpi_kernel_signal_event(uacpi_handle event) {
    auto semaphore = static_cast<KSEMAPHORE*>(event);
    KeReleaseSemaphore(semaphore, 0, 1, false);
}
void uacpi_kernel_reset_event(uacpi_handle event) {
    auto semaphore = static_cast<KSEMAPHORE*>(event);
    KeInitializeSemaphore(semaphore, 0, INT32_MAX);
}
dense steppe
torpid root
#

initialising uacpi on a thread instead of before the scheduler results in a few hundred thousand points more on average

#

only on uefi though, on bios the performance is affected negatively

#

I'm getting 4.5 million consistently on my cpu

dense steppe
#

and your CPU is?

fiery turtle
#

since aml is the same

torpid root
torpid root
mortal yoke
torpid root
#

I'm really cursed

fiery turtle
#

we really need a good automated test runner trl

north holly
#

obos is basically an automated test runner

torpid root
#

run - triple fault - run - triple fault - ...

north holly
#

what does iloblix do again?

torpid root
#

so true

north holly
#

you'll get there one day

#

right now I forgor how file reading works

fiery turtle
#

i mean a piece of hardware

strong heath
#

Use a watchdog and any existing hardware

hollow elm
#

picokvm with it wired up to press the power and reset buttons

flat badge
#

A test runner is not very hard to wire up

#

I have a bpi-f3 wired up as a test runner for RV

#

I just use a smart wall plug to turn power on/off

#
  • tftp boot + uart wired to a different machine
calm latch
#

We need a leaderboard for RISC-V trl

fiery turtle
#

risc-v qemu acpi is like 10 opcodes

kind mantle
#

lmao

flat badge
#

The board doesn't have acpi

#

I use it to test managarm, not uacpi

#

But the same approach would also work for uacpi on x86

calm latch
#

Do ARM and RISC-V have sleep states as well?

fiery turtle
#

yes

flat badge
#

RISC-V can sleep using SBI

#

I'm not sure how this is wired up to ACPI

#

it'd help if they released a proper acpi spec with risc-v support in it meme

calm latch
#

there are ECRs in github issues pointing to google drive links trl

kindred beacon
#

last time I checked the links were dead

#

this does not include RISC-V shit tho??????????????????????

#

bruh

#

waiting for 6.6 then

calm latch
#

Should've saved the rest

#

Is it even worth supporting 64 bit wakeup vector memes?

kindred beacon
calm latch
#

Like they were not dead a year ago

calm latch
#

So like just having the 16 bit mode one is fine?

fiery turtle
#

the 64-bit one is protected mode

#

and idk if anyhing supports it

calm latch
#

Does everyone folow this?

Platform runtime firmware restores the pre-sleep configuration or initial boot configuration of
each CPU (MSR, MTRR, firmware update, SMBase, and so on). Interrupts must be disabled (for IA-32 processors, disabled by CLI instruction).

#

Wait, initial boot

#

Still

#

I think someone was saving MTRRs here?

fiery turtle
#

i wouldnt rely on it

calm latch
#

Ok the spec is very short and looks very easy

#

(famous last words)

fiery turtle
#

did u read the stuff about _PRW etc

#

oberrow will know more

calm latch
#

I've read chapter 16

#

Which is about _TTS, _PRW, _PTS and _WAK

north holly
#

idk what _TTS does

#

_WAK is handled by uacpi_prepare_for_wake_from_sleep_state

#

_PTS is from uacpi_prepare_for_sleep_state

#

_PRW is fnuy

#

let me go back to my suspend code to see what it did again

#

ok yeah so PRW basically tells you the power resources needed to be enabled for the device to wake u

#

and also tells the deepest state the device can wake you frame

#

as well as the gpe index that you should use uacpi_setup_gpe_for_wake on

#

btw it mentions something about gpe block devices, ignore that

#

infy said a while back they don't exist

north holly
#

if _PSW doesn't exist, obos ignores the error and continues

#

after doing that you can simply put the device into the deepest state supported for wake from _Sn

#

(there was a chart for that in the acpi spec)

north holly
#

I just call _ON on each one

#

but technically they should all be enabled before suspend, unless manually disabled

#

but I enable them manually anyway

calm latch
#

What do I do with TTS?

north holly
#

never heard of it

calm latch
#

16.1.6 Transitioning from the Working to the Sleeping State
On a transition of the system from the working to the sleeping state, the following occurs:

  1. OSPM decides (through a policy scheme) to place the system into the sleeping state.
  2. OSPM invokes the _TTS method to indicate the deepest possible system state the system will transition to (1, 2,
    3, or 4 representing S1, S2, S3, and S4)
north holly
#

ignore

#

if you want to go to _S3

#

you check if S3 exists

calm latch
#

Control method used to prepare to sleep and run once awakened

north holly
#

uacpi probably does that for you

#

in prepare for sleep state

#

cc @fiery turtle

north holly
#

yes I see it

fiery turtle
north holly
#

hmm it says _TTS

calm latch
#

9.2.1 _SST (System Status)
This optional object is a control method that OSPM invokes to set the system status indicator as desired

calm latch
fiery turtle
#

linux calls it on its own

north holly
#

oops

calm latch
#

inb4 seabios bug was obos bug

north holly
#

no it is a seabios bug

#

crescent also works with my patch

fiery turtle
#

that said obos did die on some real hw

north holly
#

said hardware doesn't have _TTS

fiery turtle
#

out of 500 blobs only macbook pro 12/14 have it

calm latch
#

So basically,

  1. I have to implement wakeup vector
  2. I have to call a bunch of ACPI methods
  3. Profit?
fiery turtle
#
❯ grep -rn '_TTS'
Notebook/Apple/MacBookPro12/MacBookPro12,1/A236F4DD9072:9015:    Method (_TTS, 1, NotSerialized)  // _TTS: Transition To State
Notebook/Apple/MacBookPro12/MacBookPro12,1/A236F4DD9072.bin:2676:    79A0: 5F 12 08 03 0A 07 0A 07 0A 00 14 0C 5F 54 54 53  _..........._TTS
Notebook/Apple/MacBookPro14/MacBookPro14,3/91077C25D705:10177:    Method (_TTS, 1, NotSerialized)  // _TTS: Transition To State
north holly
north holly
#

smp trampoline

calm latch
north holly
#

ah well

calm latch
#

And I need some system to park cores?

fiery turtle
#

people raised by limine

north holly
fiery turtle
#

dont have smp startup code

#

L

north holly
#

L

calm latch
#

L

north holly
#

smp trampolines are always fun to write

calm latch
#

My pmm has memory zones though

north holly
#

idk what that does

calm latch
#

So it shouldn't be hard to allocate memory below 1MB

north holly
#

I just hardcode the smp trampoline at 0x1000 meme

#

(btw doing it at phys. 0 will not work in any case)

calm latch
#

No, this is too boring

#

I need to dynamically allocate it

north holly
calm latch
#

And patch the code to load the right page table top level pointer

#

Into cr3

#

Anyway

north holly
#

other than acpi stuff, you should probably get a way to tell your drivers that you are going into suspend

calm latch
#

I can then just pagefault to success

fiery turtle
calm latch
calm latch
#

Like this needs to be a syscall

north holly
#

make a worker thread, bind it to one core

#

syscall to park other cores

calm latch
#

Because I will not do @ monkous memes and I will let uACPI enter S3 from userspace instead

north holly
calm latch
#

So like the only thing I need from kernel is a syscall to flush caches and a wakeup vector?

north holly
#

btw here is a list of what you need to save before S3 (that you might forget about) on x86-64:

  • HPET status
  • LAPIC status
  • IOAPIC status
  • PCI status
  • ACPI NVS ram regions (some devices don't need to / cannot do it, so add a kernel command line option to enable/disable this)
  • and that should be it
north holly
#

and also you will need to wake other CPUs again

north holly
calm latch
#

Shouldn't be hard though

north holly
#

nah

#

(it only resulted in a full PCI interface rewrite for me)

#

((nothing big))

#

btw unless you have my patched seabios, if you use PCIe, it will be broken

#

after wake from suspend

calm latch
#

I will see

#

My kernel devicesd server already keeps the list of PCI devices

#

Apparently

north holly
#

what about BARs

#

command register

#

MSI

#

any IRQ pin status

calm latch
#

I just add a few fields and then memcpy?

#

Also I can just let device drivers take care of it
(except that it would be a race condition)

north holly
#

ok...

#

iirc the PCI cap list is intact after wake from suspend

calm latch
#

Ok, I need to look how to implement SMP wakeup vector

#

/ACPI

#

(My hyper builds have no SMP for now)

#

(so that also needs to be taken care of (eventually))

north holly
calm latch
north holly
#

kys (keep yourself safe)

calm latch
#

(/s)

#

(although I prefer AT&T trl)

#

Do you keep cr3 in < 4GB?

north holly
#

yes

calm latch
#

unfortunate...

north holly
#

wha

#

it is quite fortunate

#

because my pmm has zones

#

so I just tell it to allocate a 32-bit cr3 for the kernel

#
obos_status Arch_InitializeKernelPageTable()
{
    obos_status status = OBOS_STATUS_SUCCESS;
    uintptr_t newCR3 = Mm_AllocatePhysicalPages32(1,1, &status);
    uintptr_t oldCR3 = getCR3();
    // ...```
frank canopy
#

i should work on smp at some point tbh

calm latch
#

I can't load 64 bit idt (except...) and I can't jump to 64 bit address (also except...)

#

Does jmp extend sign?

#

If the kernel is in -2GB

north holly
#

huh

#

why would you load the idt before being in long mode

#

in this case

calm latch
#

So I can pagefault to success

north holly
#

what

#

go to long mode

calm latch
#

Or I need to jump to somewhere in -2GB

north holly
#

load idt

#

then do whatever shit you want

calm latch
#

Also kaslr says trl

#

I'll just patch assembly trl

mortal yoke
#

?

calm latch
#

not assembly, but assembled code

#

idk I'm tired today

mortal yoke
#

you can just have a structure at the end of the trampoline and fill in the jump address to there

north holly
#

you are not making sense go to sleep and come back

calm latch
#

but I want my trampoline to be relocatable

#

(Which does not change anything)

mortal yoke
#

you can do cs relative accesses

calm latch
#

yeah

mortal yoke
#

if you don't want to patch instructions that is

calm latch
#

But still

north holly
#

jump to the jump address in long mode
so then you can use rip-relative accesses

calm latch
#

I'm doing far jump

#

Setting cs to 64 bit one and all the fancy stuff

fiery turtle
#

just mov rax, addr jump rax

calm latch
#

Does it do sign extension?

mortal yoke
#

you first enter long mode to a label within your tramp

fiery turtle
#

^

#

offset can be relative

mortal yoke
#

and after you are in long mode you do a normal jump to the actual dest

calm latch
#

I want that label to be in higher half directly

north holly
#

why

calm latch
#

Because otherwise I would need id mapping

#

(which is a single PDE)

#

(but anyway)

mortal yoke
#

its very likely not possible

north holly
#

exception thrown in my brain: e.what(): "what are you smoking?"

mortal yoke
#

you need an identity mapping for enabling paging anyway

#

like you can't just be in a random lower half page that is not mapped when you enable paging (and you can't be in higher half either because paging is not active yet)

calm latch
#

ChatGPT says this is possible trl

left orbit
#

chatgpt says a lot of things

#

gg

calm latch
#

Real mode doesn't have paging

#

So I enter long mode from real mode, the far jump would enable paging

#

If jmp does sign extension, I can jump directly to higher half address

#

Or am I too tired

left orbit
#

i dont think so lol

mortal yoke
#

afaik paging is activated immediately when you enable it in cr0 and not delayed like that

calm latch
#

Ok I forgot how to x86

left orbit
#

so you definitely do need identity mapping

#

at least a single page

calm latch
#

It enters compat mode

#

then 2, if idtr does sign extention, I could pagefault to the right address

mortal yoke
#

bru

calm latch
#

Ok fine I'll just map that page

#

But then I won't be able to detect kernel nullptr derefs

mortal yoke
#

it doesn't have to be page 0

calm latch
#

It can be page 0

north holly
#

wrong

calm latch
#

My pmm can suddenly decide it's page 0

north holly
#

the acpi spec does not allow that for wake from suspend's

mortal yoke
#

yeah that too

calm latch
#

That's anoying

mortal yoke
#

its not

north holly
#

no not really

#

also the IVT

#

is at address zero

#

so you can't even put it at phys. zero if you tried

#

otherwise you'd overwrite the IVT

#

and cause the firmware to triple fault (which I have experienced on qemu!!)

mortal yoke
#

also you could always only map the trampoline before needing it and unmap after you are done using it

north holly
#

this

calm latch
#

Anyway, before the smp trampoline
I have to make sure that entering S3 from userspace (by which I mean writing whatever to SLP_TYPx in Ring 3) doesn't destroy kernel state

north holly
#

park all other CPUs

#

and you're fine

#

*if you also make sure the current CPU doesn't get rescheduled until the wake

calm latch
#

I need to make sure I don't get a timer interrupt or whatever and uACPI doesn't get preempted unexpectedly

#

and also that the kernel is able to schedule uACPI server after wakeup

#

the hardest part is timers (?)

#

Can I have problems if I don't enter S3 from bsp?

north holly
#

hopefully not

#

although I don't depend on that

#

and make sure the suspend helper frame is pinned to the BSP

calm latch
#

Do I get NVS regions from limine?

fiery turtle
#

yes

calm latch
#

Ok, entering S3 was trivial

#

Now I just need to wake up trl

#

(my testing PC is very confused trl)

#

It showed 03 POST code, then a bunch of stuff, then went to sleep

frank canopy
#

i wish i could make limine give me the mp info without bootstrapping the APs tbh, im gonna need a trampoline anyway for possible suspend/wake so like what would be the point in having limine do it

#

uacpi tables only mode when lol

#

(so i can make a bootloader that does what i want)

left orbit
#

how about making a pr to limine to do exactly that? :^)

#

adding a simple flag to the mp request would be simple enough

#

limine source code is very approachable

left orbit
#

tbh it doesnt matter that limine starts them up for you

kindred beacon
#

I honestly don't get the point

left orbit
#

you can just ipi them and start them up again yourself

frank canopy
left orbit
#

of course you can

north holly
#

ye ofc

frank canopy
#

ok in that case im good

left orbit
#

C is just like zig

#

but less ziggy

#

and more like C

frank canopy
#

the ziggyness is why i like zig over c lol

rustic compass
#

lenovo x270 aquired letsgo

rustic compass
#

now i need a os to test uacpi on it and dump the tables

kindred beacon
#

how is the policy for adding table structs to uACPI?

#

esp for non-standard (as in, not part of the ACPI spec) tables like DMAR

flat badge
#

@fiery turtle

fiery turtle
#

any new tables are welcome

kindred beacon
#

surprising but nice

fiery turtle
#

i mean it already has hpet and mcfg

kindred beacon
#

fair

kind mantle
calm latch
#

Is fadt preserved between sleeps?

#

Or do I need to be setting wakeup vector every time?

fiery turtle
#

The wake-up vector is stored in facs

#

Its just ram so I don't see why it wouldn't

calm latch
#

what if there's some insane firmware which overwrites it, idk

fiery turtle
#

Perhaps

left orbit
#

then that isn't your problem, perhaps

#

print a big ass warning with bios interrupts

#

YOUR FIRMWARE IS STUPID

#

PLEASE BUY A NEW COMPUTER

#

and halt in a loop

#

easy

fiery turtle
left orbit
#

but realistically just see what linux does tf

lofty dragon
#

i will now port uACPI to Vinix

fiery turtle
#

Letsgo

left orbit
#

finally 🙏

lofty dragon
#

i will do that until i am eepy to go to sleep

fiery turtle
#

Good way to fall asleep

lofty dragon
#

fr

#

it's building llvm

#

i need to wait for it to finish now

#

i don't wanna interrupt it

fiery turtle
#

Might as well sleep

lofty dragon
#

ok i'll interrupt it

fiery turtle
#

Lol

fiery turtle
lofty dragon
#

acceptable

#

but i still have to write the bindings

fiery turtle
#

Can you just import c headers

#

Oh

left orbit
#

oh god lmao have fun

#

isn't there v2c?

fiery turtle
#

Convert the entire types.h and resources.h trl

#

Also me when there's like 3 or 4 kernels written in zig that use uACPI but no official bindings sad

#

I also saw one on github recently

left orbit
#

imaginarium has some bindings in tree

#

but i havent looked at them

#

learn zig and write official bindings

fiery turtle
#

Does zig have like a package manager where you would put them or how does that work

left orbit
#

sort of

#

how it works is you just fetch tarball or other form of sources

#

like uhhh

#

one sec

left orbit
#

there's thie build.zig.zon file you can put your dependencies in

#

and build.zig fetches them for you

#
.{
    .name = "zigux",
    .version = "0.0.0",
    .dependencies = .{
        .@"freestnd-c-hdrs" = .{
            .url = "https://github.com/osdev0/freestnd-c-hdrs/archive/21b59ecd6ef67bb32f893da8288ce08a324d1986.tar.gz",
            .hash = "1220a5942e368a8780187b9138b5db8c24f098533d6084c58d1122378bb4a31dcfd5",
        },
        .limine = .{
            .url = "https://github.com/48cf/limine-zig/archive/7b29b6e6f6d35052f01ed3831085a39aae131705.tar.gz",
            .hash = "1220f946f839eab2ec49dca1c805ce72ac3e3ef9c47b3afcdecd1c05a7b35f66d277",
        },
        .uacpi = .{
            .url = "https://github.com/uACPI/uACPI/archive/757dcece1a9f1c069355b23f7feaf21656728f94.tar.gz",
            .hash = "12200468fb671c04225f04d87e0fe1131e49ccd153e870be6e858dc80e39cb4e18df",
        },
    },
    .paths = .{"."},
}
fiery turtle
#

Interesting

left orbit
#

you can grab them in build.zig, either treat them as zig modules (if they have a build.zig) or just use the include directories or source files directly

fiery turtle
#

Also os name leak

left orbit
#

const freestnd_c_hdrs = b.dependency("freestnd-c-hdrs", .{});

#

this is how you refer to them in build.zig

#
kernel.addIncludePath(
    freestnd_c_hdrs.path(b.fmt("{s}/include", .{@tagName(arch)})),
);```
fiery turtle
#

Makes sense

left orbit
#

and here i add the include path for the freestanding headers to the kernel executable

#

so it ends up being ${source_dir}/${arch}/include

#

the source dir for the dependencies usually points somewhere inside the zig cache

#

there's 2 zig caches though, one in your home directory and one in the project root

#

~/.cache/zig and ./.zig-cache

fiery turtle
#

Whats the global cache for?

left orbit
#

honestly idk what its used for but i think caching dependencies

#

so the same tarballs can be reused across multiple projects

#

they are identified by the hash so

#

if it sees the same hash in the global cache it can just get it instead of downloading it again

#

thats why its important to change the hash when updating the url in the build.zig.zon file

#

or dont do it manually and just use zig fetch :^)

#
hacker@raptor:~$ zig fetch --help
Usage: zig fetch [options] <url>
Usage: zig fetch [options] <path>

    Copy a package into the global cache and print its hash.

Options:
  -h, --help                    Print this help and exit
  --global-cache-dir [path]     Override path to global Zig cache directory
  --debug-hash                  Print verbose hash information to stdout
  --save                        Add the fetched package to build.zig.zon
  --save=[name]                 Add the fetched package to build.zig.zon as name
  --save-exact                  Add the fetched package to build.zig.zon, storing the URL verbatim
  --save-exact=[name]           Add the fetched package to build.zig.zon as name, storing the URL verbatim```
calm latch
#

how do I wake qemu up? meme

left orbit
#

system_wakeup

#

in monitor

calm latch
#

I've put a while 1 loop in assembly at my wakeup vector, and gdb doesn't reach it

fiery turtle
left orbit
#

ah even better, didnt know

fiery turtle
#

It won't wake up if u didnt do any wake gpe configuration

gentle peak
#

break can be a bit finicky during cpu init

calm latch
#

just ctrl+c whatever?

gentle peak
#

ah

calm latch
gentle peak
#

nevermind then

calm latch
fiery turtle
calm latch
#

It said "QEMU paused"

#

Also that same code (without complications) did suspend my test PC

frank canopy
#

instead of the archive url

left orbit
#

damn that's nice

#

that is not documented anywhere lol

gentle peak
#

why would you choose to bypass the CDN like that

frank canopy
#

and if you give it a tag/ref on the command line itll figure out what commit to use

gentle peak
#

or well

#

not bypass

#

but still git clones are significantly slower than regular tarball downloads in my experience

calm latch
frank canopy
#

its more about being able to tell it a ref and have it resolve it

fiery turtle
#

And he won't write a wiki article

gentle peak
# calm latch

This seems like a triple fault with -no-reboot -no-shutdown

left orbit
#

gatekeeping the suspend to ram knowledge smh

calm latch
#

I could use bochs, but I need to fix my PCI functions

fiery turtle
calm latch
frank canopy
#

also worth noting on the zig dependency things, the dependency you fetch doesnt have to have any zig build support - the dependency object you get has a path method to get a dependency-relative path you can give to things in your main build. i use that to get both uacpi and limine binaries

gentle peak
#

Oh, hmm

calm latch
#

Like before I was setting wakeup vector, it was properly tripple faulting

fiery turtle
#

So does it wake or not

left orbit
calm latch
calm latch
fiery turtle
#

Also make sure you're not trashing bios state with your low mem allocator

calm latch
#

it shouldn't be

fiery turtle
#

Because of a bios bug

calm latch
#

anyway, I don't care about PCI for now

fiery turtle
#

Yeah idk why your wake vector is bogus

#

Check bios logs

#

Isa-debugcon or whatever

frank canopy
#

oh and last zig uacpi bindings note: you dont technically need them at all

calm latch
left orbit
frank canopy
#

can just

const uacpi = @cImport({
    @cInclude("uacpi.h");
    // repeat for other headers
});
#

but yeah native bindings are better

calm latch
#

I need to printf

loud ice
#

i thought you dont need one? ah nvm

gentle peak
frank canopy
#

ive got a whole bunch of stuff already bound and ill probably throw a license exception thing for the bindings in imaginarium allowing uacpi to adopt them officially

fiery turtle
#

Is imaginarium gpl?

left orbit
#

mpl-2.0

#

according to github

frank canopy
#

mpl-2 yeah

fiery turtle
#

Ohh

#

Would be great ofc

frank canopy
#

i dont use the incompatible with secondary licenses thing but ill still probably add a note for uacpi adoption for clarity anyway

fiery turtle
#

Letsgo

calm latch
kind mantle
north holly
calm latch
#

I need more printfs

fiery turtle
north holly
gentle peak
fiery turtle
#

Ohh

kind mantle
#

I thought it woke up in long mode

north holly
#

_S3 throws you in real mode on wake

fiery turtle
#

I mean yeah CPU is reset

north holly
#

poor thing

fiery turtle
#

So it starts in real mode

north holly
#

that's only _S2/_S1