#pmOS - microkernel OS for RISC-V, x86, and LoongArch

1 messages · Page 7 of 1

plain jungle
#

But having the pointer is allowed (see the definition of reinterpret_cast -- there is no requirement around alignment)

hexed knot
#

okay but having a pointer itself is fine

#

yeah

#

so its also not UB if you do it via C++

#

its also not ub via rust aiui

#

still UB to use though

kindred venture
#

but interesting

hexed knot
#

huh i have found something even more cursed

plain jungle
#

The wording in the C standard only applies to object ptr to object ptr casts

hexed knot
#
int x(int* p, int* q) { return (p+100)-q; }
int z() { int a[4]; return x(a, a); }
``` this is UB in C and rust (in rust if you use a normal add() or offset() but not wrapping_add()) but not in C++
plain jungle
#

int to object is allowed regardless of alignment

hexed knot
#

afaict

kindred venture
# plain jungle But having the pointer is allowed (see the definition of reinterpret_cast -- the...

i found this:

An object pointer can be explicitly converted to an object pointer of a different type.64 When a prvalue v of
object pointer type is converted to the object pointer type “pointer to cv T”, the result is static_cast<cv
T*>(static_cast<cv void*>(v)). [Note: Converting a prvalue of type “pointer to T1” to the type “pointer
to T2” (where T1 and T2 are object types and where the alignment requirements of T2 are no stricter than
those of T1) and back to its original type yields the original pointer value. — end note]
this doesn't explicitly mention it, but the note seems to imply that if T2 is more strictly aligned than T1 the round-trip is not preserved, which would only make sense if getting a misaligned pointer this way is UB/ID

#

i wonder if it's more explicitly mentioned anywhere

plain jungle
#

The note is non-normative

#

It refers to this part of static_cast

#

If the original pointer value represents the address A of a byte in memory and A does not satisfy the alignment requirement of T, then the resulting pointer value ([basic.compound]) is unspecified.

#

The wording in the note is more strict than required by static_cast: it is enough that the object is properly aligned, not that the type's alignment is stricter (though the latter implies the former)

kindred venture
#

ah ok

plain jungle
#

But it is correct that non-aligned casts between object pointers are not guaranteed to preserve round trips afaict

#

A compiler would be allowed to zero the alignment bits, for example

hexed knot
#

ah maybe not, maybe always

#

it can't do that for incomplete types, though

#

hmm

#

actually what are the semantics on that

plain jungle
#

No idea

plain jungle
#

due to this provision

#

That's probably the intention

hexed knot
#

yeah 100%

#

its probably for the memcpy case specifically, too

carmine nacelle
#

I think llvm is confused again with my assembly...
movl %eax, %eax

#

Is this not correct?

inline uint32_t io_readl(uint32_t *ptr)
{
    uint32_t data;
    asm volatile ("movl %1, %k0" : "=a"(data) : "o"(*ptr) : "memory");
    return data;
}

inline void io_writel(uint32_t *ptr, uint32_t data)
{
    asm volatile("movl %k0, %1" :: "a"(data), "o"(*ptr) : "memory");
}
carmine nacelle
toxic torrent
#

check ptr for null meme

carmine nacelle
#

The thing is it's not null

#

Ok I'm dumb

#

I'm blaming uACPI's vibes-based types meme

#

I was returning wrong thing in uacpi_kernel_pci_device_open

hexed knot
carmine nacelle
carmine nacelle
#

I've reached long mode waking up from S3

#

(took me too long for some reason)

hoary moat
#

do u register wake vectors?

#

or just depend on qemu

#

@carmine nacelle

carmine nacelle
#

wdym

#

I've registered it to 0x9e000

#

(which is whatever my PMM decided)

#

(I'm in a lecture)

#

(like I'm missing all the stuff to save/restore state of things)

hoary moat
carmine nacelle
#

?

#

Run a bunch of aml you mean?

#

Probably...

#

I need to get back to userspace first

hoary moat
#

before sleeping you need to register GPEs for wake

carmine nacelle
#

I haven't done that I think

hoary moat
#

it won't work on 100% of real hardware

#

until you do

carmine nacelle
#

I'll get to it

carmine nacelle
#

(I have C++)

#

Fun, I'm getting pagefault in ltr

#

With error 0x48 bruh

twilit talon
#

Initializing TSS... FAIL

carmine nacelle
#

But it makes no sense

#

Wtf

#

It just doesn't work

#

It must be something dumb

#

Like I just copy-pasted my smp init code, it can't be broken

#

And tss descriptor is FFFF8000208B018E000068

carmine nacelle
#

Initializing TSS... SUCCESS

#

Now I just need to restore (or rather save it correctly) userspace context (since I'm entering S3 from Ring 3), think about SMP bringup (idk how to expose it to userspace, I think I won't? But cpuidle would be nice to support, though idk if that depends on userspace, but I also wanted to have userspace schedulers...), save/restore ACPI NVS (?) memory (this should be another syscall), and write an interface for drivers to suspend/resume (above all I want ns16550 server for logs)

#

But like in theory, the kernel should be fully working with one core already

#

If I remove the panic

#

The difficulty with SMP bring up is my TLB shootdown code, which is just a bit unsound

#

Though I should probably also save and restore TSC?

#

And lapic timer

#

(though it shouldn't matter)

#

Yeah, lapic should already be fully working

#

For IOAPICs I've decided to add a variable which mirrors them, so it should also be trivial

twilit talon
carmine nacelle
carmine nacelle
kindred venture
#

if it's marked invariant in cpuid it's guaranteed i believe

carmine nacelle
#

If it's not I don't use it trl

#

So nothing to do?

#

Cool

kindred venture
#

sdm says it ticks in all P, C, T states

#

idk about S states

carmine nacelle
#

S is when CPU is off

carmine nacelle
eager rose
#

I'm sure I've heard of some separate TSC_CONSTANT or something. maybe that has something to do with it

kindred venture
#

yeah

#

as i said, idk about S

carmine nacelle
#

The ACPI spec explicitly says (iirc) that S1-5 are different to those 3

eager rose
#

$$P, C, T \in S0$$?

solemn sageBOT
#

david

$$P, C, T \in S0$$?
eager rose
carmine nacelle
#

P, C, T are for changing CPU frequency while the system is on

#

S1-5 is when the CPU clock is not on

#

Idk I've read a nice article about it

#

Also there are D states trl

eager rose
#

yeah lol

#

imo we should make a clearer distinction between the machine state (G0, G1[S1...S5] etc.) and CPU power state (C0...Cn)

carmine nacelle
#

Like how much cache is maintained on hlt

carmine nacelle
#

What if I ported pmOS to aarch64?

plain jungle
#

does suspend/resume work reliably?

carmine nacelle
#

Not yet

#

I enter the kernel

#

But now I need to get to userspace

toxic torrent
carmine nacelle
#

Ok, I've entered userspace/devicesd server (which runs uACPI) but I now have an issue that the stack is destroyed (kinda as expected) and I need something which could do longjmp in kernel

#

Explicitly

#

And at this point I might just implement callbacks in kernel istead of doing it by userspace thread

#

(basically making a good API for it)

left dew
#

why is the stack destroyed?

#

memory content is preserved when you wake up from sleep

#

isn't it?

#

so the stack should still be there, as long as you know where it is

twilit talon
left dew
#

oh, is there no way to like, go back to where it left off?

#

unlucky

twilit talon
#

linux uses an asm stub i think

#

to preserve stack

left dew
#

does it matter? if you just free the stack and take off from a different execution point?

#

should the "sleep" function return back to the caller once the system wakes up?

#

i guess it depends on the design lol

plain jungle
#

yeah this seems like a weird problem

#

just use a different stack when writing to the sleep vector

twilit talon
#

or that

left dew
#

i guess you could have something like

void sleep() {
  event_t wake_event;
  create_thread([](void *arg) {
    event_t *wake_event = (event_t *)arg;
    uacpi_enter_sleep(...);
    // ...
  }, &wake_event);
  wait_for_event(&wake_event);
  // we woke up from sleep !!!
}```
plain jungle
#

that's also how Managarm's idle task works

left dew
#

something liek that would be fun

plain jungle
#
        [[noreturn]] void invoke() override {
            runOnStack([] (Continuation) {
                if(logIdle)
                    infoLogger() << "System is idle" << frg::endlog;
                suspendSelf();
                __builtin_trap();
            }, getCpuData()->idleStack.base());
            __builtin_trap();
        }
left dew
#

but idk how you'd get from waking up back to after uacpi_enter_sleep

plain jungle
#

you'd switch to a new stack + record the old stack

#

then program the reset vector to essentially return to the old stack

#

then write to the sleep register

#

I'd still advise against doing the reset vector in usermode

#

that seems incredibly broken

#

especially since it'll be woken up in kernel mode

left dew
#

waking up in kernel mode and then resuming the thread that initiated the sleep seems like the best idea

#

with my "event" approach you could also just signal the event from kernel mode

#

and basically forget about the thread you spun off

#

assuming you can properly clean up the resources allocated to it

carmine nacelle
carmine nacelle
#

Since I don't store anything on them

#

I just enter the kernel as normal, and return to userspace

carmine nacelle
carmine nacelle
plain jungle
#

Sounds cursed

carmine nacelle
#

In a bad way?

plain jungle
#

But yea my main point is that it's possible to handle the situation that you can get killed at any time (e.g. by suspend or exiting the idle task) even in C (no assembly required)

carmine nacelle
#

So just kill the thread?

#

I'm not understanding

plain jungle
#

well yes, but make sure it runs on a stack that you can just discard

carmine nacelle
#

I think I'll just do longjmp meme

#

Again, the problem is with userspace stack

#

Not the kernel

#

I don't like killing threads

carmine nacelle
#

I think the easiest solution would be to do a raw syscall and save the return address to thread-local variables

plain jungle
#

if you're writing the registers from the kernel, I don't see how the suspend syscalls differs from any other syscall from userspace's perspective

carmine nacelle
#
    .text
    .globl syscall_prepare_sleep
    .type syscall_prepare_sleep, @function
syscall_prepare_sleep:
    popq %fs:return_addr@tpoff

    shlq $8, %rdx
    orq $14, %rdx
    xchgq %rdx, %rdi
    xchgq %rsi, %rdx

    movq %rcx, %r10
    syscall

    jmpq *%fs:return_addr@tpoff


    .section .tdata,"awT",@progbits   # TLS data section for initialized thread-local data
    .align 8                         # Ensure proper alignment for a 64-bit variable
return_addr:
    .quad 0
carmine nacelle
#

Ok, something is trolling me an making syscalls

#

(My first uneducated guess would be uACPI)

carmine nacelle
#

(this is getpid basically)

#

get_thread_id

#

Appartently I've been calling it on mutex lock

#

Big time bruh

#

why

#

Which also means slower uACPI score

#

I forgor about it

left dew
#

you should cache getpid/gettid/getppid results

#

and of course clear/re-cache them on fork

carmine nacelle
#

I can just use pthread_self

plain jungle
#

just use mlibc

carmine nacelle
#

Does mlibc support library threads?

plain jungle
#

what are library threads?

#

mlibc supports pthreads, yes

left dew
#

of course it does

#

that god damn thing runs chromium meme

#

-# and almost systemd

carmine nacelle
#

So every process has at least two threads

plain jungle
#

ah

#

there's nothing preventing that from working

carmine nacelle
#

I guess...

carmine nacelle
#

(almost as if I actually need a proper abstraction)

twilit talon
#

Does it tho trl

left dew
#

yeah it does

#

port has bitrotten but it did run

twilit talon
#

True

#

I've seen the screenshot

#

Although it mightve been photoshopped trl

carmine nacelle
left dew
#

it was epic

twilit talon
#

Damn

#

Hopefully we get it back

#

Along with kde

plain jungle
#

afaik KDE apps work

twilit talon
#

I mean the DE that comes with it

#

Kdewin or whatever

plain jungle
#

ah

#

not sure if anybody ever tried that

left dew
#

we did try gnome

#

we got to the screen which says that gnome encountered an error

#

not sure if it was gnome session or not

twilit talon
left dew
#

but it did have graphical output

#

which is so fucking cool

twilit talon
#

Nice

left dew
#

considering all the gobject-introspection we had to go through

#

its not very nice stuff

plain jungle
#

why didn't you merge this though?

twilit talon
#

How was that worked around again

plain jungle
#

does somebody still have that code?

left dew
#

we had this

left dew
twilit talon
#

Lol

left dew
#

it was a while back

#

it was really hacky

#

like most stuff, but most stuff is also upstreamable

#

this absolutely wasn't

#

also, hijacking pmos thread lfgg

carmine nacelle
vale hinge
#

gnu magic

#

same way as glibc works on it

left dew
#

same way as glibc will work on ironclad (🙏)

vale hinge
#

lol no

dense carbon
#

That's how freebsd etc have the latest gnome and kde

pearl narwhal
#

no idea about gnome but kde itself has a significant upstream effort for running on BSDs iirc

left dew
#

gobject-inteospection is a bitch though, still

carmine nacelle
#

Very not nice thing about Rust: it's difficult to compile while on a train

wide spruce
#

thats what I really like about jinx

#

I can just develop it offline once downloaded

lunar island
#

can't xbstrap not do this

wide spruce
#

yeah

plain jungle
#

it can

lunar island
#

this is more of a cargo thing than anything

wide spruce
#

me liking something from jinx doesnt mean xbstrap cannot do it too

#

xbstrap and jinx are more or less the same thing

lunar island
#

I mean

#

its the equivalent of just

#

compiling stuff with deps installed

#

lol

wide spruce
#

true

dense carbon
#

Not everyone has the privilege of always on broadband

kindred venture
#

cargo does have an offline mode

#

i haven't used it so i don't know how effective it is though

vale hinge
hexed acorn
#

car stop

plain jungle
#

yeah cargo seems to make the common case easy while not caring about advanced use cases at all

#

try to make it apply a patch to a transitive dependency that is imported by your Rust package

#

if you want to have some "fun"

carmine nacelle
#

Ok, qemu is really trolling me (totally not because my code is broken)

#

But luckily I'm arriving to a PC which supports S3 and has a COM port (so it's actually 2 PCs trl) in 20 minutes...

#

It wakes up but still says paused, and doesn't want to sleep again...

kindred venture
carmine nacelle
#

Pointing to the patched repo/source

kindred venture
#

or even just passing it with --config

plain jungle
#

I don't remember the exact issues but IIRC it was not possible to do this reliably within Managarm without overwriting $CARGO_HOME

kindred venture
#

is there a reason overwriting CARGO_HOME would be undesirable?

plain jungle
#

still not fixed after 4 years meme

carmine nacelle
#

Fun, the physical PC bootloops..?

left dew
#

something tells me... something is broken

#

not sure tho

carmine nacelle
#

Time for while 1 debugging meme

left dew
#

binary search time

carmine nacelle
#

This PC decided to place init vector at 0x7000

#

It also can't turn on...

#

like until i unplug it from wall

carmine nacelle
#

btw this shit is fun meme

left dew
#
mov al, 0x69
out 0x80, al```
#

🙏

plain jungle
#

what does the manual say for E3?

carmine nacelle
#

Idk

carmine nacelle
#

Like for debugging

carmine nacelle
#

@left dew

eager rose
left dew
#

lmaooo that's amazing

eager rose
#

and incredibly useful

left dew
#

i meannn

#

is it?

#

he has serial ;^)

eager rose
#

oh

#

yeah right

carmine nacelle
#

i have serial in long mode

#

this was printed from real mode

eager rose
#

a polling driver (that would work in real mode :^)) is quite simple though

left dew
#

yep, you can just poke into 0x3f8 and poll tx ready or whatever

#

its like 5-6 lines of code

#

(assembly)

kindred venture
#

serial may not be particularly hard to implement in asm but it's not really suitable as just "insert these one or two easily memorable instructions wherever you want and you now have one byte of output"

#

imo

carmine nacelle
#

fine i'll implement serial

#

the problem with this is that it's too fast

#

Bruh this PC's PSU is making really scary noises

left dew
#

don't worry

carmine nacelle
#

And it's shitty

left dew
#

it's not like it will explode or anything

#

right..? meme

carmine nacelle
#

These PSUs have a history of doing that

#

I think I'll just stick to while 1 binary search

#

For some reason it gets to line 29 and then tripple faults

kindred venture
#

i'm having a hard time figuring out why this worked on qemu and bochs in the first place

#

you're converting segments to their actual linear addresses in 16 bit registers

#

that's gonna overflow immediately

#

also when enabling protected mode, the far jump is supposed to be the very first instruction after the write to cr0

carmine nacelle
#

Yeah this prints 0x01

#

writes

#

shows

#

idk

carmine nacelle
#

Segment's values are >> 4

#

They're 16 bit registers

kindred venture
#

the segment registers themselves yes

#

but you're converting them into their linear addresses, which are 20-bit values

#

you're essentially discarding the top 4 bits of the seg regs

carmine nacelle
#

QEMU does not do that

#

And bochs

kindred venture
#

then qemu's emulating incorrectly

#

which i doubt

carmine nacelle
#

And bochs?

kindred venture
#

bochs too

carmine nacelle
#

Like I've walked over it and it was how that worked

kindred venture
#

if they're emulating correctly, this will essentially discard the top 4 bits of cs, leaving the truncated linear address in cx

#

same for what you're doing further down

carmine nacelle
#

they did not

carmine nacelle
#

what would be discarded

#

That's why I'm doing two stores

kindred venture
#

let's say cs=0x9e00 (aka wakeup vec is at 0x9e000)

bx = cs  # bx = 0x9e00
cx = bx  # cx = 0x9e00
cx <<= 4 # cx = 0xe000 
carmine nacelle
#

yes

kindred venture
#

oh wait you're working around it in a weird way slightly further down

left dew
carmine nacelle
#

wait a second

carmine nacelle
#

I need to read AMD manual

#

It must be that

kindred venture
carmine nacelle
#

ok, firmware in combination with limine is trolling me

#

Limine because it refuses to boot randomly and firmware because it refuses to output image randomly

#

Wtf, it doesn't enter ACPI mode now?

#

nvm, this PC just enters S3 too quickly

carmine nacelle
kindred venture
#

like relocating the trampoline in c++ before using it?

#

that seems like a good idea

carmine nacelle
#

Yes

#

But there's more insanity

#

This stuff is in data trl

kindred venture
#

i mean that's fine

#

it's essentially just a template

carmine nacelle
#

i think i'm in pmode

#

pmos - protected mode Operating System

#

Time for a reddit post

#

anyway

#

(i really need a pxe server)

#

like I've already got openwrt router which can host it...

#

(I'm digressing)

#

This seems promissing

#

(but suboptimal)

#

(I really need SMP trampoline)

#

It could've been really nice if limine had an option for disabling smp...

#

(anyway)

#

Yeah this is failing because it's not bsp

#

more fun stuff

#

I think my PMM is destroyed

#

(i'm blaming cache stuff)

carmine nacelle
#

I've no idea what's going on but something is allocating like a million pages

carmine nacelle
#

idk an option for not giving smp reply

#

so it's only one cpu

kindred venture
#

just don't have the smp request?

#

limine only starts the aps if you ask for it

carmine nacelle
#

No but so I can quickly test without smp without recompiling kernel

kindred venture
#

ah

carmine nacelle
#

ok, ignoring pmm, it looks like i'm waking up but getting no interrupts

#

This is weird...

carmine nacelle
#

I've added volatile to asm (wbinvd) and now it's failing in a different place

#

which should never fail

carmine nacelle
#

Ok, I think I'll work on an SMP trampoline

#

Which could also apply to 32 bits

#

And maybe I'll support Hyper on AMD64 builds as well...

carmine nacelle
#

Ok, I have CPU parking...

#

I have an idea

#

What if I make drivers explicitly unregister interrupt handlers before sleeping?

left dew
#

Parking cpu 3000000

#

Lots of cpus

modest thistle
#

3M cpus

#

lol

plain jungle
carmine nacelle
carmine nacelle
#

Idk

#

I seem to have no interrupts after waking up, for some reason

left dew
#

looks like 3<<24

#

which would make sense actually

plain jungle
#

Don't you need to reinitialize devices anyway?

carmine nacelle
#

Because I just store it as 32 bit int for x2apic compat

carmine nacelle
#

I don't know why, but I've moved relocations to C++ and now my wakeup vector throws #GP when entering protected mode

#

I don't know what I'm missing...

#
check_exception old: 0xffffffff new 0xd
  1300: v=0d e=0018 i=0 cpl=0 IP=9e00:000000000000002a pc=000000000009e02a SP=0000:0000000000000f70 env->regs[R_EAX]=0000000000000000
EAX=00000000 EBX=00009e00 ECX=00000009 EDX=00000001
ESI=00000000 EDI=00000000 EBP=00000000 ESP=00000f70
EIP=0000002a EFL=00000007 [-----PC] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0000 00000000 ffffffff 008f9300 DPL=0 DS16 [-WA]
CS =9e00 0009e000 ffffffff 008f9b00 DPL=0 CS16 [-RA]
SS =0000 00000000 ffffffff 008f9300 DPL=0 DS16 [-WA]
DS =0000 00000000 ffffffff 008f9300 DPL=0 DS16 [-WA]
FS =0000 00000000 ffffffff 008f9300 DPL=0 DS16 [-WA]
GS =0000 00000000 ffffffff 008f9300 DPL=0 DS16 [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     0009e0b0 0000001f
IDT=     00000000 000003ff
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000005 CCD=00000009 CCO=EFLAGS
EFER=0000000000000000
#

On the far jump intstruction

left dew
#

what's selector 0x18?

#

make sure the gdt is accessible and intact

carmine nacelle
#

It looks sane

carmine nacelle
#

32 bit code

left dew
#

well, apparently the gdt is not so sane

carmine nacelle
#

I've no idea what was happening

#

I undid everything and did it again and now it works...

carmine nacelle
carmine nacelle
#

I think I have SMP?

#

(idk why logs are broken)

#

(after waking up that is)

plain jungle
#

you're supposed to shut down + re-init all devices anyway

carmine nacelle
#

Yes

#

I'm not getting ACPI interrupts though

#

But I'm getting LVT0 interrupt

carmine nacelle
#

I think I'll fix interrupts

#

Then fix the 32 bit build

#

Then fix RISC-V

#

Then get fix AHCI

#

Then merge to main

carmine nacelle
#

Ok, I'm getting tired of S3 stuff

#

It semi-works

#

So I think I'll implement it in i686 build (among with adding SMP support, which it doesn't have now)

#

(Since I think I should kinda be able to just translate it from x86_64 build/trampoline)

#

And then I'll work on adding "handles" to IPC

#

And fixing timers maybe

#

(before writing a proper driver interface for suspend/resume)

#

Also, I still need to fix fork() on RISC-V...

#

(too many things to do)

carmine nacelle
twilit talon
#

what does that mean

carmine nacelle
#

It seems to wake up properly (including SMP), but it's kinda difficult to know since screen nor serial work and other drivers are also broken

carmine nacelle
#

And I'm undermotivated to write this now

plain jungle
#

why is fork() arch specific?

#

fork on managarm has zero arch specific code

carmine nacelle
carmine nacelle
#

on risc-v specifically

#

And I'm using a0 for both passing the syscall id and returning the result

twilit talon
carmine nacelle
#

It does, but my userspace driver is broken and only works in QEMU for some reason

twilit talon
#

lol

carmine nacelle
#

Fun, llvm is trolling me again

carmine nacelle
#

Average ia32 assembly

#

Ok I need vdso...

#

(What if I implemented dynamic linking?)

#

(ok, I'm getting distracted)

#

Bruh I broke something in i686 builds

#

(ok, I urgently need the symbol table memes trl)

#

(what the fuck)

#

(the best way to debug asserts is to add more asserts galaxybrain)

modest thistle
#

XD

carmine nacelle
#

Ok, my userspace was dumb and my kernel wasn't cheking it

#

ia32 build works

#

And also Rust just worked

#

(Or did it?)

carmine nacelle
#

It just failed silently

#

On the other hand PS/2 had suddenly decided to work...

#

Ok, I'm dumb

#

It's trying to load x86_64 executable on i386 for some reason

#

Wtf

#

How did that even compile?

modest thistle
#

lol what

carmine nacelle
#

My Makefiles are trolling me

#

Oh yeah, I forgot I rm -rf *'ed over it

#

This is better

pearl narwhal
#

you can just name it pmos-dev or smth

#

cuz you know toolchains can have multiple targets

pearl narwhal
#

i don't see why it couldn't, toolchain name is just the name of a directory afaik

carmine nacelle
pearl narwhal
#

oki

carmine nacelle
#

Like dev-x86_64-unknown-pmos compiler x86_64, i686 and riscv64gc

#

It's like clang/llvm

#

Which is nice

pearl narwhal
#

yep that's the entire idea

carmine nacelle
#

Which makes no sense

#

Ok, it's severely broken

#

This is very sus

#

I'm blaming this

modest thistle
#

why?

carmine nacelle
#

It just returns int64_t

#

And it's passing it as implicit argument

#

I needed repr transparent

#

Yeah, repr(transparent) worked

#

Ok, time for SMP on i686

carmine nacelle
#

Ok, smp kinda almost works in i686 port...

#

(By kinda almost I mean that I have garbage in cr3, and it pagefaults)

#
Initcheck_exception old: 0xffffffff new 0xe
     0: v=0e e=0000 i=0 cpl=0 IP=0008:0000606b pc=0000606b SP=0010:00000000 CR2=0000606b
EAX=80000001 EBX=00000000 ECX=00000000 EDX=00000001
ESI=00000000 EDI=00000000 EBP=00000000 ESP=00000000
EIP=0000606b EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00cf9a00 DPL=0 CS32 [-R-]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     00006098 00000017
IDT=     00000000 0000ffff
CR0=80000011 CR2=0000606b CR3=f000ff53 CR4=00000000
DR0=00000000 DR1=00000000 DR2=00000000 DR3=00000000
DR6=ffff0ff0 DR7=00000400
CCS=00000000 CCD=00000001 CCO=LOGICL
EFER=0000000000000000
carmine nacelle
#

Ok, I've fixed garbage cr3, but now I have garbage in cr4 galaxybrain

#

classic

#

Ok, I officially have SMP on i686 builds

carmine nacelle
#

and it just trippel faults on real hardware nooo

carmine nacelle
#

Ok, I'm blaming Ultra

#

It tripple faults on physical hardware, even if I place infinite loop at kernel's entrypoint

#

Ok, I'm dumb

#

I forgot I nuked my repo and it was this #1277232930317537341 message

carmine nacelle
manic girder
#

very cool

#

so you support i686, x86_64 and riscv64 now?

carmine nacelle
#

Yeah

#

I've had i686 working for some time now, but without SMP

#

I think I'll implement ACPI sleep stuff on it tomorrow

#

(it's almost 3 am bruh)

carmine nacelle
carmine nacelle
carmine nacelle
#

I think I need multilib support...

plain jungle
#

for the kernel?

#

or userspace?

carmine nacelle
#

userspace

#

I mean both

#

Idk, so I can compile 32 and 64 bit userspace binaries in one go

#

the kernel already supports compat mode

plain jungle
#

why do you want to run 32 bit apps though?

carmine nacelle
#

My 32 bit kernel doesn't boot in bochs

#

(because its bios is broken and I haven't figured out how to update it)

#

So that I can debug 32 bit aplications with 64 bit kernel...

#

(I think it's an X Y problem)

carmine nacelle
#

Also for convenience

#

I have to recompile libc++ and friends every time I want to target a different architecture

#

(But maybe it's just a bad build system)

plain jungle
#

just have different build dirs for different targets

carmine nacelle
modest thistle
#

can't you just do that with env vars?

hexed knot
#

you can probably patch it

#

to teach it about your new /lib location

carmine nacelle
carmine nacelle
carmine nacelle
carmine nacelle
modest thistle
#

can't you make a script that copies the bin into the target folder then?

carmine nacelle
#

this is not the issue

modest thistle
#

why?

carmine nacelle
#

like i already do that

modest thistle
#

then you should not need to recompile every time

carmine nacelle
#

the issue is with libraries

carmine nacelle
#

Ok, time for 1: jmp 1b

#

I'm having a skill issue with this now...

    ljmpl *%cs:(acpi_vec_jump_pmode - acpi_trampoline)
acpi_trampoline_jump_pmode:
#

Fun, ia32 builds are broken in bochs

#

I think framebuffer just isn't working

#

Nope, the whole userspace is broken

#

(but kernel didn't crash)

#

Timers are just broken

carmine nacelle
#

my pagefault handling is broken for some reason?

carmine nacelle
#

Ok, I have no clue why, but bochs just doesn't wake up

#

And QEMU triple faults

#

With nonsense

twilit talon
#

btw triple has one p

carmine nacelle
#

I need to get checked for dyslexia

#

I know why it's failing...

#

I crashed qemu

#

Nope

#

The whole WSL2

#

Ok, this looks like kernel address

carmine nacelle
#

Of course it's this

twilit talon
#

are you saying..

#

IDT init... FAIL?

kindred venture
#

TSS init... FAIL

carmine nacelle
#

busy tss

carmine nacelle
#

TSS init.. SUCCESS

#

But something pagefaulted, which kinda isn't nice I guess

#

Even SMP works...

#

Ok, i686 port is officially better that x86_64

carmine nacelle
#

What the fuck

toxic torrent
#

normal

carmine nacelle
#

I'm semi-satisfied with S3 semi-working on x86_64 and i686 (the latter crashes on physical hardware for some reason during pthread creation?), so my plan is to write an ACPI (internal) bus thing in devicesd server, add a driver for RISC-V QEMU thing, and I'll probably merge it to main, before continuing with proper init server/driver management stuff

#

(at which point I'll add an interface for callbacks for sleep/resume)

#

And I'll probably implement IPC handles/permission system/whatever

#

I'm envisioning how the interface could look for Rust/C++ coroutines with IPC

#

(and C I guess)

plain jungle
#

What's "RISC-V qemu thing"?

carmine nacelle
#

The QEMU device for delivering ACPI events on hardware reduced platforms (ARM, RISC-V, loongarch)

#

The one that @ infy mentioned in uACPI thread a few days ago

carmine nacelle
twilit talon
#

could be an OOM since u use LTO

carmine nacelle
#

Nope

#

Broken assembly

twilit talon
#

lol

carmine nacelle
#

I'm sure nobody just tested it

#

(since elf tls stuff is a bit fucked)

twilit talon
#

what did u do

carmine nacelle
#

ntpoff is IA32 thing only apparently

#

On AMD64 tpoff is already negtive

#

Time to test new EC stuff...

#

I've changed its initialization to ACPI bus

#

Fun fact: I think my interrupts are broken on x86_64 in general, not just after waking up

#

i guess my pci driver is severely broken...

twilit talon
#

vendor cece

carmine nacelle
#

Where

twilit talon
carmine nacelle
#

Yeah, PCI is reading garbage

twilit talon
#

your pci driver is cooked

carmine nacelle
#

Maybe I should just hardcode 0x3fc lol

#

It's broken on 3 laptops

twilit talon
#

well pci may be accessed during namespace load

carmine nacelle
#

(or I could fix ECAM)

twilit talon
#

before u are able to access _CRS

#

so yes u have to hardcode it

#

but check linux

carmine nacelle
#

Linux's source is unreadable

#

Macro hell

twilit talon
#

nah its easy

#

let me look for you

carmine nacelle
#

I think they just hardcode it

twilit talon
#

_CRS is parsed later here, read the comment above ^

carmine nacelle
#

So just hardcode it?

twilit talon
#

tldr yes

carmine nacelle
#

I guess MacBook wants ecam

twilit talon
#

does it not work correctly without ecam?

carmine nacelle
#

What does that even mean?

twilit talon
#

this means u returned UACPI_STATUS_NOT_FOUND

carmine nacelle
twilit talon
#

yeah u hit line 295

carmine nacelle
#

I know about that

#

but

#

I'm doing this

#

It returns any device

twilit talon
#

soo how does it fail

carmine nacelle
#

I'll add printfs

#

My PCI driver is having a skill issue with finding segment 0

twilit talon
#

bruh

carmine nacelle
#

wtf

#

how did ecam even work?

#

This has to be something very dumb

#

Wait a second

#

So I have to have PCI before uacpi_namespace_load?

carmine nacelle
carmine nacelle
#

fin, my EC driver didn't survive

#

This assembly is funky...

#

(brainrot)

#

(I think my code quality did in fact decrease after disabling copilot)

twilit talon
#

Lol that's interesting

#

Yeah probably

#

Does it send a proper lid notify as well if you close it entirely?

carmine nacelle
twilit talon
carmine nacelle
#

And the kernel only uses legacy IO

twilit talon
#

Oh

carmine nacelle
#

Because I'm planning to make PCI accesses an IPC call

#

Since I don't have shared mutexes

#

(too many things to do)

carmine nacelle
#

I think it has an accelerometer

carmine nacelle
#

Time for the QEMU device I guess...

twilit talon
carmine nacelle
#

Like if I just move the laptop it also spams those events

#

Idk why apple would have that

#

It's reasonable for tablets and 2 in 1s

twilit talon
carmine nacelle
#

Idk

twilit talon
carmine nacelle
twilit talon
#

Lol

carmine nacelle
#

(I basically have something akin to mbus written in Rust, and it's publishing to there)

#

Also, am I supposed to install devices before uacpi_finalize_gpe_initialization?

carmine nacelle
twilit talon
#

We talked about this error, its cosmetic

carmine nacelle
#

I remember that

carmine nacelle
#

Including AMD GPIO

#

Mostly because of that PCI error

twilit talon
#

Ah nice, you just didn't include it in the vid

carmine nacelle
#

I've basically copy-pasted code from osdev wiki

#

So the internal devices are also using ACPI bus thing now

#

(same with GPIO)

#

Time for the kernel to completely destroy me

#

(I think I'll do it tomorrow)

toxic torrent
carmine nacelle
toxic torrent
#

why i8

carmine nacelle
#

Kernel takes uint8_t *

toxic torrent
#

as it should

carmine nacelle
#

Wait, no, it should be c_char

#

idk, I'm just dumb

#

it's i8 on x86 and u8 on risc-v

#

It's refusing to link for some reason...

#

Do I just do big time stubbing?

hexed knot
#

you can make rustc use u8 somehow

#

idk how

#

and to make the C abi match you can build with -funsigned-char

carmine nacelle
#

I've just set it to libc::c_char trl

#

Kernel shouldn't care anyway

#

But why isn't it optimizing it out like on x86?

#

(I mean there was a flag to allow undefined symbols)

hexed knot
carmine nacelle
#

?

hexed knot
#

like it just didnt optimize out

#

because of luck

#

or yeah a compiler flag that made it ignore the errors

carmine nacelle
#

But I'm definitely not using opendir and stuff

#

Like it doesn't want it with C++

#

Ok, I need an ARM port to see if it's RISC-V skill issue or not being x86 skill issue

carmine nacelle
#

So RISC-V port is alive, and I've fixed ECAM

#

But there is a but

#

for some reason uACPI just quietly fails...

#

What the fuck

#

(I can smell UB and insane optimizations by clang)

#

@twilit talon

#

uACPI returns 7 (UACPI_STATUS_INVALID_ARGUMENT) in uacpi_finalize_gpe_initialization()

#

On RISC-V

#

Imma check x86 build just in case...

carmine nacelle
carmine nacelle
#

It's not ECAM

#

I'm gonna look at it again tomorrow

twilit talon
#

That said I should probably make it just return ok in this case

carmine nacelle
#

Do I ifndef UACPI_REDUCED_HARDWARE?

twilit talon
#

no

#

UACPI_REDUCED_HARDWARE is designed so that u dont have to ifndef anythign

#

u can just call finalize_gpe_initialization

#

I should just mark this as ALWAYS_OK

#

although what's interesting is ACPICA also does this

#

linux just doesnt check the return value

twilit talon
carmine nacelle
#

I was calling it before and it was not returning error

twilit talon
#

before what

carmine nacelle
#

Before updates...

#

Maybe I wasn't noticing it wasn't working though

twilit talon
#

yes

#

it cant possibly return OK on risc-v, never has

#

so tldr:

  1. on riscv, compile with UACPI_REDUCED_HARDWARE to strip useless code
  2. either don't call finalize_gpe_initialization on risc-v, or ignore its return value
#

because u cant finalize initialization of something that doesnt exist KEKW

carmine nacelle
#

But it shouldn't be invalid argument then (?)

#

UACPI_STATUS_NOT_FOUND meme

#

Ok, Rust also just worked on RISC-V

twilit talon
carmine nacelle
#

Maybe I'll add aarch64

#

I'm in mood for that

#

Can't be too difficult

twilit talon
#

same as risc-v except u have 99999999999 instructions for manipulating caches

carmine nacelle
#

(inb4 I get destroyed by non 4K pages)

twilit talon
#

it has 4k pages

plain jungle
#

aarch64 is quite different from riscv

twilit talon
#

it's the hard mode risc-v

carmine nacelle
#

Loongarch seems to be similar

carmine nacelle
#

(Raspberry Pi 4 and 1)

#

And raspberry pi 4 is systemready certified

twilit talon
#

it's obviously different from risc-v, but a lot of risc-v code on linux is just adopted cp arm/x.c .

plain jungle
#

what parts exactly?

twilit talon
#

but all regs and stuff are different ofc

twilit talon
#

idk, ive looked at the port a while ago

twilit talon
#

there's a ton more btw

#

this is like 30% of the output

carmine nacelle
twilit talon
#

yeah if u can just straight up copy most stuff maybe it's not abstracted away very well

carmine nacelle
carmine nacelle
#

(sounds fun)

plain jungle
#

It's not only weak ordering but caching in general

plain jungle
#

On aarch64 you can't just do unaligned accesses to devices or access mmio through page mappings with default cacheability etc

carmine nacelle
#

But I think that RISC-V's memory ordering is stronger

plain jungle
#

on risc-v the firmware is supposed to configure device memory using PMAs

twilit talon
#

we all know firmware can be trusted with that trl

plain jungle
#

well, this is the same on x86, really

twilit talon
#

yes but on x86 at least it generally works

#

on risc-v on the other hand, see limine framebuffer on risc-v

plain jungle
#

is that fixed?

#

the limine framebuffer?

twilit talon
#

nope

plain jungle
#

then you don't know if it's firmware misbehaving or not

twilit talon
#

we do because like

#

you can tell it's incorrect caching settings

#

some cache lines get flushed, others dont

#

also i remember someone mentioning u have to manually mess with PMA-related stuff on real boards

#

but maybe it's some other issue shrug

plain jungle
#

you can't mess with PMAs on real boards

#

because they're accessible to M mode only

twilit talon
#

Maybe I was lied to nooo

plain jungle
#

also, if the limine framebuffer thing is caching related, it should be easy to fix, right?

#

just map as uncached

#

didn't somebody try that already?

twilit talon
#

No clue, I think Marvin never got around to it

plain jungle
#

I can probably take a look at this when i get access to a board with a non-broken uefi

carmine nacelle
#

I've decided that I'll finally write an init server, which would listen to pmbus and start the drivers...

#

(among other things)

#

what I'm thinking about is how to store/represent properties, and I think I'll use tree for it, and yaml for config

carmine nacelle
#

(the plans have changed)

#

I'm porting to loongarch!

#

It's basically RISC-V...

toxic torrent
carmine nacelle
#

libc is almost compiling

twilit talon
#

"ported to loongarch"

#

linux has had a loongarch port since forever

carmine nacelle
#

Don't they have their own kernel fork?

twilit talon
#

Yes but its called AltLinux

#

like its literally linux

#

with their own local patches for some stuff

carmine nacelle
#

Like for elbrus stupidity

twilit talon
#

maybe what they meant is that they now have an iso for loongarch

carmine nacelle
carmine nacelle
#

Russian CPU KEKW

twilit talon
#

what was nice is they give anyone who wanted it an ssh server with that cpu

#

so u can try it out

#

via telegram or website application

carmine nacelle
#

But like how is one supposed to port operating systems to it

twilit talon
#

like which? for linux its natively supported

#

windows wont ever run on it

carmine nacelle
#

elbrus

twilit talon
#

which os i mean

carmine nacelle
#

anything that's not linux

twilit talon
#

why would they care like

#

its for the goverment

#

which uses linux

#

their own fork that has been verified via various crap

#

static analyzers etc

#

also it supports x86_64 emulation natively

twilit talon
carmine nacelle
#

Well, there will be pmOS and Menix KEKW

#

(how to attract the attention of all 3 letter agencies)

#

LLVM only has Linux KEKW

toxic torrent
toxic torrent
#

oh shit

#

i gotta do the loongarch mlibc port first

carmine nacelle
#

I've already ported my libc chad

#

I'm now porting kernel

pearl narwhal
carmine nacelle
#

Yes

#

And RISC-V

#

I mean I was thinking about eventually supporting 32 bit risc-v userspace with 64 bit kernel

#

And I might do the same with loongarch because why not...

pearl narwhal
#

if you do old world you might be able to get WPS Office running lmao

carmine nacelle
#

?

#

I don't get it

pearl narwhal
#

with some shims and syscall emulation

carmine nacelle
#

what are you referring to

pearl narwhal
#

loongarch abis

#

there's old world and new world

#

pretty much everything open source uses the new world so it's like the sys-v ABI for loongarch

carmine nacelle
#

what is the difference

pearl narwhal
#

but the proprietary OS(es?) made by loongson use the old world ABI

#

and the WPS Office joke is that there's a port of WPS Office to old world linux on loongarch

carmine nacelle
#

New world probably

#

Ok, the kernel already compiles (the arch-independent stuff that is)

#

I'm just missing paging, interrupts and timers

pearl narwhal
#

ooo Kylin, Loongnix and UOS are migrating to new world

#

so old world will die lol

carmine nacelle
#

Lol it has a wikipedia entry

#

(I mean it's serious)

pearl narwhal
#

hmm I thought callconvs were different between OW/NW but apparently not

#

most of the differences are linux syscalls

#

the only differences that should really matter are ELF differences and firmware differences

carmine nacelle
#

What is the point of this?

toxic torrent
#

linux code

#

typical

lunar island
#

theres probs an ifdef

twilit talon
carmine nacelle
#

I give up and will probably add framebuffer output to kernel

#

For boot logs and panics

carmine nacelle
#

thonk This is interesting...

carmine nacelle
#

So, in theory I should have all paging functions

#

Now I just gotta figure out the interrupt controllers + add flanterm to kernel

#

I guess it's time to resurrect this branch...

toxic torrent
#

gcon :D

carmine nacelle
#

?

toxic torrent
#

why put flanterm in the kernel

kindred venture
#

to be able to see kernel log messages before userspace is initialized

vale hinge
#

even Ironclad does that now lol

vale hinge
# toxic torrent gcon :D

bold of you to suggest people use a project that was never ported to !Ironclad and you probably never used yourself

wide spruce
#

yeah we had issues with early initialization on certain machines that required that output for early debug

toxic torrent
#

guh

wide spruce
#

we dont have a terminal that userland uses though, its just flanterm as a quick mirror of /dev/console

#

the quickest and roughest way to just get some text to screen before gcon hits

#

so if uacpi shits the bed, we can know instead of having a black screen on laptops

toxic torrent
#

i initially wanted to do the same but you raise a good point

wide spruce
#

like things fail, if it was fool proof I wouldnt have it, but its just such a pain to do bug reports without that

#

ive had like 20 people tell me at random moments that Ironclad doesnt boot and they have a black screen

#

what do I do

vale hinge
#

what i meant to say is that there are very valid reasons to want to have text/terminal output from inside a kernel way before userland is initialised

carmine nacelle
#

(maybe it does but docs are even more distributed than those of RISC-V)

#

Like there's no SBI debug output or 0xe9

hexed knot
#

you definitely have either pl011 or an 8250

carmine nacelle
#

But I can't just hardcode it for early debugcon

#

Like with x86 ns16550

hexed knot
#

yes you can

carmine nacelle
carmine nacelle
carmine nacelle
#

How do you handle kernel panics?

#

Like my solution is praying that it doesn't on physical HW, but it's not a good one

wide spruce
#

In terms of what, reporting to the user?

carmine nacelle
#

Yes

#

Like if kernel panics, you can't (easilly) ask userspace terminal driver to print it to the screen

twilit talon
wide spruce
#

What you can though is take over the framebuffer again and print it yourself

toxic torrent
carmine nacelle
kindred venture
carmine nacelle
hexed knot
wide spruce
hexed knot
#

this is how it works on literally all platforms (except kinda not really riscv, and kinda x86)

carmine nacelle
wide spruce
#

If it's mapped by userland we don't use it

#

Simple and sweet

carmine nacelle
wide spruce
#

As a microkernel you shouldn't panic much

toxic torrent
#

i mean same

wide spruce
#

If at all

toxic torrent
#

i dont know fuckall about what im doing lol

#

just asking

carmine nacelle
carmine nacelle
#

Note to myself and anyone doing loongarch: "If the exception processed is an error-related exception" means machine check exception

#

(so the interrupt handling is very similar to RISC-V)

carmine nacelle
#

Ok, so by the end of the day I'm missing

  • Page walking
  • Interrupt controllers
  • Floating point?
  • Exceptions
carmine nacelle
#

Rust is trolling me

carmine nacelle
#

Limine is trolling me...