qinwei2004 commented on code in PR #6478: URL: https://github.com/apache/incubator-nuttx/pull/6478#discussion_r918865253
########## arch/arm64/src/common/arm64_internal.h: ########## @@ -0,0 +1,387 @@ +/**************************************************************************** + * arch/arm64/src/common/arm64_internal.h + * + * 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. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM64_SRC_COMMON_ARM64_INTERNAL_H +#define __ARCH_ARM64_SRC_COMMON_ARM64_INTERNAL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#ifndef __ASSEMBLY__ +# include <nuttx/compiler.h> +# include <nuttx/arch.h> +# include <sys/types.h> +# include <stdint.h> +#endif + +#include "arm64_arch.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Determine which (if any) console driver to use. If a console is enabled + * and no other console device is specified, then a serial console is + * assumed. + */ + +#ifndef CONFIG_DEV_CONSOLE +# undef USE_SERIALDRIVER +# undef USE_EARLYSERIALINIT +#else +# if defined(CONFIG_LWL_CONSOLE) +# undef USE_SERIALDRIVER +# undef USE_EARLYSERIALINIT +# elif defined(CONFIG_CONSOLE_SYSLOG) +# undef USE_SERIALDRIVER +# undef USE_EARLYSERIALINIT +# else +# define USE_SERIALDRIVER 1 +# define USE_EARLYSERIALINIT 1 +# endif +#endif + +/* If some other device is used as the console, then the serial driver may + * still be needed. Let's assume that if the upper half serial driver is + * built, then the lower half will also be needed. There is no need for + * the early serial initialization in this case. + */ + +#if !defined(USE_SERIALDRIVER) && defined(CONFIG_STANDARD_SERIAL) +# define USE_SERIALDRIVER 1 +#endif + +/* Check if an interrupt stack size is configured */ + +#ifndef CONFIG_ARCH_INTERRUPTSTACK +# define CONFIG_ARCH_INTERRUPTSTACK 0 +#endif + +/* If the floating point unit is present and enabled, then save the + * floating point registers as well as normal ARM registers. + */ + +#define arm64_savestate(regs) (regs = (uint64_t *)CURRENT_REGS) +#define arm64_restorestate(regs) (CURRENT_REGS = regs) + +/* This is the value used to mark the stack for subsequent stack monitoring + * logic. + */ + +#define STACK_COLOR 0xdeaddead +#define HEAP_COLOR 'h' + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ +typedef void (*up_vector_t)(void); +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifndef __ASSEMBLY__ +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/* AArch64 the stack-pointer must be 128-bit aligned */ + +#define STACK_ALIGNMENT 16 + +/* Stack alignment macros */ + +#define STACK_ALIGN_MASK (STACK_ALIGNMENT-1) +#define STACK_ALIGN_DOWN(a) ((a) & ~STACK_ALIGN_MASK) +#define STACK_ALIGN_UP(a) (((a) + STACK_ALIGN_MASK) & ~STACK_ALIGN_MASK) + +struct __attribute__((__packed__)) thread_stack_element +{ + char data; +}; + +#define STACK_PTR_ALIGN(ptr) ROUND_DOWN((ptr), STACK_ALIGNMENT) + +#define THREAD_STACK_DEFINE(sym, size) \ + struct thread_stack_element locate_data(".initstack") \ + aligned_data(STACK_ALIGNMENT) sym[size] + +#define THREAD_STACK_ARRAY_DEFINE(sym, n, size) \ + struct thread_stack_element locate_data(".initstack") \ + aligned_data(STACK_ALIGNMENT) sym[n][size] + +#define THREAD_STACK_DEFINE_EXTERN(sym, size) \ + EXTERN struct thread_stack_element locate_data(".initstack") \ + aligned_data(STACK_ALIGNMENT) sym[size] + +#define THREAD_STACK_ARRAY_DEFINE_EXTERN(sym, n, size) \ + EXTERN struct thread_stack_element locate_data(".initstack") \ + aligned_data(STACK_ALIGNMENT) sym[n][size] + +#define STACK_PTR_TO_FRAME(type, ptr) \ Review Comment: Oh, I check container_of at nuttx.h, define is #define container_of(ptr, type, member) \ ((type *)((uintptr_t)(ptr) - offsetof(type, member))) but for STACK_PTR_TO_FRAME, it's #define STACK_PTR_TO_FRAME(type, ptr) \ (type *)((ptr) - **sizeof(type)**) it's deference define -- 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