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

1 messages · Page 44 of 1

calm latch
#

My kernel is having a giant skill issue returning an integer

kind mantle
#

real->long mode any% speedrun

calm latch
#

I'm dumb

#

I was returning u16

#

And 1MB is 20 bits

north holly
#

lol

fiery turtle
#

Return a u20

kind mantle
#

Yes let's return not only an integer type that doesn't exist but also one that doesn't align to bytes KEKW

fiery turtle
#

Zig moment

calm latch
#

DSP moment

gentle peak
#

u145

north holly
#

u6

kind mantle
#

PipelineC moment

calm latch
#

This is promising

north holly
#

uACPI

fiery turtle
frank canopy
# fiery turtle Zig moment

if its not in a packed struct then zig uses the next representable size and adds the branching etc to implement the right semantics for the specified size so its fine

calm latch
#

I know

kind mantle
kindred beacon
#

next do S0ix states troll

fiery turtle
#

I'll let oberrow figure it out trl

north holly
#

yeah he can have fun

#

idk how he managed to do that

frank canopy
#

also good news i updated to uacpi 2.0 on imaginarium and it still compiles

fiery turtle
#

That s cool

calm latch
kind mantle
#

also good news I updated to uacpi 2.0 on BadgerOS like a month ago and BadgerOS is still useless KEKW

north holly
#

what

calm latch
#

So I will be first coolmeme

north holly
#

uacpi 2.0 didn't exist a month ago

gentle peak
#

uacpi 2.0 was released like a few days ago

fiery turtle
#

Back to the future

kind mantle
#

is funni joke

frank canopy
#

2 days ago yeah

fiery turtle
#

I'm currently running uacpi 467.0

north holly
kind mantle
#

wait 2.0

north holly
north holly
kind mantle
#

man I really should stop doing stuf at 1am

#

because my brain melts

#

anyway sure I'll update to that soon™️

calm latch
#

This is what I wanted

fiery turtle
#

When more badgeros work

calm latch
#

It's %cs:1

kind mantle
calm latch
fiery turtle
#

Nice

kind mantle
#

Still staring at AHCI.

north holly
#

try that instead of disas

fiery turtle
frank canopy
#

also happy to report that i can fully delete my uacpi_libc.h now that 2.0 is out whee

fiery turtle
#

Bochs debugger is much nicer for this

calm latch
#

But I need to fix PCI for uACPI init nooo

#

And I can't be bothered

#

Since ... I would need to implement a bunch of stuff because I don't have a shared mutex

fiery turtle
#

F

north holly
#

F

fiery turtle
#

Oberrow should at least send u patched seabios

north holly
#

take it

#

-bios bios.bin

#

to qemu

frank canopy
#

what specifically is patched with this?

north holly
frank canopy
#

out of curiosity

#

ah ok cool

fiery turtle
frank canopy
#

mhm

fiery turtle
#

Since it tries to re enable it via ecam KEKW

frank canopy
#

lmao

calm latch
#

Through this I can see that I have a skill issue with gdt trl

fiery turtle
#

Debugging by instruction counting chad

#

Also obligatory GDT INIT.... FAIL

calm latch
#

is there no way to see gdtr contents in gdb?

north holly
#

just do monitor info registers

calm latch
#

Ok I'm dumb

#

forgor to shift ecx by 4

calm latch
left orbit
#
uacpi_status uacpi_set_waking_vector(
    uacpi_phys_addr addr32, uacpi_phys_addr addr64
)
{
    struct acpi_facs *facs = g_uacpi_rt_ctx.facs;

    if (facs == UACPI_NULL)
        return UACPI_STATUS_OK;

    // ...
}
#

why does it return OK if there is no facs?

calm latch
left orbit
#

shouldn't it be like unsupported or something?

frank canopy
#

idk if my wording is any good

#

the shims.zig file i exclude from the clause is the file of all my kernel-specific exports for the kernel api

calm latch
#

thonk I think I've reached protected mode?

#

(gdb is really confused)

#

(which is actually compat mode)

#

(why am I having so much skill issue with a simple asm trampoline?)

lofty dragon
frank canopy
#

nice

frank canopy
#

tbh i was originally planning to make my uacpi zig bindings a separate repo or at least separate folder outside my kernel repo but the callbacks/kernel api proved more annoying than i wanted to deal with to make feel right

#

i think ive got some ideas though for making it a bit cleaner

#

the simplest is to just say let the kernel do its own uacpi_kernel shims and only provide type and api bindings and not anything for making the shims prettier but idk

fiery turtle
fiery turtle
calm latch
#

Is there a way to discover legacy PCI io port with uacpi?

#

Like so I don't have to hardcode 0xCF8

fiery turtle
#

PCI._CRS

#

It will have decodable IO ports

fiery turtle
vast kestrel
#

Is there any spec for what crs to expect

fiery turtle
#

dont think so, but it's a range of busses covered by this bus, range of io and memory it's able to handle for BARs, and resources that can be used for talking to it

vast kestrel
#

It annoys me so much it's basically a guessing game with the crs

fiery turtle
#

yeah thats kinda annoying

calm latch
#

Btw

The address that a processor uses to access a device is not necessarily the same as the address stored
in the device’s BAR. The translation (_TRA, _TTP, and _TRS) information is not available to the
operating system until after the operating system brings up the ACPI interpreter. The operating
system must wait until after the ACPI interpreter is up to determine the address at the processor
side associated with the BAR registers configured by firmware

#

(for people who refuse to support ACPI)

#

What does this mean?

Before re-enabling a resource, the operating system must reprogram the BAR register using a value that falls within the range reported in the _CRS descriptor of the parent Host Bridge

#

(what if I implemented PCI hotplug in pmOS? trl)

#

I have several PCs with thunderbolt/USB 4...

calm latch
#

I think I'll redo my PCI enumeration memes...

fiery turtle
calm latch
#

Idk, all of it

fiery turtle
#

if u enable memory decoding on a pci device, its bar must be configured to a range from _CRS

calm latch
#

Hot-Plug Surprise Control
bruh

flat badge
fiery turtle
#

@gentle peak why did u do this btw?

#

also when proxima thread

gentle peak
#

don't remember

#

proxima thread idk

fiery turtle
#

damn

kind mantle
fiery turtle
#

Ikr

median crest
surreal current
kind mantle
surreal current
#

thats the normal constraint that causes someone to turn a blocking mutex into a spinlock so im just guessing why they did that

kind mantle
#

Because if e.g. a thread has the spinlock and is interrupted, that interrupt cannot then also take the spinlock.

surreal current
#

well

#

thats why you disable interrupts

#

when you hold spinlocks

#

its cooler to have everything possible be mutex guarded though and use worker threads if you need an interrupt to cause an access to something mutex-guarded

#

but for instance nonpaged pool in NT is guarded with a spinlock specifically so that interrupt handlers (DPCs technically but same thing for these purposes) can free blocks of memory

vale isle
#

i assume that's ziggy object notation

#

RON is the best for debug printing

calm latch
#

Like do I just assume it exists if there's no MCFG or _CBA?

left orbit
frank canopy
#

speaking of zon i may look into splitting my zig uacpi bindings out into their own repo either today or tomorrow

#

wonder if theres a way to turn a subdirectory into a repo in git without losing history

left orbit
#

probably not without altering it at the very least

frank canopy
#

i just want to keep the history of that directory

left orbit
#

unless u are very strict about not touching kernel and zuacpi in the same commit

frank canopy
#

i am not strict about that no lol

left orbit
#

yoooo

frank canopy
#

ive got filter-branch experience too lmao

#

albeit many years ago

vale isle
#

probably more of what you're looking for

frank canopy
#

they kinda split up filter-branch after the last time i used it

#

filter-repo is th other half of that split

#

oh wait no filter-repo isnt official

#

im stupid

#

its a third party addon command

#

i didnt realise it wasnt official because git officially recommends it lmao

vale isle
#

[Keep vs. remove] Instead of just providing a way for users to easily remove selected paths, also provide flags for users to only keep certain paths. Sure, users could workaround this by specifying to remove all paths other than the ones they want to keep, but the need to specify all paths that ever existed in any version of the repository could sometimes be quite painful. For filter-branch, using pipelines like git ls-files | grep -v ... | xargs -r git rm might be a reasonable workaround but can get unwieldy and isn't as straightforward for users; plus those commands are often operating-system specific (can you spot the GNUism in the snippet I provided?).

#

yes you want filter-repo

frank canopy
#

yeah filter-branch kinda sucks

#

filter-repo just didnt exist last time i used filter-branch

fiery turtle
#

We can put it under the uacpi org

#

If you wish that is

frank canopy
#

yeah im good for that

#

thinking MIT license for zuacpi, since thats the same as what uacpi proper does

fiery turtle
#

That would be fitting indeed

frank canopy
#

but yeah ill look into filter-repo-ing it out of imaginarium once im done making cookies

fiery turtle
#

Damn which cookies

north holly
#

but these cookies I might

frank canopy
fiery turtle
#

Nice

frank canopy
#

(i have celiac so has to be gf)

calm latch
#

@fiery turtle do you have dumps of AML with multiple host bridges?

fiery turtle
#

yes

calm latch
#

thanks

fiery turtle
#

looks like second bus _CRS just returns the bus range

calm latch
#

Yeah

#

And it's not a PCIe bus

#

So no MCFG?

#

But I think I'm just supposed to use IO

fiery turtle
#

this bus is covered by mcfg

frank canopy
#

if its present mcfg will probably cover all host bridges yeah

calm latch
#

But I'm trying to target systems that don't have PCIe

#

E.g. bochs

fiery turtle
#

so grab the io port resource from the pci bus

#

0xCF8 is there

calm latch
#

yeah

#

also

#

How would uACPI handle hotplug surprise events?

#

Wouldn't this need to be removing resources?

fiery turtle
#

thats not how pcie hotplug works

#

also these resources are static, they just describe memory ranges you may use for BARs

#

PCIe hotunplug works by first notifying you, then you do the unplug work, and then let the system know the device may be removed by the user safely

#

if done via acpi u call the _EJ0 method

calm latch
#

But what about something like thunderbolt

fiery turtle
#

thats pcie

calm latch
#

but user can just yank the cable out (?)

fiery turtle
#

do u have a dump from that laptop or whatever

calm latch
#

My lenovo laptop has USB 4

left orbit
calm latch
#

And the macbook had firewire and thunderbolt

left orbit
#

except different protocol that's much faster

fiery turtle
#

yeah maybe its just usb, idk

left orbit
#

but there's probably still a controller that manages all of that, no?

calm latch
#

My old laptop with Thunderbolt 3 died so I can't take its dump sadmeme

left orbit
#

even pci has to go through some other controller that translates usb->pci

#

(probably the usb4 controller)

calm latch
left orbit
#

or thunderbolt controller or whatever

#

so that controller is in charge of actually notifying you of a device disappearing

calm latch
#

I think you can take old thunderbolt 3 devices and they should just work with USB 4

#

There's also cardbus

#

(I have a couple of laptops with that)

frank canopy
#

ok i really like filter-repo

#

this slaps

#

ok heres a question

#

should zuacpi handle the relevant c headers or no?

#

im leaning no

fiery turtle
#

What does that mean?

torpid root
#

zuacpi is a great name lol

frank canopy
#

im leaning rely on the kernel

left orbit
#

yeah same

#

what if the kernel already has some headers for exactly this purpose

fiery turtle
#

Yeah

frank canopy
#

yeah

left orbit
#

or you could put this behind an option

#

like, if the kernel does have them it can tell zuacpi to fuck off

frank canopy
#

option is kinda where i was leaning but im not 100% sure overall

left orbit
#

only downside is that they need to be fetched regardless, but oh well

#

does recursive build.zig.zon stuff work as expected?

#

if you fetch a zig package, does the build system also go through the fetched dep's zon file?

fiery turtle
#

at least a readme mention would be nice ig

calm latch
#

Btw, it there an equivalent of ACPI_BUS_NUMBER_RANGE in uACPI?

frank canopy
#

that only get fetched if used

#

idk the details of how to use lazy deps tho

fiery turtle
#

UACPI_RANGE_BUS

#

if u mean the resource type

calm latch
#

I think so

fiery turtle
#

just call get_current_resources and find out

frank canopy
fiery turtle
#

damn thats really cool

frank canopy
#

im happy to transfer over to the uacpi org and update the readme to match that if you want to do that now but otherwise i dont have the energy to do any more with this today

fiery turtle
#

yeah that would be great

#

how do we do that?

frank canopy
#

i need perms to create repos in the org at least long enough to do the transfer apparently

fiery turtle
#

i guess i need to add you to the org for that?

#

yeah

frank canopy
fiery turtle
#

first official uacpi org member

frank canopy
fiery turtle
#

ill add a mention/link to the bindings to the uacpi repo readme LETSFUCKINGGOOOOOO

#

thanks for your work, very cool

rustic compass
#

@fiery turtle add me too

fiery turtle
#

sure

#

done

frank canopy
#

as noted in the zuacpi readme its wip so theres functions missing but ill be swapping over imaginarium to use the zuacpi repo as a submodule when i next work on it and most of what youd need for simple stuff (no suspend or shutdown yet really but device/namespace stuff is there) is probably already bound in zuacpi

rustic compass
#

"You don’t have the permission to create public repositories on uACPI" nooo

frank canopy
#

did you accept the invite from your email or wherever it showed up?

#

oh beat me to it

rustic compass
rustic compass
fiery turtle
rustic compass
#

only took a few months trl

fiery turtle
#

lol

rustic compass
#

*to move the repository

fiery turtle
#

how close are they in general?

#

(to being done)

rustic compass
#

well types are mostly done like 95% looking at the edge cases and handler stuff

fiery turtle
#

nice

rustic compass
#

rest is relatively easy

fiery turtle
#

thats cool

hollow elm
fiery turtle
#

@left orbit do u want the org invite as well since you basically did uacpi-linux yourself?

rustic compass
fiery turtle
#

and also monkuous for uacpi userspace work

left orbit
#

i won't say no to that :^)

#

but i don't promise i will bring anything of value in lol

fiery turtle
#

thats okay lol

#

whats your github again

frank canopy
#

for zuacpi:

  • eval only for integers atm
  • missing shutdown/power binding stuff
  • resources arent finished yet or tested
  • has shims for putting through an allocator for uacpi to use and implements alloc/free and logging kernel apis
  • basically i can fully init uacpi complete with namespace enumeration and get enough to start working on basic drivers but not much more yet and the rest of the shims the kernel has to provide
left orbit
#

@48cf

fiery turtle
left orbit
#

lmao

frank canopy
#

i was able to receive power button events and enumerate all devices with these zuacpi bits but didnt bother to actually do shut down with them

#

lol

left orbit
#

that is most definitely not me on the picture

fiery turtle
#

czapek face reveal

left orbit
rustic compass
#

#polls message

frank canopy
#

oh and i put my table types into zuacpi so you can have HPET, MADT, FADT, and MCFG tables typed

frank canopy
#

yeah its got the basics at least

left orbit
#

shouldn't the table types be pulled from uacpi itself?

frank canopy
#

zuacpi is very much me adding bindings as i need them in imaginarium lol

frank canopy
#

im not using cImport

fiery turtle
frank canopy
#

so its an extern struct either way

rustic compass
#

thanks for creating the zig bindings, i will probably never use them but their mere existance forces me to work on the rust bindings to be earlier finished than yoursKEKW

frank canopy
left orbit
#

@cImport is amazing

left orbit
#

truly one of the best features of zig

frank canopy
#

also zig translate-c

fiery turtle
frank canopy
#

i started the bindings by running translate-c on some of the first headers i needed and then refining that lol

fiery turtle
#

thats probably a good way to do it

frank canopy
#

yeah it was a good staring point for sure

#

it didnt recognize the status as an enum though which was pain

#

its def not a perfect tool

#

but thats why im making proper bindings anyway

fiery turtle
frank canopy
fiery turtle
#

ah

left orbit
#

probably because in C the enum is really just a weird integer type

frank canopy
#

yeah

fiery turtle
#

i could really use : type for enums in a lot of places

#

but its super recent C

#

i didnt want to force that

slim panther
#

yea probably don't

#

that's a c23 thing iirc

mortal yoke
#

gnu supported it as an extension, though idk about msvc

left orbit
#

msvc does it too iirc

fiery turtle
#

TCC doesnt tho trl

rustic compass
#

good thing in rust you can "tag" enum values with integers and tell the enum to behave like a integer

left orbit
#

actually msvc doesn't

#

interesting

fiery turtle
#

bruh

left orbit
#

me when <source>(1): error C2059: syntax error: ':'

rustic compass
#

and then use transmute on that, what could go wrong

fiery turtle
frank canopy
#

zig has enums and tagged unions separately so it works out here too where it treats it as an int on the abi level

left orbit
#

mfw you just commited at least 5 war crimes by writing 3 lines of rust code

frank canopy
#

sadly zig tagged unions arent c abi compatible because theres no standard for where to put the tag

#

but i can make an extern union for the things that go like that

fiery turtle
#

it sucks there isnt an abi for automatic optimized struct layout

frank canopy
#

i love comptime

left orbit
#

i love zig war crimes

fiery turtle
#

bruh

left orbit
#

might not be the most readable code ever

#

but it just works

rustic compass
left orbit
#

and you learn to embrace it

frank canopy
#

i think that code is actually broken

left orbit
#

lmao

frank canopy
#

zig comptime war crimes are fun

#

ill fix it when i actually try calling the resources functions lol

#

but yeah the idea is i can take the extern union and automatically generate at comptime the tagged union

#

and then use inline else to convert the two without having to serialize the field names to the binary

loud ice
#

lol

left orbit
#

ugly

fiery turtle
#

u wont get warnings for type punning etc

#

which is the entire point sort of

left orbit
#

wait for pitust to come up with a way to achieve this with the most cursed set of macros ever

fiery turtle
#

literally any problem in C can be solved with insane macros

frank canopy
#

lol

loud ice
#

you can also just newtype uacpi_status to a struct

#

at the cost of breaking api

rustic compass
fiery turtle
#

lol yeah

#

they broke, but only some versions of msvc

#

which is the cool part

rustic compass
#

If we can decide on what our real hardware benchmark machine should be, I have found a aspect that should be considered. Newer Intel cpus tell you the tsc frequency, using such a machine removes discrepancies from inaccurate tsc calibration

fiery turtle
#

true ig, although newer cpus allow you to have tsc scaling in VMs so u can set any frequency you want

#

also kvm reports it as well

rustic compass
#

But it would make the test more complex if you also have to compensate for tsc calibration or the hypervisor needs to trap cpuid calls and emulate those leafs or similar

fiery turtle
#

true

calm latch
#

Is this normal that bochs returns resources->entries[0].irq.num_irqs == 0 for all IRQs in uacpi_get_pci_routing_table?

fiery turtle
#

show code

calm latch
#

I think I've fixed it

#

(I was reading from 0xd00 instead of 0x3fc)

#

Though now, suspiciously, all interrupts point to GSI 9 and GSI 11??

fiery turtle
#

hm, how is that related to rsources?

fiery turtle
calm latch
fiery turtle
#

ah

calm latch
#

I guess I have uACPI working in Bochs now?

#

(I just need to reimplement ECAM)

fiery turtle
#

thats nice

surreal current
#

this was a literal trillion yrs ago but wrk pushlocks are literally identical to the reactos implementation - that isnt to say he literally looked at the wrk itself, that was just an observation i made at some point while looking at reactos pushlocks to figure out how to implement them myself

#

i got suspicious because of what you mentioned about the comments not understanding what the pushlocks were actually doing

winter orbit
#

i see

#

yeah i dont blame the suspicion

surreal current
#

but that could be just as much an effect of 1:1 decompilation without really getting what it was doing

fiery turtle
#

Btw how's reactos new acpi coming along?

surreal current
#

as opposed to literally copying code or something

winter orbit
#

maybe

winter orbit
fiery turtle
#

ah

#

whos gonna be first, haiku or ros meme

winter orbit
#

Idk probably haiku

#

this is what im losing my mind over atm

#

last thing i need to do before clt

fiery turtle
#

seems to work?

winter orbit
#

it's using a file from windows 2003 still

#

win32k.sys

fiery turtle
#

ah

winter orbit
#

im trying to fix that yeah

#

like this is all ive done for like.. the past 6-7 days

fiery turtle
#

damn, good luck

calm latch
#

How do I wake up bochs from S3?

north holly
#

bochs window

fiery turtle
#

i've studied proxima sources for a bit

#

pretty smart stuff

#

well the pre-split proxima

strong heath
#

how do powerbutton events work with uacpi

#

how does it notify the OS

fiery turtle
#

there is like 4 ways a power button can be routed

#

the simplest one aka the fixed event is just a callback from interrupt context

#

if u add support for embedded controllers then you just install a notify handler to a power button device

#

Notify() is how AML calls into a kernel

#

for the fixed event there's a uacpi_install_fixed_event_handler

#

the third way is a GPIO device, this is applicable to modern AMDs, works similarly to an EC

#

the fourth way is a generic event device, also similar idea, but needs a separate os driver as well

#

only applicable to embedded

#

and qemu on aarch64 i think

strong heath
#

okay so what do I do lol

fiery turtle
#

uacpi_install_fixed_event_handler

#

this will cover most hardware

#

well most desktops

#

and older laptops

strong heath
#

and for covering all hardware I gotta do that plus GPIO device? whats a GPIO device

fiery turtle
#

let's say this covers 60% of hardware

#

EC driver covers 30%

#

9% is GPIO

#

1% is GED

#

thats how id put it

strong heath
#

okay life sucks is the takeaway

fiery turtle
#

ec and gpio drivers are both like 200 loc of C

#

for a crappy version that will mostly work

#

if u want it fancy and async then maybe 1k loc

#

e.g. pmos supports all 4

#

well no it doesnt support the GED

#

but thats mostly for arm crap

fiery turtle
calm latch
#

It's in the AMD manual whatever

fiery turtle
#

really?

fiery turtle
#

ah

calm latch
#

Linux source for it was not too insane

fiery turtle
#

and this was on your amd laptop or pc?

gentle peak
calm latch
#

on my laptop

strong heath
#

ill give a look to what pmos does, the 60% setup should be easy

fiery turtle
#

ah ok it was on qookies laptop as well

#

maybe it doesnt concern modern amd desktops

calm latch
#

the primary sources were manual and linux

calm latch
#

Not even EC

fiery turtle
#

thats nice

calm latch
#

Btw, how does power button work on RISC-V in QEMU?

fiery turtle
#

see the GED link I sent above

#

for EC-routed power buttons i have a short summary on the osdev wiki

fiery turtle
strong heath
#

is qemu of those machines that do the fixed event handler thing

#

or not

fiery turtle
#

yeah of course

hollow elm
#

qemu uses PNP0C0C yeah

strong heath
#

so it uses the notify thing

#

thats the notify thing

fiery turtle
#

nah

#

i dont think it even has a PNP0C0C

#

even if it does, its still routed as a fixed event

hollow elm
#

i misremembered

fiery turtle
#

it's the device u hook up with a notify handler usually

strong heath
#

well I can tell you my fixed event aint firing

#

now I gotta figure out why

fiery turtle
#

issue of the skill

keen shard
#

I’ve ported all of the sysdeps for uacpi @fiery turtle

#

Now I have to actually implement it

#

Should I init uacpi at the beginning of my kernels main function?

strong heath
#

could it be the irq not firing?

fiery turtle
#

yes and yes

#

is your install_irq_handler implemented properly?

strong heath
#

I am checking if it is

fiery turtle
#

last time i checked it was a no op

strong heath
#

last time you checked it was less full than it is now

#

:3

fiery turtle
#

lol

strong heath
#

okay it works now

#

I wasnt unmasking it in my lapics

#

I pagefault on return but thats details

fiery turtle
#

ah

#

cool

#

just dont return and shutdown instantly

strong heath
#

is that a thing

#

or a joke

fiery turtle
#

nah u shouldnt do that

#

its a joke ofc

strong heath
#

you got me scared for a second

fiery turtle
#

lol

#

a lot of kernels using uacpi do it because they dont have softirq or workqueue etc

strong heath
#

does the return address or anything of the sort get passed in the uacpi handler context of the ISR

fiery turtle
#

wdym? uacpi doesnt care about anything like that, it just reads a few regs and stuff

strong heath
#

you know that you have a variable you gotta pass to the interrupt when called

#

the context thing

fiery turtle
#

its just uacpi state

strong heath
#

could not respecting that have to do with this misterious write to 0x30 that is pagefaulting me

fiery turtle
#

nah

fiery turtle
#

do u literally discard the context lol

strong heath
#

that does fit the bill in not respecting it

fiery turtle
#

what are u giving that function then

#

just null?

strong heath
#

lets say, the void

fiery turtle
#

wtf

#

that wont work ofc

strong heath
#

yeah the page fault to 0x30 could just be you trying to access a structure element in the handle

fiery turtle
#

yeah it just retrieves some stuff from the ctx associated with that irq

strong heath
#

yeah its probably that

#

how does linux handle power button events, I will need to expose this to userland somehow

#

does it just send a SIGPWR and userland picks the pieces?

fiery turtle
#

no lol

#

the power button gets an object in sysfs or wahtever

#

then u can listen to it as if it was a keyboard

#

or w/e

strong heath
#

I am going to send a SIGPWR to init

#

and it picks the pieces

fiery turtle
#

lol

hollow elm
#

gobless evdev

keen shard
#

Hi Infy sorry to bother but could you answer my question I asked earlier?

fiery turtle
#

ah right

fiery turtle
#

i mean depends on you

#

see when other kernels do it

#

you probably want early table access so u can bootstrap stuff

keen shard
#

Should I have like the idt and stuff initialized

fiery turtle
#

yes

keen shard
#

Okay

fiery turtle
#

when you call uacpi_initialize your scheduler must be online

keen shard
#

Okay so I could go memory, gdt, idt, tmpfs, sched uacpi?

kind mantle
#

You don't need FS

keen shard
#

Oh okay

left orbit
#

you need to initialize it after scheduling primitives are available but before you enumerate any buses

keen shard
#

Oh okay

#

Got you

fiery turtle
#

uacpi_kernel_mkdir trl

left orbit
#

it will also need memory management

#

and pci/port io access

#

and an allocator

#

so make sure all of that is available befoe calling uacpi_initialize and friends

keen shard
#

Okay sounds good

keen shard
#

I’m going to spend hours on gdb and get back to you guys

keen shard
#

Well now I’m having a great time

strong heath
#

okay, after making an abomination, Ironclad now handles poweroff just fine passing it to userland as a signal, which then the init chooses to poweroff with

#

ill clean up the thing a bit and I am done

fiery turtle
#

If it works it works

north holly
#

when uacpi JavaScript bindings? trl

calm latch
#

So it's like EC?

(from linux)

static irqreturn_t acpi_ged_irq_handler(int irq, void *data)
{
    struct acpi_ged_event *event = data;
    acpi_status acpi_ret;

    acpi_ret = acpi_execute_simple_method(event->handle, NULL, event->gsi);
    if (ACPI_FAILURE(acpi_ret))
        dev_err_once(event->dev, "IRQ method execution failed\n");

    return IRQ_HANDLED;
}
#

Maybe I'll write a driver for it

calm latch
#

Btw, how does uACPI handle device hotplug?

fiery turtle
#

it doesnt

#

hotplug just calls Notify

#

it's up to you to handle it

flat badge
#

ACPI based hotplug is not that useful

#

Implementing PCIe based hotplug probably makes more sense

fiery turtle
#

I dont really have any data on that, but qemu recently switch to acpi hotplug by default because SHPC is racey and sucks

flat badge
#

shpc is not pcie though

fiery turtle
#

Iirc pcie has similar problems

#

Could be wrong

flat badge
#

PCIe hotplug works fine

fiery turtle
#

Probably

kind mantle
#

TIL ACPI has a hotplug mechanism?

fiery turtle
#

Acpi is best for virtual environments

fiery turtle
flat badge
#

And you can actually use it on real hw on most modern boards

fiery turtle
#

Acpi hotplug is nice because it doesnt have any sort of timeouts

#

You have to ack it or its denied

kind mantle
#

What's it used for?

gentle peak
fiery turtle
#

Anything, pci devices, ram sticks, cpus

kind mantle
#

Hotplugging... RAM.

#

And CPU.

gentle peak
#

yes?

flat badge
gentle peak
#

both cpu and ram hotplug has been a thing for a while

calm latch
fiery turtle
fiery turtle
kind mantle
#

I guess I'm thinking too much of real HW?

flat badge
#

No

calm latch
#

But devices will always be there?

fiery turtle
#

In the namespace yes

gentle peak
# calm latch You get a notify, what do you do with it?

insertion: scan the device and its children for devices whose _STA indicates they've been newly inserted (if you encounter enumerable buses like pci i'm pretty sure you're supposed to re-enumerate those too)
removal: same thing but for newly removed

kind mantle
#

Damn, I want to support CPU and RAM hotplug on BadgerOS now

fiery turtle
#

Its trivial on qemu

gentle peak
#

any devices that need to end up in the namespace will be there from the beginning

fiery turtle
#

For ram just read _CRS when its inserted

flat badge
#

PCIe hotplug works on any thunderbolt controller though and also on many ports (they may not expose a physical button for hot plug / hot remove but there are expansion cards that do)

kind mantle
#

BadgerOS doesn't even need any big modifications to support that funnily enough.

fiery turtle
#

NT had supported acpi hotplug since forever so idk if korona is right about it being vm only

#

For both cpus and ram

flat badge
#

I'm not saying that acpi hotplug in general is VM only

fiery turtle
#

Well and pci ofc

kind mantle
#

Well NT VMs exist too, it's not like windows only gets run on real hardware

flat badge
#

But hot plugging ram or cpus is VM only

fiery turtle
#

Why? Cant u insert ram sticks at runtime lol

flat badge
#

Iirc there is ACPI hotplug for pci devices that also works on real hw

fiery turtle
#

On server hw

flat badge
#

No

fiery turtle
#

Why?

flat badge
#

Because the memory controller doesn't support it

fiery turtle
#

Like all of them?

flat badge
#

I'm not aware of any x86 machine that supports ram or cpu hotplug

kind mantle
#

AFAIK there exist some high-end expensive stuff that does actually allow for RAM hot plugging with real HW

#

Like the IBM Z mainframes for example

flat badge
#

But i know that plenty machines (even intel consumer hw) support hotplug of pci devices

kind mantle
#

That's basically mandatory with the whole USB4 situation and its PCIe tunneling

flat badge
#

But they obviously don't run acpi

kind mantle
#

No

fiery turtle
#

Anyway ram hotplug is fun to play around with on qemu

#

Same goes for cpus

kind mantle
#

Can QEMU also remove said RAM and CPUs again?

fiery turtle
#

Yeah

#

You have to ack it tho

flat badge
#

CPU hotplug on VMMs is useful, that's true

fiery turtle
#

By calling _EJ0

kind mantle
flat badge
#

Does acpi really support ram hotplug btw? How does it work?

kind mantle
#

You wouldn't want a CPU core suddenly poofing out of existence while it's still running

flat badge
#

Why would you ever do this instead of virtio balloon?

fiery turtle
fiery turtle
flat badge
#

I'm not asking about hotplug in general, I'm asking: how can ram be represented in the namespace

fiery turtle
#

Just a device with pnp id ram?

#

Or rather nvdimm or whatever

flat badge
#

Does that exist?

kind mantle
#

*that is marked as not present/inserted/whatever

fiery turtle
#

Of course

mortal yoke
#

I wonder if there are any devices doing ram offlining with acpi

flat badge
fiery turtle
#

Thats what qemu uses I think

#

Wait no its PNP0C80

#

Memory module

fiery turtle
flat badge
#

I see. I didn't know that the namespace can represent memory

slim panther
fiery turtle
#

Chinese acpi

slim panther
#

🔥 hell yes

fiery turtle
slim panther
#

,Linux

#

obviously

fiery turtle
#

Maybe its saying that windows 11 supports them

rustic compass
pine leaf
#

I could test uACPI on a UEFI implementation that's compatible with my phone meme

fiery turtle
#

like aarch64?

#

i dont think there's an aarch64 kernel with uacpi

calm latch
#

Managarm?

fiery turtle
#

It doesn't support acpi

#

On arm

calm latch
#

Ok maybe I'll port pmOS

pine leaf
#

next time I'm doing shenanigans w/ my phone I might give it a try then

fiery turtle
#

Does it actually support acpi in aarch64, or does it mostly rely on dts

left orbit
#

it does support acpi iirc

fiery turtle
#

i started work on UACPI_BAREBONES_MODE, only need to solve these now

#

it should compile only with this available

flat badge
#

very nice

slim panther
#

what about a non interactive mode?

fiery turtle
#

whats that?

slim panther
#

everything except sleep/aml stuff

#

or is that already what this is for

fiery turtle
#

every other subsystem besides tables is useless if you have no AML, so yeah

slim panther
#

👍

fiery turtle
#

but

#

this one has no allocation or thread safety

#

so there can be like a TABLES_ONLY_MODE that does feature allocation and mutexes

#

but nothing else

#

idk if it's as useful

#

not sure about a use case for that

slim panther
#

there probably isnt

flat badge
#

for what?

fiery turtle
#

an advanced table-only mode

#

with mutexes and dynamic allocation

flat badge
#

Ah

#

So a primitive table mode is definitely useful. For example, we'll use it in Managarm to detect CPUs in eir

#

= the prekernel

fiery turtle
#

yeah, a primitive one can be used in bootloaders, pre-kernels, microkernels, etc

#

builtin drivers as well

flat badge
#

That's useful because it allows to pre-allocate some data structures

fiery turtle
#

a fully featured one, idk

flat badge
#

Also, in the future we'll use SRAT for numa support etc

fiery turtle
#

yeah

flat badge
#

An advanced one sounds a bit useless, agree

fiery turtle
#

although that would probably be parsed by managarm itself

frank canopy
#

yeah once we get tables-only mode i plan to make a pre-kernel for imaginarium

fiery turtle
#

added some docs to uacpi_kernel_map

dense steppe
#

nice 👍

fiery turtle
#

i've never written the word ifndef this many times in my life

gentle peak
#

busd: info: successfully loaded 1 AML blob, 1705 ops in 3434ms (avg 496/s)
👍

fiery turtle
#

how 💀

gentle peak
#

conditional breakpoints in uacpi's main loop

fiery turtle
#

are you working on proxima 2.0?

gentle peak
#

yeah

fiery turtle
#

nice

calm latch
#

I see d at the end of bus thonk

gentle peak
#

yeah

#

it's in userspace

fiery turtle
#

bus daemon?

gentle peak
#

indeed

#

anyway, if i remove all the debugging stuff i get 73k/s on -O0 TCG

flat badge
#

-O0 TCG? is that with qemu in debugging mode?

gentle peak
#

yes

#

here's a release build (-O3 LTO KVM)

flat badge
#

that sounds painful

fiery turtle
#

damn lol

#

proxima 2.0 already faster than everything

gentle peak
#

including proxima 1.0! and it's running in userspace!

fiery turtle
#

how tho

gentle peak
#

this is probably because as of right now the libc isn't capable of threading and thus does not bother doing locking

calm latch
#

I've also just found a skill issue in my mutex, so maybe pmOS will be a bit faster

left orbit
#

wait wtf

#

8M?

#

crazy

fiery turtle
#

technically its illegal because no locking

left orbit
#

cant wait for acpi.sys sadmeme

gentle peak
#

iirc i asked you a while ago if it'd be legal if a single-threaded userspace server (that inherently does not need to care about locking) does not lock

#

and you said yes

#

so by that standard this is legal

fiery turtle
#

oh yeah

#

true ig

gentle peak
#

but it's a bit cheesy

fiery turtle
#

this design doesnt require locking

#

so its fair

gentle peak
#

also this doesn't use any cache-related cheats

#

this is the first run, nothing has been paged in yet, allocator cache is empty

fiery turtle
#

whats the libc and allocator used?

gentle peak
#

plibc (proxima libc), which uses a stripped-down version of the allocator in hydrogen

fiery turtle
#

are you planning on using it forever?

gentle peak
#

yes

fiery turtle
#

damn

#

is this an mlibc competitor

#

or do u want to keep it proxima only

gentle peak
#

oh it's absolutely not a competitor lmao

#

i'm not really trying to make it portable

fiery turtle
#

well its fast

gentle peak
#

people are welcome to use it if they wanna go through the effort ig

#

but all the code assumes it runs on proxima

fiery turtle
#

You could make it more portable

gentle peak
#

okay wtf i switched to uacpi's builtin uacpi_kernel_alloc_zeroed instead of mine that's aware of when something's already zeroed and the performance went up

fiery turtle
gentle peak
#

i guess the check's more expensive than actually zeroing

flat badge
#

meme managarm could probably beat managarm's score by running uacpi in userspace as well

fiery turtle
#

Probably

gentle peak
calm latch
#

time for a third uACPI in userspace implementation meme

gentle peak
#

like i'm pretty sure i have as many lines of table defs as actual logic in the acpi stuff

flat badge
#

nah, it's too much work just for the meme

left orbit
#

@gentle peak will you do suspend/resume?

gentle peak
#

i want to do so eventually but it's a really low priority

fiery turtle
#

But managarm could be #1

calm latch
#

It's not hard if you have libc (which you do)

flat badge
#

no, proxima would probably still be better optimized for this use case

fiery turtle
#

It's hard in managarm world because a lot of stuff in the kernel uses it

gentle peak
#

i mean there aren't really any uacpi optimizations here

#

i cobbled together this kernel api impl in a few hours

fiery turtle
#

Is the src for everything available btw?

gentle peak
#

well i haven't pushed busd yet but yeah

fiery turtle
#

Nice

#

I'll take a look when you push

gentle peak
#

might take a while, i haven't implemented all the primitives necessary for the full kernel api impl and i'm not pushing until that's done

fiery turtle
#

Luckily work stuff should be trivial in userspace

gentle peak
#

yeah especially single-threaded

fiery turtle
#

Would you do it with an event loop?

gentle peak
#

probably

fiery turtle
#

Yeah

calm latch
fiery turtle
#

Id just do an event loop probably

#

Where u can schedule oneshot work

gentle peak
#

i'll need an event loop anyway for ipc

calm latch
#

How are you planning to do your IPC btw?

fiery turtle
#

Would be cool if you make it with coroutines

#

So that e.g. uacpi sleep pauses instead of blocking

calm latch
#

makecontext stuff

gentle peak
# calm latch How are you planning to do your IPC btw?

two methods, which one is used depends on traffic type (message size, amount of traffic, etc)

  • a unix socket like thing which can bidirectionally send/receive bytes and/or handles
  • shared memory for submission & completion queues and futexes to notify either side of a new message
fiery turtle
#

As in, most qemu work is done in coroutines

calm latch
fiery turtle
#

Stackless sucks anyway

calm latch
#

but at this point why not just use threads

fiery turtle
#

Proxima fibers when

calm latch
#

You can use userspace scheduler

fiery turtle
#

Than fibers

#

And for stuff like busd u probably dont need threads

gentle peak
#

yeah threads are only for stuff that really needs high perf like the posix server

flat badge
#

= basically managarm's design

calm latch
#

But threads are also convenient and easy to use meme

fiery turtle
#

So are fibers lol except u dont get race conditions

gentle peak
flat badge
#

Managarm has shared memory queues for kernel <-> userspace communication

#

and it has mostly single threaded drivers in userspace

calm latch
gentle peak
#

ah

#

yeah it seems kinda like the most obvious design to go for

fiery turtle
calm latch
#

I did, but not for parallel stuff

#

Idk how to explain it

fiery turtle
#

Lol

calm latch
#

Like there is a single event loop in everything, and I just create threads when I feel like it

calm latch
#

My pipes server creates a thread per pipe

#

But my AHCI driver is using C++ coroutines

fiery turtle
#

Aka u use pthreads because you're lazy to design stuff

calm latch
#

yes

#

Also because of my IPC skill issue

gentle peak
#

i wanted to see what the score would be like if i did the funny uacpi_state_reset thing, instead i got vmm whack a mole

gentle peak
#

so many bugs

#

i should've expected this from something i wrote mostly between 2am and 4am

fiery turtle
#

I thought proxima was bug free

gentle peak
#

i should add more asserts

calm latch
calm latch
fiery turtle
gentle peak
#

so there's a lot of very untested code paths i'm hitting

fiery turtle
#

Is it an rb tree?

gentle peak
#

avl tree yeah

fiery turtle
#

Ah

gentle peak
#

it's not in the tree management code though

#

i'm pretty sure at least

fiery turtle
#

Where does it die?

gentle peak
#

it dies while trying to initialize a new page for busd's allocator, for some reason it can't find the region it just created

#

i'm investigating rn

fiery turtle
#

Ah

#

[redacted] curse

dense steppe
#

things like tree data structures etc. are like the one thing I consider important enough to test at the moment

fiery turtle
#

Yep

gentle peak
#

i probably should do that too

#

but i really can't be bothered

fiery turtle
#

I wonder why the old proxima was triple faulting on that pc

gentle peak
#

which pc

fiery turtle
#

Oberrows pc

gentle peak
#

ah

#

i never did figure that out

fiery turtle
#

With an i5 something

#

Yeah its strange

gentle peak
#

for my own sanity i'm just gonna assume he downloaded one of the march=native images

fiery turtle
#

Lol

gentle peak
#

okay nvm it's definitely the tree code, the region's in the linked list but not in the tree

fiery turtle
#

True true

#

Classic

dense steppe
fiery turtle
#

Yeah lol these self balancing trees are very easy to fuck up

#

Linux still has code to debug them and verify

dense steppe
#

it wasn't the self-balancing part that I messed up, though

#

rather

#

the auxiliary data I keep for fast free space lookup

fiery turtle
#

Eh whatever

#

Still

dense steppe
#

yeah

fiery turtle
#

Good thing they're easy to cover with tests in userspace

gentle peak
dense steppe
#

it's not exactly easy to think in terms of invariants everywhere

gentle peak
#

well that's not good

mortal yoke
dense steppe
fiery turtle
#

Do u still have the code btw

gentle peak
#

sounds like a lot of extra edge cases lol

dense steppe
dense steppe
dense steppe
fiery turtle
gentle peak
#

simple = fast usually

fiery turtle
#

Like pmm and heap allocator were trivial yet fast

gentle peak
#

lines of code in the fast path is in many cases a great estimate for performance

#

(incl. iterations)

dense steppe
#

what was it that Einstein said now again? thonk

calm latch
mortal yoke
flat badge
#

that could probably be merged to upstream frigg

dense steppe
#

I tried to implement something like the relatively new Linux maple tree for virtual address space management, based on some blog post or something that described the datastructure.

I won't be going down that road again for a very long time.

fiery turtle
#

Tbh it should have been iterative from the start

mortal yoke
left orbit
#

self balancing BSTs are magical

gentle peak
#

they are also a bit of a pain to implement

#

old proxima just used a plain old non-balancing bst for the vmm

#

but once you have them they're great yeah

dense steppe
#

there was one time that, for a competitive programming problem, I implemented a multiplicative segment tree over matrices. (segment tree=poor man'scompetitive programmer's self-balancing BST)

fiery turtle
#

But would be nice if you upstreamed iterative stuff

mortal yoke
dense steppe
#

Initializing lawsuit... OK

calm latch
fiery turtle
flat badge
#

lol

#

don't worry, but it would be nice to add a comment to indicate the origin of the code

mortal yoke
#

I could add a mention about frigg at the top yeah

dense steppe
#

"Initializing <whatever>... OK" is basically osdev brainrot

#

what did it even originate from?

gentle peak
#

my favorite

fiery turtle
slim panther
#

oh you mean who

dense steppe
#

no

slim panther
#

i think lapfed

left orbit
#

every osdev project ever showcased

#

that did not feature anything more impressive than a shitty ps2 keyboard driver

dense steppe
#

I should print that in my rewrite just for the meme

fiery turtle
gentle peak
#

essential proxima code

fiery turtle
#

how did it even exist without that

left orbit
#

real

#

petition to add Init GDT... OK to managarm

dense steppe
#

a slight problem for me... I initialize the GDT before any C++ code is even executed 💀

fiery turtle
#

dont forget IDT

dense steppe
#

fake OS

fiery turtle
#

that is flushed when logger is initialized

dense steppe
#

just call printk from asm

#

lol

fiery turtle
#

yes

dense steppe
fiery turtle
#
mov rdi, "Initializing GDT..."
call printk
#

or whatever

gentle peak
fiery turtle
#

lol

left orbit
#

perfect

#

how will u print

#

without a valid staack

fiery turtle
#

also inserts sleeps and progress bars

#

for gdt init

gentle peak
fiery turtle
#

to seem like a cool os

left orbit
#

ah

#

so you just do it

#

because why not

#

own stack = cool

#

:^)

gentle peak
fiery turtle
#

Stage 1 GDT init... starting

dense steppe
#

own stack = I know what I get

gentle peak
#

and the stack used for the entry point stays used for the lifetime of the system because the entry thread becomes the idle thread

dense steppe
#

etc.

left orbit
#

good to know

mortal yoke
#

I also do that ```x86asm
.lcomm STACK, 0x8000, 16

.section .text
.globl _start
.def _start
.type 32
.endef
_start:
lea rsp, [rip + STACK + 0x8000 - 40]

mov rax, cr0
// clear EM
and rax, ~(1 << 2)
// set MP
or rax, 1 << 1
mov cr0, rax

// set OSXMMEXCPT and OSFXSR
mov rax, cr4
or rax, (1 << 10 | 1 << 9)
mov cr4, rax

jmp early_start
calm latch
#

Quick question, how do I stop clang from optimizing entered_sleep away? trl

left orbit
#

asm volatile("" :: "m"(entered_sleep) : "memory");