From 36acd4fce5adbbd6e98f0b0fba52f7b01bb861b4 Mon Sep 17 00:00:00 2001 From: zhangyuan21 Date: Thu, 11 May 2023 22:57:26 +0800 Subject: [PATCH] arch/arm64: .bss initialization using assembly language The compiler will optimize boot_early_memset to memset, but memset in libc cannot be used before MMU is enabled. Therefore, assembly language is used to implement the initialization of bss to avoid this problem. Signed-off-by: zhangyuan21 --- arch/arm64/src/common/arm64_boot.c | 16 ------------- arch/arm64/src/common/arm64_head.S | 37 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/arch/arm64/src/common/arm64_boot.c b/arch/arm64/src/common/arm64_boot.c index a46fba6390..46f1a7017d 100644 --- a/arch/arm64/src/common/arm64_boot.c +++ b/arch/arm64/src/common/arm64_boot.c @@ -174,24 +174,8 @@ void arm64_boot_el1_init(void) ARM64_ISB(); } -/* These simple memset alternatives are necessary - * as the function at libc is depend on the MMU - * to be active. - */ - -static void boot_early_memset(void *dst, int c, size_t n) -{ - uint8_t *d = dst; - - while (n--) - { - *d++ = c; - } -} - void arm64_boot_primary_c_routine(void) { - boot_early_memset(_START_BSS, 0, _END_BSS - _START_BSS); arm64_chip_boot(); up_perf_init(NULL); nx_start(); diff --git a/arch/arm64/src/common/arm64_head.S b/arch/arm64/src/common/arm64_head.S index 357fefa410..f90c0d953f 100644 --- a/arch/arm64/src/common/arm64_head.S +++ b/arch/arm64/src/common/arm64_head.S @@ -212,6 +212,8 @@ primary_core: bl arm64_earlyprintinit #endif + bl arm64_data_initialize + PRINT(primary_boot, "- Ready to Boot Primary CPU\r\n") cpu_boot: @@ -351,3 +353,38 @@ boot_stage_puts: .type boot_low_puts, %function; #endif /* !CONFIG_ARCH_EARLY_PRINT */ + +/*************************************************************************** + * Name: arm64_data_initialize + ***************************************************************************/ + + .type arm64_data_initialize, #function + +arm64_data_initialize: + + /* Zero BSS */ + + adr x0, .Linitparms + ldp x1, x2, [x0], #8 + + mov x0, #0 +1: + cmp x1, x2 + bge 2f + str x0, [x1], #8 + b 1b +2: + ret + .size arm64_data_initialize, . - arm64_data_initialize + +/*************************************************************************** + * Text-section constants + ***************************************************************************/ + + .data + .align 8 + .type .Linitparms, %object +.Linitparms: + .quad _sbss + .quad _ebss + .size .Linitparms, . -.Linitparms