-#include <hal/cpu.h>
#include <klibc/string.h>
#include <lunaix/mm/pmm.h>
#include <lunaix/mm/vmm.h>
#include <lunaix/spike.h>
#include <lunaix/syslog.h>
+#include <sys/cpu.h>
+#include <sys/mm/mempart.h>
+
LOG_MODULE("VMM")
void
// See if attr make sense
assert(attr <= 128);
- if (!l1pt->entry[l1_inx]) {
+ x86_pte_t* l1pte = &l1pt->entry[l1_inx];
+ if (!*l1pte) {
x86_page_table* new_l1pt_pa =
(x86_page_table*)pmm_alloc_page(KERNEL_PID, PP_FGPERSIST);
}
// This must be writable
- l1pt->entry[l1_inx] =
- NEW_L1_ENTRY(attr | PG_WRITE | PG_PRESENT, new_l1pt_pa);
+ *l1pte = NEW_L1_ENTRY(attr | PG_WRITE | PG_PRESENT, new_l1pt_pa);
// make sure our new l2 table is visible to CPU
- cpu_invplg((ptr_t)l2pt);
+ cpu_flush_page((ptr_t)l2pt);
memset((void*)l2pt, 0, PG_SIZE);
} else {
+ if ((attr & PG_ALLOW_USER) && !(*l1pte & PG_ALLOW_USER)) {
+ *l1pte |= PG_ALLOW_USER;
+ }
+
x86_pte_t pte = l2pt->entry[l2_inx];
if (pte && (options & VMAP_IGNORE)) {
return 1;
}
if (mnt == VMS_SELF) {
- cpu_invplg(va);
+ cpu_flush_page(va);
}
if ((options & VMAP_NOMAP)) {
x86_page_table* l2pt = (x86_page_table*)(mnt | (l1_index << 12));
x86_pte_t l2pte = l2pt->entry[l2_index];
- cpu_invplg(va);
+ cpu_flush_page(va);
l2pt->entry[l2_index] = PTE_NULL;
return PG_ENTRY_ADDR(l2pte);
{
x86_page_table* l1pt = (x86_page_table*)L1_BASE_VADDR;
l1pt->entry[(mnt >> 22)] = NEW_L1_ENTRY(T_SELF_REF_PERM, pde);
- cpu_invplg(mnt);
+ cpu_flush_page(mnt);
return mnt;
}
{
x86_page_table* l1pt = (x86_page_table*)L1_BASE_VADDR;
l1pt->entry[(mnt >> 22)] = 0;
- cpu_invplg(mnt);
+ cpu_flush_page(mnt);
return mnt;
+}
+
+ptr_t
+vmm_dup_page(pid_t pid, ptr_t pa)
+{
+ ptr_t new_ppg = pmm_alloc_page(pid, 0);
+ vmm_set_mapping(VMS_SELF, PG_MOUNT_3, new_ppg, PG_PREM_RW, VMAP_NULL);
+ vmm_set_mapping(VMS_SELF, PG_MOUNT_4, pa, PG_PREM_RW, VMAP_NULL);
+
+ asm volatile("movl %1, %%edi\n"
+ "movl %2, %%esi\n"
+ "rep movsl\n" ::"c"(1024),
+ "r"(PG_MOUNT_3),
+ "r"(PG_MOUNT_4)
+ : "memory", "%edi", "%esi");
+
+ vmm_del_mapping(VMS_SELF, PG_MOUNT_3);
+ vmm_del_mapping(VMS_SELF, PG_MOUNT_4);
+
+ return new_ppg;
}
\ No newline at end of file