Absurdponcho / PonchoOS

The Unlicense
158 stars 48 forks source link

New Page Map broken #27

Closed Andrej123456789 closed 2 years ago

Andrej123456789 commented 2 years ago

I finish 8th episode (https://www.youtube.com/watch?v=e47SApmmx44&list=PLxN4E629pPnJxCQCLy7E0SQY_zuumOVyZ&index=8) and Page Map don't work for me: image

Code: image

Please fix this problem in near future

Moldytzu commented 2 years ago

What doesn't work with the page map?

Moldytzu commented 2 years ago

Be more precise

Moldytzu commented 2 years ago

Does your OS crash or does it do something special?

Andrej123456789 commented 2 years ago

Nothing crash

Andrej123456789 commented 2 years ago

I clone PonchoOS and works

Andrej123456789 commented 2 years ago

Priting text don't work

Moldytzu commented 2 years ago

so it crashes

Moldytzu commented 2 years ago

image

Moldytzu commented 2 years ago

this is a hint

Andrej123456789 commented 2 years ago

I have this

Moldytzu commented 2 years ago

I already told you where you should look in your code

Moldytzu commented 2 years ago

https://media3.giphy.com/media/0owap7cyOBVZO45ZNO/giphy.gif?cid=ecf05e47slxs8asumllxge8nt702pscxel9un1avy9g1k0vk&rid=giphy.gif&ct=g

Andrej123456789 commented 2 years ago

I copying Poncho code

Moldytzu commented 2 years ago

no

Moldytzu commented 2 years ago

let me tell you what's the problem

Andrej123456789 commented 2 years ago

I will keep my modifications

Moldytzu commented 2 years ago

you're causing a page fault

Moldytzu commented 2 years ago

do you know what is a page fault?

Andrej123456789 commented 2 years ago

Problem is I cannot print text using new PageMap

Moldytzu commented 2 years ago

let me explain to you what's happening ok?

Moldytzu commented 2 years ago

you're causing a page fault that's crashing everything

Moldytzu commented 2 years ago

do you know what's a page fault?

Andrej123456789 commented 2 years ago

I watch Poncho episode, create new PageMap like Poncho. Poncho print's text using new PageMa, I cannot print text

Moldytzu commented 2 years ago

I asked you something. If you don't listen to me, I won't help you

Moldytzu commented 2 years ago

do you know what's a page fault?

Moldytzu commented 2 years ago

if not: https://wiki.osdev.org/Exceptions

Andrej123456789 commented 2 years ago

I don't know where is fault

Moldytzu commented 2 years ago

image

Moldytzu commented 2 years ago

here

Moldytzu commented 2 years ago

A Page Fault occurs when:

A page directory or table entry is not present in physical memory.
Attempting to load the instruction TLB with a translation for a non-executable page.
A protection check (privileges, read/write) failed. <- that's happening now
A reserved bit in the page directory or table entries is set to 1. 
Moldytzu commented 2 years ago

you're writing to privileged or inexistent memory

Moldytzu commented 2 years ago

if you don't understand what I'm saying let me know

Moldytzu commented 2 years ago

wanna tell you the fix?

Andrej123456789 commented 2 years ago

Whatever you say, I can print now

Moldytzu commented 2 years ago

you removed that chunk of code, right?

Andrej123456789 commented 2 years ago

#include <stdint.h>
#include "BasicRenderer.h"
#include "cstr.h"
#include "efiMemory.h"
#include "memory.h"
#include "Bitmap.h"
#include "paging/PageFrameAllocator.h"
#include "paging/PageMapIndexer.h"
#include "paging/paging.h"
#include "paging/PageTableManager.h"

struct BootInfo {
    Framebuffer* framebuffer;
    PSF1_FONT* psf1_Font;
    EFI_MEMORY_DESCRIPTOR* mMap;
    uint64_t mMapSize;
    uint64_t mMapDescSize;
} ;

extern uint64_t _KernelStart;
extern uint64_t _KernelEnd;

extern "C" void _start(BootInfo* bootInfo){

    BasicRenderer newRenderer = BasicRenderer(bootInfo->framebuffer, bootInfo->psf1_Font); 

    //Welcome
    newRenderer.Colour = 0xff00ffff;
    newRenderer.CursorPosition = {0, 0};
    newRenderer.Print("Welcome to ringOS!!");
    newRenderer.Print(" ");

    //Basic system info
    newRenderer.Colour = 0xffffff00;

    newRenderer.CursorPosition = {0, 16};
    newRenderer.Print("Basic System Info:");
    newRenderer.Print(" ");

    newRenderer.Print("Width: ");
    newRenderer.Print(to_string((uint64_t)bootInfo->framebuffer->Width));
    newRenderer.Print(" | ");

    newRenderer.Print("Height: ");
    newRenderer.Print(to_string((uint64_t)bootInfo->framebuffer->Height));
    newRenderer.Print(" | ");

    newRenderer.Print("PixelsPerScanLine: ");
    newRenderer.Print(to_string((uint64_t)bootInfo->framebuffer->PixelsPerScanLine));
    newRenderer.Print(" | ");

    uint64_t mMapEntries = bootInfo->mMapSize / bootInfo->mMapDescSize;

    GlobalAllocator = PageFrameAllocator();
    GlobalAllocator.ReadEFIMemoryMap(bootInfo->mMap, bootInfo->mMapSize, bootInfo->mMapDescSize);

    uint64_t kernelSize = (uint64_t)&_KernelEnd - (uint64_t)&_KernelStart;
    uint64_t kernelPages = (uint64_t)kernelSize / 4096 + 1;

    GlobalAllocator.LockPages(&_KernelStart, kernelPages);

    PageTable* PML4 = (PageTable*)GlobalAllocator.RequestPage();
    memset(PML4, 0, 0x1000);

    PageTableManager pageTableManager = PageTableManager(PML4);

    for (uint64_t t = 0; t < GetMemorySize(bootInfo->mMap, mMapEntries, bootInfo->mMapDescSize); t+= 0x1000){
        pageTableManager.MapMemory((void*)t, (void*)t);
    }

    uint64_t fbBase = (uint64_t)bootInfo->framebuffer->BaseAddress;
    uint64_t fbSize = (uint64_t)bootInfo->framebuffer->BufferSize + 0x1000;
    for (uint64_t t = fbBase; t < fbBase + fbSize; t += 4096){
        pageTableManager.MapMemory((void*)t, (void*)t);
    }

    asm ("mov %0, %%cr3" : : "r" (PML4));

    pageTableManager.MapMemory((void*)0x600000000, (void*)0x80000);

    uint64_t* test = (uint64_t*)0x600000000;
    *test = 26;

    newRenderer.Print(to_string(*test));

    return ;
}
Andrej123456789 commented 2 years ago

My code

Moldytzu commented 2 years ago

does it work?

Andrej123456789 commented 2 years ago

Yes

Moldytzu commented 2 years ago

ok

Andrej123456789 commented 2 years ago

image

Andrej123456789 commented 2 years ago

Thanks for help

Moldytzu commented 2 years ago

ur welcome