#Nyaux

1 messages ยท Page 12 of 1

tawdry mirage
#

by 8 probably

surreal path
#

it is aligned

#

its still faulting

#

ok new problem

#

when mlibc tries to log via a syscall

#

the value of the msg is null

#

so i page fault

#

is that allowed

#

wtf

tawdry mirage
#

sounds like your sysdep is broken?

surreal path
#

FUCKING LOOK

#

CHAT LOOK

#

WE WON

#

MLIBC WORKS

#

LOADED FROM AN ELF

#

OH MY GILLY GOSH

#

!!!!

#

MINTSUKI

#

SEE THIS

surreal path
unkempt relic
surreal path
surreal path
#

so far implmentated 2 syscalls

#

sys_log and sys_vm_map

#

i need sys_open

#

then these syscalls

#

and then i will have bash

#

๐Ÿ˜Ž

kind root
#

Are you telling me bash doesn't need to start processes or wait on them

surreal path
#

uhhh no just for like

#

a basic prompt

#

like without executing processes lol

#

to continue tho

#

i need to implment file decsriptors

#

or whatever tf

kind root
#

Trivial

surreal path
#

also with me now officially getting into userland and stuff

#

i wanna start thinking of how i should design my kernel

#

currently my kernel is a monolithic kernel

#

but i am a little interested in the benefits of a microkernel or hybrid kernel

#

im not saying im making nyaux into a hybrid kernel or heck even a microkernel

#

but im just saying that like

#

when i get a chance to breath and we have a good amount of syscalls implmented into the kernel

#

i might start thinking about splitting some things off into modules or smthin maybe make the kernel more modular idk

#

we'll see

#

also maybe one day ill rewrite the scheduler to support smp

#

later down the line

#

also 23d is pretty fast for proper user mode and elf loading

#

do i get server wr any%

#

oh and also we just hit 11k messages in ze thread

#

lol

finite summit
#

well if you make a hybrid kernel

#

you'll likely need module loading

#

and modules will likely need kernel symbols or symbols from other modules

#

which pretty much means you need some sort of dynamic linker in the kernel

surreal path
#

ah hell nah

#

nvm

#

i heard extra work and my body went

#

๐Ÿƒโ€โ™‚๏ธ

finite summit
#

my third kernel's dynamic loader for modules is only

#

~700 lines

surreal path
#

"only 700 lines"

#

๐Ÿ’€

#

yeah and my entire vmm is 533 lines

#

im not doing a dynamic linker u cannot make me!!! ๐Ÿ˜ 

finite summit
#

old kernel is only 300 lines

surreal path
#

bru

finite summit
#

nvm

#

that wasn't the dynamic loader

#

it's 500 lines

surreal path
#

oh

finite summit
#

but it supports almost all relocations for some reason

#

you apparently can get away with only a couple

surreal path
#

maybe later down the line

#

ill think bout it

thorn bramble
# surreal path do i get server wr any%

im sorry but i got into userspace in one night with zigux :^) i was loading statically linked binaries but whatever, i had some syscalls and i was able to run an assembler, i was also learning zig at the same time!!

alpine mulch
#

thats not fair, wasnt your first

thorn bramble
#

but it was my first that got past creating a page table

leaden hinge
#

23d was about when i had things like signals and poll()

#

then i lost all my motivation

ionic jetty
thorn bramble
unkempt relic
#

a hybrid kernel has all the benefits of a monolithic kernel and none of the downsides of a microkernel

unkempt relic
#

all actually-existing things called "hybrid kernels" are just monolithic kernels with more features

worldly condor
unkempt relic
worldly condor
#

also, on another note, it seems you have K&R-style function definitions in your code

green elbow
#

register ๐Ÿ’€

unkempt relic
#

it's a special sort of kernel which has all the benefits of a monolithic kernel

#

but none of the downsides of a microkernel

haughty kite
unkempt relic
haughty kite
#

other than that you can pretend to be a microkernel

unkempt relic
#

monolithic might be a cool word but hybrid is cooler

haughty kite
unkempt relic
haughty kite
#

do you have drivers in usermode

unkempt relic
unkempt relic
surreal path
#

yea

worldly condor
#

I'd recommend fixing it, and maybe not stealing code in the future

#

especially considering licensing

#

cuz the license on your repo says BSD0

haughty kite
#

oh yeah you cant do that

surreal path
#

wait wha

worldly condor
#

and I don't think you can redistribute 4.4BSD code under BSD0

surreal path
#

whats the liscence

#

for 4.4bsd

unkempt relic
#

3-clause BSD, possibly 2

worldly condor
#

3-clause BSD iirc

surreal path
#

lemme read about it

molten grotto
#

just rewrite the function yourself

#

its not that hard

worldly condor
#

^

#

and don't use K&R style functions

#

use ANSI style functions exclusively

surreal path
#

i dont want bsd to sue me

worldly condor
#

nah, you want to get rid of that code anyways

unkempt relic
#

it's easy to follow the licence, you just copy the notice

worldly condor
#

^

surreal path
worldly condor
#

that's true

surreal path
#

lol

worldly condor
#

but it's a K&R style definition

#

so just get rid of it

#

just a handful of lines

#

you can write it yourself

surreal path
#

its probs gonna be shitty code so im just gonna copy the notice

worldly condor
#

no

worldly condor
#

you'll improve it by rewriting it yourself

molten grotto
# surreal path nah its okay ill just modify my license or whatever

also you don't have to change the license of your entire project if you use some code licensed under a different license unless its like gpl or whatever, you just add a notice somewhere saying what part is licensed differently and the corresponding copyright/license notice

worldly condor
#

^

surreal path
#

okay

worldly condor
#

at least if you're going to keep it

#

I urge you

#

rewrite it to ANSI-style declaration

#

please

molten grotto
#

also while you are at it fix all the compiler warnings (well except for unused things) :p

worldly condor
#

yes

#

don't ignore compiler warnings

#

especially in C

surreal path
#

and im not touching string functions i fucking hate working on them

worldly condor
#

just rewrite the one you have

surreal path
#

i hate strings

#

in general

worldly condor
#

ok

#

fine

#

I'll rewrite it for you

unkempt relic
#

you don't need to steal you can just move the parameter types into the brackets

worldly condor
#

sek

surreal path
#

if u do that make it a pr or somthin

worldly condor
#

turn

int strncmp(s1, s2, n)
    register const char *s1, *s2;
    register size_t n;
{

    if (n == 0)
        return (0);
    do {
        if (*s1 != *s2++)
            return (*(unsigned char *)s1 - *(unsigned char *)--s2);
        if (*s1++ == 0)
            break;
    } while (--n != 0);
    return (0);
};

into

int strncmp(const char *s1, const char *s2, size_t n)
{

    if (n == 0)
        return (0);
    do {
        if (*s1 != *s2++)
            return (*(unsigned char *)s1 - *(unsigned char *)--s2);
        if (*s1++ == 0)
            break;
    } while (--n != 0);
    return (0);
};
#

that's all you need to do

#

also fix the declarations

#

in the header

#

from:

int strncmp(s1, s2, n);

to:

int strncmp(const char *s1, const char *s2, size_t n);
#

same goes for every other K&R style function you have in your codebase

haughty kite
worldly condor
#

i.e. strcpy etc ...

molten grotto
#
int strncmp(const char* a, const char* b, size_t len) {
    for (; len; --len, ++a, ++b) {
        int ret = *a - *b;
        if (ret != 0 || !*a || !*b) {
            return ret;
        }
    }
    return 0;
}
surreal path
#

done i fixed the functions

#

u happy now

#

@worldly condor

worldly condor
#

๐Ÿ‘

#

now fix all the other compiler warnings as well (if there are any) halfmemeright

surreal path
#

okay fine

#

but there are like

#

a billion compiler warnings

haughty kite
#

add -Wall -Wextra -Werror to your makefile

worldly condor
#

well maybe not -Werror

haughty kite
#

no add -Werror

worldly condor
#

but he already has -Wall and -Wextra

haughty kite
#

exactly

#

so add -Werror

surreal path
#

this is uacpi code

#

im not fuckin messing with that

#

go ask @kind root to fix the warnings in his code

haughty kite
#

@ 8infy fix your shitty code smh gcc's onto you

#

oh yeah this path is broken

worldly condor
#

I guess it's complaining cuz the default case in that switch doesn't initalize res

#

yeah

haughty kite
#
            uacpi_error("dead code\n");
            return UACPI_STATUS_INTERNAL_ERROR;
``` add this instead of the break after default
surreal path
#

tell him to merge that into uacpi or smthin

kind root
#

what

surreal path
#

fix ur compiler warnings

#

for uacpi

kind root
#

its a false positive

haughty kite
kind root
#

that case is unreachable

haughty kite
#

assert that?

#

__builtin_trap

kind root
#

i dont do that

haughty kite
#

or return internal error or whatever

kind root
surreal path
#

then go do that

kind root
#

later

#

i have a wip pr that ill add that fix into probably

haughty kite
#

you should build with -Wall -Wextra -Werror tbh

worldly condor
surreal path
kind root
#

i already do

haughty kite
#

weird

#

oh i guess new gcc

kind root
#

maybe nyaux is using some new gcc

haughty kite
#

"fix"

surreal path
kind root
#

the official fix will be return UACPI_STATUS_INVALID_ARGUMENT

kind root
surreal path
#

the vmm alone has 30 warnings

#

fucking pain

#

frick am i supposed to fix these type of warnings

surreal path
#

bruh

molten grotto
#

just use zero in place of NULL if its an integer

surreal path
#

ill just cast null to uint64

molten grotto
#

bruh

surreal path
molten grotto
#

its not even a pointer that you are comparing so why do you want to compare it with NULL

surreal path
#

does it matter

#

it fixes the warnings

molten grotto
#

yes but it doesn't really make any sense to do that

surreal path
#

๐Ÿฆ

molten grotto
#

unless you purposefully want to make bad code

surreal path
#

fine

#

ill fix it

#

ugh

haughty kite
#

also what on earth is that line

surreal path
#

checks if theres a page table entry at that index

#

anyways fixed all vmm.c warnings

#

the heck is this warning for

molten grotto
#

it doesn't make any sense to have volatile on a return type

#

at the very least when its void

surreal path
#

right

molten grotto
#

probably not otherwise either

surreal path
#

okay fixed a bunch of warnings

#

be happy now

#

๐Ÿ˜ 

#

anyways

#

i need to work on making file descriptors or whatever tf those are

#

okay so a file descriptor is like

leaden hinge
#

an integer

surreal path
#

wdym

#
struct file_descriptor
{
  struct vnode *ptr;
}
struct file_descriptor descriptors[MAX_FILE_DESCRIPTORS];
#

or maybe im

#

misunderstanding

#

am i misunderstanding?

tawdry mirage
#

i think you want another level of indirection between a file descriptor and a vnode?

surreal path
#

wdym

tawdry mirage
#

fd table -> open_file * -> vnode *

surreal path
#

and what is this open file structure consists of

molten grotto
#

things like the current position in the file for an example

surreal path
#

why would u store that

leaden hinge
#

and mode its opened with

surreal path
#

wdym mode?

leaden hinge
surreal path
#

huhhhh

leaden hinge
#

with a file with contents hello, you would expect these results getc() -> 'h' getc() -> 'e'

#

which means you need to store the position somewhere

surreal path
#

right

#

but what about

#

mode

tawdry mirage
#

actually you need even more indirection? fd table -> fd -> open file -> vnode

surreal path
#

bru

#

why

tawdry mirage
#

fd has flags like CLOEXEC, open file has offset

haughty kite
tawdry mirage
#

(also abbreviated fd)

leaden hinge
#

ah

#

yeah

tawdry mirage
surreal path
#

this is getting confusing

surreal path
#

wtf

#

๐Ÿ’ฅ

tawdry mirage
#

close on exec

surreal path
#

wdym Close on Exec??

#

tf does that do

tawdry mirage
#

that it says on the tin

surreal path
#

execute what

tawdry mirage
#

when you exec file descriptors with CLOEXEC set are automatically closed

haughty kite
#

closes the file when you call exec

surreal path
#

why would u exec a file descriptor

#

wtf

kind root
#

bro doesnt know what exec is

surreal path
#

bru

molten grotto
kind root
#

the most common unix primitive

tawdry mirage
#

and man 2 execve

surreal path
#

bru im confused (i barely know shit about unix internals, so its difficult to make my kernel unix like if i dont know unix internals in ze first place nooo )

#

im gonna watch a few videos on unix internals ig

#

this playlist seems cool

#

GUYS OD U SEE THAT

#

S-S-S-S-S-SUS????

#

THE FUNNY WORD????

#

#amongusreferencefoundinunix

haughty kite
#

so funny.

surreal path
#

i know right

haughty kite
#

the sus was first.

surreal path
#

among us is unix

#

confirmed

leaden hinge
#

not description

surreal path
#

i guess this is one of the mistakes of writing a kernel too fast, you miss key aspects about basic os design (in this case UNIX) and you spend way more time then u should learning about them cause you didnt take the time to learn about them

#

dunno if this made sense but yea

#

well to be fair

#

this is my first real os afterall, i never rlly got far with neptune or photon cause those fucking sucked and i didnt understood mostly of what i was doing

#

to which i do now

#

and the faact that i got this

#

far

#

into userland?

#

with elf loading and mlibc

#

im rlly proud of myself

#

and in just under 30 days too

#

im happy that all the late night hours working on this project paid off to something

#

the kernel may be spaghetti code, and i literarly only have 2 syscalls but still

#

it paid off to something

alpine mulch
surreal path
#

whats with the marks on the kitty

#

what happened

#

???

#

are those kiss marks?

#

poor kitty

unkempt relic
molten grotto
#

also @surreal path can you commit the .gitmodules file when you do your next commit?

#

without it being there you have to manually clone uacpi and the submodule is useless

surreal path
molten grotto
#

its set up by git

#

you should have it if you added a submodule with git submodule add

surreal path
#

i dont know what submodules are in git lol

#

also i modified uacpi source a bit

#

so

molten grotto
#

I wonder what exactly is the uACPI thing you have in your repo then

surreal path
#

uacpi

molten grotto
#

I mean obviously but it just results in an empty folder when you clone it and it shows it the same way as submodules in github ui

surreal path
#

i dont know how to fix that

#

cause i didnt use git submodule add

#

for uacpi

#

i just cloned it

molten grotto
#

ah yeah that probably explains it

#
[submodule "uACPI"]
    path = kernel/src/ACPI/uACPI
    url = https://github.com/UltraOS/uACPI.git
``` just put this into a file named .gitmodules in your repo root
surreal path
#

thing is

#

i modified some uacpi source

#

its gonna undo those changes

#

isnt it

molten grotto
#

ah, well yeah

#

why did you modify something in uacpi tho

surreal path
#

cause its required

#

for porting uacpi

#

platform include headers

#

yk

molten grotto
#

you mean files like platform/stdlib.h?

#

well actually no you don't need to modify that as you can just create a file named uacpi_stdlib.h somewhere in the include paths and define UACPI_OVERRIDE_STDLIB

surreal path
#

br

#

bru

#

no workie

molten grotto
#

that would recursively include it, assuming you do have src/ACPI added to the include paths

#

you don't want to include platform/stdlib.h in your uacpi_stdlib.h

surreal path
#

ok

molten grotto
#

and you add the define in the makefile using -D

surreal path
#

ldflags?

#

no workie

molten grotto
#

cppflags

surreal path
#

ko

#

ok

molten grotto
#

did you add -I src/ACPI to cppflags too

surreal path
#

ok works now

#

ok now i added the .gitmodules as well

#

what else

#

that it?

molten grotto
#

assuming you didn't modify anything else within uacpi then yeah that should be enough

surreal path
#

alr

#

pushing to git

#

done

molten grotto
#

looks like you also should add -D UACPI_SIZED_FREES to cppflags as you are using the sized variant of uacpi_kernel_free, include lib/nanoprintf.h in uacpi_stdlib.h and define PRIu64 to "lu" there too because uacpi still looks to be using that in a few places instead of UACPI_PRIu64

#

after those changes it builds straight from git (after either cloning it with git clone --recurse-submodules or running git submodule update --init after cloning it)

surreal path
#

ok done

#

ok works now

#

anyways i have a question, so when loading ld.so

#

what does mlibc do

#

im curious

thorn bramble
#

go read the code

#

ld.so is the dynamic linker

#

it looks at the executable

#

loads all the needed libraries

#

relocates them

#

resolves symbols

#

jumps

surreal path
#

so why does ld.so call sys_openat

#

or sys_open

#

is it trying to get some libraries

#

to load

#

?

thorn bramble
#

yes

#

lmao

surreal path
#

lol

#

also another question, about sse and stuff

#

i heard i need to do fxstore

#

and fxload

#

after every context switch

#

or smthin

#

is this correct?

#

do i have to store the value of these registers in the thread struct somewhere?

#

or am i misunderstanding

thorn bramble
#

yes, sort of

#

you do need to save and restore them

#

at the same time you save and restore other registers

#

except the fpu state is variable size

finite summit
surreal path
#

oh

molten grotto
#

well with the legacy fxsave its not

thorn bramble
#

oh fair enough

surreal path
#

im not using xsave

#

to be fair

thorn bramble
#

then listen to these guys

#

:^)

finite summit
thorn bramble
#

i think i just allocated a single page for the fpu state

#

more than enough

surreal path
# finite summit why not

it seems quite complicated and i dont wanna dive into the SDM head down for days trying to setup xsave

finite summit
#

bruh

thorn bramble
#

its just one bit

#

in cr0

#

or whatever

#

or cr4

#

idr

finite summit
#

also some cpuid for the save of the xsave region

#

and some writing to some fpu register

#

to enable it

#

xcr0

#

or somethin

surreal path
#

i dont think its a big deal if my kernel supports xsave or not

finite summit
#

it kinda is

surreal path
#

why

thorn bramble
#

i think you need it for sse

#

idk

molten grotto
#

no

finite summit
#

you lose a lot of sse

molten grotto
#

you need it for avx

finite summit
#

stuff

surreal path
finite summit
#

which user space might want to use

thorn bramble
#

advanced vector extensions

finite summit
#

to hardware accellerate shit

#

or something

molten grotto
surreal path
#

oh

#

great

#

more confusing shit for me

#

!!!

thorn bramble
#

its not that confusing

#

its very simple

#

compared to what you went through

#

lol

surreal path
#

i bet its probs pain trust

thorn bramble
#

you set some bits in the registers

#

ive done it

surreal path
#

but fpu state can have variable region size

thorn bramble
#

if you use xsave

#

which you might want to do

#

you use cpuid to get the size of xsave region

surreal path
#

oh

finite summit
#

It's cpuid leaf 0xd subleaf 0

#

in ecx

surreal path
#

sorry subleaf?

thorn bramble
#

some cpuid functions check the value of edx

#

or ecx

#

or wahtever

#

its documented

surreal path
#

sdm says subleaf is ecx

#

i think

#

so i need to put 0xd in eax

#

and 0 in ecx

#

and then run the cpuid instruction

#

correct?

finite summit
#

indeed

thorn bramble
#

i think so

#

yeah

finite summit
#

then the output ecx should have the size of xsave

#

note you should probably check if xsave is supported beforehand

#

and maybe fallback to fxsave if it's unsupported

#

anyway gtg

surreal path
thorn bramble
#

yes

finite summit
#

yes

surreal path
#

okay

#
get_xsave_region_size:
  push rbp
  push rbx
  mov rbp, rsp ; stack frame lol
  mov eax, 0xd
  mov ecx, 0
  cpuid
  mov rax, ecx ; put return value 
  pop rbx
  pop rbp
  ret

then i can call it in C

thorn bramble
#

you dont need the first 2 instructions and pop rbp if you dont touch the stack

molten grotto
#

you have to preserve rbx

#

also just make a cpuid function in c that does cpuid using inline asm and returns a struct

#

its more useful

surreal path
#

i suck at inline asm

#

u have no idea

#

how fucking bad i am at inline asm

surreal path
#

lol

molten grotto
#

cpuid touches rbx tho

surreal path
#

oh

#

yea so i need to push that to the stack then

surreal path
#

xsave region is of 2696 bytes

#

how big can a xsave region be?

molten grotto
#

that sounds reasonable

thorn bramble
#

wait until you realize that avx512 exists

#

it might grow even bigger if you enable that

surreal path
#

now should i just store a pointer to the xsave region allocated on thread creation for each thread struct?

thorn bramble
#

yea

surreal path
#
struct Thread
{
   ...
   void *fpu_state;
   ...
}
kind root
#

fpu_state

surreal path
#

fine fpu_state

surreal path
#

to be fair

thorn bramble
#

doesnt matter

surreal path
#

okay and what else do i need to do

#

on context switch just do the instruction "xsave"?

#

and xstor?

molten grotto
#

yeah first save the old thread's context using xsave and then load the new thread's context using xrstor

#

also you need to setup the xcr0 register once at the same time when you get the xsave region size for an example

surreal path
#

what do i write to xcr0?

#

cause theres a bunch of stuff

#

bit 1 and 2?

molten grotto
#

the two first bits you can always enable yeah

surreal path
#

oka

molten grotto
#

for the rest you should query cpuid to see if they are supported (mostly just avx and avx512) before enabling

surreal path
#

why care about avx512

molten grotto
#

well if you don't compile userspace programs with it then you don't need to care

surreal path
#

i dont

#

since when did cpus have avx tho

#

?

molten grotto
#

sandy bridge

#

and whatever amd had at that time

surreal path
#

great so now i have to query cpuid AGAIN

molten grotto
#

just steal my cpuid inline asm function or smth

surreal path
#

where

molten grotto
#

its gpl according to the repo license but I don't care if you just steal it, its so small anyway

surreal path
#

u sure?

molten grotto
#

yes

surreal path
#

thanks qwinci

molten grotto
#

and I mean you have to modify it a little to work with c anyway meme

surreal path
#

yea meme

molten grotto
#

also one thing with the xsave area is that it has to be 64-byte aligned so you probably want to just align the size up to page size and then allocate that amount of virtual pages (unless your kmalloc gives you addresses that are aligned to that)

surreal path
#

๐Ÿ˜Ž

surreal path
#

xcr0 is a register

#

tf

molten grotto
#

you use xsetbv to write to there

surreal path
#

oh

#

xsetbv %0

#

no wait i need to put the value in ecx

#

this is where my inline asm knowledge dies

molten grotto
#

asm ("" : outputs : inputs (and for outputs you prefix the modifier with =), for ecx you use "c", for eax "a", for edx "d"

surreal path
#

oh

molten grotto
#

or actually there is a way which might be easier to understand, c void wrxcr(uint32_t index, uint64_t value) { register uint32_t ecx asm("ecx") = index; register uint32_t eax asm("eax") = value & 0xFFFFFFFF; register uint32_t edx asm("edx") = value >> 32 & 0xFFFFFFFF; asm volatile("xsetbv" : : "r"(ecx), "r"(eax), "r"(edx)); } "r" normally specifies that it can be any register but if you define a variable like that with register and asm(<reg name>) it uses the register specified in that asm

surreal path
#

can i steal this trl

#

im stealing this

#

and then im gonna make the xsave and xrstore

molten grotto
#

yeah thats fine, I just made this up as I don't do it using register/asm like this, but imo this is easier to understand if you don't know the inline asm register modifiers

surreal path
#

also, xsave %0

#

and then

#

xrstor

#

%0

#

what is an instruction mask

molten grotto
#

I think you can choose what states (like avx etc) from the ones you have enabled in xcr0 you want to save, you can just pass all ones to it to save everything you have enabled

#

same with xrstor

surreal path
#

okay so put nothing in edx:eax

#

dont care bout it

#

alr

molten grotto
#

all ones

surreal path
#

oh

#

i misunderstood

molten grotto
#

I meant like all bits as ones

surreal path
#

oh

#

right

molten grotto
#

also you want to use the 64 bit versions of xsave/xrstor which means postfixing them with q

surreal path
#

okay

#

what about xsetbv

#

xsetbvq?

molten grotto
#

I don't think you need it for that

surreal path
#

ok

molten grotto
#

you need it for xsave/xrstor because they use a different state format depending on whether you use the 32-bit or 64-bit one

surreal path
#

okay these are my functions

#

i think they look okay

#

xsetbv causes invalid opcode?

molten grotto
#

there is a cr4 bit for it

surreal path
#

oh

#

yea bit 18

#

ok enabled

#

now on thread creation just create fpu_state

#

allocate size of xsave_region

#

and whenever we switch threads

#

use xsave store and xrstor

#

?

#

that it

#

should kernel threads also have fpu state

molten grotto
#

if your kernel doesn't use sse or whatever else then they don't need to

surreal path
#

i dont rlly mind

#

to be fair

#

ill just allocate it anyway

#

this easy?

molten grotto
#

yes

#

you might need to make xsave/xrstore static inline instead of plain inline though because inline sucks in c

#

or just make them normal non-inline functions in a c file and then put decls to a header

surreal path
#

i just put them in the header

molten grotto
#

probably because you need to put parens around the %0 as they expect memory operands

surreal path
#

ok works

#

okay it works!!!

#

now we have fpu state!!!!

#

๐Ÿ˜Ž

#

isnt that cool

molten grotto
#

oh also there is some special values you want to put in fcw/mxcsr parts of the fpu state that you can look up in the sysv amd64 spec when you create the state (and other than that it should be zeroed out)

surreal path
#

that was actually rlly easy

molten grotto
#

(and you find fcw/mxcsr registers in the fxsave structure that is at the beginning of the xsave region)

surreal path
#

wha

molten grotto
#

just look at the sysv abi spec and sdm

surreal path
#

umm sysv abi and sdm spec dont say much about it

surreal path
#

i just

#

void *fpu_state

molten grotto
#

well you can just create it and then cast your fpu state to it

molten grotto
surreal path
#

but i do see what im supposed to set fcw and mxcsr to

surreal path
#

is this it?

molten grotto
surreal path
#

ok found

molten grotto
#

yes that

surreal path
#

what are the numbers on the top

molten grotto
#

bytes from the offset on the right

surreal path
#

okay so mxcsr and fcw is all i care about

molten grotto
#

yeah you don't really have to modify anything else

#

everything else can be zeros

surreal path
#
struct fpu_state_t
{
uint16_t fcw;
...
uint32_t mxcsr;
}
molten grotto
#

fcw is two bytes

surreal path
#

oh

#

ok there

surreal path
molten grotto
#

thats not correct

surreal path
#

wdym?

molten grotto
#

look at the image you sent

surreal path
#

oh right

#

wait no

#

64 bits is 8 bytes

#

fcw is 2 bytes

#

thats 16 bits

#

right

molten grotto
#

yes

surreal path
#

last one should be 6 bytes

#

instead of 8

#

ig

#

okay there

#

i should also make the struct packed ig

molten grotto
#

first rev should be 6 bytes

surreal path
#

oh

#

better?

molten grotto
#

yes

surreal path
#

ok

#

cool

#

now should work

#

ok works

#

๐Ÿ˜Ž

#

NOW

#

we have fpu state

molten grotto
#

I don't think the values you put there are correct though, the sysv abi just tells you the bit values of the individual fields, they are not in that order in the actual control word/mxcsr

surreal path
#

then what is the values that are correct

molten grotto
#

8.1.5 and 10.2.3 tell you the positions

molten grotto
#

I mean yeah you could just steal those, it might be easier KEKW

surreal path
#

stolen

#

wait whats the managarm license

molten grotto
#

MIT

surreal path
#

do i have to put a copyright notice or

kind root
#

it already says stolen from managarm

surreal path
#

yea but like i need to put the actual copyright notice

kind root
#

and its not a direct copy

#

so i dont think u need anything else

surreal path
#

ok

tawdry mirage
#

don't think constants like that are even copyrightable, considering headers aren't (iirc?)

kind root
#

well it was in a cpp file caret

#

inb4 dmca and takedown of nyaux

#

fbi waiting at his door

tawdry mirage
#

shhh stop exposing my plan

surreal path
#

๐Ÿ˜ 

#

wait does this mean i can compile my kernel with fpu

kind root
#

that would be unfortunate

surreal path
#

enabled

kind root
#

no, no it does not

surreal path
#

aw

molten grotto
#

well then you'd also need to save fpu state on syscall entry and restore on exit

surreal path
#

ah hell naw

#

okay im not doing that

#

lol

molten grotto
#

and same for interrupts

surreal path
#

sounds like pain

kind root
#

and context switch

surreal path
#

pain

kind root
#

save user - restore kernel - save kernel - restore user

finite summit
#

also mega slow

kind root
#

4 fpu reloads per switch

surreal path
#

yea sounds mega slow

#

anyways pushed fpu changes to git

#

time to crawl back into that unix playlist

#

til bro talks about file descriptors

#

so i can flipping implment them

#

cause i wanna make SOME progress to bash

#

im gonna make this a challenge

#

every day for the next week i must implement at least 2 syscalls

#

pins this

#

keeping myself accountable with this

kind root
#

what was your end goal

surreal path
#

uhhh

#

idk maybe doom and xorg ported one day to nyaux

#

like astral

kind root
#

both should be easy

tawdry mirage
kind root
#

if you know what you're doing you can speedrun those in 24 hours

surreal path
#

thing is this is my first proper osdev project

surreal path
#

idk

kind root
#

yeah you need to slow run it before you can speed run it

surreal path
#

fr

surreal path
surreal path
#

thanks qwinci

#

anyways i have 2 hours to implment 2 syscalls cause my dad forcing me to sleep early

#

so

#

lets go

kind root
#

you're 17 right?

surreal path
#

ye

kind root
#

interesting

surreal path
#

why u askin lol

kind root
#

last time my parents forced me to sleep I was like 14

surreal path
#

lol

surreal path
#

this entire fuckin unix playlist didnt explain file descriptors

molten grotto
#

they are just plain integers, you just have some sort of way to get a struct out of one of them

#

like a dynamic array or whatever that you can index with it to get the corresponding struct

surreal path
#

no they arent cause what qookie said earlier

#

there are things called file descriptions

#

and

#

stuff

molten grotto
#

yes but it still works the same

#

you map an integer to a struct

#

you could probably just ignore the second layer of indirection for now and just store the access offset + mode + vnode within that struct

surreal path
#

whats the purpose of the second layer of indirection

molten grotto
#

idk tbh

surreal path
#

and what does it mean to "open" a file and to "close" a file in this situation, like the file is right there in memory why do i need to "open" it

#

does that just return a fd

#

or what

tawdry mirage
molten grotto
surreal path
molten grotto
#

yes

surreal path
#

so why do we need to "allocate" an fd

molten grotto
#

I mean allocating them can mean just incrementing a variable you have inside the process

#

but you likely want to reuse closed fds too

#

so you have some sort of vector of freed fds you can look at first before creating a completely new fd by incrementing the integer inside the process or smth

surreal path
#

can threads have separate file descriptor tables

plush hearth
molten grotto
surreal path
#

ok

#
struct FileDescriptor
{
  struct vnode *ptr;
  uint64_t offset;
}
struct ProcessInfo
{
  struct FileDescriptor Descriptors[MAX_FILE_DESCRIPTORS];
  uint8_t descriptor_bitmap[MAX_FILE_DESCRIPTORS];
}
#

somethin like this?

#

or misunderstanding?

molten grotto
#

something like that yeah

surreal path
#

okay

#

how many file descriptors should a

#

process have

#

whats the max

#

value

#

what value should i set that

#

to be

#

is 256 too little?

molten grotto
#

I think linux has 1024 by default

surreal path
#

oko

leaden hinge
#

i made mine like 64

molten grotto
#

or you can just dynamically resize the array

surreal path
#

no

#

that pain

#

no

leaden hinge
#

do you not have some kind of struct for a dynamic set of objects

surreal path
#

wha

leaden hinge
#

like a linked list

#

or vector

surreal path
#

yea

#

i dont wanna dynamically allocate

leaden hinge
#

why not

surreal path
#

the kernel should

#

find the vnode from the path

#

find an avabile fd

#

get the empty entry from within the array

#

set the ptr to the vnode found from the path

#

and whenever the process tries to read with an offset or write

#

update the offset of the fd

#

correct?

molten grotto
#

or when the thread seeks then you set the offset to the value where it wants to seek at

leaden hinge
surreal path
#

mode

#

mode?

leaden hinge
#

read/write

surreal path
#

why do we need modes

molten grotto
#

well for an example you may only have read permission to a file

surreal path
#

so im not gonna worry

#

๐Ÿ˜Ž

#

#ihatesecurity

#

#alwaysassumetheuserisright

#

can directories have file descriptors?

#

?

worldly condor
surreal path
#

ah ok

#

man rlly wants libreadline

unkempt relic
#

the open syscall will probably include code like this
vnode = cwd_vnode->lookup("whatever/path/asked/for");
if (vnode != NULL)
if (vnode->open() didn't return an error)
then do the rest of the work

surreal path
#

wdym bytes read

#

the heck

finite summit
#

the amount of bytes read

surreal path
#

why

finite summit
#

because

#

it's possible that you couldn't read count bytes

#

I think

surreal path
#

huh???

#

why cant it satisfy the dependency?

#

???

tawdry mirage
surreal path
#

okay fixed bug in my vnode lookup

#

lol

#

now we gotta give mr sys_seek

#

what is whence

#

the heck does that mean

#

๐Ÿ˜ญ

finite summit
#

where to seek from

elder shoal
#

man 2 lseek

finite summit
#

specifically

#

whether to seek from the current file pos

#

the end of the file

#

or the beginning

surreal path
#

oh makes sense

#

but why would u want SEEK_END?

#

???

#

lol

tawdry mirage
surreal path
#

oh right

tawdry mirage
#

so you can do things like "-10 bytes from the end"

surreal path
#

makes sense

#

wtf is going on

finite summit
#

something includes cstdio

surreal path
#

generic.cpp

#

yes

#

and

#

im not modifying anything

#

@tawdry mirage do u know whats going on??

tawdry mirage
#

are you sure clangd didn't help you by adding the cstdio include

surreal path
#

idk

#

lemem check

#

ok works now lol

#

me when clangd

#

bru

#

bro what

#

u gotta be kidding me

#

๐Ÿ˜„

#

oh

#

flags are wrong values

#

what ze fuc

#

oh right

#

what is bro trying to do

tawdry mirage
#

map memory for phdrs

surreal path
#

probs do something other then map_annoymous

tawdry mirage
#

it specifies MAP_ANONYMOUS | MAP_FIXED

surreal path
#

right

kind root
#

Bro just switched on a flags field

surreal path
#

so bro is trying to map fixed

surreal path
#

๐Ÿ˜Ž

surreal path
#

oh

kind root
#

Why would bash want a fixed mapping?

surreal path
#

->

#

bash

tawdry mirage
kind root
#

Oh

surreal path
#

hint is address right?

#

for MAX_FIXED

#

MAP*

tawdry mirage
#

yes

surreal path
#

alr

#

brother

tawdry mirage
#

what flags are you enabling in meson.build for your os?

surreal path
#

uhhh

tawdry mirage
#

hm if you copied vinix then none

surreal path
#

yea

tawdry mirage
#

oh it's MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS

surreal path
surreal path
#

uhhh im not gonna worry about this

#

oh come on

kind root
surreal path
#

blud is trying to memcpy

surreal path
kind root
#

Writes to that memory dont change the underlying file

#

Instead it creates a fresh copy

tawdry mirage
surreal path
#

why is it calling memcpy

#

whos calling memcpy

#

fuckin hell

kind root
surreal path
#

someone is clearly trying to memcpy this

kind root
#

So I dont know what thats supposed to do

tawdry mirage
tawdry mirage
kind root
surreal path
tawdry mirage
surreal path
#

๐Ÿ˜ƒ

#

that is legit all i do

kind root
surreal path
#

so clearly someone is giving me invalid memory to whatever

kind root
#

And not cowed?

surreal path
#

nope

#

it is

#

buf

#

for some reason buf is invalid???

#

like sorry

#

what

tawdry mirage