tasking: add simple base for running things in ring 3

This commit is contained in:
2025-04-07 16:13:31 +03:00
parent 03e718c2c8
commit 372b308ec8
9 changed files with 163 additions and 10 deletions
+11 -2
View File
@@ -3,6 +3,8 @@
uint32_t kernel_page_directory[1024] __attribute__((aligned(4096)));
uint32_t kernel_page_table[1024] __attribute__((aligned(4096)));
uint32_t user_page_table[1024] __attribute__((aligned(4096)));
void enablePaging() {
asm volatile (
@@ -35,8 +37,9 @@ void paging_init() {
// Проверяем физические адреса
uint32_t pd_phys = (uint32_t)kernel_page_directory;
uint32_t pt_phys = (uint32_t)kernel_page_table;
uint32_t user_pt_phys = (uint32_t)user_page_table;
if (pd_phys & 0xFFF || pt_phys & 0xFFF) {
if (pd_phys & 0xFFF || pt_phys & 0xFFF || user_pt_phys & 0xFFF) {
while (1); // Ошибка выравнивания
}
@@ -51,6 +54,12 @@ void paging_init() {
}
kernel_page_directory[0] = pt_phys | 0x3;
// Ring 3: 0x004000000x007FFFFF, User-accessible
for (i = 0; i < 1024; i++) {
user_page_table[i] = 0; // Изначально не отображено
}
kernel_page_directory[1] = user_pt_phys | 0x7; // Present, R/W, User
// Рекурсивное отображение
kernel_page_directory[1023] = pd_phys | 0x3;
@@ -76,4 +85,4 @@ void test_paging() {
printf("(uint32_t)first_page_table | 0x3 = %X", (uint32_t)kernel_page_table | 0x3);
while (1); // Рекурсия сломана
}
}
}