Commit Graph

25 Commits

Author SHA1 Message Date
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
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
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
yangdongdong 1956385a7d libs/libc: Breakdown LIBC_BUILD_STRING into specific string operations macro.
Provide a way to only customize specific string operations,
such as for memcpy with the DMA capability by ROM.

Signed-off-by: yangdongdong <yangdongdong@xiaomi.com>
2023-08-29 22:55:18 +08:00
chenrun1 fb74c46e4d arm64/gnu:Set arch_* optimizations to be on by default.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2023-08-19 18:43:08 +08:00
chao an 6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Xiang Xiao b5c48f3ed8 binfmt: Always include arch/elf.h in include/nuttx/elf.h
since symbols defined in arch/elf.h is also used in other case, for example:
CC:  pthread/pthread_testcancel.c machine/arm/gnu_unwind_find_exidx.c:32:8: error: unknown type name '__EIT_entry'
   32 | static __EIT_entry *__exidx_start_elf;
      |        ^~~~~~~~~~~

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-25 19:02:53 -03:00
Tiago Medicci Serrano 58e97e521c libc/string: prevent libc in the kernel/userspace optionally
Add the `LIBC_PREVENT_STRING_KERNEL` and `LIBC_PREVENT_STRING_USER`
that are meant to be selected by the chip if no libc implementation
is going to be built. If selected, neither NuttX's software version
of the libc nor any architecture-specific implementation will be
built in the kernel or in the userspace, respectively. In this
case, the linker may provide a ROM-defined version of the libc
functions instead.
2023-05-17 13:58:48 +08:00
Tiago Medicci Serrano d3ffeb40a7 libc/machine/xtensa: make longjmp safe against context switch
In order to turn longjmp context-switch safe, it's necessary
to disable interrupts before modifying windowbase and windowstart.
Otherwise, after a context switch, windowstart and windowbase
would be different, leading to a wrongly set windowstart bit due to
longjmp writing it based on the windowbase before the context switch.
This corrupts the registers at the next window overflow reaching
that wrongly set bit.

*Background:*
This PR is related to an issue first observed on ESP-IDF
https://github.com/espressif/esp-idf/issues/5229 and it was, then,
checked on NuttX using a test application.

*The test application:*
To check if the problem affects ESP32, ESP32-S2 and ESP32-S3 on
NuttX, it was created an application based on:
https://en.cppreference.com/w/c/program/longjmp

The application creates 16 tasks (`#define NUMBER_OF_TASKS  16`)
that implements the following daemon:

```
static int setjmp_longjmp_daemon(int argc, char *argv[])
{
  for (int i = 0; i < NUMBER_OF_TASKS * 2; i++)
    {
      jmp_buf env;

      volatile int count = 0;
      if (setjmp(env) != UINT16_MAX)
        {
          foo(&env, ++count);
        }
    }

  sem_post(&g_sem);

  return EXIT_SUCCESS;
}
```

The main function also initializes a semaphore to avoid application
exiting before tasks return successfully:

```
  sem_init(&g_sem, 0, -NUMBER_OF_TASKS);
```

Finally, the round-robin interval was lowered to 1ms to raise the
chances of the longjmp being interrupted by a context switch
(`CONFIG_RR_INTERVAL=1).

This setup was able to reproduce the problem prior to this patch
being applied.
2022-11-22 19:34:44 +01:00
Nathan Hartman 849f760b77 Fix various typos 2022-07-08 02:15:54 +08:00
zhuyanlin 3455002ffd libc:xtensa:arch_memmove: fix warning
warning: 'SIM_CHECKS_ALIGNMENT' macro redefined
[-Wmacro-redefined] #define SIM_CHECKS_ALIGNMENT 1

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-06-07 11:09:57 +03:00
Xiang Xiao 51cf7ba05a Remove FAR from arm/risc-v/xtensa/sim/x86
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-15 13:55:58 +03:00
zhuyanlin 38f8032e31 libc:xtensa: move syscall to swint call
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-05-11 10:48:53 +02:00
zhuyanlin 1aedf30f38 libc:machine:xtensa: fix warning
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-02-24 22:13:46 +08:00
Xiang Xiao 1d1bdd85a3 Remove the double blank line from source files
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-20 20:10:14 +01:00
Petro Karashchenko 51a2db6ffc Kconfig: improve uniformity
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2021-12-14 07:32:48 -06:00
zhuyanlin 5a4140f020 arch:xtensa: add setjmp xtensa function
N/A

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2021-11-06 07:39:27 -05:00
zhuyanlin cfcff5f570 libc:machine:xtensa:add xtensa libc implement
N/A

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2021-11-06 07:39:27 -05:00
Abdelatif Guettouche d85c432278 Few typos fixes in binfmt and libc/machine.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-03-11 10:35:40 +08:00
YAMAMOTO Takashi df44909b30 xtensa/arch_elf.c: Ignore R_XTENSA_NONE
Now examples/sotest passes on qemu.
2020-03-16 07:54:49 -06:00
YAMAMOTO Takashi e135c938d2 xtensa: Implement a few relocations 2020-03-16 07:54:49 -06:00
YAMAMOTO Takashi 2776a5bbea Replace a few Gregory Nutt's copyright notices with Apache 2.0
The text was copied from sched/sched/sched_getcpu.c.
2020-03-16 07:54:49 -06:00
YAMAMOTO Takashi b2627225bd Update file paths of copy-and-paste'ed files 2020-03-16 07:54:49 -06:00
YAMAMOTO Takashi c7526e551e arch_elf.c: Appease nxstyle errors 2020-03-16 07:54:49 -06:00
YAMAMOTO Takashi 5e1b24f012 xtensa: Add modlib boilerplate
This is a modified copy of armv6-m/armv7-m version.
2020-03-16 07:54:49 -06:00