#Ultra
1 messages · Page 17 of 1
or pfndb I forgot
what do u use runtime services for?
RTC on != x86
and also maybe on x86 because its easy tbh
u could use them for suspend
also uefi variables - any time you use a thing to set the efi boot order from an os it needs that
also reboot and shutdown but not suspend
uefi runtime services dont do suspend but they do reboot and shutdown
you can also upload firmware updates from runtime services
you can get the high 32 bits of a system-wide monotonic counter for some reason
i really dont understand that one lmao
the main things are ResetSystem, Get/SetTime, Get/SetWakeupTime, and the variables stuff tho
oh i understand the monotonic count thing now
theres a boot services thing to get a 64-bit monotonic counter
the low 32 bits reset on boot but the upper 32 bits are nonvolatile
so the runtime service for the upper 32 bits lets you increment that if you want to keep using it at runtime and have the upper 32 bits persist
(the upper 32 bits also increment on reboot in addition to overflow from the low 32 bits at boot services time or when you call the runtime service)
i still dont really get why youd want that but good to know ig
you can also use runtime services to set a flag saying to go into an os-defined recovery mode on reboot
which i imagine is how windows does that feature
the big one for runtime services is still RTC though
because sometimes the firmware says fuck you and excises all mention of the RTC from acpi tables and/or devicetrees and insists that you use uefi services (or hardcode it)
as an example of firmware doing that: OVMF on aarch64 lmao
slash i think edk2 in general on aarch64
Its supposedly the number of times the system has been reset.
But for me it usually reads zero, even if I used ResetSystem() 
Ah ok, it does more than that
The platform’s monotonic counter is comprised of two 32-bit quantities: the high 32 bits and the low 32 bits. During boot service time the low 32-bit value is volatile: it is reset to zero on every system reset and is increased by 1 on every call to GetNextMonotonicCount(). The high 32-bit value is nonvolatile and is increased by 1 whenever the system resets, whenever GetNextHighMonotonicCount() is called, or whenever the low 32-bit count (returned by GetNextMonoticCount()) overflows.
#1385970208631427173 message i figured that out a bit later lol
Oh lol my bad
Yeah neither, I print it for fun bit thats it
fair lol
It's to prevent replay attacks in cryptographic protocols
at least, that's one use of it
say, your system boots, reads some pre-generated entropy from disk and generates a private key from that
oh that makes sense
Yeah, interesting
w/o any per-boot input, the private key will always be identical if you can for example crash the machine before it writes back new entropy to disk
but you can take the increasing integer and hash it together with the entropy to prevent this attack (it doesn't matter that the boot counter has low entropy for this to work)
How is this normally exposed to userspace? er, nvm
You don't have to have a pre kernel to do that either 
How much would I be doing in assembly to be able to properly do the full thing to setup paging and load the elf 😭
My kernel is bootable with limine, ultra and mb2 with the same binary
mb2 loads the elf in memory for you, you just have to build the page tables
Like since you're probably rebuilding the page tables later anyway, you can just map from kernel start to kernel end with RWX permissions to jump to higher half
Though I parse and map the ELF in assembly 
Tbf in a pre boot environent that's not that bad 
Ultra and limine are easy to support at the same time, you just need to normalize e820, and limine gives you the entry point request, which gives you a separate entry point for it (and mb2 as well)
Though I wonder how I'd want to allocate the memory for the HHDM and page tables 😭
Unless I switch to recursive
Just reserve it in bss
I've tried to filter e820 in assembly, but was too big of a pita
If you limit yourself to a 4GB bootstrap direct map, then you know how much memory you need for page tables (about 2MB)
(iirc)
I can also just do recursive page tables and avoid a direct map
Then only BSS enough to map the kernel image
But that wouldn't work on riscv 
Which is fine with it not doing mb2
I don't think it's enough
Or rather you probably would have to do a lot of trickery?
Also there's no mb2 on risc-v
Yeah that's my point
I mean my kernel then just maps itself + temporary mapper area and that's enough to initialize the pfndb/pmm and vmem
In theory you could bump allocate off the memory map after cleaning with just a recursive map

Idk, I don't like recursive maps
why not, out of curiosity?
I had used it and there were too many tlb flushes involved
I know that you can optimize it, but still
ah
yeah, thanks vscode, this is exactly what i wanted
nah, still fixing hyper, it has supported aarch64 since forever
ahh
and im definitely going to support aarch64 in ultra, probably not any time soon tho
fair enough
does it support VHE though? 
yep, it supports el2 only if vhe is supported
does it enable VHE if it's supported but disabled?
the enable sequence from uefi is quite painful 
you plan to support/use uefi for aarch64? if so, you going to hardcode the address of the RTC for a given board setup or use uefi/setvirtualaddressmap stuff for rtc?
I mean i think so:
// Complete all prior memory accesses before touching the MMU
dsb sy
isb
/*
* Disable the MMU while we reprogram the translation registers, then (at
* EL2) switch to VHE. The current regime's MMU is controlled by SCTLR_EL2
* at EL2 with E2H still 0, and by SCTLR_EL1 at EL1, so pick the right one.
* Once E2H is set the _EL1 register names below redirect to their _EL2
* counterparts, and setting E2H with the MMU already off avoids
* reinterpreting a live SCTLR_EL2/TCR_EL2 in the EL1 (VHE) format.
*/
cbz w6, .disable_el1
mrs x13, sctlr_el2
bic x13, x13, #SCTLR_M
msr sctlr_el2, x13
isb
mrs x13, hcr_el2
orr x13, x13, #HCR_E2H
orr x13, x13, #HCR_TGE
msr hcr_el2, x13
isb
b .mmu_disabled
.disable_el1:
mrs x13, sctlr_el1
bic x13, x13, #SCTLR_M
msr sctlr_el1, x13
isb
.mmu_disabled:
msr mair_el1, x3
msr tcr_el1, x4
msr ttbr0_el1, x1
msr ttbr1_el1, x2
// Ensure the writes are observed by the table walker, then flush the TLB
dsb ish
tlbi vmalle1
dsb ish
isb
// Re-enable the MMU with data + instruction caches on
mrs x14, sctlr_el1
orr x14, x14, x5
msr sctlr_el1, x14
isb
// Set up the kernel stack
msr spsel, #SPSEL_ELX
mov sp, x7
/*
* Jump to the higher-half copy of the code below so we can drop the lower
* half from under our own feet if requested
*/
adr x13, .higher_half
add x13, x13, x9
br x13
.higher_half:
Yeah, i've already added code for propagating the UEFI memory map + runtime service stuff to the kernel
that doesn't flush the cache
before disabling the mmu
which is needed because the currently executing binary may have dirty cache lines
do you relocate it in loader or just propagate and let the kernel do it? if the latter, i assume you leave the 0-base identity map in the page tables passed to the kernel for the runtime services to use before/during the relocation?
and after disabling the mmu you'd read stale data or code
hmm yeah ig
i just propagate it as is, i think the kernel should build a separate page table for the runtime services and then switch to it dynamically
like linux does
👍
does linux switch to an identity map for uefi runtime services?
i still think relocating to high mem and using setvirtualaddressmap is better than giving uefi its own page tables but ig that works
it walks the uefi map and checks what regions are needed for the runtime services (via an attribute bit), only those are mapped
i think yeah its an ID map
probably a defense for crappy firmware?
i guess? windows doesnt do that but idk
actually that's probably saner than passing the virtual map to uefi
i never thought about this possibility
yeah i think thats pretty nice, uefi cant corrupt any of your mappings that way
shrug
it's also less complicated
i feel like swapping page tables whenever you go to uefi is more complex than doing a single call during init once and never touching it again personally
it does some weird stuff here, so it's not always identity map
only in mixed mode apparently
and they have a thunk for setvirtualaddressmap
I think most of the complexity is from supporting mixed mode
what is mixed mode?
Aka 64 bit kernel booted from 32 bit UEFI
in non-mixed mode it does this apparently
/*
* We allocate runtime services regions top-down, starting from -4G, i.e.
* 0xffff_ffff_0000_0000 and limit EFI VA mapping space to 64G.
*/
static u64 efi_va = EFI_VA_START;
yeah
although yeah as i said theres a separate efi_mm
Thats actually a big issue with the limine proto i think, it doesnt tell you the bitness of the uefi firmware anywhere(?)
fable said this: https://pastebin.com/nm0hpu29
Is that wrong?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
- Instruction fetches during the window aren't a problem either: with M=0, I=1 they're Write-Through cacheable, and the trampoline code hasn't been modified since it started executing, so the I-side is coherent with memory regardless.
I'd double check this, idr it w/o looking it up
I do remember that it didn't work consistently w/o flushes on real hw
and Linux also flushes
Ill tell the agi to check linux sources and explain why it does that then
Linux does not do a set/way flush
btw
that'd be overkill
set/way flushes are rather complicated on ARM as well
it's must easier to just flush the trampoline region
Can you link the file where u saw it flushing
it's in some early boot file
Does it only flush the trampoline also?
search for dcache in head.S, there are multiple code paths
/*
* If we entered with the MMU and caches on, clean the ID mapped part
* of the primary boot code to the PoC so we can safely execute it with
* the MMU off.
*/
Thanks
Maybe your code is indeed correct because it doesn't touch any data
For data / stack whatever accesses, it'd definitely be broken
Yeah but for example this talks about the instruction cache
And I never cleaned the trampoline to the poc
Yeah, poc != pou
You can assume that it's cleared to pou by uefi / your loader but not to poc
But this probably doesn't make a difference if the argument that claude gave is correct
Because there can (obviously) be no writes though the instructions stream
Yeah clanker caved after i pointed it at the linux source https://pastebin.com/g3VUdC8E
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
ah so it matches what i remembered
and also the code in eir is correct and i didn't hallucinate that it ran into real hw issues before i added flushes 
I wouldnt expect that to repro on real hardware, how does the icache not end up evicting that code later on anyway?
or is the amount of code that it runs so tiny it never does that
unsure
Its crazy even fable is kind of shit at understanding exactly what arm arm wants
well
I think the ARMARM is a particularly hard case but also fable is not infallible
yeah
the ARMARM also doesn't fit into its context window, so it can only read parts of it
yeah, its a 120mb pdf
that it converted to text also
but its a lot of duplications for aarch32 vs aarch64
Even crappy LLMs that I use can sift through the loongarch manual with its partly broken English 😭
I've heard many things about arm
And none have been good
I mean the LLM can probably read the original chinese spec 
And people that don't know computer architecture never listen to me about CISC/RISC being stupid and that arm is basically becoming CISC with its ISA feature set and x86 is RISC internally after the decoder
People keep trying to push arm in the desktop space when riscv would probably be better to push it even la64 potentially if it could expand a bit more proper
I mean arm is the only one where there are already relatively fast cpus u can at least use
I mean of course but there are alot of other factors with things
And they also tried to say the windows scheduler was bad and its memory management was bad
💀
Who did?
Oh this was other place crap with people who don't do osdev as much
ah
that happens a lot
i should add hyper support to zinnia
helix*
Kate*
kate be like: what's a good lsp
I forgor about helix :p
meanwhile zig:
(ZLS is either completely useless or crashes instantly)
no
it miscolors some types entirely
(they don't update)
I haven't noticed that somehow?
in rust?
Ah I haven't used it for much rust yet
bad lsp is a dealbreaker for me
it makes me quicker because i can easier tell code apart
(and with rust this is necessary for let bindings)
[331578.845086] Out of memory: Killed process 319906 (clangd.main) total-vm:11723156kB, anon-rss:7617680kB, file-rss:8kB, shmem-rss:1408kB, UID:1000 pgtables:15392kB oom_score_adj:100
you need how much memory

my laptop literally hung for like 10 seconds and music stopped playing
how greedy is clang
😭
the funny part is i wasnt even doing anything, not building nor editing source
indeed
Considering it's from GNOME it was probably leaking memory 
who needs lsp anyways
get on with the times just write it using ai and if compile errors happen just ask the ai to fix it on a loop
Need the type of a variable? Just ask ai to tell you
Using a non LLM assisting debugger?
get llmdb today
Its rare for a clanker to make a syntax error anyway especially for common languages
To get Obscura, you don't even need to link a personal email to your account. So if you, want a privacy first VPN go to https://obscura.com/ACTION and get 25% off a subscription or use code ACTION
Obscura is available on Mac and iPhone, android and other platforms coming soon
Haiku finally supports modern dedicated GPUs! Well, with some effort....
@errant temple leo did u see this one yet?
i thought all they had was some dev demo, but this seems to just work for the most part
cool
not that it matters for me because i'll just use the proprietary nvidia userspace impl

wdym? I don't know much about graphics stuff
u know how nvidia made the open source driver
that one is a simple shim for the most part, that just calls methods on the gpu firmware basically
ah
its trivial to port but it does nothing on its own
you need a huge userspace part thats still proprietary
there have been efforts to make an oss impl using this new nvidia kernel driver in mesa
and as u can see it works in haiku
but nvidia wants you to use its proprietary libgl.so etc
but that won't be an issue with linux compat :^)
exactly
well trivial with an asterisk ofc
because it requires all of drm implemeneted and a fully mature kernel
its not uacpi with mostly dog simple kernel api
well I still have a long way to go before I can start thinking about accelerated graphics
same
It's not a simple shim, right? It's still a lot of code
Like many hundreds of source files
Iirc the driver is a 70M binary on Managarm
Maybe you're thinking of the old closed source nvidia driver that had just a simple gpl2 shim module
Nvidia open has actual logic in the kernel
It's true that it uses the gsp for actual mode setting etc but it still has a lot of code in the kernel
How does it work? Do you have a Linux kernel API shim?
Ah cool
this doesn't even look that bad if it's the only thing to edit for a port
That's all the things you need to implement
There may be stuff in other header files, not sure. You can take a look at Managarm's implementation
gg
Yeye, maybe not a simple shim but that thing doesn't contain any actual gpu logic, only setting the queues and stuff to send commands to the actual firmware to dispatch
it still contains 2M sloc
it does contain gpu logic, just not direct register manipulation
Yes
the small shim that just forwards userspace to the gpu was the old proprietary driver
at some point someone gotta just /goal codex or claude into getting the nvidia open source driver working with nvo
start with /goal implement drm for astral & make virtio-gpu work 
talk is cheap send tokens
Lol
tokens are expensive...
cheap is talk tokens send
@errant temple
point the clanker at https://github.com/no92/mesa-nvk-on-nvo
whatever you do DONT write a fucking bios bootloader
bought a $10 netbook for fun for ultra stuff
hyper triple faults on boot
after 10 hours of debugging sessions and 99999 reflashes with test boot sectors
upper halves of gp registers are corrupted after int13
💀 💀 💀
cursed pos
dont you do pushad/popad?
in the pmod bios_call variant yeah, but the early boot sector that loads stage2 didnt unconditionally preserve all registers (since it's not really a requirement(?))
i see
the funny part is it was reaching the C code and even running a few lines, but then exploding
so it wasnt as obvious at all
since the first few reads survived
and the test boot secotrs i made worked flawlessly (obv because they didnt use extended regs at all)
windows bootloader is probably built like a tank
openfirmware bootloader (theyre supposed to be architecture independent forth scripts but everybody just appends an executable to the script and has the script just jump to its entrypoint asap instead)
looks goofy
the screen is tiny res i think
google says the cpu freq is 1.66Ghz, look how correct my calibration code is 
Can you overclock it by uhhh 30mhz?
lol
im also a bit of a retard and did try out that theory fairly early on, but without the d suffix so it only pushed the small registers
so obv that didnt work

looool
this is my favorite activity now 
what model is that?
This one is fable 5
"unfuck it" lmao
dont have a codex subscription unfortunately
in some countries like mine they give a 1 month free plus trial, i cant get it cuz i dont have a card 
(not an ad btw)
it's quite good actually, it was able to instantly crack a few complex bugs by just looking at like 2 lines of logs
damn
i have a terminal bug so complex
i bet it cant even fix it
I can tell you that doesnt include my country 
use a vpn

fair
im turk btw so maybe u have a vpn that has turk servers?
one example is i had a bug in the test kernel where it was treating huge pages as a nested pte level, fable was able to detect it from just looking at the corrupted output and realizing its actually the page table flags
it also instantly pinpointed the thing that produced that incorrect pt format etc
isnt discord banned in turkey btw
lol

I'm pretty sure everyone on internet uses a DNS :^)
not the google dns
I know
i mean something like cloudflare
im assuming their ISP "blocked" discord by just removing DNS entries for it
most ISPs in our country just block custom dns'
dns over tls/https 🤔
DoT my beloved
DotA my beloved
what's that?
Dota 2 the game
ah
But I don't play it I was just trolling lol
i was able to scam sam altman and get two months for free
lmao
sam scam altman
finally reviewed & merged a pull request unfucking a lot of long standing issues in hyper and adding PXE support, also added a shit ton of new features, like uefi info passthrough, proper boot partition detecton, infinite cmdline length support, module description support, proper video mode selection etc
i can now get back to ultra (after I draft this release ofc
)
this was like a 3 week detour or smth
also tested on my auto real hw ci with 3 laptops
oh also clanker helped increase the test coverage probably x10, now pretty much all boot variants are covered by integration tests with full handover info validation etc
based
what is soft reserved and unaccepted
soft reserved is a relatively modern thing, it's how they mark CXL memory iirc
or any other memory that may have side effects if treated as normal ram
either it will be slow or degrade etc
unaccepted is for SEV i think
memory that must be accepted by the kernel to be used
i see
actually, no hobby os for now takes into account the cxl memery
when is ultra going to be cxl native
yeah
i chose not to support NUMA or CXL
at this stage
based
i want to focus on GPU and overall driver support instead
yeah
i decided to support numa from the beginning and it has been a bit annoying
it's not just "oh okay, let tasks have preferences"
you also have to take into account what happens with early allocations, kernel allocations, etc
also try and make node local stuff
yeah, it basically makes its way into every subsystem
this is still a todo lmao
i allocate all from node 0 by default
ig that the good thing about having numa is that in virtual environments you can "compartmentalize" memory easily
for example, say you want to have an entire hotplug region, and you want to force some program to be located there
you can tell qemu to make a memory node which only has that hotplug region, and in your os you just use the numa api


