Skip to content

Commit 0fe2d72

Browse files
dcpleungFlavio Ceolin
authored andcommitted
xtensa: dc233c: enable userspace support
This massages kconfig and linker script to enable userspace support on dc233c core. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
1 parent 3771eaa commit 0fe2d72

File tree

3 files changed

+61
-41
lines changed

3 files changed

+61
-41
lines changed

soc/xtensa/dc233c/Kconfig.soc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ config SOC_XTENSA_DC233C
99
select ARCH_HAS_THREAD_LOCAL_STORAGE
1010
select CPU_HAS_MMU
1111
select ARCH_HAS_RESERVED_PAGE_FRAMES if XTENSA_MMU
12+
select ARCH_HAS_USERSPACE if XTENSA_MMU

soc/xtensa/dc233c/include/xtensa-dc233c.ld

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <zephyr/linker/linker-tool.h>
2121

2222
#define RAMABLE_REGION RAM :sram0_phdr
23-
#define ROMABLE_REGION rom0_seg :rom0_phdr
23+
#define ROMABLE_REGION RAM :sram0_phdr
2424

2525
#ifdef CONFIG_MMU
2626
#define MMU_PAGE_ALIGN . = ALIGN(CONFIG_MMU_PAGE_SIZE);
@@ -287,6 +287,9 @@ SECTIONS
287287
_DoubleExceptionVector_text_end = ABSOLUTE(.);
288288
} >sram0_18_seg :sram0_18_phdr
289289

290+
#define LIB_OBJ_FUNC_IN_SECT(library, obj_file, func) \
291+
*##library##:##obj_file##(.literal.##func .text.##func) \
292+
290293
#ifdef CONFIG_XTENSA_MMU
291294
.vec_helpers :
292295
{
@@ -301,48 +304,45 @@ SECTIONS
301304
* TLB multi-hit exception.
302305
*/
303306

304-
*libarch__xtensa__core.a:xtensa-asm2-util.S.obj(.literal)
305-
*libarch__xtensa__core.a:xtensa-asm2-util.S.obj(.text)
306-
*libarch__xtensa__core.a:xtensa-asm2-util.S.obj(.iram.text)
307-
*libarch__xtensa__core.a:xtensa-asm2-util.S.obj(.iram0.text)
307+
*libarch__xtensa__core.a:xtensa-asm2-util.S.obj(.literal .text)
308+
*libarch__xtensa__core.a:xtensa-asm2-util.S.obj(.iram.text .iram0.text)
308309

309310
*libarch__xtensa__core.a:window_vectors.S.obj(.iram.text)
310311

311-
*libarch__xtensa__core.a:xtensa-asm2.c.obj(.literal.*)
312-
*libarch__xtensa__core.a:xtensa-asm2.c.obj(.text.*)
313-
314-
*libarch__xtensa__core.a:fatal.c.obj(.literal.*)
315-
*libarch__xtensa__core.a:fatal.c.obj(.text.*)
316-
317-
*libarch__xtensa__core.a:crt1.S.obj(.literal)
318-
*libarch__xtensa__core.a:crt1.S.obj(.text)
312+
*libarch__xtensa__core.a:crt1.S.obj(.literal .text)
319313

320-
*libarch__xtensa__core.a:cpu_idle.c.obj(.literal.*)
321-
*libarch__xtensa__core.a:cpu_idle.c.obj(.text.*)
314+
LIB_OBJ_FUNC_IN_SECT(libarch__xtensa__core.a,xtensa-asm2.c.obj,*)
315+
LIB_OBJ_FUNC_IN_SECT(libarch__xtensa__core.a,fatal.c.obj,*)
316+
LIB_OBJ_FUNC_IN_SECT(libarch__xtensa__core.a,cpu_idle.c.obj,*)
322317

323318
*(.text.arch_is_in_isr)
324319

325320
/* To support backtracing */
326-
*libarch__xtensa__core.a:xtensa_backtrace.c.obj(.literal.*)
327-
*libarch__xtensa__core.a:xtensa_backtrace.c.obj(.text.*)
328-
*libarch__xtensa__core.a:debug_helpers_asm.S.obj(.iram1.literal)
329-
*libarch__xtensa__core.a:debug_helpers_asm.S.obj(.iram1)
321+
LIB_OBJ_FUNC_IN_SECT(libarch__xtensa__core.a,xtensa_backtrace.c.obj,*)
330322

331-
*libkernel.a:fatal.c.obj(.literal.*)
332-
*libkernel.a:fatal.c.obj(.text.*)
323+
*libarch__xtensa__core.a:debug_helpers_asm.S.obj(.iram1.literal .iram1)
324+
325+
/* Userspace related stuff */
326+
LIB_OBJ_FUNC_IN_SECT(libarch__xtensa__core.a,userspace.S.obj,z_xtensa_do_syscall)
327+
LIB_OBJ_FUNC_IN_SECT(libarch__xtensa__core.a,xtensa_mmu.c.obj,z_xtensa_swap_update_page_tables)
333328

334329
/* Below are to speed up execution by avoiding TLB misses
335330
* on frequently used functions.
331+
*
332+
* There is almost 1MB space (due to TLB pinning) so we can
333+
* be generous.
336334
*/
337-
*libkernel.a:sched.c.obj(.literal.*)
338-
*libkernel.a:sched.c.obj(.text.*)
339-
*libkernel.a:timeout.c.obj(.literal.*)
340-
*libkernel.a:timeout.c.obj(.text.*)
341-
342-
*libdrivers__console.a:(.literal.*)
343-
*libdrivers__console.a:(.text.*)
344-
*libdrivers__timer.a:(.literal.*)
345-
*libdrivers__timer.a:(.text.*)
335+
LIB_OBJ_FUNC_IN_SECT(libkernel.a,,*)
336+
337+
LIB_OBJ_FUNC_IN_SECT(libdrivers__console.a,,*)
338+
LIB_OBJ_FUNC_IN_SECT(libdrivers__timer.a,,*)
339+
340+
*(.literal.z_vrfy_* .text.z_vrfy_*)
341+
*(.literal.z_mrsh_* .text.z_mrsh_*)
342+
*(.literal.z_impl_* .text.z_impl_*)
343+
*(.literal.z_obj_* .text.z_obj_*)
344+
345+
*(.literal.k_sys_fatal_error_handler .text.k_sys_fatal_error_handler)
346346
} >vec_helpers :vec_helpers_phdr
347347
#endif /* CONFIG_XTENSA_MMU */
348348

@@ -380,7 +380,7 @@ SECTIONS
380380

381381
_text_end = ABSOLUTE(.);
382382
_etext = .;
383-
} >RAM :sram0_phdr
383+
} >RAMABLE_REGION
384384
__text_region_end = .;
385385

386386
.rodata : HDR_MMU_PAGE_ALIGN
@@ -394,7 +394,16 @@ SECTIONS
394394
. = ALIGN(4);
395395
#include <snippets-rodata.ld>
396396
#include <zephyr/linker/kobject-rom.ld>
397+
} >RAMABLE_REGION
398+
399+
#include <zephyr/linker/common-rom.ld>
400+
401+
#include <zephyr/linker/thread-local-storage.ld>
397402

403+
#include <zephyr/linker/cplusplus-rom.ld>
404+
405+
.rodata_end : ALIGN(4)
406+
{
398407
. = ALIGN(4); /* this table MUST be 4-byte aligned */
399408
_bss_table_start = ABSOLUTE(.);
400409
LONG(_bss_start)
@@ -404,19 +413,26 @@ SECTIONS
404413
MMU_PAGE_ALIGN
405414

406415
__rodata_region_end = ABSOLUTE(.);
407-
} >RAM :sram0_phdr
416+
} >RAMABLE_REGION
408417

409-
#include <zephyr/linker/common-rom.ld>
418+
#ifdef CONFIG_USERSPACE
419+
#define SMEM_PARTITION_ALIGN(size) MMU_PAGE_ALIGN
420+
#define APP_SHARED_ALIGN MMU_PAGE_ALIGN
410421

411-
#include <zephyr/linker/thread-local-storage.ld>
422+
#include <app_smem.ld>
412423

413-
#include <zephyr/linker/cplusplus-rom.ld>
414-
415-
#include <snippets-sections.ld>
424+
_image_ram_start = _app_smem_start;
425+
_app_smem_size = _app_smem_end - _app_smem_start;
426+
_app_smem_num_words = _app_smem_size >> 2;
427+
_app_smem_rom_start = LOADADDR(_APP_SMEM_SECTION_NAME);
428+
_app_smem_num_words = _app_smem_size >> 2;
429+
#endif /* CONFIG_USERSPACE */
416430

417431
.data : HDR_MMU_PAGE_ALIGN
418432
{
433+
#ifndef CONFIG_USERSPACE
419434
_image_ram_start = ABSOLUTE(.);
435+
#endif
420436
__data_start = ABSOLUTE(.);
421437
*(.data)
422438
*(.data.*)
@@ -438,7 +454,9 @@ SECTIONS
438454
MMU_PAGE_ALIGN
439455

440456
__data_end = ABSOLUTE(.);
441-
} >RAM :sram0_phdr
457+
} >RAMABLE_REGION
458+
459+
#include <snippets-sections.ld>
442460

443461
#include <snippets-data-sections.ld>
444462

soc/xtensa/dc233c/mmu.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const struct xtensa_mmu_range xtensa_soc_mmu_ranges[] = {
1818
{
1919
.start = (uint32_t)XCHAL_VECBASE_RESET_VADDR,
2020
.end = (uint32_t)CONFIG_SRAM_OFFSET,
21-
.attrs = Z_XTENSA_MMU_X | Z_XTENSA_MMU_CACHED_WB,
21+
.attrs = Z_XTENSA_MMU_X | Z_XTENSA_MMU_CACHED_WB | Z_XTENSA_MMU_MAP_SHARED,
2222
.name = "vecbase",
2323
},
2424
{
@@ -52,15 +52,16 @@ void arch_xtensa_mmu_post_init(bool is_core0)
5252
/* Map VECBASE permanently in instr TLB way 4 so we will always have
5353
* access to exception handlers. Each way 4 TLB covers 1MB (unless
5454
* ITLBCFG has been changed before this, which should not have
55-
* happened).
55+
* happened). Also this needs to be mapped as SHARED so both kernel
56+
* and userspace can execute code here => same as .text.
5657
*
5758
* Note that we don't want to map the first 1MB in data TLB as
5859
* we want to keep page 0 (0x00000000) unmapped to catch null pointer
5960
* de-references.
6061
*/
6162
vecbase = ROUND_DOWN(vecbase, MB(1));
6263
xtensa_itlb_entry_write_sync(
63-
Z_XTENSA_PTE(vecbase, Z_XTENSA_KERNEL_RING,
64+
Z_XTENSA_PTE(vecbase, Z_XTENSA_SHARED_RING,
6465
Z_XTENSA_MMU_X | Z_XTENSA_MMU_CACHED_WT),
6566
Z_XTENSA_TLB_ENTRY((uint32_t)vecbase, 4));
6667
}

0 commit comments

Comments
 (0)