tasking: add simple base for running things in ring 3
This commit is contained in:
+21
-1
@@ -1,6 +1,26 @@
|
||||
#include "../include/paging.h"
|
||||
#include <stdint.h>
|
||||
|
||||
static uint32_t next_user_virt = 0x00400000;
|
||||
void* setup_user_process(void* user_code_phys, uint32_t* user_stack_top) {
|
||||
void* stack_phys = alloc_page();
|
||||
if (!stack_phys) return 0;
|
||||
|
||||
uint32_t code_virt = next_user_virt;
|
||||
uint32_t stack_virt = code_virt + 0x3FF000; // 4 МБ - 4 КБ
|
||||
map_page(user_code_phys, (void*)code_virt, 0x7);
|
||||
map_page(stack_phys, (void*)stack_virt, 0x7);
|
||||
|
||||
*user_stack_top = stack_virt + 0x1000;
|
||||
next_user_virt += 0x400000; // Следующий 4 МБ блок
|
||||
return (void*)code_virt;
|
||||
}
|
||||
|
||||
void free_user_process(void* code_phys, void* stack_phys) {
|
||||
free_page(code_phys);
|
||||
free_page(stack_phys);
|
||||
}
|
||||
|
||||
void *get_physaddr(void *virtualaddr) {
|
||||
unsigned long pdindex = (unsigned long)virtualaddr >> 22;
|
||||
unsigned long ptindex = (unsigned long)virtualaddr >> 12 & 0x03FF;
|
||||
@@ -85,4 +105,4 @@ void map_kernel_page(void* virtualaddr, unsigned int flags) {
|
||||
|
||||
pt[ptindex] = (uint32_t)phys | (flags & 0xFFF) | 0x1; // supervisor, present
|
||||
asm volatile("invlpg (%0)" : : "r" (virtualaddr) : "memory");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user