qinwei2004 commented on code in PR #6478: URL: https://github.com/apache/incubator-nuttx/pull/6478#discussion_r916802696
########## 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) \ + (type *)((ptr) - sizeof(type)) + +#define INTSTACK_SIZE (CONFIG_ARCH_INTERRUPTSTACK & ~STACK_ALIGN_MASK) + +#ifdef CONFIG_SMP + +/* The size of interrupt and idle stack. This is the configured + * value aligned the 8-bytes as required by the ARM EABI. + */ + +#define SMP_STACK_SIZE STACK_ALIGN_UP(CONFIG_IDLETHREAD_STACKSIZE) + +THREAD_STACK_ARRAY_DEFINE_EXTERN(g_cpu_idlestackalloc, CONFIG_SMP_NCPUS, + SMP_STACK_SIZE); +THREAD_STACK_ARRAY_DEFINE_EXTERN(g_interrupt_stacks, CONFIG_SMP_NCPUS, + INTSTACK_SIZE); +uintptr_t arm64_intstack_alloc(void); +uintptr_t arm64_intstack_top(void); +#else +/* idle thread stack for primary core */ + +THREAD_STACK_DEFINE_EXTERN(g_idle_stack, CONFIG_IDLETHREAD_STACKSIZE); +THREAD_STACK_DEFINE_EXTERN(g_interrupt_stack, INTSTACK_SIZE); +#endif + +/* This is the beginning of heap as provided from arm64_head.S. + * This is the first address in DRAM after the loaded + * program + bss + idle stack. The end of the heap is + * CONFIG_RAM_END + */ + +/* Address of the saved user stack pointer */ + +#if CONFIG_ARCH_INTERRUPTSTACK > 3 +EXTERN uint64_t g_intstackalloc; /* Allocated stack base */ +EXTERN uint64_t g_intstacktop; /* Initial top of interrupt stack */ +#else +# error CONFIG_ARCH_INTERRUPTSTACK must be defined (4096 at least) at arm64 +#endif + +/* These 'addresses' of these values are setup by the linker script. They + * are not actual uint64_t storage locations! They are only used + * meaningfully in the following way: + * + * - The linker script defines, for example, the symbol_sdata. + * - The declaration extern uint64_t _sdata; makes C happy. C will believe + * that the value _sdata is the address of a uint64_t variable _data + * (it is not!). + * - We can recover the linker value then by simply taking the address of + * of _data. like: uint64_t *pdata = &_sdata; + * + * Memory layout for Nuttx at arm64 for FLAT Build + * + * +-------------------------+ <- RAM BASE + * | | + * |<<<<<<<<<<<<<<<<<<<<<<<<<| <- LOAD_BASE + * | text(code) section | + * | vector table | + * +-------------------------+-- page align(4096) + * | rodata section | + * +-------------------------+-- page align(4096) + * | data/bss section | + * +-------------------------+-- page align(4096) + * | initstack section | + * +-------------------------+-- page align(4096) + * | heap alloc area | + * | | + * | | + * | | + * +-------------------------+ + * + * Note: + * 1. initstack is for idle_thread and interrupt stack, + * it has dedicated stack for IRQ handler in arm64 + * 2. Every section with different memory attribute, + * please check mmu_nxrt_regions at arm64_mmu.c + * + * please check dramboot.ld at specified platform for more detail + */ + +EXTERN char _stext[]; /* Start of .text */ +EXTERN char _etext[]; /* End of .text */ +EXTERN char _sztext[]; /* Size of .text */ Review Comment: the size is used at the struct mmu_nxrt_regions of arm64_mmu.c the structure is defined as const and put it into rodata section. I want set the rodata as RO attribute to avoid illegal access to the section. it will be done when I used the MMU/MPU completely but if i use _exxxx - _sxxxx, it will trigger compile error -- 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