Commit graph

202 commits

Author SHA1 Message Date
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
chenrun1
1fce345481 libc/machine/CMakeLists: should alaways build arch_atomic.c
Summary:
  This issue comes from https://github.com/apache/nuttx/pull/14570. In the previous Atomic implementation https://github.com/apache/nuttx/pull/13044, we have removed the CONFIG_LIBC_ARCH_ATOMIC macro, so arch_atomic.c should always be compiled.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-11-03 02:33:03 +08:00
wangmingrong1
fbaace01d0 libc/arch_libc: replace all arch define to ARCH_LIBCFUN(x) style
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-31 18:11:16 +08:00
wangmingrong1
b22e8c7c1c libc: Modify the check length
We should not check the length of both strings at the same time.

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-31 18:11:16 +08:00
wangmingrong1
e466c637fc arch_lib.c: close kasan readcheck no return
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-31 18:11:16 +08:00
anjiahao
22e5c88479 libs/machine:strnlen need check return
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-31 18:11:16 +08:00
anjiahao
603c87977f libc/machine:Add prefixes to libc functions implemented by arch
kasan does not instrument the assembly function,
so it is checked in advance before calling.
If Kasan is not turned on, the speed and space will
be almost unchanged under compiler optimization.

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-31 18:11:16 +08:00
cuiziwei
12fd5ec472 nuttx: Add LIBSUPCXX_TOOLCHAIN to link the prebuilt library provide by toolchain.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2024-10-24 01:38:03 +08:00
Gao Jiawei
89d6abf3df setjmp: fix setjmp returns 0 when calling longjmp with 0 as the second argument
Signed-off-by: Gao Jiawei <gaojiawei@xiaomi.com>
2024-10-15 12:36:19 +08:00
chao an
39c1c871a0 Revert "libc/atomic: decoupling atomic and spinlock to avoid recursion"
This reverts commit c37b0de28c.
2024-10-14 17:42:16 +08:00
zhanghu5
f8f6bfff29 use r1-r3 as tmp register
Signed-off-by: zhanghu5 <zhanghu5@xiaomi.com>
2024-10-13 10:12:27 +08:00
chao an
c37b0de28c libc/atomic: decoupling atomic and spinlock to avoid recursion
1. use irq save in AMP mode
2. use critical section in SMP mode

Signed-off-by: chao an <anchao@lixiang.com>
2024-10-13 10:00:22 +08:00
wangmingrong1
300ce45365 libc/machine: Fix the error caused by tag kasan
Use address addition and subtraction, no longer as the return value of the address. Tags must be removed before calculation

Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2024-10-11 01:29:56 +08:00
yinshengkai
d375a09c0a libs: add gprof arm64 support
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-10 18:46:51 +08:00
yinshengkai
eb8449cb0c sched/gprof: add gprof support
gprof can analyze code hot spots based on scheduled sampling.
After adding the "-pg" parameter when compiling, you can view the code call graph.

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2024-10-10 18:46:51 +08:00
liwenxiang1
4c19e75ff5 libs/x86_64:Add the setjmp/longjmp function
Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
2024-10-09 22:24:03 +08:00
chenxiaoyi
b39807fae0 sim: add windows64 setjmp/longjmp support
Signed-off-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
2024-10-04 08:21:35 +08:00
Alin Jerpelea
6b5dddd5d7 libs/libc: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-10-01 12:25:52 +08:00
chenrun1
76e83a5424 arch_atomic.c:Provide __sync_synchronize when the compiler does not support it
Summary:
  Configuration/Tool: zp214xpa/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
2024-09-14 06:11:00
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
  Building NuttX...
arm-none-eabi-ld: /github/workspace/sources/nuttx/staging/libfs.a(fs_inoderemove.o): in function `inode_remove':
fs_inoderemove.c:(.text.inode_remove+0x94): undefined reference to `__sync_synchronize'
arm-none-eabi-ld: fs_inoderemove.c:(.text.inode_remove+0x9c): undefined reference to `__sync_synchronize'
make[1]: *** [Makefile:212: nuttx] Error 1
make: *** [tools/Unix.mk:548: nuttx] Error 2
make: Target 'all' not remade because of errors.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-09-23 14:07:03 +08:00
anjiahao
e085f0ee80 armv8-m:arch libc function need save ip register use pacbti
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-19 03:50:53 +08:00
p-szafonimateusz
92cbb63fc8 arch/x86_64: add basic support for R_X86_64_REX_GOTPCRELX relocation
GOTPCRELX reloc available only for CONFIG_ARCH_ADDRENV=y

when CONFIG_ARCH_ADDRENV is not set, CONFIG_ARCH_TEXT_VBASE is not specified
so we can't relocate

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-09-17 03:20:03 +08:00
guoshichao
7f6fb9ce1c greenhills: add the "__sync_synchronize" func impl
we add ghs header file support using to fix the following link error:
[elxr] (error #412) unresolved symbols: 1
 __sync_synchronize 	from libopenamp.a(io.o)

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-24 18:07:12 +08:00
chenrun1
900e713cd0 atomic:Add more interfaces
Summary:
  1. add atomic_flag_test_and_set and atomic_flag_clear
  2. add typedef memory_order
  3. add atomic_flag

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:44:29 +08:00
chenrun1
8e1a042eef nuttx/atomic.h:Fix missing type declarations at compile time
Summary:
  1.Modify the conditions for entering different include header files
  2.Added pre-definition for _Atomic _Bool when it is missing
  3.Added nuttx for stdatomic implementation. When toolchain does not support atomic, use lib/stdatomic to implement it

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:44:29 +08:00
xuxin19
819685fbec cmake:bugfix enable ARCH_STRING_FUNCTION CMake build fail
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-14 20:58:59 +08:00
guoshichao
ed9d57b501 greenhills: fix the arch_setjmp.S build error
CC:  bch/bchlib_read.c [asarm] (error #2067) machine/arm/gnu/arch_setjmp.S 34: unknown instruction
  .syntax unified
--^

[asarm] (error #2230) machine/arm/gnu/arch_setjmp.S 62: bad directive
  .type setjmp , function
-----------------^

[asarm] (error) errors during processing

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-11 14:28:12 -03:00
Tiago Medicci Serrano
84d39a8d9a binfmt/libelf: Enable ELF loader if text heap read is word-aligned
The ELF loader needs to load the app into the memory before
executing it from the same location. As expected, this memory space
should be able to execute code. For architectures containing data
and instruction buses, the instruction bus may not be able to be
accessed in a non-aligned way, which is usually required when
copying data to that location. Eventually, this same memory space
can be accessed through the data bus, using different address
ranges. This commit enables accessing the memory through the data
bus to copy the app's data before executing it when
`CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ` is enabled.
2024-07-31 02:33:12 +08:00
chao an
7780cfc5a6 tricore/cmake: add support of cmake build for tricore
Toolchain Upstream:
https://github.com/EEESlab/tricore-gcc-toolchain-11.3.0

CMake command:
$ cmake -B build -DBOARD_CONFIG=tc397/nsh -GNinja
$ cmake --build build

Signed-off-by: chao an <anchao@lixiang.com>
2024-07-18 13:40:49 +08:00
p-szafonimateusz
53d112fa95 x86_64: add ELF support
add arch_elf64.c for x86_64, ported from sim/x86

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-07-03 17:40:53 +08:00
p-szafonimateusz
e6553eee5a libc/x86_64: port string functions from bionic
port optimized string functions for x86_64 from Bionic (BSD licensed)

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-07-02 23:59:18 +08:00
Yanfeng Liu
8ebc3aa9e8 arch/risc-v: initial qemu-rv64ilp32 support
This applies uintreg_t in risc-v commons and fixes araised ci issues
for multiple devices. The FLAT build runs on qemu-rv64ilp32 target.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2024-06-14 19:50:00 +08:00
simbit18
7677f10d3f fix nxstyle
fix Relative file path does not match actual file.
2024-04-16 19:09:12 +08:00
p-szafonimateusz
9b0017659c arch/x86_64: add cmake support
Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-02-23 07:45:57 +08:00
Peter van der Perk
40f4cde8f5 armv7-m: Expose section name to allow relocation 2024-01-04 15:07:18 +01:00
xuxin19
524425573e CMake:init arm64 CMake qemu-armv8a build
this patch contains arm64 Toolchain, arch common, qemu board and arm64 libc modifications.
support using CMake to compile the qemu executable file.

```
 cmake -B build -DBOARD_CONFIG=qemu-armv8a:nsh -GNinja
 cmake --build build -t menuconfig
 cmake --build build
 qemu-system-aarch64 -cpu cortex-a53 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx
```
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-12-27 07:27:17 -08:00
Ville Juven
90d73153fb riscv/arch_elf: Check for _HI20 relocation validity
As pointed out in #11322 there is a hardware design issue in RISC-V that
affects RV64 relocations. The problem is with how address bits are loaded
into registers via lui / auipc and sign extension.

If the hi20 relocation value happens to have its 32-bit sign bit set, i.e.
value is 0x80000000 (but not negative! i.e. negative in 64-bit format) the
relocation will fail, as the address is erroneously sign extended:

0x00000000_80000000 becomes 0xffffffff_80000000 which is not correct.

Also, make sure the correct opcode is used with PCREL_HI20, it expects
AUIPC (not LUI). The C compiler will never emit such code but when hand-
writing assembly code this can happen.
2023-12-14 06:54:17 -08:00
Ville Juven
996625ec58 riscv/arch_elf.c: Handle PCREL_HI20/LO12_I/S relocations correctly
There is a problem with the current elf loader for risc-v: when a pair of
PCREL_HI20 / LO12 relocations are encountered, it is assumed that these
will follow each other immediately, as follows:

label:
	auipc      a0, %pcrel_hi(symbol)    // R_RISCV_PCREL_HI20
	load/store a0, %pcrel_lo(label)(a0) // R_RISCV_PCREL_LO12_I/S

With this assumption, the hi/lo relocations are both done when a hi20
relocation entry is encountered, first to the current instruction (addr)
and to the next instruction (addr + 4).

However, this assumption is wrong. There is nothing in the elf relocation
specification[1] that mandates this. Thus, the hi/lo relocation always
needs to first fixup the hi-part, and when the lo-part is encountered, it
needs to find the corresponding hi relocation entry, via the given "label".
This necessitates (re-)visiting the relocation entries for the current
section as well as looking for "label" in the symbol table.

The NuttX elf loader does not allow such operations to be done in the
machine specific part, so this patch fixes the relocation issue by
introducing an architecture specific cache for the hi20 relocation and
symbol table entries. When a lo12 relocation is encountered, the cache
can be consulted to find the hi20 part.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc
2023-12-12 17:32:36 -08:00