#EvalynOS

1 messages · Page 5 of 1

devout path
#

i can finally sleep in fuckin peace

#

Lord so help me

hazy saddle
#

thank you so much

devout path
#

you're welcome!

hazy saddle
#

o n o

devout path
hazy saddle
#

nothing heh

#

go sleep

devout path
#

imma read more of ur kernel before i do

hazy saddle
#

Is my kernel really that cool?

devout path
#

maybe document this in a md file : )

hazy saddle
devout path
#

yes :D

hazy saddle
#

What was the fix btw?

#

I’m also sleep deprived

devout path
#

@viral bison

#

pls explain

viral bison
#

what?

#

the fix you did?

devout path
#

wat was the fix

#

yes

#

i want someone else to figure it out

viral bison
#

from what i saw, you added back the saving of all the registers

devout path
#

y e s

#

correct

viral bison
#

i still don't know why that works

devout path
#

n e i t h e r d o i : )

#

that's why i sa i d

#

d o n 't j u d g e : )

#

this is me taking shots at random shit

devout path
#

until u actually do get it

hazy saddle
#

You might wana checkout my HRMR codebase if you like my kernel code

viral bison
#

@obtuse loom why would saving all the regs on ctx switch fix this?

devout path
#

im presuming that this doesn't return to garbage anymore

hazy saddle
#

That’s some of my c++ work

hazy saddle
#

Wait

#

@devout path @viral bison

#

The real hardware test

devout path
#

hi

#

oh god

hazy saddle
#

Let me generate a patch file

viral bison
hazy saddle
viral bison
#

and the initramfs

hazy saddle
hazy saddle
#

Remember when my kernel was like 5MB

#

Because the bad apple was bundled inside of it

devout path
#

XD

hazy saddle
#

Oh also remember when it was kernel.bin and not kernel.elf

#

When I had my own bootloader

viral bison
#

oh god

devout path
hazy saddle
#

That never wanted to work between real machines

viral bison
#

i nuked the kernel before the cli initialized

hazy saddle
#

Because universal my ass UEFI

viral bison
devout path
#

im juggling between what i know and what theory would be

#

and both contradicts atp

#

i have no fuckin clue anymore

obtuse loom
devout path
viral bison
#

btw @hazy saddle pressing enter or whatever key before it says press enter, will lock up the kernel

hazy saddle
#

Thread one saves data in R9
Kernel switches to thread 2
Thread 2 puts its own shit in R9
Kernel switches back to thread one
Thread one gets wrong data from R9 and fucks over the stack

viral bison
#

the framebuffer was getting nuked after a bit

obtuse loom
hazy saddle
viral bison
#

so was the whole stack

hazy saddle
#

Once I get a user space shell

devout path
#

try mine

viral bison
devout path
#

im losing hair chat

hazy saddle
viral bison
#

@obtuse loom from here basically

hazy saddle
#

It’s held up with sticks and stone and ten pounds of Elmer’s glue

viral bison
#

btw, it's working on real hw

hazy saddle
#

LETS GOOOO

viral bison
#

tho i hear my cpu crying in pain

hazy saddle
devout path
#

im going to cry

viral bison
#

pls put pause on the quit thread

hazy saddle
obtuse loom
hazy saddle
obtuse loom
#

what does the context switch look like

devout path
viral bison
devout path
#

before it was this

global thread_switch
global thread_switch_user
global switch_to_user

section .text
thread_switch:
    pushfq
    push rbx
    push rbp
    push r12
    push r13
    push r14
    push r15

    mov [rdi], rsp
    mov rsp, rsi

    pop r15
    pop r14
    pop r13
    pop r12
    pop rbp
    pop rbx
    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


#

now this

viral bison
#

now it looks like this

devout path
#
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


obtuse loom
#

how do you declare/call thread_switch

#

in C land

hazy saddle
#

Switch to user will get rewritten btw so I can load them anywhere and maybe even have ASLR?

#

With how buggy it is though I don’t know if we should have ASLR XD

devout path
hazy saddle
devout path
#

xd

devout path
#

yeah and then i decided to change it

viral bison
#

somehow saving all the regs fixed it tho?

obtuse loom
#

I think your diff just happens to make another bug not happen

devout path
#

yeah and then i saved every reg

hazy saddle
obtuse loom
#

you probably have some situation with some corruption hitting the stack of another task

#

that's my best guess

#

and changing the layout like this happens to make the important values move somewhere that's not overwritten

hazy saddle
obtuse loom
#

all the registers you added to the push/pop list are callee saved

#

so the compiler should manage it correctly

devout path
#

y e s

obtuse loom
#

unless you call it incorrectly

#

like from inline asm without clobbers

devout path
#

well i think it was with the create_thread funct earlier it had dupe pops

#

so i was like

#

: )

#

am i right

#

m literally just

#

completely guessing

viral bison
#

tho that function worked

#

i was using it fine

hazy saddle
#

Until it didn’t hmmCat

devout path
#

y e s

viral bison
#

it didn't when you changed something inside badapple

devout path
#

it had dupe pops so the ptr after the switch wasn't pointing at a valid saved rip

viral bison
#

huuh

obtuse loom
#

the old thread_switch is correct, can't say the same for the rest of the codebase

#

:^)

devout path
#

hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

#

REALLY

#

so it wasn't the ret jumping to whatever the fuck?

viral bison
#

no

devout path
#

im gonna stop thinking

viral bison
#

it was working

#

badapple was even starting correctly

devout path
#

but it did it randomly

#

oh

#

fair

#

wait my bad

hazy saddle
#

Question? How much of a performance penalty is there from manually putting the pushes and pops verses the compiler doing it for you

devout path
#

: )

obtuse loom
#

well I mean

#

you're not changing the declaration

#

so the calling code will still save all those registers for you

#

and then you're saving them again

devout path
#

so there wasn't any missing regs or anything??!

obtuse loom
#

so you're not getting the benefit of the compiler not saving them for you either

obtuse loom
devout path
#

im damn hallucinating

obtuse loom
#

only the ones listed as Preserved across function calls need to be listed

devout path
#

oh yeah right

obtuse loom
#

the compiler knows calling an external function will clobber all the other registers

#

as I said, as long as you're not misusing inline assembly to call it

hazy saddle
#

I don’t think I am

obtuse loom
#

as long as you're calling it from normal C there should be no bugs related to this

hazy saddle
#

this would be proper for setting up the inital stack though right?

#

and feeding in an argument

viral bison
devout path
hazy saddle
obtuse loom
#

switches are not functions

hazy saddle
#

yes i did remove that

obtuse loom
#

this only applies for sys-v

#

what's your target

devout path
#

yeah

hazy saddle
#

should be sys-v

devout path
#

huh

obtuse loom
#

okay

#

double check that

devout path
#

y e a

#

cuz

hazy saddle
#

how would i do that?

obtuse loom
#

if you're targeting some UEFI callconv or something

#

then you're fucked

hazy saddle
#

i dont think i would be

devout path
#

o m h

obtuse loom
devout path
#

i mean

#

this is sys-v

#

it's compiling freestanding to x64 so

#

absolutely it is

obtuse loom
devout path
#

yeaaah

#

ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Advanced Micro Devices X86-64
Version: 0x1

#

i had to do readelf xd

obtuse loom
#

okay you're good

hazy saddle
#

if i put this back in i gett an uhh page fault right away

devout path
#

HUH

viral bison
obtuse loom
hazy saddle
#

right

viral bison
#

yeah well

hazy saddle
#

fuck

#

i need to shave it to 6 registers right

viral bison
#

yes

devout path
#

yeah

viral bison
#
  • flags
#
  • rip
devout path
#

it should work theoretically

hazy saddle
#

@devout path

devout path
#

hi

#

wat happened

hazy saddle
#

dramatic drum roll please

devout path
#

dramatic drumroll

hazy saddle
#

It works

obtuse loom
#

amazing

hazy saddle
#

Thank you for your help @obtuse loom

obtuse loom
#

🎉

viral bison
#

so it wasn't the registers

#

lol

devout path
#

;-;

obtuse loom
hazy saddle
obtuse loom
#

what was it

hazy saddle
#

God if I know

obtuse loom
#

😂

#

fair enough

devout path
#

it was about saving the flags?

viral bison
#

it's time for me to finish implementing syscalls

hazy saddle
#

Who needs system calls when you have int 0x69

obtuse loom
devout path
#

lesson learned: 67

hazy saddle
devout path
#

wait can u send the patch for what u just did @hazy saddle

obtuse loom
devout path
#

fair

hazy saddle
obtuse loom
#

it's fine

#

but it's not needed

#

up to you if you want to remove it

hazy saddle
#

how would one go about doing that btw

obtuse loom
#

removing pushf and popf?

hazy saddle
#

oh thats it

#

@devout path this is it

#

asude from the | to an &

#

in the vmm

devout path
#

oh

viral bison
hazy saddle
#

What happens if the thread attempts to return to nothing though?

viral bison
#

it shouldn't

#

i think

obtuse loom
hazy saddle
#

Better safe than sorry?

devout path
hazy saddle
#

Task quit could also start auto cleanup of the thread on return

viral bison
#

i have a reaper thread just for that

#

(you should too)

hazy saddle
#

but what if the thread its self was also the reaper?

viral bison
#

it might end up very badly

hazy saddle
devout path
#

these what if shouldn't be discussed when it hasn't happened yet : )

#

i love making problems for myself

hazy saddle
#

but hell yeah

viral bison
#

turns out i set the scheduler in the same interrupt as my PIT

#

LOL

hazy saddle
hazy saddle
#

Wdym

obtuse loom
#

unexpected

hazy saddle
#

Ah

devout path
#

wat featuers would u like to have in ur OS @hazy saddle

hazy saddle
#

I eventually want it to be able to compile its self

devout path
#

i copuld probably dev somethin

#

oh

#

fair

hazy saddle
#

And to run a window manager

hazy saddle
hazy saddle
devout path
#

develop somethin

hazy saddle
devout path
#

i mean

viral bison
#

small cheat to skip int 0x80

#

lol

hazy saddle
#

I use int 0x69

#

Because I can

viral bison
#

0x80 is the standard in linux apps

#

for 32 bit

hazy saddle
viral bison
#

btw, that code is for IOApics

#

so if they ever reach 0x80, i just make them go up by 1

hazy saddle
#

Can’t that u8 be a Boolean

viral bison
#

boolean is an u8

devout path
#

imma jus do a pr

#

is anyone workin on ur os too or nah?

hazy saddle
#

A PR to what

devout path
#

just u

hazy saddle
#

I still have some cleanup to do rn

#

Of debug logs n shit

devout path
#

oh for stuff that i'ma try to build for this os xd

#

o h

#

oke

hazy saddle
devout path
#

ext2 support : )

hazy saddle
#

Don’t I need a physical disk driver tho?

devout path
#

f a i r

hazy saddle
#

I was gonna hold off on that until PCIe and USB so I can have a driver for nvme ssd and mass storage devices

viral bison
#

you'll need uAcpi

#

and prob IOApic

#

and Apic

hazy saddle
devout path
#

true

viral bison
#

and some better timer

#

like hpet and tsc

#
  • the apic timer
hazy saddle
viral bison
#

so you can get accurate timings

hazy saddle
#

But yeah ext2 would be really low priority

#

And honestly jumping the gun to ext4 would be based

devout path
#

yea ;-;

hazy saddle
#

Perhaps you can work on the APIC and co drivers?

devout path
#

yeah why not

hazy saddle
#

After I do some basic cleanup on this and push

devout path
#

ye yes

#

that' swhat i was plannin to do

hazy saddle
#

Can you also use sata in a legacy mode to make it more easy to talk to too?

#

That could work for ext2 perhaps

devout path
#

yes

hazy saddle
#

And I can get a cheap SSD and throw it in my PC for testing

viral bison
#

me who wanna support HPFS

devout path
#

uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuh it'll prolly take me a week though ;-; but yes yes ofc ofc

viral bison
#

or was it APFS

hazy saddle
viral bison
#

it was APFS

devout path
#

yeaa

viral bison
#

if you wanna read this

#

lol

devout path
#

xd

hazy saddle
#

Linux DRM driver port when

#

Sarcasm btw to be clear

devout path
#

;-;

obtuse loom
viral bison
obtuse loom
#

I mean sure lol the license allows it

viral bison
#
  • i plan to have macos and windows ones too in the future
hazy saddle
#

Has anyone ever done that before here

obtuse loom
#

yes of course

#

very unoriginal

hazy saddle
obtuse loom
#

there are even people who do it without releasing the source and breaking the license

devout path
#

i copy linux (the kernels) subsystem's architecture : )

hazy saddle
#

Honestly my kernel should be able to get doom once I get a libc done?

viral bison
hazy saddle
#

I just need to get system calls for file stuff

#

And handle file descriptors

hazy saddle
#

It’s not that much more than libc and 5 functions

viral bison
#

corpos are strange

obtuse loom
obtuse loom
#

you can already break the license

viral bison
#

MIT license

obtuse loom
#

no one is getting in trouble for it

viral bison
#

they are giving the rust ports MIT licenses

hazy saddle
#

Huh

obtuse loom
#

plenty of companies have changed linux, not released changes and gotten away with it

#

it happens daily

hazy saddle
#

I think I may of broken the license when I had to modify the driver on my local device to get a controller working bonking

obtuse loom
hazy saddle
#

I should probably dig it up fix it and put it on GitHub

#

Ahh then I’m fine

obtuse loom
#

etc etc

hazy saddle
#

Ehhhh so sue me

#

@devout path alright I’m gonna clean it up

viral bison
#

this is a strange memmap, lol

hazy saddle
#

What were the parts you were gonna work on again

viral bison
#

uefi and its strange stuff

#

also, you should prob not use bootloader reclaimable stuff

obtuse loom
viral bison
obtuse loom
#

what stack are you using

viral bison
#

i leave the default one alone

obtuse loom
#

from the bootloader?

viral bison
#

yes

obtuse loom
#

then check the spec

viral bison
#

k

devout path
#

just simple stuff

#

i plan to make a block driver for now

obtuse loom
#

or something else?

devout path
#

i can make the syscal isr though

#

if u'd like

viral bison
obtuse loom
#

"rsp is set to point to the top of a stack, in bootloader-reclaimable memory, which is at least 64KiB (65536 bytes) in size, or the size specified in the Stack Size feature. An invalid return address of 0 is pushed to this stack before jumping to the executable's entry point."

viral bison
#

i'll leave the bootloader reclaimable mem alone then

#

i don't lose a lot anyway

obtuse loom
#

...or just allocate a stack in the kernel :^)

viral bison
#

i can do that?

obtuse loom
#

I mean

#

there are a few ways of doing that

#

but yes

viral bison
#

i already get the stack top

obtuse loom
#

1: Just set up multitasking and exit the init task that's using it

#

2: Just write to rsp in the entry point, declare it in asm

viral bison
#

oh i do that already

obtuse loom
#

there are probably many more

viral bison
#

all the tasks have their own rsps

obtuse loom
#

yes and when you're done using bootloader data (including that stack) then you could use bootloader reclaimable memory

viral bison
#

k

#

i might do that in the future then

hazy saddle
#

wait @devout path how should i handle returning systemcall data?
would i just do frame->rax = ...

#

yeah that works

devout path
#

yes

#

my hand was filled with cheese i couldn't reply

#

xd

hazy saddle
#

and now this clobber list can go bye bye now i control registers properly

#

i wonder what n00b thinks of this

devout path
#

heh

hazy saddle
devout path
#

@hazy saddle

#

do u know zig

#

the programming language

hazy saddle
#

ive heard of it

#

but never touched it

devout path
#

oh damn

#

it's better than C i tell ya

hazy saddle
#

looks too high level

devout path
#

yep

hazy saddle
#

i really like C alot tbh

devout path
#

what's weird is that u declare by making it a constant xd

#

same

#

imma hit the sack

#

mention me here once you're done cleanin up

hazy saddle
#

wait before you do

devout path
#

mm?

hazy saddle
#

what was the things you were gonna work on?

#

and yeah i will

devout path
#

oh just a simple block driver

#

so i can have it support ahci

hazy saddle
#

from SATA and ext2 right?

devout path
#

yes

#

that'll take me

#

more or less

#

a week to 3

#

im slow

hazy saddle
#

nice ;3
what devices will it be selecting lol

#

also if i make any changes il ping

#

so the merge conflict isnt an ass

devout path
hazy saddle
#

like what if there are two sata drivers

devout path
#

oh that'll be a problem for me in the future

#

i'll think of something XD

hazy saddle
devout path
#

HEH

hazy saddle
#

have it check GPT parition table for the right UUID?

#

and pass it in as a limine boot cli arg

devout path
#

hmmmmmmm yeah prolly

#

mmmmmmmmmmmmmmmmmmmmm

#

yeah i guess

hazy saddle
#

its how linux does it right

devout path
#

LMAO

#

i was planning to deviate from what linux does

#

but if i get extremely lazy

#

i'd probably just do that

hazy saddle
#

but i mean wouldnt it be good to be able to spesifiy the drive and partition to mount

#

maybe have it handled in the initramfs?

devout path
#

yeah yeah

hazy saddle
#

maybe init system program?

#

it has some conf files about drives

devout path
#

maybe hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm

#

oh

devout path
hazy saddle
#

and then that can even start the shell etc

#

No need for a FULL init system

#

But having a program to read a config on how to mount the root drive and start the shell?

devout path
#

yes ofc

#

more practical tbh

hazy saddle
#

That way you can make the conf file run any program

#

Or have it be a chain of programs to run?

#

To say mount drive and then run program to setup network card layer

#

And THEN run the shell

#

Maybe use TOML for the config that’s easy to parse right

devout path
#

yeah

hazy saddle
#

Or “TOON” mmLol

devout path
devout path
#

was that sarcastic or

#

xD

hazy saddle
#

No

#

Not sarcasm

devout path
#

o h

hazy saddle
#

What’s the issue with TOML

devout path
#

nothing nothing

#

im just kinda dead rn

#

4 am

#

3 am *

hazy saddle
#

gonna need one more test on irl hardware before push

#

but im almost done reviewing and getting rid of stargglers

devout path
#

nice

hazy saddle
#

next commit will be a simple generic constructor for threads

#

what do these refer to again

#

ehhh il figure it out

#

should work with sysv

#

worst case mmLol inline asm grab the reg

devout path
devout path
hazy saddle
#

can i also get a video recording of the many bad apples for friends?

devout path
#

oh

hazy saddle
devout path
hazy saddle
#

on real hardware

#

so leme finish this up

#

almost there

devout path
#

oke

#

I lost my flashdrive i can't run this on hardware ;-;

hazy saddle
#

WTF

devout path
#

why

hazy saddle
#

nuuuuuu

#

@viral bison you still here

viral bison
#

just finished eating

hazy saddle
#

code review looks good enough and its LGTM

viral bison
#

send it if you want me to try

hazy saddle
#

Can you also record a little video of it running many bad apples at once

viral bison
#

i'll try to see if i then can upload it here

devout path
viral bison
#

@hazy saddle

hazy saddle
#

Fuck yeah

hazy saddle
#

I did it buddy. It’s gonna be pushed to main soon and then you can get inspired

#

Your kernel is saved

#

@viral bison this about sums it up right

hazy saddle
#

@devout path its pushed

tawdry ingot
devout path
#

thank u!

hazy saddle
hazy saddle
#

Il add that to the list for far things in the future

devout path
hazy saddle
# devout path yea

If the initramFS is starting to near ~16MB il start work on compression probs

hazy saddle
#

I think I can compile it as a freestanding app and point it to my headers for a libc and generate a .a file for static linking

#

As il need to make a really custom libc because I’m missing some semantics it would need

#

And il have to emulate them

devout path
hazy saddle
#

I’m gonna have to have the libc emulate them

#

And that will handle FDs and map them to the right file operations for the system call side

hazy saddle
#

@viral bison how do the system call instructions work on x86-64 btw

#

Like how would I be meant to set them up

#

I know it’s an MSR but isn’t a bit more than that?

viral bison
#

Frame and Syscall regs contain basically the same values

hazy saddle
#

Looks really easy tho

viral bison
#

the Segments?

hazy saddle
#

And then in userspace it’s just load things into register and call syseenter?

hazy saddle
#

The selectors and the MSR addresses

viral bison
#

warning, the GDT has to be like this

hazy saddle
#

The selectors are offsets to the GDT entires right

viral bison
#

yes

#

but it HAS to be like this

#

the layout i mean

hazy saddle
#

Unless I change the offsets to work for me?

#

Or just straight up

viral bison
#

the msrs are fucked up

#

they want UCODE32, UDATA and UCODE64 in that exact order

#

same for KCODE and KDATA

hazy saddle
viral bison
#

you can skip UCODE 32 tho

#

and just set that value to the entry before UDATA

#

if you don't want to use the syscall instruction in a 32 bit env

hazy saddle
#

My kernel is gonna be 64 bit only

#

For now atleast

viral bison
#

i do support compat mode too

hazy saddle
viral bison
#

(or well, it should)

viral bison
#

then as i said, the msrs are fucked up

#

so it gets the other entries by hardcoded offsets

hazy saddle
hazy saddle
#

I don’t know the magic numbers I have to fill in here yaaar

hazy saddle
viral bison
#

just change the Long Mode bit on ucode

#

for the compat mode

#

every entry is +0x8

hazy saddle
#

Ok the wiki has the right numbers

#

Il change to #defines and then use them

#

These are the 32bit ones

hazy saddle
viral bison
#

yes

hazy saddle
#

Should be easy

viral bison
#

we hope

hazy saddle
#

20 minute quick adventure in and out

#

@devout path i may wana make a dev server for github commit notis and shit so its easier for you if i am pushing stuff when you work

#

or just in general

#

i dunno if the mods here could get a web hook in a thread?

#

wtf do flags match to

#

@viral bison anything wrong with this

#

the wiki values dont wana work

#

even just for 64 bit ones

#

wait why did this skip 4??

viral bison
#

?

#

XD

hazy saddle
#

the flags should be fine

viral bison
#

then wdym it doesn't work

viral bison
hazy saddle
#

triple fault

viral bison
#

when?

hazy saddle
#

then would this jsut work™

viral bison
#

if you set the right offsets yes

#

aren't the flags wrong tho

hazy saddle
#

This is my original code

#

That did work

#

But with it swapped

viral bison
#

well, did you edit all the selector values too?

#

like, in every other asm file

#

you should have to edit: GDT asm file and the ctx switch

hazy saddle
#

I don’t have a GDT asm file

viral bison
#

well, the code you use to load it

hazy saddle
#

What code do I need to change? The segments were at the same offset for atleast trying to replicate the wikis version

viral bison
#

well, you did swap ucode and udata

#

did you also swap their values in the loading / ctx switch?

hazy saddle
#

Wait what

viral bison
#

if previously udata was 0x30 and ucode was 0x28

#

now it's the opposite

hazy saddle
#

But its faulting even before my context switch code

#

But yeah I’d have to change that I think

viral bison
#

well, i think you did not swap those values in the gdt loading

hazy saddle
#

I’m
Too sleepy for this rn

viral bison
#

oh wait

#

i don't think you have to swap them there

#

hmm

#

i think the flags are wrong

hazy saddle
hazy saddle
viral bison
#

try to copy mine

hazy saddle
#

I’m trying to get system calls to use the right instruction

hazy saddle
viral bison
#

it's just 4 bits

hazy saddle
#

So like a compiler hint?

viral bison
#

no, it sets the size to 4 bits only

hazy saddle
#

Oh you can’t do that in C yaaar

#

Or can you?

#

You can

#

Huh neat

#

wait @viral bison how do these constructors work to mappings things out

hazy saddle
#

i mean how does c++ map the consttor arguments to parts of the struct

#

this shoiuld be okay ho

void gdt_set_tss (int num) {
    gdt[num].limit_low = sizeof(tss);
    gdt[num].base_low = (uint64_t)&tss & 0xffff;
    gdt[num].base_mid = ((uint64_t)&tss >> 16) & 0xffff;
    gdt[num].access = 0x89;
    gdt[num].flags = 0;
    gdt[num].base_high = gdt[num].base_mid = ((uint64_t)&tss >> 24) & 0xff;
    gdt[num].base_high = gdt[num].base_mid = ((uint64_t)&tss >> 32);
}
viral bison
#

srry here

#

after the :

viral bison
#

try to set the flags like i do

#

also

#

ltr is just wrong

#

ltr should be loading 0x18

#

oh wait no

#

you changed it

#

then yes it's ok

hazy saddle
#

then why triple fault

viral bison
#

idk

hazy saddle
viral bison
#

we need the full log

hazy saddle
#

what log its faulting i cant get anyb data out

viral bison
#

.!c qemu

#

.!t qemu

nova edgeBOT
#
qemu

Run QEMU with following flags: -M accel=tcg,smm=off -d int -no-reboot -no-shutdown

hazy saddle
#

i did fix this line gdt[num].base_higher = gdt[num].base_mid = ((uint64_t)&tss >> 32);

viral bison
#

here

hazy saddle
viral bison
#

also -D log.txt

devout path
devout path
hazy saddle
#

the base_high vs base_higher

#

thats blocked by the server?

viral bison
#

no

floral kettle
#

yeah it got automodded

hazy saddle
#

damn

viral bison
#

i downloaded it

#

well, here are the 2 exceptions

hazy saddle
#

thats a tripple fault no?

viral bison
#

doesn't seem like so

hazy saddle
#

i mean without the flags it auto reboots

floral kettle
#

then its a triple fault

viral bison
#

but i only see 2 exceptions there

hazy saddle
#

last line

devout path
viral bison
#

check RIP ffffffff80001e37

devout path
#

im still tryna figure out why my fix worked yesterday

devout path
#

absolute dead

hazy saddle
viral bison
#

addr2line -fai -e <exe> <addr>

hazy saddle
#

/home/evalyn/Documents/Programming/C/evalynOS/src/kernel/drivers/x86_64/gdt.c:73

devout path
#

i on't think doin any static analysis would come up to somethin useful

#

ok im gonna regret saying that but

#

nvm

#

ok nice

viral bison
#

well, what's there?

hazy saddle
viral bison
#

try to do it in pure asm

#

and stop using inline

hazy saddle
viral bison
devout path
#

oh nvm

viral bison
#
  • the asm above
floral kettle
hazy saddle
viral bison
#

wtf

hazy saddle
hazy saddle
viral bison
# hazy saddle

did you set the ist of every other interrupt to a non 0 or 1 value?

hazy saddle
#

I don’t think so

viral bison
#

that might cause problem

hazy saddle
viral bison
#

move the df stack to like 2

#

and leave 0 unallocated

hazy saddle
#

like this

viral bison
#

yes

viral bison
#

but remember to update it too

hazy saddle
viral bison
#

where you set the ints

hazy saddle
#

TRIPLE FAULT

viral bison
hazy saddle
#

What

viral bison
#

you set DF to 2 here

hazy saddle
#

shit

viral bison
#

while on the ist screenshot you set it to 1

#

(this is not the cause btw)

hazy saddle
#

still TFs

viral bison
#

yeah well

#

we have to find out why it TFs

viral bison
hazy saddle
#

would this be proper qwinci?

struct __attribute__((packed)) GDTEntry {
    uint16_t limit_low;
    uint16_t base_low;
    uint8_t  base_mid;
    uint8_t  access;
    uint8_t  limit_high : 4;
    uint8_t  flags : 4;
    uint8_t  base_high;
    uint32_t base_higher;
    uint32_t _reserved;
};

void gdt_fill_entry (int num, uint8_t access, uint8_t flags) {
    gdt[num].limit_low = 0;
    gdt[num].base_low = 0;
    gdt[num].base_mid = 0;
    gdt[num].access = access;
    gdt[num].limit_high = 0;
    gdt[num].flags = flags;
    gdt[num].base_high = 0;
    gdt[num].base_higher = 0;
}

void gdt_set_tss (int num) {
    gdt[num].limit_low = sizeof(tss) - 1;
    gdt[num].base_low = (uint64_t)&tss & 0xffff;
    gdt[num].base_mid = ((uint64_t)&tss >> 16) & 0xffff;
    gdt[num].access = 0x89;
    gdt[num].limit_high = 0;
    gdt[num].flags = 0;
    gdt[num].base_high = gdt[num].base_mid = ((uint64_t)&tss >> 24) & 0xff;
    gdt[num].base_higher = gdt[num].base_mid = ((uint64_t)&tss >> 32);
}
hazy saddle
# viral bison how is the stack represented btw

heh

__attribute__ ((aligned (16))) uint8_t kernel_stack[16384];

__attribute__ ((aligned (16))) uint8_t user_stack[65536];

__attribute__ ((aligned (16))) uint8_t df_stack[65536];

__attribute__ ((aligned (16))) uint8_t nmi_stack[65536];
viral bison
#

ah

#

65k is too much i think btw

#

i only gave it 4k

#

anyway, let's go back to that TF

floral kettle
#

it should only be 64 bits

#

and the 64-bit int following the actual tss gdt entry is what you should set to tss_addr >> 32 like you did in the old code you had in git

viral bison
#

like this

hazy saddle
#

i copied this for that yaaar

viral bison
#

XD

#

that is the TSS one

#

lol

floral kettle
#

you don't need a separate one for the tss one anyways, if you really want to keep the gdt entry split to separate fields like that instead of just one u64 you could make it an union of a struct that contains the normal fields and then just a plain u64

#

and then do smth like ```c
gdt[index].entry = make_gdt_entry(...);
gdt[index + 1].tss_addr = tss_addr >> 32;

hazy saddle
#

whats a union

floral kettle
#

you haven't ever used an union in c?

viral bison
hazy saddle
#

Not yet

#

But working GDT

viral bison
#

Gg

hazy saddle
#

Could you re give the screenshots for the MSRs and stuff for the new syscall thing

viral bison
#

Sec, i'm finishing my pizza

hazy saddle
#

Oooo what kind

viral bison
#

and homemade

hazy saddle
#

Oooooo

viral bison
#

here

hazy saddle
#

thank you

hazy saddle
#

Note that the Kernel does not automatically have a kernel stack loaded. This is the handler's responsibility.
@viral bison should i just grab this from the threads->stack_top?

viral bison
#

i think

#

or i might be doing it wrong

hazy saddle
viral bison
#

sec

#

u64 yeah

hazy saddle
viral bison
#

you also need to enable again interrupts After you loaded rsp

viral bison
#

and split it inside

hazy saddle
#

i mean for the first arg

hazy saddle
viral bison
#

it should be u64

hazy saddle
#

the osdev wiki says otherwise yaaar

viral bison
#

it's a 64 bit reg

viral bison
#

i think it's still in 32 bit

#

lol

hazy saddle
#

XD

viral bison
#

or well, maybe MSRs are all 32 bit for IDs

#

i just use 64 bit for convenience

rancid viper
#

there are no 32bit MSRs

#

where on the osdev wiki

hazy saddle
#

for the ID

rancid viper
#

oh

#

that is 32bit

hazy saddle
#

here we go

viral bison
#

huuh

#

rdmsr is wrong

#

it's the same as wrmsr XD

#

it's reading

#

so it should be returning stuff

hazy saddle
#

this is the wikis version

viral bison
#

that is using pointers

hazy saddle
#

ah

viral bison
#

you are not

rancid viper
#

here is a C one ```c
static inline uint64_t x86_64_msr_read(uint64_t msr) {
uint32_t low;
uint32_t high;
asm volatile("rdmsr" : "=a"(low), "=d"(high) : "c"(msr));
return low + ((uint64_t) high << 32);
}

viral bison
#

yeah i sent it above

hazy saddle
#

bonk me

rancid viper
viral bison
#

it's basically the same

#

nothing changes

#

just the cast

hazy saddle
#

wait i also need to set bit zero here

viral bison
#

huuh

#

i might have to do it too

floral kettle
rancid viper
viral bison
hazy saddle
rancid viper
viral bison
#

ah

#

what does limine enable in that register?

rancid viper
#

LME

viral bison
#

only?

rancid viper
#

afaik

#

yeah

viral bison
#

oh

#

i'll enable all the features then

rancid viper
#

could double check the proto, I dont use limine after all

floral kettle
# rancid viper xd, is that a clang one

msvc lol (though clang's intrin.h implements that too, idk if you can use that with other targets than windows tho might not be able to because of sizeof(long) being different)

viral bison
#

does fast FXSAVE enable any other instruction?

viral bison
rancid viper
#

that gets enabled by the cpu

floral kettle
#

lma isn't something you can set yeah

rancid viper
#

seems like I was almost correct

#

NX is also set

viral bison
#

k

rancid viper
#

I forgot that was in efer

#

lol

viral bison
#

so what does fast fxsave do?

#

and can i enable it always if i have fxsave?

rancid viper
#

im not sure, I dont enable it at least

#

prolly gotta read the sdm for that answer

hazy saddle
#
    uint64_t efer = rdmsr(EFER);
    efer |= (1 <<  0);
    efer |= (1 << 11);
    wrmsr(EFER, efer);
viral bison
hazy saddle
#

that enable NX right

viral bison
#

limine enables that for you if the cpu supports it

rancid viper
#

yep

hazy saddle
rancid viper
#

I just panic out if NX isnt supported iirc

#

lmao

viral bison
rancid viper
floral kettle
rancid viper
#

I check a bunch of cpuid bullshit in init somewhere

#

so happens to be there iirc

hazy saddle
#

if your CPU dosnt have NX get a cheap used office pc from ebay for cheap

rancid viper
#

will prolly come across that code soon, im revamping my init system

floral kettle
#

for the fxsave bit as far as I can tell the intel sdm doesn't say its even there, it falls within a reserved range so it might be amd only

viral bison
floral kettle
#

its probably nothing you should worry about (and you should prefer xsave/xrstor to fxsave/fxrstor anyway if they are present)

viral bison
hazy saddle
#

this is what i do for fxsave and it works on intel. i enabled it to fix a crash when i had kernel sse

hazy saddle
#

i dont use kernel sse anymore tho

rancid viper
#

xD

hazy saddle
viral bison
#

how i do it

rancid viper
#

I have this routine that I for the most part borrowed from somewhere

viral bison
#

also, this is cursed

#

but works

#

lol

hazy saddle
rancid viper
#

#define true (__rdtsc() % 2 == 0)

viral bison
#

?

#

rng boolean?

rancid viper
#

chad boolean

hazy saddle
#

wrmsr(SFMASK, ~0x2); why is this a NOT 0x2?

viral bison
#

so you disable every rflag except res1

hazy saddle
#

ah

hazy saddle
#

@viral bison ?

void init_syscall() {
    // enable syscall instruction
    uint64_t efer = rdmsr(EFER);
    efer |= (1 <<  0);
    wrmsr(EFER, efer);

    uint64_t star = ((uint64_t)0x18 < 48) | ((uint64_t)0x08 << 32);
    wrmsr(STAR, star);

    wrmsr(LSTAR, (uint64_t)syscall_handler);
    wrmsr(SFMASK, ~0x2);
}

void execute_syscall(struct syscall_frame* frame) {
    asm volatile (
        "movq %0, %%rsp"
        :
        : "r"(get_current_thread()->stack_top)
        : "rsp"
    );
viral bison
#

do you have a user code 32?

hazy saddle
#

yes

viral bison
#

k, it should be ok then

hazy saddle
#

then i swap this out

viral bison
#

huh?

#

it's already ok

hazy saddle
#

nono

#

from int 0x69 to syscall

viral bison
#

i don't see an int 0x69 there

hazy saddle
#

it was

viral bison
#

idk if it'll work

hazy saddle
#

yeah shit

#

il just not inline it

#

its easier

#
change_stack:
    mov rsp, rdi
    ret
#

wait what else did i have to do other than chanign stacks? @viral bison

#

it still GPFs

#

at in usercode

viral bison
#

i think you are still changing the rsp wrong

hazy saddle
#

huh

viral bison
#

tho it's strange that it happens in usercode

#

what do the error bits say?

hazy saddle
#

external IDT

#

wait leme check somthin

viral bison
#

strange that is failing in the IDT

hazy saddle
#

wait

#

lmfao