x86: linker: define z_mapped_* symbols

We will use this to map the kernel instead of all RAM.
The end of the kernel is always page-aligned, regardless
of CONFIG_SRAM_REGION_PERMISSIONS as it must be mapped.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2020-12-10 12:35:44 -08:00 committed by Anas Nashif
commit 891776ec2a
2 changed files with 31 additions and 12 deletions

View file

@ -51,14 +51,20 @@
#define RAMABLE_REGION RAM
#endif
#ifdef CONFIG_MMU
#define MMU_PAGE_ALIGN . = ALIGN(CONFIG_MMU_PAGE_SIZE);
#else
#define MMU_PAGE_ALIGN
#endif
/* Used to align areas with separate memory permission characteristics
* so that the page permissions can be set in the MMU. Without this,
* the kernel is just one blob with the same RWX permissions on all RAM
*/
#ifdef CONFIG_SRAM_REGION_PERMISSIONS
#define MMU_PAGE_ALIGN . = ALIGN(CONFIG_MMU_PAGE_SIZE);
#define MMU_PAGE_ALIGN_PERM MMU_PAGE_ALIGN
#else
#define MMU_PAGE_ALIGN
#define MMU_PAGE_ALIGN_PERM
#endif
ENTRY(CONFIG_KERNEL_ENTRY)
@ -90,6 +96,9 @@ SECTIONS
SECTION_PROLOGUE(_TEXT_SECTION_NAME,,)
{
_image_text_start = .;
#ifndef CONFIG_XIP
z_mapped_start = .;
#endif
/* Located in generated directory. This file is populated by calling
* zephyr_linker_sources(ROM_START ...). This typically contains the vector
@ -112,7 +121,7 @@ SECTIONS
#include <linker/kobject-text.ld>
MMU_PAGE_ALIGN
MMU_PAGE_ALIGN_PERM
} GROUP_LINK_IN(ROMABLE_REGION)
_image_text_end = .;
@ -156,7 +165,7 @@ SECTIONS
#include <linker/cplusplus-rom.ld>
MMU_PAGE_ALIGN
MMU_PAGE_ALIGN_PERM
/* ROM ends here, position counter will now be in RAM areas */
#ifdef CONFIG_XIP
_image_rom_end = .;
@ -177,6 +186,10 @@ SECTIONS
/* RAMABLE_REGION */
GROUP_START(RAMABLE_REGION)
#ifdef CONFIG_XIP
MMU_PAGE_ALIGN
z_mapped_start = .;
#endif
/* Located in generated directory. This file is populated by the
* zephyr_linker_sources() Cmake function.
*/
@ -184,8 +197,8 @@ SECTIONS
#ifdef CONFIG_USERSPACE
/* APP SHARED MEMORY REGION */
#define SMEM_PARTITION_ALIGN(size) MMU_PAGE_ALIGN
#define APP_SHARED_ALIGN MMU_PAGE_ALIGN
#define SMEM_PARTITION_ALIGN(size) MMU_PAGE_ALIGN_PERM
#define APP_SHARED_ALIGN MMU_PAGE_ALIGN_PERM
#include <app_smem.ld>
@ -198,7 +211,7 @@ SECTIONS
SECTION_PROLOGUE(_BSS_SECTION_NAME, (NOLOAD),)
{
MMU_PAGE_ALIGN
MMU_PAGE_ALIGN_PERM
#if !defined(CONFIG_USERSPACE)
_image_ram_start = .;
#endif
@ -227,7 +240,7 @@ SECTIONS
#include <linker/common-noinit.ld>
MMU_PAGE_ALIGN
MMU_PAGE_ALIGN_PERM
SECTION_DATA_PROLOGUE(_DATA_SECTION_NAME,,)
{
@ -261,7 +274,7 @@ SECTIONS
#include <snippets-rwdata.ld>
#ifdef CONFIG_X86_KPTI
MMU_PAGE_ALIGN
MMU_PAGE_ALIGN_PERM
z_shared_kernel_page_start = .;
/* Special page containing supervisor data that is still mapped in
* user mode page tables. IDT, GDT, TSSes, trampoline stack, and
@ -302,7 +315,7 @@ SECTIONS
#ifdef CONFIG_X86_KPTI
z_trampoline_stack_start = .;
MMU_PAGE_ALIGN
MMU_PAGE_ALIGN_PERM
z_trampoline_stack_end = .;
z_shared_kernel_page_end = .;
@ -334,6 +347,8 @@ SECTIONS
_image_ram_end = .;
_image_ram_all = (KERNEL_BASE_ADDR + KERNEL_RAM_SIZE) - _image_ram_start;
z_mapped_end = .;
z_mapped_size = z_mapped_end - z_mapped_start;
_end = .; /* end of image */
GROUP_END(RAMABLE_REGION)

View file

@ -70,7 +70,7 @@ SECTIONS
"shared kernel area is not one memory page");
#endif /* CONFIG_X86_KPTI */
MMU_PAGE_ALIGN
. = ALIGN(CONFIG_MMU_PAGE_SIZE);
_lodata_end = .;
} > LOCORE
@ -87,6 +87,7 @@ SECTIONS
{
_image_rom_start = .;
_image_text_start = .;
z_mapped_start = .;
*(.text)
*(.text.*)
@ -179,14 +180,17 @@ SECTIONS
/* Must be last in RAM */
#include <linker/kobject.ld>
. = ALIGN(CONFIG_MMU_PAGE_SIZE);
_image_ram_end = .;
z_mapped_end = .;
_end = .;
/* All unused memory also owned by the kernel for heaps */
__kernel_ram_end = KERNEL_BASE_ADDR + KERNEL_RAM_SIZE;
__kernel_ram_size = __kernel_ram_end - __kernel_ram_start;
z_mapped_size = z_mapped_end - z_mapped_start;
#include <linker/debug-sections.ld>
/DISCARD/ :