I've been working through these changes in BBL and the elfloader. The BBL as mentioned seems to be easy (though I'm not ruling out issues here). The elfloader is a little more problematic. I have made some modifications there, but they result in a lot of page table entries that seems erroneous. At the point where the virtual memory translations are committed (writing to satp register) it hangs and cannot access memory at the next instruction's address. Here is what I've done to map_kernel_window in boot.c of the elfloader: #define NEW_PT_LEVEL_2_BITS = 17 //instead of 21 65 void map_kernel_window(struct image_info *kernel_info) 66 { 67 uint32_t index; 68 unsigned long *lpt; 69 70 /* Map the elfloader into the new address space */ 71 printf("_text: %x\n", (uintptr_t)_text); 72 index = GET_PT_INDEX((uintptr_t)_text, PT_LEVEL_1); 73 printf("73 index: %x\n", index); 74 75 #if __riscv_xlen == 32 76 lpt = l1pt; 77 #else 78 lpt = l2pt_elf; 79 l1pt[index] = PTE_CREATE_NEXT((uintptr_t)l2pt_elf); 80 index = GET_PT_INDEX((uintptr_t)_text, PT_LEVEL_2); 81 printf("81 index: %x\n", index); 82 #endif 83 84 if (IS_ALIGNED((uintptr_t)_text, NEW_PT_LEVEL_2_BITS)) { 85 for (int page = 0; index < PTES_PER_PT; index++, page++) { 86 lpt[index] = PTE_CREATE_LEAF((uintptr_t)_text + 87 (page << NEW_PT_LEVEL_2_BITS)); 88 printf("_text: %x\n", (uintptr_t)_text); 89 printf("lpt[index]: %x\n", lpt[index]); 90 printf("page: %x\n", page); 91 printf("index: %x\n", index); 92 } 93 } else { 94 printf("Elfloader not properly aligned\n"); 95 abort(); 96 } 97 98 /* Map the kernel into the new address space */ 99 printf("kernel_info->virt_region_start: %x\n", kernel_info->virt_region_start); 100 index = GET_PT_INDEX(kernel_info->virt_region_start, PT_LEVEL_1); 101 printf("101 index: %x\n", index); 102 103 #if __riscv_xlen == 64 104 lpt = l2pt; 105 l1pt[index] = PTE_CREATE_NEXT((uintptr_t)l2pt); 106 index = GET_PT_INDEX(kernel_info->virt_region_start, PT_LEVEL_2); 107 printf("107 index: %x\n", index); 108 #endif 109 if (VIRT_PHYS_ALIGNED(kernel_info->virt_region_start, 110 kernel_info->phys_region_start, NEW_PT_LEVEL_2_BITS)) { 111 for (int page = 0; index < PTES_PER_PT; index++, page++) { 112 lpt[index] = PTE_CREATE_LEAF(kernel_info->phys_region_start + 113 (page << NEW_PT_LEVEL_2_BITS)); 114 printf("kernel_info->virt_region_start: %x\n", kernel_info->virt_region_start); 115 printf("lpt[index]: %x\n", lpt[index]); 116 printf("page: %x\n", page); 117 printf("117 index: %x\n", index); 118 } 119 } else { 120 printf("Kernel not properly aligned\n"); 121 abort(); 122 } 123 printf("l1pt: %x\n", l1pt); 124 } Can anyone see what I've done wrong here?