Commit graph zephyr/arch/arm
Author SHA1 Message Date
Andrei-Edward Popa
4b3a3f2f3f arch: arm: cortex_a_r: keep IRQs disabled during interrupt exit
The Cortex-A/R interrupt wrapper enables IRQs to support nested interrupt
handling while running the registered ISR.

Move cpsie i after the spurious IRQ check so only valid ISR calls run
with IRQs enabled, and add cpsid i after the ISR returns. This prevents
EOI and z_arm_int_exit() from running with IRQs enabled.

Signed-off-by: Andrei-Edward Popa <andrei.popa105@yahoo.com>
2026-07-15 14:50:00 -05:00
Sudan Landge
5f5284d518 arch: arm: Report escalated non-secure SecureFaults
When Secure firmware handles a fault with a recovered Non-Secure
exception frame, keep that context through fault classification.

Use it when reporting SecureFaults so the dump makes clear that the
fault originated in Non-Secure state and escalated into Secure state.
Also include guidance for the missing or disabled Non-Secure fault
handler case, where this escalation is commonly seen.

Handle the unexpected case where an exception frame cannot be recovered
without relying on __ASSERT(). Report the failure through the fault log
and terminate through z_arm_fatal_error(), so the path remains fatal
even when assertions are disabled.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2026-07-14 16:39:49 -04:00
Sudan Landge
8678a37a4a arch: arm: Fix secure Cortex-M callee register reporting
The fault assembly wrapper saves r4-r11 after exception entry. When
EXC_RETURN says callee stacking was skipped, the processor has already
saved the interrupted Secure r4-r11 in the Secure additional context
block, so the wrapper's live r4-r11 are not the interrupted values.

Keep a pointer to the skipped Secure additional context and use it to
populate extra_info.callee when available, so fault dumps and other ESF
consumers report the interrupted Secure context.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2026-07-14 16:39:49 -04:00
Sudan Landge
4bcd74122a arch: arm: Fix secure Cortex-M ESF lookup
Secure exception entry can place an integrity signature and additional
Secure context at the top of the stack before the basic exception frame.
Detect that signature when resolving the ESF and skip the additional
context before casting the stack pointer to struct arch_esf.

When EXC_RETURN says callee stacking was skipped, treat a missing
integrity signature as an invalid frame instead of silently using the
original stack pointer as the ESF. This avoids reporting misleading
fault state when the Secure stack shape is inconsistent or corrupt.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2026-07-14 16:39:49 -04:00
Alberto Escolar Piedras
6eeba1b541 arch: arm: fix extended frame check compilation for Cortex-A/R
Fix a compilation error when CONFIG_EXTRA_EXCEPTION_INFO is enabled
on platforms that do not define EXC_RETURN_STACK_FRAME_TYPE_Msk
(which is only defined for Cortex-M).

For Cortex-A/R devices we just default to the same code path as before
bce6f0de63

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-07-13 16:38:32 +02:00
Mike J. Chen
bce6f0de63 arch: arm: only dump fpu registers if stack has extended frame
Check the exc_return flags to determine if the FPU registers were actually
pushed onto the stack by the exception handler and only dump them if they
are used. Otherwise the stack locations for the FPU registers are invalid
and we're just dumping garbage.

Signed-off-by: Mike J. Chen <mjchen@google.com>
2026-07-13 09:44:49 +02:00
Appana Durga Kedareswara rao
074c711f59 arch: arm: add CONFIG_ARM_MPU_SKIP_ARCH_INIT for pre-enabled MPU
Add CONFIG_ARM_MPU_SKIP_ARCH_INIT for platforms where early boot code
(for example a TCM-resident stub) enables the MPU before z_arm_mpu_init()
runs. On Versal RPU split TCM/OCM images the kernel is linked in OCM while
reset code runs from TCM; z_arm_mpu_init() must not disable and reprogram
the MPU while the CPU is executing from an OCM-only region map.

When SCTLR.M is already set, z_arm_mpu_init() records the SoC static MPU
region count in static_regions_num and returns without touching the live
region table. That preserves the boot-time map (TCM, peripherals, OCM)
and keeps vector fetches at 0x0 executable after relocation.

SoCs that need this behavior select CONFIG_ARM_MPU_SKIP_ARCH_INIT from
their Kconfig; no Versal-specific logic is added under arch/.

Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
2026-07-13 09:44:27 +02:00
Josh DeWitt
162b921c7d arch: arm: Keep CONFIG_INIT_STACKS behavior consistent
Implement CONFIG_INIT_STACKS for the main stack when
CONFIG_MULTITHREADING is disabled. This keeps the config behavior
consistent between the main stack and the interrupt stack which is
memset in reset.S.

Signed-off-by: Josh DeWitt <josh.dewitt@garmin.com>
2026-07-10 11:29:38 +01:00
Ayan Kumar Halder
23d02c824b arch: arm: zimage_header: emit end-of-image LMA in zImage header
The ARM zImage header (header.S) ends with three words that follow
the Linux self-decompressor convention:

    .long   0x016f2818          // Magic number
    .long   __rom_region_start  // start address of zImage
    .long   __end               // end address of zImage

A standard ARM zImage consumer (e.g. U-Boot bootz, or the Xen arm32
kernel loader) reads the third word and computes the on-disk file
size of the zImage as (__end - __rom_region_start). Linux establishes
the same invariant in arch/arm/boot/compressed/head.S, where the
analogous field is encoded as "_edata - start", i.e. the LMA of the
last byte of the image relative to its load address.

The current zimage_header.ld emits __end with:

    KEEP(*(.image_header))
    KEEP(*(.".image_header.*"))
    __end = .;

zimage_header.ld is plugged into the linker script via the ROM_START
hook (see arch/arm/core/CMakeLists.txt) and runs immediately after
the 48-byte .image_header section is placed. At that point '.' is
still just past the header, so __end ends up only 0x30 bytes past
__rom_region_start regardless of how large the actual image is.
Every zImage built with CONFIG_ARM_ZIMAGE_HEADER=y therefore
advertises a size of 48 bytes in its header.

For Zephyr standalone this is invisible: the FVP / debugger loads
the whole file unconditionally and never consults the header. It
breaks any consumer that honours the header, though. On a Cortex-R52
FVP under Xen dom0less, the guest fails to boot:

    (XEN) Loading zImage from 11000000 to 30000000-30000030
    (XEN) CPU0: Unexpected Trap: Undefined Instruction

Xen copied only the 48 header bytes into the DomU and the guest
branched into uninitialised memory.

Fix it by computing __end the way Linux's head.S computes _edata:
take the LMA of the very last output section. Zephyr already exposes
that anchor as .last_section, and uses

    LOADADDR(.last_section) + SIZEOF(.last_section)

elsewhere for the same purpose (e.g. _flash_used in
include/zephyr/arch/arm/cortex_a_r/scripts/linker.ld and the
equivalent cortex_m / arm64 / riscv linker scripts). The expression
is resolved lazily by the linker at final link time, so referring
to it from a ROM_START fragment that runs before .last_section is
emitted is safe.

After this change, a build of samples/hello_world for
fvp_baser_aemv8r/fvp_aemv8r_aarch32 with -DCONFIG_ARM_ZIMAGE_HEADER=y
produces a 27268-byte zephyr.bin whose header reads:

    magic = 0x016f2818
    start = 0x30000000
    end   = 0x30006a84       (end - start == file size)

`file(1)` now identifies it as "Linux kernel ARM boot executable
zImage", U-Boot bootz accepts it without complaint, and the same
binary boots cleanly as a Xen R52 dom0less DomU using Xen's standard
zImage loader path (no special payload-only handling required).

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@amd.com>
Signed-off-by: Satya Sri <satyasri.katru@amd.com>
2026-07-06 14:50:09 +01:00
Chidvilas Yerramsetti
36d2f824c3 arch: Fixed p15 register name arm switch.S
Fix the MCR instruction in switch.S to use the 'p15' coprocessor prefix
required by ARMv7-A toolchains.

Signed-off-by: Chidvilas Yerramsetti <cyerrams@qti.qualcomm.com>
2026-07-06 10:21:36 +02:00
Chidvilas Yerramsetti
f40cabb6b9 arch: arm gic ignore special interrupt ids
Added code in arm isr_wrapper.S to handle GICv3 special INTID
(1020-1023) filtering.

Signed-off-by: Chidvilas Yerramsetti <cyerrams@qti.qualcomm.com>
2026-07-06 10:21:36 +02:00
Chidvilas Yerramsetti
b54efaee98 drivers: intc_gicv3: extend NS support to ARMv7-A
Extend the GICv3 driver's Non-Secure mode handling to cover ARMv7-A
platforms via CONFIG_ARMV7_A_NS, alongside the existing
CONFIG_ARMV8_A_NS.

Signed-off-by: Chidvilas Yerramsetti <cyerrams@qti.qualcomm.com>
2026-07-06 10:21:36 +02:00
Etienne Carriere
b2fdf98b3c arch: use <> to include Zephyr headers instead of ""
Use <> operator to include a Zephyr header file instead of "" that
is intended to local header files, not header files relative to
specifically defined search paths.

This change was made running the sed shell command below:
$ sed -i -E 's/#include "zephyr\/([^"]+)\.h"/#include <zephyr\/\1.h>/g' \
    `grep -rsl "#include \"zephyr/" arch/`

Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
2026-06-30 06:49:18 -04:00
Anas Nashif
b3806c0bd6 Revert "arch: arm: mpu: declare arm_core_mpu_enable/disable in header"
This reverts commit 98dd017374.

some major breakage with this change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-25 08:13:47 -04:00
Andrej Butok
98dd017374 arch: arm: mpu: declare arm_core_mpu_enable/disable in header
The arm_core_mpu_enable() and arm_core_mpu_disable() functions were
defined in the ARM MPU driver but never declared in a header.
As a result, callers had to provide their own local `extern`
declarations to use them.

Add documented prototypes for both functions to
include/zephyr/arch/arm/mpu/arm_mpu.h and drop the redundant `extern`
declarations in arm_core_mpu.c and the userspace memory protection
test.

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
2026-06-25 06:18:19 -04:00
Nicolas Pitre
97fac4b782 kernel: mmu: remove LINKER_USE_PINNED_SECTION and __pinned_* tagging
CONFIG_LINKER_USE_PINNED_SECTION is the second half of the selective
kernel-pinning model removed in issue #108773. With the kernel image
now always resident at boot (previous commit), the __pinned_*
attribute family is a no-op: every page they would have segregated is
already pinned by z_mem_manage_init()'s whole-image loop, so the
tagging contract neither adds safety nor remains maintainable.

Drop it.

Mechanical removals:

* All ~219 in-tree uses of __pinned_text, __pinned_rodata,
  __pinned_data, __pinned_bss, __pinned_noinit, and __pinned_func
  across arch/x86, drivers/interrupt_controller, drivers/timer,
  arch/common, kernel, lib/libc, subsys/portability/posix, tests, and
  the syscall code generator (scripts/build/gen_syscalls.py).

* The assembly aliases PINNED_TEXT/RODATA/DATA/BSS/NOINIT used in
  arch/x86/core/ia32/*.S and drivers/interrupt_controller/
  intc_loapic_spurious.S become plain TEXT/RODATA/DATA/BSS/NOINIT.

* K_KERNEL_PINNED_STACK_DEFINE, K_KERNEL_PINNED_STACK_ARRAY_DEFINE,
  K_KERNEL_PINNED_STACK_ARRAY_DECLARE, K_THREAD_PINNED_STACK_DEFINE,
  and K_THREAD_PINNED_STACK_ARRAY_DEFINE are removed. The few
  in-tree callers (kernel/init.c, arch/arm/core/cortex_a_r/smp.c,
  arch/arm64/core/fatal.c, arch/rx/core/prep_c.c,
  arch/x86/core/prep_c.c, kernel/include/kernel_internal.h,
  tests/bluetooth/hci_uart_async) move to the corresponding
  non-pinned macros.

Machinery removals:

* Kconfig.zephyr drops CONFIG_LINKER_USE_PINNED_SECTION.
  qemu_x86_tiny and qemu_x86_atom_virt drop their =y overrides.

* include/zephyr/linker/section_tags.h drops the __pinned_* macro
  definitions (both arms). __isr collapses to an empty macro since
  its only purpose was to alias __pinned_func.

* include/zephyr/linker/sections.h drops PINNED_TEXT_SECTION_NAME,
  PINNED_BSS_SECTION_NAME, etc. and the bare PINNED_TEXT/RODATA/etc.
  forwarders, plus the _APP_SMEM_PINNED_SECTION_NAME constant.

* include/zephyr/linker/linker-defs.h drops the lnkr_pinned_*
  externs, the _app_smem_pinned_* externs, and the lnkr_is_pinned()
  / lnkr_is_region_pinned() inline helpers.

* include/zephyr/linker/utils.h drops the lnkr_pinned_rodata branch
  in linker_is_in_rodata().

* include/zephyr/linker/app_smem_pinned{,_aligned,_unaligned}.ld
  are deleted; cmake/linker/ld/target_configure.cmake stops
  configuring them.

* boards/qemu/x86/qemu_x86_tiny.ld and
  include/zephyr/arch/x86/ia32/linker.ld drop their pinned-section
  blocks and the now-redundant #ifndef CONFIG_LINKER_USE_PINNED_SECTION
  conditionals throughout the body. The
  LIB_KERNEL_IN_SECT / LIB_ARCH_X86_IN_SECT / LIB_ZEPHYR_IN_SECT /
  LIB_C_IN_SECT / LIB_DRIVERS_IN_SECT / LIB_SUBSYS_LOGGING_IN_SECT /
  LIB_ZEPHYR_OBJECT_FILE_IN_SECT / ZEPHYR_KERNEL_FUNCS_IN_SECT macros
  in qemu_x86_tiny.ld are deleted; they existed only to feed the
  pinned text/rodata/data/bss/noinit sections.

* kernel/mmu.c drops the mark_linker_section_pinned(lnkr_pinned_start,
  ...) call. The mark_linker_section_pinned() helper survives but is
  now gated only on CONFIG_LINKER_USE_BOOT_SECTION.

* arch/common/init.c and include/zephyr/arch/common/init.h drop
  arch_bss_zero_pinned(); arch/x86/core/ia32/crt0.S drops the call
  to it.

* arch/x86/core/userspace.c drops the eager k_mem_page_in() of the
  thread's privileged stack on user-mode entry. With the kernel
  image fully resident the stack is already mapped.

* arch/x86/gen_mmu.py drops map_region("lnkr_pinned") and the
  set_region_perms() calls for lnkr_pinned_text / lnkr_pinned_rodata.

* CMakeLists.txt drops the LINKER_USE_PINNED_SECTION block that
  generated APP_SMEM_PINNED_* variables and the
  pinned_partitions target property feeding gen_app_partitions.py.
  cmake/modules/extensions.cmake removes the PINNED_RODATA /
  PINNED_RAM_SECTIONS / PINNED_DATA_SECTIONS zephyr_linker_sources()
  location keywords and their snippet files.
  scripts/build/gen_app_partitions.py drops --pinoutput /
  --pinpartitions arguments and the pinned-output branch.
  subsys/testsuite/coverage/CMakeLists.txt drops its
  CONFIG_DEMAND_PAGING-conditional fork.

* scripts/build/gen_kobject_list.py drops the
  app_smem_pinned_start / _end fallback for kobject placement
  validation.

* tests/arch/x86/pagetables and tests/kernel/mem_protect/userspace
  drop their lnkr_pinned_text / lnkr_pinned_rodata branches.

* include/zephyr/arch/x86/ia32/arch.h folds IRQSTUBS_TEXT_SECTION
  to the unconditional ".text.irqstubs" form.

* tests/subsys/llext/src/syscalls_ext.c drops a stale comment about
  syscalls landing in .pinned_text.

Targeted retentions:

* arch/x86/core/bootargs.c keeps multiboot_cmdline and efi_bootargs
  in .noinit (was __pinned_noinit, which decayed to __noinit when
  LINKER_USE_PINNED_SECTION was unset). The multiboot and zefi loader
  paths write these buffers before Zephyr's BSS-zero step, so
  zeroing them at boot loses the cmdline.

* arch/x86/core/ia32/fatal.c keeps _df_esf and _df_stack in .noinit.
  They are scratch space written by the double-fault handler and have
  no zero-init requirement; keeping them in .noinit also preserves
  the historical post-noinit alignment that gen_mmu.py relies on
  (z_mapped_size is computed before CMake-injected iterable sections
  are appended to the linker script, so the post-noinit page padding
  is what keeps those sections within the mapped region).

* include/zephyr/arch/x86/ia32/syscall.h and
  include/zephyr/arch/x86/arch.h wrap the per-arch
  arch_syscall_invoke* / arch_is_user_context / arch_k_cycle_get_*
  implementations in @cond INTERNAL_HIDDEN. The public Doxygen
  contract lives on the prototypes in
  include/zephyr/arch/arch_interface.h; the per-arch implementations
  are internal. Without this, removing the __pinned_func attribute
  exposes the implementations to the doxygen-coverage delta check
  as 10 newly-undocumented APIs.

Documentation updates are deferred to a separate commit.

Issue: #108773

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-06-23 09:11:08 -04:00
Valerio Setti
167ed9e38a arch: arm: define TLS area also when multithreading is disabled
TLS area must be defined also when multithreading is disabled. Not doing
so whould cause access to libc variables like 'errno' to fail with a
crash.

This commit adds the TLS area for the single thread case by reserving
some space at the top of the main stack area.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2026-06-22 17:57:25 +02:00
Holt Sun
85a2085172 pm: make IRQ-locked state-set the default
Replace the opt-in locked marker with a legacy unlocked marker. With
this, SoC PM hooks use the locked IRQ contract by default, and only
legacy SoCs that still unmask interrupts from PM hooks select
PM_STATE_SET_IRQ_UNLOCKED.

Drop the old locked marker selections from already migrated NXP SoCs and
update the PM test expectation accordingly.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-06-19 11:09:51 +02:00
Fin Maaß
83b739049c arch: arm: don't overwrite D/ICACHE_LINE_SIZE from dt
if the D/ICACHE_LINE_SIZE is set in the devicetree,
don't overwrite it.

Signed-off-by: Fin Maaß <info@finmaass.de>
2026-06-18 05:35:12 -04:00
Anas Nashif
054932f167 arch: arm: cortex_m: guard CONFIG_USE_SWITCH for stack buffer
arm_m_switch_stack_buffer is only defined when CONFIG_USE_SWITCH is
enabled. With link-time optimization or certain no-optimization builds
using Clang, the symbol is referenced unconditionally and the linker
fails with:

  ld.lld: error: undefined symbol: arm_m_switch_stack_buffer

Move the reference inside a preprocessor guard so that the symbol is
only accessed when the kernel is built with CONFIG_USE_SWITCH.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-16 23:16:08 +02:00
Ibrahim Abdalkader
388d3f465f arch: arm: implement llext veneer support for baseline cores
Add support for generating llext veneers for Arm baseline cores.

The veneer is AAPCS-compliant: r0-r3, r5-r11 and LR are preserved,
r4 is saved and restored, and only r12 (ip) is clobbered as
permitted by AAPCS.

Tested on RP2040 (Cortex-M0+) loading an extension that calls
__gnu_thumb1_case_uqi.

Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
2026-06-11 14:14:09 +02:00
Peter Mitsis
3d405326a7 arch: arm: Forcibly set K_FP_REGS when FPU enabled
Enabling the FPU forces the choice between CONFIG_FP_HARDABI
and CONFIG_FP_SOFTABI. Both of these options allow the compiler
to generate FP instructions. As a result, all threads must have
the K_FP_REGS options bit set because we can not predict where
the compiler will generate those instructions.

The forced enablement is keyed off those ABI Kconfig options
and not FPU sharing nor the FPU enablement. This leaves the
option open for a future (as yet not implemented) case where
someone might want FPU support but not have the compiler generate
any FPU instructions at all.

Fixes #108793

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2026-06-10 14:53:15 -04:00
Silesh C V
ad249444a5 arch: arm: add support for Cortex-A32
Add support for the Cortex-A32 processor. The Cortex-A32 processor
is built on the ARMv8-A architecture and supports only the AArch32
execution state.

Signed-off-by: Silesh C V <silesh@alifsemi.com>
2026-06-09 08:41:24 +02:00
Silesh C V
4d5c0e7cfe arch: arm: add AARCH32_ARMV8_A monitor mode initialization
Add CONFIG_AARCH32_ARMV8_A_MONITOR_INIT to perform early Monitor mode
(EL3 AArch32) initialization at reset, modelled after z_arm64_el3_init()
in the arm64 port.

On ARMv8-A AArch32 platforms booting bare-metal without Trusted
Firmware-A, the core resets into Secure SVC mode. Certain system
registers (such as ICC_MSRE for GICv3) are only accessible from Monitor
mode. This option briefly switches to Monitor mode at reset to configure
such registers before returning to Secure SVC mode.

Currently used to configure ICC_MSRE, which enables GICv3 CPU
interface system register access at lower privilege levels (equivalent
to ICC_SRE_EL3 in the arm64 port).

ICC_MSRE_INIT reuses the existing ICC_SRE_ELx_* bit definitions from
cpu.h as the AArch32 ICC_MSRE shares the same bitfield layout as its
AArch64 counterpart ICC_SRE_EL3.

Signed-off-by: Silesh C V <silesh@alifsemi.com>
2026-06-09 08:41:24 +02:00
Silesh C V
e11025804e arch: arm: introduce ARMv8-A AArch32 support
Add a new AARCH32_ARMV8_A Kconfig symbol for ARMv8-A processors
running in AArch32 execution state, modelled after the existing
ARMv8-R AArch32 support. ARMv8-A AArch32 execution state is used
by processors such as the Cortex-A32 that implement only the AArch32
state as well as by other ARMv8-A processors that support AArch32
at specific exception levels.

A dedicated Kconfig symbol is needed (compared to simply reusing
ARMV7_A)because ARMv8-A AArch32 shares some code paths with ARMv7-A
and others with ARMv8-R AArch32. This also means that rather than
introducing a new standalone architecture port, the implementation
selectively extends the code paths used by either of these
architectures based on the architectural requirements as detailed
below.

MMU/fault handling: The implementation uses the existing short
descriptor translation table format used by ARMv7-A, sharing
the MMU programming and FSR encodings.

exception modes stack initialization: ARMv8-A AArch32 implements the
same exception modes as ARMv7-A and so reuses the ARMv7-A exception
mode stack initialization framework directly.

VBAR programming: Unlike ARMv7-A, ARMv8-A AArch32 mandates the use of
VBAR to store the vector table base address. So extend the vector
table relocation support already used by ARMv8-R AArch32. Also map
the vectors region from arch-level code rather than requiring each
SoC to provide this.

Arm generic timer support: The Generic Timer is mandatory in ARMv8-A
AArch32 and is accessed via the system register interface rather than
the memory-mapped I/O interface used by some ARMv7-A implementations.
The system-register-based timer path is therefore shared with ARMv8-R
AArch32.

interrupt masking: Reuse the CPSR based interrupt masking used by
ARMv7-A and ARMv8-R AArch32.

SVC based fatal error path: Reuse the SVC based fatal error path
shared by ARMv7-A and ARMv8-R AArch32.

Signed-off-by: Silesh C V <silesh@alifsemi.com>
2026-06-09 08:41:24 +02:00
Anas Nashif
d0b389da9e kernel: remove redundant kernel_structs.h includes
kernel.h implies kernel_structs.h via kernel_includes.h, making
explicit inclusion of kernel_structs.h unnecessary whenever kernel.h
is already included in the same translation unit.

Remove the redundant includes across arch, boards, drivers, kernel,
lib, samples, subsys, and tests trees.

in include/zephyr/kernel_structs.h:
 *  2. kernel.h shall imply kernel_structs.h, such that it shall not be
 *    necessary to include kernel_structs.h explicitly when kernel.h is
 *    included.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-02 20:24:14 +02:00
Anas Nashif
046a430890 arch: fix various typos
Fix various typos under arch/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-06-01 12:43:27 -04:00
Ibrahim Abdalkader
86c17aef06 llext: arm: Restrict llext veneer support to Mainline cores.
Restrict ARCH_HAS_LLEXT_VENEERS to ARMV7_M_ARMV8_M_MAINLINE instead
of all CPU_CORTEX_M targets, since the veneer implementation relies
on a Mainline-only Thumb-2 instruction sequence not supported on
Baseline cores.

Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
2026-05-21 17:04:24 -04:00
Holt Sun
15af50d202 pm: keep irq restore ownership in idle
Keep the original architecture IRQ key owned by idle across a

successful system PM transition.

Add architecture hooks and the PM_STATE_SET_IRQ_LOCKED migration

contract for SoCs that keep PM hooks from unmasking interrupts.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-05-21 17:02:03 -04:00
Ibrahim Abdalkader
820e4424d4 arch: arm: core: Fix references and comments.
A follow-up to PR #104994 to address late comments.

Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
2026-05-19 11:57:41 +01:00
Ibrahim Abdalkader
ec4d4ff2ea llext: Add support for generating veneers for out-of-range branches.
When an LLEXT is loaded in memory and calls kernel or libc symbols
located in flash, the target may fall outside the range of branches
on some architectures, such as Thumb-2 BL, causing relocations to
fail.

Add CONFIG_LLEXT_VENEERS which, when enabled, generates trampoline
stubs for such out-of-range relocations.

Stubs are allocated from the LLEXT heap into a new LLEXT_MEM_VENEER
region, instead of using new state variables to track the memory, to
leverage the existing llext machinery that flushes cache, frees memory
on unload, etc.

A test extension is added, compiled with -mno-long-calls to force
direct branches on Arm and exercise the veneer path against multiple
libc symbols.

Signed-off-by: Ibrahim Abdalkader <i.abdalkader@gmail.com>
2026-05-14 15:13:09 +02:00
Jamie McCrae
96d1142210 arch: Add support for dts RAM configuration
Allows using the chosen SRAM node for RAM configuration without
using Kconfig values

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2026-05-11 08:45:38 +02:00
Adam Szczygieł
f4747547d9 arch: ISR table size optimization
Allow to use a switch-case instead of an array holding ISR entries.

When most of IRQs are not used, they share the same, default entry.
It results in most of the ISR array entries being identical duplicates.

This change allows to use dynamically generated function (after first
linker pass) that uses switch-case instead of a full array.
Default entries are handled only once, in a default section.
Used IRQs have their own case sections.
This can help reduce binary size.

Signed-off-by: Adam Szczygieł <adam.szczygiel@nordicsemi.no>
2026-04-17 12:35:34 +01:00
Luca Burelli
69d479c51f llext: add support for ARM TLS LE32 relocation
This relocation is used by the ARM TLS code to access thread local
variables. It is a simple absolute relocation that adds the symbol's
offset to the value at the location. This allows the code to access
thread local variables using a fixed offset from the thread pointer,
which is determined at runtime.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2026-04-15 05:50:57 -04:00
Holt Sun
3227ac7d55 arch: arm: mpu: fix non-ARCH cache cleanup
The generic ARM MPU nocache-memory cleanup path assumes Cortex-M
SCB dcache support whenever it needs to clean and invalidate
cache state before programming MPU regions.

That is correct for integrated ARCH_CACHE systems, but not for
cache backends such as NXP LMEM on RT11xx CM4 targets. Those
targets can select CPU_HAS_DCACHE and NOCACHE_MEMORY while using
a non-ARCH cache backend, which makes the direct SCB dcache
symbols unavailable and breaks builds in z_arm_mpu_init().

Keep the direct CMSIS SCB_CleanInvalidateDCache() call under the
ARCH_CACHE guard — since we already test SCB->CCR the integrated
cache controller is known to be present — and use the generic
cache API for other cache backends.  This preserves the existing
integrated-cache behavior while allowing non-ARCH cache backends
to participate in the same MPU cleanup path.

Signed-off-by: Holt Sun <holt.sun@nxp.com>
2026-04-01 15:11:35 -05:00
Tony Han
dc90a8d6af arch: arm: core: add Kconfig and CMakeLists.txt for ARM9 support
Add or update Kconfig and CMakeLists.txt files for supporting ARM9
CPUs (mainly focus on ARM926EJ-S).

Signed-off-by: Tony Han <tony.han@microchip.com>
2026-03-23 12:27:55 -05:00
Appana Durga Kedareswara rao
bb3795b75f arch: arm: cortex_a_r: align reset entry to 32 bytes for ARMv8-R RVBAR
ARMv8-R AArch32 cores determine the CPU start address on reset from
RVBAR (Reset Vector Base Address Register), which only stores bits
[31:5] — bits [4:0] are RES0.  Any firmware or boot-loader that
programs RVBAR from the ELF entry point will silently truncate
a non-aligned address to a 32-byte boundary, causing the CPU to
begin executing at the wrong location.

Whether __start lands on a 32-byte boundary depends on the size of
code sections placed before it, which changes with Kconfig options.
This makes the failure non-deterministic: a build may work today and
break after enabling an unrelated feature like logging.

Force 32-byte alignment on z_arm_reset/__start for ARMv8-R so the
entry point survives RVBAR truncation on any SoC.

Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
2026-03-13 16:34:05 +01:00
Jisheng Zhang
f0df349808 arch: arm: implement EHABI walk_stackframe
Implement walk_stackframe() according to EHABI(Exception Handling ABI) [1]
Then implement arch_stack_walk() and z_arm_unwind_stack() based on
walk_stackframe. After that, hook the z_arm_unwind_stack() to
z_arm_fatal_error() so that we can unwind the stack during fatal error.

Tested with tests/arch/common/stack_unwind and enabling SYMTAB and
EXTRA_EXCEPTION_INFO:

*** Booting Zephyr OS build v4.3.0-3078-g23892b038f6a ***
Hello World! xxx
1: func1
2: func2
3: func1
4: func2
5: func1
6: func2
E: r0/a1:  0x00000003  r1/a2:  0x300000e8  r2/a3:  0x300000e8
E: r3/a4:  0x00000003 r12/ip:  0x00000000 r14/lr:  0x100011eb
E:  xpsr:  0x21000000
E: r4/v1:  0x00000006  r5/v2:  0x10009250  r6/v3:  0x00000000
E: r7/v4:  0x00000000  r8/v5:  0x00000000  r9/v6:  0x00000000
E: r10/v7: 0x00000000  r11/v8: 0x00000000    psp:  0x30000f58
E: EXC_RETURN: 0x0
E: Faulting instruction address (r15/pc): 0x100011fe
E: call trace:
E:      0: lr: 0x100011fe [func2+0x21]
E:      1: lr: 0x10001233 [func1+0x16]
E:      2: lr: 0x10001205 [func2+0x28]
E:      3: lr: 0x10001233 [func1+0x16]
E:      4: lr: 0x10001205 [func2+0x28]
E:      5: lr: 0x10001233 [func1+0x16]
E:      6: lr: 0x1000125d [main+0x10]
E:      7: lr: 0x10002cb5 [bg_thread_main+0x20]
E:
E: >>> ZEPHYR FATAL ERROR 3: Kernel oops on CPU 0
E: Current thread: 0x300000e8 (main)
E: Halting system

NOTE: cortex_a_r's walk_stackframe() works too, but extra_info.callee
is NULL during oops because the z_arm_svc doesn't save it, see below
comment in swap_helper.S or switch.S:

/* Zero callee_regs and exc_return (only used on Cortex-M) */
    mov r1, #0
    mov r2, #0
    bl z_do_kernel_oops

So the cortex_a_r's k_oops() can't unwind the stack now. For safe
reason, let's enable ARCH_HAS_STACKWALK for only CPU_CORTEX_M now.

Link: https://github.com/ARM-software/abi-aa/blob/main/ehabi32/ehabi32.rst [1]
Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
2026-03-12 13:59:45 -05:00
Jisheng Zhang
fc5a1f3542 arch: arm: setup exc_return
We will make use of the .exc_return member during walk_stackframe() to
know whether we have extended stack or standard stack.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
2026-03-12 13:59:45 -05:00
Jisheng Zhang
13b3dfdfcd arch: arm: guard arch_syscall_oops() with CONFIG_USERSPACE
The arch_syscall_oops() is only used when CONFIG_USERSPACE=y.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
2026-03-12 13:59:45 -05:00
Henrik Brix Andersen
032cc60ba8 Revert "arch: arm: cortex_a_r: Add CPU load"
This reverts commit 10a23b39a2.

Fixes: #105316

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2026-03-12 00:10:09 +01:00
Andy Lin
1d1c41ccc2 arch: arm: fix ARCH_HAS_STACK_PROTECTION exclusion for v6-M/v8-M baseline
Some ARMv6-M and ARMv8-M Baseline cores indeed support MPU
(CPU_HAS_ARM_MPU in soc Kconfig), so the exclusion should
not be based on ARMV6_M_ARMV8_M_BASELINE.

Signed-off-by: Andy Lin <andylinpersonal@gmail.com>
2026-03-11 17:57:32 +00:00
Mark Holden
302f978bb2 debug: coredump: arm: add callee-saved offset for thread debugging
Extend the ARM Cortex-M coredump arch block to version 3 with metadata
that provides the offset to the callee_saved struct within k_thread.
This enables the coredump GDB stub to accurately retrieve callee-saved
registers (r4-r11) for non-faulting threads during multi-thread
debugging.

Signed-off-by: Mark Holden <mholden@meta.com>
2026-03-11 17:56:17 +00:00
Appana Durga Kedareswara rao
ff403fd355 arch: arm: cortex_a_r: make cache enable functions idempotent
The arch_dcache_enable() and arch_icache_enable() functions could
cause system crashes when called on caches that were already enabled.
This occurs because arch_dcache_invd_all() invalidates the entire
cache without first flushing dirty data, leading to memory corruption
when the cache was previously enabled.

This scenario happens in cache tests where test setup calls
sys_cache_data_enable(), but the SoC early init hook has already
enabled caches during boot.

Fix by checking the SCTLR register before performing cache operations:
- If D-cache is already enabled, perform clean+invalidate instead of
  just invalidate to preserve dirty cache lines
- If I-cache is already enabled, perform invalidate only (no dirty
  lines in I-cache)
- If cache is not enabled, proceed with normal enable sequence

This makes the enable functions safe to call multiple times without
risking data corruption or system crashes.

Signed-off-by: Appana Durga Kedareswara rao <appana.durga.kedareswara.rao@amd.com>
2026-03-11 17:55:36 +00:00
Shreyas Shankar
f6439eea6c arch: arm: cortex_a_r: Use arch_early_memcpy in relocate_vector_table
relocate_vector_table is called as part of z_arm_reset.
This is considered early-boot code before XIP.

At this stage, Program might not have access to optimized
compiler APIs that reside in FLASH.
Thus, its better for relocate_vector_table to use arch_early_memcpy.

Signed-off-by: Shreyas Shankar <s-shankar@ti.com>
2026-03-11 17:55:24 +00:00
Jisheng Zhang
10a23b39a2 arch: arm: cortex_a_r: Add CPU load
Add calls to sys_trace_idle_exit before leaving idle state
to track CPU load.

Extend CPU_LOAD to CPU_AARCH32_CORTEX_R and CPU_AARCH32_CORTEX_A, thus
we can support CPU_LOAD for all CPU_CORTEX.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
2026-03-11 17:51:09 +00:00
Jisheng Zhang
1e332daae2 arch: arm: cortex_a_r: Convert cpu_idle from ASM to C
ASM is notoriously harder to maintain than C and requires core specific
adaptation which impairs even more the readability of the code.

As for performance concern, there's no difference of generated code
between ASM and C version.

ASM version:

<arch_cpu_idle>:
f57ff04f 	dsb	sy
e320f003 	wfi
f1080080 	cpsie	i
f57ff06f 	isb	sy
e12fff1e 	bx	lr

<arch_cpu_atomic_idle>:
f10c0080 	cpsid	i
f57ff04f 	dsb	sy
e320f002 	wfe
e3500000 	cmp	r0, #0
1a000000 	bne	102ca8 <_irq_disabled>
f1080080 	cpsie	i

<_irq_disabled>:
e12fff1e 	bx	lr

C version:

<arch_cpu_idle>:
f57ff04f 	dsb	sy
e320f003 	wfi
f1080080 	cpsie	i
f57ff06f 	isb	sy
e12fff1e 	bx	lr

<arch_cpu_atomic_idle>:
f10c0080 	cpsid	i
f57ff04f 	dsb	sy
e320f002 	wfe
e3500000 	cmp	r0, #0
112fff1e 	bxne	lr
f1080080 	cpsie	i
e12fff1e 	bx	lr

As can be seen, the C version use 'bxne lx' to return directly for irq
disabled case, cost one less instruction than asm version. So from this
PoV, C version not only improves the readability and maintainability
but also generates better code.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
2026-03-11 17:51:09 +00:00
Martin Jäger
659069617b arch: arm: core: Kconfig: introduce CONFIG_FP16_ARITHMETIC
This allows to distinguish between f16 storage format support
(CONFIG_FP16) and actual f16 arithmetic capability.

CONFIG_FP16_ARITHMETIC requires either MVE float (ARMV8_1_M_MVEF) or a
Cortex-A core (CPU_CORTEX_A).

Signed-off-by: Martin Jäger <martin.jaeger@a-labs.io>
2026-03-11 17:50:15 +00:00
Sudan Landge
c407f46eb9 arch: arm: disable USE_SWITCH by default
USE_SWITCH is a new feature and needs more testing before enabling it by
default. While all tests in upstream Zephyr CI passed, keeping this
config disabled helps in getting majority of the work in without causing
regression on upstream boards that are not tested in ci.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2026-03-10 17:24:10 +01:00
Sudan Landge
076a21c30a arch: arm: fix USE_SWITCH for armclang
Fix below issues when trying to build hello world with armclang:
```
Error: L6218E: Undefined symbol z_arm_exc_exit (referred from reset.o).
Error: L6218E: Undefined symbol z_arm_int_exit (referred from reset.o).
Error: L6218E: Undefined symbol z_arm_pendsv (referred from reset.o).
```

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2026-03-10 17:24:10 +01:00