Skip to content

Commit a91da54

Browse files
linuswRussell King (Oracle)
authored andcommitted
ARM: 9089/1: Define kernel physical section start and end
When we are mapping the initial sections in head.S we know very well where the start and end of the kernel image in physical memory is placed. Later on it gets hard to determine this. Save the information into two variables named kernel_sec_start and kernel_sec_end for convenience for later work involving the physical start and end of the kernel. These variables are section-aligned corresponding to the early section mappings set up in head.S. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
1 parent b78f63f commit a91da54

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

arch/arm/include/asm/memory.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ extern unsigned long vectors_base;
158158

159159
#ifndef __ASSEMBLY__
160160

161+
/*
162+
* Physical start and end address of the kernel sections. These addresses are
163+
* 2MB-aligned to match the section mappings placed over the kernel.
164+
*/
165+
extern phys_addr_t kernel_sec_start;
166+
extern phys_addr_t kernel_sec_end;
167+
161168
/*
162169
* Physical vs virtual RAM address space conversion. These are
163170
* private definitions which should NOT be used outside memory.h

arch/arm/kernel/head.S

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@
4747
.globl swapper_pg_dir
4848
.equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
4949

50+
/*
51+
* This needs to be assigned at runtime when the linker symbols are
52+
* resolved.
53+
*/
54+
.pushsection .data
55+
.align 2
56+
.globl kernel_sec_start
57+
.globl kernel_sec_end
58+
kernel_sec_start:
59+
.long 0
60+
kernel_sec_end:
61+
.long 0
62+
.popsection
63+
5064
.macro pgtbl, rd, phys
5165
add \rd, \phys, #TEXT_OFFSET
5266
sub \rd, \rd, #PG_DIR_SIZE
@@ -229,16 +243,23 @@ __create_page_tables:
229243
blo 1b
230244

231245
/*
232-
* Map our RAM from the start to the end of the kernel .bss section.
246+
* The main matter: map in the kernel using section mappings, and
247+
* set two variables to indicate the physical start and end of the
248+
* kernel.
233249
*/
234-
add r0, r4, #PAGE_OFFSET >> (SECTION_SHIFT - PMD_ORDER)
250+
add r0, r4, #KERNEL_OFFSET >> (SECTION_SHIFT - PMD_ORDER)
235251
ldr r6, =(_end - 1)
236-
orr r3, r8, r7
252+
adr_l r5, kernel_sec_start @ _pa(kernel_sec_start)
253+
str r8, [r5] @ Save physical start of kernel
254+
orr r3, r8, r7 @ Add the MMU flags
237255
add r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER)
238256
1: str r3, [r0], #1 << PMD_ORDER
239257
add r3, r3, #1 << SECTION_SHIFT
240258
cmp r0, r6
241259
bls 1b
260+
eor r3, r3, r7 @ Remove the MMU flags
261+
adr_l r5, kernel_sec_end @ _pa(kernel_sec_end)
262+
str r3, [r5] @ Save physical end of kernel
242263

243264
#ifdef CONFIG_XIP_KERNEL
244265
/*

0 commit comments

Comments
 (0)