This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 46860f54a92aca136c7a152455416fe4137f14de Author: hujun5 <[email protected]> AuthorDate: Mon Nov 23 11:03:39 2026 +0800 arm: Restore ARMv5 MMU support The consolidated MMU header uses ARMv7 descriptor encodings and only accepts 4 KiB pages. ARM926EJ-S legacy paging requires ARMv5 fine page tables and 1 KiB tiny pages, so LPC31 paging configurations no longer build correctly. Select an ARMv5-specific MMU definition set for classic ARM cores, restore the fine and coarse descriptor semantics used by legacy paging, and provide the CP15 and SCTLR definitions needed by the classic ARM exception and startup code. Signed-off-by: hujun5 <[email protected]> --- arch/arm/src/arm/arm_vectors.S | 1 + arch/arm/src/arm/pg_macros.h | 8 +- arch/arm/src/arm_a_r/mmu.h | 11 +++ arch/arm/src/arm_a_r/mmu_v5.h | 185 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 201 insertions(+), 4 deletions(-) diff --git a/arch/arm/src/arm/arm_vectors.S b/arch/arm/src/arm/arm_vectors.S index d219a7b6227..fe6bd5b227b 100644 --- a/arch/arm/src/arm/arm_vectors.S +++ b/arch/arm/src/arm/arm_vectors.S @@ -28,6 +28,7 @@ #include <nuttx/irq.h> #include "arm.h" +#include "mmu.h" .file "arm_vectors.S" diff --git a/arch/arm/src/arm/pg_macros.h b/arch/arm/src/arm/pg_macros.h index 120de86b2fa..b99076018f0 100644 --- a/arch/arm/src/arm/pg_macros.h +++ b/arch/arm/src/arm/pg_macros.h @@ -99,12 +99,12 @@ /* MMU Flags for each memory region */ -# define MMU_L1_TEXTFLAGS (PMD_TYPE_PXN|PMD_BIT4) +# define MMU_L1_TEXTFLAGS (PMD_TYPE_FINE|PMD_BIT4) # define MMU_L2_TEXTFLAGS (PTE_TYPE_TINY|PTE_EXT_AP_UNO_SRO|PTE_C) -# define MMU_L1_DATAFLAGS (PMD_TYPE_PXN|PMD_BIT4) +# define MMU_L1_DATAFLAGS (PMD_TYPE_FINE|PMD_BIT4) # define MMU_L2_DATAFLAGS (PTE_TYPE_TINY|PTE_EXT_AP_UNO_SRW|PTE_C|PTE_B) # define MMU_L2_ALLOCFLAGS (PTE_TYPE_TINY|PTE_EXT_AP_UNO_SRW) -# define MMU_L1_PGTABFLAGS (PMD_TYPE_PXN|PMD_BIT4) +# define MMU_L1_PGTABFLAGS (PMD_TYPE_FINE|PMD_BIT4) # define MMU_L2_PGTABFLAGS (PTE_TYPE_TINY|PTE_EXT_AP_UNO_SRW) # define MMU_L2_VECTRWFLAGS (PTE_TYPE_TINY|PTE_EXT_AP_UNO_SRW) @@ -123,7 +123,7 @@ /* Mask to get the page table physical address from an L1 entry */ -# define PG_L1_PADDRMASK PMD_SECT_PADDR_MASK +# define PG_L1_PADDRMASK PMD_COARSE_TEX_MASK /* MMU Flags for each memory region. */ diff --git a/arch/arm/src/arm_a_r/mmu.h b/arch/arm/src/arm_a_r/mmu.h index 44418b4fdf9..9cdd8ea9030 100644 --- a/arch/arm/src/arm_a_r/mmu.h +++ b/arch/arm/src/arm_a_r/mmu.h @@ -36,6 +36,15 @@ ****************************************************************************/ #include <nuttx/config.h> + +#if defined(CONFIG_ARCH_ARM7TDMI) || defined(CONFIG_ARCH_ARM920T) || \ + defined(CONFIG_ARCH_ARM926EJS) || defined(CONFIG_ARCH_ARM1136J) || \ + defined(CONFIG_ARCH_ARM1156T2) || defined(CONFIG_ARCH_ARM1176JZ) + +# include "mmu_v5.h" + +#else + #include <sys/types.h> #include <arch/barriers.h> #include "sctlr.h" @@ -1773,4 +1782,6 @@ void mmu_invalidate_region(uintptr_t vstart, size_t size); #endif #endif /* __ASSEMBLY__ */ +#endif /* Classic ARM or ARMv7-A/R MMU */ + #endif /* __ARCH_ARM_SRC_ARM_A_R_MMU_H */ diff --git a/arch/arm/src/arm_a_r/mmu_v5.h b/arch/arm/src/arm_a_r/mmu_v5.h new file mode 100644 index 00000000000..2a0b2ff44e0 --- /dev/null +++ b/arch/arm/src/arm_a_r/mmu_v5.h @@ -0,0 +1,185 @@ +/**************************************************************************** + * arch/arm/src/arm_a_r/mmu_v5.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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_ARM_SRC_ARM_A_R_MMU_V5_H +#define __ARCH_ARM_SRC_ARM_A_R_MMU_V5_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#ifndef __ASSEMBLY__ +# include <stdint.h> +#endif + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Fault status register */ + +#define FSR_MASK 15 +#define FSR_FAULT(fsr) ((fsr) & FSR_MASK) +#define FSR_FAULT_DEBUG 2 +#define FSR_FAULT_TRANSLATION_L1 5 +#define FSR_FAULT_TRANSLATION_L2 7 + +#ifdef __ASSEMBLY__ +# define CP15_IFSR(r) p15, 0, r, c5, c0, 1 +# define CP15_IFAR(r) p15, 0, r, c6, c0, 2 +#endif + +/* System control register */ + +#define SCTLR_M (1 << 0) +#define SCTLR_A (1 << 1) +#define SCTLR_C (1 << 2) +#define SCTLR_W (1 << 3) +#define SCTLR_P (1 << 4) +#define SCTLR_CCP15BEN (1 << 5) +#define SCTLR_S (1 << 8) +#define SCTLR_R (1 << 9) +#define SCTLR_SW (1 << 10) +#define SCTLR_Z (1 << 11) +#define SCTLR_I (1 << 12) +#define SCTLR_V (1 << 13) +#define SCTLR_RR (1 << 14) + +/* Level 1 descriptors */ + +#define PMD_TYPE_MASK 0x00000003 +#define PMD_TYPE_FAULT 0x00000000 +#define PMD_TYPE_COARSE 0x00000001 +#define PMD_TYPE_SECT 0x00000002 +#define PMD_TYPE_FINE 0x00000003 +#define PMD_BIT4 0x00000010 +#define PMD_DOMAIN_MASK 0x000001e0 +#define PMD_DOMAIN(x) ((x) << 5) +#define PMD_PROTECTION 0x00000200 + +#define PMD_SECT_BUFFERABLE 0x00000004 +#define PMD_SECT_CACHEABLE 0x00000008 +#define PMD_SECT_AP_MASK 0x00000c00 +#define PMD_SECT_AP_WRITE 0x00000400 +#define PMD_SECT_AP_READ 0x00000800 +#define PMD_SECT_TEX_MASK 0xfff00000 +#define PMD_SECT_PADDR_MASK PMD_SECT_TEX_MASK +#define PMD_SECT_APX 0x00008000 +#define PMD_SECT_S 0x00010000 +#define PMD_SECT_NG 0x00020000 + +#define PMD_SECT_UNCACHED 0 +#define PMD_SECT_BUFFERED PMD_SECT_BUFFERABLE +#define PMD_SECT_WT PMD_SECT_CACHEABLE +#define PMD_SECT_WB (PMD_SECT_CACHEABLE | PMD_SECT_BUFFERABLE) + +#define PMD_COARSE_TEX_MASK 0xfffffc00 +#define PMD_FINE_TEX_MASK 0xfffff000 + +/* Level 2 descriptors */ + +#define PTE_TYPE_MASK (3 << 0) +#define PTE_TYPE_FAULT (0 << 0) +#define PTE_TYPE_LARGE (1 << 0) +#define PTE_TYPE_SMALL (2 << 0) +#define PTE_TYPE_TINY (3 << 0) +#define PTE_B (1 << 2) +#define PTE_C (1 << 3) + +#define PTE_LARGE_AP_MASK (0xff << 4) +#define PTE_LARGE_AP_UNO_SRO (0x00 << 4) +#define PTE_LARGE_AP_UNO_SRW (0x55 << 4) +#define PTE_LARGE_AP_URO_SRW (0xaa << 4) +#define PTE_LARGE_AP_URW_SRW (0xff << 4) +#define PTE_LARGE_TEX_MASK 0xffff0000 + +#define PTE_SMALL_AP_MASK (0xff << 4) +#define PTE_SMALL_AP_UNO_SRO (0x00 << 4) +#define PTE_SMALL_AP_UNO_SRW (0x55 << 4) +#define PTE_SMALL_AP_URO_SRW (0xaa << 4) +#define PTE_SMALL_AP_URW_SRW (0xff << 4) +#define PTE_SMALL_TEX_MASK 0xfffff000 +#define PTE_SMALL_NPAGES 256 + +#define PTE_EXT_AP_MASK (3 << 4) +#define PTE_EXT_AP_UNO_SRO (0 << 4) +#define PTE_EXT_AP_UNO_SRW (1 << 4) +#define PTE_EXT_AP_URO_SRW (2 << 4) +#define PTE_EXT_AP_URW_SRW (3 << 4) +#define PTE_TINY_TEX_MASK 0xfffffc00 +#define PTE_TINY_NPAGES 1024 + +/* Default mappings */ + +#define MMU_ROMFLAGS \ + (PMD_TYPE_SECT | PMD_BIT4 | PMD_SECT_AP_READ) +#define MMU_MEMFLAGS \ + (PMD_TYPE_SECT | PMD_SECT_WB | PMD_BIT4 | PMD_SECT_AP_WRITE | \ + PMD_SECT_AP_READ) +#define MMU_IOFLAGS \ + (PMD_TYPE_SECT | PMD_BIT4 | PMD_SECT_AP_WRITE | PMD_SECT_AP_READ) + +#define MMU_L1_VECTORFLAGS (PMD_TYPE_COARSE | PMD_BIT4) +#define MMU_L2_VECTORFLAGS (PTE_TYPE_SMALL | PTE_SMALL_AP_UNO_SRW) + +#define SECTION_SHIFT 20 +#define SECTION_SIZE (1 << SECTION_SHIFT) +#define SECTION_MASK (SECTION_SIZE - 1) +#define PGTABLE_SIZE 0x00004000 + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct section_mapping_s +{ + uintptr_t physbase; + uintptr_t virtbase; + uint32_t mmuflags; + uint32_t nsections; +}; + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +static inline void cp15_invalidate_tlb_bymva(uint32_t mva) +{ + mva &= PTE_TINY_TEX_MASK; + __asm__ __volatile__ + ( + "mcr p15, 0, %0, c8, c7, 1" + : + : "r" (mva) + : "memory" + ); +} + + #define tlb_inst_invalidate_single(mva) cp15_invalidate_tlb_bymva(mva) + +#endif /* __ASSEMBLY__ */ + +#endif /* __ARCH_ARM_SRC_ARM_A_R_MMU_V5_H */ \ No newline at end of file
