#OBOS (not vibecoded)

1 messages · Page 29 of 1

thick jolt
#

bru

flint idol
#

or should I just save the timers I use

thick jolt
#

ignore

real pecan
thick jolt
#

there will be suspend

flint idol
#

if that happens

thick jolt
#

after

#

it will

flint idol
#

I will be muting that thread

thick jolt
#

wait seriously

flint idol
#

because of the amount of activity of nyauxmaster complaining

#

about wake not working

thick jolt
#

😭 💀

flint idol
#

and wake crashing

#

and whatnot

real pecan
#

Yeah that one is going to be tough

#

No one can spoonfeed that

thick jolt
#

bro

#

i dont get spoonfeed

#

stop saying that

#

its not even funny seriously

real pecan
#

Jkjk

thick jolt
#

okay

flint idol
#

implementing suspend is going into the wild west of acpi

#

the actual power management part

#

it's no longer fun and games when you implement suspend

thick jolt
#

it will def be pain but yk ill pull through\

flint idol
#

you won't

thick jolt
#

i will because ill do something u wont

flint idol
#

I already have it..?

thick jolt
#

work on other aspects of the kernel while suspend isnt working

#

then like keep debugging suspend

#

but still working on other things

flint idol
thick jolt
#

yes will be very scary

flint idol
#

do you know what a power resource is?
that's what I thought, no

thick jolt
#

💀

real pecan
thick jolt
#

ummm actually i know what that is

#

🤓

flint idol
#

_ON, _OFF, _PSW, _S3W, _S3D, _PRW, _DSW

#

those are the methods I remember having to evaluate to setup wake gpes

#

also _PSn, _PRn with n being a D state

#

then I needed an entire smp trampoline just to wake up to a bare minimum long mode state

#

along with some 50 lines of x86_64-specific wake code

#

to get stuff running again

#

which will be increasing since I'm adding HPET restore code

#

as well as another ~50 lines of x86_64 specific code to wake the other CPUs again

thick jolt
#

for restoring the hpet do u just need to enable the main counter again?

flint idol
#

no

thick jolt
#

okay then what do u need to do

flint idol
#

you need to save everything

#

about it

thick jolt
#

ah okay

flint idol
#

at least everything you need

#

ig you can skip init of some timers

#

since it has multiple comparators

flint idol
#

which needed a REVAMP of my pci interface

#

I also needed to add suspend/wake callbacks to drivers

#

just for it to still be partially incomplete

#

because I have no framebuffer

#

if that hasn't scared you off, idk what will

#

wait

#

how would I restore const HPET fields

#

maybe I just don't

real pecan
#

Yes

flint idol
#

so I need to restore:

  • HPET.generalConfig
  • HPET.mainCounterValue
  • HPET.timer0
  • any other HPET comparators I use
#

I also don't restore IOAPIC state

#

silly me

real pecan
#

Who needs that chad

flint idol
#

me nooo

real pecan
#

Does it work with hpet restoration?

flint idol
#

nah

#

I need IOAPIC for GPEs

#

so I will add restore code for that soon™️

#

and you should probably go to sleep

real pecan
#

Does it hang still

flint idol
#

it still hangs

real pecan
#

Strange

#

Anyways yeah continue tmrw

flint idol
#

yup

#

can't believe I'm going to sleep at the same time as infy (he's 8 hours ahead of my timezone)

#

infy challenge: have sleep schedule, challenge level: impossible

real pecan
#

Lol

flint idol
#

but hey who needs sleep when you have osdev

real pecan
#

Thought u were in Europe

flint idol
#

no I'm in canada

real pecan
#

Did you move recently?

flint idol
#

no I've been in canada for like

#

my entire life

real pecan
#

Ah

#

Lol

#

Gn then

flint idol
#

gn

#

it's like -10 degrees outside

#

quite warm

real pecan
flint idol
#

fair

#

when I was on vacation in uae, I would go to sleep at 3 am

#

in saudi I had a normal-ish sleep schedule

#

mainly in mecca since I think I wanted to be able to get up for the dawn prayer at the sacred mosque

#

but alas, I was only able to make it once

#

another time I woke while the prayer was happening

#

so I used my phone to record the reciter

real pecan
#

Oh well

flint idol
#

yeah

#

gn now ig

real pecan
#

Yup

flint idol
thick jolt
#

hi omar

#

#1230349543623757845 rn 😡

flint idol
#

Hai

flint idol
#

time to add I/O APIC restoration code

weak kestrel
flint idol
#

soon™️

weak kestrel
#

how much do you have left?

flint idol
#

I need to write I/O APIC restoration code

#

and fix this bug with wake

#

on my laptop

flint idol
#

TODO: Rewrite I/O APIC code to not use bitfields

flint idol
#

nvm, that's for S4 (hibernate) only

real pecan
flint idol
#

ok

real pecan
#
/*
 * The ACPI specification wants us to save NVS memory regions during hibernation
 * and to restore them during the subsequent resume.  Windows does that also for
 * suspend to RAM.  However, it is known that this mechanism does not work on
 * all machines, so we allow the user to disable it with the help of the
 * 'acpi_sleep=nonvs' kernel command line option.
 */
static bool nvs_nosave;

void __init acpi_nvs_nosave(void)
{
    nvs_nosave = true;
}

#
/*
 * The ACPI specification wants us to save NVS memory regions during hibernation
 * but says nothing about saving NVS during S3.  Not all versions of Windows
 * save NVS on S3 suspend either, and it is clear that not all systems need
 * NVS to be saved at S3 time.  To improve suspend/resume time, allow the
 * user to disable saving NVS on S3 if their system does not require it, but
 * continue to save/restore NVS for S4 as specified.
 */
static bool nvs_nosave_s3;
#

kinda annoying

#

but thats suspend for u

flint idol
#

yeah

#

I'll add a command line option because linux does
no-nvs-save-suspend

#

or something like that

real pecan
#

ye

flint idol
#

linux calls it nvs-nosave-s3

#

so I'm copying that into obos

#

and I might as well also add a config option for it

#
option (OBOS_NVS_SAVE_S3 "Enable compile-time support for saving NVS before S3" ON)
real pecan
#

nice

flint idol
#
struct acpi_nvs {
    void* saved_region;
    uintptr_t phys;
    size_t size;
};
struct acpi_nvs* saved_nvs;```
#

@real pecan ULTRA_MEMORY_TYPE_NVS is acpi nvs right? not some weird uefi thing

#

it seems like it, but I'm just making sure

real pecan
#

ye

flint idol
#

kthx

#

are there any PCs where there are multiple NVS regions?

#

surely there are, right?

real pecan
#

probably

thick jolt
#

i believe so but i may be wrong

flint idol
#

Error 503 Backend fetch failed

#

elixir died

thick jolt
#

rip

real pecan
#

its been dead for multiple days

#

it takes 10 refreshes to load anything

flint idol
#

well I always got github

thick jolt
flint idol
#

linux treats NVS ram as IO memory

#

calls acpi_os_get_iomem on it

#

to get its address

#

then memcpy's that in the buffer it allocated

#

for each nvs region

#

and restore does the same thing, backwards

#

@real pecan what kernel api does uacpi use to timeout loops, get_nanoseconds_since_boot?

#

like aml loops

real pecan
#

i mean what other api could it even use

flint idol
#

idk

#

I will return zero from that in case the hpet is still dead somehow

#

and a loop isn't timing out

#

during _WAK

real pecan
#
/*
 * Calculate the expiration point for this loop.
 * If a loop is executed past this point, it will get aborted.
 */
block->expiration_point = uacpi_kernel_get_nanoseconds_since_boot();
block->expiration_point +=
    g_uacpi_rt_ctx.loop_timeout_seconds * UACPI_NANOSECONDS_PER_SEC;
flint idol
#

or maybe not zero

#

uhh

#

1000000000

#

no

#

UINT64_MAX

real pecan
#

it doesnt matter which constant u return

#

since its a constant

flint idol
#

no, because UINT64_MAX+any number would overflow

real pecan
#

and

flint idol
#

but then that number is < UINT64_MAX

#

so the loop times out

#

immediately

real pecan
#

why would the loop timeout

#

max + any number is some number

#

if u do this calculation again u get the same number

#

or wait

#

yeah ur right

flint idol
#
[uACPI][INFO]: successfully loaded 1 AML blob, 1726 ops in 0ms (avg 1726000000000/s)
#

woo

real pecan
#

but this will make it so any while that must run at least twice will not run at all

flint idol
#

take that mammogram

real pecan
#

or will run once i guess

#

so this might break something

flint idol
#

I only set the loop timeout before calling wake_from_sleep

#

or whatever the function was called

#
uacpi_context_set_loop_timeout(3);
uacpi_wake_from_sleep_state(UACPI_SLEEP_STATE_S3);```
#

I assume the default is zero?

#

no it's 30

real pecan
#

zero so it insta aborts everything yes LULW

#

do u do full nvs restore now?

flint idol
#

yes

#
    if (!OBOS_GetOPTF("nvs-nosave-s3"))
    {
        // Save ACPI NVS regions.
        // Why? Some versions of windows do, so I guess we have to :)

        // Read the memory map.
        uintptr_t index = 0;
        for (obos_pmem_map_entry* entry = MmS_GetFirstPMemMapEntry(&index); entry; )
        {
            if (entry->type == ULTRA_MEMORY_TYPE_NVS)
                saved_nvs_count++;

            entry = MmS_GetNextPMemMapEntry(entry, &index);
        }

        saved_nvs = OBOS_NonPagedPoolAllocator->ZeroAllocate(OBOS_NonPagedPoolAllocator, saved_nvs_count, sizeof(struct acpi_nvs), nullptr);

        index = 0;
        size_t nvs_index = 0;
        for (obos_pmem_map_entry* entry = MmS_GetFirstPMemMapEntry(&index); entry; )
        {
            if (entry->type == ULTRA_MEMORY_TYPE_NVS)
            {
                saved_nvs[nvs_index].region_address = Arch_MapToHHDM(entry->physical_address);
                saved_nvs[nvs_index].size = entry->size;
                saved_nvs[nvs_index].saved_region = OBOS_NonPagedPoolAllocator->Allocate(OBOS_NonPagedPoolAllocator,
                                                                                         saved_nvs[nvs_index].size,
                                                                                         nullptr);
                memcpy(saved_nvs[nvs_index].saved_region, saved_nvs[nvs_index].region_address, saved_nvs[nvs_index].size);
                nvs_index++;
            }

            entry = MmS_GetNextPMemMapEntry(entry, &index);
        }
    }```
#

that's to save

real pecan
#

have u tested this on real hw?

flint idol
#

Yes, I have no idea if it works

real pecan
#

wdym

flint idol
#

I tested it

#

but idk if it does its job correctly

#

it doesn't triple fault tho

real pecan
#

but i guess it doesnt help with hangs?

flint idol
#

nope

real pecan
#

its probably nothing complex like that

#

some simple bug

#

maybe obos using ecam to restore ecam type of bug

flint idol
#

that was seabios

real pecan
#

MTRRs are restored at this point right?

flint idol
#

yes

real pecan
#

I said type of bug not literal bug lol

flint idol
#

what I have restored at that point:

  • tss/gdt/idt
  • LAPIC
  • caching stuff (MTTRs/PAT)
  • IOAPIC
  • NVS
  • HPET
  • SMP is restored
  • scheduler is alive
  • LAPIC timer is alive
#

maybe there is some obscure device I forgot about

#

that I need to restore

real pecan
#

trace logs would really help

#

but alas

flint idol
#

yeah

#

what I become the AML interpreter

#

I read _WAK until i see something fishy

real pecan
#

u can try

#

it does way too much stuff

flint idol
#

stores to regions should never do anything but write to memory/io, right?

#

e.g., \_SB.PCI0.GFX0.CLID = 0x80000000

#

that would only ever translate to uacpi writing to that memory/ioport, right?

real pecan
#

possibly locking the global firmware lock

#

yes

flint idol
#

maybe it would help to use uacpi before thread safety

#

if this truly is a deadlock

real pecan
#

yeah

#

u can try an older uacpi

#

but the glock was supported before thread safety

real pecan
#

or i mean

#

dump 3

flint idol
#

dump 3

#

laptop dump in _WAK

real pecan
#
OperationRegion (IGDM, SystemMemory, ASLB, 0x2000)
Field (IGDM, AnyAcc, NoLock, Preserve)

Its a non-locked SystemMemory opregion

#

so its literally a volatile r/w

flint idol
#

anyway, I'm going to send my uacpi version back in time

real pecan
#

yeah

flint idol
#

to before thread-safety-p2

#

or even before p1

#

if possible

real pecan
#

oh btw

flint idol
#

ye

real pecan
#

it checks ECON

#

maybe disable your ec driver and retry

#

could be hanging in that

flint idol
#

k

real pecan
#

although

#

thats just a field in NVS lol

#

its not set by anyone

flint idol
#

wAIT

#

wtf

#

not wtf

#

that fixed it

#

guess my EC driver is bad

real pecan
#

yeah

#

nvm there is an ec opregion

#

and it does ECOK = 1

flint idol
#

cok meme

real pecan
#

so i geuss that updates NVS via SMM

#

so ur ec driver is just garbo

flint idol
real pecan
#

your ec also has queries

flint idol
flint idol
real pecan
#
            Method (_Q27, 0, NotSerialized)  // _Qxx: EC Query, xx=0x00-0xFF
            {
                P80H = 0x27
                Notify (ACAD, 0x80) // Status Change
                Notify (BAT1, 0x80) // Status Change
            }
#

u should get events for power plug/unplug

#

u support events right?

flint idol
#

never register any

real pecan
#

no like

#

u support running EC queries

#

right?

flint idol
#
void onECQuery(uacpi_handle hnd)
{
    // Evaluate whatever the EC wants us to evaluate.
    uint8_t idx = (uint8_t)(uintptr_t)hnd;
    char method[] = { '_', 'Q', 0,0,0 };
    snprintf(method+2, 3, "%02x", idx);
    uacpi_eval_simple(ec_node, method, nullptr);
    uacpi_finish_handling_gpe(ec_gpe_node, ec_gpe_idx);
}```
#

yes

real pecan
#

do u get any?

#

on that laptop

flint idol
#

idk maybe

real pecan
#

its 02X not x

flint idol
#

thx

real pecan
#

because u would see it in logs

#

so yeah fix your ec

flint idol
#
static uint8_t ec_read_reg(struct acpi_gas* reg)
{
    uint64_t val = 0;
    // Wait until OBF goes to one.
    do {
        uacpi_gas_read(&ec_control_register, &val);
    } while (!(val & EC_OBF));
    // Read the register.
    uacpi_gas_read(reg, &val);
    return val;
}

static void ec_write_reg(struct acpi_gas* reg, uint8_t what)
{
    uint64_t val = 0;
    // Wait until IBF goes to zero.
    do {
        uacpi_gas_read(&ec_control_register, &val);
    } while (val & EC_IBF);

    // Write the register.
    uacpi_gas_write(reg, what);
}

static uint8_t ec_read(uint8_t offset)
{
    ec_write_reg(&ec_control_register, BD_EC);
    ec_write_reg(&ec_data_register, offset);
    return ec_read_reg(&ec_data_register);
}

static uacpi_status ec_write(uint8_t offset, uint8_t value)
{
    ec_write_reg(&ec_control_register, BD_EC);
    ec_write_reg(&ec_data_register, offset);
    ec_write_reg(&ec_data_register, value);
    return UACPI_STATUS_OK;
}```
#

this looks sane to me

real pecan
#

no idea

flint idol
#

this part

#

oops

#

I write burst disable to command

#

instead of ec read/ec write

#

silly me

flint idol
#

idk why

#

but enabling burst in the ec driver

#

doesn't work

flint idol
#

@real pecan what does UACPI_InternalOpUnresolvedNameString_L do

#

because obos hangs on it during EC init

#

at least taht's the last thing logged before a hang

real pecan
#

probably read from a field that starts with an L

flint idol
#

hmm

real pecan
#

yeah

#

LDS0

#
Method (_REG, 2, NotSerialized)  // _REG: Region Availability
{
    If (((Arg0 == 0x03) && (Arg1 == One)))
    {
        ECOK = One
        If (ECOK)
        {
            If (LDS0)
            {
#

this is where u hang

flint idol
#

infy has cameras in my house confirmed

real pecan
#

no

#

im in your walls

flint idol
#

it hung in INVOKE_HANDLER

flint idol
#

can you come help me debug

#

then

real pecan
#

invoke handler just calls into your ec_read

real pecan
flint idol
#

in my walls?

real pecan
#

yes

#

i have the entire house to watch

flint idol
#

understandable

thick jolt
flint idol
#

it hangs waiting for EC_OBF

short mortar
#

uint64_t?

flint idol
#

yeah what about it

short mortar
#

Registers are 8 bits

flint idol
#

yeah

#

but gas_read takes a uint64_t*

#

also I just found the bug

#

I was doing reg = uacpi_gas_read(reg, &val)

#

whoops

#

ec driver still hangs on wake from suspend

flint idol
#

so I worked around that

real pecan
#

lol maybe fix the driver instead

flint idol
#

could be broke firmware

real pecan
#

x to doubt

#

but check linux quirk table

flint idol
#

sure

real pecan
#

do u get events now at least

flint idol
#

unless

#

these look like lid events

#

at one point I get an ec event

#

which fails for reasons

#

fuck

#

why isn't my laptop booting

#

nvm

flint idol
#

according to my logs

#

linux' ec driver makes no sense

white mulch
#

at least you are not getting 5 random power button ec querys when you start your kernel like I do on my laptop troll

flint idol
#

at least you don't get an ec query every second on your laptop

#

after fixing a deadlock bug with ec events

#

(me right now)

white mulch
white mulch
flint idol
#

and each time it

#

is spurious

#

i.e., index=0

#

hmm

#

oopsie

#

still not fixed

#

but I did find a bug

#

unless...

real pecan
white mulch
#

I am not sure, I haven't booted any uacpi kernel on it enough to be able to tell as it only happens sometimes

real pecan
white mulch
#

I can try to boot managarm on it for a few tens of times sometime to see

flint idol
#

damn the EC

real pecan
#

or pmos

flint idol
#

fnuy field name

weary hound
#

cunter

#

CNTR and CTR was too hard

flint idol
#

maybe it was first named COUNT

#

but preprocessed to CUNT

#

automod flagged a message sent by oberrow

weary hound
#

i fail to see how that would happen

#

COUN would be more likely in that case

flint idol
#

preprocessor that removes the 2nd letter of a name until it becomes four letters

#

@short mortar did your ec driver not give events?

#

and if so what wsa the problem

short mortar
#

Or we can just assume it was intentional

flint idol
#

maybe it's the same problem for me

short mortar
flint idol
#

the only events I am getting are spurious

short mortar
#

And then it worked fine

flint idol
short mortar
#

I'll add framebuffer to kernel

thick jolt
#

wait this is better

flint idol
#

ok

thick jolt
#

sorry

flint idol
#

np

thick jolt
#

can u tell me what i did wrong so i know not to do in future

flint idol
#

you did nothing wrong

thick jolt
#

oh okay 😭

flint idol
#

otherwise I wouldn't be saying "np"

#

:)

thick jolt
#

😭 😭

#

fair

flint idol
#

(if it were a problem, I'd say so)

#

I HATE ACPI

#

I HATE ACPI

#

I HATE ACPI

#

I HATE ACPI

#

I HATE ACPI

quaint rivetBOT
#
Anti-spam Message

Possible spam detected for user: oberrow. Please contact a moderator to be unmuted.

thick jolt
#

@white mulch

#

@real pecan

flint idol
#

thanks

white mulch
#

np

flint idol
#

wth

#

why is the ec driver giving me 0x00 after enabling burst

#

seems pretty fishy

#

OSPM driver writes the Burst Enable Embedded Controller, BE_EC (0x82) command byte and then the Embedded Controller will prepare to enter the Burst mode. This includes processing any routine activities such that it should be able to remain dedicated to OSPM interface for ~ 1 microsecond.

#
    poll_ibf(device);
    write_reg(&device->control, BE_EC);
    poll_obf(device);
    uint8_t status = read_reg(&device->data);
    if (status != BURST_ACK)
        printf("Failed to enable EC burst mode. Out: %hhx\n", status);

pmOS' code

#
    ec_write_reg(&ec_control_register, BE_EC);
    uint8_t response = ec_read_reg(&ec_data_register);
    if (response != BURST_ACK)
    {
        OBOS_Warning("ACPI: Burst not acknoledged by EC, ignoring. Expected: 0x%02x, got 0x%02x\n", BURST_ACK, response);
        return false;
    }
    return true;```
#

obos' code

#

ec_write_reg/ec_read_reg poll ibf/obf

short mortar
#

You need to poll obf before reading anything

flint idol
#

I do

#

it's implicit

short mortar
#

Oh

flint idol
#

@real pecan when uacpi reads from a gas, the raw io port read returns 0x801a56a0, among other values, yet the actual gas read returns 0x00, do you have any idea how this could be?

real pecan
#

not sure what that means

flint idol
#

so basically

#

my ec driver reads from the gas

#

when uacpi actually reads the io port, the value returned is 0x801a56a0

#

and some other values occasionally

#

but the value given to me by uacpi is 0x00

#

the gas format is:
register bit offset: 0
register bit width: 8
access size: 0
address: 0x62

real pecan
#

how can this be the value returned if port width is 1 byte

flint idol
#

idk

#

wait I'm stupid

#

I was printing a pointer

real pecan
#

no like what are u reading even

#

lmao

flint idol
real pecan
#

i meant the fact that its a 4 byte value

flint idol
#

it isn't, I was printing a pointer by accident

real pecan
#

💀

flint idol
#

uacpi gets 0xb2 from the raw io read

#

but my ec driver gets 0x00

real pecan
#

show code

flint idol
#
static uint8_t ec_read_reg(struct acpi_gas* reg)
{
    uint64_t val = 0;
    // Wait until OBF goes to one.
    ec_wait_for_bit(&ec_control_register, EC_OBF, EC_OBF);
    // Read the register.
    uacpi_gas_read(reg, &val);
    return val;
}```
#

reg = ec control register

real pecan
#

check the return status as well

flint idol
real pecan
#

it sounds like its not even initialized

flint idol
#

what isn't?

real pecan
#

val

flint idol
#

it fails

real pecan
#

lmao

flint idol
#

not found

real pecan
#
    if (!gas->address)
        return UACPI_STATUS_NOT_FOUND;
flint idol
#

weird

#

omg I am stupid

#

I was incrementing a variable called current_index in the resource iterate callback

#

to figure out if this is the control register's resource or data register's

#

resource

#

I incremented it

#

before

#

switch (*current_index)

#

upon fixing this bug

#

suspend breaks

#

it hangs before going into S3

#

and

#

I stop getting all those spurious events

real pecan
#

linux disables ec interrupts prior to going into s3

#

i think

#

maybe ur hanging in that

flint idol
#

well it hangs polling IBF

short mortar
#

It has a framebuffer in kernel

flint idol
#

k

#

it logs shit quickly

#

then the screen goes blank

#

with a cursor

#

at the last line

short mortar
#

Can you record what it logs?

short mortar
#

If the screen goes blank then it enters userspace

#

My EC driver might also be hanging...

#

I know what I can try

#

@flint idol

flint idol
#

Sure

real pecan
#

there goes pmos stability LULW

short mortar
#

The kernel did boot it seems

real pecan
#

jkjk

short mortar
#

oberrow laptop's fault KEKW

real pecan
#

linux doesnt seem to have any quirks for ecs that hang on poll or dont respond with acks

#

whats that laptops model

short mortar
#

pmos might hang because of spinlocks skill issue

flint idol
short mortar
#

wdym

#

It's flanterm

flint idol
#

then the rest is a blank screen until a cursor on the last line

short mortar
#

Does it turn off with power button?

flint idol
#

no

#

BUT

#

it does seem to "enter userspace/idle"

#

oh shi

#

it does

#

it takes like 5 seconds

short mortar
#

Yeah it waits for 3 seconds

#

So EC potentially works? lol

#

And framebuffer is fucked

flint idol
#

I need logs from pmOS to help me debug, but alas

short mortar
#

It also logs to serial

flint idol
#

..which I don't have

short mortar
#

yeah

flint idol
#

does it log to xhci halfmemeright

short mortar
#

Your power button is through EC, right?

flint idol
#

think so

short mortar
flint idol
flint idol
short mortar
#

I don't have usb

#

So like in a month

flint idol
#

I think that's a bit too far for me

#

so back to printf debugging I go

short mortar
#

Idk what's going on with my framebuffer

flint idol
#

someone needs to make uUSB

#

why is it hanging nooo

short mortar
#

Could this be wrong?

flint idol
#

lgtm

short mortar
#

If bpp is less than 8

flint idol
#

it isn't

short mortar
#

wtf why would it not work

flint idol
#

microkernel skill issue

short mortar
#

No

flint idol
short mortar
#

microkernel booted

#

It's userspace skill issue

#

Oh right

flint idol
#

it hangs waiting on OBF

#

in obos

short mortar
#

USB serial controllers?

flint idol
#

I guess

short mortar
#

Like I have a couple of those...

flint idol
#

now the screen goes blank

#

but the power button still works

short mortar
#

I've removed kernel framebuffer...

#

Could it be because of how I map framebuffer?

#

No cache

flint idol
#

no

short mortar
#

I can do other thing

#

Disable userspace framebuffer

#

@flint idol

flint idol
#

I get logs

#

from kernel

short mortar
#

What does it print

flint idol
#

cpu x entering userspace/idle

#

three times

#

then a bunch of tasks exit

#

then it stops

short mortar
#

Which tasks exit

short mortar
flint idol
#

wait why is my mmap 282 loc

#

+65 loc to find an avaliable address

#

I wonder if it could help (for profiling purposes) to store how long locks are held in stuff like spinlocks and mutexes

#

and pushlocks

flint idol
#

obos surprisingly doesn't have too much spinlocks

#

29 spinlocks in total

#

18 mutexes

#

or well 16

#

or well

#

maybe a bit less than these numbers because uacpi kernel api

#

2 semaphores

#

2 rw locks

#

and like three event objects

flint idol
#

this field has the time in nanoseconds of how long the lock was last taken

#

as in, the time between acquire and release, in nanoseconds

#

and it's configurable the config option OBOS_ENABLE_LOCK_PROFILING

#

which configures if it is enabled or not, since it has a big perf hit

#

which is visible

flint idol
#

Another day, another gruesome obos debug session

#

I have this crippling fear that I'm gonna remove some wait by accident in the EC driver then accidentally corrupt some proprietary bios state causing the system to hang in the firmware

short mortar
#

#1217009725711847465 message

real pecan
#

yeah its easy to corrupt firmware with a bad ec driver

#

but it fixes itself after power loss

flint idol
#

this shit is so stupid

#

why does it just hang there

#

waiting for OBF

real pecan
#

skill issue

#

do u have locking around EC?

flint idol
#

almost

real pecan
#

because u might get an event at the same time as opregion access

#

i had to fix that for managarm

flint idol
#

I added some locking

#

and now it hangs somewhere later

real pecan
#

lol

flint idol
#

so the read completes then

#

it hangs reading from a gas

#

or well

#

hangs waiting for OBF to become one

short mortar
#

I have locks in EC

#

I need to fix the framebuffer...

flint idol
#

I might know the problem

#

I wait for OBF trying to read the status register

#

in the control register

#

meaning there isn't any data for me to read

#

from any pending commands

short mortar
#

I think you read the control whenever you want

flint idol
#

yeah

#

is it the same with writes?

#

I think so..

short mortar
#

No

flint idol
#

ok

short mortar
#

As I understood it

#

But it doesn't hurt to wait

flint idol
#

it probably does

short mortar
#

No but if the control register isn't buffered the ibf won't be set

#

or obf

#

whichever is host to ec

flint idol
#

OBF is ec->host

#

IBF is host->ec

short mortar
#

But as I understood it, there are 2 registers

#

Host to EC and EC to host

#

When you write to EC, the register is written to and the bit is set

flint idol
#

no, the two registers are EC command/status

#

and EC data

short mortar
#

untill it is processed

real pecan
#

its actually 4 registers

short mortar
real pecan
#

its 2 but virtually split into 4

short mortar
#

Like length 1 buffer

real pecan
#

because reading and writing do completely unrelated things

short mortar
#

Anyway

flint idol
#

fuck

short mortar
#

There is buffer for host to device stuff and there is buffer for device to host stuff

flint idol
#

why didn't my laptop boot

vale nymph
#

Brickes

#

Bricked

flint idol
#

all is fine now

short mortar
#

💀

flint idol
#

yay

#

ec driver is fixed finally I think

vale nymph
#

Ill buy your bricked laptop for 1 dollar

flint idol
#

when I plug in and plug out my laptop I get EC evetns/!111!11!

short mortar
#

what was it?

#

and is power button with events?

flint idol
#

I don't think so

#

I think my laptop uses fixed events for htat

real pecan
#

what about suspend

flint idol
#

it wakes successfully

real pecan
#

damn congrats

flint idol
#

and no longer hangs in the ec driver

real pecan
#

big work

short mortar
#

that's cool

flint idol
#

indeed

short mortar
#

second working uACPI reference EC driver

#

(or third)

flint idol
#

does managarm's driver not work

#

yeah

real pecan
#

third

flint idol
#

good enough for me

real pecan
#

even your nvs restore works i guess

flint idol
#

I guess

#

no way to work

#

I meant

#

no way to know

real pecan
#

are u going to make an article about suspend to s3?

flint idol
#

Yes

real pecan
#

nice

flint idol
#

whoa

#

I get events when I close/open the lid

#

I get occasional Notifys abouts some device with the HID "VPC2004"

#

and even one from an "Ambient Light Sensor"

#

when I remove the battery, I get a Notify

#

@real pecan is there a way to get uacpi to stop spamming Notify warnings without raising the log level > UACPI_LOG_WARN

real pecan
#

install a notify handler to root

flint idol
#

thx

#

time to update uacpi

#

test

#

then push

#

bruh why is SMP so slow in obos

#

probably because of my TLB shootdowns

#

I need to make cancellable syscalls soon

#

TODO™️

#

theoretically, it is as shrimple as lowering the IRQL to PASSIVE

#

instead of DISPATCH

#

then also adding a way to cancel waits

#

which I have half of

#

the half I have is signalling the waiting threads

#

the half I need is getting it to notice that it needs to abort what it's doing

#

when it's awaken

flint idol
#

yeah why did I raise the irql to dispatch in my syscall handlers

#

surely there was a good reason to that?

#

if it don't crash when I remove it

#

then it's fine

#

@real pecan I was trying to see if would get the framebuffer restored by firmware after wake from suspend if I set back my OSI to windows XP, but instead it deadlocks before suspend

#

in uacpi, ofc

#

at least I think in uacpi

#
    uacpi_bulk_configure_interfaces(UACPI_INTERFACE_ACTION_DISABLE, UACPI_INTERFACE_KIND_VENDOR);
    uacpi_install_interface("Windows 2001", UACPI_INTERFACE_KIND_VENDOR);```
real pecan
#

where does it deadlock

flint idol
#

idk, all I'm getting are some TIDs and memory addresses

#

of mutexes

real pecan
#

well i've looked at those two functions and there's no way they can deadlock

flint idol
#

yeah it's not those

#

this is before suspend

real pecan
flint idol
#

after having done that

flint idol
real pecan
#

ah ok

flint idol
#

first it acquires two locks in a row on the same thread
then another thread deadlocks while trying to acquire the first mutex acquired

#

tid 2: waiting for tid 8 to release mutex x
tid 2: waiting for tid 8 to release mutex y
tid 9: waiting for tid 2 to release mutex x
DEADLOCK

#

but the weird thing is, tid 2 is CPU 0's idle thread

real pecan
flint idol
#

whatever it is

#

it causes it to hang

real pecan
flint idol
#

hmm weird

#

a reboot causes it to PF
another reboot causes it to work as normal

#

but unfotunately, no framebuffer

real pecan
#

no framebuffer after reboot that pfs?

flint idol
#

nope

real pecan
#

how do u know it pfs

flint idol
#

it PFed before suspend

#

what if I become windows 2000

#

no framebuffer after suspend :(

#

anyway

#

once uDRM comes out, this problem will be solved

#

I guess it's time for me to make interruptible I/O

real pecan
flint idol
#

idk

#

it's gone now tho

real pecan
#

lol

flint idol
#

I think NT has something called an IRP which is basically an I/O request packet

#

and I like that idea

#

my current I/O system is:

  • io requested
  • forward to driver, this action is synchronous
  • you wanted async I/O? oh let me just start a worker thread for you and you give me an event object
#
  • wait you wanted progress on that async I/O? too bad so sad.
#
  • you wanted to abort an I/O operation, uhh sorry we don't do that here
#

which, imo, is quite shit

#

luckily, I don't have much I/O

#

in the kernel

#

most of it is abstracted behind the VFS

#

#polls message
pls vote

#

in the meantime while I wait for the poll

#

I will be implementing elf loading

#

which I do have

#

but that's for loading drivers

#
/// <summary>
/// Allocates space on a thread's stack. Calling this after the thread has started running can be catastrophic.
/// </summary>
/// <param name="ctx">The thread's context.</param>
/// <param name="size">The of the stack region.</param>
/// <param name="status">The status of the function.</param>
/// <returns>A pointer to the region..</returns>
OBOS_WEAK void* CoreS_ThreadAlloca(const thread_ctx* ctx, size_t size, obos_status *status);
#

I have made this amazing api for pushing stuff to the stack

#

there aren't any platforms where the stack grows upward, right?

flint idol
#

no

#

this is meant for stuff like process loading where I need to push auxillary values

#

before the process starts

#
void* CoreS_ThreadAlloca(const thread_ctx* ctx, size_t size, obos_status *status)
{
    void* ret = (void*)(ctx->sp -= size);
    return ret;
}```
#

That should be how it's implemented when the stack grows downward

#
void* CoreS_ThreadAlloca(const thread_ctx* ctx, size_t size, obos_status *status)
{
    void* ret = (void*)ctx->sp;
    ctx->sp += size;
    return ret;
}```
and that's for when it grows upward
#

If I ever need that for future reference

#

these functions are just pseudocode, as I need error checking

flint idol
#

I theoretically have an elf loader now

#

except it uses an unimplemented function: Mm_MapViewOfUserMemory

#

which I will implement rn

flint idol
#

I kinda completely forgot how my VMM works

#

(oops)

thick jolt
#

lmao

flint idol
#

which will be a problem

#

if I need to implement a new vmm function

#

SO what I'll do is copy and paste code

#

so this is supposed to be mapping a private user memory region ubase->ubase+size from user_ctx into the kernel's context as shared memory

#

at kbase

#

with prot flags protection

#

possibly locking the user pages, depending on lock_pages

#
                // File page.
                page_info info = {};
                MmS_QueryPageInfo(ctx->pt, (uintptr_t)reg->owner->data+currFileOff, &info, nullptr);
                if (flags & VMA_FLAGS_PRIVATE)
                {
                    // Private.
                    // Moooo (CoW)
                    cow = true;
                }
                isPresent = info.prot.present;
                page what = {.phys=info.phys};
                phys = isPresent ? RB_FIND(phys_page_tree, &Mm_PhysicalPages, &what) : nullptr;
                if (phys)
                    MmH_RefPage(phys);
                rng->cow = cow;
                if (cow)
                {
                    rng->un.cow_type = COW_SYMMETRIC;
                    pc_range->cow = true;
                    pc_range->un.cow_type = COW_SYMMETRIC;
                    pc_range->prot.rw = false;
                    info.prot.rw = false;
                }
                MmS_SetPageMapping(ctx->pt, &info, info.phys, false);```
#

this is what I do for mmap'ing files

#

and reading this I discover a possible bug

thick jolt
#

lmaooo

flint idol
#

but idk if it's ever going to happen given my current page cache setup

thick jolt
#

do u want my pizza btw

flint idol
#

yes

#

send it over

thick jolt
#

my dad bought me pizza even tho i told him im not hungry

flint idol
#

my address is 123 seasme street

thick jolt
#

yes i will send it by mail

#

it will arrive rotten

flint idol
#

jk

#

I live at ||2 Rideau Street, Ottawa, Ontario, Canada||

thick jolt
#

hi its me ur uber eats driver

#

open the door

flint idol
#

search that address

#

maybe I'm not joking

thick jolt
#

hold on

#

ah yes easiest way to get shot

flint idol
#

I live at the senate of canada

thick jolt
flint idol
#

they've a website about my house

thick jolt
#

@astral mason

#

wheres ur managa

#

manga*

#

and ur os

thick jolt
flint idol
#

cc @astral mason

thick jolt
#

i js hurt my bone

#

ow

#

very painful

flint idol
#

is it broken?

thick jolt
#

anyways work on vmm function

#

😡

flint idol
#

no.

thick jolt
flint idol
#

then ur fine

thick jolt
#

i need 3 million dollars

#

then ill be fine

flint idol
#

right after I complete this function

#

I will be redoing TLB shootdowns

#

obos thread at 40 stars

flint idol
#

I can only work so much on obos in a day before getting bored

real pecan
#

obores

thick jolt
#

anything i can contribute to obos

#

anything SMALL

#

please

flint idol
#

Let me see

thick jolt
#

kk

weak kestrel
#

double ;;

thick jolt
#

hold on while i clone obos

weak kestrel
thick jolt
#

which branch is the right one

flint idol
#

Clone userspace-work

thick jolt
#

found it

flint idol
flint idol
thick jolt
#

oki

flint idol
#

that you can fulfill

#

oh dear

thick jolt
#

just please dont give me stuff like suspend support

flint idol
#

I already have that

#

you can do PCIe

#

should be simple enough

thick jolt
#

ive never done pci let alone pcie before

flint idol
#

I'll find something else then..

thick jolt
#

okay

weak kestrel
flint idol
#

you can implement interruptible waits

flint idol
thick jolt
flint idol
#

you're usually blocked

#

until that thing is fulfilled

thick jolt
#

yea?

flint idol
#

I want you to make that interruptible from external sources

weak kestrel
#

obos

flint idol
#

the intended behaviour is that CoreS_WaitOnObject reports OBOS_STATUS_ABORTED

weak kestrel
#

do you want multiple bugs introduced in your kernel

flint idol
#

dw

thick jolt
vale nymph
#

You dont even test yours extensively meme

flint idol
#

under src/oboskrnl

thick jolt
#

okay

flint idol
#

you might also need to make changes to mutexes, semaphores, and events

weak kestrel
#

contribute to my kernel

flint idol
#

which are also under locks/*

thick jolt
#

okay

flint idol
#

come back if you have a question on wtf something does

#

or when you're done

#

:)

thick jolt
#

yea im so confused

weak kestrel
flint idol
thick jolt
#

when u want to wait on an object

#

or thread*

#

u add it to some kind of threadlist

#

am i understanding this

flint idol
#

yup

thick jolt
#

if i wanted to make this interruptable

#

hmmm

flint idol
#

hint: CoreH_SignalWaitingThreads

weak kestrel
#

between different parts

flint idol
#

and I do occasionally go around the codebase adding newlines

vale nymph
flint idol
vale nymph
#

Oh dear

#

Also in one of the if cases you return with dispatch irql

flint idol
#

where?

thick jolt
vale nymph
#

The one right before the thread block

thick jolt
#

is this correct

flint idol
#

thanks mathew

#

nd

flint idol
#

and iirc, it has to be called at <= IRQL_DISPATCH

#

or yells at your face

thick jolt
#

i dont know what IRQL_DISPATCH is supposed to mean

#

sorry im asking a ton of stupid questions

flint idol
#

nah it's fine

#

this is stranger code to you

#

IRQL_DISPATCH is where all scheduler IRQs are masked out

#

as well as timer IRQs

#

an IRQL is basically a level where certain IRQs are not executed

#

highest is 15 on x86-64, which means masked

thick jolt
#

i see

flint idol
#

lowest is PASSIVE (0) which means unmasked

#
enum
{
    IRQL_PASSIVE,
    IRQL_DISPATCH = 2,
    IRQL_TIMER = 2,
#if OBOS_ARCHITECTURE_HAS_ACPI
    IRQL_GPE = 8,
#endif
    IRQL_MASKED = 0xf,
}
#

this is the enum simplified

thick jolt
#

i get you

vale nymph
#

Its meant to be like the interrupt priority some cpus have

#

So its a per cpu thing

flint idol
#

and at a higher IRQL, lower IRQL interrupts are also masked

thick jolt
flint idol
#

because it doesn't expect to be interrupted except when it succeeds in getting what it wants

#

because signalling an object really just means waking an arbitrary thread in it

thick jolt
#

how does obos know if its wait is getting interrupted exactly

flint idol
#

how it knows is because it's in a list of threads in the object
and signalling an object just chooses an arbitrary thread to wake

#

so it's like:

waitforobject:
    append(obj->waiting_threads, curr)
    block(curr)
    return success
signalobject:
    thread towake = obj->waiting_threads.head
    remove(obj->waiting_threads, towake)
    ready(towake)
    return```
thick jolt
#

mm okay i see

flint idol
#

now signal object in the actual kernel can also signal all objects at once

#

as you'll able to see from the signature

thick jolt
#

yea i can see that in the while loop

#

with the all bool

weak kestrel
flint idol
#

it's pseudocode

weak kestrel
#

ik

thick jolt
#

so what we need to do exactly is in waitforobject somehow check if we got signalled, then stop blocking the current thread and return an obos failure

#

am i understanding the problem correct

flint idol
#

yup

thick jolt
#

or does this sound like complete gibbberish

#

okay

#

is there like a function you already have that can check if the current thread is getting signalled?

#

like some callback or smthin

weak kestrel
flint idol
#

you specifically need to check if you got signalled and the object is still not ready

flint idol
#

because you know you've been signalled as soon as you leave the CoreH_ThreadBlock

#

you need to make it figure out why, instead of it assuming blindly it was because it was signalled successfully

#

and then return the "why" as the status

#

so it's rather it returns OBOS_STATUS_SUCCESS because our wait was successful
or it returns OBOS_STATUS_ABORTED because our wait was aborted

thick jolt
#

im probs gonna have to mess with this snippit of code here

#

the actual waiting part

flint idol
#

that less so

#

you might need to add a new function

#
void abort_wait(struct waitable_header* obj);```
#

something like that

thick jolt
#

why would i need the actualy object itself

#

if im checking IF I GOT

#

interrupted

flint idol
#

well to add interruptible waits to the kernel, you first need a way to interrupt a wait

#

brb

thick jolt
#

okay

flint idol
#

the behaviour to interrupt a wait would probably be slightly different than that of the behaviour to signal a wait

#

but it's up to you to figure it out

thick jolt
#

well

#

if i take the object

#

signal it but disable use signaled

#

maybe that could work?

#

no thats stupid