Compare commits

...

6 commits

Author SHA1 Message Date
Mike.
6a2566a3e0
Merge de2174bc46 into ff488133c9 2025-01-11 19:05:51 +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
wangmingrong1
de2174bc46 macro/align: Use ALIGN_UP and ALIGN_DOWN uniformly
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-11 01:10:45 +08:00
18 changed files with 120 additions and 62 deletions

View file

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

View file

@ -1103,7 +1103,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
&src_freq); &src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -1161,7 +1161,7 @@ static void imxrt_lpi2c_setclock(struct imxrt_lpi2c_priv_s *priv,
#endif #endif
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

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

View file

@ -1010,7 +1010,7 @@ static void s32k1xx_lpi2c_setclock(struct s32k1xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0); DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -990,7 +990,7 @@ static void s32k3xx_lpi2c_setclock(struct s32k3xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0); DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -1122,7 +1122,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
imx9_get_rootclock(priv->config->clk_root, &src_freq); imx9_get_rootclock(priv->config->clk_root, &src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) / /* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale) * (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
* *
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2 * Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/ */

View file

@ -31,18 +31,13 @@
#include <errno.h> #include <errno.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/nuttx.h>
#include <nuttx/binfmt/binfmt.h> #include <nuttx/binfmt/binfmt.h>
#include "binfmt.h" #include "binfmt.h"
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE) #if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -98,7 +93,7 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
case SPAWN_FILE_ACTION_OPEN: case SPAWN_FILE_ACTION_OPEN:
open = (FAR struct spawn_open_file_action_s *)entry; open = (FAR struct spawn_open_file_action_s *)entry;
size += ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)), size += ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
sizeof(FAR void *)); sizeof(FAR void *));
break; break;
@ -155,7 +150,7 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
strcpy(open->path, tmp->path); strcpy(open->path, tmp->path);
buffer = (FAR char *)buffer + buffer = (FAR char *)buffer +
ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)), ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
sizeof(FAR void *)); sizeof(FAR void *));
break; break;

View file

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

View file

@ -35,6 +35,7 @@
#include <nuttx/init.h> #include <nuttx/init.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h> #include <nuttx/fs/fs.h>
#include <nuttx/nuttx.h>
#include <nuttx/spinlock.h> #include <nuttx/spinlock.h>
/**************************************************************************** /****************************************************************************
@ -112,11 +113,6 @@
#define MAXARCS (1 << 20) #define MAXARCS (1 << 20)
/* General rounding functions. */
#define ROUNDDOWN(x, y) (((x) / (y)) * (y))
#define ROUNDUP(x, y) ((((x) + (y) - 1) / (y)) * (y))
/* See profil(2) where this is described (incorrectly) */ /* See profil(2) where this is described (incorrectly) */
#define SCALE_1_TO_1 0x10000 #define SCALE_1_TO_1 0x10000
@ -288,12 +284,12 @@ void moncontrol(int mode)
if (mode) if (mode)
{ {
uintptr_t lowpc = ROUNDDOWN((uintptr_t)&_stext, uintptr_t lowpc = ALIGN_DOWN((uintptr_t)&_stext,
HISTFRACTION * sizeof(HISTCOUNTER)); HISTFRACTION * sizeof(HISTCOUNTER));
uintptr_t highpc = ROUNDUP((uintptr_t)&_etext, uintptr_t highpc = ALIGN_UP((uintptr_t)&_etext,
HISTFRACTION * sizeof(HISTCOUNTER)); HISTFRACTION * sizeof(HISTCOUNTER));
size_t textsize = highpc - lowpc; size_t textsize = highpc - lowpc;
size_t kcountsize = ROUNDUP(textsize / HISTFRACTION, size_t kcountsize = ALIGN_UP(textsize / HISTFRACTION,
sizeof(*p->kcount)); sizeof(*p->kcount));
int scale = kcountsize >= textsize ? SCALE_1_TO_1 : int scale = kcountsize >= textsize ? SCALE_1_TO_1 :
(float)kcountsize / textsize * SCALE_1_TO_1; (float)kcountsize / textsize * SCALE_1_TO_1;
@ -370,10 +366,10 @@ void monstartup(unsigned long lowpc, unsigned long highpc)
* so the rest of the scaling (here and in gprof) stays in ints. * so the rest of the scaling (here and in gprof) stays in ints.
*/ */
lowpc = ROUNDDOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER)); lowpc = ALIGN_DOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
highpc = ROUNDUP(highpc, HISTFRACTION * sizeof(HISTCOUNTER)); highpc = ALIGN_UP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
textsize = highpc - lowpc; textsize = highpc - lowpc;
fromssize = ROUNDUP(textsize / HASHFRACTION, sizeof(*p->froms)); fromssize = ALIGN_UP(textsize / HASHFRACTION, sizeof(*p->froms));
tolimit = textsize * ARCDENSITY / 100; tolimit = textsize * ARCDENSITY / 100;
if (tolimit < MINARCS) if (tolimit < MINARCS)

View file

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

View file

@ -183,6 +183,10 @@ context:: bin kbin
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y) ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo context BIN=$(BIN) $(Q) $(MAKE) -C zoneinfo context BIN=$(BIN)
endif endif
ifeq ($(CONFIG_LIBC_MODLIB),y)
$(Q) $(MAKE) -C modlib context
endif
# Dependencies # Dependencies
@ -210,6 +214,7 @@ depend:: .depend
clean:: clean::
$(Q) $(MAKE) -C zoneinfo clean BIN=$(BIN) $(Q) $(MAKE) -C zoneinfo clean BIN=$(BIN)
$(Q) $(MAKE) -C modlib clean
$(call DELFILE, $(BIN)) $(call DELFILE, $(BIN))
$(call DELFILE, $(KBIN)) $(call DELFILE, $(KBIN))
$(call CLEAN) $(call CLEAN)
@ -218,6 +223,7 @@ clean::
distclean:: clean distclean:: clean
$(Q) $(MAKE) -C zoneinfo distclean BIN=$(BIN) $(Q) $(MAKE) -C zoneinfo distclean BIN=$(BIN)
$(Q) $(MAKE) -C modlib distclean
$(call DELFILE, exec_symtab.c) $(call DELFILE, exec_symtab.c)
$(call DELFILE, .depend) $(call DELFILE, .depend)
$(call DELDIR, bin) $(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 * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with * 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 SECTIONS
{ {
.text 0x00000000 : .text TEXT :
{ {
_stext = . ; _stext = . ;
*(.text) *(.text)
@ -58,7 +72,7 @@ SECTIONS
_erodata = . ; _erodata = . ;
} }
.data : .data DATA :
{ {
_sdata = . ; _sdata = . ;
*(.data) *(.data)

View file

@ -41,8 +41,6 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG) #if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
# define ioberr _err # define ioberr _err
# define iobwarn _warn # define iobwarn _warn

View file

@ -35,6 +35,7 @@
#ifdef CONFIG_IOB_ALLOC #ifdef CONFIG_IOB_ALLOC
# include <nuttx/kmalloc.h> # include <nuttx/kmalloc.h>
#endif #endif
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h> #include <nuttx/mm/iob.h>
#include "iob.h" #include "iob.h"
@ -333,7 +334,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
FAR struct iob_s *iob; FAR struct iob_s *iob;
size_t alignsize; size_t alignsize;
alignsize = ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size; alignsize = ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize); iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize);
if (iob) if (iob)
@ -344,7 +345,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
iob->io_bufsize = size; /* Total length of the iob buffer */ iob->io_bufsize = size; /* Total length of the iob buffer */
iob->io_pktlen = 0; /* Total length of the packet */ iob->io_pktlen = 0; /* Total length of the packet */
iob->io_free = iob_free_dynamic; /* Customer free callback */ iob->io_free = iob_free_dynamic; /* Customer free callback */
iob->io_data = (FAR uint8_t *)ROUNDUP((uintptr_t)(iob + 1), iob->io_data = (FAR uint8_t *)ALIGN_UP((uintptr_t)(iob + 1),
CONFIG_IOB_ALIGNMENT); CONFIG_IOB_ALIGNMENT);
} }

View file

@ -28,6 +28,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h> #include <nuttx/mm/iob.h>
#include "iob.h" #include "iob.h"
@ -39,10 +40,10 @@
/* Fix the I/O Buffer size with specified alignment size */ /* Fix the I/O Buffer size with specified alignment size */
#ifdef CONFIG_IOB_ALLOC #ifdef CONFIG_IOB_ALLOC
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \ # define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
CONFIG_IOB_ALIGNMENT) CONFIG_IOB_ALIGNMENT)
#else #else
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) # define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
#endif #endif
#define IOB_BUFFER_SIZE (IOB_ALIGN_SIZE * CONFIG_IOB_NBUFFERS + \ #define IOB_BUFFER_SIZE (IOB_ALIGN_SIZE * CONFIG_IOB_NBUFFERS + \
@ -137,7 +138,7 @@ void iob_initialize(void)
* aligned to the CONFIG_IOB_ALIGNMENT memory boundary * aligned to the CONFIG_IOB_ALIGNMENT memory boundary
*/ */
buf = ROUNDUP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data), buf = ALIGN_UP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data); CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data);
/* Get I/O buffer instance from the start address and add each I/O buffer /* Get I/O buffer instance from the start address and add each I/O buffer

View file

@ -32,6 +32,7 @@
#include <nuttx/coredump.h> #include <nuttx/coredump.h>
#include <nuttx/elf.h> #include <nuttx/elf.h>
#include <nuttx/nuttx.h>
#include <nuttx/sched.h> #include <nuttx/sched.h>
#include "sched/sched.h" #include "sched/sched.h"
@ -54,9 +55,6 @@
#define PROGRAM_ALIGNMENT 64 #define PROGRAM_ALIGNMENT 64
#define ROUNDUP(x, y) ((x + (y - 1)) / (y)) * (y)
#define ROUNDDOWN(x ,y) (((x) / (y)) * (y))
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
@ -166,7 +164,7 @@ static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
static int elf_emit_align(FAR struct elf_dumpinfo_s *cinfo) static int elf_emit_align(FAR struct elf_dumpinfo_s *cinfo)
{ {
off_t align = ROUNDUP(cinfo->stream->nput, off_t align = ALIGN_UP(cinfo->stream->nput,
ELF_PAGESIZE) - cinfo->stream->nput; ELF_PAGESIZE) - cinfo->stream->nput;
unsigned char null[256]; unsigned char null[256];
off_t total = align; off_t total = align;
@ -258,9 +256,9 @@ static int elf_get_note_size(int stksegs)
{ {
int total; int total;
total = stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) + total = stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prstatus_t)); sizeof(elf_prstatus_t));
total += stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) + total += stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prpsinfo_t)); sizeof(elf_prpsinfo_t));
return total; return total;
} }
@ -414,8 +412,8 @@ static void elf_emit_tcb_stack(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr); (tcb->stack_base_ptr - tcb->stack_alloc_ptr);
} }
sp = ROUNDDOWN(buf, PROGRAM_ALIGNMENT); sp = ALIGN_DOWN(buf, PROGRAM_ALIGNMENT);
len = ROUNDUP(len + (buf - sp), PROGRAM_ALIGNMENT); len = ALIGN_UP(len + (buf - sp), PROGRAM_ALIGNMENT);
buf = sp; buf = sp;
elf_emit(cinfo, (FAR void *)buf, len); elf_emit(cinfo, (FAR void *)buf, len);
@ -546,17 +544,17 @@ static void elf_emit_tcb_phdr(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr); (tcb->stack_base_ptr - tcb->stack_alloc_ptr);
} }
sp = ROUNDDOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT); sp = ALIGN_DOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT);
phdr->p_filesz = ROUNDUP(phdr->p_filesz + phdr->p_filesz = ALIGN_UP(phdr->p_filesz +
(phdr->p_vaddr - sp), PROGRAM_ALIGNMENT); (phdr->p_vaddr - sp), PROGRAM_ALIGNMENT);
phdr->p_vaddr = sp; phdr->p_vaddr = sp;
phdr->p_type = PT_LOAD; phdr->p_type = PT_LOAD;
phdr->p_offset = ROUNDUP(*offset, ELF_PAGESIZE); phdr->p_offset = ALIGN_UP(*offset, ELF_PAGESIZE);
phdr->p_paddr = phdr->p_vaddr; phdr->p_paddr = phdr->p_vaddr;
phdr->p_memsz = phdr->p_filesz; phdr->p_memsz = phdr->p_filesz;
phdr->p_flags = PF_X | PF_W | PF_R; phdr->p_flags = PF_X | PF_W | PF_R;
*offset += ROUNDUP(phdr->p_memsz, ELF_PAGESIZE); *offset += ALIGN_UP(phdr->p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, phdr, sizeof(*phdr)); elf_emit(cinfo, phdr, sizeof(*phdr));
} }
@ -608,13 +606,13 @@ static void elf_emit_phdr(FAR struct elf_dumpinfo_s *cinfo,
for (i = 0; i < memsegs; i++) for (i = 0; i < memsegs; i++)
{ {
phdr.p_type = PT_LOAD; phdr.p_type = PT_LOAD;
phdr.p_offset = ROUNDUP(offset, ELF_PAGESIZE); phdr.p_offset = ALIGN_UP(offset, ELF_PAGESIZE);
phdr.p_vaddr = cinfo->regions[i].start; phdr.p_vaddr = cinfo->regions[i].start;
phdr.p_paddr = phdr.p_vaddr; phdr.p_paddr = phdr.p_vaddr;
phdr.p_filesz = cinfo->regions[i].end - cinfo->regions[i].start; phdr.p_filesz = cinfo->regions[i].end - cinfo->regions[i].start;
phdr.p_memsz = phdr.p_filesz; phdr.p_memsz = phdr.p_filesz;
phdr.p_flags = cinfo->regions[i].flags; phdr.p_flags = cinfo->regions[i].flags;
offset += ROUNDUP(phdr.p_memsz, ELF_PAGESIZE); offset += ALIGN_UP(phdr.p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, &phdr, sizeof(phdr)); elf_emit(cinfo, &phdr, sizeof(phdr));
} }
} }