paging is now enabled with __shaky__ code

This commit is contained in:
2025-06-09 21:01:17 -04:00
parent 83b6a9eaf2
commit 920d0b01e1
7 changed files with 97 additions and 10 deletions

View File

@ -5,6 +5,9 @@
(https://wiki.osdev.org/Troubleshooting#Showing_the_stack_content)
lets implmeent some better testing functions aswell
- Paging & virtual memory
- Get GRUB to show memory map - DONE
- Write a page allocator - WIP
- Setup paging
- Setup higher half kernel
- Heap allocator (malloc)
- after this, implment some data structures? cleanup queue?

View File

@ -10,7 +10,7 @@ outb:
ret ; return to the calling function
global outb_16
global outb_16 ; TODO these are probably wrong, eh, the stack might need more bcs the variables are bigger? im not sure
outb_16:
mov ax, [esp + 8]
mov dx, [esp + 4]

View File

@ -1,6 +0,0 @@
#include <stdint.h>
extern uint32_t endkernel; // found in link.ld

View File

@ -0,0 +1,55 @@
#include <stdint.h>
#include <stdio.h>
#include <kernel/paging.h>
//extern uint32_t endkernel; // found in link.ld
/**
* The page table must be page aligned (aligned at 4KiB)
*
*
* This is a temporary solution, as we want a page frame allocator, to properly get page frames.. but this works for now
*/
uint32_t page_directory[PAGE_DIRECTORY_ENTRIES] __attribute__((aligned(4096)));
uint32_t first_page_table[PAGE_TABLE_ENTRIES] __attribute__((aligned(4096)));
void setup_page_table(void)
{
uint32_t i;
for (i = 0; i < PAGE_TABLE_ENTRIES; i++) {
first_page_table[i] = (i * 0x1000) | 3; // supervisor, r/w, present
}
puts("test");
}
void setup_page_dir(void)
{
setup_page_table();
/**
* Now that we have a page directory, we need to blank it.
*
* The page directory should have exactly 1024 entries. We will set each entry to not present, so that the if the
* MMU looks for that page table, it will see that it is not there yet.
*/
int i;
for (i = 0; i < PAGE_DIRECTORY_ENTRIES; i++) {
// This sets the following flags to the pages:
// Supervisor: Only kernel-mode can access them
// Write Enabled: It can be both read from and written to
// Not Present: The page table is not present
page_directory[i] = 0x00000002;
}
page_directory[0] = ((uint32_t) first_page_table) | 3;
}
void setup_paging(void)
{
setup_page_dir();
load_page_directory(page_directory);
enable_paging();
}

View File

@ -0,0 +1,20 @@
global load_page_directory
load_page_directory:
push ebp
mov esp, ebp
mov eax, [esp + 4]
mov cr3, eax
mov esp, ebp
pop ebp
ret
global enable_paging
enable_paging:
push ebp
mov ebp, esp
mov eax, cr0
or eax, 0x80000000
mov cr0, eax
mov esp, ebp
pop ebp
ret

View File

@ -1,3 +1,16 @@
typedef struct {
#include <stdint.h>
} pageframe_t;
#ifndef ARCH_PAGING_H
#define ARCH_PAGING_H
#define PAGE_TABLE_ENTRIES 1024
#define PAGE_DIRECTORY_ENTRIES 1024
void load_page_directory(uint32_t*);
void enable_paging();
void setup_paging(void);
#endif

View File

@ -5,12 +5,12 @@
#include <kernel/_kernel.h>
#include <kernel/tty.h>
#include <kernel/serial.h>
#include <kernel/paging.h>
#include <kernel/x86/gdt.h>
#include <kernel/x86/idt.h>
#include <kernel/x86/io.h>
#include <kernel/x86/keyb.h>
#include <kernel/x86/pit.h>
#include <kernel/x86/pci.h>
#include "multiboot.h"
@ -76,6 +76,8 @@ void _main(multiboot_info_t* mbd, uint32_t magic)
serial_initialize();
#endif
setup_paging();
init_kb();
init_pit(0x36, PIT_CHANNEL_0, 0);