Skip to content

Commit c3abd7a

Browse files
dcpleungcfriedt
authored andcommitted
demand_paging: add a flash-based backing store for qemu_x86_tiny
This adds a flash-based backing store for qemu_x86_tiny board for testing demand paging. This allows us to test code execution where .text section is not in physical memory at boot. Signed-off-by: Daniel Leung <[email protected]>
1 parent fa32671 commit c3abd7a

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

subsys/demand_paging/backing_store/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ include_directories(
1111
if(NOT DEFINED CONFIG_BACKING_STORE_CUSTOM)
1212
zephyr_library()
1313
zephyr_library_sources_ifdef(CONFIG_BACKING_STORE_RAM ram.c)
14+
15+
zephyr_library_sources_ifdef(
16+
CONFIG_BACKING_STORE_QEMU_X86_TINY_FLASH
17+
backing_store_qemu_x86_tiny.c
18+
)
1419
endif()

subsys/demand_paging/backing_store/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ config BACKING_STORE_RAM
1818
This implements a backing store using physical RAM pages that the
1919
Zephyr kernel is otherwise unaware of. It is intended for
2020
demonstration and testing of the demand paging feature.
21+
22+
config BACKING_STORE_QEMU_X86_TINY_FLASH
23+
bool "Flash-based backing store on qemu_x86_tiny"
24+
depends on BOARD_QEMU_X86_TINY
25+
help
26+
This uses the "flash" memory area (in DTS) as the backing store
27+
for demand paging. The qemu_x86_tiny.ld linker script puts
28+
the symbols outside of boot and pinned sections into the flash
29+
area, allowing testing of the demand paging mechanism on
30+
code and data.
2131
endchoice
2232

2333
if BACKING_STORE_RAM
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright (c) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief Backing store on qemu_x86_tiny for testing
10+
*
11+
* This uses the "flash" memory area (in DTS) as the backing store
12+
* for demand paging. The qemu_x86_tiny.ld linker script puts
13+
* the symbols outside of boot and pinned sections into the flash
14+
* area, allowing testing of the demand paging mechanism on
15+
* code and data.
16+
*/
17+
18+
#include <mmu.h>
19+
#include <string.h>
20+
#include <kernel_arch_interface.h>
21+
#include <linker/linker-defs.h>
22+
#include <sys/util.h>
23+
24+
void *location_to_flash(uintptr_t location)
25+
{
26+
uintptr_t ptr = location;
27+
28+
/* Offset from start of virtual address space */
29+
ptr -= CONFIG_KERNEL_VM_BASE + CONFIG_KERNEL_VM_OFFSET;
30+
31+
/* Translate the offset into address to flash */
32+
ptr += CONFIG_FLASH_BASE_ADDRESS;
33+
34+
__ASSERT_NO_MSG(ptr >= CONFIG_FLASH_BASE_ADDRESS);
35+
__ASSERT_NO_MSG(ptr < (CONFIG_FLASH_BASE_ADDRESS
36+
+ KB(CONFIG_FLASH_SIZE)
37+
- CONFIG_MMU_PAGE_SIZE));
38+
39+
return UINT_TO_POINTER(ptr);
40+
}
41+
42+
int k_mem_paging_backing_store_location_get(struct z_page_frame *pf,
43+
uintptr_t *location,
44+
bool page_fault)
45+
{
46+
/* Simply returns the virtual address */
47+
*location = POINTER_TO_UINT(pf->addr);
48+
49+
return 0;
50+
}
51+
52+
void k_mem_paging_backing_store_location_free(uintptr_t location)
53+
{
54+
/* Nothing to do */
55+
}
56+
57+
void k_mem_paging_backing_store_page_out(uintptr_t location)
58+
{
59+
(void)memcpy(location_to_flash(location), Z_SCRATCH_PAGE,
60+
CONFIG_MMU_PAGE_SIZE);
61+
}
62+
63+
void k_mem_paging_backing_store_page_in(uintptr_t location)
64+
{
65+
(void)memcpy(Z_SCRATCH_PAGE, location_to_flash(location),
66+
CONFIG_MMU_PAGE_SIZE);
67+
}
68+
69+
void k_mem_paging_backing_store_page_finalize(struct z_page_frame *pf,
70+
uintptr_t location)
71+
{
72+
/* Nothing to do */
73+
}
74+
75+
void k_mem_paging_backing_store_init(void)
76+
{
77+
/* Nothing to do */
78+
}

0 commit comments

Comments
 (0)