qinwei2004 commented on code in PR #6478: URL: https://github.com/apache/incubator-nuttx/pull/6478#discussion_r902414586
########## arch/arm64/src/common/arm64_backtrace.c: ########## @@ -0,0 +1,184 @@ +/**************************************************************************** + * arch/arm64/src/common/arm64_backtrace.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 <nuttx/config.h> + +#include <nuttx/arch.h> + +#include "sched/sched.h" +#include "arm64_internal.h" +#include "arm64_arch.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#if defined(CONFIG_FRAME_POINTER) + +/**************************************************************************** + * Name: backtrace + * + * Description: + * backtrace() parsing the return address through frame pointer + * + ****************************************************************************/ + +#ifdef CONFIG_MM_KASAN +__attribute__((no_sanitize_address)) +#endif +static int backtrace(uintptr_t *base, uintptr_t *limit, + uintptr_t *fp, uintptr_t *pc, + void **buffer, int size, int *skip) +{ + int i = 0; + + if (pc) + { + i++; + if (*skip-- <= 0) + { + *buffer++ = pc; + } + } + + for (; i < size; fp = (uintptr_t *)*(fp - 1), i++) + { + if (fp > limit || fp < base || *fp == 0) + { + break; + } + + if (*skip-- <= 0) + { + *buffer++ = (void *)*fp; + } + } + + return i; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: up_backtrace + * + * Description: + * up_backtrace() returns a backtrace for the TCB, in the array + * pointed to by buffer. A backtrace is the series of currently active + * function calls for the program. Each item in the array pointed to by + * buffer is of type void *, and is the return address from the + * corresponding stack frame. The size argument specifies the maximum + * number of addresses that can be stored in buffer. If the backtrace is + * larger than size, then the addresses corresponding to the size most + * recent function calls are returned; to obtain the complete backtrace, + * make sure that buffer and size are large enough. + * + * Input Parameters: + * tcb - Address of the task's TCB + * buffer - Return address from the corresponding stack frame + * size - Maximum number of addresses that can be stored in buffer + * skip - number of addresses to be skipped + * + * Returned Value: + * up_backtrace() returns the number of addresses returned in buffer + * + ****************************************************************************/ + +#ifdef CONFIG_MM_KASAN +__attribute__((no_sanitize_address)) +#endif +int up_backtrace(struct tcb_s *tcb, + void **buffer, int size, int skip) +{ + struct tcb_s *rtcb = (struct tcb_s *)arch_get_current_tcb(); + struct regs_context * p_regs; + +#if CONFIG_ARCH_INTERRUPTSTACK > 7 + void *istacklimit; +#endif + irqstate_t flags; + int ret; + + if (size <= 0 || !buffer) + { + return 0; + } + + if (tcb == NULL || tcb == rtcb) + { + if (up_interrupt_context()) + { +#if CONFIG_ARCH_INTERRUPTSTACK > 7 +# ifdef CONFIG_SMP + istacklimit = (void *)arm64_intstack_top(); +# else + istacklimit = g_interrupt_stack + INTSTACK_SIZE; +# endif /* CONFIG_SMP */ + ret = backtrace(istacklimit - (CONFIG_ARCH_INTERRUPTSTACK & ~15), + istacklimit, + (void *)__builtin_frame_address(0), + NULL, buffer, size, &skip); +#else + ret = backtrace(rtcb->stack_base_ptr, + rtcb->stack_base_ptr + rtcb->adj_stack_size, + (void *)__builtin_frame_address(0), + NULL, buffer, size, &skip); +#endif /* CONFIG_ARCH_INTERRUPTSTACK > 7 */ + if (ret < size) + { + p_regs = (struct regs_context *)CURRENT_REGS; + ret += backtrace(rtcb->stack_base_ptr, + rtcb->stack_base_ptr + rtcb->adj_stack_size, + (void *)p_regs->regs[REG_X29], + (void *)p_regs->elr, + &buffer[ret], size - ret, &skip); + } + } + else + { + ret = backtrace(rtcb->stack_base_ptr, + rtcb->stack_base_ptr + rtcb->adj_stack_size, + (void *)__builtin_frame_address(0), + NULL, buffer, size, &skip); + } + } + else + { + flags = enter_critical_section(); + p_regs = (struct regs_context *)CURRENT_REGS; + + ret = backtrace(tcb->stack_base_ptr, + tcb->stack_base_ptr + tcb->adj_stack_size, + (void *)p_regs->regs[REG_X29], + (void *)p_regs->elr, + buffer, size, &skip); + + leave_critical_section(flags); + } + + return ret; +} +#endif /* CONFIG_FRAME_POINTER && !CONFIG_ARM_THUMB */ Review Comment: fix at [48faa78](https://github.com/apache/incubator-nuttx/pull/6478/commits/48faa78d9898c978116903e3d2860b1f2593196a) please check ########## arch/arm64/src/common/arm64_cache.c: ########## @@ -0,0 +1,449 @@ +/**************************************************************************** + * arch/arm64/src/common/arm64_cache.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 <nuttx/config.h> +#include <nuttx/cache.h> +#include <nuttx/irq.h> + +#include <nuttx/arch.h> +#include <arch/irq.h> +#include <arch/chip/chip.h> +#include <nuttx/spinlock.h> + +#include "arm64_arch.h" +#include "arm64_internal.h" +#include "arm64_mmu.h" + +/**************************************************************************** + * Pre-processor Macros + ****************************************************************************/ + +/* Common operations for the caches + * + * WB means write-back and intends to transfer dirty cache lines to memory in + * a copy-back cache policy. May be a no-op in write-back cache policy. + * + * INVD means invalidate and will mark cache lines as not valid. A future + * access to the associated address is guaranteed to generate a memory fetch. + * + * armv8 data cahce instruction: + * + * DC CIVAC (WB+INVD): + * Data or unified Cache line Clean and Invalidate by VA to PoC + * Clean and Invalidate data cache by address to Point of Coherency. + * + * DC CVAC (WB): + * Data or unified Cache line Clean by VA to PoC + * Clean data cache by address to Point of Coherency. + * + * DC IVAC (INVD): + * Data or unified Cache line Invalidate by VA to PoC + * Invalidate data cache by address to Point of Coherency + */ + +#define CACHE_OP_WB BIT(0) +#define CACHE_OP_INVD BIT(1) +#define CACHE_OP_WB_INVD (CACHE_OP_WB | CACHE_OP_INVD) + +#define LINE_MASK(line) (line - 1) Review Comment: fix at [48faa78](https://github.com/apache/incubator-nuttx/pull/6478/commits/48faa78d9898c978116903e3d2860b1f2593196a) please check -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org