#OBOS (not vibecoded)
1 messages · Page 25 of 1
although it speeds up by so much
without optimizations there are a lot of redundant memory accesses for an example
unlike any other time I've used optimizations
larger the code base, more optimisations compiler can do
and performance difference becomes more apparent
well LTO is being a pain\
it's removing my ubsan symbols
I'll move ubsan/kasan/stack checker to a separate lib
attribute used?
undefined reference
no, like
weird
works fine for me
ubsan is for debug mode anyway
and you don't use lto with debug mode 
and if there is a kernel module in debug mode
being used on a release kernel
it doesn't find ubsan
so it starts crying
the linker is rearted
ok
I define the symbol OBOS_InitrdBinary
export it
reference it in 5 different places
WHERE THE FUCK
is my symbol
looks like it needed to be volatile
fuck binutils
fuck LTO
OBOS_EXPORT const void *hashmap_get(struct hashmap *map, const void *item);```
makes the visibility of
hashmap_get
'default'
[ DEBUG ] Could not resolve symbol 'hashmap_get' (symbol is hidden) referenced within a driver.```
what if you add -Wl,--export-dynamic?
that fixes that
now I just need to fix the nullptr access in the COM driver
bruh
inlining is ruining me stack traces
implement dwarf cfi interpreter 
ok wtf is up with LTO
how is it making
Symbol->name become nullptr
JUST HOW
yeah goodbye LTO
time to stop rotting away behind my phone scrolling
and instead
rot away behind my computer
writing the new PCI interface
and actually
I will be using early table-access
in uacpi
don't ask how cpu_local.h somehow ends up including pci.h

Wtf
well it includes cpu_local_arch.h
which includes arch/x86_64/gdbstub/connection.h
which includes driver_interface/header.h
for like, cpu-local gdb stub stuff
which then includes driver_interface/pci.h
for the struct pci_hid
I'm also going to be refactoring the driver interface init
fun fact: the obos master branch still doesn't have dirty/standby lists
I need to merge userspace-work soon....
while I am on the topic of the vmm
I think I want to merge struct working_set_node and struct page
someway
because there might be a bug related to that
(I haven't observed the bug yet, since it has to do with shared pages between two vmm contexts)
basically, the amount of working sets a page is in is stored in the working set node
but each time a page is put into a working-set
a new one is made
potentially causing fnuy stuff to happen
such as:
- a page being removed from a working-set (therefore being paged out), while it's still in another process' working-set
the way to solve that is really simple
put a working_set_node in the struct page
like a pointer to it
I just realized that locking virtual pages really just means "locking it into the working-set"
so pseudocode for that would be:
lock(&pages->ctx)
prefault(pages)
foreach page in pages:
working_set_node n = insert_page_into_workingset(&pages->ctx->ws, page)
n->locked = true
unlock(&pages->ctx)```
and the opposite would be the same, but without the prefaulting, and instead of inserting the page into the working-set, it gets the page's ws entry, then sets n->locked = false
I wonder how prefault will work
I could just call Mm_HandlePageFault for each page in there
Mm_HandlePageFault(ctx, page->virt, page->present ? PF_EC_PRESENT : 0);
in like a week
I'm off on vacation
so no osdev there
I'm sure yall will miss me
I'll bring my laptop :^)
u cant osdev from laptop?
well idk if I'll be bringing my laptop
if I can
(I don't think my family would be fine with me bringing my laptop on a 2-week vacation)
((just to do the exact thing I do everyday))
two weeks is enough to get extremely bored at a vacation
can someone pin this?
thanks
fr
lmao
♫ 137 little bugs in the code ♫
♫ 137 little bugs ♫
♫ take one down, patch it around ♫
♫ 93,428,471,930,587,234,682,318,095,723,456,932,108,653,294,867,394,583,495,715,902,847,523,905,
♫ 20,730,897,752,653,674,714,720,723,427,459,000,889,249,915,529,600,981,530,433,365,335,188,589,206,775,527,139,229,601,995,115,836,043,535,786,629,580,792,144,773,078,426,776,834,268,298,332,187,236,818,042,380,226,849,443,884,860,369,688,406,406,660,118,018,751,041,554,543,095,806,670,784,324,017,067,690,408,791,078,125,463,951,378,030,499,174,512,211,021,762,053,899,146,321,811,754,326,676,200,848,317,668,615,746,032,791,477,810,189,370,765,796,872,015,454,208,726,535,891,065,392,365,497,780,680,934,294,765,890,614,462,433,230,434,642,019,850,210,194,574,941,837,149,904,506,668,092,623,531,566,731,463,976,957,855,738,022,148,581,771,099,684,223,664,263,637,368,004,862,059,648,627,935,705,330,725,186,314,285,961,032,283,586,277,966,145,966,280,929,918,887,266,909,890,820,024,385,375,444,923,126,652,775,589,102,263,540,978,186,901,034,212,346,494,403,140,899,551,856,996,521,257,241,285,133,877,814,522,994,967,358,822,224,685,926,377,660,467,871,022,924,275,654,082,181,950,373,765,807,211,473,562,917,453,950,351,601 little bugs in the code ♫
���
better
although it isn't perfect
the interpreter
it kinda works
and it also can run a bf interpreter written in bf in it
Why the fuck are you making a brainfuck interpreter
@flint idol Is this the bf-in-bf you're using? https://raw.githubusercontent.com/canoon/bfbf/refs/heads/master/bf.bf
$ time echo '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.!' | kuroko bf.krk "$(cat bf.bf)"
Hello World!
real 2m29.956s
user 2m29.879s
sys 0m0.068s
nah this is https://brainfuck.org/dbfi.b
was bored
didn't feel like osdev
oh that's a lot faster than the one I linked
that was a lie
I ran the wrong command
$ time echo '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.!' | ./kuroko bf.krk "$(cat bf.bf)"
Hello World!
real 0m0.362s
user 0m0.354s
sys 0m0.011s
lol
2 minutes?!
wow
dude respond to dms 😭
back to osdev lesgo
lesgo
just say soon™️ and then never do it
https://github.com/OBOS-dev/obos/blob/4a6e9a9830b312f6a8994a74d2952205eca19926/src/sanitizers/asan.c
__asan_load1
then that last number is all the powers of two up to and including 8
what
bru
__asan_load1, __asan_load2, __asan_load4, __asan_load8
and then the same thing, but with the word store instead of load
ok
then in that, you call some other function, which I call asan_verify
which verifies the memory isn't poisoned
and I explain what "poison" is in the messages here
and in the case that the memory is poisoned
you panic
you can poison just about anything
freed memory, out-of-bounds memory
non zeroed memory
i think im just gonna take a break from osdev for a week i dont feel motivated anymore. i feel like every piece of code i write is utter shit so i would probs also screw up the kasan impl as well
to be honest
bro is saying ok cya
look fine ill impl kasan
but ur gonna see how shit
it will be
look
ill probs
triple fault or some shit
you probably will if you forget to mark the asan helper functions as __attribute__((no_sanitize("address")))
you'd stack overflow if you forget to do that
lol
rule 1 of osdev
don't expect to write linux 2, but don't let your code reflect that
Rule of osdev #1469: never assume memory is zero'd - moondeck
Rule of osdev #1468: never assume indices are sequential - mniip
Rule of osdev #1470: don't divide when you can shift - glauxosdever
Rule of osdev #fbf89521-21f1-4a52-b5cb-a0bf0f761bb4: probably avoid collisions with globally unique identifiers - sortie
Rule of osdev #1985: Never try ...
I tried asan once but idk how do you actually make it work because you have to have initialized enough stuff to make it work in the first place
just don't write bad code
well like you have to have an allocator for an example to be able to use asan so you'd have to mark all functions needed to bring that up with no sanitize address
huh
okay and what do i need to do in __asan_load_n?
or ig with out of line instrumentation you could just skip any asan checks when its not initialized
it calls asan_verify
or well
it calls something
that verifies the memory is unpoisoned
in load and store?
no
where
this wont verify my vmm region tho
y
because
how would you poison/unpoison kernel without it
just don't bother with globals
❓
oh
if you wanted to poison globals
global variables?
no it won't?????
why
you can make clang emit out of line function calls everywhere so then you could probably skip the asan checks before you have initialized everything
because why would it?
no it doesn't
it's like
no
it's after an allocated piece of memory
what I do is in my allocator
if kasan is enabled
I add like 256 bytes I think
to the size
what
before allocating anything
and then after allocation
I do memset(addr+size-256, poison, 256);
what why 256
nice number
what if that goes over that page
no
because what if
ur on the last allocated region in the slab
ur just gonna
overwrite another page
fun
then just
memory corruption
what
this is what I meant
oh
no
oh
that's the malloc function
what
it adds 256 to the size parameter
use that thing you have in your head
wassit called
brain
and think of what I could've meant
when I said "size function"
size parameter
so like
in this calculation
u remove -256 bytes
giving the page 256 more bytes
no I don't
oh
for one I don't use a slab allocator
probs not
oh
what I mean is
you would add 256 to amount
at the beginning of the function
(if kasan is enabled)
yea
ifdef __SANITIZE_ADDRESS__
ok can my posion be whatever i want?
ok
go to asan_verify
couldn't you rename it lol
im confused looking at this
rename what
OBOS_AsanPoisonValues
it checks the memory against three different poison values
ok
why does it need size again
size is the size of the access
and what is this function
do i have to impl it
yes?
ok
yea i dont know what this bitmask is checking for
shhifting at by 47
and inverting it
checking if the memory is canonical
and oring it with
ok ill just copy that if statement
:)
what is memcmp_b whats the difference between memcmp and memcmp_b
is there a impl of this function i can yoink
make it urself
no????
oh
it returns a bool for one
if the memory is equal
to val
return true
else return false
not at all
I wonder who's been cloning obos 
november 2nd?
yea
someone cloned it
so what is it then
look at memcmp
yea im looking at memcmp
what about it
oh
so u loop over
if (p1[i] == val
do whatever
okay
there
incorrect
oh
yea im reading
your checking if the ptr
16 bytes before is posioned
if one of the sides is posioned
yk
who wants to implement asan in my kernel 
it's all good
if (isposright || isposleft) panic
okay
mhm
but you don't index into nyaux_poison when you poison the memory
you had used some other value
which I stated before
what
????
i dont understand
what does it mean when u say "when checking if its posioned but not when posioned you had used some other value"
like
i dont understand what you meant
oh yeah#
but i remembered
to do this
so
its right
😎
0x1a is for non-zeroed memory
profit
but don't forget to define these
call into asan_verify
i do __asan_load_n
and?
why do i need to define __asan_load1
because
etc
that's what the compiler expects
dw about it
nearly
add -fsanitize=kernel-address
to your CC_FLAGS
and also asan_store doesn't take a size paramter
and also, asan_verify needs kasan disabled
i do that with NYAUX_NO_KSAN
ok
now it wants
idk
okay
__asan_load1 becomes __asan_load1_noabort
etc
btw, no underscore
between the number
and load/store
so instead of __asan_load_1
you do __asan_load1
now it wants load16????
so add one for 16
now its talking about load_n?
i did
cr2 is
ffff800006672ff8
then from 0xe
it 0xd's
then 0x8
then 0xd
you know how I check if I cross a page boundary
yea
how do i check that
math
#define OBOS_CROSSES_PAGE_BOUNDARY(base, size) (round_down_to_page(base) == round_down_to_page((uintptr_t)(base) + (size)))
mine
now
:)
I use MIT license for a reason
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
okay and what do i do if i did cross a page boundary
go to the next comparison
?????????
like
if i cross a page boundary and either check passes
do i panic saying a page boundary was crossed or what
is that what i do?
i dont know if that is correct so im asking to verify if thats correct or not
what do i do then
go to the next comparison
return;
just return?
isnt it a bad thing if u cross a page boundary
anyways i did the checks
still the same triple fault
still at memcmp_b

who the hell uses 2 space indents unironically
im having vscode format it
not my fault
but anyways i dont know whats going on
im going sleep
tmrw we figure this out
changes are on git
get a .clang-format
static obos_status writeback_bar(pci_device* device, pci_bar* bar)
{
obos_status status = OBOS_STATUS_SUCCESS;
switch (bar->type) {
case PCI_BAR32:
status = DrvS_WritePCIRegister(device->location, 0x10+bar->idx*4, 0x4, bar->phys & 0xffffffff);
break;
case PCI_BAR64:
status = DrvS_WritePCIRegister(device->location, 0x10+bar->idx*4, 0x4, bar->phys & 0xffffffff);
status = DrvS_WritePCIRegister(device->location, 0x10+bar->idx*4+4, 0x4, bar->phys >> 32);
break;
case PCI_BARIO:
status = DrvS_WritePCIRegister(device->location, 0x10+bar->idx*4, 4, bar->phys & 0xffffffff);
break;
default:
return OBOS_STATUS_INVALID_ARGUMENT;
}
return status;
}```
go to sleep.
gn\
other than the fact that I need to essentially rewrite the pci part of pnp
and the ahci driver doesn't compile
a large part of the new pci interface is implemented
well not large part
but a part
writing pci resources
and capabilities
now of course I don't initialize any buses yet
so it's useless
now my head hurts so I'm going to sleep early
but tomorrow I will probably continue on this
when I'm done my new pci interface, the ahci driver will have support for multiple ahci controllers
hopefully
how would I name the drives though? sd1a
for ahci controller 1, drive a
sd2a
for ahci controller 2, drive a
Can't you just link the same module in multiple times?
No
btw uHDA now has the locking stuff, fixed path configuration (as the old one was broken on real hw) and some doc on the concepts if you want to try it with your kernel (it would be good to have some other kernels to see if the kernel api is good enough though it may change with the possible unified api and also would be good to see if it works in general on different real hardware cards)
also oberrow has some old hw so would be interesting to test
one thing I am slightly worried about is cards that have broken stream position reporting
though I don't think its that hard to fix as there is an other mechanism to get it too so you'd just switch to that if the position didn't change at all between irqs
i5-4590T
which one?
unpresent sounds weird
a one
just say not present idk
printing out your long git hash wastes memory too
yeah but it's useful for bug reports
(not mentioning the ascii art)
Oopsie! The cpu did a fucky wucky!!!!
isn't that the astral panic screen
i'm writing a qr code generator for the drm panic handler
(I may or may not have thought about doing that once)
Cpu0: oops.
Cpu1 watched cpu0 crash and decided to retire
ah
sometimes I'm scared of what auto-merge can do
like when git merge decides it thinks it knows how to fix a merge conflict
uh oh
why is the current obos branch so much slower than master
Did you forget -O0
fat + slow
the name of the fat driver is a parody of NT's fastfat driver
because like
my fat driver is slow af
I'm just going to blame it on uacpi

true
I did also make the log level higher on userspace-work
and the speed seems matched
and it uses 9M less memory
since I'm going to the UAE I might be able to test obos on some relatives devices (with consent first, of course)
cc @real pecan
apparently obos doesn't like CPUs reporting as AuthenticAMD
Have you never tested with tcg? IIRC tcg returns AuthenticAMD
I have with -cpu Haswell
but never with -cpu qemu64
or rather, no -cpu argument
it literally just triple faults on initializing the page tables
maybe I'm missing some sorta check
huh?
it triple faults in stb sprintf
__builtin_popcount crashes
probably due to #UD
yup
Nice
I told the compiler to compile for x86_64-v1
and it works
since __builtin_popcount calls a libgcc function
I just added a config option to obos
to configure the value passed to march
OBOS_X86-64_VERSION
v1 is x86-64
v2 is x86-64-v2
v3 is x86_64-v2
v4 is x86_64-v4
I'm gonna see if obos works on qemu on my phone
I got termius installed
*termux
And will be cloning obos
Oh wait
I have no obos iso
Oh cool termux uses apt
Cannot link executable cmake
Libcrypto not found
And apt file
Doesn't work
loool
TCG reports GenuineIntel on windows for me, iirc
The qemu64 cpu makes it use authenticamd
ah, I must have been testing on qemu-system-i386 only
Ok
obos is now my os muhahaha
ill make a commit today obos will be ported to mlibc! yes muhahahahaha and it will run bash !!!
muheheheh
Then obos becomes more cursed 
Just got me hands on an esp32
As soon as I come back and am done writing the new pci interface
I will port obos
To xtensa
Or really after userspace-work is merged
Some ESP32s have RISC-V cores...
like this one :P
Then I'd be porting to that
obos riscv port based
I have some ESP32-C3s (I think) spread around home doing IoT stuff
I'm wondering how much can be implemented with their MMUs...
Just realized obos uses waaaay too much memory
At least for esp32
This model specifically seems to have 4.5M total
And obos uses 10M memory
*virtual memory
And a lot more physical
memory
Although a couple MB of physical memory is framebuffer
Related
And my physical memory count doesn't even include any VMM structures (including PTs)
I'll just make it start swapping memory aggressively
damn cooollll
OBOS proprietary edition when
nyaux goes closed source and buys out obos
😱
I don't get it
Nothing I just hate embedded
I wonder if esp32 has acpi
no
It also kinda doesn't have proper virtual memory
How come?
Yeah but what makes it non proper
I don't remember how it works, but it is very limited
Like you can only have 32 or so memory regions and it's meant for memory protection, not to have virtual memory
And only select ESP32s have user mode
Which ESP32 did you get?
Got it from my uncle, but it said something like ai thinker
On the chip
♫ 20.73 Sesquinquagintaducentillion little bugs in the code ♫
Bruh
Division Error
Page fault
General protection fault (loaded 0x58 to cs when gdtr.limit was 0x38)
Because int 0x3 is for SIGTRAP
because it's privileged 🤓
Used in debuggers
And other interrupts shouldn't be called manually otherwise it can cause cpu funniness
Btw that is only for interrupts through the int instruction
For example the page fault exception handler expects an error code
If it's not there it probably crashes
(It is not pushed when you do the int instruction to invoke int 0x14)
Type attribute in the idt entry
idtEntry.typeAttributes = DEFAULT_TYPE_ATTRIBUTE | (canUsermodeCall ? TYPE_ATTRIBUTE_USER_MODE : 0);
Debug trap
@flint idol ```c
typedef struct ATTR(packed)
{
u16 base_0_15;
u16 selector;
#if CONFIG_bits >= 64
Bits ist:2;
Bits reserved:6;
#else
bits reserved:8;
#endif
u8 type;
u16 base_16_31;
#if CONFIG_bits >= 64
u32 base_32_63;
u32 reserved2;
#endif
} IdtDesc;
which bit would that be here
U see that type field
yea
That's it
which bit
why
Because that's a general rule for structs like th8s
*this
Compiler can do wacky stuff to it
how
well for idt it doesn't really matter unless you enable something that generates that irq in the middle when you are modifying the entry but in general its a good idea to avoid yeah
#osdev-misc-0 message
the code is so clean though 😢
Sorry
you can make pretty clean abstraction that's like bitfields but with structs (at least in c++, idk about c but I can't think it would be too bad there either)
Example?
yea example pls
Bitfields are fine if you use them for internal structs
Or smth
That aren't from any sorta spec
why isn't that an enum
namespace op_regs {
constexpr BitRegister<u32> USBCMD {0x0};
}
namespace usbcmd {
constexpr BitField<u32, bool> RS {0, 1};
constexpr BitField<u32, bool> HCRST {1, 1};
}
void test() {
IoSpace space {0xsomeaddressofxhci};
auto cmd = op_space.load(op_regs::USBCMD);
cmd &= ~usbcmd::RS;
op_space.store(op_regs::USBCMD, cmd);
cmd |= usbcmd::HCRST(true);
op_space.store(op_regs::USBCMD, cmd);
}
``` this is basically what I do in my kernel and I borrowed the idea from managarm, basically the BitRegister contains the offset of the register within the space and then the space's load method just does a load from that offset returning a BitValue you can get those individual bitfields out of (or set them)
Used internally
but why not do this
That's not its purpose
what is it used for
For page ranges
The virtual alloc thing has its own flags
so you would use it like prot.present = true; prot.user = true;
Yes
instead of prot = present | user;
Yes
meh, i won't criticize that, imo the latter is cleaner
Btw my vmm is made to be platform independent
So I don't write anything like it's about to go in a pte
i don't either
Lies
So it's not cross platform?
wdym
If it's different for each arch it's not really cross platform
the header/usage is, the implementation is obviously architecture dependent
Sorry what the hell is acquire_force
how the hell would that work otherwise
If you really care I can send a link to my code
i do care
attempts to acquire the spinlock until it succeeds
spin_acquire can fail
I mean if I were you, I'd make this acquire
💀
And the fallible one is try_acquire
though actually idk doing something like this in c might be painful because of no generics or methods, ig the best you can do is macros to extract/set specific fields which is kinda a c skill issue ngl
Imagine having to repeat this kinda code for each arch
😔
I don't think they are repeating that kind of code for each arch? it was just the code to map one page
and that obviously needs to be arch dependent
I'm talking about the implementation itself
yea but how can that possibly be arch independent
vm_map maps one page tho so the impl has to be arch dependent
though the desc is kinda undescriptive lol
Oh I thought that was like the mmap
true
maybe you should rename it to something like vm_map_page
but what else would i be mapping
Files
or a bigger region
Skill issue
yep
btw if you mean the mmap syscall impl that is actually arch independent
probably the worst code you'll see today
but it does its thing
doesnt this leak half of these mappings
or like depending on where it OOMs
lol
yes
that's what i was talking about in #polls
this shit is completely broken because i didn't know wtf i was doing
lol
Like
if it works it works

Smhsmh no file mapping
pipe()
dup()
broken 
or just anything launched not from a terminal
the solution here is clear: have everything be associated with a pty

always return true
#define } __builtin_trap(); }
Currently, my pthread_mutex_unlock can fail with ENOMEM 
W h a t
Microkernel skill issue
I'm thinking of reworking it and moving it to the kernel (instead of relying on IPC)
(also because of the deadlock issues related to scheduler priorities)
Microkernel skill issue
post made by managram 
Post made by the vmm with paging
but dynamic paging doesnt imply overcommit
*swap
I have ahci
Nvme is planned™️
Pci interface rewrite
Of course I'm on vacation so I'm not working on it now
Lmao
I'm gonna support PCIe
Currently the pci interface is very shit™️
Not much
Except MSI is guaranteed to be supported
On the software side ofc
I don't support MSI (yet)
I support MSI and MSI-X
Except that it doesn't work on RISC-V
And legacy irqs
Through int pin
It's paid
Just use osdev wiki, should be good enough
I don't have it
I do have a spec that explains the relationship between pci and acpi
I found parts of it on a random website with hw (homework) solutions stuff
And seen enough of it to implement ACPI
Wdym
Did you buy it or sum?
you can also find them literally everywhere lol, even on intel's site
Proof?
just google "pci specification pdf" for yourself, ofc its likely not intended to be public and its some old spec (iirc like 2.0)
this cat says hi
Not PCIe spec though
it is pcie
PCI Firmware*
yeah, for that you have to use archive.org lol
Huh
there was a gh repo where someone leaked all of the most recent pcie and pci specs
probably down now tho
I've just found 2021 verison
though its not terribly useful imo, the acpi spec already contains most of the stuff iirc
i buy it :)
for 2k? 

2k for a little pdf
I think drafts are free
kthxbye
KiBye
someone forked obos
Have no idea who
Well I know the github account
Yes yes definitely
100%
Is ur os not on github?
Then why isn't it on that github account
That's the account that forked obos
Oh yeah it is
I saw yeah
Btw master is missing many features from userspace-work
ah alr imma download it

