#Nullium

1 messages · Page 3 of 1

wild glen
#

maybe because no assembly is used but still (assembly file routine)

hushed briar
#

Because 32 bit

wild glen
#

so whar

#

anyways still tho

hushed briar
#

Okay let me look

wild glen
#

absolute cancer i have

hushed briar
#

You are doing way too much lol

#

Also there is no reason to do any of this shit in an actual assembly file

wild glen
#

fair

hushed briar
#

The reason mine looks simpler

#

Is because C takes care of half of the shit

wild glen
#

fair

hushed briar
#

I mean others may disagree with it, but all of the assembly stubs you have in that paging file are not necessary

#

Like

#

No need for a paging.asm

#

At all

wild glen
#

fair enough

hushed briar
#

Well then fuck em lol

#

Just no need for that file at all

#

It’s basically just trivial mov statements

#

For parameters and shit

wild glen
#

fair

hushed briar
#

You just need to access cr3 and c0 within C

#

Which is trivial

wild glen
#

asm volatile (why did it underline)

hushed briar
#

Yes

#

With inline assembly

#

Discord formatting

wild glen
#

TIL i learned underlines exist on discord lmao

hushed briar
#

It’s like when you do bold

wild glen
hushed briar
#

Yeah that’s why many people type code within these blocks

wild glen
#

true

hushed briar
#

Truth nuke

wild glen
#
its like markdown language

literally?
hushed briar
#

It is markdown

#

Like it quite literally is lol

wild glen
#

same syntax

#

ok anyways so uh paging

hushed briar
#

Okay imma hit my weed pen first

#

Sorry

#

Long day

wild glen
#

mk

hushed briar
#

Tell me your dilemma ill brb

wild glen
#

aight

#

uh

#

shit triple faults

#

idk thats the dillema

#

how do you set it up as well

hushed briar
#

Triple faults when

wild glen
hushed briar
#

What instruction/line of code

wild glen
#

unsure

hushed briar
#

Okay run qemu with these args

raven mountainBOT
#
qemu

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

hushed briar
#

Then when you crash, you should see the EIP value

wild glen
#

no reboot no shutdown reminds me of "YOU WILL NOT LAUGH, YOU WILL NOT CRY!"

anyways aight

wild glen
hushed briar
#

We’ll get to that

#

Just get the EIP value first

wild glen
#

k

#

EIP=00202bbe

#

then it ded

#

paging is initialized before gdt btw

hushed briar
#

Okay well from there

#

You’re going to use a cute program named addr2line

#

It’s extremely helpful

#

addr2line -e yourkernelexe 0x[EIP]

#

Yourkernelexe is just whatever your kernel executable is called

wild glen
#

i wanna know where the fuck it pulls out the specific file and line from but mk

hushed briar
wild glen
#

what the actual fuck

hushed briar
#

Well there you go then

#

Your GDT is fucked

wild glen
#

lemme make sure its not paging

#

infinite for loop trl

wild glen
#

my gdt is fucked

#

ITS ALWAYS THE GDT

#

bong

hushed briar
#

There you go

#

You debugged for the first time lol

#

That’s very basic but

wild glen
#

this is helpful but now i want to jump out the window

hushed briar
#

A good way to do it

wild glen
#

the gdt is always evil

hushed briar
#

But that’s rudimentary debugging lol

#

I do that shit all the time

#

It’s a cheat for life fr

lethal summit
#

wait till bro gets race conditions trl

hushed briar
#

Oh yeah

#

They don’t work for that

lethal summit
#

"commit 897cb6: Introduce BKL to avoid race condition"

wild glen
#

wait

#

it crashes if i draw after paging is initialized

#

as well

hushed briar
#

What?

#

Sorry I just

#

Wdym

wild glen
#

if i do anything other than a for loop it just goes to shit

hushed briar
#

For loop for what

wild glen
hushed briar
#

Okay well then init paging doesn’t work

#

You did something wrong

wild glen
#

the paging is always evil

hushed briar
#

Why are you doing the extern in the function

#

Thats interesting

#

I do worse things in my os tho lol

wild glen
hushed briar
#

Fair

wild glen
#

moved it to header

hushed briar
#

Nice

#

But anyways

#

I could look through your paging code but

#

I think you would stand to learn some good things if you studied some more implementations

wild glen
#

true maybe

hushed briar
#

I think I know what’s wrong with it but

lethal summit
#

show code i'll give it a shot

wild glen
#

scroll up

lethal summit
#

is it pushed yet

#

o hok

wild glen
#

here

hushed briar
#

^^^

wild glen
lethal summit
#

this?

#

oh yes

wild glen
#

behold

#

cancer

lethal summit
#

why are you marking the pages not present

#

also is this 32 bit

hushed briar
#

It is yeah

wild glen
#

yes

hushed briar
#

So it’s a bit diff

lethal summit
#

ok so try marking the pages present

hushed briar
#

But still

lethal summit
#

unpresent page causes fault

hushed briar
#

No they absolutely must be marked present

#

For sure

lethal summit
#

so yes when you make the mappings mark the pages present

#

otherwise fault

wild glen
#

replace this with 3 i think?

#

011

hushed briar
#

Or just use constants

lethal summit
#

idk im not an ia32 kid

wild glen
#

still death

#

i might just want to rewrite this code

hushed briar
#

Yeah

#

There’s many many things wrong

wild glen
#

true

hushed briar
#

Where are your page table and directory structs

#

Where is your page flags struct

wild glen
#

uhhh

#

vaporized

hushed briar
#

Just create a page attributes struct

#

You can just yoink mine

wild glen
#

aight lemme find the intel manual im going insane

wild glen
hushed briar
#

typedef struct {
    uint32_t present    : 1;
    uint32_t rw         : 1;
    uint32_t user       : 1;
    uint32_t write_thru : 1;
    uint32_t cache_dis  : 1;
    uint32_t accessed   : 1;
    uint32_t dirty      : 1;
    uint32_t pat        : 1;
    uint32_t global     : 1;
    uint32_t available  : 3;
    uint32_t frame_addr : 20;
} page_attrs_t;
lethal summit
#

why does everyone always crashout when paging vro 🥀

lethal summit
#

bitfield layout is implementation defined

lethal summit
#

this could be fine with GCC and die on some other compiler

hushed briar
lethal summit
#

okay sure that is fine

wild glen
#

literally all code might die with some other compiler

#

if you dont compile with gcc support isnt provided
if you compile with gcc no support either

#

(average user expects a working hobby os, he does not know that is impossible)

#

anyways

hushed briar
#

My shit is not working or functional

#

Jk jk

#

But definitely not very great

wild glen
#

fair

hushed briar
#

But yeah don’t mark pages the way you were before

#

Just

#

I would rewrite tbh

#

Not saying what you did was shit

wild glen
wild glen
hushed briar
#

It’s okay, I rewrote my paging implementation a few times

wild glen
#

fair

hushed briar
#

So I won’t be able to answer

#

But when I come back I’ll look at what you’ve done

wild glen
#

mk i have to sleep now too probably

hushed briar
#

Remember, study

#

Ah

#

Well good luck tomorrow

#

With your paging

wild glen
#

aight thx

#

im gonna go actually read a bunch of implementations for it

hushed briar
#

Yup

#

Look up

#

Mentos

#

MentOS

#

Extremely extremely solid 32 bit operating system

#

And very good to learn from

#

It’s almost perfect in my opinion

#

In terms of a hobbyist ia32 operating system, it is as perfect as it gets

wild glen
#

found it

lethal summit
#

or learn from real kernels... 💔

hushed briar
#

I actually disagree

hushed briar
#

If you want to make a hobby kernel you need both to study real kernels and hobby kernels

wild glen
#

(registered trademark)

wild glen
#

maybe the real kernels are the friends we made along the way

lethal summit
#

real kernels are the ones that groups of people actually maintain long term and thus their code tends to be designed with some degree of maintainability in mind meanwhile we have hobby kernels like nyaux

lethal summit
#

and also real kernels, well, do things properly for the most part

hushed briar
#

I’m talking decent hobby kernels

wild glen
#

unix-style war crimes

hushed briar
#

MentOS, managarm, astral, menix, mintia

lethal summit
hushed briar
#

Yeah but that’s why you keep a variety

#

Not just hobby or real kernels, study both

#

I’ve learned so much from MentOS

lethal summit
#

why do you gain anything from looking at the hobby implementation

#

why not just look at the real kernel

wild glen
hushed briar
#

So you can see a vmm implementation without scrolling through 5 10000 line files

#

Like

#

Linux source tree is complicated

#

And sometimes it’s nice to see a smaller implementation

lethal summit
#

sooooooo 💥

hushed briar
#

Idk I just like studying a good mix

#

I mainly study BSD

#

70% of my source code studying is BSD

lethal summit
lethal summit
hushed briar
#

I do read Linux daily just not as much as before

#

I just fucking hate the drivers in Linux

gloomy musk
#

Linux source looks scary lol

wild glen
#

true

lethal summit
hushed briar
#

I like reading it but it’s a bit overwhelming at times

lethal summit
#

I find that it tends to be okayish if you view it in an editor and sit down and read it well and good

#

not on github lol

gloomy musk
#

I've seen a few snippets here and there

lethal summit
#

no actual code reading? 💔😔😔

hushed briar
#

I like viewing it in notepad ++ and other simpler editors

#

And sublime

lethal summit
#

are there any hobby kernels with numa aware allocators and other components because that's what I'll be doing soon

gloomy musk
#

I was trying to read the page struct impl but I forgor

lethal summit
#

heartbreaking...

hushed briar
#

If you pull that off that’s insane

lethal summit
hushed briar
#

Nah like not even NT had that for a long time

lethal summit
#

Hobbyist And Recreational

lethal summit
#

but it's 2025 and it's everywhere

gloomy musk
#

Welp, I guess I'm doing NUMA now, cause all the cool kids are doing it KEKW on a serious note what are the actual benefits of NUMA

lethal summit
#

even on some """"consumer hardware"""

lethal summit
#

only numa systems benefit

#

but those tend to be servers or 64 core desktop processors

hushed briar
#

I don’t have any fun doing OSdev

#

Jk jk

gloomy musk
#

ah, okie, might be lower on the priority list then

hushed briar
#

It’s fucking awesome

lethal summit
lethal summit
#

I'm doing it for fun

#

I don't think anyone else is doing it but imo they're just lame and missing out on fun

#

an aura loss as one may say

hushed briar
#

It’s definitely aura farming to implement numa

gloomy musk
#

yeah, again probably pretty low on the priority list atm, since mine is supposed to be a desktop OS lol

lethal summit
#

wow what a helpful note

gloomy musk
#

supah helpful

wild glen
#

truly

#

numa

do it

lethal summit
#

bookmark ts fr

#

source tree low kinda funny im ngl

gloomy musk
#

Ooooh, and non-UNIX :3

lethal summit
hushed briar
# wild glen numa do it

I’m not even fucking kidding when I say this… I went to pick up my friend and outside his place there was a fucking gunshot

lethal summit
#

unc is in the hood

hushed briar
fluid moon
#

I have a even more tree-structured drivers directory
io
-> io.h
-> serial
gfx
-> fb
-> vt
net
-> intel
-> e1000

#

I'll add timers

wild glen
#

and internet adapters

lean relic
#

maybe instead of intel/e1000 i would e1000.c

#

or whatever language

wild glen
#

anyways except MentOS (int nuke_pagemap suggested it) are there any other good/ok paging implementations

#

i will combine them into an unholy abomination (joke)

#

break several open source licenses and cause the end of the universe as a whole (joke 2)

wild glen
#

im somehow still surprised big projects are open source (freebsd, linux) im used to these just being gatekept to hell or not shared (windows)

lean relic
#

yeah linux source code is a god send

wild glen
#

why do strawberry and watermelon starbursts have basically the same color

#

i thought it was a misprint

#

(this should go to lounge 0)

wild glen
#

is the standard for paging 4 KiB or 4 KB

#

if it's KiB someone is gonna be dying tonight

#

(kib = 1024 bytes, kb = 1000 bytes, i think)

#

i fucking hate humanity why cant we choose between 1000 or 1024 bytes

#

0x1000 bytes or 4000 bytes

#

iUEJKFQWHDKJQWDMKJQW

#

ok yeah time to actually look for myself

#

who made this bullshit

#

why cant it be 1000

fluid moon
#

power of 2 is always better

fluid moon
#

0x1000 bytes

wild glen
#

Both tables contain 1024 4-byte entries, making them 4 KiB each.

nooo nooo nooo nooo nooo nooo nooo nooo nooo nooo nooo nooo nooo nooo nooo nooo

wild glen
#

-# (WHY DOES IT HAVE TO BE LIKE THIS)

fluid moon
#

computers work on base 2

wild glen
#

true but its still evil

fluid moon
#

nah, you get used to it

wild glen
#

tbh i alr have 0x1000 in the page thing

#

anyways to convert a page index number to a memory address do i just multiply it by 0x1000?

#

not sure

#

i mean idk my itoa function outputs a little bit goofily

#

works but goofy

wild glen
# fluid moon ?

page is 4 kib (0x1000 bytes)

to make it from just a page number to an addr do i multiply number by 0x1000?

fluid moon
wild glen
#

ik

fluid moon
#

generically it's just address + (PAGE_SIZE * page_num)

wild glen
#

im mentally fucked i dont have an offset but this seems right enough

fluid moon
#

paging is based on your PMM

wild glen
#

true

fluid moon
#

it translates physical addresses into virtual ones

#

you got to have a base address

wild glen
#

wait i do have an offset

#

im more stupid than i thought

#

anyways

wild glen
#

reworked pmm so it will do kibibytes instead of "you have like 4 gb or something idk lmao enjoy trl"

wild glen
#

how necessary is paging and all that

THE thing that i want from it is program isolation
idk if i will actually use virtual memory and all that stuff

#

its probably quite necessary but i do not exactly want virtual memory because im quite ok with my current memory layout

lethal summit
lethal summit
#

it's """possible"""

lethal summit
wild glen
#

like what

lethal summit
#

security is the least of your worries when you can't implement half the syscalls from posix

#

and also portability just dies

#

if you had an executable that only works with more than X amount of memory, and you have less than that, well ur outta luck

wild glen
lethal summit
lethal summit
wild glen
lethal summit
#

I mean you can have a non posix OS but you'd have a lot of system calls similar to what posix has

wild glen
#

stdio?

lethal summit
#

like winapi has tons of stuff that has "mirrors" in posix

lethal summit
wild glen
#

windowing system is either hell or peace

lethal summit
#

and then compared it to other apis

wild glen
#

oh

#

i found a chart

#

its like 4p

#

i see

#

system calls

gloomy musk
#

I literally used to write my syscall table is "blahblahblah | (my version of foo() in posix)" lol

lethal summit
wild glen
#

this is information of all time

#

quite useful indeed

lethal summit
#

how did vro not know about ts 💔

wild glen
#

anyways

lethal summit
#

multithreaded preempting ti-84 operating system

wild glen
#

no i deadass learned c from a calculator and shitty directx tutorials

lethal summit
#

maximal throughput high performance low latency scalable ti-84 operating system kernel

wild glen
#

anyways back to the point

#

this is information of all time

#

i mean they had to exist tho

#

otherwise like

#

pain

#

i am not adding all of these tho that would just be suffering (vm86 😭)

lethal summit
#

isn't this classic macOS thing

#

pretty sure they didn't do that either

#

bro copying them

wild glen
wild glen
#

like no

lethal summit
wild glen
#

absolute total no

lethal summit
#

💥

wild glen
#

its literally just mac os except "what if it ran on an x86 machine and wasnt shit in certain aspects and was even worse in others"

lethal summit
#

💥

#

goodluck

wild glen
#

truly

#

this server when someone doesnt know something:

#

(allegedly)

wild glen
#

theres a shit ton of windows clones already

wild glen
#

wait do you need to set up virtual memory stuff for system commands

lethal summit
#

forget paging, you don't even need 32 bit to do this

wild glen
#

fair

wild glen
#

i made software interrupt now

#

INT 0x10

#

anyways uh

#

le paging

#

nvm

#

interrupt broak

#

ok i got software interrupts yooooooooo

#

vector 0x45

#

go convert that to decimal i fucking dare you trl

wild glen
#

do i add multiple interrupts that you can call or do i just add one really big one with all the commands and a shit ton of settings

#

or add like 5 really big ass interrupts and you have to call each to pass the arguments trl

fluid moon
fluid moon
wild glen
#

one big interrupt?

fluid moon
wild glen
#

aight

#

0x45 is a nice number too (even more in decimal) its gonna ruin the thing if theres 0x46 or smth

wild glen
#

isr 0-31 are reserved

fluid moon
wild glen
fluid moon
#

wtf did I write

wild glen
#

wait what did that just say

fluid moon
fluid moon
#

allocate…

#

the irqs incident

wild glen
#

isr's

#

it's isr's

#

i have either 256 of them or 128

#

irq's are hardware

fluid moon
#

from int 0x78 is safe

wild glen
#

dos uses 0x21 but its real mode so idk

wild glen
#

lemme check to make sure

fluid moon
wild glen
#

no not gippity

#

im going on the wiki

#

and fishing for old ass intel manuals

fluid moon
#

wiki says up to 77h

wild glen
#

up to 77h are reserved?

fluid moon
#

nvm I was spreading misinformation

#

48-255 are for software interrupts

wild glen
#

Dam

#

FUCK I CANT DO ISR 69

fluid moon
#

actually once got over interrupt 31 you are free to handle them how you want to

wild glen
#

oh

#

thats what i thought

#

i was right 🎉

fluid moon
wild glen
#

0x45 != 45

#

im not interfering with any irq's

#

isr 69 my beloved

fluid moon
wild glen
fluid moon
wild glen
#

ion wanna do that i just have them reserved right here and now so i wont do something stupid with the idt later

#

and/or me lazy

fluid moon
wild glen
#

well thats for pci

#

when i get there im gonna add a list

wild glen
#

stolen image (yay)

#

anyway

#

one big ass interrupt

#

(causes collapse of universe)

#

im glad i joined this server

#

otherwise i would have so many damn misunderstandings of literally everything in osdev

fluid moon
wild glen
#

i heard of sysenter

#

do i just keep both sysenter and 0x45?

fluid moon
wild glen
#

i think that sounds like a good practice because there's def gonna be old grandpas using interrupts and normal people using the more modern stuff

#

linux i think still has the interrupt

fluid moon
wild glen
#

it understands :0

#

i already have a crappy markdown file that ill put all the functions into

#

now commented

wild glen
#

im gonna actually add paging when it doesnt drive me mentally insane

#

im kinda interested by the interrupts

#

i mean i have to add it eventually its just

#

ultimate procrastination

#

actually wait no

#

lemme just fucking add it i swear to god

#

also funny table

wild glen
#

i think i have a slight idea of the concept of paging now

#

useful shit

rocky elbow
#

cool

sour pollen
wild glen
#

yes sadly

#

adding it when i get home

lean relic
#

is there even userspace

#

or are they ring 0 syscalls

wild glen
#

its more of a test

#

theres a single syscall

#

it doesnt do anything

#

literally 3 minutes worth of work

#

im gonna add paging when i get home

#

programs are gonna be pain theyre gonna think that everything starts at 0x000000

#

higher half programs at 0xC0000000 maybe? trl

#

elf is evil

wild glen
#

am i legally obliged to use elf

cant work on paging yet not home rn

#

ok nvm its a good format

#

all i really want is a portable asf format

#

too lazy to specify what exactly i want

lethal summit
wild glen
wild glen
#

ok i triple checked that the physical allocator works

#

if paging shits itself i will not trust myself

#

(i already dont)

#

4096 byte pages

#

i think

#

anyways so i need a page directory and the page entry thing

#

wait

#

wtf is the explanation on the wiki

#

im confused

#

oh

#

nevermind i got it

#

its a bit weird

#

i thought the page directory had an address of the page table and the page table had access rights

#

i mean it has them both but its a bit funny

wild glen
#

it works

#

officially

#

the last two columns show memory addresses now

#

i think that is a good enough pmm

#

currently

#

also it divides

#

i think it works

#

probably

#

does it

#

the page start is multiplied by 0x1000

#

page size is 0x1000 bytes

#

im gonna say it works it has no problems at all

#

at a glance

lethal summit
#

did you finish the buddy allocator

#

awesome sauce

#

🛸

wild glen
#

also its a freelist allocator apparently

lethal summit
#

wgat

wild glen
#

i have to store stuff in kb now because some numbers get too big

#

the 32 bit hex

lethal summit
#

👍

wild glen
# wild glen

i hope the user wont have to just do "here's the number of your page bruh put it in a uint64_t and convert it to a memory addr no further explanation provided trl"

#

ok so this is supposed page memory addresses in kibibytes

#

if you want bytes multiply that by 1024

#

then do whatever you want

#

(users writing drivers TOTALLY wont have a major pain in the ass)

#

for driver making theres gonna be a better way

#

outputs bytes

fluid moon
#

the only thread I follow has new messages!!

#

how is development going

wild glen
wild glen
#

trying to do paging

fluid moon
wild glen
#

true

#

i unfucked my pmm

#

it does 4 KiB pages

#

should help a lot with that

#

(triple fault go brrr trl)

fluid moon
#

I wish I had your patience when I started osdev, I used to do everything swiftly and without reading specifications

#

well done so far letsgo

wild glen
#

after dropping whatever tf that was thats when i actually didnt rob anyone's code

#

(that happened when the nullium thread started thats when i dropped that somewhat crappy piece of shit os)

#

anyways yay

wild glen
#

pmm never works right

#

wait

#

nvm it works right

#

i thought pages could intersect

#

no lmao trl

#

nvm they can

#

or can they

#

iOFKJASDJASKDHKJASDIOJWQDN

#

my brain too small

lethal summit
wild glen
#

intersection

#

this doesnt happen apparently and i am happy

lethal summit
wild glen
#

intersection

lethal summit
#

what does "space" mean

wild glen
#

memory

lethal summit
#

4kb pages must be 4kb large and 4kb aligned

wild glen
#

yes

lethal summit
#

how do they intersect

wild glen
#

idk

#

i thought they did in practice because uh

#

fard

lethal summit
#

page 2 starts right after page 1 ends

#

no intersection

wild glen
#

yes

lethal summit
#

yes

wild glen
#

it triple fault

#

:'(

#
>addr2line -e nullium.bin -f 0x0020490a
init_Paging
??:?
#

what died

#

i wanna know

#

lemme disasm it for shits and giggles

#

i cant find the address???

#

i wanted to disassemble and see where exactly it dies

#

behold

#

i am using gdb

#

me smort now

#

(my brain is a smore)

lethal summit
#

how it feels to bt

wild glen
#

i added -g into the make file and now the world is at peace

#

or whatever the debug option was

#

include debug symbols

#

i know exactly where it shits itself now

#
load_pd(pageDir);

enable_paging();

for(;;);

it dies right at the for loop

#

damn

#

i removed it and now it just dies at the function closing thing

#

it can load the page directory fine

#

ok it dies on the enabling paging instruction

#

it says it dies at line 59

#

made that last __asm__ a volatile

#

didnt help

#

lemme rework that piece of shit

#

i made it wonky as shit now

#

anyways so it crashes at the line after moving cr0 to eax

#

crash at:

mov %ebp, %esp
#

i did something really funny with the page tables probably

#

this is the init paging function

#

wait

#

ld_start might be the problem

#

modified to pageDir[0].table_addr = ((uint32_t)&pageTable + (uint32_t)&ld_start);

#

still death

#

removing it entirely

#

idk what was i thinking i doubt its even necessary

#

nope

#

dies

#

i used this struct

#

dont want to ping anyone

wild glen
#

declarations

#

these are both 1024

#

im gonna de goofy that enable paging function

lethal summit
lethal summit
#

it would just not have a mapping

wild glen
#

true

#

can i map it to a physical address

#

and also how

lethal summit
wild glen
#

found this on wiki

lethal summit
# wild glen and also how

you just make a PML4 (or whatever you do for ia32) and then set up all the entries in it and then load it

#
void vmm_init(struct limine_memmap_response *memmap,
              struct limine_executable_address_response *xa) {
    kernel_pml4 = alloc_pt();
    if (!kernel_pml4)
        k_panic("Could not allocate space for kernel PML4\n");

    kernel_pml4_phys = (uintptr_t) kernel_pml4 - global.hhdm_offset;
    memset(kernel_pml4, 0, PAGE_SIZE);

    uint64_t kernel_phys_start = xa->physical_base;
    uint64_t kernel_virt_start = xa->virtual_base;
    uint64_t kernel_virt_end = (uint64_t) &__kernel_virt_end;
    uint64_t kernel_size = kernel_virt_end - kernel_virt_start;

    for (uint64_t i = 0; i < kernel_size; i += PAGE_SIZE) {
        vmm_map_page(kernel_virt_start + i, kernel_phys_start + i,
                     PAGING_WRITE | PAGING_PRESENT);
    }``` something like that
#

but with whatever you're using

wild glen
#

fair

lethal summit
#

my kernel image is only 400kb so I only map it with 4kb pages and I don't expect it to grow to the extent that I need 2mb hugepages

wild glen
#

also rq question in the pmm page start addresses have to divide by 4096?

wild glen
#

like page 1 is 0 and page 2 is 0x1000, 3 is 0x2000, etc

lethal summit
#

what does this mean though

wild glen
#

fuck idk how to explain

#

so (pmm) page 1 starts at 0

#

page 2 is at 0x1000

lethal summit
#

ok sure

#

so what about it

wild glen
#

is that how its supposed to be

lethal summit
#

it's supposed to be however you designed it to be

wild glen
#

fair enough 😭

#

anyways

wild glen
lethal summit
#

if you want it to actually work after you enable paging, ya that would be the approach

wild glen
#

mk

#

my kernel starts at 2 mb tho how do i do an offset

lethal summit
lethal summit
wild glen
lethal summit
#

wdym how do you do an offset

wild glen
#

wait

#

nvm

#

my kernel in its entirety is like 2.5 mb or smth (with the stack and all that other crap)

#

shouldnt be a problem actually because one table covers 4 mb

#

i think

lethal summit
#

that's a pretty big kernel

wild glen
#

i mean

#

it starts at 2 mb

#

2mb is just wasted for shits and giggles

lethal summit
lethal summit
wild glen
#

fair

#

i can try moving it to like 1mb maybe

lethal summit
#

it's not a big deal you'll be fine

wild glen
#

ok whatever

#

im gonna try mapping it then ping you if it works or not is that ok

lethal summit
#

sure thing

fluid moon
fluid moon
fluid moon
wild glen
#

yall old macbooks are evil

#

yes they can run windows and yes they are pc compatible

#

however

#

no ps/2 emulation at all

#

you HAVE to add a usb keyboard driver

#

which sounds like fucking bullshit

#

also i feel like integrating 7zip or some other zip archiver into my system for shits and giggles once i finish literally everything

lethal summit
#

just write an xhci driver

#

my 2015 macbook air uses xhci

#

so fancy

#

then once you write the controller driver you just make a generic usb abstraction layer and write your usb driver

wild glen
wild glen
#

im talking as early as 2006 tho

lethal summit
#

i would still say that that's a great thing

#

centralizing stuff with USB is great

wild glen
#

true

#

im just lazy

lethal summit
#

and USB keyboards are indeed better than PS2 (that's why they exist)

lethal summit
#

consider it if u want

wild glen
#

so it has some advantages

#

one downside is that you cant press all the keys at one time

#

i dont really care about that though

#

who tf just pounds their keyboard like a monkey

wild glen
lethal summit
#

I suppose PS2 being interrupt driven makes it better

wild glen
lethal summit
#

but also

PS2 downsides:

no backlight
no rgbtq lighting

very important

wild glen
#

they arent noticeable at all

wild glen
lethal summit
#

exatlclylsly....

wild glen
#

what i said basically

#

you can just make a program

#

fuck

#

stroke

wild glen
#

what happens to a brain when you try to update windows vista :(

wild glen
#

im not gonna be available for most of the day tomorrow

#

pain

#

anyways uh

#

paging time

#

i have 4095 byte pages

#

i hate my pmm

#

😭

gloomy musk
#

what happened to the last byte KEKW

wild glen
#

im not even sure if its 4095 or not

#

these are addresses of two pages near each other

#

so is it 4096 bytes of is it not

#

does it start at 0 and go to 4095 like arrays do

#

this is the most confusing problem in the history of mankind to me

#

iorijerwklfwekjlfewkjlewkjlfjlwlfjldsjsklfakjl

#

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

#

anyways

gloomy musk
wild glen
#

i hate my pmm less

#

(it always breaks somehow)

#

also random piece of code:
(void*)((uint64_t)palloc(1, true) * 1024) converts a page address in kib to bytes please someone check this if i start ranting about how paging triple faults in like a few minutes (i have doubts if this is right or not)

#

👍

#

palloc function prototype: palloc(uint32_t pages, bool returnMemoryAddr)

#

anyway

lethal summit
wild glen
#

because im mildly stupid

lethal summit
#

💥

#

you can turn a memory address into a page number and vice versa

#

#define ADDR_TO_PAGE(addr) ((uintptr_t)(addr) / PAGE_SIZE)

#

very astounding

wild glen
#

im gonna add that later trl

#

(palloc is the same thing except its fucking stupider)

#

(system use only :trl)

#

(emoji fail)

lethal summit
wild glen
#

kib

#

wait

#

FUCK IT DIVIDES

#

now multiplies :0

lethal summit
wild glen
#

internal system functions can be as spaghetti as i want them to be

gloomy musk
#

Your palloc sounds weird lol

lethal summit
#

you will not have a blast

wild glen
#

ok before it gets worse im just gonna make it return bytes i think this is pain

#

ok its un spaghettied

#

now returns bytes

#

im keeping the kib to byte macro though

fluid moon
#

how is paging going?

fluid moon
wild glen
#

redoing it now

#

im trying to redo it until im gonna fully understand it for some ungodly reason

#

i need a kernel mapping code afterwards too

fluid moon
wild glen
#

it doesnt work for me

#

saddening

wild glen
#
pagetable0[i] = (i * 0x1000) | 192; //11000000: present, read-write

any way to make this not look like some random ass magic number

#

can i just #define something then or (|) it with the pagetable item

gloomy musk
#

Pretty sure that's what most people do ye

sour pollen
#

you can define stuff like PTE_PRESENT | PTE_WRITE

wild glen
#

yes

#

what do i put in these

#

lemme try googling it actually

sour pollen
#

Look up the sdm pages

wild glen
#

wait no idk how to word it (for google search (big stupid))

sour pollen
#

read the intel sdm for the page table structure if thats what you need

wild glen
#

i know the page table structure

sour pollen
#

then what do you need then

wild glen
#

(shitty wording) how do i | several values to get 192 or whatever other combination i want

#

so i wont have to go into a binary to decimal converter

#

bit shifting maybe??

sour pollen
sour pollen
#

also iirc present bit is 0, write is lower too? Why 192

wild glen
#

11000000

#

first numbers

#

if its supposed to be backwards i can flip it

sour pollen
#

you read it right to left basically. Look at the bits on top of the table

wild glen
#

yes

#

i know thats what i did

#

i read it from right to left

#

little endian

#

start from 0 end at 31

sour pollen
#

you‘re representing it wrong though. you set bit 0 and 1, not the high bits

wild glen
#

so its reversed?

#

00000011 instead of 11000000?

sour pollen
#

its lowest bits right, highest bits left

#

yes

wild glen
#

ok cool

#

its 3 then

sour pollen
#

right

wild glen
#

right

wild glen
lethal summit
# wild glen ```c pagetable0[i] = (i * 0x1000) | 192; //11000000: present, read-write ``` any...
#define PAGING_PRESENT (0x1UL)
#define PAGING_WRITE (0x2UL)
#define PAGING_USER_ALLOWED (0x4UL)
#define PAGING_ALL 0xFFFUL
#define PAGING_XD (1UL << 63) // E(x)ecute (D)isable
#define PAGING_PHYS_MASK (0x00FFFFFFF000UL)
#define PAGING_PAGE_SIZE (1UL << 7)
#define PAGING_UNCACHABLE (1UL << 4)
#define PAGING_NO_FLAGS (0)
#define PAGING_WRITETHROUGH (1UL << 3)
#define PAGING_2MB_page (1ULL << 7)``` kaboom
#

ignore ALL

lethal summit
#

dont use that like ever lol

wild glen
lethal summit
#

XD

wild glen
#

this might also work

lethal summit
#

table

wild glen
#

it sets flags on to the physical table my computer is on

#

tested it

#

it works

#

time to do the same for the page directory

lethal summit
wild glen
lethal summit
#

whar

wild glen
#

f

#

anyways uhhhhhh im gonna add these once i unfuck the initial paging setup code thing

lethal summit
#

how did you get here thinking that you can just turn on paging like a switch and do nothing special before it 💀

#

💥

wild glen
#

well this is done here in the setup thing

for (uint32_t i = 0; i < PAGE_TABLE_SIZE; i++){
   pagetable0[i] = (i * 0x1000) | PAGETABLE_PRESENT | PAGETABLE_RW;
}
lethal summit
#

vro that doesnt do anything tho

wild glen
lethal summit
#

that's not how that works 💔

wild glen
lethal summit
#
void vmm_map_page(uintptr_t virt, uintptr_t phys, uint64_t flags) {
    if (virt == 0)
        k_panic(":boom:\n");
    
    struct page_table *current_table = kernel_pml4;

    for (uint64_t i = 0; i < 3; i++) {
        uint64_t level = virt >> (39 - (i * 9)) & 0x1FF;
        pte_t *entry = &current_table->entries[level];
        if (!ENTRY_PRESENT(*entry))
            pte_init(entry, 0);

        current_table = (struct page_table *) phys_to_virt(*entry & PAGING_PHYS_MASK);
    }

    uint64_t L1 = (virt >> 12) & 0x1FF;
    pte_t *entry = &current_table->entries[L1];
    *entry = (phys & PAGING_PHYS_MASK) | flags | PAGING_PRESENT;
}```
#

kablooey

wild glen
#

cool

#

thanks(?)

lethal summit
#

this doesn't work for 32 bit don't copy the code

wild glen
#

yes ik

lethal summit
#

but you will need something like this to map the kernel code so you don't jump to a nowhere address

#

💔

#

🥀

wild glen
#

it triple faults

#

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

wild glen
#

wait

#

i forgor to do vmm

#

these 4 messages didnt happen

wild glen
#

quite informative

#

is that the bite of 768

the resource i sent above says that the directory index (for 0xC0000000) is 768

#

idk im trying to write a thing that flags physical memory addresses to virtual

#

im just dumping whatever im doing here

#

peak progress report amirite

#

though for 1 mb i get "1"

#

0x00100000

#

makes sense i suppose

#

wait im doing it wrong

#

fuck it im assigning 0 to 0

#

patrick water jug.png

wild glen
#

i have made some progress

#

instead of triple faulting as soon as paging is started

#

it triple faults when something happens after it

#

(how bad is everything that i am celebrating a crash right after the first one)

#

i may want a second table

#

oh

#

what the fuck

#

why is it 27 mb

wild glen
#

KJWEFM<WNEFKWJEFHJKWEF

#

DEADASS
WHAT

#

????????????????????????????????????????????????????

#

i was going to say a few bad words that are too bad for this server

#

what in the fuck

#

NO SHIT IT CRASHED WHO MADE THIS

#

(me)

gloomy musk
wild glen
#

the entire kernel is 27 fucking mb (IDK WHY I JUST CRASHED OUT OVER THAT)

#

and i only took 1 table

#

1 page table

#

thats not enough for this oversized fart 😭

#

i also allocated the 1mb before the actual kernel

#

that may or may not count

gloomy musk
#

27 MB seems like waaaaaay too big lol

wild glen
#

true

#

it starts at 1 mb but i also allocated everything before that 1 mb

#

maybe i dont have to allocate that

#

its probably not ever even used

#

i can just pretend it doesnt exist

#

should decrease size a lot

gloomy musk
#

also note you can use info tlb and info mem to see your mappings

gloomy musk
#

qemu monitor

wild glen
#

oh ok

#

thank

#

lmao its still 27 mb

#

no wait

#

its 26

#

de farte

#

whoever made this operating system needs to die immediately