42_KFS/src/memory/memory.c
2024-10-15 10:55:13 +02:00

43 lines
1.0 KiB
C

#include "memory.h"
#include "kprintf.h"
#include "string.h"
#include <stdint.h>
extern void enable_paging(void);
extern void load_page_directory(uint32_t *);
extern uint32_t boot_page_table1;
extern uint32_t boot_page_directory;
// Pour récupérer une entrée spécifique
uint32_t *page_directory = &boot_page_directory;
uint32_t *page_table_entries = &boot_page_table1;
unsigned long read_cr3()
{
unsigned long cr3_value;
// Inline assembly to read CR3
__asm__ volatile(
"mov %%cr3, %0" // Move the value of CR3 into cr3_value
: "=r"(
cr3_value) // Output operand: cr3_value will receive the value
: // No input operands
: // No clobber list
);
return cr3_value;
}
static inline void load_cr3(uint64_t cr3_value)
{
asm volatile("mov %0, %%cr3" ::"r"(cr3_value) : "memory");
}
void init_memory(void)
{
//for (int i = 0x00; i < 0x300; i++)
// page_table_entries[i] = (i << 12) | INIT_FLAGS;
//page_directory[1] = (uint32_t)page_table_entries | INIT_FLAGS;
}