This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0d757d0134d392e846e6ee0a060e22c7b8958911 Author: chenxiaoyi <[email protected]> AuthorDate: Tue Apr 22 17:52:05 2025 +0800 libc/machine/xtensa: add mcount implementation for gprof Add the implementation of _mcount() to meet the requirements of gprof. Signed-off-by: chenxiaoyi <[email protected]> --- libs/libc/machine/xtensa/CMakeLists.txt | 4 ++ libs/libc/machine/xtensa/Make.defs | 4 ++ libs/libc/machine/xtensa/arch_mcount.c | 68 +++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) diff --git a/libs/libc/machine/xtensa/CMakeLists.txt b/libs/libc/machine/xtensa/CMakeLists.txt index 1364d55652f..8d3dc9dfda6 100644 --- a/libs/libc/machine/xtensa/CMakeLists.txt +++ b/libs/libc/machine/xtensa/CMakeLists.txt @@ -55,4 +55,8 @@ if(CONFIG_XTENSA_STRCMP) list(APPEND CSRCS arch_strcmp.S) endif() +if(NOT CONFIG_PROFILE_NONE) + list(APPEND CSRCS arch_mcount.c) +endif() + target_sources(c PRIVATE ${CSRCS}) diff --git a/libs/libc/machine/xtensa/Make.defs b/libs/libc/machine/xtensa/Make.defs index 3f38e09fe01..a1c1348ff39 100644 --- a/libs/libc/machine/xtensa/Make.defs +++ b/libs/libc/machine/xtensa/Make.defs @@ -56,6 +56,10 @@ ifeq ($(CONFIG_XTENSA_STRCMP),y) ASRCS += arch_strcmp.S endif +ifeq ($(CONFIG_PROFILE_NONE),) +CSRCS += arch_mcount.c +endif + DEPPATH += --dep-path machine/xtensa VPATH += :machine/xtensa diff --git a/libs/libc/machine/xtensa/arch_mcount.c b/libs/libc/machine/xtensa/arch_mcount.c new file mode 100644 index 00000000000..f4dda9b0cc2 --- /dev/null +++ b/libs/libc/machine/xtensa/arch_mcount.c @@ -0,0 +1,68 @@ +/**************************************************************************** + * libs/libc/machine/xtensa/arch_mcount.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <sys/gmon.h> + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: _mcount + * + * Description: + * This is the Xtensa mcount function. It is called by the profiling logic + * to record the call. + * + * Input Parameters: + * frompc - The address of the calling instruction + * + * Returned Value: + * None + * + ****************************************************************************/ + +noinstrument_function +void _mcount(uintptr_t from_pc) +{ +#ifndef __XTENSA_CALL0_ABI__ + uint32_t high_bit_mask = (0x03 << 30); + uint32_t low_bit_mask = ~high_bit_mask; + uint32_t pc_high_bits = ((uint32_t)_mcount) & high_bit_mask; +#endif + uintptr_t self_pc; + + __asm__ __volatile__ + ( + "mov %0, a0\n" + : "=r" (self_pc) + ); + +#ifndef __XTENSA_CALL0_ABI__ + self_pc = pc_high_bits | (self_pc & low_bit_mask); + from_pc = pc_high_bits | (from_pc & low_bit_mask); +#endif + + mcount_internal(from_pc, self_pc); +}
