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

1 messages Β· Page 4 of 1

left orbit
#

its very aggressive when it comes to optimization

#

i think

fiery turtle
#

Like error messages?

#

Or ub

left orbit
#

ub

#

or more like

#

stuff that you wouldnt expect from your program

#

also the lto is enabled by default

#

some might find that to be nice, but it tends to be too good

#

also clashes with inline assembly nuking half of the symbols from the binary :^)

#

but that is most likely a zig bug, hopefully fixed in the future

#

and of course the compiler is very pedantic, for example if a variable is never written to it will emit an ERROR that you HAVE to make it const

#

or if you have unused parameters/variables... but you can use _ = expr; syntax for that, basically discarding them... which turns into an error if you use them later lol

#

i hope you can see how that might get a bit annoying after a while

#

</rant> sorry for hijacking thread :p

fiery turtle
#

Lol damn

#

Yeah thats a lot

#

Clearly not production ready yet

fiery turtle
left orbit
#

there's a reason it's 0.13, not 1.x i guess

fiery turtle
fiery turtle
left orbit
#

found some funkiness with pointer const-ness in uacpi apis, zig's translate-c translates const char ** in uacpi_device_matches_pnp_id as a non-const array of [*c]const uacpi_char, which would make sense if it wasn't for the fact it tells zig that uacpi will mutate the array :p

#

i am going to solve this with a @constCast for now but it would be really nice if you could go over the apis that take read-only null terminated arrays, like uacpi_device_matches_pnp_id does, and make sure it is properly marked as const

fiery turtle
#

Thanks for bringing that up

left orbit
#

happy to help!

#

c interop from zig is such a chore lol, but i "finished" implementing uacpi support in my kernel, now i discover pcie root buses and ps2 keyboard controllers by calling uacpi_device_matches_pnp_id :^)

fiery turtle
#

But nice

#

I have an example of usage on the wiki

fiery turtle
#

Not that what you're doing is wrong, just some suggestions

fiery turtle
#

Strangest uACPI usage I've seen

#

This guy copied some files and split some of them into other files, rewrote some of it

hollow elm
#

ucapi

fiery turtle
#

Made his own structures for some reason

#

And still does the _S5 manual scan from osdev hacks

fiery turtle
#

I mean its MIT so its whatever, just strange

jaunty fox
north holly
jaunty fox
#

Folder structure also dumb it's dozens of folders each with one or two one function files in most cases it's disgusting

hollow elm
fiery turtle
jaunty fox
#

This arsehole also too much of a bastard devoid of scruples to follow the SINGLE requirement of Mit licence

#

He stripped it our. You can't do that it's a violation

fiery turtle
#

True lol

hollow elm
#

dmca time halfmemeleft

fiery turtle
#

He didn't do it out of ill intent tho

#

I mean he does have the repo starred

#

So probably just doesn't know how these things work

vagrant hull
#

lmao

#

what a knob

#

and of course he has a shitty borked BIOS bootsector "bootloader"

fiery turtle
#

Lol

sterile egret
#

lmfao

fiery turtle
#

He also added gpl headers to uACPI files

#

I guess we GPL now lmao

hollow elm
sterile egret
#

oh my god, no consistency in naming

#

probably all Ctrl-C/Ctrl-V I suspect meme

hollow elm
#

Starting the Kheap...
Starting the Kheap..
Kheap is getting started...

vagrant hull
fiery turtle
#

What the hell

north holly
#

worse code than @dusky glade's code

rain nimbus
dusky glade
fiery turtle
vagrant hull
#

minor patch

dusky glade
#

minor patch

north holly
#

lol wtf is this kernel

fiery turtle
#

This is some cursed stuff

north holly
#

the description looks AI generated

dusky glade
#

πŸ’€

#

bros code looks ai generated

north holly
#

he must be an AI

#

then

dusky glade
#

fr

fiery turtle
#

So many words that carry 0 information

sterile egret
#

My pronouns are now power/supply

fiery turtle
#

Lol

#

a/h/c/I when

north holly
#

especially considering his other two repos' descriptions are gramatically incorrect

rain nimbus
north holly
#

he has a fork of uACPI

#

and continues to not modify uACPI in it at all

fiery turtle
#

Probably realized he cant make it GPL

#

lmao

sterile egret
#

This code is too shitty to be AI generated

fiery turtle
#

Yeah the code is hand written

rain nimbus
#

ByteSmart-Compiler Public
A compiler which calculates a mathematical/human readable data and convert it to bit code.
Dafuq does that even mean xD

fiery turtle
#

Maybe with copilot

sterile egret
#

arch/alpha? what the fuck

north holly
#

what the actual fuck is this naming ""convention""

hollow elm
sterile egret
#

Yeah that^

hollow elm
north holly
hollow elm
sterile egret
sterile egret
#

LMFAO

#

95 FILES FOR THE GDT

rain nimbus
#

wtf

north holly
#

wtf

fiery turtle
#

Is this like a meme project or what

rain nimbus
#

And I thought my 2 files were a lot kekw

fiery turtle
#

Or is this guy mentally ill

hollow elm
north holly
#

This has 2500 commits

vagrant hull
north holly
#

who would spend that much time just to troll

vagrant hull
sterile egret
#

fractals of stupidity

north holly
#

this kernel

#

is frankenstein

#

basically

fiery turtle
vagrant hull
#

a meme kernel made by some Russian child that i have also gotten banned off github 3 times for harassment

fiery turtle
#

Lol

vagrant hull
#

""""kernel""""

#

it did not actually build

#

it was just a random mish mash of nonsense

fiery turtle
#

Have you actually verified that this builds halfmemeright

vagrant hull
#

no lol

north holly
#

well

#

they have github verify it

fiery turtle
#

Oh

north holly
fiery turtle
#

Damn

#

I doubt its a meme then

north holly
#

also

fiery turtle
#

Just really weird stuff

north holly
#

over 2 months wtf

north holly
vagrant hull
#

grujb????

rain nimbus
fiery turtle
#

Wtf

rain nimbus
#

Straight up feels like that one kid who made a shader from scratch, which totally wasn't stolen from cherno O_O

north holly
#

I have lost too many brain cells as a result of this to continue looking at the code

fiery turtle
#

Has to be either a child or mentally ill person

rain nimbus
#

"Hey I'll give you my solution, just don't straight up copy it"
"Yeah sure I'll change some things"
Changes only the filename

vagrant hull
#

why the fuck does it have a Makefile.am that isn't automake and there is no autotools usage that i can tell

#

this is literally just random shit

fiery turtle
#

Im actually laughing out loud lmao

north holly
#

lol

fiery turtle
#

This shits insane

north holly
#

abbreiviation fail

vagrant hull
#

how did you even find out about this

fiery turtle
#

This guy starred uACPI and has a fork apparently

sterile egret
fiery turtle
#

I just saw it

vagrant hull
#

ah

fiery turtle
north holly
#

ok good my kernel isn't here

rain nimbus
#

I read ToaruOS as "A certain OS" O_O

north holly
#

so @rain nimbus, when you making kernel?

hollow elm
sterile egret
#

There's so many different kernels in this repo lol

rain nimbus
# north holly so <@272414379083825154>, when you making kernel?

Well rn I'm doing some rendering stuff, wanting to make a path tracing based engine using wavelengths for more beautiful renderings PogW
And then once I'm done with the next two exams I'll go back to finishing HTTP1.1, HTTP2, HTTP3 and TLS1.3 implementations for my secrets manager (well more like a shared library I use in most of my C++ projects). And once I'm fully done with the secrets manager I'll go back to working on the kernel :>

#

Give it like 3 months, or roughly to august

#

Then maybe I'm done xD

rain nimbus
left orbit
#

translate-c doesn't seem to like that atm

fiery turtle
left orbit
#

not really, at least not in the C sense

fiery turtle
#

Damn

left orbit
#

zig has it's own packed structs, which is basically a struct backed by a single integer type

#

but they aren't abi compatible with C

fiery turtle
#

I see

#

Might make user api like that use flags instead of bit fields

left orbit
#

so i'll just have to manually mask out bits from that field it seems Lol

fiery turtle
#

But for native C code this is more convenient

left orbit
#

that would be nice

#

yeah definitely

#

i wonder how rust handles that

#

with regards to C interop

fiery turtle
#

Yeah interesting

#

Zig could at least add helpers for that

left orbit
#

oh god the string length includes the null terminator

fiery turtle
#

Yeah

left orbit
#

i hope that it's consistent at least, but imo string lengths shouldn't include the null terminator

fiery turtle
#

So that all api that has lengths is consistent and also no empty strings

#

Yeah I just copied that api aspect from acpica

left orbit
#

a bit unrelated but what is the pci host bus "segment"? it seems that they it's not part of the address, what is it used for?

fiery turtle
#

Just another level

#

Its new in pcie

#

Look at osdev wiki I guess

#

It used to be BDF now its SBDF

left orbit
#

ahh PCIe stuff, my knowledge when it comes to that is minimal unfortunately

#

i still access the config space using port io, i should probably work on that!

fiery turtle
#

ECAM is better yeah

left orbit
#

looks like i can discover the base address for MMIO from the MCFG table

#

i need the segment and bus numbers for that..?

#

and then i can use that address to poke certain device/function's config space

fiery turtle
#

Yeah

left orbit
#

should i use MCFG to find the config space base address?

#

or can i find those using acpi?

fiery turtle
#

uacpi_table_find(MCFG)

left orbit
#

so MCFG is the way to go, got it

fiery turtle
#

Ye

left orbit
#

and now my PCI addresses should take the segment into consideration as well

fiery turtle
#

There's also a method in aml to get the base

#

You could use that

#

_CBA

left orbit
#

i feel like i can learn a lot by looking at the aml, what do you use to decompile it?

#

also where i can get a copy of qemu's DSDT? im assuming that's what i need

left orbit
#

ah, iasl

fiery turtle
#

You have to dump it yourself

left orbit
#

so boot linux and dump

#

alright

fiery turtle
#

Or write it to serial

left orbit
#

oh right, it just a table right?

#

do i just feed the raw bytes of the table to iasl?

#

well, save it to a file then pass it to iasl

fiery turtle
#

Yup

left orbit
#
czapek@raptor-wsl:~/source/zigux$ file dsdt.bin 
dsdt.bin: ACPI Machine Language file 'DSDT' BXPC     1 by BOCHS, revision 1, 8389 bytes, created by BXPC 1
czapek@raptor-wsl:~/source/zigux$ iasl dsdt.bin 

Intel ACPI Component Architecture
ASL+ Optimizing Compiler/Disassembler version 20230628
Copyright (c) 2000 - 2023 Intel Corporation

File appears to be binary: found 81 non-ASCII characters, disassembling
Table [DSDT] is too long for file - needs: 0x20C5, remaining in file: 0xF3
Binary file does not contain a valid standard ACPI table

Compilation successful. 0 Errors, 0 Warnings, 0 Remarks, 0 Optimizations```
#

hmmm

#

i am dumping sdt_hdr.length bytes starting at the header

fiery turtle
#

That should be correct

left orbit
#

libmagic says it's an AML file, so there's that

#
czapek@raptor-wsl:~/source/zigux$ file dsdt.bin 
dsdt.bin: ACPI Machine Language file 'DSDT' BXPC     1 by BOCHS, revision 1, 8389 bytes, created by BXPC 1```
fiery turtle
#

It doesn't do sanity checking of length

left orbit
#

well thats fair

fiery turtle
#

Can you show the dump code?

left orbit
#
const dsdt_table = findTable(uacpi.ACPI_DSDT_SIGNATURE);
if (dsdt_table != null) {
    logger.info("DSDT: {any}", .{std.fmt.fmtSliceHexUpper(dsdt_table.?.getData())});
}```
#
pub fn getData(self: *const @This()) []const u8 {
    const hdr: *uacpi.acpi_sdt_hdr = @ptrCast(self.uacpi_table.unnamed_0.hdr);
    const data: [*]const u8 = @ptrCast(hdr);
    return data[0..hdr.length];
}```
#

sorry for zig lol hope it's not too much of a trouble

fiery turtle
#

How do you get the pointer to it from uACPI?

left orbit
#
var table: ?*uacpi.uacpi_table = null;
uacpi.uacpi_table_find_by_signature(signature, &table)```
#

and then i pass that table pointer around wrapped in a struct

#

it works for MADT

fiery turtle
#

Yeah but what is GetData

fiery turtle
#

Oh thats wrong

left orbit
#

it just constructs a byte slice starting at the sdt header spanning hdr.length bytes

fiery turtle
#

hdr is the header

left orbit
#

oh?

fiery turtle
#

U need virt_addr

left orbit
#

it's a union though

#

should be the same, no?

fiery turtle
#

Hmm yeah I guess, maybe its some zig meme

left orbit
#

i cast it to a u8* later

fiery turtle
#

Strange

left orbit
#

i think that getData works for the MADT

#

but i have no way of knowing for sure

fiery turtle
#

Do you have the test runner handy?

left orbit
#

the uacpi one?

fiery turtle
#

From uACPI

#

Yeah

left orbit
#

i can clone and build it

fiery turtle
#

I wonder what it would say about the blob

#

Can you try real quick

#

Should be easy

left orbit
#
czapek@raptor-wsl:~/source/uACPI/tests/runner$ ./build/test-runner ../../../zigux/dsdt.bin
unexpected error: DSDT declares that it's bigger than ../../../zigux/dsdt.bin```
#

i guess im not dumping enough bytes?

fiery turtle
#

Yea

#

For some reason

left orbit
#

what does the length in the sdt header mean?

#

is it how big the table + header is?

fiery turtle
#

The length of the entire thing in bytes

#

Including the header

left orbit
#

so that should be fine

fiery turtle
#

Yeah

fiery turtle
left orbit
#

let me log what im getting

fiery turtle
#

Maybe log the number

#

Yeah

left orbit
#

idk if that is gonna help lol

#

one sec

#

oh wait

#

☠️

#

oh nvm

fiery turtle
#

What?

left orbit
#

i got confused in my code a little bit

#

nothing, my bad

#

ill log it now

fiery turtle
#

Lol

left orbit
#

8389 bytes

#

OH

#

i am dumb, let me just log to e9 instead

#

my print has a length limit...

fiery turtle
#

Lol

left orbit
#

that was very dumb lmao

fiery turtle
#

Why do u even have a limit lmao

left orbit
#

im using zig's fmt library which needs a buffer to format stuff into

#

and instead of having a global buffer that's big + a lock around it i just have a buffer on stack

#

and it cant be too big for obvious reasons

fiery turtle
#

I see

left orbit
#

ill see if i can somehow use zig's fmt with some writer thing that will let me avoid buffering

fiery turtle
#

Cant u just byte bang to e9

left orbit
#

the dsdt? i am doing that right now

fiery turtle
#

Oh ok

#

I meant bypassing the printf

left orbit
#
Disassembly completed
ASL Output:    dsdt.dsl - 88563 bytes```
#

wooo

#

time to figure out how the pci host bridges are defined in there

#

ohh the bridge's _HID is PNP0A08 but the _CID is PNP0A03, i see

#

there doesn't seem to be a _CBA anywhere unfortunately

left orbit
#

yep

#

though with smm=off

#

shouldnt matter though right?

fiery turtle
#

Interesting, someone did mention it existed on qemy

#

Maybe yours is old or they were wrong

#

Anyway its not mandatory and mcfg is used as fallback

left orbit
#

i am on 8.2.3

fiery turtle
#

9 is the current release

left orbit
#

ill try compiling from source

#

and dumping the dsdt there

fiery turtle
#

Yeah give that a try

#

do β€”target-list=x86_64-softmmu

#

Or you will be compiling that shit for an hour

left orbit
#

yeah i was gonna do just x86_64, but qemu takes like a minute for me anyway

#

or maybe thats with the target list

#

i cant remember

fiery turtle
#

For all 9k files?

left orbit
#

yeah

fiery turtle
#

Are you on a NASA server

left orbit
#

lmao

#

13700k

#

but its a bit slow because of wsl

fiery turtle
#

Lol

left orbit
#

already at 3k

fiery turtle
#

Qemu compiles on windows as well

#

Its a bit of a hassle but ut works

left orbit
#

i should have done --target-list

#

but its not too bad

fiery turtle
#

Target list is only 2k files

left orbit
#

i am building master so i hope thats recent enough

#

well then that'd be done in 20 seconds

#

anyway im at 7.5k right now

fiery turtle
#

Lol

#

Maybe make an m68k port since u compiled it anyway

left orbit
#

ok its done now, lets see

#

i could try looking into that but i dont think its a well supported zig target lol

#

aarch64 is bad enough

fiery turtle
#

Lol

#

Yeah

left orbit
#

hmm for some reason the build got stuck at 9401/9437

fiery turtle
#

I bet its not

#

lto is enabled by default

#

It takes a while

left orbit
#

i just ctrl+c and rane make again

#

it linked

#

fun

fiery turtle
#

Nah it was fine

left orbit
#

got dsdt, lets see

#

nothing

#

rip

fiery turtle
#

Bruh

#

You sure there's an mcfg?

left orbit
#
czapek@raptor-wsl:~/source/zigux$ diff dsdt.bin dsdt-9.bin
czapek@raptor-wsl:~/source/zigux$ diff dsdt.dsl dsdt-9.dsl
8c8
<  * Disassembly of dsdt.bin
---
>  * Disassembly of dsdt-9.bin
left orbit
fiery turtle
#

Do that

#

An opportunity for you to make a patch halfmemeright

left orbit
#

yeah there is an MCFG table

fiery turtle
#

Damn

left orbit
#

sooo lack of _CBA is fine then?

fiery turtle
#

Its not mandatory yeah

left orbit
#

alright

fiery turtle
#

Mcfg is the fallback

left orbit
#

a patch to qemu?

fiery turtle
#

It should be 3 lines of code in qemu

fiery turtle
#

aml_append(aml_name(_CBA, aml_integer(...)))

left orbit
#

it's just an integer?

#

fair enough

fiery turtle
#

Ye

left orbit
#

should it be available on i440fx?

fiery turtle
#

There isnt a method call operator

#

So its automatically invoked

#

So method or named object is same thing

fiery turtle
#

Old chipset is pci only

left orbit
#

lol it doesnt work

#

i think im regarded or smth

#
if (mcfg_valid) {
    printf("adding _CBA %zx\n", mcfg.base);
    aml_append(dev, aml_name_decl("_CBA", aml_int(mcfg.base)));
}```
#

the printf gets printed but the name doesn't appear in the decompiled aml

#

nvm im blind

#

Name (_CBA, 0xB0000000) // _CBA: Configuration Base Address

#

seems to have worked?

fiery turtle
#

Yup

#

Good job

left orbit
#

time to become a qemu contributor

fiery turtle
#

Do it

#

Unironically good patch

left orbit
#

hmm there is already a method called acpi_dsdt_add_gpex which adds a pci bus device to the aml, and that adds does add a _CBA thing

fiery turtle
#

Huh

#

Dont tell me is tied to smm lmao

#

Gpe is definitely tied to smm

left orbit
#

it's only called for loongarch

fiery turtle
#

Oh ok

#

You're good then

left orbit
#

i did try without smm and there wasn't a _CBA anyway

fiery turtle
#

Yeah ok

left orbit
#

nvm the acpi_dsdt_add_gpex is called from multiple places, including i386 from a file called acpi-microvm.c

#

also from whatever the hell hw/pci-host is

#

ah that's where the method is defined lmao nvm

fiery turtle
#

microvm is amazon firecracker

fiery turtle
left orbit
#

good question! thanks qemu

fiery turtle
#

Lol

left orbit
#

i think its because it checks if its q35 or i440fx?

fiery turtle
#

Dont u specify q35

left orbit
#

yeah i do

fiery turtle
#

Huh

left orbit
#

but q35 builds its own dsdt

fiery turtle
#

Strange

left orbit
#

doesnt seem to use the same functions everything else does

#

definitely weird

fiery turtle
#

Maybe its a bug

#

Or a regression

left orbit
#

honestly i'm going to leave that for someone who actually knows what they are doing, especially since it looks like i need to send a patch to a mailing list (!!!) and i've never done that before lol

fiery turtle
#

Its pretty trivial tbh

#

But yeah whatever

left orbit
#

yeah it is trivial, but like you said maybe it's a bug or a regression and in that case the patch is pretty useless

fiery turtle
#

I guess

left orbit
#
#define ACPI_MADT_POLARITY_MASK 0b11
#define ACPI_MADT_POLARITY_CONFORMING 0b00
#define ACPI_MADT_POLARITY_ACTIVE_HIGH 0b01
#define ACPI_MADT_POLARITY_ACTIVE_LOW 0b11```

how does that work? why are both mask and active_low 0b11?
#

spec says

Polarity of the APIC I/O input signals:
00 Conforms to the specifications of the bus (for example,
EISA is active-low for level-triggered interrupts).
01 Active high
10 Reserved
11 Active low

fiery turtle
#

its not some other value lol

left orbit
#

ahhh

#

oh that makes sense, my bad

fiery turtle
#

value & MASK == ACITIVE_LOW etc

fiery turtle
#

The only "feature" uacpi is currently missing is basically thread safety

#

and its so fkn boring

#

but i guess i have to bite the bullet and just do it

#

namespace & table should be easy to protect with just a mutex

#

interpreter is more complicated

#

particularly the only edge cases where something does a CopyObject

#

Which either needs an RCU-like object replacement thing or some other bs

fiery turtle
#

@hollow elm btw I finally cleaned up & merged While timeouts

#

any fuzzer timeout is now considered a bug

fiery turtle
#

also since the test runner with --enumerate-namespace now runs _PRS and _CRS we might uncover new conversion bugs with fuzzer especially against real hw blobs

#

if fuzzer generates bogus resource lengths or offsets

#

i do have validation there but i doubt its perfect

#

i was too lazy to write out a dumper for each resource, but at least it prints out the length

#

wtf is this

dusky glade
#

does pnp mean plug n play

#

why is it called that lmao

tired crater
#

Because you plug it in and play

dusky glade
#

real

fiery turtle
vast kestrel
#

In general the idea is that you just plug the hardware and the os can automatically detect it

#

At least afaik

#

Like pcie is plug and play since you as the user don't need to configure anything be it in the hardware or the software

#

unlike legacy hardware which is just assumed to exist or you need to properly configure the ids/addresses for devices

fiery turtle
#

soo im working on mutexes and im a bit unsure

#
this_id = uacpi_kernel_get_thread_id();
if (mutex->owner == this_id) {
    mutex->depth++;
    return UACPI_TRUE;
}
#

since mutexes are recursive i have to do this

#

but owner is 0 by default

#

and technically thread_id of 0 is also valid

#

so there must be some sentinel value that corresponds to no owner

#

i could just say that 0 is that value, or maybe make it customizable by the client

#

or maybe thats bad api in general

#

like i have no idea

rustic compass
#

why do you give a mutex a owner?

fiery turtle
#

ok ACPICA just does this #define ACPI_MUTEX_NOT_ACQUIRED ((ACPI_THREAD_ID) -1)

#

i think ill just do this as well but make it customizable as well

fiery turtle
loud ice
#

read: this is definitely broken

fiery turtle
#

what algorithms

loud ice
#

as in

#

this is wrong

jaunty fox
#

well, if the mutex is currently held by yourself, then it ought not to be pulled out from under you

fiery turtle
#

yeah i dont understand

#

looks correct to me

#

other than missing relaxed atomic load

#

if owner is larger than the word size it might potentially be write in progress

#

but other than that i think its ok

#

its always one of two values: sentiel no owner placeholder, a valid thread id

#

well also depth overflow, i should check for that

rain nimbus
#

I mean it's not very atomic that's for sure...

fiery turtle
#

does that matter if owner is less than or equal to word size

#

but the proper way is to define atomic helpers sad

#

does msvc even have them

#

InterlockedOrNoFence

#

lmao

rain nimbus
#

About that xD

#

Their interlocked stuff can be odd

fiery turtle
#

its only used for userspace tests so i dont care to be honest

#

but odd how?

#

ACPICA:

/* Support for multiple acquires by the owning thread */

if (ObjDesc->Mutex.ThreadId == ThreadId)
{
    /*
     * The mutex is already owned by this thread, just increment the
     * acquisition depth
     */
    ObjDesc->Mutex.AcquisitionDepth++;
    return_ACPI_STATUS (AE_OK);
}
#

0 fucks given

#

overflow, atomicity

#

tbh if your thread_id is larger than word size just take the L

fiery turtle
#

nvm

rain nimbus
fiery turtle
#

welll who cares its just a name\

rain nimbus
#

True, just an odd choice imo

#

Doesn't make a difference in regard to usage

jaunty fox
rain nimbus
fiery turtle
#

bruh

rain nimbus
#

except for with msvc I suppose

jaunty fox
#

i don't know of any kernel where there isn't at least part of the thread structure that's always resident and i can't immediately think of any where the thread structure is relocated, so the pointer to it is a reasonable thread id

rain nimbus
#

I don't think anyone has thread_id's larger than 32 bits...

#

Tbf even 16 bits is enough

#

until you're like windows and spawn a separate thread for every window regardless and you spawn like 100k windows...

fiery turtle
#

yeah i think a pointer or a 32-bit value is reasonable

jaunty fox
#

i will say i was actually a bit surprised

#

"atomic read" does return significantly more results than does "interlocked read" searching published articles indexed on google scholar prior to 1986

fiery turtle
#

interlocked is more of a legacy term I guess

rain nimbus
#

Possibly

#

But I've only seen it in regards with microsoft stuff so...

jaunty fox
#

enjoy this use of it by the people who invented Mach then

rain nimbus
#

amd doesn't use the term in their amd64 docs

jaunty fox
#

NT does have spiritual lineage to Mach so it's not overly surprising

vast kestrel
#

Also because of single copy atomicity on any sane architecture it's actually completely fine (obviously as long as the size and alignment allow for it )

#

It will never have a case where you see your own thread id when the lock is taken by someone else because you had to reset it yourself and a thread is in sync with itself (alpha doesn't exist and can't hurt me)

#

Obviously assuming that the compiler will do it nicely is not the correct thing to do so using a relaxed atomic is the correct thing to do

#

But Microsoft be Microsoft, and Microsoft loves doing this kind of shit all over

kindred beacon
#

yeah offloading to the OSΒ seems like a good choice

fiery turtle
#

Not to mention there's e.g. a global lock that has special acquire semantics

#

But offloading would work with a few extra helpers on top I guess

vast kestrel
#

I still think the recursive part should be handled by the kernel, it makes sure that if anything strange needs to happen it does

#

And the global lock works very different to an os lock

#

Your wakeup is using an interrupt

#

And tbh that requires very specific semantics from the OS

fiery turtle
#

That uses a combination of events and mutexes

vast kestrel
#

Your primitives should be cond var + mutex

fiery turtle
#

Yeah thats basically what it is

#

I could even force the os to implement RCU

#

I just think less is better

vast kestrel
#

Nah that's not good

#

Especially if you have a microkernel running it in user space

loud ice
vast kestrel
#

Where rcu doesn't make much sense

loud ice
#

so

vast kestrel
#

I mean, it's much more expensive in user space than in kernel

#

Or idk if much

vast kestrel
fiery turtle
#

Yup

#

If I do a relaxed load I need to force the os to use a specific type for thread id

#

Of force it to specify an atomic helper to use to load it

loud ice
#

you could just

fiery turtle
#

Its just all super annoying

loud ice
#

if (mutex not in stack)

#

acquire()

fiery turtle
#

Which stack?

loud ice
#

the stack of mutexes you have acquired

fiery turtle
#

That works well for managed mutexes in aml

loud ice
#

the one you maintain already

fiery turtle
#

But not the mutexes that could be taken by me or the os

loud ice
#

you could just ban those uses from being recursive?

fiery turtle
#

Technically there's still one mutex that is shared by aml and user

#

So it must be recursive

#

Or maybe it could be only recursive in AML side idk

fiery turtle
fiery turtle
#

_GL

loud ice
#

oh global lock?

fiery turtle
#

Yeah

loud ice
#

yeah just make it exclusive on the kernel side only

fiery turtle
#

Good idea

#

Ill see how that works out

fiery turtle
#

i dont even need an owner pointer in this case

#

and a thread id helper

#

the only problem is i have to iterate the entire array so it could be more expensive

#

but aml usually just acquires one mutex

#

if any at all

loud ice
#

so yeah

#

its not that bad

#

you can do another thing tho

#

instead of a thread id

#

you can use the stack pointer at interpreter entry

#

as a "thread id"

fiery turtle
#

i currently do this

#

but i use execution context pointer as owner

loud ice
#

ah yes

#

cursed but works probably

fiery turtle
#

why is it cursed

#

its a heap allocated address so

#

it must be unique

loud ice
#

true

fiery turtle
#

but yeah i think this should be fine

#

and i can use an atomic load helper for it

#

since its a pointer

rustic compass
#

can i run uapci in userspace?

fiery turtle
#

i do it all the time

#

i have a pretty advanced test runner at this point

fiery turtle
rustic compass
#

so i could run uacpi as a userspace driver in my microkernel?

fiery turtle
#

absolutely

#

your kernel must provide capabilities to map memory or io ports if you're a microkernel anyway

left orbit
#

is the irq passed to uacpi_kernel_install_interrupt_handler an ISA irq? or is it just a vector that uacpi wants it to be registered at?

fiery turtle
#

isa

#

its a field from fadt called sci_int

#

almost always its set to 9

left orbit
#

so i would route it through ioapic, right?

#

taking ISOs into account and all that

#

if there happens to be one for that irq of course

fiery turtle
#

yeah

left orbit
#

thanks!

fiery turtle
#

np!

left orbit
#

also one more question, what is the return value of the interrupt handler meant to be?

#

oh, whether it was handled or not

#

i guess i can just ignore it if i dont plan on sharing that vector then

fiery turtle
#

yeah its just handled/unhandled

left orbit
#

sorry for stupid questions but what is this sci interrupt used for?

#

is it just a way for firmware/acpi to callback into the operating system?

#

when like the power button is pressed or whatever

fiery turtle
#

its called the system control interrupt

#

and its a replacement of the SMM interrupt

#

its used by the firmware to make the acpi subsystem do something

left orbit
#

ah interesting

fiery turtle
#

sometimes its just something simple like power button press

#

sometimes more involved like a general purpose event to execute arbitrary AML

left orbit
#

qemu doesnt generate an sci interrupt for me when i press "power off" in the menu

#

unfortunate

fiery turtle
#

it does!

left orbit
#

then i guess i broke something :p

fiery turtle
#

did u look at this?

left orbit
#

i call these functions in this order:
uacpi_initialize
uacpi_install_notify_handler
uacpi_namespace_load
uacpi_namespace_initialize
uacpi_set_interrupt_model

#

i will, one sec

#

ah i need a fixed event handler

#

i was expecting an sci at the very least though

fiery turtle
#

yeah, the status bit for the power button must be set

#

otherwise a SCI is not generated

#

its a mask register

left orbit
#

ahhh that makes sense

#

let me do that real quick!

#

thanks :^)

#

hmm, repeat power button presses are not generating sci interrupts though

#

is this some flag i have to clear?

#

oh wait my kernel seems to have hung

fiery turtle
left orbit
#

yeah then i think something went horribly wrong because all of a sudden everything died lol

fiery turtle
#

qemu might spam it forever, but note that real hardware generally doesnt

#

there's a timeout before it sends the event again

#

it waits for the os to enter some sleep state for a bit

left orbit
#

wait, does uacpi_enter_sleep_state(UACPI_SLEEP_STATE_S5); perform the actual shutdown?

#

lol cool

#

so simple

fiery turtle
#

yeah there's two calls you must make

#

prepare & enter

left orbit
#

yep i am looking at the wiki right now

#

didnt know it would be so simple

fiery turtle
#

lol

#

thats the entire point

left orbit
#

fair

fiery turtle
#

did you figure out why it hangs? caret

left orbit
#

nope, but i dont really care since i'm not gonna be scheduling after that anymore tf

fiery turtle
#

lol

left orbit
#

shutting down works perfectly fine

#

i dont think it schedules anymore

fiery turtle
#

yeah but like it says there calling these from an interrupt context is really fragile

#

especially for real hw

#

it might call like Sleep() or try to grab a mutex

torpid ferry
#

MS even has annotations to prevent you from calling stuff at the wrong irql

fiery turtle
#

linux also with __might_sleep or whatever

torpid ferry
#

ms sal is really cool

left orbit
#

yeah yeah my stuff is shit though

torpid ferry
#

also has in/out params and length

fiery turtle
#

yeah

left orbit
#

i love the annotations on windows apis

#

but when i accidentally go to definition of some function

#

i tend to reconsider my life choices

#

i wonder who at microsoft willingly decided to sit down and annotate all the parameters

hollow elm
#

there's probably a policy that you have to annotate them from the start nowadays

jaunty fox
left orbit
#

yeah, qookie and nooby helped me out a lot :^)

jaunty fox
#

libclang

fiery turtle
#

Okay I think i implemented global lock stuff, now i just need to hook it up to the interpreter and that's it

#

that will mark the end of missing ACPI-specific features

#

everything else is done

jaunty fox
#

what will you work on next? ultraOS?

fiery turtle
fiery turtle
fiery turtle
fiery turtle
jaunty fox
fiery turtle
#

Lil is focused on modesetting but yeah

jaunty fox
tired crater
kindred beacon
#

right now, however, yeah

#

modesetting comes first meme

sterile egret
#

seems like the kind of thing where collaboration would be the best way forward

#

Mostly I want to encourage this so that there's a good option for hobby os 3d accel, because I sure as hell can't write a modern GPU driver meme

fiery turtle
#

yeah I can definitely see value in that, but lil is C++ and just sort of different from how I would approach this

#

will see if i even get anywhere anyway

#

i might make a library similar to uacpi or i might make it coupled to my kernel

fiery turtle
#

@mortal yoke btw if u still work on your acpi interpreter, i now have --large for tests, which runs 354 real hardware blobs against the interpreter

mortal yoke
#

nice, maybe I should try running those

fiery turtle
#

yeah definitely

#

some of them will run forever for you unless you have while timeouts implemented

mortal yoke
#

do they use loadtable tho? because I still don't have that

fiery turtle
#

nah

mortal yoke
#

speaking of which I also lack ToString lol

fiery turtle
#

LoadTable is only used if you're _OSC'ing advanced capabilities

fiery turtle
mortal yoke
#

yeah I haven't seen it being used in any of the real hw/virtual machines I have tried it on

fiery turtle
#
❯ grep -rn 'ToString' ./ --exclude \*.bin | wc -l
1169
#

well

#

looks like its somewhat common

#

but probably not during init

fiery turtle
#

okay looks like global lock stuff passes the tests

#

im not yet 100% confident about this pr and interface, but will see

#

ill definitely test this in managarm before merging

left orbit
#

uacpi works on my old ass dell optiplex together with the power button, very nice :^)

fiery turtle
#

Pog

hollow crescent
#

@fiery turtle does the U in uACPI stand for micro or Ultra?

fiery turtle
#

used to be the former, but I dont know anymore

#

i like to think its both

fiery turtle
#

as well as bitfields in the public API

#

since obviously it makes interop kind of annoying

left orbit
#

based

mortal yoke
fiery turtle
#

lol

mortal yoke
#

now I just need to go through the test outputs and look what exactly they are all about

fiery turtle
#

hey you got two of them passing LULW

mortal yoke
#

actually I realized that I didn't update the test runner's function that gets object type enum from an object variant, that seems to be why a lot of them failed

#

so Ill run it again and see what the actual number of failures is

fiery turtle
#

try it

mortal yoke
fiery turtle
#

not bad

mortal yoke
#

looks like 60 of them are either timeouts, bufferacc being unsupported or using connectfield which I apparently implemented wrong (and idk how should I actually implement it in a good way because the data is stuff that would need to be parsed using the main interpreter so I couldn't just parse the fields in a loop like I do now) and the other 2 were a mistake in the amount of args/locals as I had the counts the wrong way around

#

well I guess I could like have a new frame type for the field list and then have a separate opcode block table + handlers for that or smth, anyway I probably shouldn't be posting about this in here as this is for uACPI KEKW

fiery turtle
#

Lol

left orbit
#

oh man sadmeme

dusky glade
#

sad

#

can we make the u in uacpi stand for ultracool

#

ultracoolacpi

#

😎

left orbit
#

i wonder what the heck is my firmware doing that it wants events for

mortal yoke
#

@fiery turtle btw there are a few usages of PRIu64 in source/utilities.c that should probably be UACPI_PRIu64

fiery turtle
#

just make create return something like 0x1

#

and then panic if its used

dusky glade
#

lol

fiery turtle
#

i fixed that and nyaux warning in the PR

#

im not merging that today but anyway

left orbit
fiery turtle
#

lol

left orbit
#

i wonder whats so special about this dsdt that makes uacpi fail

#

it doesnt seem to be on an error path though, maybe its just some zig stupidity

fiery turtle
#

i think its making your allocator fail

left orbit
#

do you know of any tool for windows that can dump the dsdt?

fiery turtle
#

acpidump -b

left orbit
#

on windows?

fiery turtle
#

yes

fiery turtle
#

yup

left orbit
#

thanks

dusky glade
left orbit
#

it is my allocator tho

fiery turtle
#

lol because its almost always the case

dusky glade
#

not mine

#

😀

fiery turtle
#

but ofc lets see what the test runner has to say

left orbit
#

so obivously something is wrong

fiery turtle
#

how is it allocating an event in free() code lmao

left orbit
#
[uACPI][INFO] namespace initialization done: 295 devices, 0 thermal zones, 0 processors
[uACPI][TRACE] _STA calls: 105 (1 errors), _INI calls: 30 (0 errors)```
fiery turtle
#

yeah looks like it works

left orbit
fiery turtle
#

the error is probably related to an undefined reference (because u didnt load SSDTs obviously)

#

but other than that looks like it works

left orbit
#

how to load ssdts?

#

in the test runner

fiery turtle
#

u cant, it only accepts one blob at a time

left orbit
#

ah i thought i did something wrong

#

all good then

fiery turtle
#

nah

left orbit
#

time to look into the god damned allocator

fiery turtle
#

what was the _STA related error?

left orbit
#
[uACPI][ERROR] unable to lookup named object '\_SB_.PC00.LPCB.H_EC._STA.^^^GFX0.CLID': not found
[uACPI][ERROR] aborting method invocation due to previous error: AML referenced an undefined object
[uACPI][ERROR]     #0 in \_SB_.PC00.LPCB.H_EC._STA()
[uACPI][WARN] aborted execution of '\_SB_.PC00.LPCB.H_EC._STA' due to an error: AML referenced an undefined object```
fiery turtle
#

oh yeah GFX0 is loaded by SST2 or 3

#

so thats fine

fiery turtle
left orbit
#

assert(old_mem.len != 0);

#

thats the assert it fails on

#

apparently uacpi passes in a zero size

#

i guess ill just @min(size, 8) on both alloc and free

fiery turtle
#

hmm i dont think thats a code path that exists

#

maybe assert that size != 0 during allocation

#
// 2. Release the object array
uacpi_free(pkg->objects, sizeof(*pkg->objects) * pkg->count);
#

technically it could that the package is empty ofc

left orbit
#

how unlikely is that?

fiery turtle
#

never seen one

#

but you could disassemble your dsdt and see if thats a thing

left orbit
#

okay so the @max(...) is already done by the allocator

#

const new_aligned_size = @max(len, @as(usize, 1) << @as(Allocator.Log2Align, @intCast(log2_ptr_align)));

fiery turtle
#
uacpi_bool uacpi_package_fill(uacpi_package *pkg, uacpi_size num_elements)
{
    uacpi_size i;

    pkg->objects = uacpi_kernel_calloc(num_elements, sizeof(uacpi_handle));
#

if its indeed an empty package you will see this

left orbit
#

the disassembler dsdt is 4.5MB

#

i aint looking through all of that

fiery turtle
#

send

left orbit
#

can i just send it here?

fiery turtle
#

yea

left orbit
#

dsdt

fiery turtle
#

yeah

left orbit
#

is that a package of size 0?

fiery turtle
#

yup

left orbit
#

oh i didnt know the size was right there lmao

#

i was looking for one with empty {}

#

sooooo my aml is kinda weird

#

but thats okay

#

im just going to align size up to 8 :)

fiery turtle
#

yeah i mean, alloc(0), free(0), should work i think?

left orbit
#

well not in zig, here we usually dont allocate 0 bytes for anything lol

fiery turtle
#

usually 0 is treated as 1 basically

#

so its just rounded up

fiery turtle
left orbit
#

yea true, i just never hit that so i didnt think of it

#

now with that accounted for its time for another bare metal run

fiery turtle
#

thats absolutely giant dsdt tho

left orbit
#

this time i enabled memory space access and bus mastering in my xhci driver

fiery turtle
#

its 120k lines of asl

left orbit
#

so hopefully? it gives some sign of life

left orbit
fiery turtle
#

how was it not crashing before?

#

before reaching your xhci

left orbit
#

it was, but i tested on another machine as well

#

uacpi works there

#

but xhci nope

fiery turtle
#

ohh i see

left orbit
#

this machine i had some issues with because it has too much memory meme

fiery turtle
#

how modern is this hw?

left orbit
#

i was getting a page fault inside a page fault and ended up smashing the stack

#

z790 board

#

last intel gen

fiery turtle
#

makes sense

#

probably has tons of SSDTs as well

left orbit
#

there's 10

#

is that a lot?

fiery turtle
#

thats moderately a lot

#

some laptops go into 20s

left orbit
fiery turtle
#

thanks

left orbit
#

idk what they contain

#

so have fun :^)

fiery turtle
#

i could add it to the large tests that uacpi runs

left orbit
#

as long as that's legal, sure

#

i mean anyone can dump them i guess

#

but since they are binaries idk what rules apply to redistributing them

fiery turtle
left orbit
#

right, fair enough

fiery turtle
#

I have a fork of this with some fixes

left orbit
#

im glad i can contribute at least in that way

fiery turtle
#

can u do acpidump > res.txt and send that so its more of a standard format

fiery turtle
#

that dump lacks latest hardware

#

i mean the repo

left orbit
#

lol my free "fix" broke other frees

#

i should have tested in qemu first

fiery turtle
#

lol

left orbit
#

oh right i forgot, the allocator interface accepts "log 2 of align" and i was passing the align itself, i fixed that for alloc but forgot to update for free

#

so instead of 8 i should be passing 3 (1 << 3 == 8)

#

ofc the god damn scheduler dies, ill tackle that another time, im glad i got uacpi to work

fiery turtle
#

nice

#

does it boot now?

left orbit
#

yep, just dies when doing some xhci stuff, presumably because of the scheduler or whatever else

fiery turtle
#

did u try the power button too?

#

or is it too dead to test

left orbit
#

that didnt work but im not sure if it wasnt working or because it was dead

#

i can try without spawning any thread to rule that out

fiery turtle
#

or u can look at fadt

#

see if that declared fixed power button

fiery turtle
#

all other dumps in that repo are that format so

left orbit
fiery turtle
#

Control Method Sleep Button (V1) : 1

#

Control Method Power Button (V1) : 0

#

yeah should be working as a fixed event

left orbit
#

yup works!

fiery turtle
#

Nice!

hollow elm
#

people would complain about heap corruption or whatever

#

but in the end it was their allocator shitting itself

fiery turtle
#

always blame the tools caret

#

if anyone else wants to volunteer to be a part of uACPI test suite, im open to acpidump > res.txt submissions caret

#

currently have 355 blobs

north holly
#

take it

#

I guess

fiery turtle
#

Thanks

north holly
#

wait

#

it has some MSDM

#

table

#

which apparently contains some windows licensing info

fiery turtle
#

I doubt that matters but u can remove it if u want

fiery turtle
#

I would hope

left orbit
#

got your key

#

:^)

fiery turtle
#

Yeah not that simple lmao

left orbit
#

i mean it seems to be there in plain text

#

i would hope its not that simple

fiery turtle
#

Yeah doubt

mortal yoke
#

at least you can usually transfer retail windows licenses between pc's (at least when you have signed in with an ms acc)

hollow elm
#

it's an oem key so it's probably not usable outside the acpi table?

north holly
#

about that

#

IT IS THAT SIMPLE

left orbit
#

i was just kidding anyway, but people do make it seem that easy

fiery turtle
#

Huh

left orbit
#

people say this is enough to get the key: strings /sys/firmware/acpi/tables/MSDM

#

fun

north holly
#

As long as I use a windows installation

#

you can steal my windows

left orbit
#

no idea, should i try? tf

dusky glade
#

🐈

mortal yoke
fiery turtle
#

Anyway oberrow delete it I guess and reupload without that table

north holly
#

Don't forget to send us the output

mortal yoke
north holly
#

for educational purposes

mortal yoke
#

or at least what I consider legal enough

left orbit
#

LMAO

#

whoops

north holly
#

.

dusky glade
#

our windows license

north holly
#

We should've known better

#

So can I have my windows back

left orbit
#

Yep u can have it

north holly
#

Wait

#

with this knowledge

zenith crescent
#

just realised this has the MSDM table

north holly
#

we have the windows installation keys for a couple hundred computers

left orbit
#

another key for me

#

thanks!

fiery turtle
#

Probably all 500 public dumps have it

zenith crescent
#

how do I remove that table

#

just edit the file?

left orbit
#

you use a text editor

#

yes

fiery turtle
#

Its ascii

north holly
#

now without the MSDM

zenith crescent
fiery turtle
#

Thanks! Were now at 356

dusky glade
#

wtf

#

😭

fiery turtle
#

What

dusky glade
#

what are we doing here exactly

fiery turtle
#

Im expanding the test suite

north holly
#

now how do we tell ms to get their shit together and stop putting activation keys as plain text in acpi tables

dusky glade
#

activation keys in plain text

#

in acpi tables

#

πŸ’€

north holly
#

yeah

#

windows activation keys