#include "pmm.h"
#include "vmm.h"
#include "console.h"
+#include "process.h"
#include "utils.h"
- #include "arch/x86/usermode.h"
+#include "arch/x86/usermode.h"
#include "arch/x86/idt.h"
#if defined(__i386__)
return;
}
- vmm_map_page((uint64_t)(uintptr_t)code_phys, (uint64_t)user_code_vaddr,
- VMM_FLAG_PRESENT | VMM_FLAG_RW | VMM_FLAG_USER);
- vmm_map_page((uint64_t)(uintptr_t)stack_phys, (uint64_t)user_stack_vaddr,
- VMM_FLAG_PRESENT | VMM_FLAG_RW | VMM_FLAG_USER);
-
const uintptr_t base = user_code_vaddr;
const uint32_t addr_t1_ok = (uint32_t)(base + 0x200);
const uint32_t addr_t1_fail = (uint32_t)(base + 0x210);
memcpy((void*)((uintptr_t)code_phys + 0x250), "T3 FAIL\n", t3_fail_len);
memcpy((void*)((uintptr_t)code_phys + 0x300), "Hello from ring3!\n", msg_len);
+ /* Create a private address space so the ring3 user pages do NOT
+ * pollute kernel_as (which is shared by all kernel threads).
+ * Code/data was emitted above via the identity mapping still
+ * active in kernel_as; now we switch to the new AS and map the
+ * physical pages at their user virtual addresses. */
+ uintptr_t ring3_as = vmm_as_create_kernel_clone();
+ if (!ring3_as) {
+ kprintf("[USER] Failed to create ring3 address space.\n");
+ pmm_free_page(code_phys);
+ pmm_free_page(stack_phys);
+ return;
+ }
+
+ current_process->addr_space = ring3_as;
+ vmm_as_activate(ring3_as);
+
+ vmm_map_page((uint64_t)(uintptr_t)code_phys, (uint64_t)user_code_vaddr,
+ VMM_FLAG_PRESENT | VMM_FLAG_RW | VMM_FLAG_USER);
+ vmm_map_page((uint64_t)(uintptr_t)stack_phys, (uint64_t)user_stack_vaddr,
+ VMM_FLAG_PRESENT | VMM_FLAG_RW | VMM_FLAG_USER);
+
uintptr_t user_esp = user_stack_vaddr + 4096;
x86_enter_usermode(user_code_vaddr, user_esp);
}
#include "hal/cpu.h"
#include "hal/uart.h"
+#include "timer.h"
#include "utils.h"
#define TTY_LINE_MAX 256
if (target > len) target = len;
if (target == 0) target = 1;
- /* VTIME in tenths-of-second => ticks at 50 Hz */
+ /* VTIME in tenths-of-second => ticks at TIMER_HZ */
uint32_t timeout_ticks = 0;
if (vtime > 0) {
- timeout_ticks = (vtime * 5U);
+ timeout_ticks = vtime * (TIMER_HZ / 10);
if (timeout_ticks == 0) timeout_ticks = 1;
}