linux for ARM 中的矢量页面映射

Vectors page mapping in linux for ARM

我想了解如何将矢量页面映射到 0xffff0000. 我指的是 3.14 内核。

根据 early_trap_init() traps.c 中的注释,矢量从 entry-armv.S 复制到矢量页面。

似乎 early_trap_init() 是从 devicemaps_init() mmu.c 调用的。

在调用 early_trap_init() 之前,它正在使用 early_alloc() 创建矢量页面,我在这里看不到任何映射。

能否请您帮助了解矢量页面映射是如何完成的?

答案在你的devicemaps_init()link中(关于 3.14 中的第 1250 行)。

     /*
      * Create a mapping for the machine vectors at the high-vectors
      * location (0xffff0000).  If we aren't using high-vectors, also
      * create a mapping at the low-vectors virtual address.
      */
     map.pfn = __phys_to_pfn(virt_to_phys(vectors));
     map.virtual = 0xffff0000;
     map.length = PAGE_SIZE;
 #ifdef CONFIG_KUSER_HELPERS
     map.type = MT_HIGH_VECTORS;
 #else
     map.type = MT_LOW_VECTORS;
 #endif
     create_mapping(&map);

那里有额外的代码可以进行更多映射。注意这里有物理向量指令加上code to transition modes。这是通过 vector_stub 汇编器宏完成的。评论里的一个解释很好(另见第2条相关link)。

   Vector stubs.

   This code is copied to 0xffff1000 so we can use branches in the
   vectors, rather than ldr's.  Note that this code must not exceed
   a page size.

   Common stub entry macro:
     Enter in IRQ mode, spsr = SVC/USR CPSR, lr = SVC/USR PC

   SP points to a minimal amount of processor-private memory, the address
   of which is copied into r0 for the mode specific abort handler.

所以我们可以在向量中使用分支表示向量中的第一条指令table。

相关:Find the physical address of exception vector table
Linux kernel arm exception stack init