3

I am trying to understand how vectors page is mapped to 0xffff0000. I am referring 3.14 kernel.

As per the comment in early_trap_init() traps.c the vectors are copied from entry-armv.S to vector page.

It seems early_trap_init() is called from devicemaps_init() mmu.c.

Before calling early_trap_init(), it is creating vectors page using early_alloc() and I couldn't see any mapping here.

Can you please help to understand how vectors page mapping is done?

user3693586
  • 1,227
  • 5
  • 18
  • 40

1 Answers1

3

The answer is in your devicemaps_init() link (about line 1250 in 3.14).

     /*
      * 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);

There is additional code there to make more mappings. Note that there are the physical vector instruction plus code to transition modes. This is done via the vector_stub assembler macro. An explanation in the comments is very good (also see the 2nd related 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.

so we can use branches in the vectors means the very first instruction in the vector table.

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

Community
  • 1
  • 1
artless noise
  • 21,212
  • 6
  • 68
  • 105
  • I was in assumption that " initially memory will be created for vector page(with physical address) and will map to virtual address 0xffff0000 then vectors will be copied to vector page", but after seeing reply 1st memory is created for vector page(using early_alloc(), it is returning virtual address), copied vectors by calling early_trap_init() and after that mapping for 0xffff0000 is done for vectors page. My doubt here is two virtual mappings are happening for vector page?(1st virtual address is returned by early_alloc() and 2nd one is doing explicit mapping as shown in the above reply). – user3693586 Apr 16 '16 at 04:06
  • Yes, there are multiple mappings. That is fine? Some are read/write and others are read-only. Some are accessible by user space and others are not. *I am trying to understand how vectors page is mapped to 0xffff0000.* is a question I answered. You never said anything about a *doubt* about two mappings. – artless noise Apr 16 '16 at 15:21
  • Initially my doubt is about vector page mapping, after seeing the reply I got doubt about two virtual mappings for vector page. – user3693586 Apr 16 '16 at 16:13
  • [I have a doubt](https://ell.stackexchange.com/questions/91043/i-have-a-doubt-v-im-in-doubt) is common in India and some romantic languages (Spanish, Italian, etc). As per that page, *I have a question* is a better translation/expression. To many native English speakers, *I have a doubt* would mean you don't believe what the person is saying, and so this did not motivate me to answer the 2nd question. *My **question** here is two virtual mappings are happening for vector page?* I did briefly comment on. I have had many question askers use this 'doubt' expression in further inquiries. – artless noise Sep 30 '20 at 11:39