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

1 messages ยท Page 8 of 1

carmine nacelle
#

This is fishy

#

Limine does .align 4?

vale hinge
carmine nacelle
#

PALEN-1:12?

#

I don't know if the address has to be shifted by 12, or be aligned to 4K

#

Like limine does this if I'm not missing something

vale hinge
#

.align 4 in non-x86 means shift by 4

#

so that's probably wrong

#

as per spec

carmine nacelle
#

yeah

#

But I can't find what linux does

#

Maybe the spec is wrong galaxybrain

vale hinge
#

probably the function happens to end up on a 4k boundary so that's why it works fine anyways?

#

either that or the hardware doesn't actually care about alignment

carmine nacelle
#

Linux seems to align to 64k

#

I guess I'll just align it to 4K then

carmine nacelle
vale hinge
#

yeah

carmine nacelle
#

and it didn't care..?

vale hinge
#

you can send a PR fixing this

#

or send me a patch (made with git format-patch)

#

if you want attribution for fixing this

carmine nacelle
#

Ok, I'll look into it tomorrow...

#

(It's almost 2AM where I live)

vale hinge
#

i'll just do it myself then

vale hazel
carmine nacelle
#

๐Ÿ’€

carmine nacelle
#

mul.d is a vector instruction?

carmine nacelle
#

clang is seriously trolling me...

#

Ok, I need gdb...

carmine nacelle
carmine nacelle
#

Fun, apparently it does have 5 level paging...

carmine nacelle
#

Ok, I'm not detecting the skill issue, but the paging is refusing to work

#

This is a bit strange...

twilit talon
#

loongarch?

carmine nacelle
#

Yeah

twilit talon
#

cool

#

how hard is it

carmine nacelle
#

The kernel just pagefaults

carmine nacelle
twilit talon
#

lol

carmine nacelle
#

The documentation is a bit difficult to comprehend at times

carmine nacelle
carmine nacelle
twilit talon
#

which

carmine nacelle
#

Software refilled tlb/split paging/direct mapping regions for example

twilit talon
#

how does limine work if its software refilled

carmine nacelle
#

It has a special exception for TLB misses, where CPU drops into mode without paging and you refill it

#

But like they give you special instructions which do it for you basically

twilit talon
#

interesting, is it really cheaper for chips to do this instead of handling it internally

carmine nacelle
#

But you can configure how many bits is each level and so on

carmine nacelle
#

But like otherwise it's normal page tables

twilit talon
#

so u can implement hhdm in software technically?

carmine nacelle
#

Yeah

#

Limine does that

twilit talon
#

cool

carmine nacelle
#

Wait a second

carmine nacelle
#

Bruh I crashed gdb

carmine nacelle
#

I don't get it

#

Page invalid exception for fetch operation: This exception is triggered when the virtual address of the
fetch operation finds a match in the TLB with V=0.

#

How am I messing up my page tables like that

#

It has to be something absolutely dumb...

carmine nacelle
#

Ok, my 3rd level has shit in it

carmine nacelle
#

I think my tlb configuration is off

#

lddir $t0, $t0, 2 is trolling me

#

wait, what the fuck, it's loading the page from 0x80001ff1

#

So I'm not supposed to be setting any bits in page directories?

#

Ok, this is really fucked

carmine nacelle
#

I don't get how it works, but I think I have paging...

carmine nacelle
#

This is interesting...

carmine nacelle
#

I think I've gotten paging to work...

#

Now I need to figure out the direct map thing...

carmine nacelle
#

So, DMW0 is choosing to troll me...

carmine nacelle
#

Good documentation

The hit is determined as follows: the highest 8 bits of the virtual address ([63:60] bits) are equal to the VSEG field in the configuration window register, and the current privilege level is available.

#

Someone is high

exception: 72 (Address error for Memory access)
(documentation doesn't mention anything about it, or I'm blind )

#

It was this...

#

ADdress error Exception (ADE): when the program has a functional error that causes the address of the instruction fetch or memory access instruction to appear illegal (such as the instruction fetch address
is not aligned on 4-byte boundaries, and the privileged address space is accessed), ADdress error Exception for Fetching instructions (ADEF) or ADdress error Exception for Memory access instructions 13 (ADEM) will be triggered.

#

Cool

#

Why does it get triggered though meirl

#

Like this address should be ok 90000000ebf8a000

#

I don't get it, why does it not work

For example, if PALEN is equal to 48 and DMWO is set to 0x9000000000000011, virtual address space
0x9000000000000000-0x9000FFFFFFFFFFFF will be directly mapped to physical address space 0x0-
0xFFFFFFFFFFFF at the PLV0 privilege level, the memory access type of which is consistent and
cacheable.

carmine nacelle
carmine nacelle
#

Linux docs are contradicting themselves...

#

Unless...

left dew
#

linux docs are linux docs

#

good resource until they aren't

carmine nacelle
#

I think it time to read qemu source

carmine nacelle
#

QEMU bug?

#

@toxic torrent can you test an image?

toxic torrent
#

sure

carmine nacelle
toxic torrent
#

always assume qemu is broken

#

though with loongarch this is sometimes actually the case

carmine nacelle
#

Does Linux not use DMWs?

#

It's checking bits [63:48] to be canonical, which is like not what you're supposed to do according to manual

carmine nacelle
#

It should show something and probably panic

toxic torrent
#

gimme a command

carmine nacelle
#

Not a bug

#

Nevermind

carmine nacelle
toxic torrent
#

qemu command

#

-cdrom doesn't work

carmine nacelle
#

I use this qemu-system-loongarch64 -m 2G -cdrom limine/pmOS.iso -smp 4 -serial stdio -bios ovmf-riscv64/RELEASELOONGARCH64_QEMU_EFI.fd -device ramfb -d int

toxic torrent
#

can i has ovmf pls

carmine nacelle
#

I'm on a train with bad internet and discord is taking an eternity to upload files

carmine nacelle
#

I have an idea

#

(well, not an idea, but a plan)

#

What the fuck

#

I think C++ is trolling me, except I've looked at assembly and it looked fine

#

So the top bit somehow does not get set??

#
ffffffff8000c0b8: 05 44 80 03      ori    $a1, $zero, 17
ffffffff8000c0bc: a5 00 24 03      lu52i.d    $a1, $a1, -1792
;     asm volatile("csrwr %0, %1" ::"r"(0x9000000000000011), "i"(CSR_DMW0));
ffffffff8000c0c0: 25 00 06 04      csrwr    $a1, 384

To me this is setting 0x180 to 0x9000000000000011

#

I am definetely setting it

#

The CSRWR instruction writes the old value of the general register rd to the specified CSR and updates the old value of the specified CSR to the general register rd
Oh, fun, very intuitive instruction name

#

bootlin elixir broken as usual

#

(I need to redo my exception handlers...)

#

Fun, almost missed my stop...

carmine nacelle
#

(I need to redo my exception handlers...)

#

(anyway)

carmine nacelle
#

I have something

#

My assembly is just UB

toxic torrent
#

guh

carmine nacelle
#

and it just pagefaults

#

but I maybe have flanterm

carmine nacelle
carmine nacelle
#

I've tried to fix framebuffer and it only made it worse, so I think I'm gonna proceed to getting the rest working and pretend it isn't broken

#

This just pagefaults for no reason...

#

I think the kernel really doesn't want to be running on this arch...

#

(should have ported to ARM first)

#

I have a theory on why this is happening...

#

Yeah ```
loongarch_cpu_do_interrupt enter: pc ffffffff8000af2c ERA 000000000d4cca60 TLBRERA ffffffff8000af1d exception: 2 (Page invalid exception for store)
loongarch_cpu_do_interrupt: PC 00000000ebe18000 ERA ffffffff8000af2d cause 2(refill)
, ESTAT 0000000000000000 EXCFG 0000000000000800 BADVA ffff800000218820BADI 0000000029812085 SYS_NUM 12288 cpu 0 asid 00000000000a0000
helper_ertn: TLBRERA ffffffff8000af2c
loongarch_cpu_do_interrupt enter: pc ffffffff8000af1c ERA 000000000d4cca60 TLBRERA ffffffff8000af2c exception: 2 (Page invalid exception for store)
loongarch_cpu_do_interrupt: PC 0000000000000000 ERA ffffffff8000af1c cause 2
, ESTAT 0000000000020000 EXCFG 0000000000000800 BADVA ffff800000219020BADI 00000000298080c5 SYS_NUM 3215360 cpu 0 asid 00000000000a0000

#

(The key here is BADVA ffff800000218820 in first exception and BADVA ffff800000219020 in the second)

#

I think I'm being destroyed by loongarch caching invalid TLB entries

#

(and it's also why flanterm breaks if I fix it...)

#

I think I'll fix it tomorrow

carmine nacelle
#

So I've decided to add early exceptions...

carmine nacelle
#

I fixed the framebuffer...

carmine nacelle
#

So the kernel is trolling me

#

Something is trashing $tp

left dew
#

how do you store the per cpu data ptr on loomgarch?

#

im doing loongarch too but i havent had the time to read the manual yet :^)

#

is there a csr you can use to restore it when entering the kernel from user space?

carmine nacelle
#

$s0 (aka $r23 has garbage)

carmine nacelle
#

Linux uses 8 of them

left dew
#

ah, interesting

carmine nacelle
#

RISC-V only has one, so I did the same thing

#

csrwr swaps the csr with the given general register, so you can save the thread-local stuff there

#

So it's like kernel gs base in some sense

left dew
#

i thought thats what csrxchg was for

carmine nacelle
left dew
#

or something like that

left dew
#

lol real

carmine nacelle
left dew
#

thanks for explanation

carmine nacelle
#

not doing rd = csr, csr = rj

#

More like

temp = csr & rj;
csr &= ~rj | rd;
rd = temp;
#

idk

carmine nacelle
left dew
#

nope

#

i only have experience with x86

#

but i want riscv too in my new kernel

carmine nacelle
#

Also machine check and tlb refill exceptions have their own save CSRs

left dew
#

how do you access kernel data structures from within the tlb refill handler?

#

since it switches to physical address mode

#

and kernel data structures use virtual addresses, or they should at least

#

maybe im overthinking

carmine nacelle
#

(or through pc-relative instructions)

#

I guess

carmine nacelle
#

So you basically have normal page tables (with bad names for their fields in the manual)

carmine nacelle
carmine nacelle
carmine nacelle
#

Very good documentation

kindred venture
#

what's wrong with those docs? seems perfectly fine to me

carmine nacelle
#

what is hint?

kindred venture
#

instruction category probably? it seems like the same kinda thing as the tables at the top of instruction docs in the x86 sdm, and its format is probably documented elsewhere in the manual

carmine nacelle
#

Maybe it's a me problem, but I didn't find it

#

Like for other instructions it's explained in their documentation

#

(Maybe I'm just spoiled by Intel docs)

kindred venture
#

oh hmm

carmine nacelle
#

I guess it's just an instruction encoding thing and only 0 is allowed

#

(since loongarch has 32 bit instructions a bit like risc-v)

#

(with fixed encoding formats)

carmine nacelle
#

I think I've reached userspace!

#

(after fixing some brainrot)

#

(can't even blame copilot for stupid code now cope)

#

(astral negative influence)

#

It's actually userspace and timer interrupt I think?

carmine nacelle
#

It was a timer interrupt

#

The documentation is a bit confusing...

left dew
#

writing la assembly is an experience

#

am i dumb or is the right way of moving data between two registers add.d $t0, $t1, $zero

#

risc architectures are so cruel :(

#

where's my mov $t0, $t1 nooo

hexed acorn
#

interesting that the assembler doesn't have a pseudoinstruction for that

left dew
#

im not sure if it does honestly, i just know that the manual does not specify one

#

also llvm-objdump says there's move but idk what it does

hexed acorn
#

inb4 rep movsb

left dew
#

hmm

#

might be exactly what im looking for

hexed acorn
#

{ 0x00150000, 0xfffffc00, "move", "r0:5,r5:5", 0, 0, 0, INSN_DIS_ALIAS }, /* or rd, rj, zero */

#

from a binutils patch

left dew
#

+ { 0x00150000, 0xfffffc00, "move", "r0:5,r5:5", 0, 0, 0, INSN_DIS_ALIAS }, /* or rd, rj, zero */

#

oh lol

#

we had the same idea

#

anyway, nice! good to know

#

replaced my add.d with move, so much cleaner now that i dont have to explicitly use $zero lol

carmine nacelle
#

Ok, I've gotten to userspace doing syscalls

carmine nacelle
#

But I didn't find a good list

#

(also, I'm pushing changes to dev branch all the time)

left dew
#

or not said but linked

#

and not a singular patch but rather the binutils source in general

#

the patch just tells you where to look

carmine nacelle
#

How did I miss that loongarch has a sane timer?

carmine nacelle
#

So, I need vector instructions...

#

By the look of things, the userspace is alive

#

(I think I'll figure that out tomorrow...)

carmine nacelle
hexed knot
#

huh?

#

thats interesting

#

its probably only on user/kernel reschedules though

carmine nacelle
#

Gotta love vscode...

carmine nacelle
carmine nacelle
#

What the fuck is this code

#

Ok, the kernel is trolling me

#

Something is corrupting memory...

carmine nacelle
#

nevermind, it was a bug in my interrupt handler

carmine nacelle
#

So what's crashing is Rust...

carmine nacelle
#

I think I'm in a mood of adding support for interrupt controllers...

carmine nacelle
#

(I think my interrupt handling mess needs to go)

carmine nacelle
#

Wow, my ns16550 driver just half-worked without touching anything

#

(I'm missing the interrupt memes)

#

Picking stuff up from ACPI

#

(also, I don't know how to handle them yet)

#

Like there is no obvious way to "return to userspace with interrutps on"

#

(although I guess I can just mask them)

carmine nacelle
#

the interrupts are too galaxybrain for me and are refusing to work...

carmine nacelle
#

PIC is just refusing to work

carmine nacelle
#

Time to figure out how to trace it I guess...

#

I don't get it; I think qemu doesn't bother to set up iocsr access to liointc?

#

Am I supposed to get this from AML?

#

(anyway, I think I'm just gonna support this for the time being...)

carmine nacelle
#

So QEMU wants BIO PIC...

pearl narwhal
carmine nacelle
#

no

pearl narwhal
#

jk

carmine nacelle
#

it has hpet though

pearl narwhal
#

lol really?

carmine nacelle
#

i haven't looked at it in depth, but the manual mentions hpet, and it seems to be very similar to x86

carmine nacelle
#

The ACPI is being weird

#

It says that BIO PIC GSI starts at 48...

#

I wonder if there's some sort of interrupt override thing

#

(Or I need to change the ACPI interrupt model)

carmine nacelle
carmine nacelle
#

So, through my rigorous investigation (a bunch of printfs), I have concluded that QEMU has EIO PIC, BIO PIC and MSI PIC

#

Now, I am completely clueless how I'm supposed to get it to work

#

Like ugh what do I do with this bruh

#

(So EIO PIC is the Loongson 3A5000 controller, and BIO PIC is 7A1000 controller)

twilit talon
#

Did you figure it out

twilit talon
carmine nacelle
#

MADT

carmine nacelle
twilit talon
#

in your case you have only one

carmine nacelle
#

What I don't quite get is why it doesn't give me address

twilit talon
#

Base Address?

carmine nacelle
#

Yeah

#

I've tried to use the one provided in the manual and nothing hallpened

#

(But with legacy controller)

#

Maybe QEMU doesn't implement it at all?

twilit talon
#

git grep

carmine nacelle
#

I'll try to figure it out

carmine nacelle
#

I mean except the cascade vector, this is what I expected

#

Time to add more pritnfs to qemu...

twilit talon
#

is this where ur reading from?

carmine nacelle
#

I'm trying to use iocsr instructions

carmine nacelle
twilit talon
carmine nacelle
#

I'm probably doing it wrong then

carmine nacelle
#

Idk, I want to get over with it, but I'm just feeling unwell and don't understand anything

#

(I think I'm getting close to a burnout, which is suboptimal)

carmine nacelle
#

I'll just panic if I detect legacy only system

#

The kernel first identifies the extended interrupt mode support by CSR[0x8][3], and then enables the
extended interrupt mode by register CSR[0x420][48].

#

Ok, I am writing to the right place, at least

carmine nacelle
#

It's not showing byte-width accesses

#

Is it what's messing everything up?

#

I am dumb

#

The dumbness has been ratified

#

I still have no interrupts nooo

#

This is just trolling

#

Maybe it needs to be level-triggered...

#

Like this is the only thing which might be broken

carmine nacelle
#

and it's impossible to debug because of pagefaults

twilit talon
carmine nacelle
carmine nacelle
#

So linux is doing some weirdness with its interrupts

#

Like UART is still conected to lioint

#

In newer generation Loongson CPUs, Extend I/O Programmable Interrupt Controller (EIO PIC) replaces the combination
of HT PIC and part of LIO PIC, and routes interrupts from BIO PIC and MSI PIC to CORE PIC directly. The
format of the EIO PIC structure is shown in the following table.

#

"part of LIO PIC"

carmine nacelle
#

I think qemu has no LIO PIC

#

What am I missing?

carmine nacelle
#

It was not 0

#

I think this SPCR is invalid?

#

I'm gonna add #ifdef to it

#

Nope, still no interrupts...

carmine nacelle
#

Desperate times call for desperate measures (I've added more printfs to QEMU)

#

This looks wrong

#

Yeah, it should 66 and not 112

#

This is broken

#

(except it's not)

carmine nacelle
#

Nevermind, I can't read

carmine nacelle
#

Maybe I do need BIO PIC after all...

#

Yeah, I think UART is connected to it

carmine nacelle
#

I think I'm starting to see the parallels

#

The EIO PIC is like LAPIC, and GIO PIC is like IOAPIC

carmine nacelle
#

Lol, they literally call it IO-APIC

carmine nacelle
#

I think the time has come to finally move interrupt allocation to the kernel

#

This sounds like lapic

In addition to being compatible with the legacy I/O interrupt method, the 3A5000 supports extended I/O
interrupts, which are used to distribute 256-bit interrupts on the HT bus directly to each processor core
instead of forwarding them through the HT interrupt line, increasing the flexibility of I/O interrupt usage.

carmine nacelle
#

Through breaking interrupts, I now have serial console...

carmine nacelle
carmine nacelle
#

(Time to add a new syscall)

carmine nacelle
#

What the fuck

carmine nacelle
#

Ok, so the interrupt controllers situation is insane

#

on loongarch

toxic torrent
#

where is it not tbh

carmine nacelle
#

Ok RISC-V you can just risc and use PLIC and don't think about it

carmine nacelle
#

I think I'm liking the new interrupts interface...

left dew
#

why result2

#

is it a different result than result? lol

carmine nacelle
#

Different type

#

because not Rust

left dew
#

why is it a different type

#

anyway that looks pretty nice

carmine nacelle
#

because it returns result + vector from the kernel

#

it's a struct

left dew
#

ah, well you don't seem to use it though meme

carmine nacelle
#

(my kernel always returns int64_t result and uint64_t value)

#

yeah

#

It should be the same as vector

left dew
#

you can also docpp if (auto res = ...; !res) { // ... }

carmine nacelle
#

I know

#

(sad that C doesn't have it)

left dew
#

you can emulate that

#

somewhat easily

#
if (({ int res = ...; res != 0; })) {
  // ...
}```
#

you can probably macro it away

carmine nacelle
#

but that's gcc extension

left dew
#

so what lol

#

who writes real C anyway

#

embrace GNU gnuslashtroll

carmine nacelle
#

The writes don't get to the controller

#

I'm going to sleep

carmine nacelle
left dew
#

sounds like you aren't writing the registers

carmine nacelle
#

What am I doing wrong kms

carmine nacelle
#

Could ACPI be just wrong?

#

Since Linux doesn't use it

#

(or does it? thonk)

carmine nacelle
#

(wrong source)

twilit talon
carmine nacelle
#

I had been bitten by ACPI tables being broken in QEMU

#

On RISC-V

#

I don't know why it doesn't work

twilit talon
#

tbh i have no idea where qemu assigns memory to these regions

carmine nacelle
#

thonk I don't have memory clobbers on inline assembly...

#

The assembly looks different

#

nope, still broken

carmine nacelle
#

Brain damage

#

(see line 337 and 357)

#

I think it's somewhat working...

twilit talon
carmine nacelle
#

I forgot an ~

#

This looks better

#

But still no interrupts nooo

#

(except that the enable bit is not what it should be)

#

(why am I failing so badly at this?)

#

I can't believe it...

carmine nacelle
#

So this is basically PLIC with extra complications...

carmine nacelle
#

I think I have interrupts!

#

Or not...

carmine nacelle
#

So it works, but I'm getting an interrupt storm

twilit talon
#

now do the ged thing

carmine nacelle
#

I want to fix interrupts nooo

carmine nacelle
carmine nacelle
#

I am too dumb for this...

#

Either I don't understand something (very likely) or QEMU dgaf about interrupt masking

carmine nacelle
carmine nacelle
#

Why is it spamming the interrupts then?

#

Ok, it works with the terrible thing...

carmine nacelle
carmine nacelle
#

What the fuck is this assembly

;     la     $t0, on_failure
ffffffff80003098: 8c 09 00 1a      pcalau12i    $t0, 76
ffffffff8000309c: 8c c1 d0 28      ld.d    $t0, $t0, 1072
;     st.d   $t0, $tp, 48 # CPU_Info::jumpto_func
ffffffff800030a0: 4c c0 c0 29      st.d    $t0, $tp, 48
carmine nacelle
#

But SPCR does tell me the interrupt level

#

Which is fun

#

Though it shouldn't matter

carmine nacelle
#

Also, doesn't limine do GOT relocations?

carmine nacelle
#

Omg, I think I know why fork is broken on RISC-V

#

(this was making the loongarch build hang)

eager rose
carmine nacelle
#

I've discovered that la is la.got by default

#

And my GOT is broken?

carmine nacelle
#

(I think I need a reschedule defer mechanism...)

carmine nacelle
# carmine nacelle (I think I need a reschedule defer mechanism...)

For context: since I don't switch contexts, the rescheduling could be a race condition since the task could appear on the other CPU, so on these syscalls, I set the result to success before the copy to user is completed, which overwrites the arguments on loongarch, risc-v and i686...

#

(which switches the task inside it)

#

But I think the loongarch build kinda fully works now

#

I just need to fix the other builds and also change the interrupt registering stuff

twilit talon
#

Does it have an _S5 btw

carmine nacelle
#

I haven't checked

#

I'm feeling very burnt out

twilit talon
#

Take your time to chill

carmine nacelle
#

And I have exams next week

#

I think I'll finish/fix the other ports parts so it's presentable enough to be in the main branch and doesn't linger on me, and take a break for a couple of weeks

carmine nacelle
carmine nacelle
#

I think I'll fix RISC-V memes...

carmine nacelle
#

(note to myself: qemu-system-loongarch64 -m 2G -cdrom limine/pmOS.iso -smp 4 -serial stdio -bios ovmf-riscv64/RELEASELOONGARCH64_QEMU_EFI.fd -device ramfb)

#

Uncool

#

It's trolling me

#

I'm not returning nullptr there...

carmine nacelle
#

Cool, my brain is fried from the loongarch assembly

#

I can't write RISC-V one anymore

carmine nacelle
#

(so I almost have fast syscalls on risc-v)

plain jungle
#

fast syscalls?

carmine nacelle
#

Basiccally doing memcpy on user memory and catching pagefaults

#

Instead of walking the page tables every time I copy from user

left dew
#

holy โ˜ ๏ธ

#

how have u went so far without a proper user memcpy

twilit talon
carmine nacelle
carmine nacelle
twilit talon
#

if u lock the address space

#

then its fine

carmine nacelle
#

I do

left dew
#

i mean yeah i guess, but it's kinda badddd

twilit talon
#

thats literally more lines of code than just catching a fault

carmine nacelle
#

It was a design skill issue

#

I'm trying to catch them now

#

Besides, it works on x86 and loongarch already

twilit talon
#

if loongarch is so good, wheres loongerarch

carmine nacelle
#

MIPS? trl

carmine nacelle
carmine nacelle
twilit talon
#

btw u should support smap/smep etc

carmine nacelle
#

Yeah

#

I even have hooks for them

#

I do support them on RISC-V

carmine nacelle
#

The kernel is choosing violence

#

I think everything is calling exit again nooo

#

No?

#

The screen and ns16550 drivers are just refuse to work...

carmine nacelle
#

actual brainrot

#

(this should be a0-a2)

#

so by the looks of things, the RISC-V port is also fully working now...

carmine nacelle
#

So the plan is to

  1. Fix x86 port, and by that I mean moving IOAPIC code to kernel
  2. Change the drivers to use that
carmine nacelle
#

Nice code

carmine nacelle
#

Cool, using auto in C feels magical...

#

the kernel is trolling me

#

It's tripple faulting

#

I think I need to take a break

#

It is trolling me hard

#

It's casually faulting with error 0 with instruction ... cmpq %rdi, 0x10

carmine nacelle
carmine nacelle
#

Fun, the kernel ooms and dies if I enable LAPICs nooo

carmine nacelle
#

This makes absolutely no sense

#

What the fuck

#

It has to be something extremely dumb

carmine nacelle
#

So somehow this is just broken...

#

I think I've caught it

#

There is no such thing as too many asserts

#

I was missing a ~ again

carmine nacelle
#

IOAPIC in kernel finally seems to be working...

carmine nacelle
#

fun, the 32 bit x86 port is dead for some reason...

#

it's not dead but interrupts are broken nooo

#

(Even though it shares the interrupt code with x86_64)

carmine nacelle
#

RISC-V and LoongArch are fully working

#

I think I'll fix the ia32 port (after taking a nap) and then push loongarch stuff to main

#

And maybe I'll write the GED driver after that

carmine nacelle
#

uACPI server hangs?

#

(probably a skill issue)

#

Or like doesn't hang, but it doesn't ack the interrupt for some reason

#

Maybe I broke something

carmine nacelle
carmine nacelle
carmine nacelle
#

EC stopped working??

#

i think the kernel is panicking...

#

Anyway, I merged the changes to main

#

Unfun...

carmine nacelle
#

Ok, I fixed it

#

But my Lenovo laptop still seems to be unable to recieve EC interrupts...

#

I have a suspicion my com driver is misconfiguring the baud rate...

#

interrupts are very broken

carmine nacelle
#

i have no idea why

#

and have very little motivation to fix them

#

(or do anything)

#

(maybe it's kernel panic)

#

Maybe I should announce my OS on Reddit trl

lunar orchid
#

๐Ÿ‘€๐Ÿ‘€๐Ÿ‘€

carmine nacelle
#

The kernel is hardcore trolling me

#

I've put a printfs around it, and there are no interrupts, at all

#

on physical hardware

#

like not even apic timer interrupt

carmine nacelle
#

Cool, the ns16550 driver has started working on my PC

#

In i686 build...

#

I have no clue of what's going on...

#

Still no SCI

carmine nacelle
twilit talon
carmine nacelle
#

Probably for the same reason that firmware remaps LAPICs

carmine nacelle
#

I think I've fixed SCIs...

carmine nacelle
#

So, I think I have kinda completed what I wanted (LoongArch port) and it would be best for me to take a break from osdev

#

The only thing missing from it compared to other platforms (x86, RISC-V) is SMP (since it's not supported by Limine), and I also wanted to write an ACPI GED driver for it, but I feel like I'm too burnt out to do it now

#

The next plan would be to write the proper init server, which would include listening to pmbus events and starting drivers, as they are discovered by ACPI/PCI/other buses, then finish the ext4 driver (in Rust) and try to get bash working

carmine nacelle
#

But I want to do GED...

carmine nacelle
#

I've decided to write an init server

carmine nacelle
twilit talon
#

you've just discovered the idea of a monolithic kernel!

carmine nacelle
#

no

#

process as a collection of threads

#

Idk what to do nooo

#

I'm in a design limbo

#

Like the issue is that I want to track processes in my init server, but I need process server for that, which can't then be tracked by init

#

Maybe I should merge them into one server trl

#

this would solve all of my problems galaxybrain

#

The only issue is that my init server is in C, and my processes server is in C++

#

And I don't like C

carmine nacelle
inland temple
#

systemd troll

carmine nacelle
inland temple
#

if you integrate it meme

#

not sure

carmine nacelle
#

I'm planning my init server to do it

inland temple
#

on managarm, once devices show up on mbus, posix creates the sysfs stuff for them, and they show up on udev

#

from where on out we use udev rules for starting servers

#

for systemd, we have a service that awaits for a keyboard, mouse and DRM card to be available before continuing to launch weston/kmscon

#

depends on how you define "integration" ig

twilit talon
carmine nacelle
#

yeah I guess that's cool

#

But too much work

covert apex
carmine nacelle
#

I think I'll merge the init and POSIX servers into one...

carmine nacelle
#

What if I want to port to ARM?

carmine nacelle
carmine nacelle
#

My vmm is deciding to troll me nooo

#

I think it's broken

carmine nacelle
#

I've found various bugs in my vmm

#

I have no idea how it didn't crash before

carmine nacelle
#

VMM now works properly KEKW

fringe grove
#

you think it does

#

but it doesnt

#

never belive the vmm

#

it only knows how to lie to you

carmine nacelle
#

I've put a bunch of printfs and it did seem correct

carmine nacelle
#

Small update: I've decided to move the port resolution by name into bootstrap server as well, and I think I can hook it into init server as well, which is pretty interesting I guess...

carmine nacelle
#

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

inland temple
#

mlibc is getting loongarch support soonโ„ข๏ธ

#

when switch to mlibc?

carmine nacelle
#

my libc and kernel supports loongarch without soonโ„ข๏ธ

toxic torrent
#

@carmine nacelle did you have to do anything special to port gcc to loongarch?

#

it's giving me this bullshit

#

my honest reaction

carmine nacelle
#

I'm just using clang ultrameme

#

I haven't tried it, I need to check

toxic torrent
#

lmfao

#

im tempted to just switch to clang as well

carmine nacelle
#

Like it and rust just worked no questions asked

#

(clang + lld+ libc++)

toxic torrent
#

that's crazy

#

got a link to your fork/patch?

carmine nacelle
#

It's in my gitlab

toxic torrent
#

kk

carmine nacelle
#

I think binutils also had just worked

#

(at least it compiled and GCC worked with "no issues" (except ocasional segafults))

toxic torrent
#

neat

#

do you define a dynamic linker anywhere?

carmine nacelle
#

I don't support it

toxic torrent
#

ah

carmine nacelle
#

(I need to work on it)

#

But I think you define it in os-specific C++ class thing

toxic torrent
#

yea

#

i think that's so much nicer

#

than whatever gcc is doing

#

also spec ๐Ÿคข

toxic torrent
#

okay yay it's building with the weird ass hack

carmine nacelle
toxic torrent
#

fyi i had to do this shit

carmine nacelle
#

in gcc?

toxic torrent
#

ye

#

cursed

carmine nacelle
#

isn't it what you're supposed to do?

toxic torrent
#

no

#

well not for the other archs

carmine nacelle
#

(I mean I don't use mlibc so that's what I was doing as well)

toxic torrent
#

only loongarch has this garbage hack

carmine nacelle
#

ok, idk

#

I don't have motivation to touch my gcc stuff right now

toxic torrent
#

don't bother

#

i think my llvm toolchain works as well so far, except it doesn't have a dynamic linker for some reason

#

like no interp

kindred venture
#

that all seems pretty standard, i imagine the only reason you didn't have to do it for anything else would be if mlibc support for those targets was upstreamed into gcc

toxic torrent
#

hm

#

it's weird they hardcoded this though

#

like, ever other target doesn't have this switch

kindred venture
#

i don't know if it is, i just don't know any other reason why that wouldn't be required for other targets

#

or well, the top hunk seems standard, the triplet_os=... thing is weird

toxic torrent
#

yes

#

that's what i mean

kindred venture
#

ah ok

toxic torrent
#

they unset the target for some reason

carmine nacelle
#

Small update: after a week being unmotivated and debugging it with no printf, I've managed to move "named ports" stuff to bootstrap daemon, and will be removing it from kernel shortly

#

after which the plan is to finally add handles/capabilities/whatever the name is to the IPC

#

I don't know how to name it so it's not too confusing

#

Right now I have ports, and I want to be giving out send "capabilities"/whatever I decide to call it

#

Mach calls it rights?

carmine nacelle
#

thonk I've looked at Mach docs and it talks about port rights namespace, which gave me an idea...

#

I have task groups, so I thought about associating port rights to them, but didn't want to do that because I would have to look up the task group, verify that the task is part of it, and then look up to port/right inside the tak group...

#

What I think I'll do instead is I'll have add a way to set the default task group for ports, which will just be a pointer, which kinda solves all the problems

#

So the libc will probably just set it to be the task group of the process, but you're free to redefine it if you want to...

#

But first I have to replace this atrocity (shared pointers for task groups) with RCU

#

(too many things to do nooo)

bitter wasp
carmine nacelle
#

the lock isn't the problem, I can easily replace it

#

My shared pointers impl is kinda bad and I'm trying to get rid of it

carmine nacelle
#

bruh my ports already used RCU...

#

(which is convenient I guess)

#

I think I know how I would implement the rights thing

#

Mach has a refcount, but I don't like it, I'll just have one right per task (group)

carmine nacelle
toxic torrent
#

awesome highlighting

carmine nacelle
#

average vscode experience

carmine nacelle
#

Nice types

carmine nacelle
toxic torrent
#

what's an RCU

carmine nacelle
#

Read copy update

plain jungle
#

an algorithm to manage lifetimes in concurrent programs

#

say, if you have a lock free linked list and you delete an element. you can only truly release the memory when no other thread can still have a pointer to it

#

and that's what RCU ensures

carmine nacelle
#

thonk I think I more or less have the idea of how I'm going to implement the rights thing...

#

and the interface should also be relatively nice, I'm going to add a (atomic) syscall, which allows to set the task group for the rights namespace by the thread, and I'm going to limit it to the caller thread and the task group it is in, so there will not be a need to use locks, or check permissions...

#

And for the kernel stuff, I'm going to create a task group, which would have the idle (and if I add them, general kernel) threads

#

Which could also be used for other stuff, like for example, at the moment I use the task groups to track threads in processes, and detect when a thread exits unexpectedly

carmine nacelle
#

I think I know how I'm gonna handle notifications about rights being closed (on the other side)

#

Don't know it it's the best solution, but I'll insert all the rights into a tree in the parent port (with my intrusive BST class), keyed by some internal ID, and I'll allow duplicate nodes there and do count() on their deletion

#

I like this better than keeping some common data structure (if that makes sense)

#

The send once rights (which I anticipate to be the most common/created and deleted the most I guess) will not have to do this

carmine nacelle
#

(also, I think this will solve the IPC balancing in multithreaded processes thonk )

carmine nacelle
#

What the fuck

toxic torrent
carmine nacelle
#

no

#

I think one is in global namespace, and the other is in kernel::sched

#

(I've just decided to add namesapces to kernel)

modest thistle
#

lol

carmine nacelle
#

Nice formatting again

fringe grove
#

but why you use light mode???????

#

are you ok?

carmine nacelle
#

I've gotten bored of dark mode

fringe grove
carmine nacelle
#

I think I'm finally ready to implement rights...

carmine nacelle
#

Small (not) update: I think I've burnt myself out, so there has been very little progress, and probably won't be for a few weeks

carmine nacelle
#

But on an unrelated note, I've ordered an ARM board, which should have UEFI support, so I think I will do an ARM port once I get myself together...

fringe grove
carmine nacelle
#

I think I'm going to drop Rust

#

Maybe I'll use it for stuff like NVMe

#

drivers

carmine nacelle
#

The issue is that clang doesn't support some architecture I'm considering targeting

toxic torrent
#

which

carmine nacelle
#

sh4

toxic torrent
#

never heard

carmine nacelle
#

Dreamcast

toxic torrent
#

when ppc

carmine nacelle
#

I've looked at it and it gave me MIPS vibes

carmine nacelle
toxic torrent
#

uboot

carmine nacelle
#

(someone could be me, but I can't be bothered)

toxic torrent
#

aarch64

carmine nacelle
toxic torrent
#

so?

carmine nacelle
#

I will target it

carmine nacelle
#

average C++

modest thistle
#

lol what is that XD

carmine nacelle
#

C++

modest thistle
#

why do you even need a ref to a pointer?

carmine nacelle
#

who said it was a pointer? trl

#

I mean I am getting a pointer

modest thistle
#

oh wait

#

you are getting the value

#

and then getting a pointer to it again

carmine nacelle
#

yes

modest thistle
#

that's cursed

carmine nacelle
modest thistle
#

the lambda is even more cursed

carmine nacelle
#

why

modest thistle
#

never saw a lambda like that

carmine nacelle
modest thistle
#

oh XD

#

why not keep r tho?

carmine nacelle
#

(tbh I could just return iterator here)

carmine nacelle
modest thistle
#

like, remove &*

#

isn't it the same?

carmine nacelle
#

yeah I could do it

#

tecnically not quite but yes

carmine nacelle
dense carbon
carmine nacelle
#

(I basically have my own intrusive tree type)

lunar island
#

thats not valid C++

carmine nacelle
#

vscode shenanigans

#

It's just auto

lunar island
#

ah the coloring is confusing

fast bolt
left dew
#

inline type hints provided by the language server

#

i agree the color scheme is terrible

carmine nacelle
#

Cool, my rights thing is becoming a concurrency nightmare

#

I think I'll be having to hold up to 6 locks at the same time ultrameme

#

(in one function)

lunar island
#

Why not just use a bitmap

#

and have a handle table

carmine nacelle
#

?

#

I want to allow sending up to 4 rights + reply right with each meesage

#

And the only feasable way to do it that I've come up with is by protecting each right with a lock

#

(Since I want them to do a bunch of stuff)

#

I'm not very clear where I could use bitmap in there

lunar island
#

Ah ok nvm

#

Yea I would just do one right per message

#

And one reply

carmine nacelle
#

I want at least two

#

I mean reply + right

lunar island
#

No?

carmine nacelle
#

The rights are per reciever chanel

#

And tied to the task group on the other end

lunar island
#

yeah

carmine nacelle
#

So they are not in a global namespace

carmine nacelle
#

(I don't remember which)

#

And since I'm having to take locks on both of them anyway (to pass ownership from right to a message), I might as well expand it to four

#

Since it would also be useful for drivers, where I can have a reply right, "service right" (e.g. so that the server can communicate with the driver), and some sort of public facing right, so that stuff can communicate with server directly

#

Idk

#

Maybe it's not needed thonk

#

But at least two should be nice

#

Anyway, I think it's going to be a neat system

#

I'm planning to have send once and send many rights, with ability to explicitly revoke them, some sort of notification to the sender if the right disappears, and notification to the reciever if sender closes it as well

#

So it should solve the permission issues and the issue of servers dying unexpectedly and not replying to messages

carmine nacelle
carmine nacelle
#

(at most)

#

(maybe I have too many locks in the kernel)

carmine nacelle
#

I think I need to finaly add continuations to the kernel...

#

Or maybe not trl

carmine nacelle
#

No, I do absolutely need some queue for them

#

Eventually

carmine nacelle
#

New fun problem/design decision, I can send rights, but how do I accept them? thonk

carmine nacelle
#

Somehow my rights stuff is working??

carmine nacelle
#

I guess now I just need to rewrite everything to use it...

fringe grove
#

yippe

#

that sounds like so much fun

carmine nacelle
#

My ARM hardware has arrived...

#

I think I'll steal NVMe drive from my old laptop

carmine nacelle
toxic torrent
#

oh shit

#

that's the rk3588-edk2 right?

#

i have the same for my rock 5b+

carmine nacelle
#

yes

#

so debian had installed itself, but had broken repos, and ubuntu installer is just refusing to boot?

carmine nacelle
#

ok, my os is completely destroyed after the IPC rewrite...

plain jungle
#

what are you changing?

carmine nacelle
#

I'm adding IPC writes

plain jungle
#

IPC writes?

carmine nacelle
#

Autocorrect bruh

carmine nacelle
plain jungle
#

rights in the sense of capabilities?

#

or access control bits?

carmine nacelle
#

Capabilities

#

Something like send rights in Mach

#

(but simpler)

carmine nacelle
#

I think my libc is really falling apart...

plain jungle
#

time to merge your libc into mlibc :^)

carmine nacelle
#

Yeah

#

I've been looking at mlibc recently

#

(though I have exams soon and don't have time to do this now)

#

But how does it handle os-specific libraries and stuff?

carmine nacelle
#

Like since my kernel API is weird and a lot of my stuff goes through IPC

left dew
#

and sysdeps are of course a way for mlibc to call into your kernel to allocate memory, open files or whatever

carmine nacelle
left dew
#

they map pretty closely to libc functions

carmine nacelle
#

(but didn't really search much)

carmine nacelle
#

idk how to explain it

left dew
#

well, as long as you can link against it from c++ code you should be just fine

#

you're gonna have to make it available to meson somehow

#

a simple meson.build to build them as a static library should do

#

so you can pull it in through a subproject and have it work with meson of course

#

again, managarm itself is a good example of how to do it since they rely on libraries from the managarm repo in mlibc

carmine nacelle
#

So like it's better to make it a separate library?

left dew
#

well, that's what i assumed it was already

#

alternatively, if you don't plan on using it outside (m)libc, and you want to replace your libc with mlibc, you can just copy the code into your sysdep directory and use it like that

#

i see include/pmos/ has the headers you probably need but i don't know where to find the actual sources lol

carmine nacelle
#

lib/libc

left dew
#

well, that's libc

#

that's not what i was looking for

#

but i don't think i need to look at it anyway

carmine nacelle
#

I don't have a separate library for it, but I should probably make it be so

toxic torrent
#

mlibc can install custom headers as part of the headers_only build target

carmine nacelle
#

Maybe I want to have it as a separate library

#

if I want to have 2 c libraries for some reason...

toxic torrent
#

though that probably won't work in upstream

plain jungle
#

It's also probably worth checking if it makes sense to integrate parts of your libc into mlibc

#

There may be areas where your libc is more complete

carmine nacelle
#

The issue is that my libc is in pure C

left dew
#

doesn't matter

carmine nacelle
#

Though yeah, this benefits everyone

left dew
#

code can be copied

carmine nacelle
#

I'll take a look

left dew
#

and adjusted to be c++

#

it's not that big of a deal

hexed knot
#

or just not adjusted

#

C is usually a subset of C++

left dew
#

aren't there some things that aren't valid c++ that are valid c?

#

i was mainly talking about that

hexed knot
#

i said usually

kindred venture
#

those are very very minor

#

things like implicit void pointer casting

hexed knot
#

and yeah very minor edge cases

left dew
#

yeah i know, that's why i said it's not a big deal to adjust it

carmine nacelle
#

But with C++ you need exception safety and stuff like that

#

?

hexed knot
#

not really

#

especially if you compile with -fno-exceptions

#

which mlibc probably does?

left dew
#

iirc it does, yeah

plain jungle
#

yes

carmine nacelle
#

Fun, I'm trying to write nothrow C++ wrappers for my IPC stuff, and it's really obnoxious with stl

#

I wonder if I should roll my own vector (again)

carmine nacelle
#

I think most of the OS compiles with the new IPC functions?
I just need to fix Rust rust

carmine nacelle
#

Somehow this is promising

#

By the look of things, this is a blatent nullptr deref?

carmine nacelle
#

Somehow it's not in the order that I expected it to be?

twilit talon
#

this is ub lol

carmine nacelle
#

nah

#

it was in the right order

#

I was just dereferencing nullptr

twilit talon
#

the order of evaluation is undefined here

carmine nacelle
#

I though that functions were evaluated from right to left?

twilit talon
#

wrong lol

#

same reason why a++ + ++a is ub

carmine nacelle
#

fun

#

Ok, now everything just fails

kindred venture
#

With && and || being the obvious exceptions

hexed acorn
#

order of argument evaluation is undefined

#

oh i was scrolled up

hexed acorn
carmine nacelle
#

I think I'm getting somewhere...

#

I'm dumb

carmine nacelle
#

ok, both the kernel and userspace are trolling me now

carmine nacelle
#

brain damage detected

#

Now this is fun...

carmine nacelle
#

Now I actually have no words

toxic torrent
#

is not a keyword

carmine nacelle
#

It is

#

It was supposed to be one not

modest thistle
#

same as "and" = &&, "or" = ||

twilit talon
modest thistle
#

it does recognise it tho

#

it just negates the negation

twilit talon
#

there's a c++ header that adds a macro for not

#

for users that dont have ! on their keyboard

#

its not an official keyword

#

dont use it

modest thistle
#

ik and and or do not require any header

twilit talon
#

really? thats cool

modest thistle
#

unless it's a c23 only feature

#

bc rn i am using them with no header

carmine nacelle
carmine nacelle
#

What if I do a GPU driver?

#

(I've gotten myself an ARC card)

carmine nacelle
carmine nacelle
#

Clang is being dumb...

#

Very silly compiler

carmine nacelle
carmine nacelle
#

I'm starting to suspect that it might be a deadlock

#

(I need a watchdog timer...)

carmine nacelle
#

I'm losing my mind

carmine nacelle
#

It looks like the userspace is at fault...

#

(pointer infestation)

#

(I've no idea what's going on)

#

The userspace has gone insane

#

and the assembly looks sane

#

(I think I kinda know what's going on)

#

Insanity

#

(instead of loader_port_name, it should be create_result.right)

carmine nacelle
#

After a lot of printfs, I think I have userspace back...

carmine nacelle
#

Now I just actually need coroutine abstractions around my IPC nooo

carmine nacelle
#

I think that excluding the printf weirdness, my IPC rights thing is fully working?

#

this feels like it's readin from heap or something

#

(I think I know what's up)

#

That were non null terminated strings

carmine nacelle
#

thonk maybe I want to get 32 bit risc-v userspace working?

carmine nacelle
#

brain damage

carmine nacelle
#

Ok, the loongarch port is not as dead as I expected

#

I think it's a skill issue of my libc...

carmine nacelle
#

"But Rust is memory safe"

#

Cool, it jumps to 0 in panic

#

And I really don't feel like debugging that right now

#

I think my printf is not returning the right size

#

(that's my suspicion)

#

Maybe I should check ia32 build first

carmine nacelle
#

So, I'm done with studying

#

Which means it's time to fix Rust

#

And then add more stuff

#

I think the top priority would be the init server

carmine nacelle
#

Cool, Rust is just trolling me

toxic torrent
#

when is it not xd

carmine nacelle
#

thonk maybe Rust isn't the issue??

#

I think this is a C skill issue