Commit graph zephyr/arch
Author SHA1 Message Date
Hongquan Li
d52d4583f5 arch: arm: cortex_a_r: smp: flush boot parameters with arch cache ops
arch_cpu_start() published the boot parameters through
sys_cache_data_flush_range(), which returns -ENOTSUP when cache
management or d-cache support is disabled.  The return value was
discarded, so a secondary core could observe stale parameters.

The AArch32 MMU setup enabled the data cache unconditionally, even
with CONFIG_DCACHE disabled, so sys_cache_data_flush_range() could
silently skip the clean while the cache was live.  Gate the SCTLR.C
bit in z_arm_mmu_init() on CONFIG_DCACHE, like soc_reset_hook() in
soc/arm/fvp_aemv8r/aarch32/soc.c already does, so that CONFIG_DCACHE=n
does not enable the data cache.

Call arch_dcache_flush_range() and check its result before releasing
the secondary core, and build cache.c for CONFIG_ARCH_CACHE or
CONFIG_DCACHE so the operation exists without cache management.  The
flush is then only needed, and only compiled, when CONFIG_DCACHE is
enabled.

Keep the existing dsync barriers; they remain the ordering point when
the flush is compiled out.  Include zephyr/arch/cache.h directly
because zephyr/cache.h only exposes the arch cache interface when a
cache type is selected.

This only avoids setting SCTLR.C; a C bit left set by an earlier boot
stage is not cleared.

Fixes #119663

Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
2026-10-30 12:48:58 -04:00
Hongquan Li
ed7107dd82 arch: arm64: smp: clean boot parameters with arch cache ops
arch_cpu_start() published the boot parameters through
sys_cache_data_flush_range(), which does nothing unless
CONFIG_CACHE_MANAGEMENT and CONFIG_DCACHE are both enabled: it returns
-ENOTSUP without touching the data cache, and the caller discarded that
value.  A secondary core reads these parameters with the MMU and the data
cache disabled, so it could observe a stale mpid, sp, fn, arg or cpu_num.

Call arch_dcache_flush_range(), which is the operation the architecture
provides, and check the result.  The flush completes with its own dsync
barrier, so nothing else is needed before the secondary core is
released.  Include zephyr/arch/cache.h directly, because zephyr/cache.h
only pulls the arch cache interface in when a cache type is selected,
which is exactly the configuration that used to drop the clean.

The port turns the data cache on unconditionally as part of the MMU
setup, and the data cache maintenance operations are available
regardless of CONFIG_DCACHE.

Fixes #119663

Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
2026-10-30 12:48:58 -04:00
Daniel Leung
f5b63a674a xtensa: check BSA bounds before printing fatal exception
print_fatal_exception() read bsa->exccause before checking whether the
BSA lies within stack bounds, and the out-of-bounds branch then read
bsa->excvaddr anyway. Either access can fault again while reporting
the original fault.

Do the bounds check first. When the BSA is invalid, print only the CPU
id and the BSA and stack pointer values, then drain the hook and return
as before. The EXCCAUSE line is printed after the check.

Assisted-by: Claude:claude-sonnet-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-29 19:44:22 -04:00
Daniel Leung
cf290917dc xtensa: harden stack bound checks in fault reporting
xtensa_backtrace_get_next_frame() only checked that the stack pointer
was within the stack, but then read the 16-byte base save area below
it, which could lie outside the stack.

xtensa_is_outside_stack_bounds() computed addr + sz without checking
for wrap-around, so a range near the top of the address space could be
reported as within the stack.

Check the base save area itself in the backtrace, and treat a wrapping
addr + sz as out of bounds. The latter also rejects a stack pointer
below 16 in the backtrace, where sp - 16 wraps.

Assisted-by: Claude:claude-sonnet-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-29 19:44:22 -04:00
Iuliana Prodan
75200176ff arch: x86, xtensa: select BARRIER_OPERATIONS_BUILTIN
Neither architecture selected a barrier backend, so every caller of the
barrier API got the no-backend fallback.
Both have hardware that reorders and both run SMP and shared-memory IPC,
so they need the real fence.

This surfaced in pbuf and icmsg, which switched from __sync_synchronize()
to barrier_sync_synchronize() in commit dbe1e63d36 ("ipc: Move to
barrier_sync_synchronize()").

x86 selects the builtin backend unconditionally.
Xtensa excludes xcc, which defines __sync_synchronize() as a bare compiler
barrier in include/zephyr/toolchain/xcc.h and provides no
__atomic_thread_fence(), so selecting the builtin backend there would
claim ordering it does not emit.
xcc keeps the compiler-barrier fallback instead.

Signed-off-by: Iuliana Prodan <iuliana.prodan@nxp.com>
2026-10-29 19:44:13 -04:00
Nicolas Pitre
a40498e11f arch: arm64: take CNTFRQ_EL0 from devicetree when available
z_arm64_el_highest_init() sets CNTFRQ_EL0 from
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC. Since commit 864ea0ea3f ("kernel:
default SYS_CLOCK_HW_CYCLES_PER_SEC from timebase-frequency") that symbol
is only defined with SYS_CLOCK_EXISTS, so an arm64 build without a
system clock no longer compiles, for example samples/basic/minimal with
no-timers.conf on qemu_cortex_a53.

CNTFRQ_EL0 does not configure the counter: it only tells software the
counter frequency, and whatever runs at the highest EL is expected to
set it. The devicetree describes that frequency as timebase-frequency
whether or not the counter drives the system timer, so use it. Fall
back to the Kconfig value for boards that only provide that, and leave
the register alone when neither is known. That also avoids writing the
0 placeholder SYS_CLOCK_HW_CYCLES_PER_SEC defaults to with
TIMER_READS_ITS_FREQUENCY_AT_RUNTIME.

Boards that set the Kconfig value explicitly have no timebase-frequency,
and elsewhere the Kconfig default comes from timebase-frequency, so the
value written is unchanged wherever it was written before.

Fixes #121736

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-10-29 19:43:31 -04:00
Benjamin Cabé
75aa4d6233 arch: arm: select the CMSIS core that the CPU needs
Each Arm CPU selected HAS_CMSIS_CORE, which the cmsis and the cmsis_6
glue both define, so a build without the module for its CPU passed
Kconfig and failed in the compiler on cmsis_core.h. Select the CPU's
own HAS_CMSIS_CORE_M, HAS_CMSIS_CORE_A or HAS_CMSIS_CORE_R instead,
which only the glue of the module that provides it defines, so that
Kconfig stops on the missing module. Configurations that have the
modules are unchanged.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-29 19:43:27 -04:00
Nicolas Pitre
7897e2b15d arch: arm64: mmu: report a private mapping that could not be applied
remap_mapping() splits a block when the range covers only part of it, and
ignored expand_to_table() returning NULL when the translation table pool
is empty. The attributes then landed on the whole block, granting the
domain access to everything the block maps rather than to the partition,
and the caller was told the partition had been added.

Return -ENOMEM instead and let it out through private_map(), which the
callers already propagate. privatize_page_range()'s error is passed on
the same way rather than merely asserted, now that there is somewhere for
it to go.

arch_mem_domain_thread_add() did not: it overwrote a map_thread_stack()
failure with the result of reset_map() and moved the thread to tables
where its stack is not mapped for user access. Return the error before
switching instead, leaving the thread on its old tables. Once the thread
runs on the new tables the move is done: if reset_map() fails then, the
old domain still maps the stack for user access, so revoke that in place,
which needs no new table since the private entries already cover the
stack.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-10-29 19:41:56 -04:00
Nicolas Pitre
da152d360e arch: arm64: mmu: split a source block when globalizing part of it
globalize_table() asserts the source entry is a table whenever the range
stops in the middle of it. That holds when a range is globalized at the
granularity the kernel mapped it with, and not when a partition covers
only part of a range the kernel mapped as a block: reset_map() then walks
the partition's range against the kernel tables, finds a block spanning
more than the range, and the assertion fires on partition removal.

Split the source the way the destination is already split a few lines
down, which is also what set_mapping() does when a new mapping lands
inside an existing block. The mappings are unchanged, only the
granularity they are held at.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-10-29 19:41:56 -04:00
Nicolas Pitre
babfeeabd3 arch: arm64: mmu: map partitions over what the kernel already maps
arch_mem_domain_partition_add() and map_thread_stack() both create the
domain private mapping with phys == virt, ignoring the entry the kernel
holds for that range. That assumes every partition is identity mapped
and always resident, and neither is guaranteed.

With demand paging, a range that is paged out when the partition is
added still gets a valid, access flagged, user permitted entry in the
domain, pointing at whatever frame sits at that physical address. The
kernel has already returned that frame to the free pool, so the domain
reads and writes memory that belongs to whoever gets it next, while the
kernel still considers the page evicted. Threads in the domain also miss
the page fault that would have brought the real contents back.

Apply the partition attributes to the entries the range already has
instead. Descriptor type, output address or paging location token, and
the access flag stay with the entry, so a paged out page stays paged
out and faults in normally, and a mapping whose virtual address is not
its physical address keeps pointing where it should. Ranges with
nothing mapped are left alone: access can only be granted to memory
that is actually mapped.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-10-29 19:41:56 -04:00
Nicolas Pitre
fe0c6d202c arch: arm64: mmu: add a test hook to read a leaf descriptor
The descriptors are what tell a domain-private mapping apart from the
kernel entry it was built over: which bits came from the partition, which
were kept from the entry, and what the entry maps. Nothing in this file
exposes them, so a test can only observe the result indirectly, by
arranging an access and seeing whether it faults.

Add arm64_mmu_pte_get(), alongside the existing table accounting hooks,
walking a set of tables down to the leaf covering an address and
reporting it with its level.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-10-29 19:41:56 -04:00
Anas Nashif
ff883873f8 arch: xtensa: use k_thread_is_user_thread()
Replace the open-coded tests of K_USER in a thread's user_options with
k_thread_is_user_thread(). No functional change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-10-29 17:34:11 -04:00
Anas Nashif
f62ef54882 arch: x86: use k_thread_is_user_thread()
Replace the open-coded tests of K_USER in a thread's user_options with
k_thread_is_user_thread(). No functional change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-10-29 17:34:11 -04:00
Anas Nashif
aca0af4a92 arch: riscv: use k_thread_is_user_thread()
Replace the open-coded tests of K_USER in a thread's user_options with
k_thread_is_user_thread(). No functional change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-10-29 17:34:11 -04:00
Anas Nashif
4a56fbfba7 arch: arm64: use k_thread_is_user_thread()
Replace the open-coded tests of K_USER in a thread's user_options with
k_thread_is_user_thread(), and drop the private is_user() helper in
thread.c, which did the same thing. No functional change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-10-29 17:34:11 -04:00
Anas Nashif
e6f29b7130 arch: arm: use k_thread_is_user_thread()
Replace the open-coded tests of K_USER in a thread's user_options with
k_thread_is_user_thread(). No functional change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-10-29 17:34:11 -04:00
Anas Nashif
d9f3158877 arch: arc: use k_thread_is_user_thread()
Replace the open-coded tests of K_USER in a thread's user_options with
k_thread_is_user_thread(), and drop the private is_user() helper in
thread.c, which did the same thing. No functional change.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2026-10-29 17:34:11 -04:00
Ederson de Souza
ec782a1c91 arch: x86: x86_64: Emit ISR tracing events
Call sys_trace_isr_enter()/sys_trace_isr_exit() around the handler
dispatch in irq_dispatch.

Fixes: #119179

Assisted-by: Claude:claude-opus-5
Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
2026-10-29 15:39:29 -04:00
Parthiban Nallathambi
eccc73448f arch: tricore: add arch_float_disable and arch_float_enable
FPU_SHARING needs these functions. TriCore has no separate FPU context,
the state lives in the data registers and PSW, so both return
-ENOTSUP.

Co-authored-by: Saravanan Sekar <saravanan@linumiz.com>
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
2026-10-28 22:54:30 -04:00
Daniel Leung
2cffdb3d97 xtensa: mpu: add and fix doxygen
Document the stack permission function and the boot region tables.
Add missing parameter and return value descriptions, and drop the
non-existent access_rights parameter from the mpu_map_region_restore()
documentation. No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
8cd6563ac9 xtensa: mmu: add and fix doxygen in page table code
Document missing doxygen doc for functions, fixing missing
parameter name, and fixing incorrect return value doc.
No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
25ab0a0003 xtensa: add doxygen to debug support code
Document the coredump, GDB stub, backtrace and semihosting functions,
and add the missing return value description of
get_gdb_exception_reason(). No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
0523e5e165 xtensa: add doxygen to exception handling
Document the vector handler and fatal error functions.
No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Daniel Leung
9dca5e6aba xtensa: add doxygen to thread support code
Document the initial stack frame setup and xtensa_hifi_disown()
stub. No functional change.

Assisted-by: Copilot:claude-opus-5.5
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-28 22:46:15 -04:00
Tahsin Mutlugun
03b808b11c arch: xtensa: Drop hard requirement for unsigned load/store emulation
Unsigned load/store emulation does not support exceptions caused by
Very Long Instruction Words (VLIW), so it requires VLIW generation to
be disabled.

However, applications may still benefit from VLIW instructions when
they can guarantee that no such exceptions will occur. Drop the hard
requirement so applications can override this behavior when appropriate.

Signed-off-by: Tahsin Mutlugun <Tahsin.Mutlugun@analog.com>
2026-10-28 22:40:47 -04:00
Daniel DeGrasse
e05549cf53 arch: riscv: use csr APIs for IRQ lock operations
Use csr APIs instead of direct inline asm for IRQ lock/unlock
operations.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@analog.com>
2026-10-28 22:40:41 -04:00
Aditya Ganesh
01d1af8524 arch: xtensa: core: Flush l2 tables in dup_l2_tables
This change flushes the l2 page table in dup_l2_table
instead of dup_l2_table_if_needed to avoid a scenario
where the l2 page table is modified but not flushed

Signed-off-by: Aditya Ganesh <aditya.ganesh@intel.com>
2026-10-28 22:39:51 -04:00
Nicolas Pitre
548a02c64f arch: arm64: coredump: offer CPU freezing only with a system clock
The coredump freeze handshake in smp.c bounds its waits with
k_cycle_get_32() and k_ms_to_cyc_ceil32(), which need a system timer
and its frequency. Without SYS_CLOCK_EXISTS,
DEBUG_COREDUMP_SMP_FREEZE_CPUS still defaults to y on SMP and smp.c
fails to build.

Only select ARCH_SUPPORTS_COREDUMP_SMP_FREEZE when SYS_CLOCK_EXISTS is
set.

Should freezing ever be wanted without a system clock, the waits could
read the architectural counter directly instead: k_cycle_get_32() is a
CNTVCT_EL0 read on arm64, and that counter runs whether or not it
drives the system timer, with CNTFRQ_EL0 giving its rate. When
CNTFRQ_EL0 is unknown, the freeze wait would have to give up on the
other CPUs right away rather than wait forever on one with interrupts
masked.

Fixes #121737

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2026-10-28 22:38:38 -04:00
Dhruv Menon
4b61e62a89 arch: hexagon: add userspace support
Add ARCH_HAS_USERSPACE and implement the trap0/syscall path, user
mode entry via vmrte/GOSP, and arch_buffer_validate() needed for
CONFIG_USERSPACE.

Signed-off-by: Dhruv Menon <dhrumeno@qti.qualcomm.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
2026-10-28 22:35:04 -04:00
Dhruv Menon
8a31659651 arch: hexagon: add MMU support
Add CPU_HAS_MMU/HEXAGON_MMU and implement arch_mem_map(),
arch_mem_unmap() and arch_page_phys_get() as thin shims over the
HVM/H2 hypervisor's single flat identity-mapped page table.

Signed-off-by: Dhruv Menon <dhrumeno@qti.qualcomm.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
2026-10-28 22:35:04 -04:00
Dhruv Menon
41e14c1db9 arch: hexagon: add HW_STACK_PROTECTION (FRAMELIMIT) support
Wire up Hexagon's hardware stack-limit register (FRAMELIMIT) as
ARCH_HAS_STACK_PROTECTION, programmed at thread-create time and
reprogrammed on every context switch and new-thread start.

Signed-off-by: Dhruv Menon <dhrumeno@qti.qualcomm.com>
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
2026-10-28 22:35:04 -04:00
Benjamin Cabé
a513c5d929 arch: xtensa: disable lazy HiFi on interrupt-driven switch
With CONFIG_XTENSA_LAZY_HIFI_SHARING, xtensa_switch() clears the HiFi
bit in CPENABLE so that the incoming thread traps on its first HiFi
instruction and gets its own registers loaded.

A switch done on interrupt return does not go through xtensa_switch()
and left CPENABLE as it was. A thread preempting the HiFi owner could
then execute HiFi instructions without trapping, overwriting the
registers of the owner, which later resumed with the other thread's
values.

Clear the HiFi bit in return_to() when the interrupt returns to a
different thread.

Assisted-by: Claude:opus-5.5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2026-10-28 22:34:49 -04:00
Cheng Yueh
ac7be8f97e arch: riscv: pmp: preserve lock bit on start address for TOR
When Top-Of-Range (TOR) mode is used with two PMP entries, the first
entry defines the lower bound address and the second entry defines the
upper bound address with the desired permissions.

If the region being configured has the lock bit (PMP_L) set, the upper
bound entry correctly receives perm | PMP_TOR, which includes PMP_L.
However, the lower bound entry previously had its configuration set to
0. As a result, the lower bound address entry was not locked, leaving
it writable. This could allow M-mode software or subsequent updates to
alter the start address of what was intended to be an immutable, locked
TOR region.

Set the lower bound entry configuration to perm & PMP_L so that the
lock bit is preserved whenever the region is locked, while keeping
address matching disabled (A=OFF) and permissions cleared (R=W=X=0)
for the lower bound slot.

Signed-off-by: Cheng Yueh <fenzhangs@gmail.com>
2026-10-28 22:29:12 -04:00
Arjun Salunkhe
ac6af918a3 arch: riscv: add mcause 18 for SCE
Add exception values for Double Trap and Software Check
Exception (Required by Zicfilp and Zicfiss).

Signed-off-by: Arjun Salunkhe <arjun.salunkhe@proton.me>
2026-10-28 22:27:10 -04:00
Arjun Salunkhe
0aa4aaf58b arch: riscv: Add Zicfilp SMP enablement
Add mseccfg regsiter configuration for secondary cpus to
enable landing pad enforcement for them.

Signed-off-by: Arjun Salunkhe <arjun.salunkhe@proton.me>
2026-10-28 22:27:10 -04:00
Arjun Salunkhe
4cc75aee39 arch: riscv: Add initial Zicfilp support
Adds M-mode, S-mode (internal SBI) and U-mode enablement for the RISC-V
Zicfilp (Landing Pad) extension for forward-edge Control Flow Integrity:
- Kconfig: Added RISCV_ISA_EXT_ZICFILP and RISCV_LANDING_PADS options.
- Toolchain: Passed -fcf-protection=branch when Zicfilp is active.
- CSR: Added definitions for MSECCFG_MLPE, MENVCFG_LPE, and SENVCFG_LPE.
- M-Mode: Configured mseccfg.MLPE in arch_kernel_init().
- S-Mode: Configured menvcfg.LPE in reset.S for internal SBI.
- U-Mode: Configured senvcfg.LPE in arch_kernel_init().

Tested against qemu_riscv32 with Zicfilp enabled. Verified that indirect
jumps to assembly routines lacking lpad correctly trigger a CPU trap.

Signed-off-by: Arjun Salunkhe <arjun.salunkhe@proton.me>
2026-10-28 22:27:10 -04:00
Zee Yudenko
3334d4a187 arch: Kconfig: add config for tracking nocache mempartition support
Add a Kconfig option for tracking if the architecture has nocache
mempartition support. This option being true the
`K_MEM_PARTITION_*_NOCACHE` defines can be used.

Signed-off-by: Zee Yudenko <zyudenko@internships.antmicro.com>
2026-10-28 21:53:52 -04:00
Mark Inderhees
0b4ebc0ff0 xtensa: honor CONFIG_SKIP_BSS_CLEAR during startup
Platforms that initialize BSS before entering Zephyr can select
CONFIG_SKIP_BSS_CLEAR, but the Xtensa core startup still clears it.

Guard the startup clearing block with CONFIG_SKIP_BSS_CLEAR so those
platforms can preserve their initialized BSS contents. Normal startup
continues to clear BSS by default.

Validated normal clearing and BSS preservation on qemu_xtensa/dc233c.
The hello_world smoke test also passed.

Assisted-by: Codex:gpt-6
Signed-off-by: Mark Inderhees <markind@meta.com>
2026-10-28 21:51:15 -04:00
Hongquan Li
dc85d00813 arch: tricore: drop WAIT from arch_cpu_atomic_idle()
ENABLE sets ICR.IE, and the core evaluates interrupt acceptance on the
instruction after it, so a request that is pending when the key is
released is turned into an interrupt and serviced before WAIT could run.
The handler then makes the condition the caller waits for true, while
WAIT suspends the core until an unrelated interrupt arrives, which in a
tickless or single-threaded configuration may never happen.  This is the
loop k_timer_status_sync() runs with CONFIG_MULTITHREADING=n.

ENABLE and WAIT are separate instructions with the acceptance check in
between, so no enable-and-wait sequence on this architecture can be
interrupted atomically; sampling ICR.PIPN before ENABLE only moves the
window.  Drop the WAIT from this function, which makes re-enabling the
interrupts atomic by construction and gives up the low power effect of
this call.  Callers that must idle the core use arch_cpu_idle(), which
keeps the instruction and whose contract tolerates an interrupt being
taken before the core sleeps, so the idle thread still suspends normally.

Fixes #119657

Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
2026-10-28 20:19:46 -04:00
Hongquan Li
1414e3d70d arch: tricore: add helper for PCX to CSA address conversion
The PCX encoding (PCXS in bits 19:16, PCXO in bits 15:0) is open-coded
wherever a PCXI or FCX value is turned into a CSA address. Add
z_tricore_pcx_to_addr() next to the context structures and use it in
fatal.c and thread.c, so the address layout is documented in one place.

Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
2026-10-28 20:19:09 -04:00
Hongquan Li
ce0ef41d3a arch: tricore: correct PCXI to CSA address conversion
PCXS is PCXI[19:16] and PCXO is PCXI[15:0], and the CSA address they
encode is {PCXS, 6'b0, PCXO, 6'b0}. Shifting the whole PCXI value left by
12 leaves PCXO[15:10] in address bits 27:22, and insert only overwrites
bits 6:21, so the exception wrapper passed a wrong context pointer to the
fatal handler whenever a valid CSA had any of those bits set.

Extract PCXS and place it in bits 31:28 instead.

Fixes #119648

Signed-off-by: Hongquan Li <hongquan.li@processmission.com>
2026-10-28 20:19:09 -04:00
Laurie Fay
ff991f4567 arch: arm: Add support for nested IRQ offload
Introduce support for nested IRQ offloads on Arm: pass the routine
and parameter in r4 and r5 respectively, then move r5 into the
parameter r0 and branch to the routine.

On Cortex-M mainline, SVC always has higher priority than the
current interrupt, so there will be no escalation to hardfault.

On Cortex-A/R, there is no concept of escalation to hardfault
when an SVC is taken: it runs synchronously no matter what.

On Cortex-M baseline, SVC may have the same priority as the
current IRQ (if the IRQ is priority 0). However the docs
for irq_offload explicitly warn that some interrupts are
non-preemptible.

Signed-off-by: Laurie Fay <Laurie.Fay@arm.com>
2026-10-28 20:15:52 -04:00
Kai Vehmanen
f619c179fc arch: xtensa: mmu: skip unmapped L1 entries in region_map_update()
When the last page mapped in an L2 table is unmapped,
l2_page_table_unmap() releases the L2 table and marks the L1 entry
illegal, in the kernel page tables and in all memory domains. If a
memory domain partition covering that range is removed afterwards,
region_map_update() takes the PPN of the illegal L1 entry as an L2
table pointer and operates on it while holding the MMU spinlocks.
This corrupts memory and leaves the CPU dead without any fatal error
report.

There is nothing mapped in such a range, so there is nothing to
update. Skip pages whose L1 entry is illegal, as l2_page_table_unmap()
already does.

Seen on NVL-S with SOF, where unloading the last LLEXT module in the
library region unmaps its memory before removing its partitions from
the LL user memory domain.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
2026-10-22 18:24:45 +02:00
Sylvio Alves
979e655d46 xtensa: mask interrupts before leaving the cross-stack call
After the interrupt handler returns, the cross-stack call goes
back to the interrupted frame and switches A1 to the context
handle while still at the handler's interrupt level. A nested
interrupt taken there either builds its save area on top of
the outer one or spills the interrupted function's caller
registers relative to the handle, so the thread later resumes
from corrupted state.

Raise the interrupt level before returning from the handler
call in all builds, as userspace builds already did, and drop
the now redundant masking in the caller.

Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-10-21 11:41:50 +02:00
Jimmy Zheng
94bf4f365e arch: riscv: make vectored mode optional with IRQ vector table
Default RISCV_VECTORED_MODE to enabled when GEN_IRQ_VECTOR_TABLE is
enabled, rather than selecting it.

This allows platforms with a custom vectored interrupt implementation to
disable the standard RISC-V mtvec optional vectored mode while keeping
the existing behavior by default.
For example, AE350 supports the RISC-V privileged architecture but not
the optional mtvec vectored mode, and may use the Andes Vectored PLIC
extension instead.

Signed-off-by: Jimmy Zheng <jimmyzhe@andestech.com>
2026-10-19 10:27:11 +02:00
Daniel Leung
8fefdcc4e5 xtensa: export symbol xtensa_is_user_context()
xtensa_is_user_context() needs to be exported for used with
LLEXT if the SoC does not have hardware thread pointer
register.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2026-10-19 10:22:28 +02:00
Benjamin Cabé
16592affe2 arch: xtensa: save the boolean register
Floating-point compares write their result to the BR register, which
the interrupt and context switch code did not save, so a thread
preempted between a compare and the branch on its result could take
the wrong branch. Save and restore BR with the other special registers
on cores with the boolean option.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5.5
2026-10-16 15:20:38 -05:00
Luca Burelli
dbf1d2dcf9 arch: arm: cortex_m: fix DWT COMP1 clash with vendor macros
The ARMv8-M Mainline path of the DWT-based null pointer detection
writes DWT->COMP1. Several STM32 device headers (e.g. STM32U5, STM32H5,
STM32L5, STM32U3, STM32WBA) define COMP1 as the analog comparator
instance macro, so the member access expands to
DWT->((COMP_TypeDef *)COMP1_BASE_NS) and the build fails with:

  error: expected identifier before '(' token

Undefine COMP1 in debug.c, which does not use the vendor peripheral.

Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2026-10-15 20:35:24 +02:00
Benjamin Cabé
7bd8f2e4a8 arch: forbid dynamic interrupts with a switch-case ISR table
CONFIG_DYNAMIC_INTERRUPTS installs ISRs by writing _sw_isr_table[], but
CONFIG_GEN_SW_ISR_TABLE_SWITCH generates a switch statement instead of
that array, so enabling both fails to compile arch/common/dynamic_isr.c.
Make the incompatibility a Kconfig dependency, and filter the four
interrupt test suites that call arch_irq_connect_dynamic() or index the
table directly on the resulting symbol.

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Assisted-by: Claude:opus-5
2026-10-15 20:34:17 +02:00
Sylvio Alves
5a7b28425a arch: riscv: skip pmp guard when painting privileged stack
With CONFIG_INIT_STACKS, arch_user_mode_enter() fills the
privileged stack with 0xaa starting at priv_stack_start. Without
CONFIG_GEN_PRIV_STACKS the privileged stack lives in the thread
stack object and priv_stack_start is the base of the PMP stack
guard, which is still armed for the thread at that point, so the
memset takes a store access fault.

Paint only the area above the guard, and make
arch_thread_priv_stack_space_get() scan the same range so the
reported privileged stack size and usage exclude the guard. It
also returns -EINVAL for a user thread that has not entered user
mode yet, as its privileged stack is not set up.

Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2026-10-15 16:35:49 +02:00