45 lines
1011 B
C
45 lines
1011 B
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[1024];
|
|
|
|
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 = 0; i < 1024; i++)
|
|
page_table_entries[i] = (i << 12) | INIT_FLAGS;
|
|
|
|
page_directory[0] = ((uint32_t)page_table_entries << 12) | INIT_FLAGS;
|
|
} |