#OBOS (not vibecoded)

1 messages · Page 39 of 1

flint idol
#

i also might remove the dependency on the popcount instruction

#

for timer IRQs I will be using the lapic timer on the bsp

flint idol
#

oh and while im making changes to the kernel im also gonna make it so that my tcp sockets can shutdown on close asynchronously to avoid having to send a reset

#

what I currently do on tcp socket close is reset the connection

real pecan
#

Or maybe its stable now actually

flint idol
#

and what u r testing

#

for example it might hang on real hardware with smp

#

or maybe it will hang on real hardware with smp disabled

#

it may also crash if you blow on it wrong

#

but generally it is better

#

than it was in February

#

there have been more safety measures added for multithreading

#

mostly with initialization of waitable objects

#

i.e., mutexes, events, etc.

#

oh yeah a day or two ago I added file moving to the ext2 driver

#

what i did is i made it delete the old entry and replace it with a new entry in the new parent

#

and when im done my timer interface changes

#

I think i will finally

#

add usb support to obos

#

starting with xhci

real pecan
#

That's good

flint idol
#

maybe I'll also add ehci and uhci support once I understand how usb works

#

on a general basis

#

after that I might port sshd

#

or i might work on fvwm3

flint idol
flint idol
#

bruh

#

why is cpuid 0x15 returning all zeroes

#

in qemu

#

cpuid leaf zero

#

reports

#

it exists

#

cpuid 0x80000007 reports invariant tsc as existent

flint idol
#

im gonna continue this

#

tomorrow

#

gotta sleep

flint idol
#

ive mastered the art of zoning out

#

im not gonna be consciously aware of my actions at school until I get back home

#

its really convenient when I want to skip through parts of the day

#

currently i have a few hours left until I fade back into consciousness

uncut narwhal
#

you can get tsc freq on qemu from the hypervisor leaves if youre under a hypervisor instead of using tcg though

#

i spent like a week trying to figure this exact issue out and getting mad over it lmao

#

qemu just doesnt implement it for some reason shrug

#

it sucks

flint idol
#

i implemented the thing

#

for calibration

#

and it's pretty accurate

#

and i just pushed the inv. tsc code

uncut narwhal
#

god i wish qemu implemented leaf 0x15

#

might try to make a patch for that sometime tbh

flint idol
#

ok so i made doom use rdtsc

#

and the performance is exponentially better

#

and also the kernel feels a bit more responsive

flint idol
#

kms

#

why

#

does

#

it

#

have

#

to

#

be so hard

#

for the kernel to keep track of a GODDAMN NUMBER

#

FHSDUGHJDSLIHNFDIP

#

ok fixed it

stark sigil
#

lol pi

flint idol
stark sigil
flint idol
#

im writing an ifconfig command

knotty totem
#

unironically why did linux switch to iproute2 🥀

flint idol
knotty totem
#

then name it smth different

#

netconf maybe

frigid tide
#

configip trl

flint idol
#

fun fact

#

obos cannot communicate with another obos

#

over tcp

flint idol
#

i named it ||obos-ifconfig||

#

LoC update

#

to whomever it concerns (absolutely no one)

vale nymph
dense vigil
flint idol
#

oh well I'll just add a kernel cmdline option to allow using cpuid 0x15 for the tsc frequency

dense vigil
#

is it even worth it when calibration + maybe 3 rounds + average is fine?

#

that laptop is pretty new too. almost no CPUs properly support said leaf

trim bay
# dense vigil

this code will most likely not work due to an integer overflow

#

and due to integer division inaccuracy

#

instead of ecx * (ebx / eax) (which does a 32 bit multiplication with one of the operands being rounded) you should do ((uint64_t)ecx * ebx) / eax, which does a 64 bit multiplication and division and only rounds the final result

dense vigil
#

It was close to an okay value

#

Oh wait my USB is missing yaaar il test it later if i find it

#

But that is probably why it broke

#

Bonk me with a stick

flint idol
#

i haven't done driver dev

#

for basically a year

#

god damn it

flint idol
#

these people are fucking crazy

#

this specification is insane

#

wtf is a trb and why do we need so much of them wtf

#

okok that makes sense now

flint idol
#

im hoping by the end of the day ill have so much to show as like. a completed transfer on xhci, or at least port enumeration

#

i feel like the people at intel coulda designed the TCBs in xhci to be better

#

but i got no better suggestions rn so i cant really be talking

flint idol
#

man is writing structs dull

#

ok done writing structs

stark sigil
#

you get to think for hours about what crap you put into a uint64

dense vigil
#

There it’s a single bit

#

And you can put more for more flags and it will pad it properly to not take up too much

#

And you can access them without bit shift ops

stark sigil
#

also yeah ik bit fields exist

dense vigil
flint idol
dense vigil
flint idol
#

in c yeah

#

compiler can do whatever the fuck it wants with that, in theory

#

although it does have to follow the abi

dense vigil
#

Of course it can

#

Of course

#

Would that cause issues for internal code and that’s all compiled by one compiler?

trim bay
#

if the bitfield is only accessed by code you're compiling it's fine

#

the issues occur when you use bitfields for hardware stuff

#

like page table entries, device registers, acpi tables, etc

stark sigil
#

true

#

but attribute packed

flint idol
#

it's

#

it's all making sense now

stark sigil
#

ik thats probably gcc (and also clang) only but like

flint idol
#

xhci is making sense now

stark sigil
flint idol
#

what was that one meme

#

with like

#

idk

#

how to explain it

flint idol
#

not it

stark sigil
#

idk either 😔

flint idol
#

yeah trying to remember what it looks like is giving me SIGSEGV

#

OHHHHHHH it all makes sense now

dense vigil
stark sigil
#

even for internal things i do it sometimes

#

space savings 👍

dense vigil
#

That’s bad for some things because it slows things down with misaligned memory access or some shit?

stark sigil
#

i mean idk fair but still

dense vigil
#

Though speed isn’t relevant if you aren’t doing it often

#

Esp with this

flint idol
#

wait so if im not mistaken:
command TRBs go in the command ring
while transfer TRBs go in the endpoint TRB

#

yeah that makes enough sense

flint idol
#

how tf does the event ring work

#

specifically the "Event Ring Segment Table (ERST)"

#

ok i get it now

flint idol
#

ok well im testing it

#

and im not getting any IRQs

#

idk if it's the xhci driver

#

or the msi-x implementation

#

i know that msi works

#

and when i use the PCI IRQ pins, the kernel constantly gets IRQs

#

but the xhci controller never reports any IRQs anywhere

flint idol
#

i hate reading c++ code

flint idol
#

so like

#

this makes no sense

knotty totem
#

what's up though?

#

like, what are you trying to do?

flint idol
#

well im trying to get IRQs from the xhci controller

#

to no avail

#

idk if it's MSI-X or the xhci driver

#

and i have no way to test MSI-X

#

fuck it im just gonna debug qemu to see what's up

#

well it's not the xhci driver

#

it's MSI

#

it isn't MSI, nor the xhci driver

#

i am a dumbass

flint idol
#

well i can receive TRBs now

flint idol
#

today I shall continue

#

with xhci

#

and i will be initializing ports today

#

and handling device connections and disconnections

#

and after that I will be adding an interface to send TRBs

flint idol
flint idol
flint idol
#

and I think it is safe to have the different packet types be the TRBs described by xhci spec section 3.3

#

and i will also start on the usb stack

#

starting with adding kernel functions like Drv_USBDeviceAttach and Drv_USBDeviceDetach

#

and i will also add a field to the driver header for recognized usb class codes nstuff

#

for pnp

flint idol
#

I will likely add a function to the driver function table like:

void(*on_detach)(dev_desc dev);
obos_status(*on_attach)(dev_desc dev);```
#

I might even use that for pci as well

flint idol
# flint idol for pnp

I will also likely have a method for userspace to be signaled that a usb device was attached so that it can syscall and get the kernel to load the appropriate drivers

#

i don't think im gonna expose xhci controllers to devfs

#

at least not directly

flint idol
#

except those probably wont be hotpluggable

flint idol
#

ok so

#

queuing TRBs is not working

flint idol
#

ok queuing TRBs works

#

im working on port initialization

#

topology defined
well thanks? now how do I FIND OUT THE GODDAMN TOPOLOGY, HUH XHCI?

real pecan
#

Who knows

flint idol
#

(the logs that are not prefixed with [ DEBUG ] logs are from qemu)

stark sigil
#

logs 👍

flint idol
#

logs indeed

stark sigil
#

i mean i think your driver works

flint idol
#

im writing the base for the usb stack rn

stark sigil
#

cool

flint idol
#

and i think it can also initialize the control endpoint

#

and it can send control TRBs as well as endpoint TRBs

stark sigil
#

fire

flint idol
#

anyway

#

i have no idea how usb hubs are supposed to work

#

but who needs those anyway?

stark sigil
#

i need them'

#

i need more usb ports than i have

dense vigil
flint idol
#

yes

#

im gonna do hubs later i want to get this to work first

flint idol
#

neat, i got another star

#

shoutout to the guy who just starred

#

me

#

and to everyone else who starred me

#

tis much appreciated

knotty totem
#

For some reason I hadn't started it yet

flint idol
#
typedef enum usb_trb_type {
    USB_TRB_NORMAL,
    // only legal for endpoint zero (control)
    USB_TRB_SETUP,
    USB_TRB_ISOCH,
    USB_TRB_NOP,
    USB_TRB_CONFIGURE_ENDPOINT,
} usb_trb_type;

// TRB Direction is defined by irp.op

typedef struct usb_irp_payload {
    usb_trb_type trb_type;
    union {
        struct {
            struct physical_region* regions;
            size_t nRegions;
        } normal;
        struct {
            struct physical_region* regions;
            size_t nRegions;
        } isoch;
        struct {
            struct {
                uint8_t bmRequestType;
                uint8_t bRequest;
                uint16_t wValue;
                uint16_t wIndex;
                uint16_t wLength;
            } OBOS_PACK;
            struct physical_region* regions;
            size_t nRegions;
            // TODO: Return status in some way from the status stage TRB (xhci-only)? 
        } setup;
    } payload;
} usb_irp_payload;```
#

this is what i have in mind

#

for the usb stack so far

#

i mean like

#

the first layer

#

or whatever

#

idk what configure endpoint will look like yet

knotty totem
flint idol
#

probably will just be empty

#

ah

uncut narwhal
#

just realised i somehow hadnt starred obos yet either lol

flint idol
uncut narwhal
#

as you can see i fixed that

flint idol
#

yes

flint idol
#

marker

flint idol
#

yay

#

anyway before i continue with the usb stack

#

i need to implement port detaching

#

in the xhci driver

flint idol
#

i just pushed some code for the usb stack

#

as well as some xhci code

#

now time to implement xhci IRPs

#

but first

#

i want to add a submit IRP function for the USB stack

uncut narwhal
#

glad im not the only one using IRPs for io

flint idol
#

IRPs my beloved

uncut narwhal
#

its such a good pattern

#

so much so that the zig standard library is migrating to basically IRPs for io lmao, even outside of osdev context

flint idol
#

i just pirated the usb3 spec

#

letsgo

flint idol
#

todo for tomorrow: get endpoint transfers to actually work

weary hound
#

and on the root port you know which one it is because you got an event for it

flint idol
#

oh ok thanks

flint idol
#

but my control transfers are not working (qemu asserts and dies)

flint idol
#

ok well

#

now i am getting CC_STALL_ERROR on my transfers

#
usb_xhci_fetch_trb addr 0x00000000620db000, TR_SETUP, p 0x0012000001000006, s 0x00000008, c 0x00030841
usb_xhci_fetch_trb addr 0x00000000620db010, TR_DATA, p 0x00000000618b8000, s 0x00020012, c 0x00000c01
usb_xhci_fetch_trb addr 0x00000000620db020, TR_STATUS, p 0x0000000000000000, s 0x00000000, c 0x00011021
#

for reference im tryna send a GET_DESCRIPTOR request

#

i think i see why now

#

ok fixed it

#

i now receive the device descriptor

#

but it seems incomplete

#

so im gonna actually properly initialize the device first and come back

flint idol
#

hm

weary hound
#

class code 0 means determined by interface iirc

flint idol
#

thx

#

lets go

#

the usb thing configured the port

flint idol
#

i added some code so that

#

the kernel can attach drivers to usb devices

#

although, automatic driver loading for usb is not yet implemented

#

i need to implement aborting IRPs if the port is detached

#

im thinking of having an extra event pointer in the IRP for the controller to set when a port is detached

#

then Drv_USBIRPWait will wait on both events

#

(ill probably also do the same for normal IRPs)

#

did that

#

now

#

in theory

#

i have all i need to implement a keyboard driver

#

so ig that's what im gonna do

#

implement a usb keyboard driver

dense vigil
#

Because you don’t need a PS/2 keyboard

#

That’s gonna be so cool

flint idol
#

assuming the kernel boots on modern hw

#

then yeah

dense vigil
#

Btw do you handle a keyboard that exposes there virtual keyboards?

flint idol
#

(the kernel currently only boots on some haswell-era devices lmfao)

dense vigil
#

Because a lot of gaming ones

dense vigil
flint idol
#

no clue KEKW

dense vigil
flint idol
#

i tell myself "ill get modern hardware to boot eventually"

dense vigil
#

What does it do on modern hardware

#

What kind of crashes

flint idol
#

hangs sometime in really early boot

#

like before the fb or gdt is initialized

#

(fb is inited before the gdt lol)

dense vigil
#

Do you use flanterm? You can use its bump allocator to have it before any kernel shit starts to print things

flint idol
#

i think flanterm is the problem here btw

#

i think i dont give it enough memory for the bump allocator

dense vigil
#

Do you use a smaller font perchance?

flint idol
#

(i made the bump allocator region configurable for flanterm)

dense vigil
#

I had this exact same issue

flint idol
#

i use the default font currently

dense vigil
#

If the screen was bigger than 720p it would break

flint idol
#

and flanterm gets 16M of memory

dense vigil
#

Because i had an 8x8 font

flint idol
#

because if i dont see logs then it very well could be that

flint idol
#

well

dense vigil
#

Are you giving it too much memory??

#

I give 1.5mb

#

Aswell for the default font the normal amount should be fine because it scales on more then 1080p

flint idol
#

no such thing as too much memory

dense vigil
#

On the BSS maybe?

flint idol
#

especially when my fb is memory

flint idol
#

the memory

dense vigil
#

Wait huh

#

Why do i feel like this is cursed PSP1G_pspTrollar

flint idol
#

for limine i just make it load an empty file

#

maybe it is

dense vigil
#

PSP1G_pspTrollar i think this is why it’s breaking

flint idol
#
static struct {
    uintptr_t address;
    uintptr_t size;
} Arch_FlantermBumpAllocator = {};
static void *flanterm_malloc(size_t sz)
{
    static size_t bump_off = 0;
    if ((bump_off + sz) > Arch_FlantermBumpAllocator.size)
        return nullptr;
    void* ret = (void*)(Arch_FlantermBumpAllocator.address + bump_off);
    bump_off += sz;
    return ret;
}
static void flanterm_free(void* blk, size_t sz)
{
    OBOS_UNUSED(blk && sz);
    return;
}```
dense vigil
#

Flanterm has an internal bump allocator it uses

flint idol
dense vigil
#

May be worth trying that?

#

Well yeah but PSP1G_pspTrollar

flint idol
#

i override it.

dense vigil
#

And then make a PR of it works

flint idol
#

gl

dense vigil
#

What’s the process for building it and shit

flint idol
#

obos is known for having a shit build system

dense vigil
#

Just download and run make right PSP1G_pspTrollar

flint idol
#

should work

dense vigil
#

repo link?

flint idol
dense vigil
#

should i use the xhci branch?

flint idol
dense vigil
#

hope this isnt a virus trol

#

shit i dont have cmake insralled XD

flint idol
#

lol

flint idol
dense vigil
#

im too lazy

flint idol
#

tell me if u find bugs trl

dense vigil
#

il just sue ya

#

if its a vrius

flint idol
dense vigil
#

this is fineee

dense vigil
flint idol
#

oh shit

#

it booted a bit

#

with the bigger flanterm buffer

#

now it is hanging trying to initialize the scheduler timer

dense vigil
#

IL be doing the fixing trol

#

whats the build issue

flint idol
dense vigil
#

how should i ignore it to get an ISO?

flint idol
#

wdym

dense vigil
#

make[2]: *** No rule to make target '/home/evalyn/Documents/Programming/C/obos/config/initrd.tar', needed by '/home/evalyn/Documents/Programming/C/obos/out/obos.iso'. Stop.

flint idol
#

create that file

dense vigil
#

XD

flint idol
#

then cd into scripts, run generate-initrd-x86_64.sh

#

then build again

#

then you should have a bootable iso

#

that should crash because it failed to load init

dense vigil
#

cp: -r not specified; omitting directory 'out/init' this stuff broke

#

dont make me fix it

#

im gonna have to fix this

flint idol
dense vigil
#

it asked for it

flint idol
#

doesnt mean its a directory lol

#

its the init program

#

which doesnt get compiled with clang enabled

dense vigil
#

wait what

flint idol
#

what

dense vigil
#

what am I doin yaaar

flint idol
#

the script worked

#

dw

dense vigil
#

this is enough to work with

flint idol
#

this is off master?

dense vigil
#

yes

flint idol
#

uhh I'll fix that

dense vigil
#

unless i fucked that up

flint idol
#

no thats a bug in the kernel on master

dense vigil
#

ahhh

flint idol
#

also r u gonna test it on amd

#

if so

dense vigil
#

i have amd and intel machines

flint idol
#

then that wont work most likely

dense vigil
#

what wont?

#

btw how tf did you get build IDs to work?

#

they always fuck up on my kernel

flint idol
#

amd

dense vigil
#

what messes up on AMD?

flint idol
flint idol
flint idol
dense vigil
flint idol
#

no

dense vigil
flint idol
dense vigil
#

oh

flint idol
# dense vigil this

I just get cmake to run a command with git that defines a macro called GIT_HASH or something

#

idk

dense vigil
#

broken .gitignore btw

flint idol
#

oh well

dense vigil
#

care if i add it into there

#

or just ignire it

flint idol
dense vigil
#

where do you init flanterm

flint idol
#

entry.c

#

also like

#

flanterm works

flint idol
#

im debugging that rn

#

if u want to try out obos u can use xbps to install packages btw

dense vigil
#

@flint idol

#

Works on my machine

#

Let me try and

#

AMD

#

Yeah it really dosnt like AMD

flint idol
flint idol
#

what clang version are you on?

dense vigil
#

My AMD 5700x hangs at startup on flanterm

dense vigil
#

I’m on cachyOS

flint idol
dense vigil
flint idol
#

what clang version

dense vigil
#

Let me reboot

flint idol
#

I got no clue

dense vigil
#

Same lmao

#
 evalyn@EvalynPC  ~  clang --version
clang version 21.1.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
flint idol
#

thx

flint idol
#

im gonna try and reproduce this

dense vigil
#

btw it still works on my laptop without the flanterm patch

#

just the same callback bug

flint idol
#

on obos

dense vigil
#

Giving more memory fixed it then?

flint idol
dense vigil
#

Though wouldn’t stock flanterm use less memory than this idk?

#

Lmk if you need me to inspect anything else on my hardwares

flint idol
#

the amount of memory it uses scales with the display resolution tmk

stark sigil
flint idol
#

and my display resolution is pretty massive

dense vigil
#

Stock flanterm has it fixed and it’s seperate from display resolution

#

It dosnt memory per pixel but somthing else iirc?

flint idol
#

well flanterm does double buffer

dense vigil
#

The default buffer 100% could not fit a 1080p screen

dense vigil
flint idol
#

I have no clue why giving it more memory fixes it

flint idol
flint idol
#

im not mintsuki

stark sigil
flint idol
stark sigil
dense vigil
#

Which I mean either way is fucking cursed as shit rather than just using the built in one imo

#

And idk how it interacts with other things but

flint idol
#

flanterm init has the malloc and free parameters for a reason

dense vigil
#

Loading an empty file. And then binding it to a bump allocator for flanterm. Isn’t cursed?

#

Why not use standard malloc and frees?

stark sigil
# flint idol how

terminal library's memory manager works better for terminal than other memory manager idk

stark sigil
flint idol
#

before anything is initialized?

dense vigil
#

So will the built in bump allocator 😭

dense vigil
flint idol
#

ok cool

dense vigil
#

It’s not worth dying on this hill

#

Do what you want XD

stark sigil
# flint idol ok cool

if you're fine with your fart wasting space then why aint you fine with mintsuki's almighty memory manager 9000

flint idol
stark sigil
#

mods, get this guy out

dense vigil
#

I wonder how mint would react to this kind of usage of flanterm and limine

stark sigil
#

he aint important anyway trl

stark sigil
#

oh no

#

i mean they will surely react to that

#

probably

flint idol
#

me and mint go waaay back trl

#

(not really)

dense vigil
#

Mint is on my friends list technically PSP1G_pspTrollar

flint idol
#

ANYWAY the kernel hangs sending an IPI

flint idol
#

I told someone thats for sure

dense vigil
stark sigil
dense vigil
#

Did they say bravo good idea this is super good and intelligent

#

I lowkey just wana know why you don’t think this is cursed? And how it is better

#

Like what’s the reasoning

flint idol
#

it isnt cursed because of its origins

stark sigil
flint idol
#

and the reason I ever overrode the flanterm bump allocator was because in some cases

flint idol
stark sigil
#

oh

flint idol
dense vigil
#

I’ve never had that happen though i don’t use large monitors

#

What is your monitor size?

flint idol
stark sigil
flint idol
#

i think it was a normal monitor

#

but a different font

stark sigil
#

was the font smaller

flint idol
#

no clue

#

I wrote this code

dense vigil
flint idol
dense vigil
#

Can you try my kernel which uses the bump allocator

#

And see if it also crashes on you?

flint idol
#

if you have an iso download sure

dense vigil
#

Make sure to grab latest

flint idol
#

damn it now I actually have to do it

dense vigil
stark sigil
#

bad apple is everywhere

dense vigil
#

My kernel best kernel

#

Best VFS ever too

stark sigil
#

every time i see bad apple in the top right of the screen i get ptsd

dense vigil
#

Is my kernel just known as the bad apple kernel lmao

stark sigil
flint idol
#

no

dense vigil
flint idol
dense vigil
#

And the kernel will be called bad apple

dense vigil
dense vigil
#

You don’t have a serial port

#

Show full screenshot of logs

stark sigil
dense vigil
deep ember
stark sigil
stark sigil
deep ember
dense vigil
stark sigil
stark sigil
#

the docs are PAINFULLY hard to find

dense vigil
#

Isn’t that what OSdev is about

flint idol
#

there's ur log

dense vigil
#

That’s meant to gracefully fail

stark sigil
#

it has been a week and i have found no actual way to get a hello world or a framebuffer

flint idol
stark sigil
#

i want to run but i promised DO NOT DO IT

dense vigil
# flint idol

Try rebooting i think the TSC calibrated poorly because the ACPI timer sucks ass PSP1G_pspTrollar

#

I keep having it do that

flint idol
#

too much work

stark sigil
dense vigil
#

Atleast it dosnt match the frequency listen on Intels website for the base frequency

deep ember
flint idol
dense vigil
stark sigil
dense vigil
#

@stark sigil why don’t you help me debug this

stark sigil
dense vigil
#

(In the other Chanel)

deep ember
#

a define

flint idol
deep ember
#

ah

#

well then no

dense vigil
#

I wonder if there could be a way for FT to bump alloc some logs to buffer until a proper malloc/free is hooked in

#

Or just buffer them yourself

dense vigil
flint idol
#

implemented on x8664 through cr8

dense vigil
#

Ahh

flint idol
#

anyway I think the solution for my device will be to implement the x2apic

dense vigil
#

Oh yeah Intel arrow lake has no x1apic

flint idol
#

that explains it

#

you served us well, x1apic

#

you will never be forgotten

#

im gonna continue with my usb keyboard driver now

flint idol
#

because i need to "actually be careful with hotplugable devices" now

#

i am giving the usb keyboard struct a refcount

flint idol
#

ok well i added some boilerplate code to the usb hid driver

#

for submitting IRPs to it

#

and doing I/O on it

#

but i am yet to actually add code for the driver itself

uncut narwhal
#

of curiosity, how does obos do device hierarchy internally? do all devices have (optional) parents in a unified way or is it a per-driver thing if a device has some parent/bus device it references, or are buses as devices not even a thing in obos?

flint idol
#

and currently, no driver has a concept of device hierarchy

#

except, when I do USB hubs, such a concept will be added

uncut narwhal
#

none of that for pci-pci bridges?

flint idol
#

devices on pci-pci bridges do not have anything like pci_bus* parent_bus

uncut narwhal
#

👍

#

side note as i scroll through irq.c, whats with these gotos that do nothing

#

also shouldIgnoreObjectCapacity is always false so this is always an infinite loop if it cant find a vector

#

those gotos at least do something near line 304ish but the shouldIgnoreObjectCapacity is still never modified so itll still be an infinite loop if it cant find one

flint idol
#

(QOTD: "When I wrote this code, God and I knew what it does. Now, only God knows")

uncut narwhal
#

i think the first gotos i linked was copying from the other function, removing the continue, and then just not removing all the useless stuff that existed to skip the continue sometimes lol

flint idol
#

who knows

#

wait that makes no sense

uncut narwhal
#

lol

flint idol
#

i need to fix a bug with xhci

#

when it reaches the end of a TRB queue

#

it fails to go back to the beginning

#

and so the HID driver hangs

#

nvm that's not the bug

#

but something in the xhci is breaking

#

causing the HID driver to hang

flint idol
flint idol
#

fixed it

#

it turned out

#

i was trying to write the doorbell for the completely wrong endpoint

flint idol
#

well i fixed that

#

and also added a link TRB at the end of each TRB ring

#

but now it hangs after receiving 2 pages worth of events

#

or well it doesnt hang

#

but the dequeue pointer becomes zero for some reason

#

nvm it isn't

flint idol
#

causing the trb queue function to return would_block

#

ok fixed that

#

now it hangs because it doesnt seem to find the link TRB anymore

#

fixed that

#

oh yeah

#

the HID driver can receive packets now

#

but it doesn't interpret any packets yet

#

which is a TODO for tomorrow

#

ill add mouse packet interpretation first because that is easier

#

then ill add keyboard packet processing code

#

and then ill test it ig

#

ill see if i can get a TTY working (in qemu) with it

#

then, i will implement usb hubs

#

and see if the HID+USB Hub+XHCI driver works on any of my devices

blazing python
flint idol
real pecan
#

L

flint idol
# real pecan L

well im gonna add the other protocol I just want smth basic to work first

#

this driver is currently only as a test for the xhci driver

flint idol
#

obos hit 70k loc

#

ive no clue what all those LoC do, but yknow

flint idol
#

anyway there is a bug

#

with the thing

#

if u detach an hid device after having submitted an IRP to it

#

then the kernel dies

#

use-after-free

#

i see the bug

flint idol
#

well the mouse driver works

#

(barely)

#

input is really choppy for some weird reason

#

worse than the ps/2 mouse

dense vigil
#

I wonder what the polling rate is?

flint idol
#

who knows

#

ok i fixed the choppiness

#

the driver wasn't polling the mouse fast enough

#

now for USB keyboards

flint idol
#

ok well whoever designed this should kts

stark sigil
flint idol
#

ok so im writing an algorithm to see what keys are released given the previous state of the keys and the new state

#
#define BITFIELD_DIFF(bitfield1, bitfield2, bitfield_out) \
do {\
    for (int i = 0; i < (104/8); i++)\
        bitfield_out[i] = ~bitfield1[i] & bitfield2[i];\
} while(0);
// ...
BITFIELD_DIFF(currently_pressed_keys, dev->pressed_keys, released_keys);
#

i think this works

flint idol
#

there are some slight bugs meme

flint idol
#

time to implement usb hubs

#

i think i just get the hub descriptor and tell the xhci controller "probe these ports pls"?

#

this is schizophrenic

#

how do usb hubs work and interact with xhci

stark sigil
flint idol
#

i mean that's objectively wrong

stark sigil
#

at least physically

#

companies vs making the most reasonable solution for a problem

flint idol
#

who the actual fuck designed this

#

i am currently reading a pirated usb book

#

that explains how usb works

#

and i am reading the usb hub section

#

and What The Fuck

#

actually

#

it's not that bad

flint idol
#

this actually makes perfect sense

#

when a hub driver detects a device connected:

call enable slot to get a new slot
configure that slot to be associated with the port by setting the route string appropriately
profit

flint idol
#

ok usb2 hubs work now

#

rn it goes: root hub->hub->hub->keyboard

#

hold on there is a bug

#
xhci: input slot context: 08000011 00010000 00000103 00000000
#

hm

#

this is supposed to represent 1.1.2

flint idol
#

i removed the recursive hubs to make it easier to debug

#

but anyway

#
xhci: input slot context: 08000001 00010000 00000201 00000000
xhci: port 1.1 already assigned to slot 2
flint idol
#

it's hacky

#

but it works

#

i think ive ironed out the last bug with the route strings and such

flint idol
#

for tomorrow: finish usb hubs (implement the interrupt endpoint thingy), get root hub port enumeration to work on real hardware

#

the goal before i merge this branch is to get the xhci driver working as well as possible on my test subjects

#

and to have USB3 hubs implemented

#

and to make sure that hotplugging doesn't cause the kernel to shit itself

#

and after, ill add a usb block device driver

stark sigil
#

yo usb man how bad is usb to impelement (i think i have to implement that nooo)

flint idol
flint idol
stark sigil
#

fair

#

i think i have to do 1.0 for now

flint idol
#

hint: start with xhci

#

USB1?

stark sigil
flint idol
#

why, 2011 device?

stark sigil
flint idol
#

bruh

stark sigil
flint idol
#

i feel like xhci gave me a better way to grasp the concept of usb

stark sigil
flint idol
#

you can't use qemu?

stark sigil
#

im gonna port my os to x86 but thats later

flint idol
#

oh so this is a non-x86 os

#

yeah gl with that icl

stark sigil
#

yehs

stark sigil
#

it has like the worst firmware ever too

flint idol
#

ehci made no sense to me, and you're going to be using uhci which is apparently even more schizo

stark sigil
#

im already a schizoid with picking osdev for powerpc i think ill be fine

flint idol
#

k

#

im gonna sleep now so gn ig

stark sigil
#

ight

#

good luck with your evil usb rituals

flint idol
#

thx

flint idol
flint idol
#

I tested the logic, it doesnt make sense for this case

flint idol
#

which actually might be correct behavior?

#

I'll test it after school ig

flint idol
#

I need to fix this bug in my mlibc sysdep

flint idol
#

yeah the xhci driver doesn't work on real hardware

#

i decided to try and submit a NOP COMMAND trb

#

and it just hangs

#

without so much as an irq

#

i will note that this device seems to use msi

#

for the xhci controller

flint idol
#

reminder to self: fix the bug on line 602 of xhci.c

blazing python
flint idol
#

its an if statement with the wrong condition

#

while the code is not technically wrong it makes the kernel have to do unnecessary stuff

#

oh and I also need to fix a bug on line 967 of xhci.c and line 975

flint idol
#

chat

#

should I join

dense vigil
#

also yes you should join may be fun

devout niche
dense vigil
flint idol
dense vigil
#

I do gotta know

flint idol
dense vigil
#

Ohhh

flint idol
#

im still in high school

dense vigil
#

Ahhh makes sense

flint idol
dense vigil
#

Honestly I bet you have a good shot at winning

#

Your pretty damn smart

flint idol
#

thx

#

im gonna see that teacher sometime soon™

#

sign up

dense vigil
#

I’m gonna be asking you about USB btw later

#

Few months probably

lean glen
#

Ive wanted to participate before but I've never been to a school with a programming club or whatever that organizes these kinds of things

#

and you cant enter as an individual

lean glen
lean glen
#

then there's CCO (canadian olympiads)

#

then if u win all of that you go to IOI

flint idol
#

aight so either tomorrow or after exams im gonna find the teacher and register for this

flint idol
#

i fixed the bug with TRBs on real hardware

#

fuckass xhci spec

#

"oh yeah on top of having to set the CCS bit in op_regs.crcr, you also have to set the cycle bit in the first trb because fuck you"

flint idol
#

usb's a bitch

flint idol
#

xhci is fucking insane

flint idol
blazing python
flint idol
#

i just want the CCS bit to be set man

#

January 20th, 2026, at 2311: I am debugging XHCI, it is driving me insane. I can hear voices when I sleep telling me about TRBs and xhci stuff and I think I am going insane.
(diary entry end)

#

ok it is kind of almost getting there

#

wtf

#

i managed to make it try to initialize a disconnected port on qemu

#

i should git reset my changes and try again icl

#

like i managed to generate the bit out of thin air on qemu

#

so like

#

it hangs on waiting for the ADDRESS_DEVICE to finish

#

and one thing i noticed is that the portsc has the port link state as "compliance mode"

#

which seems suspicious

flint idol
#

TODO for whenever i get back to this: rewrite the port attach and reset logic

#

after that i think ill have a working xhci implementation on real hardware

#

because TRBs work

#

and well that's pretty much all that matters

#

anyway gn yall

#

tomorrow im studying for an exam probably so

#

wont work on this most likely

#

and thursday im studying for my other exam on friday because well procrastination at its finest ig

#

and i will have time on the weekend

#

and on monday i will study for my exam on tuesday

#

then im done

#

and i will be free once again

#

god willing

blazing python
flint idol
flint idol
#

fucking hate

#

xhci

#

and usb

#

WHY WONT YOU JUST REPORT A GODDAMN CONENCTION ON THE ROOT HUB

#

JOB HAD ONE BRO

#

AND BRO FAILED JOB

#

wtf is wrong with my hardware

#

there's an xhci controller

#

for no goddamn reason

#

i booted into linux

#

and the usb3 root hub is completely unused

#

wtf is wrong with hardware, who designed this shit

#

nvm

#

it's just a USB2 hub on the xhci controller

#

with all my devices connected on it

#

kms

#

what have i done to deserve this

#

all ports are in RxDetect

#

two ports never even get the reset bit cleared

#

sdfgsdjoikgfhdsfjkgdsfhjgkfdshngfd

stark sigil
#

i think there was no good luck with the usb rituals

flint idol
#

i dont think so no

stark sigil
flint idol
stark sigil
#

qemu problem?

flint idol
#

NO THIS IS ON REAL HARDWARE

stark sigil
#

it doesnt follow certain specifications correctly

stark sigil
#

doesnt work on your machine 😔

flint idol
#

(xhci spec) Only a USB3 protocol port may fail the bus reset sequence. USB2 protocol ports
never fail the bus reset sequence.
resets USB2 port
reset fails
fsdfdsklfsd

sterile sparrow
flint idol
#

yknow what maybe the problem is with the bios handoff code

#

like maybe the bios still thinks it has control of xhci

#

and is doing evil shit

sterile sparrow
flint idol
#

im reading freebsd code

#

it has gotten to this point

#

haiku maybe?

#

nvm

dense vigil
#

Before and after XHCI driver

#

How’s it going

flint idol
flint idol
#

ok well ive an English exam tomorrow

#

its like there's an essay question on there and like I dont wanna write it but like I have to because like its worth 80% of the exam mark

flint idol
#

so tomorrow after my exam: continue work on this, maybe ill try it on another device

#

(maybe I should study for my exam on Friday instead? hm)

dense vigil
# flint idol im reading freebsd code

I do remember seeing some youtube tutorials on XHCI that showd it worked on real hardware and how to get it working? Might be a long shot but maybe they have something?

flint idol
#

idk about that

#

anyway im studying some stuff i mightve forgotten for my exam to make sure I dont blank tomorrow

flint idol
#

im having absolutely no luck with this

#

so my solution: use the kernel gdb stub

#

this is my only hope

flint idol
#

fack the gdbstub doesn't work anymore

#

or ig it's that the network stack is being doodoo

#

and not the gdbstub

white mulch
#

maybe you could pass through the controller to qemu? though I guess it depends on what controller your keyboard/mouse are connected to if any, if they are connected to the same one then its probably not a good idea

flint idol
#

(as in the test subject)

#

so that's not an option

white mulch
#

it doesn't have an iommu?

flint idol
#

nope, not to my knowledge

#

i mean there's no harm in checking

#

oh there is an iommu

flint idol
#

usb hates me

#

i do passthrough, now instead of getting port reset errors

#

im getting trb completion code 4

#

"USB Transaction Error"

white mulch
#

that is a really annoying error due to how many different things it can be caused by

flint idol
#

oh fuck

#

i think i bricked my pc

#

(test subject pc)

#

nvm

flint idol
#

wait apparently im supposed to send ADDRESS_DEVICE twice

blazing python
#

isnt it only one time

flint idol
#

idk

#

let me check the spec, because as i know that always helps me with my problems /s

#

For some legacy USB devices it may be necessary to communicate with the
device when it is in the Default state, before transitioning it to the Address state.
To accomplish this system software shall issue an Address Device Command with
the BSR flag set to ‘1’. Setting the BSR flag enables the operation of the Default
Control Endpoint for the Device Slot but blocks the xHC from issuing a
SET_ADDRESS request to the device, which would transition it to the Address
state.

#

A USB Transaction Error shall be generated if an error is detected on the USB
SET_ADDRESS request and the Device Slot shall not transition to the Addressed
state.

#

amazing, very useful

#

(what was the goddamn error)

flint idol
#

yo wtf is the xhci controller smoking