Browse Source

[libcpu][risc-v] fix:only map the 1GB space where the original code segment is located

zhangjing 2 months ago
parent
commit
3922ec7e99
1 changed files with 4 additions and 5 deletions
  1. 4 5
      libcpu/risc-v/common64/mmu.c

+ 4 - 5
libcpu/risc-v/common64/mmu.c

@@ -691,11 +691,10 @@ void rt_hw_mem_setup_early(void)
          * identical mapping,
          * identical mapping,
          * PC are still at lower region before relocating to high memory
          * PC are still at lower region before relocating to high memory
          */
          */
-        for (size_t i = 0; i < __SIZE(PPN0_BIT); i++)
-        {
-            early_pgtbl[i] = COMBINEPTE(ps, MMU_MAP_EARLY);
-            ps += L1_PAGE_SIZE;
-        }
+        rt_ubase_t pg_idx ;
+        ps = (rt_ubase_t)symb_pc & (~(L1_PAGE_SIZE - 1));
+        pg_idx = GET_L1(ps);
+        early_pgtbl[pg_idx] = COMBINEPTE(ps, MMU_MAP_EARLY);
 
 
         /* relocate text region */
         /* relocate text region */
         __asm__ volatile("la %0, _start\n" : "=r"(ps));
         __asm__ volatile("la %0, _start\n" : "=r"(ps));