#OBOS (not vibecoded)
1 messages Β· Page 6 of 1
After fighting with KASAN to not crash or be slow af
I finally get a violation
ASAN Violation at ffffffff8001a276 while trying to read 8 bytes from 0x0000000000000000.```
While initializing the scheduler
But of course that's in the VMM
I just realized that I've been doing something extremely stupid
I've been checking if the address that's trying to be accessed was allocated by the kernel allocator
then if it was
it would check if the address falls into the shadow space after the node
It could've easily been a memcmp to check if the address is poisoned (all n bytes are set to 0xA5)
Upon doing that
I triple fault
Bug with memcmp?
As you can see my kernel is very stable
oops:
mov al, dil
mov rcx, rdx
repe scasb
sete al```
spot the mistake?
for reference this is the signature:
bool memcmp(void*, uint8_t against, size_t count)
if the symbol is called memcmp then you should make it work like the standard memcmp
because the compiler expects that
The symbol is mangled
I should probably fix that though
I only have mangled versions of memcmp, memcpy, and memset
Well some vmm node is getting zeroed or is never getting initialized
Because it is zeroed I can't even find out what address it's supposed to point to
That is because the VMM is reallocating pages again
Whoopsie...
It was because of the interdependency between the allocator and VMM
The VMM was requesting a page node
But the allocator needed more room
and the conditions were just right in this case for the VMM to choose the same base address
for the allocator
The fix to this is
idk
I can only think of temporarily adding the node passed to AppendPageNode
So it doesn't get reallocated
and then removing it once the node on the heap is added
which is pretty hacky imo
The problem is deeper
It occurs before the node can be appended in the vmm's allocate function
ie. in it's initialization
I described how my VMM finds addresses somewhere in #1230349543623757845
So the only solution is to rather change that
or remove the interdependency
I could separate the allocator's regions and other kernel regions
So that this becomes impossible to happen
I'll just reserve a shit ton of memory for the allocator
and commit parts of it whenever the allocator needs to grow
Anyway sounds like a problem for tomorrow
I thought of another idea to fix the bug. That is to remove the interdependency entirely. One way I thought of doing that is using the hhdm along with pages from the PMM. Although since continuous physical pages are inefficient to get, this will only be done for the vmm's allocator.
The normal kernel allocator should be able to keep using the vmm to allocate new regions
Although this has the disadvantage that guard pages cannot be added to pages allocated in the HHDM, so memory being written past the region's limit will corrupt other blocks of physical memory
That'd be a fun bug to track down
I just found a very dumb memory corruption bug
Well not very dumb
More like an oversight
I was initially using the regular new/delete operator pair for allocating/freeing page nodes and page descriptors
When I gave the VMM its own allocator, I just overloaded the new operator for page_node and page_descriptor
But I didn't overload the delete operator
Causing all VMM frees to go through the general kernel allocator (not good)
Sometimes I'm genuinely surprised how bugs like this go untriggered for so long
Ok it works now
ie. boots with no problem
Just a "bit" slower
I should fix my UB that UBSan detects
Then I can fulfill [this](#1217009725711847465 message)
O_O
Should've used C :>
Which is more verbose as to which allocator you're using
I enabled KASAN in uACPI's static library and there is coincidentally a table which contains KASAN's value that it uses for poisoning
Reporting a KASAN violation
Seems like I need to use a more random value
I decided to instead attempt further verifying if the address is actually poisoned and doing that
the value 0xA5 seems to come up in ACPI Tables quite often
I just found a USB stick with a very, very early revision of my first kernel
In it's protected mode, vga text mode glory
Time to see what it does
"Hello, world!"
Triple fault
I also found another
That used some crappy acpi shutdown function on the osdev wiki
That's kinda oof
I just found a usb stick with my 2nd kernel
Time to see what it does
"Entering rescue mode"
"grub rescue> "

A lot more reliable then what modern kernels call "memory mangement" or "scheduling"
KASAN+my kernel on my laptop = slow af
Until it finally reaches the test driver
where it finishes
and asan reports an asan violation
the stack trace is pretty goofy
the first stack trace entry is asan_report
then panicVariadic
then reportKASANViolation
Letting the kernel panic through the debugger
Reports stack corruption and not kasan violation
I think I should poison the stack through KASAN
That might catch uninitialized variable access
Instead it:
Attempt to call LowerIRQL() with the irql 15, which is greater than the current IRQL, 0.```
That doesn't happen second reboot
or after fixing a bug with a use of uninitialized variable
I have found a scheduler bug
Where if the kernel main thread exits
ie. it gets terminated
The scheduler will find a way to switch to the part of KernelArchInit that checks for the watchdog timer
Of course, because why not, the code gets run as the BSP's idle task
Attempt to call LowerIRQL() with the irql 15, which is greater than the current IRQL, 15.```

Solution: Remove stack poisoning
Anyway I may or may not have 22 outgoing commits
But this time I tried to only keep a couple changes per commit
Instead of one fat commit for changes to everywhere
Between current commit and master:
54 files changed, 1252 insertions(+), 341 deletions(-)```
I've merged that branch
and also merged the vfs branch
then I made it again
so it can have the bug fixes
and other changes
Anyway, what was I doing before this
Ah yes VFS
I guess I'll have some struct
that stores an opened file's context
ie. the offset
how it was opened
etc.
Then I'll have some member functions
that initialize it (open a file)
read from the file
write to it
close it
whatever else a file descriptor does
I have found a scheduler bug
I just don't know why it happens
Nor do I want to look into why it happens
But it doesn't happen all the time
Time to use UBSan I guess
what does it do
interesting
(of course as I turn on UBSan the bug disappears)
I'm sure it'll come back
it just happened
with no UBSan violations...
Time to turn on KASAN
With KASAN, I get stack corruption
i.e., it causes the stack corruption
It reports the stack corruption in scheduler::yield
All I wanted was an implementation of KASAN, is that so hard to ask for?
Why does it have to do all this
Very goofy stack trace:
Stack trace:
0xffffffff800344eb: _ZN4obos6logger9panicImplEPvbPKcP13__va_list_tag+378
0xffffffff8003430b: _ZN4obos6logger20reportKASANViolationEPKcz+0
0xffffffff800342d9: _ZN4obos6logger13panicVariadicEPvPKcP13__va_list_tag+0
0xffffffff80050b14: _ZN4obos3vfs11string_viewC1EPKc+0
0xffffffff8004f296: _ZN4obos9scheduler5yieldEv+370```
let's see what it becomes on a reboot
it becomes nothing
These bugs are making me want to rewrite my kernel, although I must resist
The stack seems to be getting fucked by my scheduler
Somehow
Time for more debugging on how
Specifically, the yield() function
this guy made more debugging than those who tested GDB
My kernel should be used as a test case for GDB
That'd probably not even be that bad of a way of testing it
Considering how much bugs I produce
Lol
maybe adding a cli in the YieldThread function (which saves thread context and calls the scheduler) will help
Well that certainly does something
Whether that thing is a good thing or not, idk
I'll wait to see if KASAN reports anything or if anything shits itself
Well
nothing shat itself
but that's probably a lucky run
hmmm
another reboot worked
I'll try again...
three reboots and not one fails with magical memory corruption
I'll rebuild
then run qemu
and see what happens
It works
Time to consider this bug fixed until not fixed
KASAN significantly slows down the kernel
Do u even understand why that was a bug
Perhaps u just made the bug more unlikely to trigger
Well if a cli made it not get triggered over 4 reboots
that probably means YieldThread got preempted by an interrupt
(similar behaviour also happens when I try to get my IRQs preemptible)
I do use ISTs for some interrupts in my kernel
Which uses the CPU temp stack
oh dear
so does the scheduler
maybe that was my previous kernel and I'm misremembering
it was my previous kernel that did that
oops
double faults use ist 2
but that's never initialized
No IRQ uses IST stacks
only certain exceptions
I'm going to remove the cli
and disable ISTs
for all interrupts
and I'll see what happens
triple fault
oh yeah
I remember now
I need to map all stacks as no demand page
after fixing that, everything goes to shit
ISTs aren't the root cause
Maybe ISRs somehow leave the stack in a goofy state
Doubt it though
Well I would've noticed that a long time ago
I don't know why this bug happens
all I know is disabling interrupts in YieldThread "fixes" it
Shouldn't matter
Maybe it has something to do with KASAN being disabled in only some functions the scheduler depends on
idk how that would affect anything though
I got the VFS's look for index node function working
I just need to vigorlessly test it
(with three available nodes for it to test)
I'll also do goofy stuff with the path to test if parsing the path works
like putting many slashes beside each other for no reason
Parsing the path seems to work
I'll try paths relative to the root passed to LookForIndexNode
see what that does
doesn't work
It's a problem with parsing the path
Fixed it
I'll also try adding ../ to the path and see if that gets messed up
oops
infinite recursion
I fixed it
I'll try adding ./ to see if that works
page fault
I saw a gdb option for instrumenting functions, and I thought it would be nice if I could implement it.
To see what functions take the longest
which get called the most
etc.
It's only two functions I need to implement
and they can technically be pretty simple
The downside is that everything related to the VMM and allocator now needs to be marked as no_instrument_function or everything will go to shit because of recursion (the function for recording function calls may or may not depend on the allocator)
Which means not the allocator nor the VMM can be instrumented (at least not in kernel mode)
Although anything else can be
and I have to do this for ANY dependency of them
Even so much as an exception handler
or the IRQL functions
or spin lock (although tbf that shouldn't be instrumented anyway)
I feel bad for anyone who wanted to port OBOS (me in the future)
There will be so much forgotten quirks
Like this
That will pop out of no where
Even one liner functions in the VMM have to be marked
as no instrument
because there is the slight off-chance that infinite recursion happens
Now luckily for me the VMM nor the allocator really depend on anything else in the kernel
Ok I'm done a very barebones implementation
Time to see whether it shits itself (it will)
You know what this is too unstable
I might rewrite the kernel (again)
note how "might" is emphasized
The reasons, well, look above this message
Mainly kernel instability
But that can always be fixed, my previous kernel at one point had similar problems
Except none of which were with the allocator
Mainly scheduler instability
Actually there were some
The allocator would be ported if I rewrite
Oh man how many rewrites have been done already lol
what is it that you're worried you've miscoded/misarchitected?
Well for one I messed up IRQs a bit
I wanted them to be preemptible
It's not really too late for that
It's just a lot of debugging because when I tried the kernel shat itself
The kernel, at least in the early stages of boot, is really fragile
I shall rewrite the kernel (starting in a couple hours)
I'll merge VFS with master then rename master to some old_code
This time, I'll rewrite in C
C? What language werr you using before?
C++
I think you probably were not using C++ features anyways, but if that's the case the rewrite will be much easier anyways
No way π€£
Can I place a bet on how many rewrites until you stop doing osdev
would not it be better to take your time and slowly build up working code instead of slowly building up bugs? That's what you say, but also what you should really do
you will just waste your time otherwise
Yeah that's what I'll do this time
I'm going to try and get KASAN and UBSAN asap
to prevent those bugs
heavily test each part, trying different edge cases, analyzing the values and so on
I'll test everything
vigorously
This rewrite might take longer to get to around the same state as this kernel
But at least it won't be buggy af
first uncursed version of obos incoming?
the third kernel wasn't cursed
place your bet, come on!
it was just a bit devil
nothing to worry about (I was not even here)
No it was fine and relatively stable
It was able to get to a point where I could port a libc
until someone (hyenasky) saw my VMM and made me want to rewrite
I also decided some parts were designed poorly
He was banned in this server
you could use the best of all the rewrites
But you can find him elsewhere
yeah I know
do you usually test your code in a controlled environment?
Nope
why?
Too tempting to just go on and use the feature
is that a pun which my english does not understand?
nope
which feature?
and that is the root of all your problems
VMM was very lightly tested
which is why the allocator bug came up
It was a bug in vmm::Free which could've been fixed if I tested
well hyenasky has a very advanced os afaik so it is not a surprise that your untested code might have had some poor design choices
in contrast
If anyone needs to test their debugger, you can use the fourth kernel
but you couls have continued from there, or you can roll back now
to a certain degree
btw I still haven't started the rewrite
I'm at school
I can't just start a rewrite in the middle of class
that means you can still think on what is the best way of doing it before heading in
yeah obv
oh btw for this rewrite I'm using the hyper bootloader
any particular reason?
(never heard of it)
Good luck with the rewrite
ty
yes, good luck!
hey guys
is he rewriting again ????
good
π
C is key!
actually will probs be easier cause no oop!
π π
man i love C
oop isnβt exactly harder
well C++ is just idk, idk man i dont code oop β οΈ
C++ is more than c with classes
yea and i dont like classes
then don't use them?
yea thats why i use C π
my brain just went π₯
How many rewrites do you think you will do before you'll be happy with OBOS.
Yes.
hopefully this one
but that's what I've said for each other kernel, so idk
I've almost been doing osdev for a year
which is le cool I guess
Definitely felt a lot less than a year
Only a year? I've been doing osdev for almost 2 years, and I'm still on the same kernel.
My kernels' timeline:
First kernel may 2023-august 2023
second august 2023-october 2023
third october 2023-february 2024
fourth february 2024-(basically may) april 2024
I think this rewrite will keep some parts of the previous build system
Like dependency management
I'll spend a bit of time on that, then move onto the gdt (copying and pasting the previous kernel's gdt)
First though I got to make a new branch for the rewrite
Theres no point rewriting things like the GDT, which are working well.
I know I use git branch -c to make a new branch based on another branch
but what do I use to make a new branch
ie. one with no commit history
I'll just search
git checkout --orphan
The github repo will be a bit goofy for a bit
whoops
I accidentally put in the old kernel's readme
ok the github repo is good
except there is nothing except for the branch for the old code
and master that only has markdown files and the license
what license do you use?
I used that until I came across GPLv3
boo
I like GPLv3 because you have to state changes
use c++23
bruh
I'm using C
oh wait
Well C23 is quite new
obvious solution is use ANSI C
I'll use C17
It's not so new that modern compilers don't have some features
but not that old either
C23 has constexpr so itβs obviously based
yeah but compiler support for it is unstable
c17 is basically c11
yeah I know
constexpr in c feels wrong
constexpr in c solves the problem of const int x = 5; int foo[x]; making a VLA
because now you can mark it constexpr instead of just const
Yeah that makes sense
At least it's stable
Most stable oberrow kernel
good thing I coded my gdt in asm
For how long will it stay stable?
for the previous kernel
around 1 minute
Until scheduler
when I port my GDT
What order are you planning on making things in?
gdt
idt
IRQs and IRQL
scheduler
VMM
also with vmm comes page cache
GDT is working
Wouldnt it make more sense to do vmm before scheduler? Also, you forgot the PMM
oh yeah
no
scheduler must have no dependencies
PMM before this
Even not IRQs
A wise man once told me that the timer IRQ shouldn't be linked to the scheduler
so it makes sense to just make it so early
that it can't depend on anything
What about the kernel heap?
in-between PMM and VMM
btw VMM != page table manager
a wise man told me that aswell
actually he told that to @vernal chasm
ok IDT here I got
time for a lot of porting (I'm not writing this again)
Ok this is how symbols will be named:
Arch_* arch specific code
OBOS_* General kernel code
Mm_* VMM code
Vfs_* VFS Code
Io_* Io manager
Core_* Scheduler, IRQ code, other code in the kernel that are essential to the kernel working.
Kdbg_* Kernel debugger-related functions.
Drv_* Driver interface/loader functions.
'S' suffix to a namespace name means the symbol is declared by the arch-independent part of the kernel, but the architecture must define the symbol itself.
'H' suffix to namespace name means the symbol is a helper function.
TODO: Add more```
What about things that are exclusive to x86_64?
Arch_
arch specific code
The others will be solely for arch-independant code
note that list is only for global exposed symbols
statically-linked ones aren't counted
structs will be named in snake_case
functions will be named in PascalCase
because why not
Finally my stack traces won't be wider than they are deep
wut
A wise man told you that a VMM is not a page table manager
#560042023638269955 message
Hyper is a bit too fast for my own good
I can't tell a triple fault from goofy control flow
lol
it was 5 times faster than limine for the limine barebones kernel example last time I tested
ok the int3 instruction doesn't triple fault
just the question is, does it work?
it indeed does
I think I'll leave the IRQ interface for after I port the allocator
Ok now IRQL
Pretty straightforward
Ah yes
Because these commits are so straightforward I'm just directly pushing to master
They're not really tied to a feature
I think I might put all functions in a certain "namespace" (whatever the prefix to the function is) in their own directory
Actually no
only for some
IRQL functions are going under the OBOS "namespace"
I'll see what NT does
From what I see from a wikipedia page, Nt is for syscalls
no idea
Wait NT calls SSDT the "system service descriptor table"
Nt or Zw are system calls declared in ntdll.dll and ntoskrnl.exe. When called from ntdll.dll in user mode, these groups are almost exactly the same; they execute an interrupt into kernel mode and call the equivalent function in ntoskrnl.exe via the SSDT. When calling the functions directly in ntoskrnl.exe (only possible in kernel mode), the Zw variants ensure kernel mode, whereas the Nt variants do not. The Zw prefix does not stand for anything
From here
Well I guess calls it was misleading
I still don't really know what Rtl or Zw means 
i was talking to oberrow
ah xD
I think a reason the old kernel was so fragile was because everything depended on everything
it was a big clusterfuck of dependencies
so changing one thing that is seemlingly unrelated to something else can cause the kernel to π©
Before I get to the rest of the kernel I need a way to log
stuff
and panic

use nanoprintf or stbprintf
instead of c++ logging
Imagine changing how system time is computed and the pmm dies
probably could've happened lol
I never used cout-style logging in my kernels
I hate cout logging
It's so annoying
but u did something else and not printf iirc
It was indirectly calling printf
It was first printing what kind of log message it was
Whether it was a debug log, info/general log, warning, or error
then it printed the message
also I kind of forgot about error handling in the previous kernel
Something failed and you wanted to know why? Too bad, you're not going to
error codes were "false"
success was "true"
Lmao
Indeed
It'd be funny if I implement a USB driver first thing after IRQL so I can send logs
and make a gdb stub for the kernel
That would be big
If I don't implement printing stuff on the framebuffer I'll be stuck with testing with qemu only
But I don't want to implement printing stuff on the framebuffer
because that's boring
I'll get to it eventually.
Store logs in a buffer
On key press generate a qr code from that buffer
Display it
Done
pretty sure that's more work than just printing shit on the framebuffer
Another problem with my previous kernel is that nothing was documented
There was no documentation, not even so much as comments explaining what the function does
None.
Make your own debugger api 
well I did make a kernel debugger for my previous kernel
that'd be the next step
obviously I should make a kernel debugger then add dwarf parsing so I can get line numbers
Sounds like pain
I think it is
Kernel logger is complete (port 0xE9 only for now)
The new kernel is no longer stable
It panics on every boot
Now where was I
ah yes IRQL
I got the IRQL system working
I just need to test it
It's so simple I can't think of ways to test it immediately
after testing that I'll make a spinlock
Not many ways to test that either
It (probably) won't break
Spinlocks will be a part of the Core namespace
IRQL is a part of that namespace aswell
Things in the core namespace cannot depend on anything (except basic kernel routines and other Core namespace members)
If they do the kernel can, and most definitely will at one point, go to shit
For example the scheduler code cannot depend on the logging code
nor can it depend on, for example the VMM code
Maybe the scheduler was a bad choice but you the point still stands
of course that code can depend on Core namespace code
that's kind of the entire point
Spin locks work I guess
So simple I cannot mess up
I "tested" them by locking the logging functions (as I should)
There was a bug in Core_SpinlockRelease
It was with irql.
I think the fact that I'm writing it in C has caused me to think more about namespaces and dependencies
I just pushed the code for the kernel logger, IRQL, and spinlocks.
Tomorrow I shall work on the scheduler
Then the PMM
Then I shall port the old kernel's allocator
Then VMM and page cache shit
Then drivers
write gpu driver O_O
Eventually
I told @livid oracle I would here #349857717445459968 message
But that's in a long time
I barely understand what graphics is
like what the hell does a geometry shader do?
make shapes?
Takes in some number of primitives and produces new primitives
The fewest input primitives are singular points
And the fewest output primitives are singular points
But you can produce any number of points from that singular point.
Or any number of lines or triangles
However it's technically limited up to some max number which you pre specify in the shader
But I'm not entirely sure if the driver has to conform to that limit
I'll port the WDF and have my own driver interface aswell
then I get graphics for free
and other drivers for dumb devices
anyway enough osdev for today
geometry shaders make people very upset and tell you to use mesh shaders 
I am everywhere
Spooky
Wait so are you in #614652561965711370?
Probably not
Only like 4 people there so xD
Two of which are me...

that you know of 
Now I'm scared
anyhoo it's time for me to disappear
are you employing %cr8 for that?
good luck
WDF is large
Yup
I'm writing all code related to thread context in assembly
Why you might ask? Because I can't be bothered to write a setup context in C then translate the C struct for context into assembly for the context switch function.
I've implemented those functions
Time to test them
I also have a thread structure
Lets see will I finally make stable kernel
Bro
I'm triple faulting randomly
WHYYYYYYY

oh of course it triple faults calling a function
We just love OSDev
The instruction that page faults, causing the triple fault is push rbp
then cr2 is 0x80
rsp is a good value
so is rbp
not that that would matter
no register is 0x80
there is no possible way for this to fail unless some dumb code overwrote the instruction
it's triple faulting on return?
The hell
Why is RIP the start of getIntIST then?
Why is this randomly triple faulting
the red zone is disabled
Qemu is cursed
I have more assembly in my kernel than C
unless header files count
I think it might be a bug with spinlocks somehow
const bool expected = true;
irql newIrql = Core_GetIrql() < minIrql ? Core_RaiseIrql(minIrql) : IRQL_INVALID;
while (atomic_compare_exchange_strong(lock, &expected, false))
spinlock_hint();```
whoops
Nope
It isn't
It can't be a problem with some timer IRQ coming in
cr8 is 0xf
which blocks all IRQs
oh and of course when I add -no-shutdown -no-reboot to the qemu command line it doesn't triple fault
wtf is happening
In a debugger it triple faults
outside a debugger it doesn't
it hangs I think?
It's stuck in an infinite gpf loop because there is no handler
which spit a 593 MiB qemu log
Bro how is it already unstable
It can't even be my fault
There is no code
It's page faulting on
address 0x80
THERE IS NOTHING THAT CAN ACCESS 0x80 at the faulting RIP
It's a push rbp with an intact stack pointer
Single step with gdb
That's what I'm trying
but it triple faults at random points
(of course only in a debugger)
nvm
Still triple faults at random points
I'm calling TCG bug
There is no other way
I'll use whpx as my accelerator
lo and behold it doesn't triple fault
My thread context switching code doesn't work
X to doubt
Timing issue
TCG doesn't have bugs
Or I doubt u can trigger them with such simple code
There is the qemu log
The instruction at RIP is push rbp
The part where it triple faulted is at the end
Send the report to qemu mailing list
tip: -M smm=off
But 99.9999999% sure its a you issue
I'd test on real hardware right now
But I have no way to print logs
on real hardware
rn
See if it triple faults or not
But like I said it can just be a timing issue
Which it probably is
wdym by timing issue
btw it doesn't triple fault
On real hw?
on real hardware
Anyway
btw this triple fault is happening before initialization of the gdt
and idt
so no fault handlers for me
it's happening while logging initialization of the GDT
You think basic code like that causes a TCG bug?
Try it
btw this only happens while a debugger is connected to qemu
maybe that has something to do with it
what is your gdt?
are you still using limine gdt at the point of the crash?
Well I'm using hyper's
judging by cs=0x28
but yes
is 0x10 a 64-bit data segment?
i have a feeling it's like 16-bit or 32-bit
or did you not touch the segment selectors yet
I hadn't touched them at the time of triple fault
hm what if you do x/i 0xffffffff800044b1 in the qemu monitor when it crashes
as opposed to objdumping or addr2line-ing the binary
Yeah should be fine
This is the hyper bios gdt here at the bottom https://github.com/UltraOS/Hyper/blob/master/loader/arch/x86/bios/bios_entry.asm
Thats not a thing I think? (or at least it doesn't matter)
you can just set all the other segment selectors to 0 for the kernel
but you need a valid segment for ss in user mode
Doubt
Yeah at ring 0 u can just set them to 0
such a weak mindset, you wouldn't last a minute in protected mode on the 286
CS is still used for privilege checks I think
Exactly why I use long mode
And 64-bit data segment is not a thing right? @weary hound
it is a thing, as i said you need a valid segment for ss in ring 3 in long mode
or wait hold on
common::x86::makeGdtFlatData32UserSegment(gdt, kGdtIndexClientUserData);
Yup
my bad, the data segment is the same for 32-bit and 64-bit
that leaves me wondering why [this](#curated-resources message) says 64-bit user data segment
and 64-bit data segment
probably because it's less confusing for beginners
Saga skill issue
well it was pitust's message
oh i see
yea your stack is wrong
The first unstable kernel pre gdt init
The cr2 value is fucked
is it
Bruh
okay no what's posted in curated resources is correct, the 32-bit segment has flags.DB=1 set and flags.L=0, and the 64-bit segment has flags.DB=0 and flags.L=1, which is what you are supposed to do apparently
quoth the osdev wiki gdt page
L: Long-mode code flag. If set (1), the descriptor defines a 64-bit code segment. When set, DB should always be clear. For any other type of segment (other code types or any data segment), it should be clear (0).
oh wait no
that's specifically for code
for a moment i thought managarm was doing something wrong :^)
Nah thats impossible
The triple fault changes locations every crash
did you enable interrupts by accident? :^)
You sure interrupts are disabled
Bruh
oh yeah PIC doesn't go through APIC
silly me
and it isn't subject to cr8
amazing
it works
ie. doesn't triple fault
now I got a context switch function to debug
Big
very cool tcg bug 
Lmao
does hyper by any chance remap the PIC
It doesn't touch any hardware
well why cr2=0x80 is forever unknown
limine explicitly masks the pic
I'll call Arch_disablePIC before anything
TCG bugs 
but why was cr2=0x80
accessing the idt? idt=0x0000000000000000
0
oh yeah idt entry is 16 bytes
Or that
aka where the master pic is mapped by default
on bios
so irq 0 on master pic
aka pit
Oh interesting
I remember getting this bug on my first kernel
when I stied
Because I had no IDT
I had no idea why it happened
yeah ibm didn't listen to intel saying that the first 32 vectors are reserved and now you end up with the pic in the middle of cpu exceptions on legacy bios
IBM big retard
although originally there was nothing there and no one could've predicted the pc would come out on top as the dominant platform so
So these dudes are the reason why we are forced to remap it
which is why we should make a time machine
go back in time
with the limine mafia
and threaten ibm to listen to intel
I would just buy Bitcoin
go back in time
tell ibm to map pic to vector 0x20
go back to the present
you are using a m68k computer now
Lol
lol
With keyronex as your daily driver
but why didn't it triple fault on my laptop
It should've because no hardware was touched
and it emulates the PIT
Pit not enabled by default
uefi machine?
indeed
oh yeah
I forgot that I would boot from legacy bios emulation (I forgor what it's called) on my laptop for my 2nd kernel
which is why I could use PIT
I should probably sleep even though it's pretty early
Same
if I'm forgetting stuff like this' this bad
staying up to 4 am for osdev ain't a good idea
Yes
I obviously should've started rewrite six when I got the triple fault
Obos rewrite 6, remastered gdt init
π
This time in Rust so you are safe from memory leaks triple faults scheduler bugs and allocator/vmm problems
You will get there
eventually
Yes
Good luck
ty
for future reference, the align directive in nasm does nothing for struc alignment
only code alignment
and data
ok
after some debugging
I can switch to an "arbitrary" """thread""" context
static void test_function(uintptr_t userdata)
{
OBOS_Debug("In %s, userdata: %lu.\n", __func__, userdata);
while (1);
}```
is basically is getting called in a fancy way:
thread_ctx ctx;
memzero(&ctx, sizeof(ctx));
CoreS_SetupThreadContext(&ctx, test_function, 0x45, false, thr_stack, 0x4000);
CoreS_SwitchToThreadContext(&ctx);```
Hows memzero different / better than memset
Thats a valid reason
I mean technically it's faster by a couple cycles
but why memzero and not OBOS_CoreS_MemorySetZero?
also valid
and the prefixes have a meaning
anything without the prefixes is rather statically linked or is something like memzero
or memset
or it's a type
types don't follow that rule
How, are you doing some aligned data shenanigans or simd stuff
No
wdym by statically linked? surely everything in the kernel is linked into the kernel
unless you have modules already
ah, internal
It's just xor rax,rax takes fewer cycles than mov al, sil
so using memzero is faster
by a couple clock cycles
What if the data youre zeroing isnt in a register
I'm not sure if I'm lagging or discord is
but yeah
I see a notification (I have notifications for this thread on all)
I open discord
and there is no message
until I reopen discord
Common discord L
and xor eax, eax is better still, since it's 1 byte shorter (=> 1 byte freed up in the icache)
good idea I should do that
The real question is whether you have memzero call memset or if its handmade - the compilers specially optimize specifically memset, so if you're handrolling something you're likely leaving perf on the table
I got memset implemented
using rep stosb
I optimized memzero
to be one byte shorter
https://godbolt.org/z/Yeco3zPha as an example, memset doesn't even exist in this TU but the compiler still magically optimizes it to rep stosq
not with -ffreestanding
oh really?
because it implies -fno-builtin
I thought that magic was always magic
you're right indeed
though -ffreestanding -fbuiltin brings the behavior back, idk if that has other bad side effects for a kernel though
i mean yeah because you're re-enabling it
btw what happened to banter
it means that you have to implement standard behaviour for function calls, and that you also have to be careful when implementing stuff because for example the compiler could optimise a memset() impl to a memset call
as you showed there
which is not very good
in general you can reenable -fbuiltin but it requires you to be extra careful about stuff like that
no
I have more asm in my kernel than C code
