Commit graph

5802 commits

Author SHA1 Message Date
Peter Mitsis
4bc5498399 kconfig: Remove stale references to _Swap()
_Swap() is obsolete and has since been replaced with z_swap().

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-04-16 01:10:15 +02:00
Daniel Leung
833bb667b2 xtensa: fix thread_page_tables_get being unused
thread_page_tables_get() is only used when userspace is
enabled. So move it with userspace #ifdef, or else
compiler would complain about it being unused.

Fixes #88421

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-04-15 19:09:52 +02:00
Eivind Jølsgard
ab341e0afe arch: arm: core: cortex_m: Make relocate_vector_table weak
Allow relocate_vector_table() to be overwritten. This is necessary if
the IRQ vector table is handled proprietary, e.g. before the zephyr
kernel is initialized. In this case we want this function to be empty to
avoid overriding the previous configuration.

Co-authored-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
2025-04-09 15:23:25 +02:00
Julien Racki
87719828ac arch: arm: Adding fault description for the cortex A7
Add support for processing the Fault Status Registers and recoverable
data abort for the cortex A7.

Based on Cortex-A7 MPCore Technical Reference Manual (ARM DDI 0406).
(see https://developer.arm.com/documentation/ddi0406)

Signed-off-by: Julien Racki <julien.racki@st.com>
2025-04-04 09:35:03 +02:00
Julien Racki
6d1cb00627 arch: arm: Add Cortex-A7 support
Pass the correct -mfpu and -mcpu flags to the compiler when building
for the Cortex-A7.

Signed-off-by: Julien Racki <julien.racki@st.com>
2025-04-04 09:35:03 +02:00
Jiafei Pan
573a712bed arm64: reset: disable cache and MMU for safety
When Zephyr boot from EL2, D-Cache, I-Cache and MMU should be disabled
by default, but in some cases, for example use U-Boot "go" command
to boot Zephyr Image, Cache and MMU are already been enabled by U-Boot.
So disable them at reset code to make it safety when the code goes
into C code.

Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>
2025-03-28 08:34:59 +01:00
Tom Hughes
11d70c61e5 everywhere: Replace diagnostic pragmas with TOOLCHAIN_* macros
The TOOLCHAIN_DISABLE_WARNING/TOOLCHAIN_ENABLE_WARNING macros are easier
to read and compiler agnostic.

Signed-off-by: Tom Hughes <tomhughes@chromium.org>
2025-03-20 21:57:47 +01:00
Krzysztof Chruściński
4026daa42e arch: riscv: Add support for CPU load measuring
Add sys_trace_idle_exit to RISCV cpu_idle functions and allow
enabling CPU_LOAD module for RISCV and disable it for SMP.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-03-20 17:14:52 +01:00
Sudan Landge
637bd8f587 arch: arm: Add PXN attr for userspace MPU regions
What is the change?
 - PXN attributes is set for static mpu regions such that
   __ramfunc and __ram_text_reloc having userspace code
   cannot be executed in privileged mode.
 - Updated the notable change section to inform about the change in
   behaviour of code executed from __ramfunc and __ram_text_reloc MPU
   regions.

Why do we need this change?
 - The current static MPU regions allows executing userspace/unprivileged
   code from privileged mode which may not be expected and can lead to
   secure privileged escalation attacks.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-03-20 12:17:11 +01:00
Sudan Landge
d7c629696d arch: arm: Add PXN support for Armv8.1-M
What is the change?
This commit adds support for Armv8.1-M MPU architecture's PXN attribute.
This includes support for configuring MPU regions with PXN via
custom mpu_config, devicetree and static mpu_config.
The existing MPU region attribute macros are updated to retain existing
behaviour with this change with an addition of REGION_RAM_ATTR_PXN to be
used if one needs to configure a RAM region with PXN MPU attribute.

Why do we need this change?
Armv8.1-M architecture introduced a new MPU region attribute called
Privilege eXecute Never (PXN).
If an MPU region is configured with the PXN attribute set and if the,
processor attempts to execute code in this region while at
privileged level, a Memory Management Fault exception is triggered.

This ensures that specific tasks are executed only in unprivileged mode
and helps in preventing secure privilege escalation attacks.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-03-20 12:17:11 +01:00
Peter Mitsis
0a7fde2afd arch: x86: Restrict direct IPI support
It has been discovered that direct IPI support does not work
correctly when CONFIG_X2APIC is enabled. Until that can be
fixed, restrict this feature on x86 to platforms that do not
enable CONFIG_X2APIC.

Fixes #87046

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-03-17 20:01:09 +01:00
Luca Burelli
1b48f74346 llext: avoid redundant 'ldr_parm' checks
Since commit 0aa6b1c9de, the 'ldr_parm' pointer is guaranteed to be
valid inside all the functions of the llext_load() call tree.

This commit fixes the only exception of llext_copy_strings(), which was
not passed the 'ldr_parm' pointer, and remove the redundant checks.

No functional change is intended by this commit.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-03-17 19:58:15 +01:00
Luca Burelli
219cde6621 llext: avoid direct llext_string() usage
Since 3466dab804 the generic llext_symbol_name() function abstracts
the use of llext_string() for (non-section) symbols. Define a similar
llext_section_name() function and replace current occurrences of
llext_string() with the proper abstraction.

By extending llext_symbol_name(), this commit also allows to print the
correct name of sections that are referred to by a symbol.

Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
2025-03-17 19:58:15 +01:00
Lars-Ove Karlsson
413c06b1ea arch: arm: Replaced __volatile__ with volatile
IAR doesn't support the __volatile__ keyword, and since the
toolchain.h isn't included by these arm-specific files and
other arm-specific files already uses volatile, I've made
them all use volatile.

Signed-off-by: Lars-Ove Karlsson <lars-ove.karlsson@iar.com>
2025-03-17 16:24:51 +01:00
Robert Hancock
61ae560e73 arch: arm: cortex_a_r: Flush entire I-cache on arch_icache_invd_range
Previously, the arch_icache_invd_range function simply returned
-ENOTSUP for Cortex A/R. However, this causes a correctness issue when
the processor modifies memory and then executes it as instructions, like
the LLEXT subsystem does. The CPU might not see the up-to-date instructions
in memory.

This caused an LLEXT test failure when running on an emulated Cortex-R5
in QEMU with caches enabled. QEMU doesn't actually emulate the cache,
but it does seem to need the ISB barrier that is executed as part of the
cache invalidate operation in order to handle self-modifying code
properly.

These CPUs do in fact support a selective I-cache invalidate operation
(ICIMVAU) but the CMSIS library doesn't currently support it. For now,
just invalidate the entire I-cache when an icache_invd_range operation
is performed.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
2025-03-17 02:20:50 +01:00
Robert Hancock
e36d4fafd2 arch: arm: cortex_a_r: Cortex-R5 has I/D caches
Cortex-R5 has instruction and data caches present so update Kconfig
accordingly.

Signed-off-by: Robert Hancock <robert.hancock@calian.com>
2025-03-17 02:20:50 +01:00
Peter Mitsis
c6bc09223e kernel: Move current_fp field out of z_kernel
The current_fp field in the z_kernel structure is only used
by 32-bit x86 (which does not support SMP). As such, it should
reside in the arch specific of section of _kernel.cpus[0].

This also changes the name of 'current_fp' to 'fpu_owner' to
be more consistent with other architectures.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-03-14 05:47:10 +01:00
Daniel Leung
c925b0ecd5 xtensa: mmu: fix incorrect caching attrs on double mapping
Inside map_memory() with double mapping enabled, we should not
be mapping the memory with the incoming attributes as-is since
the incoming address may be on un-cached region but with
caching attribute. So we need to sanitize the attributes
according to the incoming address.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2025-03-14 01:01:32 +01:00
Jamie McCrae
9f12f8afb2 infrastructure: Remove hwmv1 support
Removes support for the deprecated hardware model version 1

Signed-off-by: Jamie McCrae <jamie.mccrae@nordicsemi.no>
2025-03-13 16:53:07 +00:00
William Tambe
15fa9a8ed8 arch: x86: remove arch specific dependencies from DYNAMIC_BOOTARGS
CONFIG_DYNAMIC_BOOTARGS currently depends on CONFIG_MULTIBOOT_INFO
and CONFIG_BUILD_OUTPUT_EFI which are x86 specific.

This change removes those dependencies so that another architecture
can use CONFIG_DYNAMIC_BOOTARGS without the x86 specifc features.

Signed-off-by: William Tambe <williamt@cadence.com>
2025-03-13 07:22:53 +01:00
Alberto Escolar Piedras
41c576888a arch/posix posix_core.h: Remove native_posix mention
That target does not exist anymore.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-12 19:05:12 +01:00
Alberto Escolar Piedras
942ef41f5d arch/posix posix_cheats.h: Clarify two comments
native_posix does not exist anymore. This header still applies for
targets setting CONFIG_NATIVE_APPLICATION until this option is removed.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-12 19:05:12 +01:00
Alberto Escolar Piedras
5c4be68b3c arch/posix/CMakeLists.txt: Move comment to correct place
This comment "moved" over the years as more code was added.
Let's put it where it belongs, and simplify it a bit.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-12 19:05:12 +01:00
Krzysztof Chruściński
0ec2ad577d arch: arm: cortex_m: Add sys_trace_idle_exit calls
Add calls to sys_trace_idle_exit when leaving idle state. It is
used to track CPU load.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
2025-03-12 14:03:48 +00:00
Alberto Escolar Piedras
c52f625387 arch/posix/Kconfig: Remove mention of native_posix
This target board does not exist anymore.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-12 02:27:36 +01:00
Alberto Escolar Piedras
454ec337f1 arch posix: Clarify comment in posix_cheats.h
Clarify an old comment

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-12 02:27:36 +01:00
Yangbo Lu
627a3b83cd arch: arm: cortex_m: handle multi-level interrupts in irq init
Multi-level interrupts should be handled in irq init. Only level1
interrupts going directly to interrupt controller need to be
initialized.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-03-11 18:54:40 +01:00
Yangbo Lu
b4f2553cd8 arch: arm: irq: allow custom irq control for multi-level interrupts
Custom irq control for multi-level interrupts should be allowed.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
2025-03-11 18:54:40 +01:00
Jordan Yates
06d7fe8bed arch: update USERSPACE dependencies
These symbols only need to exist if `USERSPACE` is enabled, not just if
the architecture supports it.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2025-03-07 20:25:23 +01:00
Peter Mitsis
427f2c60da kernel: arch: add directed IPIs to x86/intel64
Adds support for directed IPIs to x86/intel64. Use of direct IPIs
can further reduce the number of schedule IPIs sent and processed
in a system. Fewer IPI related ISRs mean that ...
 1. Application code is interrupted less frequently
 2. Lower likelihood of scheduler spinlock contention

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
2025-03-07 20:22:40 +01:00
Alberto Escolar Piedras
7f93a80537 native/posix arch: Add option to enable building of nsi_errno component
Add a new kconfig option to enable building the new component provided
in the native simulator, nsi_errno, which allows converting the errno
value between libCs.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2025-03-07 19:56:30 +01:00
Sudan Landge
b4fb5d38eb Revert "arch: arm: cortex_m: pm_s2ram: Rework S2RAM mark functions"
What is the change?
 - This reverts commit 474d4c3249

Why do we need this change?
 - This commit was added because Cortex-M didn't have a valid
   stack to make required functionality work however,
   the previous commit fixes this and makes interrupt stack
   available for use. This removes Arm specific limitation from
   these generic APIs so revert the commit to reflect the same.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-03-07 19:46:01 +01:00
Sudan Landge
7beff12b06 arch: arm: refactor pm_s2ram
What is the change?
 - APIs `pm_s2ram_mark_set` and `pm_s2ram_mark_check_and_clear`,
   used to set/check pm_s2ram magic marker,
   no longer have Arm specific limitations.

Why is this needed?
 - These APIs are generic and should not have arch specific dependency.

Signed-off-by: Sudan Landge <sudan.landge@arm.com>
2025-03-07 19:46:01 +01:00
Eric Ackermann
b7e9b2785f llext: Support non-paired RISC-V PCREL Relocation
Currently, RISC-V's architecture-specific relocations assume that
all relocations of type R_RISCV_PCREL_LO12_I and _S are processed
immediately after the R_RISCV_PCREL_HI20 relocation that they
share a relocation target with. While this is the case most of
the time, the RISC-V PSABI specification does not guarantee that.
This commit corrects this by determining the R_RISCV_PCREL_HI20
relocation based on the symbol value of the R_RISCV_PCREL_LO12
relocation, as specified in the PSABI.

Signed-off-by: Eric Ackermann <eric.ackermann@cispa.de>
2025-03-07 19:44:54 +01:00
Eric Ackermann
3466dab804 llext: Add parameters to arch_elf_relocate
The RISC-V port of llext requires additional parameters for
handling non-adjacent HI20/LO12 relocations in arch_elf_relocate():
the current extension (struct llext), the current extension loader
(struct llext_loader), the current section header (elf_shdr_t) and
the current symbol (elf_sym_t).
This changes the signature of arch_elf_relocate accordingly.

Signed-off-by: Eric Ackermann <eric.ackermann@cispa.de>
2025-03-07 19:44:54 +01:00
Jungo Lin
d0a1945f49 arch: arm64: enhance backtrace dump check
Examine the FP and LR values of each frame to prevent nested
exceptions caused by data aborts. Sometimes, abnormal FP and LR
values are not mapped by the MMU. If we access memory addresses
based on FP or LR values, a CPU data abort will occur. This issue
often accompanies stack overflow occurrences.

Based on this, it is safe to check the validity of memory mapping
with FP and LR values before accessing them.

Signed-off-by: Jungo Lin <jungolin.tw@gmail.com>
2025-03-07 19:43:31 +01:00
Jonas Spinner
bc3a01a7e5 arch: arm64: fix spelling of "exception"
/s/expection/exception/

Signed-off-by: Jonas Spinner <jonas.spinner@burkert.com>
2025-02-27 13:28:21 +00:00
Jonas Spinner
4ffe3891df arch: arm: cortex_m: fix spelling of "exceptions"
s/expections/exceptions/

Signed-off-by: Jonas Spinner <jonas.spinner@burkert.com>
2025-02-27 13:28:21 +00:00
Andy Ross
029e8f9b61 arch/arm64: z_fatal_error() can return!
This isn't a FUNC_NORETURN function.  On a handled
k_sys_fatal_error_handler(), we'll end up back here.  And the
CODE_UNREACHABLE was causing code generateion bugs that prevented
return up the stack.

Note that the same pattern exists in MANY other architectures (it
seems like the original was part of x86).  But in most cases the arch
assembly isn't actually capable of handling the return to an aborted
thread frame correctly.  On arm64, it does actually work.  So fix it
here at least.

Signed-off-by: Andy Ross <andyross@google.com>
2025-02-26 10:10:29 +00:00
Emil Kieri
ed1b56b557 arch: arm: cortex_a_r: Add cfi directives to z_arm_cortex_r_svc
Add call frame information (cfi) directives to the function
z_arm_cortex_r_svc, which triggers an SVC exception whose handler will
execute a context switch. The return address stored on the stack of a
suspended thread will point into z_arm_cortex_r_svc, that is, this
function will be the starting point when a debugger tries to produce a
call stack for a suspended thread. As the function is written in
assembly, most compilers will not emit any cfi automatically. This patch
adds cfi directives manually so that the call stack can be unwound.

The added cfi directives instruct the compiler to note in the
.debug_frame section that the canonical frame address is at offset 0
from r13, i.e., from the stack pointer.

Signed-off-by: Emil Kieri <emil.kieri@iar.com>
2025-02-25 15:23:53 +00:00
Guennadi Liakhovetski
c29e0d3480 llext: xtensa: disable relative relocations for pre-located
When building pre-located LLEXTs of ET_DYN type (shared ELF object)
on Xtensa, all the R_XTENSA_RELATIVE relocations are already correct,
the current code actually breaks them by mobing the value from the
target address-space to a storage range address. Simply removing the
recalculation solves the issue.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
2025-02-20 21:05:37 +01:00
Benjamin Cabé
29ed8bc21e arch: arm64: fix spelling of "below"
s/bellow/below/

Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
2025-02-19 18:51:13 +01:00
Robin Kastberg
c858c8d6ba arch: arm: cortex_m: 'movs reg, imm' mnemonic
One nmemonic was missed by f84342828cd1

That commit said:

The ARM Thumb-1 instruction set, used by ARMv6-M and ARMv8-M Baseline
cores, does not have a valid encoding for "immediate-to-register move
without affecting flags" instruction (i.e. `mov reg, imm`), and the only
valid variant of immediate-to-register move instruction for it is `movs`,
which affects the flags.

Since none of the register initialisation instructions used here are
flag-sensitive in their context, this commit changes `mov` to `movs`.

This fixes the compilation errors with Clang/LLVM, which is more picky
about the `mov` mnemonic usage and prints out an "invalid instruction"
error when `mov reg, imm` is specified in Thumb-1 mode.

Note that GNU assembler implicitly converts `mov reg, imm` to `movs reg,
imm` when assembling in Thumb-1 mode.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-17 21:15:44 +01:00
Robin Kastberg
9ab06ec667 toolchain: iar: Add experimental IAR support
This adds experimental support for the IAR toolchain.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-14 19:12:44 +00:00
Robin Kastberg
f5a1585426 toolchain: iar: tls: no tls pointer offset in IAR
The IAR Toolchain currently doesn't use the two
pointer offset.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-14 19:12:44 +00:00
Robin Kastberg
e9a0d146cf toolchain: move some hardcoded flags to properties
Some basic flags that were hardcoded needed
to be moved to properties to be able to implement
alternative toolchains.

Signed-off-by: Robin Kastberg <robin.kastberg@iar.com>
2025-02-14 19:12:44 +00:00
Wilfried Chauveau
d88575b5f8 arch: arm: cortex_a_r: move exit_exc from vector_table.S to exc.S
It makes more sense to keep the exit_exc code close to the exc code.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2025-02-14 00:45:35 +01:00
Ryan McClelland
ef232f34d0 arch: arm: fix compile issue if MEM_ATTR=n and ARM_MPU=y
It's possible to have MEM_ATTR=n and ARM_MPU=y. This fixes the compile
issue with it by compiling out the calls to define the DT mpu regions.

Signed-off-by: Ryan McClelland <ryanmcclelland@meta.com>
2025-02-13 16:43:11 +01:00
Wilfried Chauveau
caafe23891 arch: arm: cortex_m: Apply clang-format on cortex_m related code
This commit updates cortex_m related code to align it with the rules from
.clang-format. This is done to simplify future changes in these files as
we are about to implement use_switch support.

Some rules conflict with checkpatch and therefore some small part of the
code locally disable clang-format.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
2025-02-13 16:42:48 +01:00
Anas Nashif
10506f8a25 x86: lakemont: split lakemont into families
Define multiple lakemont cpu families: value and performance.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2025-02-12 23:16:38 +01:00