[PATCH 03/11] x86/xip: copy writable sections into RAM

From: Jim Kukunas
Date: Mon Mar 23 2015 - 03:58:01 EST


Loads all writable and non-zero sections into their VMA.

Signed-off-by: Jim Kukunas <james.t.kukunas@xxxxxxxxxxxxxxx>
---
arch/x86/include/asm/sections.h | 4 ++++
arch/x86/kernel/head_32.S | 22 ++++++++++++++++++++++
arch/x86/kernel/vmlinux.lds.S | 4 ++++
3 files changed, 30 insertions(+)

diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 0a52424..9535e95 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -11,4 +11,8 @@ extern struct exception_table_entry __stop___ex_table[];
extern char __end_rodata_hpage_align[];
#endif

+#ifdef CONFIG_XIP_KERNEL
+extern char phys_sdata[];
+#endif
+
#endif /* _ASM_X86_SECTIONS_H */
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index f36bd42..80f344a 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -86,6 +86,28 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
*/
__HEAD
ENTRY(startup_32)
+
+#ifdef CONFIG_XIP_KERNEL
+ /*
+ * Copy writable sections into RAM
+ */
+
+ movl %esi, %ebp # Preserve pointer to zero-page
+
+ leal pa(_sdata), %edi
+ leal phys_edata, %ecx
+ leal phys_sdata, %esi
+ subl %esi, %ecx
+
+ cld
+xip_data_cp:
+ lodsb
+ stosb
+ loop xip_data_cp
+
+ movl %ebp, %esi
+#endif
+
movl pa(stack_start),%ecx

/* test KEEP_SEGMENTS flag to see if the bootloader is asking
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 414a1ac..59a9edb 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -133,6 +133,9 @@ SECTIONS
RO_DATA(PAGE_SIZE)
X64_ALIGN_DEBUG_RODATA_END

+ phys_sdata = LOADADDR(.data);
+ phys_edata = phys_sdata + (_end_nonzero - _sdata);
+
/* Data */
.data : AT(ADDR(.data) - LOAD_OFFSET) DATA_ALIGN {
/* Start of data section */
@@ -319,6 +322,7 @@ SECTIONS
NOSAVE_DATA
}
#endif
+ _end_nonzero = .;

/* BSS */
. = ALIGN(PAGE_SIZE);
--
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/