If you have a local copy then you can just put that back up. Kinda sad to see a hobby OS go away just like that just because people were bullying the guy. Idk.
It's better to use uXX/iXX types, because you know the widths are fixed. The hardware register specification often says "this is a 4-byte/32-bit register," so it's immediately obvious what you're doing if you use u32
Not a driver I don't think... This is either part of a bootloader or very early init of the nvme devices from the kernel. Hard to know for sure but it assumes 1 device g_bo (which is why it's confusing for bring up of a kernel, it would usually build a table) which makes the kmem_alloc strange to me.
Really curious about the thought behind line 78 and 79. it firsts case to a unsigned long, to then cast it it an unsigned long long, which actually never get used.
They are your two admin NVME queues. One is for your commands, the other is for completions. The other 2 that look similar are the io queues. It then takes those addresses and writes them to the NVME controllers registers on line 86.
What doesn't make sense here is that kmem_alloc as I mentioned above, but who knows what this was written for and maybe it doesn't have IOMMU on this device?
The casting is just to get an integer with out the compiler throwing a fit about signs being thrown away. There are much better ways to do this and especially in c++ lol.
no need to slander the C++ crowd, it clearly look like plain C code and you don't need to be a C++ developer to produce bad looking code, it just happen that my average cpp code can usually look as messy .... damn
I like it TBH. All the nitty nvme_init stuff in one screenful. Beats 500 lines of "structured" cargo culting with everything factored out into little poorly named functions that "do one thing" making you chase definitions and immediately forget them.
While I might have put them on separate lines, now that I see it one one it makes a certain amount of sense: the body is executed once for every possible PCI bus/device/function address.
i also avoid braces when i have one line to execute under if or in a loop but holy moly 3 consecutive loops and then ifk ehat in the world (btw learnt some !b0) thats a real handy truck to check for value at current.
It’s not complex, it’s very very sequential, but it’s not overwhelming me like other long sequential functions I’ve worked on (over and fucking over again)
The formatting is oddly alright, the three for loops one one line looks stupid - until you consider that it’s really map() over the permutation of three things
49
u/johan__A Jun 11 '26
where did you find this gem?
8
u/TheMonHub Jun 11 '26
Btw the file
146
u/KGBsurveillancevan Jun 11 '26
This has gotta be decompiled or generated or something right?
42
u/Daemontatox [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” Jun 11 '26
Formatters wet dream
30
u/FloweyTheFlower420 Jun 11 '26
using long (long) in kernelspace code when talking to hardware might be genuinely the most baffling thing ever
16
u/Financial_Owl2289 Jun 10 '26
holy cow. what even is that.
18
u/Ok_Chemistry_6387 Jun 11 '26
There is 0 chance this was written by a human.
6
u/DesiresQuiet Jun 11 '26
Looks like the initialization code for an nvme driver in linux, etc.
6
u/YourShowerHead Jun 11 '26
It looks scary only because of the formatting, right? Right??
4
u/nooby_linuxoid Jun 11 '26
this looks generated to me
1
u/TheWidrolo Jun 11 '26
Really curious about the thought behind line 78 and 79. it firsts case to a unsigned long, to then cast it it an unsigned long long, which actually never get used.
2
u/bombthetorpedos Jun 15 '26
Can't have just a long.. long long all the way, baby!
1
u/8Erigon Jun 11 '26
You can write unsigned without int or long?!
1
u/Ellicode Jun 11 '26
Great heavens…
1
u/Trard Jun 11 '26
Average cpp program
1
u/great_escape_fleur Jun 11 '26
I like it TBH. All the nitty nvme_init stuff in one screenful. Beats 500 lines of "structured" cargo culting with everything factored out into little poorly named functions that "do one thing" making you chase definitions and immediately forget them.
1
u/124k3 Jun 11 '26
i also avoid braces when i have one line to execute under if or in a loop but holy moly 3 consecutive loops and then ifk ehat in the world (btw learnt some !b0) thats a real handy truck to check for value at current.
1
u/_usr_nil Jun 11 '26
this code gave me anxiety
1
u/gfivksiausuwjtjtnv Jun 12 '26 edited Jun 12 '26
Wait
Why do I *like* this code
Not even joking
What the fuck is wrong with me
It’s not complex, it’s very very sequential, but it’s not overwhelming me like other long sequential functions I’ve worked on (over and fucking over again)
The formatting is oddly alright, the three for loops one one line looks stupid - until you consider that it’s really map() over the permutation of three things
1
u/Bubbly_Rain7858 Jun 13 '26
To be honest, the code looks fine, except for the fact that they put multiple lines on one line.
1
u/jeremyStover Jun 14 '26
This has to be obfuscated code. Not sure why they have obfuscated code pre-compiled? Maybe to prevent AI ingestion?
1
u/h1mmh1m Jul 08 '26
How to you even work like this, even my desk that I've never cleaned is cleaner
1
u/Ray_Silverlight Jul 31 '26
To my highly trained eye, the indentation and spacing almost form a picture of a guy wearing a cap
0
u/nooby_linuxoid Jun 11 '26
modern c++ am i right
0
u/richardathome Jun 11 '26
It would help immeasurably with a really simple fix:
change
int nvme_init(void) {
to:
int whatever_nvme_stands_for_init(void) {
You would at least have a starting context and it would shed some light on what the cryptic variables might mean.