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

1 messages · Page 29 of 1

gentle peak
#

handwritten assembly also doesn't cooperate with LTO at all

#

they definitely have the same issue proxima did, regardless of how it's actually implemented

fiery turtle
#

lemme find it

#

korona linked it recently

vast kestrel
#

Can you maybe try to replicate that in usermode

#

And try using Intel vtune or something alike

#

To check the diffs

gentle peak
#

i found it

fiery turtle
gentle peak
#

right

#

pain because of templates but shouldn't be too hard to port to c

#

actually i have no idea how to map the may_alias

gentle peak
#

oh i can just do __attribute__((may_alias))

fiery turtle
#

what the hell is gnu::artificial

gentle peak
#

seems like a debugging thing

fiery turtle
#

interesting

#

i dont understand it entirely

vast kestrel
#

What if you mark your memcpy as noinline and use __builtin

fiery turtle
#

like by default it already has inlined stuff as part of the backtrace

vast kestrel
#

Maybe it inlines the rep mosvb where the builtin memcpy didn't think it should

#

Like I am almost certain extern function has a stronger barrier than memory clobber

gentle peak
vast kestrel
#

I should mark my intrusive linked list functions as artificial tbh

gentle peak
vast kestrel
#

I mean against the asm code

#

Didn't you say the inline asm was worse than no inline asm

#

And using an extern

gentle peak
vast kestrel
#

Try marking the memcpy as noinline and use builtin

gentle peak
#

i'm porting the phd memcpy rn i'll test that afterwards

vast kestrel
#

Nice

gentle peak
#

nevermind i tried that first

#

it's now about on part with normal asm

#

but still not better than just the naive impls

vast kestrel
#

Hmmmmm

gentle peak
#

eh i'll try it anyway

vast kestrel
#

What if

#

You log the sizes of the memcpy

#

Like how much is copied/cleared

fiery turtle
#

inb4 recurses because logging memcpies

vast kestrel
#

:^)

#

You could override the uacpi functions specifically to log it

gentle peak
#

@fiery turtle it's official: uacpi memcpy is better than phd memcpy

#

phd memcpy gave 6.7M

fiery turtle
#

bruh

vast kestrel
#

Sus

#

Ok Linux just has an extern asm function on 64bit that either does memcpy if fsrm or a loop that copies 4x8 bytes at a time

#

Which it patches at load time obviously

hollow elm
gentle peak
#

ah ok

#

still surprising that it's slower than just the plain naive impl

vast kestrel
#

What does the compiler do with the naive impl that's so special

hollow elm
#

what does the generated code look like?

vast kestrel
#

Btw what about using O2 vs O3

gentle peak
#

not sure

#

it all gets inlined into huge functions because lto

vast kestrel
gentle peak
#

oh wait

#

if i use __builtin_* phd memcpy is on par with the naive impl

vast kestrel
#

Hmmm

gentle peak
#

pretty much the exact same score

#

without lto:

  • phd memcpy: 5.7M
  • naive memcpy: 5.0M
vast kestrel
#

With __builtin for the PhD right?

hollow elm
gentle peak
vast kestrel
#

I feel like the problem is inline

gentle peak
#

with -O2 + LTO:

  • phd memcpy: 7.4M
  • naive memcpy: 7.3M
vast kestrel
#

I feel like the copies are never large enough to make movsb be worth it, and that over inlining from it being small hurts it even more

#

It doesn't explain the variants with extern tho

#

And the naive is probably simple enough that it gets unrolled to something like the builtin

#

When it does get inlined

calm latch
#

(i'm too dumb for it)

loud ice
#

phd memcpy is good for a reason or something

left orbit
#

most same compilers wont unroll this because of code size

loud ice
#

also a "score" which is the low 95% confidence interval value

#

uacpi memmove: mean 159819.90625 +- 929.433544647053
compiler_builtins (rust) memmove: mean 159334.46875 +- 1066.4083397122151 (std 3077.8145654056934)

calm latch
loud ice
#

so within margin of error

calm latch
loud ice
#

@dire owl you are the maths expert, how do you calculate a % chance that this is actually an improvement

calm latch
#

I think it's not

loud ice
#

is it not?

loud ice
#

holy fuck

calm latch
loud ice
#

also, i benchmarked my sso patches properly now

No SSO: mean 143967.75 +- 1759.780639039281
SSO: mean 147692.625 +- 1063.661225436405

#

so its a definite improvement

#

4k points for free

calm latch
#

sse?

loud ice
#

sso

#

small string optimization

calm latch
#

oh

loud ice
#

i have some shitty custom out-of-tree uacpi patches

#

which help a bit with allocation pressure

calm latch
#

Yeah ACPI is full of 5 bytes + terminator strings

#

(probably)

loud ice
#

dont think i got them all in the sso changes though lol

#

okay lets do more perf improvement attempts

#

oh hmm i think i might not have been benchmarking correctly

left orbit
#

i've done a bit more i think, on my branch every buffer in uacpi does "sso"

loud ice
calm latch
#

Without general regs only trl

left orbit
left orbit
#

ok its probably similar then

loud ice
#

okay i fucked up my testing methodology

#

lets try again

loud ice
#

and its his code

#

so

#

its phd code

#

thus its a phd memcpy

calm latch
#

oh

#

but like it's not someone's thesis or something

loud ice
#

no no

#

lol

left orbit
#

it's just an inside joke (sort of)

loud ice
#

oh god

#

a thesis about memcpying real fast sounds so cursed

left orbit
#

all slightly overengineered code written by korona is referred to as "phd code"

gentle peak
#

thesis about maximizing uacpi score

left orbit
#

different cpus do different things fast

loud ice
#

oh no thats not that bad

#

the cursed thing is like

#

idk

#

well its way too practical for a phd

calm latch
loud ice
#

its fine

#

you are allowed to do that

calm latch
loud ice
#

it wont

#

movups is explicitly unaligned

calm latch
#

I wonder what happens if I give it restrict

#

to my code that is

loud ice
#

inb4 it gets turned into a call to memcpy

#

okay so lets try testing this

gentle peak
#

that's what -fno-builtin/-ffreestanding is for

calm latch
loud ice
#

okay lets try writing tests

#

but good ones this time

calm latch
loud ice
#
baseline           | mean 115812.91666666667 +- 1033.0985163355087
good memcpy        | mean 157890.83333333334 +- 1977.378657942172
+rust memset       | mean 147968.41666666666 +- 1287.0687489231607
good memcpy/memcmp | mean 161383.16666666666 +- 2146.584592338015
+rust memmove      | mean 159985.08333333334 +- 1673.8996305597188
+rust strlen       | mean 160433.58333333334 +- 1264.8421854959556
gentle peak
#

i should add a system to proxima that detects at runtime if there's only one cpu and if so switches out some functions for cheaper versions

gentle peak
#

for example turning spin_lock_noirq into ret or lock cmpxchg into cmpxchg

loud ice
#

you should just build two kernels

#

one with smp and one without

gentle peak
#

well yeah but then to be fair to all the smp kernels i'd have to test with the smp version

loud ice
#

you can test on both

#

have one NOSMP and one SMP result

gentle peak
#

true but that's ugly

calm latch
#

What happens if I add AVX to pmOS...

loud ice
#

lol

#

okay

loud ice
#

baseline is already with sso fwiw

#

rust memset, memmove and strlen shit

#

and memcpy and memcmp good

loud ice
#

so its a slight hit

#

my dedicated 32 byte slab fastpath was also a big improvement, without it i get mean 158387.5 +- 1826.162830652172

vast kestrel
#

I wonder if using lock elision will help the lock cmpexchg

#

Like the HLE stuff

dense steppe
#

In the ACPI specification, there's this field called the "hardware signature". Is it possible to cheat the uACPI benchmark by somehow loading a pre-populated namespace if this value matches that of the pre-populated namespace's FADT->Hardware Signature?

fiery turtle
#

this signature is for resume from S4

#

so that the os can distinguish between S4 resume and clean start up

#

it doesnt help with namespace preservation

dense steppe
#

The only thing that determines the hardware signature is the ACPI tables.
this is useless for any uACPI benchmark cheating purposes

torpid ferry
vast kestrel
#

I think HLE is different to TSX

fiery turtle
#

the ram is reset during s4 sleep soo

torpid ferry
#

HLE is part of TSX i think

vast kestrel
#

Like it's part of TSX

#

But the things with TSX was about RTM no?

calm latch
#

Quick question, if I have SSE and just do inline void save_sse() { asm volatile(" fxsave %0 " ::"m"(data)); } what do I do to support AVX?

loud ice
#

you have to use xsave i think?

gentle peak
#

avx needs xsave yeah

calm latch
#

But like is it always available?

vast kestrel
#

Not on CPUs without it

loud ice
#

i think theres an enable bit

#

for all of avx that is

calm latch
#

Because now I support all x86_64 CPUs

#

I don't pass any march

gentle peak
#

avx is usable if:

  • xsave is supported and enabled
  • avx is supported
  • xsave is configured to save/restore avx registers
calm latch
#

So like I do CPUID memes, and use XSAVE if it's supported and FXSAVE if not?

gentle peak
#

yeah

loud ice
#

so i dont know what magic rust is doing

#

but evidently its rather fast magic

loud ice
#

wtf memset on free worsened my perf

#

these error bars are way too big

#

maybe 32 samples would get me close enough

calm latch
#

Are there x86-64 CPUs which don't support GSBASE?

loud ice
#

but that makes testing too annoying

loud ice
#

but you dont really have to care

calm latch
#

bruh

loud ice
#

its hobby osdev

calm latch
#

that's no swapgs

loud ice
#

oh hmm

calm latch
#

what do you do in those situations

loud ice
#

hmm

#

okay i dont know anymore

#

oh

calm latch
#

according to some manual (idr if it's intel or amd) from my memory it's view into segment cache

loud ice
#

thats not how it works

calm latch
#

and you can't load segments of 64 bits

vast kestrel
#

Isn't swapgs architectural to x86-64?

loud ice
#

i think fsgsbase is for wrfsbase and wrgsbase

#

swapgs and the MSRs are separate

vast kestrel
calm latch
#

oh, the instructions

loud ice
#

yes

gentle peak
calm latch
#

ok

gentle peak
#

swapgs is part of the base x86_64 isa

calm latch
#

i don't use it

vast kestrel
#

The msrs and swapgs are architectural

calm latch
#

i just use msrs

#

yeah

#

false panic

gentle peak
#

fsgsbase is the faster way to read/write the GS_BASE and FS_BASE msrs

calm latch
#

how much faster? Thonk

gentle peak
#

don't know

calm latch
#

like is it even worth extra if statement faster?

gentle peak
#

probably considering they exist

calm latch
#

I think it's for manipulating them from userspace

#

mostly

frank canopy
#

yeah if you could only enable them for kernelmode id use them

#

but i just use MSRs since i dont want to allow userspace messing with fsgsbase

gentle peak
#

yeah same

calm latch
#

why not?

gentle peak
#

makes the paranoid irq entry points a pain

#

if you don't enable fsgsbase you can just read the msr and swap if it's a kernel mode address

frank canopy
#

because fs and gs base is how threadlocals and stuff work in userspace

gentle peak
#

if you enable fsgsbase userspace can set it to any canonical address they want

#

including kernel ones

calm latch
gentle peak
#

so now whether a paranoid irq entrypoint uses valid gs is controllable by userspace

calm latch
#

just don't be paranoid trl

gentle peak
#

bit hard for NMIs and MCEs

calm latch
#

also as someone suggested just store it on top of the NMI's stack

#

like one above what gets loaded from tss

#

ists*

gentle peak
#

as in, the IST? that'd work yeah

calm latch
#

wow sse is bad

#

or not

#

so CPU tells you the size of xsave stuff?

gentle peak
#

yeah

#

the cpu tells you the features you can enable

#

conveniently guaranteed to be in the same format as the register for the features you want to enable

#

then once you've set up that register it tells you the size of the context for the features you've enabled

calm latch
#

no but like it's future compatibility (?)

gentle peak
#

yes

calm latch
#

So I just add a few LoC and have AVX

gentle peak
#

if you unconditionally enable all features with xsave you'll be able to support all future extensions (as long as they don't supersede xsave)

calm latch
#

xsavec/xsaves?

gentle peak
#

i personally don't use them

#

don't remember why

vast kestrel
#

I sure do love the offtopic convos that always appear in here

#

uACPI thread > any other channel

calm latch
#

i think it's just a lot of smart people hanging out in progress-report channels

#

also AVX is totally related to uACPI

dire owl
#

but already just looking at the numbers I can see it's not statistically significant

loud ice
#

wonderful

dire owl
#

a relevant measure would be the difference dvidied by the root mean squared of the errors

#

if it is bigger than 3, one typically considers that significant

#

this is like

#

definitely smaller than 1

loud ice
#

the value after the +- is std / sqrt(n)

#

n=12

dire owl
#

so consistent with the hypothesis that it makes no difference

dire owl
loud ice
#

oh also * 1.96

gentle peak
#

EBX = everything that's enabled
ECX = everything that the cpu supports

calm latch
#

When I initialize my kernel, ebx is 576 and ecx is 2432

gentle peak
#

in this case they should be the same

calm latch
#

maybe I do it in a different order

gentle peak
#

you need to set up xcr0 before getting the size

#

if you do that you should be good

calm latch
#

or use ecx

#

yeah

#

not your bug

gentle peak
#

ecx should always be big enough yeah but it might be too big if you choose to disable certain features

#

so you might have some wasted space if you use ecx

#

shouldn't matter that much though

fiery turtle
#

@gentle peak btw why do u manually add uacpi's sources if it exposes them via a meson.build?

gentle peak
#

you can't have recursive subprojects in meson

fiery turtle
#

u can have a wrap no?

gentle peak
#

and i didn't want uacpi to be a sibling of hydrogen because it's not really a separate thing

#

uhh

#

i've never used wraps

calm latch
#

I almost have AVX but it pagefaults doing xrstor (%rcx) nooo

fiery turtle
#

anyway im not good at meson so idk what that means

dusky glade
#

hi

gentle peak
#

this is an intentional design choice

#

i don't like it personally but whatever

#

oh wait nevermind i lied apparently the meson documentation is just wrong

calm latch
# calm latch I almost have AVX but it pagefaults doing `xrstor (%rcx)` <:nooo:750466870993223...
struct SSE_Data {
    klib::unique_ptr<u8[]> data = nullptr;
    ...
};

void SSE_Data::restore_sse()
{
    switch (sse_ctx_style) {
    case SSECtxStyle::FXSAVE:
        asm volatile("fxrstorq (%0)" : : "r"(data.get()));
        break;
    case SSECtxStyle::XSAVE:
    case SSECtxStyle::XSAVEOPT:
        asm volatile("xrstor (%0)" : : "r"(data.get()), "a"(0xFFFFFFFF), "d"(0xFFFFFFFF));
        break;
    default:
        assert(false);
    }
}

Does this look ok?

mortal yoke
#

you want to use xrstorq too

calm latch
#

It's passing rcx

#

in assembly

#
;     switch (sse_ctx_style) {
ffffffff8000672c: 74 0f                    je    0xffffffff8000673d <sse_exception_manager+0x3d>
;         asm("xrstorq (%0)" : : "r"(data.get()), "a"(0xFFFFFFFF), "d"(0xFFFFFFFF));
ffffffff8000672e: b8 ff ff ff ff           movl    $0xffffffff, %eax       # imm = 0xFFFFFFFF
ffffffff80006733: ba ff ff ff ff           movl    $0xffffffff, %edx       # imm = 0xFFFFFFFF
ffffffff80006738: 0f ae 29                 xrstor    (%rcx)
#

I think I'm going to finally make kernel print %cr2 on pagefaults galaxybrain

mortal yoke
calm latch
#

huh

#

so it's not what I thought

mortal yoke
#

xrstor uses a different format for the x87 state than xrstorq

#

the same way as fxrstor and fxrstorq are different

calm latch
#

Wait a second

#

It's not a pagefault

#

It's #GP

#

This means that my cr4 is garbage

#

or misaligned pointer

#

nope

#

rcx: 0xFFFF80000001B020

#

cr4: 40620

gentle peak
#

yeah you didn't set osxsave

calm latch
#

Isn't 1 << 18 == 0x40000?

gentle peak
#

oh that's in hex

#

is the xsave area initialized?

calm latch
#

I memset it to 0

gentle peak
#

oh wait

#

it's an alignment issue

#

xsave requires 64-byte alignment

#

yours is 32-byte aligned

calm latch
#

bruh

#

I don't have alligned malloc

#

I think at least

#

Maybe I do

mortal yoke
#

just overallocate it in pages lol

#

its not that much memory wasted anyway

calm latch
#

(I use dlmalloc as kernel heap galaxybrain)

#

(it's like 1/3 of my kernel in terms of LoC)

#

Ok I think I have AVX

gentle peak
#

one way to check is qemu's info registers, if AVX is usable the output will be formatted like this

calm latch
#

I'm compiling for -march=znver3

#

I think it's faster on my laptop...

#
;         *((char *)dest++) = *((char *)src++);
  24acd0: c5 fc 10 04 3e               vmovups(%rsi,%rdi), %ymm0
  24acd5: c5 fc 10 4c 3e 20            vmovups0x20(%rsi,%rdi), %ymm1
  24acdb: c5 fc 10 54 3e 40            vmovups0x40(%rsi,%rdi), %ymm2
  24ace1: c5 fc 10 5c 3e 60            vmovups0x60(%rsi,%rdi), %ymm3
  24ace7: c5 fc 11 04 38               vmovups%ymm0, (%rax,%rdi)
  24acec: c5 fc 11 4c 38 20            vmovups%ymm1, 0x20(%rax,%rdi)
  24acf2: c5 fc 11 54 38 40            vmovups%ymm2, 0x40(%rax,%rdi)
  24acf8: c5 fc 11 5c 38 60            vmovups%ymm3, 0x60(%rax,%rdi)
#

Same as phd memcpy

#

I think zen 3 is weaker than latest intel so...

#

can someone with fast intel test it? 🙏

gentle peak
#

i'm also on zen 3 so shouldn't be too different from what you got but on my pc it's 1.2M/s

calm latch
#

I get this on 5900X

mortal yoke
gentle peak
#

that's what you get when it's zero nanoseconds

calm latch
#

Can you give it deadline tsc?

#

qemu-system-x86_64 -serial stdio -m 512M -cpu max,+hypervisor,+invtsc,+tsc-deadline -M q35 -accel kvm -cdrom limine/pmOS.iso -smp 1

#

invariant*

mortal yoke
#

ah now it looks realistic

calm latch
#

I don't have kvm clock sadmeme

calm latch
mortal yoke
#

i5 13600k

median crest
calm latch
#

Not if your clocks stuff is a mess

median crest
#

you cannot mess kvm clock up

#

it is literally a monotonic nanosecond clock for free

gentle peak
#

proxima's clocks stuff needs to be reworked too because right now it cannot cope with a time source that changes frequency

#

or with any non-tsc time source for that matter

calm latch
#

which time sources are those?

gentle peak
#

kvmclock

calm latch
#

I mean those that change frequency

gentle peak
#

yeah, kvmclock

#

let me rephrase that a bit
proxima currently uses TSC ticks as its internal time unit in a bunch of places, and it cannot cope if the TSC changes frequency

calm latch
#

My kernel can only calibrate with PIC and only uses LAPIC for scheduling and if there's not invariant TSC, it's also using lapic for monotonic time

#

With 20Hz interrupts or so

gentle peak
#

kvmclock gives you a mapping from tsc->ns that automatically changes if tsc freq changes

mortal yoke
#

why would it change tho

gentle peak
#

vm migration to another cpu that has a different tsc frequency

median crest
#

vm migration

gentle peak
calm latch
#

I'm suspecting it's issue with locks meme

calm latch
gentle peak
#

basically how kvmclock works is you give it a physical address to a structure that holds the conversion info

calm latch
#

You write to msr and it updates that

gentle peak
#

nope it auto updates

#

before the vm gets migrated a flag in that conversion info gets set that basically says 'hey this conversion info is invalid'

#

when the vm has been migrated it changes the conversion info and clears the flag

calm latch
#

but it also gives you time in nanoseconds

median crest
#

its unreadable astral code but it should give you an idea

calm latch
#

looks like average C to me

gentle peak
#

this is the one i'm looking at

#

when it starts updating flags is changed to indicate that

calm latch
#

I'm telling from memory

gentle peak
#

it changes tsc_to_system_mul and tsc_shift and then clears the bit in flags

calm latch
#

The MSR doc said that this structure gets updates when you write it

gentle peak
#

it gets updated on the initial write and every time it needs to be changed afterwards

calm latch
gentle peak
#

oh it changes version actually

gentle peak
median crest
#

different msr yeah

gentle peak
#

i'm not sure what the purpose is of that one

calm latch
median crest
calm latch
# calm latch

But it's unrealistic to be updating this all the time

gentle peak
#

yeah that one doesnt auto update

#

or well it can if the hypervisor impl feels like it

#

but its not guaranteed to

vast kestrel
#

does the acpidumps repo have the qemu tables by any chance?

dusky glade
#

i am in ur walls by chance

vast kestrel
#

I sure do not hope so given they are made of reinforced concrete

dusky glade
#

i am crawling out of them

#

muhehe

calm latch
left orbit
#

well this is vectorized

calm latch
#

I think I've used the wrong term

left orbit
#

i'd say that's a slightly different case

gentle peak
left orbit
#

you probably wouldn't get an unrolled loop with -mgeneral-regs-only

calm latch
#

You do

#
;         ((char *)to)[i] = ((const char *)from)[i];
ffffffff8003d3e0: 44 0f b6 0c 3e           movzbl    (%rsi,%rdi), %r9d
ffffffff8003d3e5: 44 88 0c 38              movb    %r9b, (%rax,%rdi)
ffffffff8003d3e9: 44 0f b6 4c 3e 01        movzbl    0x1(%rsi,%rdi), %r9d
ffffffff8003d3ef: 44 88 4c 38 01           movb    %r9b, 0x1(%rax,%rdi)
ffffffff8003d3f4: 44 0f b6 4c 3e 02        movzbl    0x2(%rsi,%rdi), %r9d
ffffffff8003d3fa: 44 88 4c 38 02           movb    %r9b, 0x2(%rax,%rdi)
ffffffff8003d3ff: 44 0f b6 4c 3e 03        movzbl    0x3(%rsi,%rdi), %r9d
ffffffff8003d405: 44 88 4c 38 03           movb    %r9b, 0x3(%rax,%rdi)
ffffffff8003d40a: 44 0f b6 4c 3e 04        movzbl    0x4(%rsi,%rdi), %r9d
ffffffff8003d410: 44 88 4c 38 04           movb    %r9b, 0x4(%rax,%rdi)
ffffffff8003d415: 44 0f b6 4c 3e 05        movzbl    0x5(%rsi,%rdi), %r9d
ffffffff8003d41b: 44 88 4c 38 05           movb    %r9b, 0x5(%rax,%rdi)
ffffffff8003d420: 44 0f b6 4c 3e 06        movzbl    0x6(%rsi,%rdi), %r9d
ffffffff8003d426: 44 88 4c 38 06           movb    %r9b, 0x6(%rax,%rdi)
ffffffff8003d42b: 44 0f b6 4c 3e 07        movzbl    0x7(%rsi,%rdi), %r9d
ffffffff8003d431: 44 88 4c 38 07           movb    %r9b, 0x7(%rax,%rdi)
ffffffff8003d436: 44 0f b6 4c 3e 08        movzbl    0x8(%rsi,%rdi), %r9d
ffffffff8003d43c: 44 88 4c 38 08           movb    %r9b, 0x8(%rax,%rdi)
ffffffff8003d441: 44 0f b6 4c 3e 09        movzbl    0x9(%rsi,%rdi), %r9d
ffffffff8003d447: 44 88 4c 38 09           movb    %r9b, 0x9(%rax,%rdi)
ffffffff8003d44c: 44 0f b6 4c 3e 0a        movzbl    0xa(%rsi,%rdi), %r9d
ffffffff8003d452: 44 88 4c 38 0a           movb    %r9b, 0xa(%rax,%rdi)
ffffffff8003d457: 44 0f b6 4c 3e 0b        movzbl    0xb(%rsi,%rdi), %r9d
ffffffff8003d45d: 44 88 4c 38 0b           movb    %r9b, 0xb(%rax,%rdi)
ffffffff8003d462: 44 0f b6 4c 3e 0c        movzbl    0xc(%rsi,%rdi), %r9d
ffffffff8003d468: 44 88 4c 38 0c           movb    %r9b, 0xc(%rax,%rdi)
ffffffff8003d46d: 44 0f b6 4c 3e 0d        movzbl    0xd(%rsi,%rdi), %r9d
ffffffff8003d473: 44 88 4c 38 0d           movb    %r9b, 0xd(%rax,%rdi)
ffffffff8003d478: 44 0f b6 4c 3e 0e        movzbl    0xe(%rsi,%rdi), %r9d
ffffffff8003d47e: 44 88 4c 38 0e           movb    %r9b, 0xe(%rax,%rdi)
ffffffff8003d483: 44 0f b6 4c 3e 0f        movzbl    0xf(%rsi,%rdi), %r9d
ffffffff8003d489: 44 88 4c 38 0f           movb    %r9b, 0xf(%rax,%rdi)
left orbit
#

oh god what in the fuck is that

calm latch
#

clang

gentle peak
#

llvm tends not to care too much about code size

#

dont know about gcc

median crest
calm latch
#

I'm gonna add restrict

left orbit
gentle peak
#

well its not too bad actually my code can handle a 'spurious' tsc deadline trigger

#

im mostly worried about events being late if the tsc frequency decreases

calm latch
#

I.e. doing what it was told

#

And not using misaligned movq

calm latch
#

Unless you're realtime

#

In which case why are you running in a VM

gentle peak
#

i don't think it'll have too many bad consequences but i don't like the concept

calm latch
#

I would be more worried about events arriving early

gentle peak
#

oh no that's not a problem since i decided the best way to handle cancelling events on another cpu was to just let the interrupt fire and trigger none of the remaining events

calm latch
#

No but like let's say you're waiting on hardware to time out

#

And suddenly your clock runs 10x faster

#

idk if that's possible but still

#

yeah

gentle peak
#

the interrupt will arrive early, the timing code will notice that the earliest event has its threshold after the current time, so none of the events get triggered and the deadline gets reprogrammed

calm latch
#

You'd ask kvmclock for time

dense steppe
#

When an interrupt happens, you just look at kvmclock and ask "has this changed?"

calm latch
#

No

#

You have a queue of events

#

A heap tabien

gentle peak
# calm latch You'd ask kvmclock for time

if you're in a polling loop with timeout, the api you're using returns nanoseconds so there's no issue
if you're using the timing events subsystem, it'll notice that the interrupt arrived early and return without triggering any events

calm latch
# calm latch You have a queue of events

When you get an interrupt, you look at the front of priority queue, however it's implemented, and if its time is smaller than system clock, you fire the event

gentle peak
#

its time wouldnt be smaller than the system clock though

#

because both times would be stored in nanoseconds

calm latch
#

Yeah that's what I'm saying, things arriving early is not a problem

gentle peak
#

oh i thought you were trying to say it is a problem

calm latch
#

I didn't think about that

calm latch
dense steppe
#

Anyways a changing TSC frequency is not something that should normally happen. If one wants a migratable kernel, it is probably possible to get some sort of interrupt/event delivered before and after migration. It isn't worth it for me to worry about VM migration

calm latch
#

It's not up to the kernel to decide if it want's to be moved (?)

calm latch
dense steppe
calm latch
#

What

#

User can throw their PC out the window

#

And the kernel would also not be able to stop that

dense steppe
#

yeah the kernel certainly cannot do anything about that lol

calm latch
dense steppe
#

yeah

#

but AFAIK that requires either of:

  1. user interaction. you tell QEMU to migrate the kernel (or suspend execution I guess)
  2. someone runs your kernel in a datacenter or something which auto-migrates.
    until either of these happen, we don't have to care about migration
calm latch
#

yeah

dense steppe
#

when they do happen, support for it can be fixed

calm latch
#

but at that point the os would have enough functionality for user to be interested in running it in a datacenter

dense steppe
slim panther
#

[ 0.005160] [ 0] acpi: successfully loaded 1 AML blob, 1711 ops in 0ms (avg 4032334/s) 4M cracked without SIMD

fiery turtle
#

slowly adding support for write-then-read fields to uACPI (IPMI, SMBus, GeneralPurposeIO, GenericSerialBus, etc)

#

i have to propagate this response all the way from field dispatch code, kinda annoying

#

@mortal yoke qacpi support for this crap when

mortal yoke
#

I wonder how hard would that be

#

well ig its not that hard but annoying yeah

fiery turtle
#

yeah its annoying af

mortal yoke
#

does it always return a buffer or can it also return an integer?

fiery turtle
#

also all fields work with u64 accesses atm, and this requires a buffer

mortal yoke
#

ah

fiery turtle
#

technically u cant even store an int

#

well ACPICA errors out

#

i will support that because my code is generic enough

#

this is ACPICA

mortal yoke
#

do you also pass the source as-is to the handler?

fiery turtle
#

nah you will have to allocate a separate buffer and memcpy

#

and then that buffer is returned to the caller

#

so the source stays unmodified

#

so basically:

  1. take src
  2. allocate a buffer with the size required by protocol + field attribute specifier
  3. memcpy src to buffer
  4. pass buffer to address space handler
  5. address space handler reads the buffer then memcpies the response into it
  6. the buffer is returned back to AML from the store op
#
uacpi_status uacpi_dispatch_opregion_io(
    uacpi_namespace_node *region_node, uacpi_field_unit *field,
    uacpi_u32 offset, uacpi_region_op op, uacpi_u64 *in_out
)

My current field dispatch thing looks like this, i guess ill have to make this u64 a union of either u64 or buffer depending on field type

mortal yoke
#

yeah idk if there are any other good options

#

ig Ill implement this in qacpi too, maybe also some kind of table api finally so I can implement most of the remaining ops lol

fiery turtle
#

its really annoying how they shoved completely different functionality into the classic field op

#

just make a separate op or something

#

because this breaks like all abstractions

#

u cant even have generic trace_field_io

#

because the write is actually both a write and a read and its actually done on a buffer and not a u64

mortal yoke
#

also other thing that I should do is breaking the huge 1k line switch to separate functions but that's a huge pain

fiery turtle
#

Load will be useful as soon as u start using capability detection

#

because it loads extra aml code when u do that

fiery turtle
#

Well as far as Load/LoadTable i have so many tests for that with probably 100% coverage of those ops so u cant screw it up

mortal yoke
fiery turtle
#

Btw if u want NT compat u pretty much must implement Load/LoadTable as fake function calls

#

because mutex state and stuff is preserved across the load boundaries

#

not that its hard tbh

#

idk why acpica didnt do it

#

acpica full on allocates an entirely new interpreter state from scratch and goes into recursion

mortal yoke
#

what about stuff like Local0, are they also separate for the load or are they the global ones (or local to the method where the load is called?)

fiery turtle
#

its an entirely fresh method, so locals are fresh as well

#

table loads are like anonymous methods with a scope of \ by default

#

and well the fact that named objects are preserved

mortal yoke
#

ah that's actually nice, so basically the only thing you have to make sure is that the nodes created inside that method don't get destroyed at the end

#

yeah

fiery turtle
#

and one more catch

#

u gotta make sure to discard anything that it may try to Return

#

so that its not magically returned by Load etc

mortal yoke
#

should be easy enough, I just mark the method's op frame as not needing a result and the return value is not pushed

fiery turtle
#

ah

mortal yoke
#

that's what I already do if you call a method that returns something and discard its result

fiery turtle
#

i see

#

btw limited recursion depth and while timeouts when

mortal yoke
#

really the only recursion is with the refcounted things, ig I could convert that to queue-based unref

fiery turtle
#

no i mean like

#

AML call stack depth

mortal yoke
#

ah lol

fiery turtle
#
// Name: Infinite recursion eventually ends
// Expect: int => 0

DefinitionBlock ("", "DSDT", 2, "uTEST", "TESTTABL", 0xF0F0F0F0)
{
    Name (MAIN, 0xDEADBEEF)
    Name (ITER, 0)

    Method (HANG) {
        ITER++
        HANG()
    }

    HANG()
    Printf("Recursed %o times before stopping", ToDecimalString(ITER))

    If (ITER > 64) {
        MAIN = 0
    } Else {
        Debug = "Recursion depth was too small"
    }
}
#

i want u to pass this test

mortal yoke
#

well it wouldn't be hard, I'd just have to check the amount of method frames in call

fiery turtle
#

this also tests the fact that method aborts dont abort the entire table load

mortal yoke
#

is that a new test?

fiery turtle
#

its pretty old

mortal yoke
#

maybe I added like 7 month old tests when I added them 2 months ago lol

fiery turtle
#

bruh

winter orbit
#

I’ll repost this here now since I’m working on making it presentable now, I’m like 40% done

north holly
#

holy shit

winter orbit
#

There’s some weirdness here since windows just takes in the raw ACPI tables and redoes some stuff in Po for some reason

#

But I’ll explain it later it’ll (probably) make sense

north holly
#

now what score does it get trl

winter orbit
#

very bad atm I got a lot of clean up to do

#

Linux is faster

left orbit
#

holy shit what?

winter orbit
#

yeah I think that’s my fault though

left orbit
#

no no like

#

how???

winter orbit
#

So I’ll get a final score when I finish rewrite

left orbit
#

how did u get windows to do that with uacpi

#

is my question

#

doesn't windows have it's own aml interpreter and all

winter orbit
#

Windows reimplements a lot of its sleep logic in Po

jaunty fox
#

po, one of the great rivers of europe

winter orbit
#

It has 3

north holly
winter orbit
#

ACPI.sys is one of the main ones

#

Which is now uACPI

left orbit
#

can you use uacpi for the actual aml parsing+interpreting

#

oh damn

winter orbit
#

yeah

left orbit
#

that is so cool

#

good job!

north holly
#

now when make fast angr

winter orbit
#

I’m trying it’s very ugly hacks atm

#

I had to reverse 80 interfaces

#

It was a pain

north holly
jaunty fox
#

was react os previously using the ACPICA?

winter orbit
#

Correct

winter orbit
#

We have a PR to fix this

jaunty fox
#

infy says they refuse to be windows compatible in acpica, so this should be more fitting

winter orbit
winter orbit
#

I tried to do this with ACPICA too at least to show some behavior comarisions

#

Nothing

#

It can’t even get close

north holly
#

hey if reactos needs a reference for S3 suspend

#

obos has done it

#

(obos shilling complete)

winter orbit
#

I’ve already looked at obos

north holly
#

who dat

#

oh

winter orbit
#

Like I work in bios dev so I know how window suspend works

#

But examples helped

left orbit
#

@winter orbit kind of an off topic question, but do you know
a) can windows run on platforms without acpi
b) can you patch hal.sys to add support for different interrupt controllers
it was on my to-do list for a long time but i wanted to look at how to get windows up an running on apple sillicon without doing some weird gic emulation but instead just replace hal with one that supports apple's interrupt controller (which is the big issue with windows iirc)

#

and by windows i mean modern windows, like latest windows 11 or something

winter orbit
#

A) no

left orbit
#

ah

winter orbit
#

B) Hal is gone in win10 22+

left orbit
#

so i do need to fake some acpi tables for it

#

damn what?

winter orbit
#

you need to implement some real ACPI tables

#

And also

#

Making a interrupt controller for windows is now almost impossible

#

Allegedly there’s some new way but we haven’t started learning yet

jaunty fox
winter orbit
#

Gic Supoort is now injected into NTOSKRNL as a lib

winter orbit
#

All inside ntoskrnl

jaunty fox
#

good for optimisation this way

left orbit
#

would patching ntoskrnl technically work?

winter orbit
#

Not going to lie to you, no

left orbit
#

damn

#

sad

winter orbit
#

There might be some new kmdf thing windows allows

left orbit
#

hypervisor + gic emulation is the only reasonable way then

winter orbit
#

To our knowledge yes

left orbit
winter orbit
#

there used to be a system for using other controllers

left orbit
#

like before any interrupt controller is set up?

winter orbit
#

yup

left orbit
#

damn okay

winter orbit
#

But figuring it what secret system windows made isn’t optimal yet

#

we don’t know of anything that replaced 3rd party Hal extensions

#

Which is how you’d do this before windows 10 23+

#

so yes there’s some old version of windows 10 you could port

#

But for win11 you’d need to reverse the early boot stuff

#

And see if there’s a way

left orbit
#

what's kinda confusing is that hal.dll still has a bunch of exports related to interrupts on my windows 11 system (24h2, 26100.2605)

#

are they just not used anymore or

winter orbit
#

file up some decompilafion and look at what those functions do :3

#

They’re there for driver compatibility

left orbit
#

oh they are all forwarded to ntoskrnl

#

im dumb

#

i was wondering why the file was so small

winter orbit
#

drivers imported from Hal for a decade

left orbit
#

now that explains it

winter orbit
#

yeah sorry they very much screwed over people when removing Hal extensions

left orbit
#

i'll get an aarch64 ntoskrnl later and take a look, maybe i can figure out some hacky way to get that thing in there

left orbit
#

i dont even want a proper way, anything would work at this point

winter orbit
#

yeah because GIC emulation makes me angry

north holly
#

another day, another infy W

#

and another nyaux bug

#

now I need to go deal with fork

winter orbit
#

Infy first person to make better ACPI than windows confirmed

left orbit
fiery turtle
winter orbit
#

Only ACPI.sys is a full on interpreter

#

But there’s two other spots that do stuff with raw ACPI tables.

#

Sleep is implemented in windows by checking stuff in Po, Hal, and ACPI.sys

#

I’ll try to document what does what but uACPI does massive amount of work here
And it booting at all is wild

#

Since win10 only uses modern APIC etc etc

fiery turtle
#

yeah insane work

#

well done

north holly
#

how many ops/s does it get

winter orbit
#

40% done with rewrite/clean up so I’ll post it after

north holly
#

currently

winter orbit
#

Uhh let me grab

fiery turtle
north holly
fiery turtle
#

but grass touching is taking my time

left orbit
#

uacpi+windows before uacpi+linux is crazy

fiery turtle
winter orbit
#

1.1M

#

On this boot

winter orbit
fiery turtle
#

OBOS faster than NT confirmed

north holly
#

hehehe

winter orbit
#

yeah it’s slow atm

#

I screwed up the locks I think

north holly
#

is this on qemu q35?

#

+kvm

#

because that's what that was done on

winter orbit
#

yeah

north holly
#

obos faster than NT trl

winter orbit
#

Confirmed

fiery turtle
#

surely trl

winter orbit
#

But NT has smooth wake up on hardware

north holly
#

with uACPI?

#

didn't think so trl

winter orbit
#

as long as I ignore the debug log it’s great

fiery turtle
winter orbit
#

stub

north holly
#

ok new server nickname

fiery turtle
north holly
#

see, obos even has better suspend support than NT with uACPI trl

#

obos superiority confirmed.

winter orbit
#

Do you want me to spend today fixing that trl

north holly
#

suspend is pain

winter orbit
#

Windows does it weird

#

I don’t understand it yet

north holly
winter orbit
#

Then there’s modern standby

fiery turtle
#

well obos cant restore the fb on wake sooo

#

its easy to beat

north holly
#

waiting for uDRM

#

@slim panther

winter orbit
#

where’s uWDDM

#

drm is awful

north holly
#

where's uWu

dusky glade
dusky glade
slim panther
dusky glade
#

someone make uNT

winter orbit
#

reactostrl

dusky glade
dusky glade
#

port uWDDM to nyaux

winter orbit
#

Thanks to uACPI I’ve been able to process my WDDM reimplementation

north holly
#

what if I just homebrew all my GPU drivers

#

surely it won't be too hard (not)

winter orbit
#

so I can load stuff for my RTX 4060 now

#

only display resizing but hey

dusky glade
winter orbit
#

That’s funny

dusky glade
dusky glade
winter orbit
#

Actually my WDDM implementation will be MIT

dusky glade
#

are u a masochist

north holly
winter orbit
#

Anyone here will be free to steal it

north holly
#

to make it as hard as possible to port

dusky glade
north holly
#

but I'll also make it public domain trl

dusky glade
winter orbit
#

Remember someone here made a storport Imlp

#

WDDM is doable

north holly
winter orbit
north holly
#

or implementation

#

whatever it's called

winter orbit
#

He’s getting WDDM

mortal yoke
#

the drivers are funny tho, like you need the shared info page so unless you are actually trying to be windows compatible it might be a little weird

dusky glade
#

shared info page mentioned

mortal yoke
#

well ig its its not that bad as long as you just don't have anything else at that address like I think linux has something in there

dusky glade
#

going back to sleep now

north holly
#

now I really gotta go fix fork

dusky glade
north holly
dusky glade
north holly
#

you complain about sleep schedule

#

you continue to sleep at 5 pm

dusky glade
#

b-b-b--b-but

#

im sleepy

mortal yoke
#

the way to fix it is to not sleep in the middle of a day

dusky glade
north holly
dusky glade
#

ugh fine ill stay awake

north holly
#

can't wait until nyaux gets fork and he spends 7 weeks debugging it

fiery turtle
north holly
#

damn it

north holly
dusky glade
mortal yoke
winter orbit
#

I could import memcpy from windows 10 ntoskrnl

#

unleash chaos

north holly
#

time to dive in to Mm_ForkContext

dusky glade
winter orbit
#

who will win

Hobbies OSes or the trillion dollar cooperation who hasn’t given a crap about its os in a decade

gentle peak
fiery turtle
#

only with lto

north holly
#

infy wish me luck

#

I am going to debug fork

fiery turtle
#

gl

dusky glade
#

infy wish me luck, i am going to watch shitty minecraft video

fiery turtle
#

gl

mortal yoke
#

also I implemented timeouts + callstack depth checks in qacpi, changed op regions to actually map memory/io instead of implicitly needing the os to do it and now I am trying to debug Load lol

mortal yoke
#

the timeout/recursion related yes

fiery turtle
#

nice

mortal yoke
#

the loads don't because idk, there are some weird things with it including leaks

jaunty fox
#

it may well do have something

mortal yoke
calm latch
#

One one of two cloned threads works trl

frank canopy
winter orbit
#

yes

#

but that requires me patching a binary

#

since ACPI tables are linked in loaderblock

frank canopy
#

ah ok yeah

thorny orbit
#

if i find bgrt table with uacpi on bios systems, if result will be null ?

#

oh nvm

fiery turtle
#

its unrelated to uacpi, depends on your firmware

#

if a table is not present on the system uacpi will return STATUS_NOT_FOUND

thorny orbit
mortal yoke
#

maybe there is just no BGRT on that system?

fiery turtle
#

show logs

thorny orbit
thorny orbit
#

in this list bgrt is exists

fiery turtle
#

any other logs?

thorny orbit
#

fiery turtle
#

gonna go out on a limb and say its a skill issue on your part

#

barely any information besides "it no work"

#

show code or logs

thorny orbit
fiery turtle
#

show code

thorny orbit
#

wait

fiery turtle
#

also any chance your memcmp is fucked?

thorny orbit
#
    earlyAcpiInit(); // uacpi_initialize(0);
    printf("Early ACPI Initializied\n");
    uacpi_table bgrt_pointer;
    uacpi_status ret = uacpi_table_find_by_signature("BGRT",&bgrt_pointer);
    if(ret != UACPI_STATUS_OK) {
        printf("BGRT Table doenst present by your firmware (%d)\n",ret);
    } else {
        bgrt_table* bgrt = (bgrt_table*)bgrt_pointer.virt_addr;
        printf("0x%p\n",bgrt->image_address);
    }
thorny orbit
fiery turtle
#

i mean a github page or something

#

this is not enough to say anything lol

thorny orbit
#

okay sir i'll commit

#

nwo

fiery turtle
thorny orbit
#

also isnt uacpi have own memcmp

fiery turtle
#

if u didnt override it, yes

thorny orbit
fiery turtle
#

you literally copied the entire uacpi source? 💀

#

which commit is it from at least

fiery turtle
#

git submodule

thorny orbit
fiery turtle
#
void earlyAcpiInit() {
    early = 1;
    uacpi_initialize(0);
}

U dont check for errors here

thorny orbit
fiery turtle
#
void *uacpi_kernel_map(uacpi_phys_addr addr, uacpi_size len) {
    uint64_t aligned_phys = ALIGNPAGEDOWN(addr);
    uint64_t aligned_virt = (uint64_t)phys2Virt(addr);
    for(uint64_t i = aligned_phys;i < aligned_phys + len;i+= PAGE_SIZE) {
        pagingMap(phys2Virt(pagingGetKernel()),i,(uint64_t)phys2Virt(i),PTE_PRESENT | PTE_WRITABLE);
    }
    return (void*)aligned_virt;
}
#

this is wrong

thorny orbit
#

in code

#

i know

#

i dont know why git dont overwrited it

fiery turtle
#

what did u change it to

thorny orbit
# fiery turtle what did u change it to
void *uacpi_kernel_map(uacpi_phys_addr addr, uacpi_size len) {
    uint64_t aligned_phys = ALIGNPAGEDOWN(addr);
    for(uint64_t i = aligned_phys;i < aligned_phys + len;i+= PAGE_SIZE) {
        pagingMap(phys2Virt(pagingGetKernel()),i,(uint64_t)phys2Virt(i),PTE_PRESENT | PTE_WRITABLE);
    }
    return (void*)phys2Virt(addr);
}
fiery turtle
#

what does phys2virt do

thorny orbit
#

phys + hhdm

#

and returns pointer to uint64_t*

fiery turtle
#

did u forget to ctrl+s?

north holly
#

alt+f4

thorny orbit
fiery turtle
#

im afraid its your allocator bug

#
// its most lazy alloc in the world
void* easy_uacpi_alloc(uint64_t size) {
    if(!ptr) {
        ptr = (uint64_t)pmmVBigAlloc(2048 * 2);
    }
    ptr += size;
    return (void*)ptr;
}

also wtf

#

4096 bytes is not enough

thorny orbit
fiery turtle
#

this returns misaligned addresses

thorny orbit
#

you dont saw upper message ???

thorny orbit
fiery turtle
#

u cant just ptr += size

#

u have to align the size up to at least 16

#

or 8

thorny orbit
#

ok

fiery turtle
#

anyway as a quick fix for u

#

u can change this to like 128

#

then it wont use your buggy allocator for table storage

thorny orbit
fiery turtle
#

uhh

#

i guess

thorny orbit
#

and MAYBE i am shit itself

fiery turtle
#

i literally told u how to fix it

thorny orbit
fiery turtle
#

avoid goose allocator at all costs

thorny orbit
#

my allocator is best in the world

fiery turtle
#

also for just tables u can use uacpi_setup_early_table_access

thorny orbit
#

i'll go to slep because it 11 pm for me

fiery turtle
#

gn

mortal yoke
#

I am starting to hate Load 💀 like I don't understand how some namespace nodes sometimes randomly get removed from the root node's children when I don't ever remove anything from there and in some of the other tests I get use after free because some frame after the load frame somehow uses a buffer allocated specifically for the load frame where the table is copied to (that gets freed when the load frame is destroyed)

fiery turtle
#

lmfao 💀

#

obos curse reached qacpi

north holly
#

I swear every time someone fixes their obos curse

#

it pops up somewhere else

#

3:08 PM
9 minutes later: memory corruption somewhere else

calm latch
#

It's not fixed, it's sent to obos

mortal yoke
#

oh right I can't just free the aml like that when the load exits 💀 then all the methods that it added are full of garbage

fiery turtle
#

u should append the tables to the table list yeah

#

and also give the os the ability to override or deny this Load

fiery turtle
#

what is ACPICA maintainer cooking LULW

jaunty fox
#

then all of a sudden, he found himself in love with the device tree instead

#

he has repented of acpi

fiery turtle
#

lmao

calm latch
#

was he released from the corvette thing?

#

or does ACPICA have different maintainer now?

fiery turtle
#

yes he was released

#

he merged my pr not so long ago

hallow marten
vagrant hull
hallow marten
#

lmao

fiery turtle
#

yeah there was a reddit article about it

#

at first i didnt even believe it was him when fadanoid posted it

#

like what are the odds

vagrant hull
#

infy when are you gonna smash a corvette?

fiery turtle
#

when I buy one

calm latch
#

I would imagine those are close to non-existent outside of US

fiery turtle
#

then never ig sad

calm latch
fiery turtle
#

worked for mr beast views farming

calm latch
#

where's the fun in not being chased by the law enforcement

kind mantle
#

Going from the virgin x86_64 acpica to the chad RISC-V chad

fiery turtle
#

most properly BIOS-patched AML blob

#

it's approximately 660k lines of Noops

thorny orbit
leaden fox
fiery turtle
fiery turtle
#

fun fact, this is the hardest (in terms of mental capacity needed to understand whats going on) function in the entire uACPI code base:

static void bit_copy(struct bit_span *dst, struct bit_span *src)
{
    uacpi_u8 src_shift, dst_shift, bits = 0;
    uacpi_u16 dst_mask;
    uacpi_u8 *dst_ptr, *src_ptr;
    uacpi_u64 dst_count, src_count;

    dst_ptr = dst->data + (dst->index / 8);
    src_ptr = src->data + (src->index / 8);

    dst_count = dst->length;
    dst_shift = dst->index & 7;

    src_count = src->length;
    src_shift = src->index & 7;

    while (dst_count)
    {
        bits = 0;

        if (src_count) {
            bits = *src_ptr >> src_shift;

            if (src_shift && src_count > (uacpi_u32)(8 - src_shift))
                bits |= *(src_ptr + 1) << (8 - src_shift);

            if (src_count < 8) {
                bits &= (1 << src_count) - 1;
                src_count = 0;
            } else {
                src_count -= 8;
                src_ptr++;
            }
        }

        dst_mask = (dst_count < 8 ? (1 << dst_count) - 1 : 0xFF) << dst_shift;
        *dst_ptr = (*dst_ptr & ~dst_mask) | ((bits << dst_shift) & dst_mask);

        if (dst_shift && dst_count > (uacpi_u32)(8 - dst_shift)) {
            dst_mask >>= 8;
            *(dst_ptr + 1) &= ~dst_mask;
            *(dst_ptr + 1) |= (bits >> (8 - dst_shift)) & dst_mask;
        }

        dst_count = dst_count > 8 ? dst_count - 8 : 0;
        ++dst_ptr;
    }
}
#

And I didn't write it either, it was contributed by a member from the cherno server

#

It's used for accessing misaligned fields

north holly
#

Isn't that the shit you did in GAS reads

#

And writes

#

Because I almost had a stroke reading that

fiery turtle
#

its not used for GAS but for actual AML fields

fiery turtle
fiery turtle
mortal yoke
north holly
fiery turtle
#

tdb yeah

fiery turtle
#

do u pass the ACPICA buffer field tests?

mortal yoke
#

I don't think I have tried, unless they are the generated buffer tests that you also have?

fiery turtle
#

nah i built them manually from the acpica repo

mortal yoke
#

are you supposed to invoke some specific method in that too?

fiery turtle
#

MAIN

mortal yoke
#

ah so its the same

fiery turtle
#

yeah

#

i even submitted a patch to fix NT compatibility in these tests

#

so they work perfectly in uacpi

#
❯ /mnt/d/uacpi/tests/runner/build-linux-64bits/test-runner bfield.aml --expect int 0
[uACPI][INFO] RSDP 0x00007FFDD7ACF830 00000024 v02 (uOEMID)
[uACPI][INFO] XSDT 0x0000604000001090 0000002C v02 (Intel  uTESTTBL)
[uACPI][INFO] DSDT 0x000062B000000200 000068A8 v02 (Intel  Many    )
[uACPI][INFO] FACP 0x00006120000004C0 00000114 v06 (uOEMID uTESTTBL)
[uACPI][INFO] FACS 0x0000606000000320 00000040
[uACPI][INFO] SSDT 0x0000000000000000 00000055 v01 (uTEST  RUNRIDTB)
[uACPI][TRACE] load of 'DSDT' (OEM ID 'Intel ' OEM Table ID 'Many    ')
[uACPI][TRACE] load of 'SSDT' (OEM ID 'uTEST ' OEM Table ID 'RUNRIDTB')
[uACPI][TRACE] [AML DEBUG] String => "TestRunner ID SSDT loaded!"
[uACPI][INFO] successfully loaded 2 AML blobs, 1395 ops in 12ms (avg 108953/s)
[uACPI][TRACE] initialized GPE block _GPE[0->128], 0 AML handlers (IRQ 0)
[uACPI][TRACE] initialized GPE block _GPE[128->256], 0 AML handlers (IRQ 0)
[uACPI][TRACE] fixed event 0 enabled successfully
[uACPI][TRACE] activated all 'EmbeddedControl' opregions controlled by '\   ', 0 _REG() calls (0 errors)
got a GPE
[uACPI][TRACE] activated all 'PCI_Config' opregions controlled by '\   ', 0 _REG() calls (0 errors)
[uACPI][INFO] namespace initialization done in 0ms: 0 devices, 0 thermal zones
[uACPI][TRACE] _STA calls: 0 (0 errors), _INI calls: 0 (0 errors)
[uACPI][TRACE] read from [\STRT.HDR_] (1 bytes) TableData[0x000062B000000208] = 0x2
[uACPI][TRACE] [AML DEBUG] String => "64-bit mode"
[uACPI][TRACE] [AML DEBUG] String => "Release of parent ACPICA code 0x1"
[uACPI][TRACE] [AML DEBUG] String => "Release of ASLTS test suite  0x16"
[uACPI][TRACE] [AML DEBUG] String => "Settings of ASLTS test suite 0x5"
[uACPI][TRACE] [AML DEBUG] String => "TEST (functional), Buffer Field"
[uACPI][TRACE] [AML DEBUG] String => "m211 test started"
[uACPI][TRACE] [AML DEBUG] String => "TEST: m211, Create 1-Bit Buffer Field:"
[uACPI][TRACE] [AML DEBUG] String => ":CTST:functional:bfield:m211:PASS:"
[uACPI][TRACE] [AML DEBUG] String => "m213 test started"
[uACPI][TRACE] [AML DEBUG] String => "TEST: m213, Create 8-Bit Buffer Field:"
[uACPI][TRACE] [AML DEBUG] String => ":CTST:functional:bfield:m213:PASS:"
[uACPI][TRACE] [AML DEBUG] String => "m215 test started"
[uACPI][TRACE] [AML DEBUG] String => "TEST: m215, Create 16-Bit Buffer Field:"
[uACPI][TRACE] [AML DEBUG] String => ":CTST:functional:bfield:m215:PASS:"
[uACPI][TRACE] [AML DEBUG] String => "m217 test started"
[uACPI][TRACE] [AML DEBUG] String => "TEST: m217, Create 32-Bit Buffer Field:"
[uACPI][TRACE] [AML DEBUG] String => ":CTST:functional:bfield:m217:PASS:"
[uACPI][TRACE] [AML DEBUG] String => "m219 test started"
[uACPI][TRACE] [AML DEBUG] String => "TEST: m219, Create 64-Bit Buffer Field:"
[uACPI][TRACE] [AML DEBUG] String => ":CTST:functional:bfield:m219:PASS:"
[uACPI][TRACE] [AML DEBUG] String => "m21d test started"
[uACPI][TRACE] [AML DEBUG] String => "TEST: m21d, Create Arbitrary Length Buffer Field:"
[uACPI][TRACE] [AML DEBUG] String => ":CTST:functional:bfield:m21d:PASS:"
[uACPI][TRACE] [AML DEBUG] String => "Run time (in seconds): 0x1"
[uACPI][TRACE] [AML DEBUG] String => "The total number of exceptions handled: 0x0"
[uACPI][TRACE] [AML DEBUG] String => "========= ROOT METHODS SUMMARY (max 600):"
[uACPI][TRACE] [AML DEBUG] String => ":STST:functional:bfield:m211:PASS:"
[uACPI][TRACE] [AML DEBUG] String => ":STST:functional:bfield:m213:PASS:"
[uACPI][TRACE] [AML DEBUG] String => ":STST:functional:bfield:m215:PASS:"
[uACPI][TRACE] [AML DEBUG] String => ":STST:functional:bfield:m217:PASS:"
[uACPI][TRACE] [AML DEBUG] String => ":STST:functional:bfield:m219:PASS:"
[uACPI][TRACE] [AML DEBUG] String => ":STST:functional:bfield:m21d:PASS:"
[uACPI][TRACE] [AML DEBUG] String => "========= END."
[uACPI][TRACE] [AML DEBUG] String => "TEST ACPICA: 64-bit : PASS"
[uACPI][TRACE] fixed event 0 disabled successfully

This is what I get

north holly
#

Lol

fiery turtle
north holly
#

LAI doesn't exist anymore

mortal yoke
# fiery turtle ``` ❯ /mnt/d/uacpi/tests/runner/build-linux-64bits/test-runner bfield.aml --expe...
qacpi warning: Ignoring DataRegion
qacpi error: Operation Region HDR_ doesn't exist
aml debug: TEST (functional), Buffer Field
aml debug: m211 test started
aml debug: TEST: m211, Create 1-Bit Buffer Field:
aml debug: :CTST:functional:bfield:m211:PASS:
aml debug: m213 test started
aml debug: TEST: m213, Create 8-Bit Buffer Field:
aml debug: :CTST:functional:bfield:m213:PASS:
aml debug: m215 test started
aml debug: TEST: m215, Create 16-Bit Buffer Field:
aml debug: :CTST:functional:bfield:m215:PASS:
aml debug: Run time (in seconds): 0x677afd72
aml debug: The total number of exceptions handled: 0x
aml debug: ========= ROOT METHODS SUMMARY (max 600):
aml debug: :STST:functional:bfield:m211:PASS:
aml debug: :STST:functional:bfield:m213:PASS:
aml debug: :STST:functional:bfield:m215:PASS:
aml debug: ========= END.
aml debug: TEST ACPICA: 32-bit : PASS
``` ![troll](https://cdn.discordapp.com/emojis/796858892985434152.webp?size=128 "troll") I should implement dataregion
north holly
fiery turtle
fiery turtle
#

right?

#

that u must read in multiple accesses

hollow elm
fiery turtle
#

i have lai built actually i can try running it against this test

hollow elm
#

there was an issue with Preserve writes where it would perform extra reads but other than that i think this works

hollow elm
fiery turtle
#
❯ ~/lai_tools/build/laiexec bfield.aml
unexpected opcode in lai_exec_run(), sequence 5B 88 48 44
[1]    19578 IOT instruction (core dumped)  ~/lai_tools/build/laiexec bfield.aml
#

idk

hollow elm
#

no some other person reported a hang on real hw iirc

left orbit
#

wtf is an iot instruction

mortal yoke
fiery turtle
#

hmm lemme comment that out

mortal yoke
fiery turtle
hollow elm
#

you made the issue and i made a pr fixing it and i asked the person who made a second issue to see if the pr fixes it

#

and they ghosted me

#

so the issue remains unfixed :^)