238 Commits

Author SHA1 Message Date
yaojiaqi 131f7f75ed arm: memcpy: add NEON paths for aligned copies
Add dedicated NEON implementations for mutually aligned medium and long memcpy copies when building with __ARM_NEON__. These paths use NEON multi-register loads and stores while preserving the existing VFP implementation for non-NEON VFP configurations.

NEON builds also define USE_VFP, so select the NEON implementation explicitly before falling back to VFP. Apply the same aligned-copy optimization to the armv7-a, armv7-r, and armv8-r implementations.

Signed-off-by: yaojiaqi <yaojiaqi@lixiang.com>
2026-05-09 09:46:43 +08:00
Piyush Patle 0dccc8ba21 include/debug.h: Move to include/nuttx/debug.h
debug.h is a NuttX-specific, non-POSIX header. Placing it in the
top-level include/ directory creates naming conflicts with external
projects that define their own debug.h.
This commit moves the canonical header to include/nuttx/debug.h,
following the NuttX convention for non-POSIX/non-standard headers,
and updates all in-tree references.

A backward-compatibility shim is left at include/debug.h that
emits a deprecation #warning and re-includes <nuttx/debug.h>,
allowing out-of-tree code to continue building while migrating.

Signed-off-by: Piyush Patle <piyushpatle228@gmail.com>
2026-04-07 07:50:06 -03:00
yinshengkai 54040c6888 libs/libc/machine/arm: add Cortex-M0/M23 support to arch_mcount
Add support for ARMv6-M and ARMv8-M Baseline architectures
(Cortex-M0/M0+/M23) in the mcount profiling function. These cores
only support limited Thumb-1 instruction set and require different
assembly instructions compared to ARMv7-M and higher.

Changes:
- Use MOVS+BICS instead of BIC for bit clearing on M0/M23
- Separate register restore for limited push/pop instructions
- Use BX instead of direct POP to PC on M0/M23

Signed-off-by: yinshengkai <yinshengkai@bytedance.com>
2026-02-04 03:03:45 +08:00
liwenxiang1 2645e06c86 arch/x86_64: Add gprof
add gprof tool

Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
2026-01-20 22:43:38 +08:00
guoshichao ba63a4d234 ghs: fix the UsageFault:INVSTATE error triggered by exception_common
when we build with greenhills compiler, if the exception_common function
is put into a separate section: ".text.exception_common", then the
address of exception_common function is an even number, for example "0x16a6c",
in this case, it will trigger the UsageFaults:INVSTATE error.
The reason for this error is that in the GHS compiler, a section declared
through the ".section" directive must specify at least the "a" attribute.
Otherwise, this section will not be linked into the final file, and this
is why the address of exception_common function is invalid.
The following is the official explanation in the GHS compiler documentation:
"The reason for this error is that in the GHS compiler, a section
declared through the .section directive must specify at least the "a"
attribute. Otherwise, this section will not be linked into the final
file. The following is the official explanation in the documentation:
"Sections that are intended be part of the final linked output should
have at least the `a` attribute"
and for GHS compiler, the .text section is recommended specify the
attribute of `ax`.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2026-01-16 09:41:13 +08:00
anjiahao 7c96537a58 string:use builtin function to optimize libc function
This allows the compiler to automatically identify which string functions
can be compiled into libraries, and the compiler's internal implementation
is faster than libc functions.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-20 10:38:53 +08:00
yangao1 011fd50bcd libc/arch_libc.c:fix bug for macro LIBC_ARCH_STRCHRNUL
config ARM64_STRCHRNUL
	bool "Enable optimized strchrnul() for ARM64"
	default n
	select LIBC_ARCH_STRCHRNUL
	depends on ARCH_TOOLCHAIN_GNU
	---help---
		Enable optimized ARM64 specific strchrnul() library function

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
yangao1 184f1ef225 libs/risc-v:add cfi for optimized compilation func
(gdb) bt
    at /home/mi/ssd/dev-system/nuttx/include/string.h:321
    ppcmd=<synthetic pointer>, vtbl=0x80069498) at nsh_parse.c:1909
    param=0x800692b8) at nsh_parse.c:2593
    cmdline=cmdline@entry=0x80069750 "hello") at nsh_parse.c:3028
    argc=argc@entry=1, argv=argv@entry=0x80068870) at nsh_session.c:246
    at nsh_consolemain.c:75
    at nsh_main.c:74
...

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
yangao1 15eb317be2 libc/arm64: add cfi for optimized func
(gdb) bt
    #0  arch_strlen () at machine/arm64/gnu/arch_strlen.S:119
    #1  0x000000004043a2c0 in strchr (s=s@entry=0x408e5e40 "HELLO WORLD", c=c@entry=87) at machine/arch_libc.c:252
    #2  0x0000000040504c6c in strchr (c=87, s=0x408e5e40 "HELLO WORLD") at /home/mi/ssd/dev-system/nuttx/include/string.h:306
    #3  test_strchr () at hello_main.c:79
    #4  hello_main (argc=argc@entry=1, argv=argv@entry=0x40b5c090) at hello_main.c:132
    #5  0x000000004043d958 in nxtask_startup (entrypt=0x40504ba0 <hello_main>, argc=argc@entry=1, argv=argv@entry=0x40b5c090) at sched/task_startup.c:72
    #6  0x00000000403f1ab4 in nxtask_start () at task/task_start.c:104
    #7  0x0000000000000000 in ?? ()

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
yangao1 34aef9cbec armv7a:add cfi instrcutions to debug
(gdb) bt
    #0  memset () at machine/arm/armv7-a/gnu/arch_memset.S:45
    #1  0x0407222e in memset (n=4, c=65, s=0x40269d94) at /home/mi/ssd/dev-system/nuttx/include/string.h:203
    #2  test_memset () at hello_main.c:57
    #3  hello_main (argc=<optimized out>, argv=<optimized out>) at hello_main.c:66
    #4  0x0403f1de in nxtask_startup (entrypt=0x40721b1 <hello_main>, argc=1, argv=0x40269628) at sched/task_startup.c:72
    #5  0x0400c66a in nxtask_start () at task/task_start.c:104
    #6  0x00000000 in ?? ()

Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-12-18 22:05:12 +08:00
ligd 5e785b14bc memset: add none NEON version support for armv7-a/r
Add memset implementation for ARMv7-A/R targets without NEON support,
ensuring proper operation on CPUs lacking NEON instructions.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2025-12-18 22:05:12 +08:00
anjiahao b623c781c5 arch:use ARCH_64BIT to mark arch is support 64bit
Add ARCH_64BIT macro to indicate architectures with 64-bit support,
improving portability and conditional compilation.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2025-12-18 22:05:12 +08:00
ligd 8a02ca5913 memcpy: fix link failed when open kasan
riscv-none-elf-ld: /home/ligd/platform/dev-system/nuttx/staging/libc.a(arch_libc.o): in function `memcpy':
/home/ligd/platform/dev-system/nuttx/libs/libc/machine/arch_libc.c:131:(.text.memcpy+0x4e): undefined reference to `arch_memcpy'

Signed-off-by: ligd <liguiding1@xiaomi.com>
2025-12-18 22:05:12 +08:00
chenxiaoyi 0d757d0134 libc/machine/xtensa: add mcount implementation for gprof
Add the implementation of _mcount() to meet the requirements of gprof.

Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2025-12-13 13:31:46 +08:00
chenxiaoyi 09a71ec7c1 libs/libc/arm: add back __aeabi_mem* functions
Add back these functions since clang will use them.

This reverts "libs/libc/arm: use builtin routines instead of aliases of __aeabi_mem*"
and adds source files to cmake.

Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2025-11-28 14:50:58 -03:00
wangchengdong f82f71d180 libs/libc: Fix Kconfig issue for memcpy and memset
Fix an issue on ARMv8-R where NEON is not supported.
    When NEON is disabled, the assembly-optimized implementations
    of memset and memcpy should not be used.

Signed-off-by: Chengdong Wang <wangchengdong@lixiang.com>
2025-11-07 13:04:20 +01:00
Tiago Medicci Serrano d250808c1c esp32s3/elf: Fix ELF loader on ESP32-S3 when using external PSRAM
Prior to this commit, it wasn't possible to load ELF modules from
the external PSRAM. There were two main issues about it: 1) copying
data using the instruction bus was being used instead of the data
bus (this, per si, isn't a problem, but requires special attention
regarding data alignment), and 2) the cache was not being properly
cleaned and flushed to properly access the loaded data using the
instruction bus.

Signed-off-by: Tiago Medicci Serrano <tiago.medicci@espressif.com>
2025-08-20 02:23:03 +08:00
yinshengkai 156ef05205 libc/mcount: compatible with armv6m mcount implementation
mcount.S: Assembler messages:
mcount.S:33: Error: cannot honor width suffix -- `bic r1,lr,#1'
mcount.S:35: Error: cannot honor width suffix -- `bic r0,r0,#1'
mcount.S:37: Error: cannot honor width suffix -- `pop {r0,r1,r2,r3,ip,lr}

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2025-07-10 18:06:03 +08:00
wangmingrong1 c6da553788 kasan: kasan_reset_tag rename kasan_clear_tag
The clear tag is more explicit than the reset tag.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-06-30 18:19:38 +08:00
Xiang Xiao 2b360c826c arch/arm: Move lib_dummy.c from arch/arm/src/common/ghs to libs/libc/machine/arm
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao 5758364f10 libc/machine/arm: Move all source files out of gnu folder
and unify the file prefix to arch_xxx.c

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
yangao1 0b6188bfa2 armv8-m: Optimize cfi instructions to debug
Signed-off-by: yangao1 <yangao1@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao c1a37ec1fb libc/machine/arm64: Move all source files out of gnu folder
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao 378f8a5c0f libc/machine/renesas: Move all source files out of gnu folder
and remove the empty CMakeLists.txt in the subdirectories.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao ae071920b4 libc/machine/riscv: Move all source files out of gnu folder
and remove the empty CMakeLists.txt in the subdirectories.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Xiang Xiao 1177ac8ee4 libc/machine/x86_64: Move all source files out of gnu folder
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2025-06-30 09:56:27 +08:00
Lars Kruse 3ce85ca54e style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
Jinliang Li d5db7d1cee libc/arm: optimize crc32/crc32c for arm
Optimize crc32 standard(poly:0x04C11DB7) and crc32
castagnoli(poly:0x1EDC6F41) with arm crc32 extension instructions.

For example, crc32 standard caculates(lookup crc32 table) 1812 bytes data,
reduced the time from 118 us to 14 us through optimization.

Performance improved ~700%

Signed-off-by: Jinliang Li <lijinliang1@lixiang.com>
2025-04-04 09:51:50 -03:00
simbit18 35a793ed17 [nxstyle] fix Relative files path
fix Relative file path does not match actual file.

Signed-off-by: simbit18 <simbit18@gmail.com>
2025-02-21 15:36:05 +01:00
hujun5 f22b93b337 sched/spin_lock: rename raw_spin_lock to spin_lock_notrace
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-02-13 20:48:15 +08:00
hujun5 b49f4286fb spinlock: Due to semantic inconsistency, remove/rename some functions with the _wo_note suffix.
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-23 19:58:49 +08:00
Neo Xu ec9b079c04 arch/x86-64: fix cmake compile error
-- Configuring done
CMake Error at cmake/nuttx_add_library.cmake:142 (add_library):
  Cannot find source file:

    /vela/nuttx/libs/libc/machine/x86_64/arch_elf.c
Call Stack (most recent call first):
  libs/libc/CMakeLists.txt:22 (nuttx_add_kernel_library)

Signed-off-by: Neo Xu <neo.xu1990@gmail.com>
2025-01-22 16:35:32 +08:00
lipengfei28 d3e3993682 arch/riscv: use UP_DSB, UP_DMB, UP_ISB as barrier standard API
Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
2025-01-20 20:13:07 +08:00
lipengfei28 2d1af01d44 mem barrier: use UP_DMP UP_DSP as barriers standard API
Signed-off-by: lipengfei28 <lipengfei28@xiaomi.com>
2025-01-20 20:13:07 +08:00
Huang Qi bac2df6bc8 risc-v: replace fence.i with __ISB for instruction sync
Summary:
- Replace direct use of `fence.i` instruction with `__ISB()` macro for instruction synchronization
- This change improves portability while maintaining the same functionality

Impact:
- No functional changes - both `fence.i` and `__ISB()` ensure instruction
synchronization on RISC-V
- Makes the code more maintainable by using the architecture abstraction
layer

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2025-01-17 09:04:45 +08:00
wangmingrong1 df7d062713 kasan/kconfig: Add config CONFIG_MM_KASAN_INSTRUMENT
Build Documentation / build-html (push) Has been cancelled
It will be used to distinguish between hardware KASan and software KASan. Hardware KASan does not need to use plug-in

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-14 14:01:48 +08:00
chenxiaoyi aa426d1edb xtensa: change write intset register to syscall instruction
Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2024-12-27 00:25:55 +08:00
wangmingrong1 e3a733ae96 libc/machine: fix config error
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-12-24 21:18:12 +08:00
chao an a59f59b9f5 libc/gnu: fix typo adress -> address
fix typo adress -> address

Signed-off-by: chao an <anchao@lixiang.com>
2024-12-17 20:48:07 +08:00
hujun5 8ffc3e3203 fix a typo
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-12-17 16:20:46 +08:00
Xiang Xiao 60fb917eda Remove FAR from 32/64bit arch
since these arch doesn't distinguish between near and far pointers

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2024-12-05 22:55:39 +08:00
zhangyuan29 dcea1b90e7 arch_atomic: only support atomic_xx and atomic64_xx function
Modify the kernel to use only atomic_xx and atomic64_xx interfaces,
avoiding the use of sizeof or typeof to determine the type of
atomic operations, thereby simplifying the kernel's atomic
interface operations.

Signed-off-by: zhangyuan29 <zhangyuan29@xiaomi.com>
2024-12-04 14:03:14 +01:00
Jinliang Li f3213efc7f armv8-r/libc: optimize libc string apis with asm
Optimize libc string apis(memcpy/memset/memmove/memchr/strcmp/strlen)
with arm32 assembly instruction including vfp and neon.
Add arch releated elf parsing

Signed-off-by: Jinliang Li <lijinliang1@lixiang.com>
2024-11-26 10:22:12 +08:00
hujun5 12cd59b3e6 arch_atomic: use small lock in libs/libc/machine/arch_atomic.c
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-11-21 16:35:29 +08:00
Takuya Miyasita 2275138dcf arch_atomic : Introduce CONFIG_LIBC_ARCH_ATOMIC
Some armv7-m-based SoCs do not work with atomic instructions,
even though armv7-m supports them.

To avoid using atomic instructions generated by gcc,
CONFIG_LIBC_ARCH_ATOMIC is newly introduced with which
arch_atomic.c is linked explicitly.

However, the function names need to be changed to avoid
build errors, since the functions described in stdatomic.h
are gcc built-in and inlined when the code is compiled.

About libcxx with CONFIG_LIBC_ARCH_ATOMIC, it still
does not work. It is also needed to call nx_atomic_ ver
instead of __atomic ver in
libcxx/include/__atomic/cxx_atomic_lmpl.h.

Signed-off-by: Takuya Miyasita <Takuya.Miyashita@sony.com>
2024-11-15 14:01:56 +08:00
wangmingrong1 c19d440db0 arm64/mcount.c: Add to nuttx compilation
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-11-14 13:30:05 +08:00
Masayuki Ishikawa bbf2bbf37d Revert "arch_atomic : Introduce CONFIG_LIBC_ARCH_ATOMIC"
This reverts commit 81e7b13a05.
2024-11-13 10:45:12 +09:00
wangmingrong1 bf93c7840a gprof: move gprof function from sched to libbuiltin/libgcc
1. Enable interrupt gprof please config CONFIG_PROFILE_MINI
2. Enable instuction gprof please add compile opt "-pg" or config CONFIG_PROFILE_ALL

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-11-13 02:42:31 +08:00
Takuya Miyasita 81e7b13a05 arch_atomic : Introduce CONFIG_LIBC_ARCH_ATOMIC
Some armv7-m-based SoCs do not work with atomic instructions,
even though armv7-m supports them.

To avoid using atomic instructions generated by gcc,
CONFIG_LIBC_ARCH_ATOMIC is newly introduced with which
arch_atomic.c is linked explicitly.

However, the function names need to be changed to avoid
build errors, since the functions described in stdatomic.h
are gcc built-in and inlined when the code is compiled.

Signed-off-by: Takuya Miyasita <Takuya.Miyashita@sony.com>
2024-11-12 14:27:42 +09:00
xuxin19 299ef6234f cmake(bugfix):add xtensa libc machine function build
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-11-03 09:16:24 +08:00