[PATCH 04/11] x86/xip: XIP boot trampoline page tables

From: Jim Kukunas
Date: Mon Mar 23 2015 - 03:55:16 EST


Constructs the trampoline page tables for early XIP boot.

Signed-off-by: Jim Kukunas <james.t.kukunas@xxxxxxxxxxxxxxx>
---
arch/x86/kernel/head_32.S | 85 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 85 insertions(+)

diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index 80f344a..642d73b 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -227,6 +227,90 @@ xip_data_cp:
movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
#else /* Not PAE */

+#ifdef CONFIG_XIP_KERNEL
+ movl $pa(__brk_base), %edi
+ movl $pa(initial_page_table), %edx
+
+ movl $PTE_IDENT_ATTR, %eax /* EAX holds identity mapping addr */
+ movl $__PAGE_OFFSET + PTE_IDENT_ATTR, %ebx /* EBX holds kernel addr */
+
+.Lxip_mapping:
+/* Allocate or Load Identity PDE */
+ leal -PTE_IDENT_ATTR(%eax), %ebp
+ andl $0xFFC00000, %ebp
+ shrl $20, %ebp
+ movl (%edx, %ebp), %ecx
+
+ test %ecx, %ecx
+ jnz .Lskip_ident_pde_alloc
+ leal PDE_IDENT_ATTR(%edi), %ecx
+ addl $4096, %edi
+ movl %ecx, (%edx, %ebp)
+
+.Lskip_ident_pde_alloc:
+ leal -PDE_IDENT_ATTR(%ecx), %ecx
+ leal -PTE_IDENT_ATTR(%eax), %ebp
+ andl $0x3FF000, %ebp
+ shrl $10, %ebp
+ movl %eax, (%ecx, %ebp)
+
+/* Allocate or Load PAGE_OFFSET PDE */
+ leal -PTE_IDENT_ATTR(%ebx), %ebp
+ andl $0xFFC00000, %ebp
+ shrl $20, %ebp
+ movl (%edx, %ebp), %ecx
+
+ test %ecx, %ecx
+ jnz .Lskip_offset_pde_alloc
+ leal PDE_IDENT_ATTR(%edi), %ecx
+ addl $4096, %edi
+ movl %ecx, (%edx, %ebp)
+
+.Lskip_offset_pde_alloc:
+ leal -PDE_IDENT_ATTR(%ecx), %ecx
+ leal -PTE_IDENT_ATTR(%ebx), %ebp
+ andl $0x3FF000, %ebp
+ shrl $10, %ebp
+ movl %eax, (%ecx, %ebp)
+
+ addl $4096, %eax
+ addl $4096, %ebx
+
+ cmpl $CONFIG_PHYSICAL_START + PTE_IDENT_ATTR, %eax
+ je .Lsetup_text_addr
+
+ cmpl $phys_sdata + PTE_IDENT_ATTR, %eax
+ je .Lsetup_data_addr
+
+ cmpl $pa(_end) + MAPPING_BEYOND_END + PTE_IDENT_ATTR, %eax
+ je .Ldone
+
+ jmp .Lxip_mapping
+
+.Lsetup_text_addr:
+ movl $CONFIG_XIP_BASE + 4096 + PTE_IDENT_ATTR, %eax
+ movl $_text, %ebx
+ addl $PTE_IDENT_ATTR, %ebx
+ jmp .Lxip_mapping
+
+.Lsetup_data_addr:
+ movl $pa(_sdata), %eax
+ addl $PTE_IDENT_ATTR, %eax
+ movl $_sdata, %ebx
+ addl $PTE_IDENT_ATTR, %ebx
+ jmp .Lxip_mapping
+.Ldone:
+ addl $__PAGE_OFFSET, %edi
+ movl %edi, pa(_brk_end)
+ movl $pa(_end) + MAPPING_BEYOND_END + PTE_IDENT_ATTR, %eax
+ shrl $12, %eax
+ movl %eax, pa(max_pfn_mapped)
+
+ movl $pa(initial_pg_fixmap) + PTE_IDENT_ATTR, %eax
+ movl %eax, pa(initial_page_table + 0xFFC)
+
+#else
+
page_pde_offset = (__PAGE_OFFSET >> 20);

movl $pa(__brk_base), %edi
@@ -257,6 +341,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
movl %eax,pa(initial_page_table+0xffc)
#endif
+#endif

#ifdef CONFIG_PARAVIRT
/* This is can only trip for a broken bootloader... */
--
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/