From 2da530b613d91c6c81c6863f6b4e6070c1805764 Mon Sep 17 00:00:00 2001 From: Shell Date: Tue, 11 Jun 2024 14:34:25 +0800 Subject: [PATCH] [libcpu] arm64: implement cpuid get by assembly --- libcpu/aarch64/common/context_gcc.S | 15 ++++++++++++--- libcpu/aarch64/common/cpu.c | 18 ------------------ 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/libcpu/aarch64/common/context_gcc.S b/libcpu/aarch64/common/context_gcc.S index 9399467935b..0233806d96b 100644 --- a/libcpu/aarch64/common/context_gcc.S +++ b/libcpu/aarch64/common/context_gcc.S @@ -62,12 +62,21 @@ rt_hw_cpu_id_set: /* int rt_hw_cpu_id(void) */ -.weak rt_hw_cpu_id .type rt_hw_cpu_id, @function rt_hw_cpu_id: +#ifdef ARCH_USING_GENERIC_CPUID + .globl rt_hw_cpu_id +#else /* !ARCH_USING_GENERIC_CPUID */ + .weak rt_hw_cpu_id +#endif /* ARCH_USING_GENERIC_CPUID */ + #if RT_CPUS_NR > 1 - mrs x0, tpidr_el1 -#else + #ifdef ARCH_USING_GENERIC_CPUID + mrs x0, tpidrro_el0 + #else /* !ARCH_USING_GENERIC_CPUID */ + mrs x0, tpidr_el1 + #endif /* ARCH_USING_GENERIC_CPUID */ +#else /* RT_CPUS_NR == 1 */ mov x0, xzr #endif ret diff --git a/libcpu/aarch64/common/cpu.c b/libcpu/aarch64/common/cpu.c index b9fedefdd30..72ccccac244 100644 --- a/libcpu/aarch64/common/cpu.c +++ b/libcpu/aarch64/common/cpu.c @@ -231,24 +231,6 @@ int rt_hw_cpu_boot_secondary(int num_cpus, rt_uint64_t *cpu_hw_ids, struct cpu_o #endif /*RT_USING_SMP*/ -/** - * Generic hw-cpu-id - */ -#ifdef ARCH_USING_GENERIC_CPUID - -int rt_hw_cpu_id(void) -{ -#if RT_CPUS_NR > 1 - long cpuid; - __asm__ volatile("mrs %0, tpidrro_el0":"=r"(cpuid)); - return cpuid; -#else - return 0; -#endif /* RT_CPUS_NR > 1 */ -} - -#endif /* ARCH_USING_GENERIC_CPUID */ - /** * @addtogroup ARM CPU */