42_KFS/src/memory/memory.c

45 lines
1011 B
C
Raw Normal View History

#include "memory.h"
2024-10-14 18:29:46 -04:00
#include "kprintf.h"
#include "string.h"
2024-10-14 18:29:46 -04:00
#include <stdint.h>
extern void enable_paging(void);
2024-10-14 18:29:46 -04:00
extern void load_page_directory(uint32_t *);
extern uint32_t boot_page_table1;
extern uint32_t boot_page_directory;
2024-10-14 18:29:46 -04:00
// Pour récupérer une entrée spécifique
uint32_t *page_directory = &boot_page_directory;
2024-10-15 07:32:02 -04:00
uint32_t page_table_entries[1024];
2024-10-14 18:29:46 -04:00
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)
{
2024-10-15 07:32:02 -04:00
for (int i = 0; i < 1024; i++)
page_table_entries[i] = (i << 12) | INIT_FLAGS;
page_directory[0] = ((uint32_t)page_table_entries << 12) | INIT_FLAGS;
2024-10-14 18:29:46 -04:00
}