#EvalynOS
1 messages · Page 4 of 1
yeah ima fix that
anyway, if you are using single core, i have added a function to get the current thread in those patches
if you wanna apply them

btw @viral bison my int 0x69 syscalls are my non POSIX ones
that im gonna axe eventualy
k
gg
Now I gotta port a libc
mlibc
It looks scary 
it's not
So how do I do it
Before I push I’m gonna make a Mandelbrot program and a generic k thread for making user programs and a function
And then we can have some fun
My kernel is free from the curses
I meaaannnn
I kind of load an elf

lol
I did read that mlibc will mainline ports for other kernels
I doubt mine is going in there tho

idk, maybe
they still synced for some reason @viral bison
lol idk
that's strange
did you apply my patches?
yes
@viral bison your patchset does the same
hmm
leme give you my patch set with the debuggable bad apple
OHHH RIGHT
you should not do that

btw, keep editing my patches

those have some more fixes
ooo like what else?
the vmm share pages fix
and a ctx switch one
tho i forgot to change this back to this
and remove the *--stack for the pagemap pasisng under it
IT WORKS
perfect
redoing the bad apple for int match and not needing to touch the PIT
you could still get the PIT ticks
Oh I meant as in reprogramming it
and convert the base freq to the amount of ticks needed
np
@viral bison I have a really stupid idea but I wana add a kernel level compositor
Not a full WM though 😭
But like being able to slice off bits of the frame buffer
And manage virtual ones
make a graphic thread
I can do that in userspace tho
And il setup my shared memory system
@viral bison wana know a fun fact about the bad apple demo I have
?
oooof
And before any userspace
And when I was making my own bootloader
FUCK THAT SHIT BTW
ALL HAIL LIMINE
XD
i might make my own BL too later on
when i have my own graphics lib
so i can make it very good looking
Oh btw wana know somthing really hacky I did
I was trying to get somthing to run on an embedded Linux device
But it only runs things as root
And my app says no no no
XD
Soooo
I made a shim .so file you preload
And it lies to it and it will tell it it’s UID 1000
And GID 1000
And that lets it run
XD
XD
That’s the other thing I need to put in my public domain repo
Because fuck this shit it’s ass
I don’t want credit
I don’t need it
Just take it and go
Oh I need to get the insane rant I made when I gave up that project
I made a timeline
From my shit memory but yeah a
@viral bison
If you open a project and seee this
What are you doing
wtf is that
Me going insane
yeah, i can see XD
I spent 3 sleepless days working on that project
maybe you should sleep more often
i'm 6h ahead if you, lol
This is also where I get some of my best work done
A lot of my kernel was made at 2am with the power of two entire two liters of Dr Pepper in my veins
This is how I code
i'm immune to caffeine
so that doesn't work for me
or well, caffeine makes me even more sleepier
But yeah I try and get shit done
And that’s why my commits are somtimes a little large
I do tons of manual fuzzing on my code
i make small commits, i have the fear of my SSD killing itself again
This is a real commit I did btw
I code a lot
(This is when I added bad apple and refactored a shit ton)
(When I did this commit I also did a limine conversion)
(And an entire project refactor from a single file)
(It was massive)
oof
Wait shit @viral bison
I don’t have a USB to validate this on real hardware
Mine dispersed
Let me merge my bad apple into your patch set and then I will generate a new patch
My OS dosnt use ISOs
You take a USB and make a fat32 gpt partition
And mark it as esp and boot
And put the proper files on it plainly
And it boots
k
It’s honestly pretty neat?
i prefer an iso
so i can use it with my ventoy usb
tho i still have like 4 or 5 more usbs

i dunno how to package it right ngl
i hope my changes diddnt fuck up the timing too bad on the bad apple
which files do i have to copy?
these?
@hazy saddle
ok, i booted in
i'm in the terminal
Yup
Now let’s test it
Can bad apple properly run twice
Or 3 times
Let’s see how far it can go before exploding
they are not overwriting in qemu
but it is failing a bit after
while on the laptop it's still going
in my qemu it keeps going
didn't it fail there?
oh wait
and then spam enter
my laptop is using the one with my patches only
i only ran make all
and copied the elf in the main dir
not the bin dir
it pagefaulted on rodata
wtf
XD
So what do we gotta do
idk
FUCKKKKK
they are still overwriting on my laptop, wtf
Even with my patches?
ye
Check the code did it apply right
yes, if i run it via qemu it works
WTF
oh wait what

Huh
idk
Does your patch set still change the TSS?
Rather the RSP0
Welp @viral bison back in stasis the project goes?
Or maybe @devout path can save us
Have you fixed the BAD APPLE fault?
Twice 😭
This one
Well any number of times*
But it randomly crashes from certain inputs
This is the current patch set rn
Idk
Mood
Yes
what is the status anyway
But we got new ones
It tries to execute code from ro data
99 little bugs in the code, 99 little bugs. Take one down, patch it around 117 little bugs in the code.
well if you want to update a branch I could take a look
Grab the main branch and apply these patches
This is how I do development as I don’t like “bad” code on the repo
bugfix is bad?
Well there are other bugs
sure but these are there currently too, wouldnt fixing one be better than none
Do you have limine installed
either way its ur repo
it will never be in that path
ill fix it somehow
It is on my system
I use nix
I should edit that script to support more than one distro
you could pull the binaries from github
or codeberg now I suppose
But it might not always been in the past specified by my script
it works if you run make all
at least, it got all the files it needed
and worked
you probably have limine installed
oh, maybe that
Limine and OVMF are used by QEMU so it it loads like a UEFI system?
The path limine is put in gets loaded automatically by OVMF
Huh neat
so how do I reproduce this issue
show
the ones evalyn told me to use
patches2.patch?
yes
strange, it's going fine for me too rn
nope
it nuked itself
the framebuffer had enough
works fine for me
are u guys running under kvm
this is after a few mins
well
Type on the keyboard too
That’s also part of it
i didn't have to do it
Run the CREDITS command and spam enter also caused it for me
why that attribute?

Dosnt unused just tell it that I don’t use it
And it should still deal with the stack right
i meant the interrupt one
Maybe it’s about time I do interupts in assembly isn’t it
yes
Good thing I have a good reference I can steal from since I’m working on a wiki with some friends as a side project and it has some about that
What’s the generated code from clang here 
I wana see what it’s doing to the stack
I’m in bed right now crying eating whip cream btw
So might take a bit to get up
Yup I should lmao
I’m work on this in the afternoon when I wakeup
And then hopefully we should be okay
@viral bison alright so plan
When I wake up I’m going to get assembly based interupts working properly and then if this fixes the bug things should be able to be properly cleaned up and pushed
I’m gonna order some USBs
Wait second wind is hitting
k
i got an extra 30 minutes of energy
lol
@viral bison would this be correct?
extern dispatch_interupt
%macro ISR 1
global do_isr%1
do_isr%1:
cli
push 0
push %1
jmp dispatch_interupt_asm
%endmacro
%macro ISR_ERR 1
global do_isr%1
do_isr%1:
cli
push %1
jmp dispatch_interupt_asm
%endmacro
dispatch_interupt_asm:
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
push rbp
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
mov rdi, rsp
call dispatch_interupt
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rbp
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
add rsp, 16
iretq
; Exceptions
ISR_ERR 0x08 ; DF
ISR_ERR 0x0D ; GPF
ISR_ERR 0x0E ; PF
; Hardware
ISR 0x20 ; PIT
ISR 0x21 ; PS/2
ISR 0x24 ; Serial #1 & #3
; Spurious Interupts
ISR 0x27 ; Spurious PIC1
ISR 0x2F ; Spurious PIC2
; System Call
ISR 0x69 ; Non POSIX System Calls
what am i missing?
basically all of the interrupts
yeah well
is fine because
that won't work
pagefault won't trigger
wym
i know?
then why you set it to 0x69

btw, syscall is not called like that in x64
ehhh
whom cares
i know but the docs were confusing for them
we talked about them a while ago in #osdev-misc-0
bc i did not uderstand those docs too
discord isnt wanting to bring up the message right 😭
search for my messages

leme finish this up first tho
oh also bonus part of this @viral bison is interupt driven panics will give me wayyy more accurate reg dumps
ye
gonna have to rework a good bit of shi rn but its gonna be good
wow and my adhd meds were taken on time
i think i got this
il keep this one in C rn because its a taken function and should be OKAY @viral bison
il convert later™
idfk it works
this shit is so unstable i dont wana touch it with a 10ft pole
that looks super close to my ISR hander code 
bc it basically is
yeah lmfao
i wanna get all the regs

so i can support syscalls from multiple oses
ooo smart
my friend had the reverse idea
if an app attempted a sys call from another os
it would know the process was compimised
so it would lock it down and lie to the process to make it suffer 
XD
eg malloc would return invalid kernel pointers or other shit
my future plan is to support windows app as good as possible
ala reactOS?
similar, yeah
you gonna have an entire UI framwork in the kernel 
can be added

i think i'll use modules for that
would be neat if you could have a hint system call maybe?
so if apps are aware of it they can tell you what layer to use
and i could compile my crt0 to emit that
well, my os will try to look at the header to know which os the app was made for
[clang] (-Wincompatible-pointer-types) Incompatible pointer types passing 'struct interrupt_frame *' to parameter of type 'struct interrupt_frame *' huh
wtf
src/kernel/interupts/gp_fault.h:4:33: warning: ‘struct interrupt_frame’ declared inside parameter list will not be visible outside of this definition or declaration
4 | extern void gp_fault_isr(struct interrupt_frame* frame);
| ^~~~~~~~~~~~~~~
src/kernel/interupts/interupts.c: In function ‘dispatch_interupt’:
src/kernel/interupts/interupts.c:10:26: error: passing argument 1 of ‘gp_fault_isr’ from incompatible pointer type [-Wincompatible-pointer-types]
10 | gp_fault_isr(frame);
| ^~~~~
| |
| struct interrupt_frame *
src/kernel/interupts/gp_fault.h:4:50: note: expected ‘struct interrupt_frame *’ but argument is of type ‘struct interrupt_frame *’
4 | extern void gp_fault_isr(struct interrupt_frame* frame);
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
✘ evalyn@EvalynPC ~/Documents/Programming/C/evalynOS master ± grep -Rnw . -e "struct interrupt_frame"
./src/kernel/interupts/gp_fault.h:4:extern void gp_fault_isr(struct interrupt_frame* frame);
./src/kernel/interupts/page_fault.h:5:extern void page_fault_isr(struct interrupt_frame*);
./src/kernel/interupts/interupts.c:4:void dispatch_interupt (struct interrupt_frame *frame) {
./src/kernel/interupts/double_fault.c:4:void double_fault_isr(struct interrupt_frame* frame) {
./src/kernel/interupts/interupts.h:30:struct interrupt_frame {
./src/kernel/interupts/interupts.h:37:extern void dispatch_interupt (struct interrupt_frame *frame);
./src/kernel/interupts/generic.c:4:void generic_isr(struct interrupt_frame* frame) {
./src/kernel/interupts/page_fault.c:4:void page_fault_isr(struct interrupt_frame* frame) {
./src/kernel/interupts/generic.h:3:extern void generic_isr(struct interrupt_frame* frame);
./src/kernel/interupts/double_fault.h:3:extern void double_fault_isr(struct interrupt_frame* frame);
./src/kernel/interupts/gp_fault.c:4:void gp_fault_isr(struct interrupt_frame* frame) {
./src/kernel/utils/panic.c:139:void panic(char* message, struct interrupt_frame* frame) {
./src/kernel/utils/panic.h:8:void panic(char* message, struct interrupt_frame* frame);
maybe a missing include?
Just gonna step in bc I noticed, but gp_fault.h also needs to include whatever header the struct is defined in
That's where the first warning is coming from at least
i do wonder why x86 dosnt have an instruction to push all GPRs to the stack?
its CISC right 
idk
i ❤️ switch/case statments
oooooof
its fine lmao
btw is my kernel code organized well
i dont have arch spesifc ISR folders because they are all x86 spesific
it should be good
well, time to find the issue
Want the patch file?
XD
im gonna breakpoint the exception handlers and then i can see the stack trace maybe
it crashes if i type too much on the keyboard
don't you already print it?
it crashes by also doing nothing
just play bad apple 1 time
its some kind of interupt
and after a bit the framebuffer is nuked
and my stacktrace failed to generate
#0 panic (message=<optimized out>, frame=<optimized out>) at src/kernel/utils/panic.c:409
#1 0xffffffff8000c0df in dispatch_interupt_asm ()
#2 0x0000000000000008 in ?? ()
#3 0x0000000000000206 in ?? ()
#4 0xffff810000030950 in ?? ()
#5 0x0000000000000000 in ?? ()
yeah well, if the stack gets nuked

yeah entire thing gets nuked
bump alloc pool is in here somwhere
prolly junk tho
@viral bison ERROR : 00000000 00000000 00000000 00001011
this aparently means its a segment related error coming from an external thing from the IDT at index 0b1
for the GPF error
oh
let me try and repro the PF one
wat hi
wat help do u guys need
lemme back tread
owh
yeah i got a few of those
serial manages to keep the logs properly tho
dis main problem?
well kinda
that dosnt happen on qemu but it will on rea; hwardware right
oke ima take my time and read
but this is most important
wat
your also gonna want the most recent patch file?
is this a fucking reserved bit being set FLAGS : 00000000 00000001 00000000 00000010
randomly
HUH
yes
what's the stack trace
fucked
random every time?
yup
not really random
i kept getting the same pagefault
but it was at a sub 0x1000 addr
but it can also somtimes GPF
okay that's at least great
wat patch are ya'll runnin on
patches2.patch
the github? then patches2.patch?
i have a patches3.patch i need to generate
no
no
how do i make it do that then
add the files
this is getting a lil big 
hm?
do i really need bootx64.efi on my /usr/share
when i did make run it said that
oh wait
im actually kinda dumb rn
;-; my ovmf name is different form here
i've been manually changing some stuff XD
wat
i can't seem to make this pf
i'll be back in like 30 mins to see what's happenin here
@hazy saddle
this must have to do with how the pages work ngl
hm?
i'll add more debug to ur pf if that's oke
im jus wildly guessin here but it must've been somethin that had to do with the corelation of the page entry table and the userspace
part of the stack trace code has checks for the kind of fault it is
yep
you can reorder it a bit and use that
hey @devout path atleast my kernel is less buggy than minecraft bedrock 
Honestly me you and diamond could probably remake bedrock in a few weeks and have something better 
Honestly that could be a fun group project after our kernels are in a decent shape
to be honest, we could LMAO
Make a from scratch vulkan game engine?
Mine is in 2d and I need to learn a lot more vulkan to fix the thing 
I did a c++ project with hot reloadable modules even
Could use some of that tech with it
It is LGPLv3 but it’s my own code so
I can do whatever I want with it
daangg
So when developing stuff could be modular and they can be reloaded like parts of the event loop
There is only one bug that I found with it too
If you delete a module
And then reload it gets unlosded
But if you put it back
And then reload to attempt to get it back
It will crash
But
that’s not HORRIBLE
And if the system dosnt need to be fully dynamic it will reduce issues
Or cross threads
Because I also had a thread pool
XDDD
But yeah what seems to be the happs here
i thought it would be that the pages are being assigned as user space
yep, lol
vulkan is pain tho
I THOUGHT it was faulty
my bad gng
Yeah but it would be good for preformance for a Minecraft like game
Nah nah I’m joking
compare it to j a v a :)
XDD
Because the pipeline can be tailored for block shor
Could even have threads for generating optimized geometry too?
So that’s offloaded
i tried patch2
HUH
QEMU or KVM bug?
SOMETHING THAT I DON'T KNOW LMAO
let me try TCG?
TRY PATCH 3
i did every thing i had to do for analysis
and im 80% sure it's all fine
i thought it was the vmm.c being a lil bitch
i skimmed it and foudn some questionable stuff
but when i put it in debug it had same result
it crashes even faster on TCG
dude intel is built diff i guess LMAO
in QEMU and TCG or KVM
im runnin on KVM rn
IM SO CONFUSED XD
wait..
i have a different bootx64 efi
nah most likely not because of that no?\
what in the actual fuck is this LMAO
here is mine
it should be limines?
i downloaded recent limine's binaries
hows your assembler
cuz i don't hav eit in usr/share
wat huh
im on latest
this is recent patch btw @viral bison
i applied patches3
do i have to apply patches.patch too?
no i don't think so ;-;
apply it to fresh
i only applied it to a new instance
i stashed the old ones
in vmm.c
so it was clean
change | to &
now it did a double PANIC HUH
ok im gonna stop guessing and actually check this out
@hazy saddle
#include <stdint.h>
#include <interupts/interupts.h>
#include <utils/panic.h>
#define PF_PRESENT (1 << 0) // Page is not present
#define PF_WRITE (1 << 1) // Fault was a write
#define PF_USER (1 << 2) // Fault from user mode
#define PF_RESERVED (1 << 3) // Reserved bit was set
#define PF_FETCH (1 << 4) // Instruction fetch fault
__attribute__((interrupt))
void page_fault_isr(struct interrupt_frame* frame, uint64_t error) {
// my head hurts
uint64_t faulting_addr;
asm volatile("mov %%cr2, %0" : "=r"(faulting_addr));
int present = (error & PF_PRESENT) ? 1 : 0;
int write = (error & PF_WRITE) ? 1 : 0;
int user = (error & PF_USER) ? 1 : 0;
int reserved = (error & PF_RESERVED) ? 1 : 0;
int fetch = (error & PF_FETCH) ? 1 : 0;
volatile uint64_t pf_addr = faulting_addr;
volatile int pf_flags = error;
volatile int pf_present = present;
volatile int pf_write = write;
volatile int pf_user = user;
volatile int pf_reserved = reserved;
volatile int pf_fetch = fetch;
(void)pf_addr;
(void)pf_flags;
(void)pf_present;
(void)pf_write;
(void)pf_user;
(void)pf_reserved;
(void)pf_fetch;
panic("Page Fault", 0x0E, frame, error, PANIC_FLAGS_FRAME | PANIC_FLAGS_ERROR | PANIC_FLAGS_VECTOR);
}
can u add this to ur page_fault.c
just check if i messed something up LMAO
void page_fault_isr(struct interrupt_frame* frame, uint64_t error) {
huh
it dosnt take in an error anymore
and it shouldnt be attribute((interrupt))??
did you not get the assembly intterupts code?
did your patch apply right?
#include <stdint.h>
#include <interupts/interupts.h>
#include <utils/panic.h>
attribute((interrupt))
void page_fault_isr(struct interrupt_frame* frame, uint64_t error) {
panic("Page Fault", 0x0E, frame, error, PANIC_FLAGS_FRAME | PANIC_FLAGS_ERROR | PANIC_FLAGS_VECTOR);
}
wasn't this the code earlier
that code got goned reduced to atoms
oops i think it didn't ;-;
o h
w e l p back to le drawing board
it should be like this
#include <interupts/interupts.h>
#include <utils/panic.h>
void page_fault_isr(struct interrupt_frame* frame) {
panic("Page Fault", frame);
}
i got a whole
extern dispatch_interupt
%macro ISR 1
global isr%1
isr%1:
cli
push 0
push %1
jmp dispatch_interupt_asm
%endmacro
%macro ISR_ERR 1
global isr%1
isr%1:
cli
push %1
jmp dispatch_interupt_asm
%endmacro
dispatch_interupt_asm:
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
push rbp
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
mov rdi, rsp
call dispatch_interupt
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rbp
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
add rsp, 16
iretq
; Exceptions
ISR_ERR 0x08 ; DF
ISR_ERR 0x0D ; GPF
ISR_ERR 0x0E ; PF
; Hardware
ISR 0x20 ; PIT
ISR 0x21 ; PS/2
ISR 0x24 ; Serial #1 & #3
; Spurious Interupts
ISR 0x27 ; Spurious PIC1
ISR 0x2F ; Spurious PIC2
; System Call
ISR 0x69 ; Non POSIX System Calls
; Others
ISR 0x16 ; Reserved (Used as placeholder for generic)
lemme rm -rf real quick
oopsie
anyways lemme make sure my patch actually applied first

XD
oops
heh...............................................................
welp
back to the drawing board
damn
oh shit what
YEP SAME REACTION
I ADDED SOME DEBUG XD
i ran that then it did that
yk what's funny i added an infinite loop but uuh it just went to that
how tf did it fail to load the bin file
0 damn clue
honestly i have no clue
oh wait
i think
nvm
nahi have no clue honestly
can you change the retuen values of the VFS layers?
see which one fails
eg
make these -2
gime a sec
@devout path is bad apple running atleast once if at all?
n o p e
It works for me???
Bad Apple runs
Is the initramfs building right?
Ok ok
There is an issue with my builds
If the bad apple compile fails
It fails silently
Cd into the folder and run the script manually
hmm me?
i kinda get it now
i don't have clang
ah yes i completely forgot
im not on my fedora
im on ubuntu
my bad my bad
thanks for pointin that out
Isn’t the main kernel also compiled with clang
Huh
now this is even more confusing LMAO
cuz i don't have clang on the os that i am using rn
philippine servers are absolute garbage
oh damn i built with gcc
fuckin
holy
BALLS
It’s the power of hopes and dreams
okay it's running
and it takes 3gb to make a cross compiler :)
fuck that ngl
What the fuck is a cross compiler!!!!!!!
I don’t use one
I probably should
But ehhhh
XD
How does cross compiler work on clang
oh idk i think clang already has one
u don't have to build it like how u did with gcc
im not entirely sure i always used gcc XD
there u go thank u so much
to be clear it wont have a target for your kernel by default obviously
so u still have to do that if thats what is being discussed
jimmir@jimmir-workstation:~/debugevalynOS$ addr2line -e ./kernel.elf 0xffffffff8000fa9f
??:?
jimmir@jimmir-workstation:~/debugevalynOS$
a compiler able to target a different platform than the host platform
this ain't useful at all lmao
I was making somthing called a joke
XD
did not make that very clear
Does that need to be complied from scratch or is it a conf file thing
needs to be compiled
depends on which compiler you wanna use
gcc needs to be rebuilt
Is there a good way of distributing that for people? Or do I make people spend like an hour comping clang 
their own kernel
Yeah and I already use clang with a ton of command line arguments so it should already be fine
It takes way more than an hour nowadays lmao
okay cool
as long as the flags are right then yes
I used to use native GCC with the same arguments and it worked 
lucky 😂😂
w a t
The flags were like
heh
Everything
Every flag
Oh you should see my first build script I had for this kernel before it got serious
oh so targeting freestanding
Actualy @devout path take a look at that and the bad apple build script
I wonder if you can see how similar they are
what did u do before u even messed this up
hmm?
Well before only one bad apple could run at once
Now there are two
Is it even running properly for you now?
Compiling etc
yes i can run badapple
yep i got a gpf
that's why i did addr2line earlier
then it returned a whopping ?:??
very insightful
this looks fine besides not disabling xmm register usage
I actually did use FPU registers in some of my kernel code at one point 
nevermind then ☠️
Like on purpose 
heh
I said I am going to use the floating point registers 
And then I used them
And it worked
actually i do nothing then it pfs
Quite queer
heh.......................................................................................................................................
it is not crashing
i think i found it
needs more in-kernel floating point
What about my set of 60 randomized kernel panic messages
Ooo
is it true random? 👀
idk if ur going to judge my fix but uuh
it works LMAO
badapple sounds like deathcore to me now
dang
Nah it’s just based of the TSC at the time of panic and some random algorithm
well
i made the context switch save evry registr
and then
i made it so that
the initial thread matches to the first switch and returns to actual code instead of whatever the fuck mlao
so yeah it's been 15 mins
no crash XD
@viral bison is the one that made the thing not save every register 
you shouldn't do that tho
that's strange
i m e a n : )
What does this mean
global thread_switch
global switch_to_user
section .text
thread_switch:
pushfq
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
push rbp
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
mov [rdi], rsp
mov rsp, rsi
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rbp
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
popfq
ret
USER_STACK_TOP equ 0x0000000080000000
switch_to_user:
mov ax, 0x30 | 3
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
push 0x30 | 3
mov rax, USER_STACK_TOP
push rax
push 0x200
push 0x28 | 3
push 0x4000
iretq
i don't save all the regs and it works
#include "stddef.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <scheduler/scheduler.h>
#include <scheduler/switch.h>
#include <filesystem/filesystem.h>
#include <memory/vmm.h>
#include <memory/pmm.h>
#include <drivers/x86_64/ports.h>
#include <drivers/x86_64/gdt.h>
#include <utils/panic.h>
uint64_t STACK_SIZE = 65536;
void task_quit() {
while (1) {
}
}
struct thread_node* threads = NULL;
int next_thread_id = 0;
void create_thread(void (*entry_point)(void*), pagemap_t *pagemap) {
bool had_threads = (threads != NULL);
struct thread* new_thread = malloc(sizeof(struct thread));
memset(new_thread, 0, sizeof(struct thread));
new_thread->stack = malloc(STACK_SIZE);
memset(new_thread->stack, 0, STACK_SIZE);
new_thread->stack_top = (void *)(((uintptr_t)new_thread->stack + STACK_SIZE) & ~0xFULL);
new_thread->is_user_task = 0;
new_thread->threadId = next_thread_id;
next_thread_id++;
if (pagemap != NULL) {
new_thread->pagemap = pagemap;
} else {
new_thread->pagemap = kernel_pagemap;
}
uint64_t *stack = (uint64_t *)new_thread->stack_top;
if (entry_point == NULL) {
entry_point = task_quit;
}
*--stack = (uint64_t)task_quit;
// heh mlao
*--stack = (uint64_t)entry_point;
*--stack = 0x202;
*--stack = 0; // rax
*--stack = 0; // rbx
*--stack = 0; // rcx
*--stack = 0; // rdx
*--stack = 0; // rsi
*--stack = 0; // rdi
*--stack = 0; // rbp
*--stack = 0; // r8
*--stack = 0; // r9
*--stack = 0; // r10
*--stack = 0; // r11
*--stack = 0; // r12
*--stack = 0; // r13
*--stack = 0; // r14
*--stack = 0; // r15
don't judge
: )
why task quit too
new_thread->rsp = (uint64_t)stack;
struct thread_node* new_node = malloc(sizeof(struct thread_node));
new_node->thread = new_thread;
if (!had_threads) {
new_node->next_thread = new_node;
threads = new_node;
} else {
new_node->next_thread = threads->next_thread;
threads->next_thread = new_node;
}
shouldSchedule = 1;
}
void schedule() {
outb(0x20, 0x20);
asm volatile("cli");
struct thread *previous_thread = threads->thread;
threads = threads->next_thread;
struct thread *current_thread = threads->thread;
vmm_switch_to(current_thread->pagemap);
tss.rsp0 = (uint64_t)current_thread->stack_top;
thread_switch(&previous_thread->rsp, current_thread->rsp);
}
struct thread *get_current_thread() {
return threads->thread;
}
this the extention to the scheduler.c
im actually brain cooked rn
im gonna look at a window and refresh
brb
what happens if a task is using r9. it context switches. and another clobbers it
im back
the problem is that the user registers are saved on the stack
so the code earlier only set a partial register set and had a stack layout that d i d n t m at ch ;-;

so changing there should not have any effect
heh : )
for some reason
what is 202 here *--stack = 0x202;
basically this bug now fixed pls do try
flags
but what flags
it prob wasn't the regs
did u remove the
as i said
remove the thing
the
no
it is the regs
u have to remove one thing
the
sti
fuck
what was it again
bro i didn't take notes
wait
wait wairt
i got it
idk just compare
but the user registers are not touched in the ctx switch
oke nice
i had a fuckup
oh
its not crashing