Compare commits

...

6 commits

Author SHA1 Message Date
Huang Qi
156a34d49e
Merge d96ed13cbd into ff488133c9 2025-01-11 19:07:03 +08:00
Yanfeng Liu
ff488133c9 qemu-armv7a: allows ELF_EXECUTABLE
This allows using BINFMT_ELF_EXECUTABLE for qemu-armv7a target.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-01-11 18:54:36 +08:00
Yanfeng Liu
48846954d8 arm/Toolchain.defs: skip -r for ELF_EXECUTABLE
This avoids using `-r` option when linking executable programs.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-01-11 18:54:36 +08:00
Yanfeng Liu
657247bda8 libc/modlib: preprocess gnu-elf.ld
This generates gnu-elf.ld via preprocessing of gnu-elf.ld.in so
that to reduce board specific app linker scripts in kernel mode
when BINFMT_ELF_EXECUTABLE is enabled.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-01-11 18:54:36 +08:00
Yanfeng Liu
be40c01ddd nuttx/addrenv.h: revise assembly guard
This allows the header file to be useful from non-C sources such as
assembly code or linker scripts.

Signed-off-by: Yanfeng Liu <p-liuyanfeng9@xiaomi.com>
2025-01-11 18:54:36 +08:00
Huang Qi
d96ed13cbd risc-v: Accelerate schedule by percpu
Fetch TCB info in percpu scratch register for better performance.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-12-20 11:26:07 +08:00
9 changed files with 106 additions and 7 deletions

View file

@ -546,7 +546,9 @@ ifeq ($(CONFIG_PIC),y)
# Generate an executable elf, need to ignore undefined symbols
LDELFFLAGS += --unresolved-symbols=ignore-in-object-files --emit-relocs
else
LDELFFLAGS += -r
ifneq ($(CONFIG_BINFMT_ELF_EXECUTABLE),y)
LDELFFLAGS += -r
endif
endif
LDELFFLAGS += -e main -T $(call CONVERT_PATH,$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)modlib$(DELIM)gnu-elf.ld)

View file

@ -15,6 +15,7 @@ config ARCH_CHIP_QEMU_CORTEXA7
bool "Qemu virtual Processor (cortex-a7)"
select ARCH_CORTEXA7
select ARCH_HAVE_ADDRENV
select ARCH_HAVE_ELF_EXECUTABLE
select ARCH_HAVE_LOWVECTORS
select ARCH_HAVE_MULTICPU
select ARCH_NEED_ADDRENV_MAPPING

View file

@ -702,6 +702,29 @@ irqstate_t up_irq_enable(void);
int up_cpu_index(void) noinstrument_function;
/****************************************************************************
* Schedule acceleration macros
****************************************************************************/
/* If RISCV_PERCPU_SCRATCH is not enabled, we can use the scratch register
* to store the current task pointer.
*/
#ifndef CONFIG_RISCV_PERCPU_SCRATCH
#define up_this_task() \
({ \
struct tcb_s *t; \
t = (struct tcb_s *)READ_CSR(CSR_SCRATCH); \
t; \
})
#define up_update_task(t) WRITE_CSR(CSR_SCRATCH, (uintptr_t)t)
#else
/* TODO: Implement up_this_task()/up_update_task() if RISCV_PERCPU_SCRATCH
* enabled.
*/
#endif
/****************************************************************************
* Name: up_this_cpu
*

View file

@ -37,6 +37,8 @@
#include <nuttx/spinlock.h>
#include <nuttx/sched_note.h>
#include <arch/irq.h>
#include "sched/sched.h"
#include "init/init.h"
#include "riscv_internal.h"
@ -69,6 +71,8 @@
void riscv_cpu_boot(int cpu)
{
struct tcb_s *tcb;
/* Clear IPI for CPU(cpu) */
riscv_ipi_clear(cpu);
@ -100,8 +104,9 @@ void riscv_cpu_boot(int cpu)
sinfo("CPU%d Started\n", this_cpu());
tcb = current_task(this_cpu());
#ifdef CONFIG_STACK_COLORATION
struct tcb_s *tcb = this_task();
/* If stack debug is enabled, then fill the stack with a
* recognizable value that we can use later to test for high
@ -111,6 +116,8 @@ void riscv_cpu_boot(int cpu)
riscv_stack_color(tcb->stack_alloc_ptr, 0);
#endif
up_update_task(tcb);
/* TODO: Setup FPU */
/* Clear machine software interrupt for CPU(cpu) */

View file

@ -29,6 +29,8 @@
#include <nuttx/config.h>
#ifndef __ASSEMBLY__
#ifdef CONFIG_BUILD_KERNEL
# include <signal.h>
#endif
@ -40,6 +42,8 @@
#include <arch/arch.h>
#endif /* __ASSEMBLY__ */
#ifdef CONFIG_ARCH_ADDRENV
/****************************************************************************
@ -241,6 +245,9 @@
(CONFIG_ARCH_PGPOOL_VBASE + CONFIG_ARCH_PGPOOL_SIZE)
#endif
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Type Definitions
****************************************************************************/
@ -251,8 +258,6 @@ struct tcb_s; /* Forward reference to TCB */
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
struct addrenv_s
{
struct arch_addrenv_s addrenv; /* The address environment page directory */

View file

@ -1,2 +1,3 @@
/exec_symtab.c
/modlib_symtab.c
modlib/gnu-elf.ld

View file

@ -183,6 +183,10 @@ context:: bin kbin
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo context BIN=$(BIN)
endif
ifeq ($(CONFIG_LIBC_MODLIB),y)
$(Q) $(MAKE) -C modlib context
endif
# Dependencies
@ -210,6 +214,7 @@ depend:: .depend
clean::
$(Q) $(MAKE) -C zoneinfo clean BIN=$(BIN)
$(Q) $(MAKE) -C modlib clean
$(call DELFILE, $(BIN))
$(call DELFILE, $(KBIN))
$(call CLEAN)
@ -218,6 +223,7 @@ clean::
distclean:: clean
$(Q) $(MAKE) -C zoneinfo distclean BIN=$(BIN)
$(Q) $(MAKE) -C modlib distclean
$(call DELFILE, exec_symtab.c)
$(call DELFILE, .depend)
$(call DELDIR, bin)

40
libs/libc/modlib/Makefile Normal file
View file

@ -0,0 +1,40 @@
############################################################################
# libs/libc/modlib/Makefile
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
# Generate gnu-elf.ld from gnu-elf.ld.in
gnu-elf.ld: gnu-elf.ld.in
$(call PREPROCESS, $<, $@)
# Create initial context
context: gnu-elf.ld
.PHONY: context clean distclean
clean:
$(call CLEAN)
distclean: clean
$(call DELFILE, gnu-elf.ld)

View file

@ -1,5 +1,5 @@
/****************************************************************************
* libs/libc/modlib/gnu-elf.ld
* libs/libc/modlib/gnu-elf.ld.in
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -18,9 +18,23 @@
*
****************************************************************************/
#include <nuttx/config.h>
#if defined(CONFIG_BUILD_KERNEL) && defined(CONFIG_BINFMT_ELF_EXECUTABLE)
# define __ASSEMBLY__
# include <nuttx/addrenv.h>
# define TEXT CONFIG_ARCH_TEXT_VBASE
# define DATA CONFIG_ARCH_DATA_VBASE + ARCH_DATA_RESERVE_SIZE
#else
# define TEXT 0x0
# define DATA
#endif
SECTIONS
{
.text 0x00000000 :
.text TEXT :
{
_stext = . ;
*(.text)
@ -58,7 +72,7 @@ SECTIONS
_erodata = . ;
}
.data :
.data DATA :
{
_sdata = . ;
*(.data)