mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-07 17:35:22 +08:00
Cleared last differences, ready for testing
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,243 +0,0 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/include/syscall.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Reference: "ELF for the ARM® Architecture," ARM IHI 0044D, current through
|
||||
* ABI release 2.08, October 28, 2009, ARM Limited.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_ARM_INCLUDE_ELF_H
|
||||
#define __ARCH_ARM_INCLUDE_ELF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* 4.3.1 ELF Identification. Should have:
|
||||
*
|
||||
* e_machine = EM_ARM
|
||||
* e_ident[EI_CLASS] = ELFCLASS32
|
||||
* e_ident[EI_DATA] = ELFDATA2LSB (little endian) or ELFDATA2MSB (big endian)
|
||||
*/
|
||||
|
||||
#if 0 /* Defined in include/elf32.h */
|
||||
#define EM_ARM 40
|
||||
#endif
|
||||
|
||||
/* Table 4-2, ARM-specific e_flags */
|
||||
|
||||
#define EF_ARM_EABI_MASK 0xff000000
|
||||
#define EF_ARM_EABI_UNKNOWN 0x00000000
|
||||
#define EF_ARM_EABI_VER1 0x01000000
|
||||
#define EF_ARM_EABI_VER2 0x02000000
|
||||
#define EF_ARM_EABI_VER3 0x03000000
|
||||
#define EF_ARM_EABI_VER4 0x04000000
|
||||
#define EF_ARM_EABI_VER5 0x05000000
|
||||
|
||||
#define EF_ARM_BE8 0x00800000
|
||||
|
||||
/* Table 4-4, Processor specific section types */
|
||||
|
||||
#define SHT_ARM_EXIDX 0x70000001 /* Exception Index table */
|
||||
#define SHT_ARM_PREEMPTMAP 0x70000002 /* BPABI DLL dynamic linking pre-emption map */
|
||||
#define SHT_ARM_ATTRIBUTES 0x70000003 /* Object file compatibility attributes */
|
||||
#define SHT_ARM_DEBUGOVERLAY 0x70000004
|
||||
#define SHT_ARM_OVERLAYSECTION 0x70000005
|
||||
|
||||
/* 4.7.1 Relocation codes
|
||||
*
|
||||
* S (when used on its own) is the address of the symbol.
|
||||
* A is the addend for the relocation.
|
||||
* P is the address of the place being relocated (derived from r_offset).
|
||||
* Pa is the adjusted address of the place being relocated, defined as (P & 0xFFFFFFFC).
|
||||
* T is 1 if the target symbol S has type STT_FUNC and the symbol addresses a Thumb instruction;
|
||||
* it is 0 otherwise.
|
||||
* B(S) is the addressing origin of the output segment defining the symbol S.
|
||||
* GOT_ORG is the addressing origin of the Global Offset Table
|
||||
* GOT(S) is the address of the GOT entry for the symbol S.
|
||||
*/
|
||||
|
||||
#define R_ARM_NONE 0 /* No relocation */
|
||||
#define R_ARM_PC24 1 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_ABS32 2 /* Data (S + A) | T */
|
||||
#define R_ARM_REL32 3 /* Data ((S + A) | T) - P */
|
||||
#define R_ARM_LDR_PC_G0 4 /* ARM S + A - P */
|
||||
#define R_ARM_ABS16 5 /* Data S + A */
|
||||
#define R_ARM_ABS12 6 /* ARM S + A */
|
||||
#define R_ARM_THM_ABS5 7 /* Thumb16 S + A */
|
||||
#define R_ARM_ABS8 8 /* Data S + A */
|
||||
#define R_ARM_SBREL32 9 /* Data ((S + A) | T) - B(S) */
|
||||
#define R_ARM_THM_CALL 10 /* Thumb32 ((S + A) | T) - P */
|
||||
#define R_ARM_THM_PC8 11 /* Thumb16 S + A - Pa */
|
||||
#define R_ARM_BREL_ADJ 12 /* Data ?B(S) + A */
|
||||
#define R_ARM_TLS_DESC 13 /* Data */
|
||||
#define R_ARM_THM_SWI8 14 /* Obsolete */
|
||||
#define R_ARM_XPC25 15 /* Obsolete */
|
||||
#define R_ARM_THM_XPC22 16 /* Obsolete */
|
||||
#define R_ARM_TLS_DTPMOD32 17 /* Data Module[S] */
|
||||
#define R_ARM_TLS_DTPOFF32 18 /* Data S + A - TLS */
|
||||
#define R_ARM_TLS_TPOFF32 19 /* Data S + A - tp */
|
||||
#define R_ARM_COPY 20 /* Miscellaneous */
|
||||
#define R_ARM_GLOB_DAT 21 /* Data (S + A) | T */
|
||||
#define R_ARM_JUMP_SLOT 22 /* Data (S + A) | T */
|
||||
#define R_ARM_RELATIVE 23 /* Data B(S) + A */
|
||||
#define R_ARM_GOTOFF32 24 /* Data ((S + A) | T) - GOT_ORG */
|
||||
#define R_ARM_BASE_PREL 25 /* Data B(S) + A - P */
|
||||
#define R_ARM_GOT_BREL 26 /* Data GOT(S) + A - GOT_ORG */
|
||||
#define R_ARM_PLT32 27 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_CALL 28 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_JUMP24 29 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_THM_JUMP24 30 /* Thumb32 ((S + A) | T) - P */
|
||||
#define R_ARM_BASE_ABS 31 /* Data B(S) + A */
|
||||
#define R_ARM_ALU_PCREL_7_0 32 /* Obsolete */
|
||||
#define R_ARM_ALU_PCREL_15_8 33 /* Obsolete */
|
||||
#define R_ARM_ALU_PCREL_23_15 34 /* Obsolete */
|
||||
#define R_ARM_LDR_SBREL_11_0_NC 35 /* ARM S + A - B(S) */
|
||||
#define R_ARM_ALU_SBREL_19_12_NC 36 /* ARM S + A - B(S) */
|
||||
#define R_ARM_ALU_SBREL_27_20_CK 37 /* ARM S + A - B(S) */
|
||||
#define R_ARM_TARGET1 38 /* Miscellaneous (S + A) | T or ((S + A) | T) - P */
|
||||
#define R_ARM_SBREL31 39 /* Data ((S + A) | T) - B(S) */
|
||||
#define R_ARM_V4BX 40 /* Miscellaneous */
|
||||
#define R_ARM_TARGET2 41 /* Miscellaneous */
|
||||
#define R_ARM_PREL31 42 /* Data ((S + A) | T) - P */
|
||||
#define R_ARM_MOVW_ABS_NC 43 /* ARM (S + A) | T */
|
||||
#define R_ARM_MOVT_ABS 44 /* ARM S + A */
|
||||
#define R_ARM_MOVW_PREL_NC 45 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_MOVT_PREL 46 /* ARM S + A - P */
|
||||
#define R_ARM_THM_MOVW_ABS_NC 47 /* Thumb32 (S + A) | T */
|
||||
#define R_ARM_THM_MOVT_ABS 48 /* Thumb32 S + A */
|
||||
#define R_ARM_THM_MOVW_PREL_NC 49 /* Thumb32 ((S + A) | T) - P */
|
||||
#define R_ARM_THM_MOVT_PREL 50 /* Thumb32 S + A - P */
|
||||
#define R_ARM_THM_JUMP19 51 /* Thumb32 ((S + A) | T) - P */
|
||||
#define R_ARM_THM_JUMP6 52 /* Thumb16 S + A - P */
|
||||
#define R_ARM_THM_ALU_PREL_11_0 53 /* Thumb32 ((S + A) | T) - Pa */
|
||||
#define R_ARM_THM_PC12 54 /* Thumb32 S + A - Pa */
|
||||
#define R_ARM_ABS32_NOI 55 /* Data S + A */
|
||||
#define R_ARM_REL32_NOI 56 /* Data S + A - P */
|
||||
#define R_ARM_ALU_PC_G0_NC 57 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_ALU_PC_G0 58 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_ALU_PC_G1_NC 59 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_ALU_PC_G1 60 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_ALU_PC_G2 61 /* ARM ((S + A) | T) - P */
|
||||
#define R_ARM_LDR_PC_G1 62 /* ARM S + A - P */
|
||||
#define R_ARM_LDR_PC_G2 63 /* ARM S + A - P */
|
||||
#define R_ARM_LDRS_PC_G0 64 /* ARM S + A - P */
|
||||
#define R_ARM_LDRS_PC_G1 65 /* ARM S + A - P */
|
||||
#define R_ARM_LDRS_PC_G2 66 /* ARM S + A - P */
|
||||
#define R_ARM_LDC_PC_G0 67 /* ARM S + A - P */
|
||||
#define R_ARM_LDC_PC_G1 68 /* ARM S + A - P */
|
||||
#define R_ARM_LDC_PC_G2 69 /* ARM S + A - P */
|
||||
#define R_ARM_ALU_SB_G0_NC 70 /* ARM ((S + A) | T) - B(S) */
|
||||
#define R_ARM_ALU_SB_G0 71 /* ARM ((S + A) | T) - B(S) */
|
||||
#define R_ARM_ALU_SB_G1_NC 72 /* ARM ((S + A) | T) - B(S) */
|
||||
#define R_ARM_ALU_SB_G1 73 /* ARM ((S + A) | T) - B(S) */
|
||||
#define R_ARM_ALU_SB_G2 74 /* ARM ((S + A) | T) - B(S) */
|
||||
#define R_ARM_LDR_SB_G0 75 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDR_SB_G1 76 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDR_SB_G2 77 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDRS_SB_G0 78 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDRS_SB_G1 79 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDRS_SB_G2 80 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDC_SB_G0 81 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDC_SB_G1 82 /* ARM S + A - B(S) */
|
||||
#define R_ARM_LDC_SB_G2 83 /* ARM S + A - B(S) */
|
||||
#define R_ARM_MOVW_BREL_NC 84 /* ARM ((S + A) | T) - B(S) */
|
||||
#define R_ARM_MOVT_BREL 85 /* ARM S + A - B(S) */
|
||||
#define R_ARM_MOVW_BREL 86 /* ARM ((S + A) | T) - B(S) */
|
||||
#define R_ARM_THM_MOVW_BREL_NC 87 /* Thumb32 ((S + A) | T) - B(S) */
|
||||
#define R_ARM_THM_MOVT_BREL 88 /* Thumb32 S + A - B(S) */
|
||||
#define R_ARM_THM_MOVW_BREL 89 /* Thumb32 ((S + A) | T) - B(S) */
|
||||
#define R_ARM_TLS_GOTDESC 90 /* Data */
|
||||
#define R_ARM_TLS_CALL 91 /* ARM */
|
||||
#define R_ARM_TLS_DESCSEQ 92 /* ARM TLS relaxation */
|
||||
#define R_ARM_THM_TLS_CALL 93 /* Thumb32 */
|
||||
#define R_ARM_PLT32_ABS 94 /* Data PLT(S) + A */
|
||||
#define R_ARM_GOT_ABS 95 /* Data GOT(S) + A */
|
||||
#define R_ARM_GOT_PREL 96 /* Data GOT(S) + A - P */
|
||||
#define R_ARM_GOT_BREL12 97 /* ARM GOT(S) + A - GOT_ORG */
|
||||
#define R_ARM_GOTOFF12 98 /* ARM S + A - GOT_ORG */
|
||||
#define R_ARM_GOTRELAX 99 /* Miscellaneous */
|
||||
#define R_ARM_GNU_VTENTRY 100 /* Data */
|
||||
#define R_ARM_GNU_VTINHERIT 101 /* Data */
|
||||
#define R_ARM_THM_JUMP11 102 /* Thumb16 S + A - P */
|
||||
#define R_ARM_THM_JUMP8 103 /* Thumb16 S + A - P */
|
||||
#define R_ARM_TLS_GD32 104 /* Data GOT(S) + A - P */
|
||||
#define R_ARM_TLS_LDM32 105 /* Data GOT(S) + A - P */
|
||||
#define R_ARM_TLS_LDO32 106 /* Data S + A - TLS */
|
||||
#define R_ARM_TLS_IE32 107 /* Data GOT(S) + A - P */
|
||||
#define R_ARM_TLS_LE32 108 /* Data S + A - tp */
|
||||
#define R_ARM_TLS_LDO12 109 /* ARM S + A - TLS */
|
||||
#define R_ARM_TLS_LE12 110 /* ARM S + A - tp */
|
||||
#define R_ARM_TLS_IE12GP 111 /* ARM GOT(S) + A - GOT_ORG */
|
||||
#define R_ARM_ME_TOO 128 /* Obsolete */
|
||||
#define R_ARM_THM_TLS_DESCSEQ16 129 /* Thumb16 */
|
||||
#define R_ARM_THM_TLS_DESCSEQ32 130 /* Thumb32 */
|
||||
|
||||
/* 5.2.1 Platform architecture compatibility data */
|
||||
|
||||
#define PT_ARM_ARCHEXT_FMTMSK 0xff000000
|
||||
#define PT_ARM_ARCHEXT_PROFMSK 0x00ff0000
|
||||
#define PT_ARM_ARCHEXT_ARCHMSK 0x000000ff
|
||||
|
||||
#define PT_ARM_ARCHEXT_FMT_OS 0x00000000
|
||||
#define PT_ARM_ARCHEXT_FMT_ABI 0x01000000
|
||||
|
||||
#define PT_ARM_ARCHEXT_PROF_NONE 0x00000000
|
||||
#define PT_ARM_ARCHEXT_PROF_ARM 0x00410000
|
||||
#define PT_ARM_ARCHEXT_PROF_RT 0x00520000
|
||||
#define PT_ARM_ARCHEXT_PROF_MC 0x004d0000
|
||||
#define PT_ARM_ARCHEXT_PROF_CLASSIC 0x00530000
|
||||
|
||||
#define PT_ARM_ARCHEXT_ARCH_UNKNOWN 0x00
|
||||
#define PT_ARM_ARCHEXT_ARCHv4 0x01
|
||||
#define PT_ARM_ARCHEXT_ARCHv4T 0x02
|
||||
#define PT_ARM_ARCHEXT_ARCHv5T 0x03
|
||||
#define PT_ARM_ARCHEXT_ARCHv5TE 0x04
|
||||
#define PT_ARM_ARCHEXT_ARCHv5TEJ 0x05
|
||||
#define PT_ARM_ARCHEXT_ARCHv6 0x06
|
||||
#define PT_ARM_ARCHEXT_ARCHv6KZ 0x07
|
||||
#define PT_ARM_ARCHEXT_ARCHv6T2 0x08
|
||||
#define PT_ARM_ARCHEXT_ARCHv6K 0x09
|
||||
#define PT_ARM_ARCHEXT_ARCHv7 0x0a
|
||||
#define PT_ARM_ARCHEXT_ARCHv6M 0x0b
|
||||
#define PT_ARM_ARCHEXT_ARCHv6SM 0x0c
|
||||
#define PT_ARM_ARCHEXT_ARCHv7EM 0x0d
|
||||
|
||||
/* Table 5-6, ARM-specific dynamic array tags */
|
||||
|
||||
#define DT_ARM_RESERVED1 0x70000000
|
||||
#define DT_ARM_SYMTABSZ 0x70000001
|
||||
#define DT_ARM_PREEMPTMAP 0x70000002
|
||||
#define DT_ARM_RESERVED2 0x70000003
|
||||
|
||||
#endif /* __ARCH_ARM_INCLUDE_ELF_H */
|
||||
@@ -1,257 +0,0 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/arm/up_elf.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <elf32.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <arch/elf.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_checkarch
|
||||
*
|
||||
* Description:
|
||||
* Given the ELF header in 'hdr', verify that the ELF file is appropriate
|
||||
* for the current, configured architecture. Every architecture that uses
|
||||
* the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hdr - The ELF header read from the ELF file.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this ELF file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool arch_checkarch(FAR const Elf32_Ehdr *ehdr)
|
||||
{
|
||||
/* Make sure it's an ARM executable */
|
||||
|
||||
if (ehdr->e_machine != EM_ARM)
|
||||
{
|
||||
bdbg("Not for ARM: e_machine=%04x\n", ehdr->e_machine);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Make sure that 32-bit objects are supported */
|
||||
|
||||
if (ehdr->e_ident[EI_CLASS] != ELFCLASS32)
|
||||
{
|
||||
bdbg("Need 32-bit objects: e_ident[EI_CLASS]=%02x\n", ehdr->e_ident[EI_CLASS]);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Verify endian-ness */
|
||||
|
||||
#ifdef CONFIG_ENDIAN_BIG
|
||||
if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB)
|
||||
#else
|
||||
if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB)
|
||||
#endif
|
||||
{
|
||||
bdbg("Wrong endian-ness: e_ident[EI_DATA]=%02x\n", ehdr->e_ident[EI_DATA]);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Make sure the entry point address is properly aligned */
|
||||
|
||||
if ((ehdr->e_entry & 3) != 0)
|
||||
{
|
||||
bdbg("Entry point is not properly aligned: %08x\n", ehdr->e_entry);
|
||||
return -ENOEXEC
|
||||
}
|
||||
|
||||
/* TODO: Check ABI here. */
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_relocate and arch_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform on architecture-specific ELF relocation. Every architecture
|
||||
* that uses the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rel - The relocation type
|
||||
* sym - The ELF symbol structure containing the fully resolved value.
|
||||
* addr - The address that requires the relocation.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the relocation was successful. Otherwise, a negated errno
|
||||
* value indicating the cause of the relocation failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr)
|
||||
{
|
||||
int32_t offset;
|
||||
|
||||
switch (ELF32_R_TYPE(rel->r_info))
|
||||
{
|
||||
case R_ARM_NONE:
|
||||
{
|
||||
/* No relocation */
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_PC24:
|
||||
case R_ARM_CALL:
|
||||
case R_ARM_JUMP24:
|
||||
{
|
||||
bvdbg("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr),
|
||||
sym, (long)sym->st_value);
|
||||
|
||||
offset = (*(uint32_t*)addr & 0x00ffffff) << 2;
|
||||
if (offset & 0x02000000)
|
||||
{
|
||||
offset -= 0x04000000;
|
||||
}
|
||||
|
||||
offset += sym->st_value - addr;
|
||||
if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000)
|
||||
{
|
||||
bdbg(" ERROR: PC24 [%d] relocation out of range, offset=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), offset);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
offset >>= 2;
|
||||
|
||||
*(uint32_t*)addr &= 0xff000000;
|
||||
*(uint32_t*)addr |= offset & 0x00ffffff;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_ABS32:
|
||||
case R_ARM_TARGET1: /* New ABI: TARGET1 always treated as ABS32 */
|
||||
{
|
||||
bvdbg("Performing ABS32 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
|
||||
(long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value);
|
||||
|
||||
*(uint32_t*)addr += sym->st_value;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_V4BX:
|
||||
{
|
||||
bvdbg("Performing V4BX link at addr=%08lx [%08lx]\n",
|
||||
(long)addr, (long)(*(uint32_t*)addr));
|
||||
|
||||
/* Preserve only Rm and the condition code */
|
||||
|
||||
*(uint32_t*)addr &= 0xf000000f;
|
||||
|
||||
/* Change instruction to 'mov pc, Rm' */
|
||||
|
||||
*(uint32_t*)addr |= 0x01a0f000;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_PREL31:
|
||||
{
|
||||
bvdbg("Performing PREL31 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
|
||||
(long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value);
|
||||
|
||||
offset = *(uint32_t*)addr + sym->st_value - addr;
|
||||
*(uint32_t*)addr = offset & 0x7fffffff;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_MOVW_ABS_NC:
|
||||
case R_ARM_MOVT_ABS:
|
||||
{
|
||||
bvdbg("Performing MOVx_ABS [%d] link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr),
|
||||
sym, (long)sym->st_value);
|
||||
|
||||
offset = *(uint32_t*)addr;
|
||||
offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff);
|
||||
offset = (offset ^ 0x8000) - 0x8000;
|
||||
|
||||
offset += sym->st_value;
|
||||
if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS)
|
||||
{
|
||||
offset >>= 16;
|
||||
}
|
||||
|
||||
*(uint32_t*)addr &= 0xfff0f000;
|
||||
*(uint32_t*)addr |= ((offset & 0xf000) << 4) | (offset & 0x0fff);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
bdbg("Unsupported relocation: %d\n", ELF32_R_TYPE(rel->r_info));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int arch_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr)
|
||||
{
|
||||
bdbg("RELA relocation not supported\n");
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
comment "ARMV7M Configuration Options"
|
||||
|
||||
choice
|
||||
prompt "Toolchain Selection"
|
||||
default ARMV7M_TOOLCHAIN_CODESOURCERYW if HOST_WINDOWS
|
||||
default ARMV7M_TOOLCHAIN_GNU_EABI if !HOST_WINDOWS
|
||||
|
||||
config ARMV7M_TOOLCHAIN_ATOLLIC
|
||||
bool "Atollic Lite/Pro for Windows"
|
||||
depends on HOST_WINDOWS
|
||||
|
||||
config ARMV7M_TOOLCHAIN_BUILDROOT
|
||||
bool "Buildroot (Cygwin or Linux)"
|
||||
depends on !WINDOWS_NATIVE
|
||||
|
||||
config ARMV7M_TOOLCHAIN_CODEREDL
|
||||
bool "CodeRed for Linux"
|
||||
depends on HOST_LINUX
|
||||
|
||||
config ARMV7M_TOOLCHAIN_CODEREDW
|
||||
bool "CodeRed for Windows"
|
||||
depends on HOST_WINDOWS
|
||||
|
||||
config ARMV7M_TOOLCHAIN_CODESOURCERYL
|
||||
bool "CodeSourcery GNU toolchain under Linux"
|
||||
depends on HOST_LINUX
|
||||
|
||||
config ARMV7M_TOOLCHAIN_CODESOURCERYW
|
||||
bool "CodeSourcery GNU toolchain under Windows"
|
||||
depends on HOST_WINDOWS
|
||||
|
||||
config ARMV7M_TOOLCHAIN_DEVKITARM
|
||||
bool "devkitARM GNU toolchain"
|
||||
depends on HOST_WINDOWS
|
||||
|
||||
config ARMV7M_TOOLCHAIN_GNU_EABI
|
||||
bool "Generic GNU EABI toolchain"
|
||||
---help---
|
||||
This option should work for any modern GNU toolchain (GCC 4.5 or newer)
|
||||
configured for arm-none-eabi.
|
||||
|
||||
config ARMV7M_TOOLCHAIN_RAISONANCE
|
||||
bool "STMicro Raisonance for Windows"
|
||||
depends on HOST_WINDOWS
|
||||
|
||||
endchoice
|
||||
@@ -1,266 +0,0 @@
|
||||
############################################################################
|
||||
# arch/arm/src/armv7-m/Toolchain.defs
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Setup for the selected toolchain
|
||||
|
||||
#
|
||||
# Handle old-style chip-specific toolchain names in the absence of
|
||||
# a new-style toolchain specification, force the selection of a single
|
||||
# toolchain and allow the selected toolchain to be overridden by a
|
||||
# command-line selection.
|
||||
#
|
||||
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_LPC43_ATOLLIC_LITE) \
|
||||
$(CONFIG_STM32_ATOLLIC_LITE) \
|
||||
$(CONFIG_LPC43_ATOLLIC_PRO) \
|
||||
$(CONFIG_STM32_ATOLLIC_PRO) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= ATOLLIC
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_BUILDROOT) \
|
||||
$(CONFIG_LM3S_BUILDROOT) \
|
||||
$(CONFIG_LPC17_BUILDROOT) \
|
||||
$(CONFIG_LPC43_BUILDROOT) \
|
||||
$(CONFIG_SAM3U_BUILDROOT) \
|
||||
$(CONFIG_STM32_BUILDROOT) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= BUILDROOT
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_LPC17_CODEREDL) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODEREDL) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODEREDL
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_LPC17_CODEREDW) \
|
||||
$(CONFIG_LPC43_CODEREDW) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODEREDW) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODEREDW
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_CODESOURCERYL) \
|
||||
$(CONFIG_LM3S_CODESOURCERYL) \
|
||||
$(CONFIG_LPC17_CODESOURCERYL) \
|
||||
$(CONFIG_LPC43_CODESOURCERYL) \
|
||||
$(CONFIG_SAM3U_CODESOURCERYL) \
|
||||
$(CONFIG_STM32_CODESOURCERYL) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODESOURCERYL
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_CODESOURCERYW) \
|
||||
$(CONFIG_LM3S_CODESOURCERYW) \
|
||||
$(CONFIG_LPC17_CODESOURCERYW) \
|
||||
$(CONFIG_LPC43_CODESOURCERYW) \
|
||||
$(CONFIG_SAM3U_CODESOURCERYW) \
|
||||
$(CONFIG_STM32_CODESOURCERYW) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODESOURCERYW
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_DEVKITARM) \
|
||||
$(CONFIG_LM3S_DEVKITARM) \
|
||||
$(CONFIG_LPC17_DEVKITARM) \
|
||||
$(CONFIG_LPC43_DEVKITARM) \
|
||||
$(CONFIG_SAM3U_DEVKITARM) \
|
||||
$(CONFIG_STM32_DEVKITARM) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= DEVKITARM
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= GNU_EABI
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_STM32_RAISONANCE) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_RAISONANCE) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= RAISONANCE
|
||||
endif
|
||||
|
||||
#
|
||||
# Supported toolchains
|
||||
#
|
||||
# TODO - It's likely that all of these toolchains now support the
|
||||
# CortexM4. Since they are all GCC-based, we could almost
|
||||
# certainly simplify this further.
|
||||
#
|
||||
# Each toolchain definition should set:
|
||||
#
|
||||
# CROSSDEV The GNU toolchain triple (command prefix)
|
||||
# ARCROSSDEV If required, an alternative prefix used when
|
||||
# invoking ar and nm.
|
||||
# ARCHCPUFLAGS CPU-specific flags selecting the instruction set
|
||||
# FPU options, etc.
|
||||
# MAXOPTIMIZATION The maximum optimization level that results in
|
||||
# reliable code generation.
|
||||
#
|
||||
|
||||
# Atollic toolchain under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),ATOLLIC)
|
||||
CROSSDEV = arm-atollic-eabi-
|
||||
ARCROSSDEV = arm-atollic-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# NuttX buildroot under Linux or Cygwin
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),BUILDROOT)
|
||||
# OABI
|
||||
# CROSSDEV = arm-nuttx-elf-
|
||||
# ARCROSSDEV = arm-nuttx-elf-
|
||||
# ARCHCPUFLAGS = -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft
|
||||
# EABI
|
||||
CROSSDEV = arm-nuttx-eabi-
|
||||
ARCROSSDEV = arm-nuttx-eabi-
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
MAXOPTIMIZATION = -Os
|
||||
endif
|
||||
|
||||
# Code Red RedSuite under Linux
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDL)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# Code Red RedSuite under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDW)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# CodeSourcery under Linux
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYL)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
MAXOPTIMIZATION = -O2
|
||||
endif
|
||||
|
||||
# CodeSourcery under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYW)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
|
||||
# devkitARM under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),DEVKITARM)
|
||||
CROSSDEV = arm-eabi-
|
||||
ARCROSSDEV = arm-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
|
||||
# Generic GNU EABI toolchain on OS X, Linux or any typical Posix system
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
MAXOPTIMIZATION = -O3
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# Raisonance RIDE7 under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),RAISONANCE)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
@@ -1,450 +0,0 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/armv7-m/up_elf.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <elf32.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <arch/elf.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_checkarch
|
||||
*
|
||||
* Description:
|
||||
* Given the ELF header in 'hdr', verify that the ELF file is appropriate
|
||||
* for the current, configured architecture. Every architecture that uses
|
||||
* the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hdr - The ELF header read from the ELF file.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this ELF file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
bool arch_checkarch(FAR const Elf32_Ehdr *ehdr)
|
||||
{
|
||||
/* Make sure it's an ARM executable */
|
||||
|
||||
if (ehdr->e_machine != EM_ARM)
|
||||
{
|
||||
bdbg("Not for ARM: e_machine=%04x\n", ehdr->e_machine);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Make sure that 32-bit objects are supported */
|
||||
|
||||
if (ehdr->e_ident[EI_CLASS] != ELFCLASS32)
|
||||
{
|
||||
bdbg("Need 32-bit objects: e_ident[EI_CLASS]=%02x\n", ehdr->e_ident[EI_CLASS]);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Verify endian-ness */
|
||||
|
||||
#ifdef CONFIG_ENDIAN_BIG
|
||||
if (ehdr->e_ident[EI_DATA] != ELFDATA2MSB)
|
||||
#else
|
||||
if (ehdr->e_ident[EI_DATA] != ELFDATA2LSB)
|
||||
#endif
|
||||
{
|
||||
bdbg("Wrong endian-ness: e_ident[EI_DATA]=%02x\n", ehdr->e_ident[EI_DATA]);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* TODO: Check ABI here. */
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_relocate and arch_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform on architecture-specific ELF relocation. Every architecture
|
||||
* that uses the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rel - The relocation type
|
||||
* sym - The ELF symbol structure containing the fully resolved value.
|
||||
* addr - The address that requires the relocation.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the relocation was successful. Otherwise, a negated errno
|
||||
* value indicating the cause of the relocation failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr)
|
||||
{
|
||||
int32_t offset;
|
||||
uint32_t upper_insn;
|
||||
uint32_t lower_insn;
|
||||
|
||||
switch (ELF32_R_TYPE(rel->r_info))
|
||||
{
|
||||
case R_ARM_NONE:
|
||||
{
|
||||
/* No relocation */
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_PC24:
|
||||
case R_ARM_CALL:
|
||||
case R_ARM_JUMP24:
|
||||
{
|
||||
bvdbg("Performing PC24 [%d] link at addr %08lx [%08lx] to sym '%s' st_value=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr),
|
||||
sym, (long)sym->st_value);
|
||||
|
||||
offset = (*(uint32_t*)addr & 0x00ffffff) << 2;
|
||||
if (offset & 0x02000000)
|
||||
{
|
||||
offset -= 0x04000000;
|
||||
}
|
||||
|
||||
offset += sym->st_value - addr;
|
||||
if (offset & 3 || offset <= (int32_t) 0xfe000000 || offset >= (int32_t) 0x02000000)
|
||||
{
|
||||
bdbg(" ERROR: PC24 [%d] relocation out of range, offset=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), offset);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
offset >>= 2;
|
||||
|
||||
*(uint32_t*)addr &= 0xff000000;
|
||||
*(uint32_t*)addr |= offset & 0x00ffffff;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_ABS32:
|
||||
case R_ARM_TARGET1: /* New ABI: TARGET1 always treated as ABS32 */
|
||||
{
|
||||
bvdbg("Performing ABS32 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
|
||||
(long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value);
|
||||
|
||||
*(uint32_t*)addr += sym->st_value;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_THM_CALL:
|
||||
case R_ARM_THM_JUMP24:
|
||||
{
|
||||
uint32_t S;
|
||||
uint32_t J1;
|
||||
uint32_t J2;
|
||||
|
||||
/* Thumb BL and B.W instructions. Encoding:
|
||||
*
|
||||
* upper_insn:
|
||||
*
|
||||
* 1 1 1 1 1 1
|
||||
* 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
* +----------+---+-------------------------------+--------------+
|
||||
* |1 1 1 |OP1| OP2 | | 32-Bit Instructions
|
||||
* +----------+---+--+-----+----------------------+--------------+
|
||||
* |1 1 1 | 1 0| S | imm10 | BL Instruction
|
||||
* +----------+------+-----+-------------------------------------+
|
||||
*
|
||||
* lower_insn:
|
||||
*
|
||||
* 1 1 1 1 1 1
|
||||
* 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
* +---+---------------------------------------------------------+
|
||||
* |OP | | 32-Bit Instructions
|
||||
* +---+--+---+---+---+------------------------------------------+
|
||||
* |1 1 |J1 | 1 |J2 | imm11 | BL Instruction
|
||||
* +------+---+---+---+------------------------------------------+
|
||||
*
|
||||
* The branch target is encoded in these bits:
|
||||
*
|
||||
* S = upper_insn[10]
|
||||
* imm10 = upper_insn[0:9]
|
||||
* imm11 = lower_insn[0:10]
|
||||
* J1 = lower_insn[13]
|
||||
* J2 = lower_insn[11]
|
||||
*/
|
||||
|
||||
upper_insn = (uint32_t)(*(uint16_t*)addr);
|
||||
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
|
||||
|
||||
bvdbg("Performing THM_JUMP24 [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
|
||||
sym, (long)sym->st_value);
|
||||
|
||||
/* Extract the 25-bit offset from the 32-bit instruction:
|
||||
*
|
||||
* offset[24] = S
|
||||
* offset[23] = ~(J1 ^ S)
|
||||
* offset[22] = ~(J2 ^ S)]
|
||||
* offset[12:21] = imm10
|
||||
* offset[1:11] = imm11
|
||||
* offset[0] = 0
|
||||
*/
|
||||
|
||||
S = (upper_insn >> 10) & 1;
|
||||
J1 = (lower_insn >> 13) & 1;
|
||||
J2 = (lower_insn >> 11) & 1;
|
||||
|
||||
offset = (S << 24) | /* S - > offset[24] */
|
||||
((~(J1 ^ S) & 1) << 23) | /* J1 -> offset[23] */
|
||||
((~(J2 ^ S) & 1) << 22) | /* J2 -> offset[22] */
|
||||
((upper_insn & 0x03ff) << 12) | /* imm10 -> offset[12:21] */
|
||||
((lower_insn & 0x07ff) << 1); /* imm11 -> offset[1:11] */
|
||||
/* 0 -> offset[0] */
|
||||
|
||||
/* Sign extend */
|
||||
|
||||
if (offset & 0x01000000)
|
||||
{
|
||||
offset -= 0x02000000;
|
||||
}
|
||||
|
||||
/* And perform the relocation */
|
||||
|
||||
bvdbg(" S=%d J1=%d J2=%d offset=%08lx branch target=%08lx\n",
|
||||
S, J1, J2, (long)offset, offset + sym->st_value - addr);
|
||||
|
||||
offset += sym->st_value - addr;
|
||||
|
||||
/* Is this a function symbol? If so, then the branch target must be
|
||||
* an odd Thumb address
|
||||
*/
|
||||
|
||||
if (ELF32_ST_TYPE(sym->st_info) == STT_FUNC && (offset & 1) == 0)
|
||||
{
|
||||
bdbg(" ERROR: JUMP24 [%d] requires odd offset, offset=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), offset);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Check the range of the offset */
|
||||
|
||||
if (offset <= (int32_t)0xff000000 || offset >= (int32_t)0x01000000)
|
||||
{
|
||||
bdbg(" ERROR: JUMP24 [%d] relocation out of range, branch taget=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), offset);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Now, reconstruct the 32-bit instruction using the new, relocated
|
||||
* branch target.
|
||||
*/
|
||||
|
||||
S = (offset >> 24) & 1;
|
||||
J1 = S ^ (~(offset >> 23) & 1);
|
||||
J2 = S ^ (~(offset >> 22) & 1);
|
||||
|
||||
upper_insn = ((upper_insn & 0xf800) | (S << 10) | ((offset >> 12) & 0x03ff));
|
||||
*(uint16_t*)addr = (uint16_t)upper_insn;
|
||||
|
||||
lower_insn = ((lower_insn & 0xd000) | (J1 << 13) | (J2 << 11) | ((offset >> 1) & 0x07ff));
|
||||
*(uint16_t*)(addr + 2) = (uint16_t)lower_insn;
|
||||
|
||||
bvdbg(" S=%d J1=%d J2=%d insn [%04x %04x]\n",
|
||||
S, J1, J2, (int)upper_insn, (int)lower_insn);
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_V4BX:
|
||||
{
|
||||
bvdbg("Performing V4BX link at addr=%08lx [%08lx]\n",
|
||||
(long)addr, (long)(*(uint32_t*)addr));
|
||||
|
||||
/* Preserve only Rm and the condition code */
|
||||
|
||||
*(uint32_t*)addr &= 0xf000000f;
|
||||
|
||||
/* Change instruction to 'mov pc, Rm' */
|
||||
|
||||
*(uint32_t*)addr |= 0x01a0f000;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_PREL31:
|
||||
{
|
||||
bvdbg("Performing PREL31 link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
|
||||
(long)addr, (long)(*(uint32_t*)addr), sym, (long)sym->st_value);
|
||||
|
||||
offset = *(uint32_t*)addr + sym->st_value - addr;
|
||||
*(uint32_t*)addr = offset & 0x7fffffff;
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_MOVW_ABS_NC:
|
||||
case R_ARM_MOVT_ABS:
|
||||
{
|
||||
bvdbg("Performing MOVx_ABS [%d] link at addr=%08lx [%08lx] to sym=%p st_value=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), (long)addr, (long)(*(uint32_t*)addr),
|
||||
sym, (long)sym->st_value);
|
||||
|
||||
offset = *(uint32_t*)addr;
|
||||
offset = ((offset & 0xf0000) >> 4) | (offset & 0xfff);
|
||||
offset = (offset ^ 0x8000) - 0x8000;
|
||||
|
||||
offset += sym->st_value;
|
||||
if (ELF32_R_TYPE(rel->r_info) == R_ARM_MOVT_ABS)
|
||||
{
|
||||
offset >>= 16;
|
||||
}
|
||||
|
||||
*(uint32_t*)addr &= 0xfff0f000;
|
||||
*(uint32_t*)addr |= ((offset & 0xf000) << 4) | (offset & 0x0fff);
|
||||
}
|
||||
break;
|
||||
|
||||
case R_ARM_THM_MOVW_ABS_NC:
|
||||
case R_ARM_THM_MOVT_ABS:
|
||||
{
|
||||
/* Thumb BL and B.W instructions. Encoding:
|
||||
*
|
||||
* upper_insn:
|
||||
*
|
||||
* 1 1 1 1 1 1
|
||||
* 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
* +----------+---+-------------------------------+--------------+
|
||||
* |1 1 1 |OP1| OP2 | | 32-Bit Instructions
|
||||
* +----------+---+--+-----+----------------------+--------------+
|
||||
* |1 1 1 | 1 0| i | 1 0 1 1 0 0 | imm4 | MOVT Instruction
|
||||
* +----------+------+-----+----------------------+--------------+
|
||||
*
|
||||
* lower_insn:
|
||||
*
|
||||
* 1 1 1 1 1 1
|
||||
* 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|
||||
* +---+---------------------------------------------------------+
|
||||
* |OP | | 32-Bit Instructions
|
||||
* +---+----------+--------------+-------------------------------+
|
||||
* |0 | imm3 | Rd | imm8 | MOVT Instruction
|
||||
* +---+----------+--------------+-------------------------------+
|
||||
*
|
||||
* The 16-bit immediate value is encoded in these bits:
|
||||
*
|
||||
* i = imm16[11] = upper_insn[10]
|
||||
* imm4 = imm16[12:15] = upper_insn[3:0]
|
||||
* imm3 = imm16[8:10] = lower_insn[14:12]
|
||||
* imm8 = imm16[0:7] = lower_insn[7:0]
|
||||
*/
|
||||
|
||||
upper_insn = (uint32_t)(*(uint16_t*)addr);
|
||||
lower_insn = (uint32_t)(*(uint16_t*)(addr + 2));
|
||||
|
||||
bvdbg("Performing THM_MOVx [%d] link at addr=%08lx [%04x %04x] to sym=%p st_value=%08lx\n",
|
||||
ELF32_R_TYPE(rel->r_info), (long)addr, (int)upper_insn, (int)lower_insn,
|
||||
sym, (long)sym->st_value);
|
||||
|
||||
/* Extract the 16-bit offset from the 32-bit instruction */
|
||||
|
||||
offset = ((upper_insn & 0x000f) << 12) | /* imm4 -> imm16[8:10] */
|
||||
((upper_insn & 0x0400) << 1) | /* i -> imm16[11] */
|
||||
((lower_insn & 0x7000) >> 4) | /* imm3 -> imm16[8:10] */
|
||||
(lower_insn & 0x00ff); /* imm8 -> imm16[0:7] */
|
||||
|
||||
/* Sign extend */
|
||||
|
||||
offset = (offset ^ 0x8000) - 0x8000;
|
||||
|
||||
/* And perform the relocation */
|
||||
|
||||
bvdbg(" offset=%08lx branch target=%08lx\n",
|
||||
(long)offset, offset + sym->st_value);
|
||||
|
||||
offset += sym->st_value;
|
||||
|
||||
/* Update the immediate value in the instruction. For MOVW we want the bottom
|
||||
* 16-bits; for MOVT we want the top 16-bits.
|
||||
*/
|
||||
|
||||
if (ELF32_R_TYPE(rel->r_info) == R_ARM_THM_MOVT_ABS)
|
||||
{
|
||||
offset >>= 16;
|
||||
}
|
||||
|
||||
upper_insn = ((upper_insn & 0xfbf0) | ((offset & 0xf000) >> 12) | ((offset & 0x0800) >> 1));
|
||||
*(uint16_t*)addr = (uint16_t)upper_insn;
|
||||
|
||||
lower_insn = ((lower_insn & 0x8f00) | ((offset & 0x0700) << 4) | (offset & 0x00ff));
|
||||
*(uint16_t*)(addr + 2) = (uint16_t)lower_insn;
|
||||
|
||||
bvdbg(" insn [%04x %04x]\n",
|
||||
(int)upper_insn, (int)lower_insn);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
bdbg("Unsupported relocation: %d\n", ELF32_R_TYPE(rel->r_info));
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
int arch_relocateadd(FAR const Elf32_Rela *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr)
|
||||
{
|
||||
bdbg("RELA relocation not supported\n");
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
@@ -1,416 +0,0 @@
|
||||
/************************************************************************************
|
||||
* nuttx/arch/arm/src/armv7-m/up_memcpy.S
|
||||
*
|
||||
* armv7m-optimised memcpy, contributed by Mike Smith. Apparently in the public
|
||||
* domain and is re-released here under the modified BSD license:
|
||||
*
|
||||
* Obtained via a posting on the Stellaris forum:
|
||||
* http://e2e.ti.com/support/microcontrollers/\
|
||||
* stellaris_arm_cortex-m3_microcontroller/f/473/t/44360.aspx
|
||||
*
|
||||
* Posted by rocksoft on Jul 24, 2008 10:19 AM
|
||||
*
|
||||
* Hi,
|
||||
*
|
||||
* I recently finished a "memcpy" replacement and thought it might be useful for
|
||||
* others...
|
||||
*
|
||||
* I've put some instructions and the code here:
|
||||
*
|
||||
* http://www.rock-software.net/downloads/memcpy/
|
||||
*
|
||||
* Hope it works for you as well as it did for me.
|
||||
*
|
||||
* Liam.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Global Symbols
|
||||
************************************************************************************/
|
||||
|
||||
.global memcpy
|
||||
|
||||
.syntax unified
|
||||
.thumb
|
||||
.cpu cortex-m3
|
||||
.file "up_memcpy.S"
|
||||
|
||||
/************************************************************************************
|
||||
* .text
|
||||
************************************************************************************/
|
||||
|
||||
.text
|
||||
|
||||
/************************************************************************************
|
||||
* Private Constant Data
|
||||
************************************************************************************/
|
||||
|
||||
/* We have 16 possible alignment combinations of src and dst, this jump table
|
||||
* directs the copy operation
|
||||
*
|
||||
* Bits: Src=00, Dst=00 - Long to Long copy
|
||||
* Bits: Src=00, Dst=01 - Long to Byte before half word
|
||||
* Bits: Src=00, Dst=10 - Long to Half word
|
||||
* Bits: Src=00, Dst=11 - Long to Byte before long word
|
||||
* Bits: Src=01, Dst=00 - Byte before half word to long
|
||||
* Bits: Src=01, Dst=01 - Byte before half word to byte before half word -
|
||||
* Same alignment
|
||||
* Bits: Src=01, Dst=10 - Byte before half word to half word
|
||||
* Bits: Src=01, Dst=11 - Byte before half word to byte before long word
|
||||
* Bits: Src=10, Dst=00 - Half word to long word
|
||||
* Bits: Src=10, Dst=01 - Half word to byte before half word
|
||||
* Bits: Src=10, Dst=10 - Half word to half word - Same Alignment
|
||||
* Bits: Src=10, Dst=11 - Half word to byte before long word
|
||||
* Bits: Src=11, Dst=00 - Byte before long word to long word
|
||||
* Bits: Src=11, Dst=01 - Byte before long word to byte before half word
|
||||
* Bits: Src=11, Dst=11 - Byte before long word to half word
|
||||
* Bits: Src=11, Dst=11 - Byte before long word to Byte before long word -
|
||||
* Same alignment
|
||||
*/
|
||||
|
||||
MEM_DataCopyTable:
|
||||
.byte (MEM_DataCopy0 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy1 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy2 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy3 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy4 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy5 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy6 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy7 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy8 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy9 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy10 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy11 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy12 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy13 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy14 - MEM_DataCopyJump) >> 1
|
||||
.byte (MEM_DataCopy15 - MEM_DataCopyJump) >> 1
|
||||
|
||||
.align 2
|
||||
|
||||
MEM_LongCopyTable:
|
||||
.byte (MEM_LongCopyEnd - MEM_LongCopyJump) >> 1 /* 0 bytes left */
|
||||
.byte 0 /* 4 bytes left */
|
||||
.byte (1 * 10) >> 1 /* 8 bytes left */
|
||||
.byte (2 * 10) >> 1 /* 12 bytes left */
|
||||
.byte (3 * 10) >> 1 /* 16 bytes left */
|
||||
.byte (4 * 10) >> 1 /* 20 bytes left */
|
||||
.byte (5 * 10) >> 1 /* 24 bytes left */
|
||||
.byte (6 * 10) >> 1 /* 28 bytes left */
|
||||
.byte (7 * 10) >> 1 /* 32 bytes left */
|
||||
.byte (8 * 10) >> 1 /* 36 bytes left */
|
||||
|
||||
.align 2
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
/************************************************************************************
|
||||
* Name: memcpy
|
||||
*
|
||||
* Description:
|
||||
* Optimised "general" copy routine
|
||||
*
|
||||
* Input Parameters:
|
||||
* r0 = destination, r1 = source, r2 = length
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
.thumb_func
|
||||
memcpy:
|
||||
push {r14}
|
||||
|
||||
/* This allows the inner workings to "assume" a minimum amount of bytes */
|
||||
/* Quickly check for very short copies */
|
||||
|
||||
cmp r2, #4
|
||||
blt MEM_DataCopyBytes
|
||||
|
||||
and r14, r0, #3 /* Get destination alignment bits */
|
||||
bfi r14, r1, #2, #2 /* Get source alignment bits */
|
||||
ldr r3, =MEM_DataCopyTable /* Jump table base */
|
||||
tbb [r3, r14] /* Perform jump on src/dst alignment bits */
|
||||
MEM_DataCopyJump:
|
||||
|
||||
.align 4
|
||||
|
||||
/* Bits: Src=01, Dst=01 - Byte before half word to byte before half word - Same alignment
|
||||
* 3 bytes to read for long word aligning
|
||||
*/
|
||||
|
||||
MEM_DataCopy5:
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=10, Dst=10 - Half word to half word - Same Alignment
|
||||
* 2 bytes to read for long word aligning
|
||||
*/
|
||||
|
||||
MEM_DataCopy10:
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=11, Dst=11 - Byte before long word to Byte before long word - Same alignment
|
||||
* 1 bytes to read for long word aligning
|
||||
*/
|
||||
|
||||
MEM_DataCopy15:
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=00, Dst=00 - Long to Long copy */
|
||||
|
||||
MEM_DataCopy0:
|
||||
/* Save regs that may be used by memcpy */
|
||||
|
||||
push {r4-r12}
|
||||
|
||||
/* Check for short word-aligned copy */
|
||||
|
||||
cmp r2, #0x28
|
||||
blt MEM_DataCopy0_2
|
||||
|
||||
/* Bulk copy loop */
|
||||
|
||||
MEM_DataCopy0_1:
|
||||
ldmia r1!, {r3-r12}
|
||||
stmia r0!, {r3-r12}
|
||||
sub r2, r2, #0x28
|
||||
cmp r2, #0x28
|
||||
bge MEM_DataCopy0_1
|
||||
|
||||
/* Copy remaining long words */
|
||||
|
||||
MEM_DataCopy0_2:
|
||||
/* Copy remaining long words */
|
||||
|
||||
ldr r14, =MEM_LongCopyTable
|
||||
lsr r11, r2, #0x02
|
||||
tbb [r14, r11]
|
||||
|
||||
/* longword copy branch table anchor */
|
||||
|
||||
MEM_LongCopyJump:
|
||||
ldr.w r3, [r1], #0x04 /* 4 bytes remain */
|
||||
str.w r3, [r0], #0x04
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r4} /* 8 bytes remain */
|
||||
stmia.w r0!, {r3-r4}
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r5} /* 12 bytes remain */
|
||||
stmia.w r0!, {r3-r5}
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r6} /* 16 bytes remain */
|
||||
stmia.w r0!, {r3-r6}
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r7} /* 20 bytes remain */
|
||||
stmia.w r0!, {r3-r7}
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r8} /* 24 bytes remain */
|
||||
stmia.w r0!, {r3-r8}
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r9} /* 28 bytes remain */
|
||||
stmia.w r0!, {r3-r9}
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r10} /* 32 bytes remain */
|
||||
stmia.w r0!, {r3-r10}
|
||||
b MEM_LongCopyEnd
|
||||
ldmia.w r1!, {r3-r11} /* 36 bytes remain */
|
||||
stmia.w r0!, {r3-r11}
|
||||
|
||||
MEM_LongCopyEnd:
|
||||
pop {r4-r12}
|
||||
and r2, r2, #0x03 /* All the longs have been copied */
|
||||
|
||||
/* Deal with up to 3 remaining bytes */
|
||||
|
||||
MEM_DataCopyBytes:
|
||||
/* Deal with up to 3 remaining bytes */
|
||||
|
||||
cmp r2, #0x00
|
||||
it eq
|
||||
popeq {pc}
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
subs r2, r2, #0x01
|
||||
it eq
|
||||
popeq {pc}
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
subs r2, r2, #0x01
|
||||
it eq
|
||||
popeq {pc}
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
pop {pc}
|
||||
|
||||
.align 4
|
||||
|
||||
/* Bits: Src=01, Dst=11 - Byte before half word to byte before long word
|
||||
* 3 bytes to read for long word aligning the source
|
||||
*/
|
||||
|
||||
MEM_DataCopy7:
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=10, Dst=00 - Half word to long word
|
||||
* 2 bytes to read for long word aligning the source
|
||||
*/
|
||||
|
||||
MEM_DataCopy8:
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=11, Dst=01 - Byte before long word to byte before half word
|
||||
* 1 byte to read for long word aligning the source
|
||||
*/
|
||||
|
||||
MEM_DataCopy13:
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=00, Dst=10 - Long to Half word */
|
||||
|
||||
MEM_DataCopy2:
|
||||
cmp r2, #0x28
|
||||
blt MEM_DataCopy2_1
|
||||
|
||||
/* Save regs */
|
||||
|
||||
push {r4-r12}
|
||||
|
||||
/* Bulk copy loop */
|
||||
|
||||
MEM_DataCopy2_2:
|
||||
ldmia r1!, {r3-r12}
|
||||
|
||||
strh r3, [r0], #0x02
|
||||
|
||||
lsr r3, r3, #0x10
|
||||
bfi r3, r4, #0x10, #0x10
|
||||
lsr r4, r4, #0x10
|
||||
bfi r4, r5, #0x10, #0x10
|
||||
lsr r5, r5, #0x10
|
||||
bfi r5, r6, #0x10, #0x10
|
||||
lsr r6, r6, #0x10
|
||||
bfi r6, r7, #0x10, #0x10
|
||||
lsr r7, r7, #0x10
|
||||
bfi r7, r8, #0x10, #0x10
|
||||
lsr r8, r8, #0x10
|
||||
bfi r8, r9, #0x10, #0x10
|
||||
lsr r9, r9, #0x10
|
||||
bfi r9, r10, #0x10, #0x10
|
||||
lsr r10, r10, #0x10
|
||||
bfi r10, r11, #0x10, #0x10
|
||||
lsr r11, r11, #0x10
|
||||
bfi r11, r12, #0x10, #0x10
|
||||
stmia r0!, {r3-r11}
|
||||
lsr r12, r12, #0x10
|
||||
strh r12, [r0], #0x02
|
||||
|
||||
sub r2, r2, #0x28
|
||||
cmp r2, #0x28
|
||||
bge MEM_DataCopy2_2
|
||||
pop {r4-r12}
|
||||
|
||||
MEM_DataCopy2_1: /* Read longs and write 2 x half words */
|
||||
cmp r2, #4
|
||||
blt MEM_DataCopyBytes
|
||||
ldr r3, [r1], #0x04
|
||||
strh r3, [r0], #0x02
|
||||
lsr r3, r3, #0x10
|
||||
strh r3, [r0], #0x02
|
||||
sub r2, r2, #0x04
|
||||
b MEM_DataCopy2
|
||||
|
||||
/* Bits: Src=01, Dst=00 - Byte before half word to long
|
||||
* Bits: Src=01, Dst=10 - Byte before half word to half word
|
||||
* 3 bytes to read for long word aligning the source
|
||||
*/
|
||||
|
||||
MEM_DataCopy4:
|
||||
MEM_DataCopy6:
|
||||
/* Read B and write B */
|
||||
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=10, Dst=01 - Half word to byte before half word
|
||||
* Bits: Src=10, Dst=11 - Half word to byte before long word
|
||||
* 2 bytes to read for long word aligning the source
|
||||
*/
|
||||
|
||||
MEM_DataCopy9:
|
||||
MEM_DataCopy11:
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=11, Dst=00 -chm Byte before long word to long word
|
||||
* Bits: Src=11, Dst=11 - Byte before long word to half word
|
||||
* 1 byte to read for long word aligning the source
|
||||
*/
|
||||
|
||||
MEM_DataCopy12:
|
||||
MEM_DataCopy14:
|
||||
/* Read B and write B */
|
||||
|
||||
ldrb r3, [r1], #0x01
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x01
|
||||
|
||||
/* Bits: Src=00, Dst=01 - Long to Byte before half word
|
||||
* Bits: Src=00, Dst=11 - Long to Byte before long word
|
||||
*/
|
||||
|
||||
MEM_DataCopy1: /* Read longs, write B->H->B */
|
||||
MEM_DataCopy3:
|
||||
cmp r2, #4
|
||||
blt MEM_DataCopyBytes
|
||||
ldr r3, [r1], #0x04
|
||||
strb r3, [r0], #0x01
|
||||
lsr r3, r3, #0x08
|
||||
strh r3, [r0], #0x02
|
||||
lsr r3, r3, #0x10
|
||||
strb r3, [r0], #0x01
|
||||
sub r2, r2, #0x04
|
||||
b MEM_DataCopy3
|
||||
|
||||
.size memcpy, .-memcpy
|
||||
.end
|
||||
@@ -1,53 +0,0 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/common/arm-elf.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_ARM_SRC_ARM_ELF_H
|
||||
#define __ARCH_ARM_SRC_ARM_ELF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_ARM_ELF_H */
|
||||
@@ -1,302 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/elf.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <elf32.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#ifdef CONFIG_ELF
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
|
||||
* defined or CONFIG_ELF_DUMPBUFFER does nothing.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
|
||||
# undef CONFIG_ELF_DUMPBUFFER
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ELF_STACKSIZE
|
||||
# define CONFIG_ELF_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ELF_DUMPBUFFER
|
||||
# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
|
||||
#else
|
||||
# define elf_dumpbuffer(m,b,n)
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (a < b ? a : b)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_loadbinary(FAR struct binary_s *binp);
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
||||
static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct binfmt_s g_elfbinfmt =
|
||||
{
|
||||
NULL, /* next */
|
||||
elf_loadbinary, /* load */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_dumploadinfo
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
||||
static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
bdbg("LOAD_INFO:\n");
|
||||
bdbg(" elfalloc: %08lx\n", (long)loadinfo->elfalloc);
|
||||
bdbg(" elfsize: %ld\n", (long)loadinfo->elfsize);
|
||||
bdbg(" filelen: %ld\n", (long)loadinfo->filelen);
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
bdbg(" ctoralloc: %08lx\n", (long)loadinfo->ctoralloc);
|
||||
bdbg(" ctors: %08lx\n", (long)loadinfo->ctors);
|
||||
bdbg(" nctors: %d\n", loadinfo->nctors);
|
||||
bdbg(" dtoralloc: %08lx\n", (long)loadinfo->dtoralloc);
|
||||
bdbg(" dtors: %08lx\n", (long)loadinfo->dtors);
|
||||
bdbg(" ndtors: %d\n", loadinfo->ndtors);
|
||||
#endif
|
||||
bdbg(" filfd: %d\n", loadinfo->filfd);
|
||||
bdbg(" symtabidx: %d\n", loadinfo->symtabidx);
|
||||
bdbg(" strtabidx: %d\n", loadinfo->strtabidx);
|
||||
|
||||
bdbg("ELF Header:\n");
|
||||
bdbg(" e_ident: %02x %02x %02x %02x\n",
|
||||
loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1],
|
||||
loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]);
|
||||
bdbg(" e_type: %04x\n", loadinfo->ehdr.e_type);
|
||||
bdbg(" e_machine: %04x\n", loadinfo->ehdr.e_machine);
|
||||
bdbg(" e_version: %08x\n", loadinfo->ehdr.e_version);
|
||||
bdbg(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry);
|
||||
bdbg(" e_phoff: %d\n", loadinfo->ehdr.e_phoff);
|
||||
bdbg(" e_shoff: %d\n", loadinfo->ehdr.e_shoff);
|
||||
bdbg(" e_flags: %08x\n" , loadinfo->ehdr.e_flags);
|
||||
bdbg(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize);
|
||||
bdbg(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize);
|
||||
bdbg(" e_phnum: %d\n", loadinfo->ehdr.e_phnum);
|
||||
bdbg(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize);
|
||||
bdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum);
|
||||
bdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx);
|
||||
|
||||
if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0)
|
||||
{
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||
bdbg("Sections %d:\n", i);
|
||||
bdbg(" sh_name: %08x\n", shdr->sh_name);
|
||||
bdbg(" sh_type: %08x\n", shdr->sh_type);
|
||||
bdbg(" sh_flags: %08x\n", shdr->sh_flags);
|
||||
bdbg(" sh_addr: %08x\n", shdr->sh_addr);
|
||||
bdbg(" sh_offset: %d\n", shdr->sh_offset);
|
||||
bdbg(" sh_size: %d\n", shdr->sh_size);
|
||||
bdbg(" sh_link: %d\n", shdr->sh_link);
|
||||
bdbg(" sh_info: %d\n", shdr->sh_info);
|
||||
bdbg(" sh_addralign: %d\n", shdr->sh_addralign);
|
||||
bdbg(" sh_entsize: %d\n", shdr->sh_entsize);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define elf_dumploadinfo(i)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadbinary
|
||||
*
|
||||
* Description:
|
||||
* Verify that the file is an ELF binary and, if so, load the ELF
|
||||
* binary into memory
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_loadbinary(struct binary_s *binp)
|
||||
{
|
||||
struct elf_loadinfo_s loadinfo; /* Contains globals for libelf */
|
||||
int ret;
|
||||
|
||||
bvdbg("Loading file: %s\n", binp->filename);
|
||||
|
||||
/* Initialize the xflat library to load the program binary. */
|
||||
|
||||
ret = elf_init(binp->filename, &loadinfo);
|
||||
elf_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to initialize for load of ELF program: %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Load the program binary */
|
||||
|
||||
ret = elf_load(&loadinfo);
|
||||
elf_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to load ELF program binary: %d\n", ret);
|
||||
goto errout_with_init;
|
||||
}
|
||||
|
||||
/* Bind the program to the exported symbol table */
|
||||
|
||||
ret = elf_bind(&loadinfo, binp->exports, binp->nexports);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to bind symbols program binary: %d\n", ret);
|
||||
goto errout_with_load;
|
||||
}
|
||||
|
||||
/* Return the load information */
|
||||
|
||||
binp->entrypt = (main_t)(loadinfo.elfalloc + loadinfo.ehdr.e_entry);
|
||||
binp->alloc[0] = (FAR void *)loadinfo.elfalloc;
|
||||
binp->stacksize = CONFIG_ELF_STACKSIZE;
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
/* Save information about constructors. NOTE: desctructors are not
|
||||
* yet supported.
|
||||
*/
|
||||
|
||||
binp->alloc[1] = loadinfo.ctoralloc;
|
||||
binp->ctors = loadinfo.ctors;
|
||||
binp->nctors = loadinfo.nctors;
|
||||
|
||||
binp->alloc[2] = loadinfo.dtoralloc;
|
||||
binp->dtors = loadinfo.dtors;
|
||||
binp->ndtors = loadinfo.ndtors;
|
||||
#endif
|
||||
|
||||
elf_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
|
||||
MIN(loadinfo.allocsize - loadinfo.ehdr.e_entry, 512));
|
||||
|
||||
elf_uninit(&loadinfo);
|
||||
return OK;
|
||||
|
||||
errout_with_load:
|
||||
elf_unload(&loadinfo);
|
||||
errout_with_init:
|
||||
elf_uninit(&loadinfo);
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_initialize
|
||||
*
|
||||
* Description:
|
||||
* ELF support is built unconditionally. However, it order to
|
||||
* use this binary format, this function must be called during system
|
||||
* format in order to register the ELF binary format.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_initialize(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Register ourselves as a binfmt loader */
|
||||
|
||||
bvdbg("Registering ELF\n");
|
||||
|
||||
ret = register_binfmt(&g_elfbinfmt);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to register binfmt: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* Unregister the ELF binary loader
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void elf_uninitialize(void)
|
||||
{
|
||||
unregister_binfmt(&g_elfbinfmt);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ELF */
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
config ELF_ALIGN_LOG2
|
||||
int "Log2 Section Alignment"
|
||||
default 2
|
||||
---help---
|
||||
Align all sections to this Log2 value: 0->1, 1->2, 2->4, etc.
|
||||
|
||||
config ELF_STACKSIZE
|
||||
int "ELF Stack Size"
|
||||
default 2048
|
||||
---help---
|
||||
This is the default stack size that will will be used when starting ELF binaries.
|
||||
|
||||
config ELF_BUFFERSIZE
|
||||
int "ELF I/O Buffer Size"
|
||||
default 128
|
||||
---help---
|
||||
This is an I/O buffer that is used to access the ELF file. Variable length items
|
||||
will need to be read (such as symbol names). This is really just this initial
|
||||
size of the buffer; it will be reallocated as necessary to hold large symbol
|
||||
names). Default: 128
|
||||
|
||||
config ELF_BUFFERINCR
|
||||
int "ELF I/O Buffer Realloc Increment"
|
||||
default 32
|
||||
---help---
|
||||
This is an I/O buffer that is used to access the ELF file. Variable length items
|
||||
will need to be read (such as symbol names). This value specifies the size
|
||||
increment to use each time the buffer is reallocated. Default: 32
|
||||
|
||||
config ELF_DUMPBUFFER
|
||||
bool "Dump ELF buffers"
|
||||
default n
|
||||
depends on DEBUG && DEBUG_VERBOSE
|
||||
---help---
|
||||
Dump various ELF buffers for debug purposes
|
||||
@@ -1,58 +0,0 @@
|
||||
############################################################################
|
||||
# binfmt/libelf/Make.defs
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_ELF),y)
|
||||
|
||||
# ELF application interfaces
|
||||
|
||||
BINFMT_CSRCS += elf.c
|
||||
|
||||
# ELF library
|
||||
|
||||
BINFMT_CSRCS += libelf_bind.c libelf_init.c libelf_iobuffer.c libelf_load.c \
|
||||
libelf_read.c libelf_sections.c libelf_symbols.c libelf_uninit.c \
|
||||
libelf_unload.c libelf_verify.c
|
||||
|
||||
ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y)
|
||||
BINFMT_CSRCS += libelf_ctors.c libelf_dtors.c
|
||||
endif
|
||||
|
||||
# Hook the libelf subdirectory into the build
|
||||
|
||||
VPATH += libelf
|
||||
SUBDIRS += libelf
|
||||
DEPPATH += --dep-path libelf
|
||||
|
||||
endif
|
||||
@@ -1,129 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/gnu-elf.ld
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
.text 0x00000000 :
|
||||
{
|
||||
_stext = . ;
|
||||
*(.text)
|
||||
*(.text.*)
|
||||
*(.gnu.warning)
|
||||
*(.stub)
|
||||
*(.glue_7)
|
||||
*(.glue_7t)
|
||||
*(.jcr)
|
||||
|
||||
/* C++ support: The .init and .fini sections contain specific logic
|
||||
* to manage static constructors and destructors.
|
||||
*/
|
||||
|
||||
*(.gnu.linkonce.t.*)
|
||||
*(.init) /* Old ABI */
|
||||
*(.fini) /* Old ABI */
|
||||
_etext = . ;
|
||||
}
|
||||
|
||||
.rodata :
|
||||
{
|
||||
_srodata = . ;
|
||||
*(.rodata)
|
||||
*(.rodata1)
|
||||
*(.rodata.*)
|
||||
*(.gnu.linkonce.r*)
|
||||
_erodata = . ;
|
||||
}
|
||||
|
||||
.data :
|
||||
{
|
||||
_sdata = . ;
|
||||
*(.data)
|
||||
*(.data1)
|
||||
*(.data.*)
|
||||
*(.gnu.linkonce.d*)
|
||||
_edata = . ;
|
||||
}
|
||||
|
||||
/* C++ support. For each global and static local C++ object,
|
||||
* GCC creates a small subroutine to construct the object. Pointers
|
||||
* to these routines (not the routines themselves) are stored as
|
||||
* simple, linear arrays in the .ctors section of the object file.
|
||||
* Similarly, pointers to global/static destructor routines are
|
||||
* stored in .dtors.
|
||||
*/
|
||||
|
||||
.ctors :
|
||||
{
|
||||
_sctors = . ;
|
||||
*(.ctors) /* Old ABI: Unallocated */
|
||||
*(.init_array) /* New ABI: Allocated */
|
||||
_edtors = . ;
|
||||
}
|
||||
|
||||
.dtors :
|
||||
{
|
||||
_sdtors = . ;
|
||||
*(.dtors) /* Old ABI: Unallocated */
|
||||
*(.fini_array) /* New ABI: Allocated */
|
||||
_edtors = . ;
|
||||
}
|
||||
|
||||
.bss :
|
||||
{
|
||||
_sbss = . ;
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.sbss)
|
||||
*(.sbss.*)
|
||||
*(.gnu.linkonce.b*)
|
||||
*(COMMON)
|
||||
_ebss = . ;
|
||||
}
|
||||
|
||||
/* Stabs debugging sections. */
|
||||
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.comment 0 : { *(.comment) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_info 0 : { *(.debug_info) }
|
||||
.debug_line 0 : { *(.debug_line) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
}
|
||||
@@ -1,258 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BINFMT_LIBELF_LIBELF_H
|
||||
#define __BINFMT_LIBELF_LIBELF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <elf32.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_verifyheader
|
||||
*
|
||||
* Description:
|
||||
* Given the header from a possible ELF executable, verify that it is
|
||||
* an ELF executable.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_verifyheader(FAR const Elf32_Ehdr *header);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_read
|
||||
*
|
||||
* Description:
|
||||
* Read 'readsize' bytes from the object file at 'offset'
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
|
||||
size_t readsize, off_t offset);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadshdrs
|
||||
*
|
||||
* Description:
|
||||
* Loads section headers into memory.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findsection
|
||||
*
|
||||
* Description:
|
||||
* A section by its name.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* sectname - Name of the section to find
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the index to the section is returned; A negated errno value
|
||||
* is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const char *sectname);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findsymtab
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol table section.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_findsymtab(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_readsym
|
||||
*
|
||||
* Description:
|
||||
* Read the ELFT symbol structure at the specfied index into memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* index - Symbol table index
|
||||
* sym - Location to return the table entry
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_readsym(FAR struct elf_loadinfo_s *loadinfo, int index,
|
||||
FAR Elf32_Sym *sym);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_symvalue
|
||||
*
|
||||
* Description:
|
||||
* Get the value of a symbol. The updated value of the symbol is returned
|
||||
* in the st_value field of the symbol table entry.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* sym - Symbol table entry (value might be undefined)
|
||||
* exports - The symbol table to use for resolving undefined symbols.
|
||||
* nexports - Number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_freebuffers
|
||||
*
|
||||
* Description:
|
||||
* Release all working buffers.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_freebuffers(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_allocbuffer
|
||||
*
|
||||
* Description:
|
||||
* Perform the initial allocation of the I/O buffer, if it has not already
|
||||
* been allocated.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_reallocbuffer
|
||||
*
|
||||
* Description:
|
||||
* Increase the size of I/O buffer by the specified buffer increment.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findctors
|
||||
*
|
||||
* Description:
|
||||
* Find C++ static constructors.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loaddtors
|
||||
*
|
||||
* Description:
|
||||
* Load pointers to static destructors into an in-memory array.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo);
|
||||
#endif
|
||||
|
||||
#endif /* __BINFMT_LIBELF_LIBELF_H */
|
||||
@@ -1,306 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_bind.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <elf32.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
|
||||
* defined or CONFIG_ELF_DUMPBUFFER does nothing.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
|
||||
# undef CONFIG_ELF_DUMPBUFFER
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ELF_BUFFERSIZE
|
||||
# define CONFIG_ELF_BUFFERSIZE 128
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ELF_DUMPBUFFER
|
||||
# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
|
||||
#else
|
||||
# define elf_dumpbuffer(m,b,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_readsym
|
||||
*
|
||||
* Description:
|
||||
* Read the ELFT symbol structure at the specfied index into memory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int elf_readrel(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const Elf32_Shdr *relsec,
|
||||
int index, FAR Elf32_Rel *rel)
|
||||
{
|
||||
off_t offset;
|
||||
|
||||
/* Verify that the symbol table index lies within symbol table */
|
||||
|
||||
if (index < 0 || index > (relsec->sh_size / sizeof(Elf32_Rel)))
|
||||
{
|
||||
bdbg("Bad relocation symbol index: %d\n", index);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get the file offset to the symbol table entry */
|
||||
|
||||
offset = relsec->sh_offset + sizeof(Elf32_Rel) * index;
|
||||
|
||||
/* And, finally, read the symbol table entry into memory */
|
||||
|
||||
return elf_read(loadinfo, (FAR uint8_t*)rel, sizeof(Elf32_Rel), offset);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_relocate and elf_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform all relocations associated with a section.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
|
||||
{
|
||||
FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx];
|
||||
FAR Elf32_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
|
||||
Elf32_Rel rel;
|
||||
Elf32_Sym sym;
|
||||
uintptr_t addr;
|
||||
int symidx;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Examine each relocation in the section. 'relsec' is the section
|
||||
* containing the relations. 'dstsec' is the section containing the data
|
||||
* to be relocated.
|
||||
*/
|
||||
|
||||
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++)
|
||||
{
|
||||
/* Read the relocation entry into memory */
|
||||
|
||||
ret = elf_readrel(loadinfo, relsec, i, &rel);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n",
|
||||
relidx, i, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the symbol table index for the relocation. This is contained
|
||||
* in a bit-field within the r_info element.
|
||||
*/
|
||||
|
||||
symidx = ELF32_R_SYM(rel.r_info);
|
||||
|
||||
/* Read the symbol table entry into memory */
|
||||
|
||||
ret = elf_readsym(loadinfo, symidx, &sym);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n",
|
||||
relidx, i, symidx, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the value of the symbol (in sym.st_value) */
|
||||
|
||||
ret = elf_symvalue(loadinfo, &sym, exports, nexports);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Section %d reloc %d: Failed to get value of symbol[%d]: %d\n",
|
||||
relidx, i, symidx, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Calculate the relocation address */
|
||||
|
||||
if (rel.r_offset < 0 || rel.r_offset > dstsec->sh_size - sizeof(uint32_t))
|
||||
{
|
||||
bdbg("Section %d reloc %d: Relocation address out of range, offset %d size %d\n",
|
||||
relidx, i, rel.r_offset, dstsec->sh_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
addr = dstsec->sh_addr + rel.r_offset;
|
||||
|
||||
/* Now perform the architecture-specific relocation */
|
||||
|
||||
ret = arch_relocate(&rel, &sym, addr);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Section %d reloc %d: Relocation failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int elf_relocateadd(FAR struct elf_loadinfo_s *loadinfo, int relidx,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
{
|
||||
bdbg("Not implemented\n");
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_bind
|
||||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Find the symbol and string tables */
|
||||
|
||||
ret = elf_findsymtab(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Allocate an I/O buffer. This buffer is used by elf_symname() to
|
||||
* accumulate the variable length symbol name.
|
||||
*/
|
||||
|
||||
ret = elf_allocbuffer(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_allocbuffer failed: %d\n", ret);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Process relocations in every allocated section */
|
||||
|
||||
for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
/* Get the index to the relocation section */
|
||||
|
||||
int infosec = loadinfo->shdr[i].sh_info;
|
||||
if (infosec >= loadinfo->ehdr.e_shnum)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Make sure that the section is allocated. We can't relocated
|
||||
* sections that were not loaded into memory.
|
||||
*/
|
||||
|
||||
if ((loadinfo->shdr[infosec].sh_flags & SHF_ALLOC) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Process the relocations by type */
|
||||
|
||||
if (loadinfo->shdr[i].sh_type == SHT_REL)
|
||||
{
|
||||
ret = elf_relocate(loadinfo, i, exports, nexports);
|
||||
}
|
||||
else if (loadinfo->shdr[i].sh_type == SHT_RELA)
|
||||
{
|
||||
ret = elf_relocateadd(loadinfo, i, exports, nexports);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Flush the instruction cache before starting the newly loaded module */
|
||||
|
||||
#ifdef CONFIG_ELF_ICACHE
|
||||
arch_flushicache((FAR void*)loadinfo->elfalloc, loadinfo->elfsize);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_ctors.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadctors
|
||||
*
|
||||
* Description:
|
||||
* Load pointers to static constructors into an in-memory array.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr;
|
||||
size_t ctorsize;
|
||||
int ctoridx;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(loadinfo->ctors == NULL);
|
||||
|
||||
/* Allocate an I/O buffer if necessary. This buffer is used by
|
||||
* elf_sectname() to accumulate the variable length symbol name.
|
||||
*/
|
||||
|
||||
ret = elf_allocbuffer(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_allocbuffer failed: %d\n", ret);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Find the index to the section named ".ctors." NOTE: On old ABI system,
|
||||
* .ctors is the name of the section containing the list of constructors;
|
||||
* On newer systems, the similar section is called .init_array. It is
|
||||
* expected that the linker script will force the section name to be ".ctors"
|
||||
* in either case.
|
||||
*/
|
||||
|
||||
ctoridx = elf_findsection(loadinfo, ".ctors");
|
||||
if (ctoridx < 0)
|
||||
{
|
||||
/* This may not be a failure. -ENOENT indicates that the file has no
|
||||
* static constructor section.
|
||||
*/
|
||||
|
||||
bvdbg("elf_findsection .ctors section failed: %d\n", ctoridx);
|
||||
return ret == -ENOENT ? OK : ret;
|
||||
}
|
||||
|
||||
/* Now we can get a pointer to the .ctor section in the section header
|
||||
* table.
|
||||
*/
|
||||
|
||||
shdr = &loadinfo->shdr[ctoridx];
|
||||
|
||||
/* Get the size of the .ctor section and the number of constructors that
|
||||
* will need to be called.
|
||||
*/
|
||||
|
||||
ctorsize = shdr->sh_size;
|
||||
loadinfo->nctors = ctorsize / sizeof(binfmt_ctor_t);
|
||||
|
||||
bvdbg("ctoridx=%d ctorsize=%d sizeof(binfmt_ctor_t)=%d nctors=%d\n",
|
||||
ctoridx, ctorsize, sizeof(binfmt_ctor_t), loadinfo->nctors);
|
||||
|
||||
/* Check if there are any constructors. It is not an error if there
|
||||
* are none.
|
||||
*/
|
||||
|
||||
if (loadinfo->nctors > 0)
|
||||
{
|
||||
/* Check an assumption that we made above */
|
||||
|
||||
DEBUGASSERT(shdr->sh_size == loadinfo->nctors * sizeof(binfmt_ctor_t));
|
||||
|
||||
/* In the old ABI, the .ctors section is not allocated. In that case,
|
||||
* we need to allocate memory to hold the .ctors and then copy the
|
||||
* from the file into the allocated memory.
|
||||
*
|
||||
* SHF_ALLOC indicates that the section requires memory during
|
||||
* execution.
|
||||
*/
|
||||
|
||||
if ((shdr->sh_flags & SHF_ALLOC) == 0)
|
||||
{
|
||||
/* Allocate memory to hold a copy of the .ctor section */
|
||||
|
||||
loadinfo->ctoralloc = (binfmt_ctor_t*)kmalloc(ctorsize);
|
||||
if (!loadinfo->ctoralloc)
|
||||
{
|
||||
bdbg("Failed to allocate memory for .ctors\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
loadinfo->ctors = (binfmt_ctor_t *)loadinfo->ctoralloc;
|
||||
|
||||
/* Read the section header table into memory */
|
||||
|
||||
ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->ctors, ctorsize,
|
||||
shdr->sh_offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to allocate .ctors: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Fix up all of the .ctor addresses. Since the addresses
|
||||
* do not lie in allocated memory, there will be no relocation
|
||||
* section for them.
|
||||
*/
|
||||
|
||||
for (i = 0; i < loadinfo->nctors; i++)
|
||||
{
|
||||
FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->ctors)[i]);
|
||||
|
||||
bvdbg("ctor %d: %08lx + %08lx = %08lx\n",
|
||||
i, *ptr, loadinfo->elfalloc, *ptr + loadinfo->elfalloc);
|
||||
|
||||
*ptr += loadinfo->elfalloc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Save the address of the .ctors (actually, .init_array) where it was
|
||||
* loaded into memory. Since the .ctors lie in allocated memory, they
|
||||
* will be relocated via the normal mechanism.
|
||||
*/
|
||||
|
||||
loadinfo->ctors = (binfmt_ctor_t*)shdr->sh_addr;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BINFMT_CONSTRUCTORS */
|
||||
@@ -1,215 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_dtors.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loaddtors
|
||||
*
|
||||
* Description:
|
||||
* Load pointers to static destructors into an in-memory array.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr;
|
||||
size_t dtorsize;
|
||||
int dtoridx;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
DEBUGASSERT(loadinfo->dtors == NULL);
|
||||
|
||||
/* Allocate an I/O buffer if necessary. This buffer is used by
|
||||
* elf_sectname() to accumulate the variable length symbol name.
|
||||
*/
|
||||
|
||||
ret = elf_allocbuffer(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_allocbuffer failed: %d\n", ret);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Find the index to the section named ".dtors." NOTE: On old ABI system,
|
||||
* .dtors is the name of the section containing the list of destructors;
|
||||
* On newer systems, the similar section is called .fini_array. It is
|
||||
* expected that the linker script will force the section name to be ".dtors"
|
||||
* in either case.
|
||||
*/
|
||||
|
||||
dtoridx = elf_findsection(loadinfo, ".dtors");
|
||||
if (dtoridx < 0)
|
||||
{
|
||||
/* This may not be a failure. -ENOENT indicates that the file has no
|
||||
* static destructor section.
|
||||
*/
|
||||
|
||||
bvdbg("elf_findsection .dtors section failed: %d\n", dtoridx);
|
||||
return ret == -ENOENT ? OK : ret;
|
||||
}
|
||||
|
||||
/* Now we can get a pointer to the .dtor section in the section header
|
||||
* table.
|
||||
*/
|
||||
|
||||
shdr = &loadinfo->shdr[dtoridx];
|
||||
|
||||
/* Get the size of the .dtor section and the number of destructors that
|
||||
* will need to be called.
|
||||
*/
|
||||
|
||||
dtorsize = shdr->sh_size;
|
||||
loadinfo->ndtors = dtorsize / sizeof(binfmt_dtor_t);
|
||||
|
||||
bvdbg("dtoridx=%d dtorsize=%d sizeof(binfmt_dtor_t)=%d ndtors=%d\n",
|
||||
dtoridx, dtorsize, sizeof(binfmt_dtor_t), loadinfo->ndtors);
|
||||
|
||||
/* Check if there are any destructors. It is not an error if there
|
||||
* are none.
|
||||
*/
|
||||
|
||||
if (loadinfo->ndtors > 0)
|
||||
{
|
||||
/* Check an assumption that we made above */
|
||||
|
||||
DEBUGASSERT(shdr->sh_size == loadinfo->ndtors * sizeof(binfmt_dtor_t));
|
||||
|
||||
/* In the old ABI, the .dtors section is not allocated. In that case,
|
||||
* we need to allocate memory to hold the .dtors and then copy the
|
||||
* from the file into the allocated memory.
|
||||
*
|
||||
* SHF_ALLOC indicates that the section requires memory during
|
||||
* execution.
|
||||
*/
|
||||
|
||||
if ((shdr->sh_flags & SHF_ALLOC) == 0)
|
||||
{
|
||||
/* Allocate memory to hold a copy of the .dtor section */
|
||||
|
||||
loadinfo->ctoralloc = (binfmt_dtor_t*)kmalloc(dtorsize);
|
||||
if (!loadinfo->ctoralloc)
|
||||
{
|
||||
bdbg("Failed to allocate memory for .dtors\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
loadinfo->dtors = (binfmt_dtor_t *)loadinfo->ctoralloc;
|
||||
|
||||
/* Read the section header table into memory */
|
||||
|
||||
ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->dtors, dtorsize,
|
||||
shdr->sh_offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to allocate .dtors: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Fix up all of the .dtor addresses. Since the addresses
|
||||
* do not lie in allocated memory, there will be no relocation
|
||||
* section for them.
|
||||
*/
|
||||
|
||||
for (i = 0; i < loadinfo->ndtors; i++)
|
||||
{
|
||||
FAR uintptr_t *ptr = (uintptr_t *)((FAR void *)(&loadinfo->dtors)[i]);
|
||||
|
||||
bvdbg("dtor %d: %08lx + %08lx = %08lx\n",
|
||||
i, *ptr, loadinfo->elfalloc, *ptr + loadinfo->elfalloc);
|
||||
|
||||
*ptr += loadinfo->elfalloc;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
/* Save the address of the .dtors (actually, .init_array) where it was
|
||||
* loaded into memory. Since the .dtors lie in allocated memory, they
|
||||
* will be relocated via the normal mechanism.
|
||||
*/
|
||||
|
||||
loadinfo->dtors = (binfmt_dtor_t*)shdr->sh_addr;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BINFMT_CONSTRUCTORS */
|
||||
@@ -1,202 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_init.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <elf32.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
|
||||
* defined or CONFIG_ELF_DUMPBUFFER does nothing.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
|
||||
# undef CONFIG_ELF_DUMPBUFFER
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ELF_DUMPBUFFER
|
||||
# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
|
||||
#else
|
||||
# define elf_dumpbuffer(m,b,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_filelen
|
||||
*
|
||||
* Description:
|
||||
* Get the size of the ELF file
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const char *filename)
|
||||
{
|
||||
struct stat buf;
|
||||
int ret;
|
||||
|
||||
/* Get the file stats */
|
||||
|
||||
ret = stat(filename, &buf);
|
||||
if (ret < 0)
|
||||
{
|
||||
int errval = errno;
|
||||
bdbg("Failed to fstat file: %d\n", errval);
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/* Verify that it is a regular file */
|
||||
|
||||
if (!S_ISREG(buf.st_mode))
|
||||
{
|
||||
bdbg("Not a regular file. mode: %d\n", buf.st_mode);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* TODO: Verify that the file is readable. Not really important because
|
||||
* we will detect this when we try to open the file read-only.
|
||||
*/
|
||||
|
||||
/* Return the size of the file in the loadinfo structure */
|
||||
|
||||
loadinfo->filelen = buf.st_size;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_init
|
||||
*
|
||||
* Description:
|
||||
* This function is called to configure the library to process an ELF
|
||||
* program binary.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
int ret;
|
||||
|
||||
bvdbg("filename: %s loadinfo: %p\n", filename, loadinfo);
|
||||
|
||||
/* Clear the load info structure */
|
||||
|
||||
memset(loadinfo, 0, sizeof(struct elf_loadinfo_s));
|
||||
|
||||
/* Get the length of the file. */
|
||||
|
||||
ret = elf_filelen(loadinfo, filename);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_filelen failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Open the binary file for reading (only) */
|
||||
|
||||
loadinfo->filfd = open(filename, O_RDONLY);
|
||||
if (loadinfo->filfd < 0)
|
||||
{
|
||||
int errval = errno;
|
||||
bdbg("Failed to open ELF binary %s: %d\n", filename, errval);
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/* Read the ELF ehdr from offset 0 */
|
||||
|
||||
ret = elf_read(loadinfo, (FAR uint8_t*)&loadinfo->ehdr, sizeof(Elf32_Ehdr), 0);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to read ELF header: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
elf_dumpbuffer("ELF header", (FAR const uint8_t*)&loadinfo->ehdr, sizeof(Elf32_Ehdr));
|
||||
|
||||
/* Verify the ELF header */
|
||||
|
||||
ret = elf_verifyheader(&loadinfo->ehdr);
|
||||
if (ret <0)
|
||||
{
|
||||
/* This may not be an error because we will be called to attempt loading
|
||||
* EVERY binary. If elf_verifyheader() does not recognize the ELF header,
|
||||
* it will -ENOEXEC whcih simply informs the system that the file is not an
|
||||
* ELF file. elf_verifyheader() will return other errors if the ELF header
|
||||
* is not correctly formed.
|
||||
*/
|
||||
|
||||
bdbg("Bad ELF header: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/elf_iobuffer.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_allocbuffer
|
||||
*
|
||||
* Description:
|
||||
* Perform the initial allocation of the I/O buffer, if it has not already
|
||||
* been allocated.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
/* Has a buffer been allocated> */
|
||||
|
||||
if (!loadinfo->iobuffer)
|
||||
{
|
||||
/* No.. allocate one now */
|
||||
|
||||
loadinfo->iobuffer = (FAR uint8_t *)kmalloc(CONFIG_ELF_BUFFERSIZE);
|
||||
if (!loadinfo->iobuffer)
|
||||
{
|
||||
bdbg("Failed to allocate an I/O buffer\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
loadinfo->buflen = CONFIG_ELF_BUFFERSIZE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_reallocbuffer
|
||||
*
|
||||
* Description:
|
||||
* Increase the size of I/O buffer by the specified buffer increment.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment)
|
||||
{
|
||||
FAR void *buffer;
|
||||
size_t newsize;
|
||||
|
||||
/* Get the new size of the allocation */
|
||||
|
||||
newsize = loadinfo->buflen + increment;
|
||||
|
||||
/* And perform the reallocation */
|
||||
|
||||
buffer = krealloc((FAR void *)loadinfo->iobuffer, newsize);
|
||||
if (!buffer)
|
||||
{
|
||||
bdbg("Failed to reallocate the I/O buffer\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Save the new buffer info */
|
||||
|
||||
loadinfo->iobuffer = buffer;
|
||||
loadinfo->buflen = newsize;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1,263 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_load.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <elf32.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ELF_ALIGN_MASK ((1 << CONFIG_ELF_ALIGN_LOG2) - 1)
|
||||
#define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK)
|
||||
#define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK)
|
||||
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_elfsize
|
||||
*
|
||||
* Description:
|
||||
* Calculate total memory allocation for the ELF file.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void elf_elfsize(struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
size_t elfsize;
|
||||
int i;
|
||||
|
||||
/* Accumulate the size each section into memory that is marked SHF_ALLOC */
|
||||
|
||||
elfsize = 0;
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||
|
||||
/* SHF_ALLOC indicates that the section requires memory during
|
||||
* execution.
|
||||
*/
|
||||
|
||||
if ((shdr->sh_flags & SHF_ALLOC) != 0)
|
||||
{
|
||||
elfsize += ELF_ALIGNUP(shdr->sh_size);
|
||||
}
|
||||
}
|
||||
|
||||
/* Save the allocation size */
|
||||
|
||||
loadinfo->elfsize = elfsize;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadfile
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory for the file and read the section data into the
|
||||
* allocated memory. Section addresses in the shdr[] are updated to point
|
||||
* to the corresponding position in the allocated memory.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
FAR uint8_t *dest;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Allocate (and zero) memory for the ELF file. */
|
||||
|
||||
loadinfo->elfalloc = (uintptr_t)kzalloc(loadinfo->elfsize);
|
||||
if (!loadinfo->elfalloc)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */
|
||||
|
||||
bvdbg("Loaded sections:\n");
|
||||
dest = (FAR uint8_t*)loadinfo->elfalloc;
|
||||
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||
|
||||
/* SHF_ALLOC indicates that the section requires memory during
|
||||
* execution */
|
||||
|
||||
if ((shdr->sh_flags & SHF_ALLOC) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* SHT_NOBITS indicates that there is no data in the file for the
|
||||
* section.
|
||||
*/
|
||||
|
||||
if (shdr->sh_type != SHT_NOBITS)
|
||||
{
|
||||
/* Read the section data from sh_offset to dest */
|
||||
|
||||
ret = elf_read(loadinfo, dest, shdr->sh_size, shdr->sh_offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to read section %d: %d\n", i, ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* Update sh_addr to point to copy in memory */
|
||||
|
||||
bvdbg("%d. %08x->%08x\n", i, (long)shdr->sh_addr, (long)dest);
|
||||
shdr->sh_addr = (uintptr_t)dest;
|
||||
|
||||
/* Setup the memory pointer for the next time through the loop */
|
||||
|
||||
dest += ELF_ALIGNUP(shdr->sh_size);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_load
|
||||
*
|
||||
* Description:
|
||||
* Loads the binary into memory, allocating memory, performing relocations
|
||||
* and inializing the data and bss segments.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_load(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
int ret;
|
||||
|
||||
bvdbg("loadinfo: %p\n", loadinfo);
|
||||
DEBUGASSERT(loadinfo && loadinfo->filfd >= 0);
|
||||
|
||||
/* Load section headers into memory */
|
||||
|
||||
ret = elf_loadshdrs(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loadshdrs failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
|
||||
/* Determine total size to allocate */
|
||||
|
||||
elf_elfsize(loadinfo);
|
||||
|
||||
/* Allocate memory and load sections into memory */
|
||||
|
||||
ret = elf_loadfile(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loadfile failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
|
||||
/* Load static constructors and destructors. */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
ret = elf_loadctors(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loadctors failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
|
||||
ret = elf_loaddtors(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loaddtors failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
|
||||
/* Error exits */
|
||||
|
||||
errout_with_buffers:
|
||||
elf_unload(loadinfo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_read.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <elf32.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#undef ELF_DUMP_READDATA /* Define to dump all file data read */
|
||||
#define DUMPER lib_rawprintf /* If ELF_DUMP_READDATA is defined, this
|
||||
* is the API used to dump data */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_dumpreaddata
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(ELF_DUMP_READDATA)
|
||||
static inline void elf_dumpreaddata(char *buffer, int buflen)
|
||||
{
|
||||
uint32_t *buf32 = (uint32_t*)buffer;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < buflen; i += 32)
|
||||
{
|
||||
DUMPER("%04x:", i);
|
||||
for (j = 0; j < 32; j += sizeof(uint32_t))
|
||||
{
|
||||
DUMPER(" %08x", *buf32++);
|
||||
}
|
||||
DUMPER("\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define elf_dumpreaddata(b,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_read
|
||||
*
|
||||
* Description:
|
||||
* Read 'readsize' bytes from the object file at 'offset'
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
|
||||
size_t readsize, off_t offset)
|
||||
{
|
||||
ssize_t nbytes; /* Number of bytes read */
|
||||
off_t rpos; /* Position returned by lseek */
|
||||
|
||||
bvdbg("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset);
|
||||
|
||||
/* Loop until all of the requested data has been read. */
|
||||
|
||||
while (readsize > 0)
|
||||
{
|
||||
/* Seek to the next read position */
|
||||
|
||||
rpos = lseek(loadinfo->filfd, offset, SEEK_SET);
|
||||
if (rpos != offset)
|
||||
{
|
||||
int errval = errno;
|
||||
bdbg("Failed to seek to position %ld: %d\n", (long)offset, errval);
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/* Read the file data at offset into the user buffer */
|
||||
|
||||
nbytes = read(loadinfo->filfd, buffer, readsize);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
int errval = errno;
|
||||
|
||||
/* EINTR just means that we received a signal */
|
||||
|
||||
if (errval != EINTR)
|
||||
{
|
||||
bdbg("Read of .data failed: %d\n", errval);
|
||||
return -errval;
|
||||
}
|
||||
}
|
||||
else if (nbytes == 0)
|
||||
{
|
||||
bdbg("Unexpected end of file\n");
|
||||
return -ENODATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
readsize -= nbytes;
|
||||
buffer += nbytes;
|
||||
offset += nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
elf_dumpreaddata(buffer, readsize);
|
||||
return OK;
|
||||
}
|
||||
@@ -1,284 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_sections.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_sectname
|
||||
*
|
||||
* Description:
|
||||
* Get the symbol name in loadinfo->iobuffer[].
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int elf_sectname(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const Elf32_Shdr *shdr)
|
||||
{
|
||||
FAR Elf32_Shdr *shstr;
|
||||
FAR uint8_t *buffer;
|
||||
off_t offset;
|
||||
size_t readlen;
|
||||
size_t bytesread;
|
||||
int shstrndx;
|
||||
int ret;
|
||||
|
||||
/* Get the section header table index of the entry associated with the
|
||||
* section name string table. If the file has no section name string table,
|
||||
* this member holds the value SH_UNDEF.
|
||||
*/
|
||||
|
||||
shstrndx = loadinfo->ehdr.e_shstrndx;
|
||||
if (shstrndx == SHN_UNDEF)
|
||||
{
|
||||
bdbg("No section header string table\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get the section name string table section header */
|
||||
|
||||
shstr = &loadinfo->shdr[shstrndx];
|
||||
|
||||
/* Get the file offset to the string that is the name of the section. This
|
||||
* is the sum of:
|
||||
*
|
||||
* shstr->sh_offset: The file offset to the first byte of the section
|
||||
* header string table data.
|
||||
* shdr->sh_name: The offset to the name of the section in the section
|
||||
* name table
|
||||
*/
|
||||
|
||||
offset = shstr->sh_offset + shdr->sh_name;
|
||||
|
||||
/* Loop until we get the entire section name into memory */
|
||||
|
||||
buffer = loadinfo->iobuffer;
|
||||
bytesread = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Get the number of bytes to read */
|
||||
|
||||
readlen = loadinfo->buflen - bytesread;
|
||||
if (offset + readlen > loadinfo->filelen)
|
||||
{
|
||||
readlen = loadinfo->filelen - offset;
|
||||
if (readlen <= 0)
|
||||
{
|
||||
bdbg("At end of file\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read that number of bytes into the array */
|
||||
|
||||
buffer = &loadinfo->iobuffer[bytesread];
|
||||
ret = elf_read(loadinfo, buffer, readlen, offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to read section name\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
bytesread += readlen;
|
||||
|
||||
/* Did we read the NUL terminator? */
|
||||
|
||||
if (memchr(buffer, '\0', readlen) != NULL)
|
||||
{
|
||||
/* Yes, the buffer contains a NUL terminator. */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* No.. then we have to read more */
|
||||
|
||||
ret = elf_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_reallocbuffer failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* We will not get here */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadshdrs
|
||||
*
|
||||
* Description:
|
||||
* Loads section headers into memory.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
size_t shdrsize;
|
||||
int ret;
|
||||
|
||||
DEBUGASSERT(loadinfo->shdr == NULL);
|
||||
|
||||
/* Verify that there are sections */
|
||||
|
||||
if (loadinfo->ehdr.e_shnum < 1)
|
||||
{
|
||||
bdbg("No sections(?)\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get the total size of the section header table */
|
||||
|
||||
shdrsize = (size_t)loadinfo->ehdr.e_shentsize * (size_t)loadinfo->ehdr.e_shnum;
|
||||
if(loadinfo->ehdr.e_shoff + shdrsize > loadinfo->filelen)
|
||||
{
|
||||
bdbg("Insufficent space in file for section header table\n");
|
||||
return -ESPIPE;
|
||||
}
|
||||
|
||||
/* Allocate memory to hold a working copy of the sector header table */
|
||||
|
||||
loadinfo->shdr = (FAR Elf32_Shdr*)kmalloc(shdrsize);
|
||||
if (!loadinfo->shdr)
|
||||
{
|
||||
bdbg("Failed to allocate the section header table. Size: %ld\n", (long)shdrsize);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Read the section header table into memory */
|
||||
|
||||
ret = elf_read(loadinfo, (FAR uint8_t*)loadinfo->shdr, shdrsize, loadinfo->ehdr.e_shoff);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to read section header table: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findsection
|
||||
*
|
||||
* Description:
|
||||
* A section by its name.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* sectname - Name of the section to find
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the index to the section is returned; A negated errno value
|
||||
* is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const char *sectname)
|
||||
{
|
||||
FAR const Elf32_Shdr *shdr;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Search through the shdr[] array in loadinfo for a section named 'sectname' */
|
||||
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
/* Get the name of this section */
|
||||
|
||||
shdr = &loadinfo->shdr[i];
|
||||
ret = elf_sectname(loadinfo, shdr);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_sectname failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check if the name of this section is 'sectname' */
|
||||
|
||||
bvdbg("%d. Comparing \"%s\" and .\"%s\"\n",
|
||||
i, loadinfo->iobuffer, sectname);
|
||||
|
||||
if (strcmp((FAR const char *)loadinfo->iobuffer, sectname) == 0)
|
||||
{
|
||||
/* We found it... return the index */
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
/* We failed to find a section with this name. */
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
@@ -1,329 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_symbols.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <elf32.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ELF_BUFFERINCR
|
||||
# define CONFIG_ELF_BUFFERINCR 32
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_symname
|
||||
*
|
||||
* Description:
|
||||
* Get the symbol name in loadinfo->iobuffer[].
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_symname(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const Elf32_Sym *sym)
|
||||
{
|
||||
FAR uint8_t *buffer;
|
||||
off_t offset;
|
||||
size_t readlen;
|
||||
size_t bytesread;
|
||||
int ret;
|
||||
|
||||
/* Get the file offset to the string that is the name of the symbol. The
|
||||
* st_name member holds an offset into the file's symbol string table.
|
||||
*/
|
||||
|
||||
if (sym->st_name == 0)
|
||||
{
|
||||
bdbg("Symbol has no name\n");
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
offset = loadinfo->shdr[loadinfo->strtabidx].sh_offset + sym->st_name;
|
||||
|
||||
/* Loop until we get the entire symbol name into memory */
|
||||
|
||||
bytesread = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Get the number of bytes to read */
|
||||
|
||||
readlen = loadinfo->buflen - bytesread;
|
||||
if (offset + readlen > loadinfo->filelen)
|
||||
{
|
||||
readlen = loadinfo->filelen - offset;
|
||||
if (readlen <= 0)
|
||||
{
|
||||
bdbg("At end of file\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Read that number of bytes into the array */
|
||||
|
||||
buffer = &loadinfo->iobuffer[bytesread];
|
||||
ret = elf_read(loadinfo, buffer, readlen, offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_read failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bytesread += readlen;
|
||||
|
||||
/* Did we read the NUL terminator? */
|
||||
|
||||
if (memchr(buffer, '\0', readlen) != NULL)
|
||||
{
|
||||
/* Yes, the buffer contains a NUL terminator. */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* No.. then we have to read more */
|
||||
|
||||
ret = elf_reallocbuffer(loadinfo, CONFIG_ELF_BUFFERINCR);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_reallocbuffer failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
/* We will not get here */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findsymtab
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol table section.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_findsymtab(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Find the symbol table section header and its associated string table */
|
||||
|
||||
for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
if (loadinfo->shdr[i].sh_type == SHT_SYMTAB)
|
||||
{
|
||||
loadinfo->symtabidx = i;
|
||||
loadinfo->strtabidx = loadinfo->shdr[i].sh_link;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Verify that there is a symbol and string table */
|
||||
|
||||
if (loadinfo->symtabidx == 0)
|
||||
{
|
||||
bdbg("No symbols in ELF file\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_readsym
|
||||
*
|
||||
* Description:
|
||||
* Read the ELFT symbol structure at the specfied index into memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* index - Symbol table index
|
||||
* sym - Location to return the table entry
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_readsym(FAR struct elf_loadinfo_s *loadinfo, int index,
|
||||
FAR Elf32_Sym *sym)
|
||||
{
|
||||
FAR Elf32_Shdr *symtab = &loadinfo->shdr[loadinfo->symtabidx];
|
||||
off_t offset;
|
||||
|
||||
/* Verify that the symbol table index lies within symbol table */
|
||||
|
||||
if (index < 0 || index > (symtab->sh_size / sizeof(Elf32_Sym)))
|
||||
{
|
||||
bdbg("Bad relocation symbol index: %d\n", index);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get the file offset to the symbol table entry */
|
||||
|
||||
offset = symtab->sh_offset + sizeof(Elf32_Sym) * index;
|
||||
|
||||
/* And, finally, read the symbol table entry into memory */
|
||||
|
||||
return elf_read(loadinfo, (FAR uint8_t*)sym, sizeof(Elf32_Sym), offset);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_symvalue
|
||||
*
|
||||
* Description:
|
||||
* Get the value of a symbol. The updated value of the symbol is returned
|
||||
* in the st_value field of the symbol table entry.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* sym - Symbol table entry (value might be undefined)
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
{
|
||||
FAR const struct symtab_s *symbol;
|
||||
uintptr_t secbase;
|
||||
int ret;
|
||||
|
||||
switch (sym->st_shndx)
|
||||
{
|
||||
case SHN_COMMON:
|
||||
{
|
||||
/* NuttX ELF modules should be compiled with -fno-common. */
|
||||
|
||||
bdbg("SHN_COMMON: Re-compile with -fno-common\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
case SHN_ABS:
|
||||
{
|
||||
/* st_value already holds the correct value */
|
||||
|
||||
bvdbg("SHN_ABS: st_value=%08lx\n", (long)sym->st_value);
|
||||
return OK;
|
||||
}
|
||||
|
||||
case SHN_UNDEF:
|
||||
{
|
||||
/* Get the name of the undefined symbol */
|
||||
|
||||
ret = elf_symname(loadinfo, sym);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("SHN_UNDEF: Failed to get symbol name: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Check if the base code exports a symbol of this name */
|
||||
|
||||
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
|
||||
symbol = symtab_findorderedbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
|
||||
#else
|
||||
symbol = symtab_findbyname(exports, (FAR char *)loadinfo->iobuffer, nexports);
|
||||
#endif
|
||||
if (!symbol)
|
||||
{
|
||||
bdbg("SHN_UNDEF: Exported symbol \"%s\" not found\n", loadinfo->iobuffer);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/* Yes... add the exported symbol value to the ELF symbol table entry */
|
||||
|
||||
bvdbg("SHN_ABS: name=%s %08x+%08x=%08x\n",
|
||||
loadinfo->iobuffer, sym->st_value, symbol->sym_value,
|
||||
sym->st_value + symbol->sym_value);
|
||||
|
||||
sym->st_value += (Elf32_Word)((uintptr_t)symbol->sym_value);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
secbase = loadinfo->shdr[sym->st_shndx].sh_addr;
|
||||
|
||||
bvdbg("Other: %08x+%08x=%08x\n",
|
||||
sym->st_value, secbase, sym->st_value + secbase);
|
||||
|
||||
sym->st_value += secbase;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_uninit.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_uninit
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources committed by elf_init(). This essentially
|
||||
* undoes the actions of elf_init.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_uninit(struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
/* Free all working buffers */
|
||||
|
||||
elf_freebuffers(loadinfo);
|
||||
|
||||
/* Close the ELF file */
|
||||
|
||||
if (loadinfo->filfd >= 0)
|
||||
{
|
||||
close(loadinfo->filfd);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_freebuffers
|
||||
*
|
||||
* Description:
|
||||
* Release all working buffers.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_freebuffers(struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
/* Release all working allocations */
|
||||
|
||||
if (loadinfo->shdr)
|
||||
{
|
||||
kfree((FAR void *)loadinfo->shdr);
|
||||
loadinfo->shdr = NULL;
|
||||
}
|
||||
|
||||
if (loadinfo->iobuffer)
|
||||
{
|
||||
kfree((FAR void *)loadinfo->iobuffer);
|
||||
loadinfo->iobuffer = NULL;
|
||||
loadinfo->buflen = 0;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_unload.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_unload
|
||||
*
|
||||
* Description:
|
||||
* This function unloads the object from memory. This essentially
|
||||
* undoes the actions of elf_load.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_unload(struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
/* Free all working buffers */
|
||||
|
||||
elf_freebuffers(loadinfo);
|
||||
|
||||
/* Release memory holding the relocated ELF image */
|
||||
|
||||
if (loadinfo->elfalloc != 0)
|
||||
{
|
||||
kfree((FAR void *)loadinfo->elfalloc);
|
||||
loadinfo->elfalloc = 0;
|
||||
}
|
||||
|
||||
loadinfo->elfsize = 0;
|
||||
|
||||
/* Release memory used to hold static constructors and destructors */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
if (loadinfo->ctoralloc != 0)
|
||||
{
|
||||
kfree(loadinfo->ctoralloc);
|
||||
loadinfo->ctoralloc = NULL;
|
||||
}
|
||||
|
||||
loadinfo->ctors = NULL;
|
||||
loadinfo->nctors = 0;
|
||||
|
||||
if (loadinfo->dtoralloc != 0)
|
||||
{
|
||||
kfree(loadinfo->dtoralloc);
|
||||
loadinfo->dtoralloc = NULL;
|
||||
}
|
||||
|
||||
loadinfo->dtors = NULL;
|
||||
loadinfo->ndtors = 0;
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/elf_verify.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
static const char g_elfmagic[EI_MAGIC_SIZE] = { 0x7f, 'E', 'L', 'F' };
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_verifyheader
|
||||
*
|
||||
* Description:
|
||||
* Given the header from a possible ELF executable, verify that it
|
||||
* is an ELF executable.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
* -ENOEXEC : Not an ELF file
|
||||
* -EINVAL : Not a relocatable ELF file or not supported by the current,
|
||||
* configured architecture.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_verifyheader(FAR const Elf32_Ehdr *ehdr)
|
||||
{
|
||||
if (!ehdr)
|
||||
{
|
||||
bdbg("NULL ELF header!");
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Verify that the magic number indicates an ELF file */
|
||||
|
||||
if (memcmp(ehdr->e_ident, g_elfmagic, EI_MAGIC_SIZE) != 0)
|
||||
{
|
||||
bvdbg("Not ELF magic {%02x, %02x, %02x, %02x}\n",
|
||||
ehdr->e_ident[0], ehdr->e_ident[1], ehdr->e_ident[2], ehdr->e_ident[3]);
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Verify that this is a relocatable file */
|
||||
|
||||
if (ehdr->e_type != ET_REL)
|
||||
{
|
||||
bdbg("Not a relocatable file: e_type=%d\n", ehdr->e_type);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Verify that this file works with the currently configured architecture */
|
||||
|
||||
if (arch_checkarch(ehdr))
|
||||
{
|
||||
bdbg("Not a supported architecture\n");
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
/* Looks good so far... we still might find some problems later. */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,167 +0,0 @@
|
||||
/********************************************************************************************
|
||||
* drivers/input/max11802.h
|
||||
*
|
||||
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Petteri Aimonen <jpa@nx.mail.kapsi.fi>
|
||||
*
|
||||
* References:
|
||||
* "Low-Power, Ultra-Small Resistive Touch-Screen Controllers
|
||||
* with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
#ifndef __DRIVERS_INPUT_MAX11802_H
|
||||
#define __DRIVERS_INPUT_MAX11802_H
|
||||
|
||||
/********************************************************************************************
|
||||
* Included Files
|
||||
********************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <semaphore.h>
|
||||
#include <poll.h>
|
||||
#include <wdog.h>
|
||||
#include <nuttx/wqueue.h>
|
||||
|
||||
#include <nuttx/spi.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/input/max11802.h>
|
||||
|
||||
/********************************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
********************************************************************************************/
|
||||
/* Configuration ****************************************************************************/
|
||||
|
||||
/* MAX11802 Interfaces *********************************************************************/
|
||||
|
||||
/* LSB of register addresses specifies read (1) or write (0). */
|
||||
#define MAX11802_CMD_XPOSITION ((0x52 << 1) | 1)
|
||||
#define MAX11802_CMD_YPOSITION ((0x54 << 1) | 1)
|
||||
#define MAX11802_CMD_MEASUREXY (0x70 << 1)
|
||||
#define MAX11802_CMD_MODE_WR (0x0B << 1)
|
||||
#define MAX11802_CMD_MODE_RD ((0x0B << 1) | 1)
|
||||
#define MAX11802_CMD_AVG_WR (0x03 << 1)
|
||||
#define MAX11802_CMD_TIMING_WR (0x05 << 1)
|
||||
#define MAX11802_CMD_DELAY_WR (0x06 << 1)
|
||||
|
||||
/* Register values to set */
|
||||
#define MAX11802_MODE 0x0E
|
||||
#define MAX11802_AVG 0x55
|
||||
#define MAX11802_TIMING 0x77
|
||||
#define MAX11802_DELAY 0x55
|
||||
|
||||
/* Driver support **************************************************************************/
|
||||
/* This format is used to construct the /dev/input[n] device driver path. It
|
||||
* defined here so that it will be used consistently in all places.
|
||||
*/
|
||||
|
||||
#define DEV_FORMAT "/dev/input%d"
|
||||
#define DEV_NAMELEN 16
|
||||
|
||||
/* Poll the pen position while the pen is down at this rate (50MS): */
|
||||
|
||||
#define MAX11802_WDOG_DELAY ((50 + (MSEC_PER_TICK-1))/ MSEC_PER_TICK)
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Types
|
||||
********************************************************************************************/
|
||||
|
||||
/* This describes the state of one contact */
|
||||
|
||||
enum max11802_contact_3
|
||||
{
|
||||
CONTACT_NONE = 0, /* No contact */
|
||||
CONTACT_DOWN, /* First contact */
|
||||
CONTACT_MOVE, /* Same contact, possibly different position */
|
||||
CONTACT_UP, /* Contact lost */
|
||||
};
|
||||
|
||||
/* This structure describes the results of one MAX11802 sample */
|
||||
|
||||
struct max11802_sample_s
|
||||
{
|
||||
uint8_t id; /* Sampled touch point ID */
|
||||
uint8_t contact; /* Contact state (see enum ads7843e_contact_e) */
|
||||
bool valid; /* True: x,y contain valid, sampled data */
|
||||
uint16_t x; /* Measured X position */
|
||||
uint16_t y; /* Measured Y position */
|
||||
};
|
||||
|
||||
/* This structure describes the state of one MAX11802 driver instance */
|
||||
|
||||
struct max11802_dev_s
|
||||
{
|
||||
#ifdef CONFIG_ADS7843E_MULTIPLE
|
||||
FAR struct ads7843e_dev_s *flink; /* Supports a singly linked list of drivers */
|
||||
#endif
|
||||
uint8_t nwaiters; /* Number of threads waiting for MAX11802 data */
|
||||
uint8_t id; /* Current touch point ID */
|
||||
volatile bool penchange; /* An unreported event is buffered */
|
||||
uint16_t threshx; /* Thresholding X value */
|
||||
uint16_t threshy; /* Thresholding Y value */
|
||||
sem_t devsem; /* Manages exclusive access to this structure */
|
||||
sem_t waitsem; /* Used to wait for the availability of data */
|
||||
|
||||
FAR struct max11802_config_s *config; /* Board configuration data */
|
||||
FAR struct spi_dev_s *spi; /* Saved SPI driver instance */
|
||||
struct work_s work; /* Supports the interrupt handling "bottom half" */
|
||||
struct max11802_sample_s sample; /* Last sampled touch point data */
|
||||
WDOG_ID wdog; /* Poll the position while the pen is down */
|
||||
|
||||
/* The following is a list if poll structures of threads waiting for
|
||||
* driver events. The 'struct pollfd' reference for each open is also
|
||||
* retained in the f_priv field of the 'struct file'.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
struct pollfd *fds[CONFIG_ADS7843E_NPOLLWAITERS];
|
||||
#endif
|
||||
};
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Function Prototypes
|
||||
********************************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __DRIVERS_INPUT_ADS7843E_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,352 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/elf32.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Reference: System V Application Binary Interface, Edition 4.1, March 18,
|
||||
* 1997, The Santa Cruz Operation, Inc.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_ELF32_H
|
||||
#define __INCLUDE_ELF32_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Values for Elf32_Ehdr::e_type */
|
||||
|
||||
#define ET_NONE 0 /* No file type */
|
||||
#define ET_REL 1 /* Relocatable file */
|
||||
#define ET_EXEC 2 /* Executable file */
|
||||
#define ET_DYN 3 /* Shared object file */
|
||||
#define ET_CORE 4 /* Core file */
|
||||
#define ET_LOPROC 0xff00 /* Processor-specific */
|
||||
#define ET_HIPROC 0xffff /* Processor-specific */
|
||||
|
||||
/* Values for Elf32_Ehdr::e_machine (most of this were not included in the
|
||||
* original SCO document but have been gleaned from elsewhere).
|
||||
*/
|
||||
|
||||
#define EM_NONE 0 /* No machine */
|
||||
#define EM_M32 1 /* AT&T WE 32100 */
|
||||
#define EM_SPARC 2 /* SPARC */
|
||||
#define EM_386 3 /* Intel 80386 */
|
||||
#define EM_68K 4 /* Motorola 68000 */
|
||||
#define EM_88K 5 /* Motorola 88000 */
|
||||
#define EM_486 6 /* Intel 486+ */
|
||||
#define EM_860 7 /* Intel 80860 */
|
||||
#define EM_MIPS 8 /* MIPS R3000 Big-Endian */
|
||||
#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
|
||||
#define EM_PARISC 15 /* HPPA */
|
||||
#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
|
||||
#define EM_PPC 20 /* PowerPC */
|
||||
#define EM_PPC64 21 /* PowerPC64 */
|
||||
#define EM_ARM 40 /* ARM */
|
||||
#define EM_SH 42 /* SuperH */
|
||||
#define EM_SPARCV9 43 /* SPARC v9 64-bit */
|
||||
#define EM_IA_64 50 /* HP/Intel IA-64 */
|
||||
#define EM_X86_64 62 /* AMD x86-64 */
|
||||
#define EM_S390 22 /* IBM S/390 */
|
||||
#define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */
|
||||
#define EM_V850 87 /* NEC v850 */
|
||||
#define EM_M32R 88 /* Renesas M32R */
|
||||
#define EM_H8_300 46
|
||||
#define EM_ALPHA 0x9026
|
||||
#define EM_CYGNUS_V850 0x9080
|
||||
#define EM_CYGNUS_M32R 0x9041
|
||||
#define EM_S390_OLD 0xa390
|
||||
#define EM_FRV 0x5441
|
||||
|
||||
/* Values for Elf32_Ehdr::e_version */
|
||||
|
||||
#define EV_NONE 0 /* Invalid version */
|
||||
#define EV_CURRENT 1 /* The current version */
|
||||
|
||||
/* Ehe ELF identifier */
|
||||
|
||||
#define EI_MAG0 0 /* File identification */
|
||||
#define EI_MAG1 1 /* " " " " */
|
||||
#define EI_MAG2 2 /* " " " " */
|
||||
#define EI_MAG3 3 /* " " " " */
|
||||
#define EI_CLASS 4 /* File class */
|
||||
#define EI_DATA 5 /* Data encoding */
|
||||
#define EI_VERSION 6 /* File version */
|
||||
#define EI_PAD 7 /* Start of padding bytes */
|
||||
#define EI_NIDENT 16 /* Size of eident[] */
|
||||
|
||||
#define EI_MAGIC_SIZE 4
|
||||
#define EI_MAGIC {0x7f, 'E', 'L', 'F'}
|
||||
|
||||
/* Values for EI_CLASS */
|
||||
|
||||
#define ELFCLASSNONE 0 /* Invalid class */
|
||||
#define ELFCLASS32 1 /* 32-bit objects */
|
||||
#define ELFCLASS64 2 /* 64-bit objects */
|
||||
|
||||
/* Values for EI_DATA */
|
||||
|
||||
#define ELFDATANONE 0 /* Invalid data encoding */
|
||||
#define ELFDATA2LSB 1 /* Least significant byte occupying the lowest address */
|
||||
#define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */
|
||||
|
||||
/* Figure 4-7: Special Section Indexes */
|
||||
|
||||
#define SHN_UNDEF 0
|
||||
#define SHN_LORESERVE 0xff00
|
||||
#define SHN_LOPROC 0xff00
|
||||
#define SHN_HIPROC 0xff1f
|
||||
#define SHN_ABS 0xfff1
|
||||
#define SHN_COMMON 0xfff2
|
||||
#define SHN_HIRESERVE 0xffff
|
||||
|
||||
/* Figure 4-9: Section Types, sh_type */
|
||||
|
||||
#define SHT_NULL 0
|
||||
#define SHT_PROGBITS 1
|
||||
#define SHT_SYMTAB 2
|
||||
#define SHT_STRTAB 3
|
||||
#define SHT_RELA 4
|
||||
#define SHT_HASH 5
|
||||
#define SHT_DYNAMIC 6
|
||||
#define SHT_NOTE 7
|
||||
#define SHT_NOBITS 8
|
||||
#define SHT_REL 9
|
||||
#define SHT_SHLIB 10
|
||||
#define SHT_DYNSYM 11
|
||||
#define SHT_LOPROC 0x70000000
|
||||
#define SHT_HIPROC 0x7fffffff
|
||||
#define SHT_LOUSER 0x80000000
|
||||
#define SHT_HIUSER 0xffffffff
|
||||
|
||||
/* Figure 4-11: Section Attribute Flags, sh_flags */
|
||||
|
||||
#define SHF_WRITE 1
|
||||
#define SHF_ALLOC 2
|
||||
#define SHF_EXECINSTR 4
|
||||
#define SHF_MASKPROC 0xf0000000
|
||||
|
||||
/* Definitions for Elf32_Sym::st_info */
|
||||
|
||||
#define ELF32_ST_BIND(i) ((i) >> 4)
|
||||
#define ELF32_ST_TYPE(i) ((i) & 0xf)
|
||||
#define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf))
|
||||
|
||||
/* Figure 4-16: Symbol Binding, ELF32_ST_BIND */
|
||||
|
||||
#define STB_LOCAL 0
|
||||
#define STB_GLOBAL 1
|
||||
#define STB_WEAK 2
|
||||
#define STB_LOPROC 13
|
||||
#define STB_HIPROC 15
|
||||
|
||||
/* Figure 4-17: Symbol Types, ELF32_ST_TYPE */
|
||||
|
||||
#define STT_NOTYPE 0
|
||||
#define STT_OBJECT 1
|
||||
#define STT_FUNC 2
|
||||
#define STT_SECTION 3
|
||||
#define STT_FILE 4
|
||||
#define STT_LOPROC 13
|
||||
#define STT_HIPROC 15
|
||||
|
||||
/* Definitions for Elf32_Rel*::r_info */
|
||||
|
||||
#define ELF32_R_SYM(i) ((i) >> 8)
|
||||
#define ELF32_R_TYPE(i) ((i) & 0xff)
|
||||
#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff))
|
||||
|
||||
/* Figure 5-2: Segment Types, p_type */
|
||||
|
||||
#define PT_NULL 0
|
||||
#define PT_LOAD 1
|
||||
#define PT_DYNAMIC 2
|
||||
#define PT_INTERP 3
|
||||
#define PT_NOTE 4
|
||||
#define PT_SHLIB 5
|
||||
#define PT_PHDR 6
|
||||
#define PT_LOPROC 0x70000000
|
||||
#define PT_HIPROC 0x7fffffff
|
||||
|
||||
/* Figure 5-3: Segment Flag Bits, p_flags */
|
||||
|
||||
#define PF_X 1 /* Execute */
|
||||
#define PF_W 2 /* Write */
|
||||
#define PF_R 4 /* Read */
|
||||
#define PF_MASKPROC 0xf0000000 /* Unspecified */
|
||||
|
||||
/* Figure 5-10: Dynamic Array Tags, d_tag */
|
||||
|
||||
#define DT_NULL 0 /* d_un=ignored */
|
||||
#define DT_NEEDED 1 /* d_un=d_val */
|
||||
#define DT_PLTRELSZ 2 /* d_un=d_val */
|
||||
#define DT_PLTGOT 3 /* d_un=d_ptr */
|
||||
#define DT_HASH 4 /* d_un=d_ptr */
|
||||
#define DT_STRTAB 5 /* d_un=d_ptr */
|
||||
#define DT_SYMTAB 6 /* d_un=d_ptr */
|
||||
#define DT_RELA 7 /* d_un=d_ptr */
|
||||
#define DT_RELASZ 8 /* d_un=d_val */
|
||||
#define DT_RELAENT 9 /* d_un=d_val */
|
||||
#define DT_STRSZ 10 /* d_un=d_val */
|
||||
#define DT_SYMENT 11 /* d_un=d_val */
|
||||
#define DT_INIT 12 /* d_un=d_ptr */
|
||||
#define DT_FINI 13 /* d_un=d_ptr */
|
||||
#define DT_SONAME 14 /* d_un=d_val */
|
||||
#define DT_RPATH 15 /* d_un=d_val */
|
||||
#define DT_SYMBOLIC 16 /* d_un=ignored */
|
||||
#define DT_REL 17 /* d_un=d_ptr */
|
||||
#define DT_RELSZ 18 /* d_un=d_val */
|
||||
#define DT_RELENT 19 /* d_un=d_val */
|
||||
#define DT_PLTREL 20 /* d_un=d_val */
|
||||
#define DT_DEBUG 21 /* d_un=d_ptr */
|
||||
#define DT_TEXTREL 22 /* d_un=ignored */
|
||||
#define DT_JMPREL 23 /* d_un=d_ptr */
|
||||
#define DT_BINDNOW 24 /* d_un=ignored */
|
||||
#define DT_LOPROC 0x70000000 /* d_un=unspecified */
|
||||
#define DT_HIPROC 0x7fffffff /* d_un= unspecified */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Figure 4.2: 32-Bit Data Types */
|
||||
|
||||
typedef uint32_t Elf32_Addr; /* Unsigned program address */
|
||||
typedef uint16_t Elf32_Half; /* Unsigned medium integer */
|
||||
typedef uint32_t Elf32_Off; /* Unsigned file offset */
|
||||
typedef int32_t Elf32_Sword; /* Signed large integer */
|
||||
typedef uint32_t Elf32_Word; /* Unsigned large integer */
|
||||
|
||||
/* Figure 4-3: ELF Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char e_ident[EI_NIDENT];
|
||||
Elf32_Half e_type;
|
||||
Elf32_Half e_machine;
|
||||
Elf32_Word e_version;
|
||||
Elf32_Addr e_entry;
|
||||
Elf32_Off e_phoff;
|
||||
Elf32_Off e_shoff;
|
||||
Elf32_Word e_flags;
|
||||
Elf32_Half e_ehsize;
|
||||
Elf32_Half e_phentsize;
|
||||
Elf32_Half e_phnum;
|
||||
Elf32_Half e_shentsize;
|
||||
Elf32_Half e_shnum;
|
||||
Elf32_Half e_shstrndx;
|
||||
} Elf32_Ehdr;
|
||||
|
||||
/* Figure 4-8: Section Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Word sh_name;
|
||||
Elf32_Word sh_type;
|
||||
Elf32_Word sh_flags;
|
||||
Elf32_Addr sh_addr;
|
||||
Elf32_Off sh_offset;
|
||||
Elf32_Word sh_size;
|
||||
Elf32_Word sh_link;
|
||||
Elf32_Word sh_info;
|
||||
Elf32_Word sh_addralign;
|
||||
Elf32_Word sh_entsize;
|
||||
} Elf32_Shdr;
|
||||
|
||||
/* Figure 4-15: Symbol Table Entry */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Word st_name;
|
||||
Elf32_Addr st_value;
|
||||
Elf32_Word st_size;
|
||||
unsigned char st_info;
|
||||
unsigned char st_other;
|
||||
Elf32_Half st_shndx;
|
||||
} Elf32_Sym;
|
||||
|
||||
/* Figure 4-19: Relocation Entries */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset;
|
||||
Elf32_Word r_info;
|
||||
} Elf32_Rel;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Addr r_offset;
|
||||
Elf32_Word r_info;
|
||||
Elf32_Sword r_addend;
|
||||
} Elf32_Rela;
|
||||
|
||||
/* Figure 5-1: Program Header */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Word p_type;
|
||||
Elf32_Off p_offset;
|
||||
Elf32_Addr p_vaddr;
|
||||
Elf32_Addr p_paddr;
|
||||
Elf32_Word p_filesz;
|
||||
Elf32_Word p_memsz;
|
||||
Elf32_Word p_flags;
|
||||
Elf32_Word p_align;
|
||||
} Elf32_Phdr;
|
||||
|
||||
/* Figure 5-9: Dynamic Structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Sword d_tag;
|
||||
union
|
||||
{
|
||||
Elf32_Word d_val;
|
||||
Elf32_Addr d_ptr;
|
||||
} d_un;
|
||||
} Elf32_Dyn;
|
||||
|
||||
//extern Elf32_Dyn _DYNAMIC[] ;
|
||||
|
||||
#endif /* __INCLUDE_ELF32_H */
|
||||
@@ -1,226 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/binfmt.h
|
||||
*
|
||||
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_BINFMT_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_BINFMT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <nxflat.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BINFMT_NALLOC 3
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
/* The type of one C++ constructor or destructor */
|
||||
|
||||
typedef FAR void (*binfmt_ctor_t)(void);
|
||||
typedef FAR void (*binfmt_dtor_t)(void);
|
||||
|
||||
/* This describes the file to be loaded */
|
||||
|
||||
struct symtab_s;
|
||||
struct binary_s
|
||||
{
|
||||
/* Information provided to the loader to load and bind a module */
|
||||
|
||||
FAR const char *filename; /* Full path to the binary to be loaded */
|
||||
FAR const char **argv; /* Argument list */
|
||||
FAR const struct symtab_s *exports; /* Table of exported symbols */
|
||||
int nexports; /* The number of symbols in exports[] */
|
||||
|
||||
/* Information provided from the loader (if successful) describing the
|
||||
* resources used by the loaded module.
|
||||
*/
|
||||
|
||||
main_t entrypt; /* Entry point into a program module */
|
||||
FAR void *mapped; /* Memory-mapped, address space */
|
||||
FAR void *alloc[BINFMT_NALLOC]; /* Allocated address spaces */
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */
|
||||
FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */
|
||||
uint16_t nctors; /* Number of constructors in the list */
|
||||
uint16_t ndtors; /* Number of destructors in the list */
|
||||
#endif
|
||||
size_t mapsize; /* Size of the mapped address region (needed for munmap) */
|
||||
size_t stacksize; /* Size of the stack in bytes (unallocated) */
|
||||
};
|
||||
|
||||
/* This describes one binary format handler */
|
||||
|
||||
struct binfmt_s
|
||||
{
|
||||
FAR struct binfmt_s *next; /* Supports a singly-linked list */
|
||||
int (*load)(FAR struct binary_s *bin); /* Verify and load binary into memory */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: register_binfmt
|
||||
*
|
||||
* Description:
|
||||
* Register a loader for a binary format
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int register_binfmt(FAR struct binfmt_s *binfmt);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: unregister_binfmt
|
||||
*
|
||||
* Description:
|
||||
* Register a loader for a binary format
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int unregister_binfmt(FAR struct binfmt_s *binfmt);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: load_module
|
||||
*
|
||||
* Description:
|
||||
* Load a module into memory, bind it to an exported symbol take, and
|
||||
* prep the module for execution.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is an end-user function, so it follows the normal convention:
|
||||
* Returns 0 (OK) on success. On failure, it returns -1 (ERROR) with
|
||||
* errno set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int load_module(FAR struct binary_s *bin);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: unload_module
|
||||
*
|
||||
* Description:
|
||||
* Unload a (non-executing) module from memory. If the module has
|
||||
* been started (via exec_module) and has not exited, calling this will
|
||||
* be fatal.
|
||||
*
|
||||
* However, this function must be called after the module exist. How
|
||||
* this is done is up to your logic. Perhaps you register it to be
|
||||
* called by on_exit()?
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int unload_module(FAR const struct binary_s *bin);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec_module
|
||||
*
|
||||
* Description:
|
||||
* Execute a module that has been loaded into memory by load_module().
|
||||
*
|
||||
* Returned Value:
|
||||
* This is an end-user function, so it follows the normal convention:
|
||||
* Returns the PID of the exec'ed module. On failure, it.returns
|
||||
* -1 (ERROR) and sets errno appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int exec_module(FAR const struct binary_s *bin, int priority);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec
|
||||
*
|
||||
* Description:
|
||||
* This is a convenience function that wraps load_ and exec_module into
|
||||
* one call.
|
||||
*
|
||||
* Input Parameter:
|
||||
* filename - Fulll path to the binary to be loaded
|
||||
* argv - Argument list
|
||||
* exports - Table of exported symbols
|
||||
* nexports - The number of symbols in exports
|
||||
*
|
||||
* Returned Value:
|
||||
* This is an end-user function, so it follows the normal convention:
|
||||
* Returns the PID of the exec'ed module. On failure, it.returns
|
||||
* -1 (ERROR) and sets errno appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int exec(FAR const char *filename, FAR const char **argv,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_BINFMT_H */
|
||||
|
||||
@@ -1,302 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/elf.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_ELF_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_ELF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <elf32.h>
|
||||
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_ELF_ALIGN_LOG2
|
||||
# define CONFIG_ELF_ALIGN_LOG2 2
|
||||
#endif
|
||||
|
||||
/* Allocation array size and indices */
|
||||
|
||||
#define LIBELF_ELF_ALLOC 0
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
# define LIBELF_CTORS_ALLOC 1
|
||||
# define LIBELF_CTPRS_ALLOC 2
|
||||
# define LIBELF_NALLOC 3
|
||||
#else
|
||||
# define LIBELF_NALLOC 1
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This struct provides a desciption of the currently loaded instantiation
|
||||
* of an ELF binary.
|
||||
*/
|
||||
|
||||
struct elf_loadinfo_s
|
||||
{
|
||||
/* The alloc[] array holds memory that persists after the ELF module has
|
||||
* been loaded.
|
||||
*/
|
||||
|
||||
uintptr_t elfalloc; /* Memory allocated when ELF file was loaded */
|
||||
size_t elfsize; /* Size of the ELF memory allocation */
|
||||
off_t filelen; /* Length of the entire ELF file */
|
||||
Elf32_Ehdr ehdr; /* Buffered ELF file header */
|
||||
FAR Elf32_Shdr *shdr; /* Buffered ELF section headers */
|
||||
uint8_t *iobuffer; /* File I/O buffer */
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
FAR void *ctoralloc; /* Memory allocated for ctors */
|
||||
FAR void *dtoralloc; /* Memory allocated dtors */
|
||||
FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */
|
||||
FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */
|
||||
uint16_t nctors; /* Number of constructors */
|
||||
uint16_t ndtors; /* Number of destructors */
|
||||
#endif
|
||||
uint16_t symtabidx; /* Symbol table section index */
|
||||
uint16_t strtabidx; /* String table section index */
|
||||
uint16_t buflen; /* size of iobuffer[] */
|
||||
int filfd; /* Descriptor for the file being loaded */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs exported by libelf (but are used only by the binfmt logic):
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_init
|
||||
*
|
||||
* Description:
|
||||
* This function is called to configure the library to process an ELF
|
||||
* program binary.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_init(FAR const char *filename,
|
||||
FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_uninit
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources committed by elf_init(). This essentially
|
||||
* undoes the actions of elf_init.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_uninit(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_load
|
||||
*
|
||||
* Description:
|
||||
* Loads the binary into memory, allocating memory, performing relocations
|
||||
* and inializing the data and bss segments.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_load(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_bind
|
||||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct symtab_s;
|
||||
EXTERN int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_unload
|
||||
*
|
||||
* Description:
|
||||
* This function unloads the object from memory. This essentially
|
||||
* undoes the actions of elf_load.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_unload(struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs used outside of binfmt by NuttX:
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: elf_initialize
|
||||
*
|
||||
* Description:
|
||||
* ELF support is built unconditionally. However, it order to
|
||||
* use this binary format, this function must be called during system
|
||||
* format in order to register the ELF binary format.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* Unregister the ELF binary loader
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void elf_uninitialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs must be provided by architecture-specific logic:
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: arch_checkarch
|
||||
*
|
||||
* Description:
|
||||
* Given the ELF header in 'hdr', verify that the ELF file is appropriate
|
||||
* for the current, configured architecture. Every architecture that uses
|
||||
* the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hdr - The ELF header read from the ELF file.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this ELF file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN bool arch_checkarch(FAR const Elf32_Ehdr *hdr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_relocate and arch_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform on architecture-specific ELF relocation. Every architecture
|
||||
* that uses the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rel - The relocation type
|
||||
* sym - The ELF symbol structure containing the fully resolved value.
|
||||
* addr - The address that requires the relocation.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the relocation was successful. Otherwise, a negated errno
|
||||
* value indicating the cause of the relocation failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr);
|
||||
EXTERN int arch_relocateadd(FAR const Elf32_Rela *rel,
|
||||
FAR const Elf32_Sym *sym, uintptr_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_flushicache
|
||||
*
|
||||
* Description:
|
||||
* Flush the instruction cache.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addr - Start address to flush
|
||||
* len - Number of bytes to flush
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this ELF file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ELF_ICACHE
|
||||
EXTERN bool arch_flushicache(FAR void *addr, size_t len);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_ELF_H */
|
||||
@@ -1,264 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/nxflat.h
|
||||
*
|
||||
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_NXFLAT_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_NXFLAT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nxflat.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This struct provides a desciption of the currently loaded instantiation
|
||||
* of an nxflat binary.
|
||||
*/
|
||||
|
||||
struct nxflat_loadinfo_s
|
||||
{
|
||||
/* Instruction Space (ISpace): This region contains the nxflat file header
|
||||
* plus everything from the text section. Ideally, will have only one mmap'ed
|
||||
* text section instance in the system for each module.
|
||||
*/
|
||||
|
||||
uint32_t ispace; /* Address where hdr/text is loaded */
|
||||
uint32_t entryoffs; /* Offset from ispace to entry point */
|
||||
uint32_t isize; /* Size of ispace. */
|
||||
|
||||
/* Data Space (DSpace): This region contains all information that in referenced
|
||||
* as data (other than the stack which is separately allocated). There will be
|
||||
* a unique instance of DSpace (and stack) for each instance of a process.
|
||||
*/
|
||||
|
||||
struct dspace_s *dspace; /* Allocated D-Space (data/bss/etc) */
|
||||
uint32_t datasize; /* Size of data segment in dspace */
|
||||
uint32_t bsssize; /* Size of bss segment in dspace */
|
||||
uint32_t stacksize; /* Size of stack (not allocated) */
|
||||
uint32_t dsize; /* Size of dspace (may be large than parts) */
|
||||
|
||||
/* This is temporary memory where relocation records will be loaded. */
|
||||
|
||||
uint32_t relocstart; /* Start of array of struct flat_reloc */
|
||||
uint16_t reloccount; /* Number of elements in reloc array */
|
||||
|
||||
/* File descriptors */
|
||||
|
||||
int filfd; /* Descriptor for the file being loaded */
|
||||
|
||||
/* This is a copy of the NXFLAT header (still in network order) */
|
||||
|
||||
struct nxflat_hdr_s header;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs exported by libnxflat (and may be used outside of NuttX):
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_verifyheader
|
||||
*
|
||||
* Description:
|
||||
* Given the header from a possible NXFLAT executable, verify that it is
|
||||
* an NXFLAT executable.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_verifyheader(const struct nxflat_hdr_s *header);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_init
|
||||
*
|
||||
* Description:
|
||||
* This function is called to configure the library to process an NXFLAT
|
||||
* program binary.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_init(const char *filename,
|
||||
struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_uninit
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources committed by nxflat_init(). This essentially
|
||||
* undoes the actions of nxflat_init.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_load
|
||||
*
|
||||
* Description:
|
||||
* Loads the binary specified by nxflat_init into memory, mapping
|
||||
* the I-space executable regions, allocating the D-Space region,
|
||||
* and inializing the data segment (relocation information is
|
||||
* temporarily loaded into the BSS region. BSS will be cleared
|
||||
* by nxflat_bind() after the relocation data has been processed).
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_load(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_read
|
||||
*
|
||||
* Description:
|
||||
* Read 'readsize' bytes from the object file at 'offset'
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
|
||||
int readsize, int offset);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_bind
|
||||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'
|
||||
* After binding the module, clear the BSS region (which held the relocation
|
||||
* data) in preparation for execution.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct symtab_s;
|
||||
EXTERN int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_unload
|
||||
*
|
||||
* Description:
|
||||
* This function unloads the object from memory. This essentially
|
||||
* undoes the actions of nxflat_load.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_unload(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs used internally only by NuttX:
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: nxflat_initialize
|
||||
*
|
||||
* Description:
|
||||
* NXFLAT support is built unconditionally. However, it order to
|
||||
* use this binary format, this function must be called during system
|
||||
* format in order to register the NXFLAT binary format.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* Unregister the NXFLAT binary loader
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void nxflat_uninitialize(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_NXFLAT_H */
|
||||
@@ -1,163 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/symtab.h
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_SYMTAB_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_SYMTAB_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* struct symbtab_s describes one entry in the symbol table. A symbol table
|
||||
* is a fixed size array of struct symtab_s. The information is intentionally
|
||||
* minimal and supports only:
|
||||
*
|
||||
* 1. Function pointers as sym_values. Of other kinds of values need to be
|
||||
* supported, then typing information would also need to be included in
|
||||
* the structure.
|
||||
*
|
||||
* 2. Fixed size arrays. There is no explicit provisional for dyanamically
|
||||
* adding or removing entries from the symbol table (realloc might be
|
||||
* used for that purpose if needed). The intention is to support only
|
||||
* fixed size arrays completely defined at compilation or link time.
|
||||
*/
|
||||
|
||||
struct symtab_s
|
||||
{
|
||||
FAR const char *sym_name; /* A pointer to the symbol name string */
|
||||
FAR const void *sym_value; /* The value associated witht the string */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findbyname
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table with the matching name.
|
||||
* This version assumes that table is not ordered with respect to symbol
|
||||
* name and, hence, access time will be linear with respect to nsyms.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN FAR const struct symtab_s *
|
||||
symtab_findbyname(FAR const struct symtab_s *symtab,
|
||||
FAR const char *name, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findorderedbyname
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table with the matching name.
|
||||
* This version assumes that table ordered with respect to symbol name.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN FAR const struct symtab_s *
|
||||
symtab_findorderedbyname(FAR const struct symtab_s *symtab,
|
||||
FAR const char *name, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findbyvalue
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table whose value closest (but not greater
|
||||
* than), the provided value. This version assumes that table is not ordered
|
||||
* with respect to symbol name and, hence, access time will be linear with
|
||||
* respect to nsyms.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN FAR const struct symtab_s *
|
||||
symtab_findbyvalue(FAR const struct symtab_s *symtab,
|
||||
FAR void *value, int nsyms);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: symtab_findorderedbyvalue
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol in the symbol table whose value closest (but not greater
|
||||
* than), the provided value. This version assumes that table is ordered
|
||||
* with respect to symbol name.
|
||||
*
|
||||
* Returned Value:
|
||||
* A reference to the symbol table entry if an entry with the matching
|
||||
* name is found; NULL is returned if the entry is not found.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN FAR const struct symtab_s *
|
||||
symtab_findorderedbyvalue(FAR const struct symtab_s *symtab,
|
||||
FAR void *value, int nsyms);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_SYMTAB_H */
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/float.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/float.h.html
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_FLOAT_H
|
||||
#define __INCLUDE_NUTTX_FLOAT_H
|
||||
|
||||
/* TODO: These values could vary with architectures toolchains. This
|
||||
* logic should be move at least to the include/arch directory.
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Radix of exponent representation, b. */
|
||||
|
||||
#define FLT_RADIX 2
|
||||
|
||||
/* Number of base-FLT_RADIX digits in the floating-point significand, p. */
|
||||
|
||||
#define FLT_MANT_DIG 24
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_MANT_DIG 53
|
||||
#else
|
||||
# define DBL_MANT_DIG FLT_MANT_DIG
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_MANT_DIG DBL_MANT_DIG /* FIX ME */
|
||||
#else
|
||||
# define LDBL_MANT_DIG DBL_MANT_DIG
|
||||
#endif
|
||||
|
||||
/* Number of decimal digits, n, such that any floating-point number in the
|
||||
* widest supported floating type with pmax radix b digits can be rounded
|
||||
* to a floating-point number with n decimal digits and back again without
|
||||
* change to the value.
|
||||
*/
|
||||
|
||||
#define DECIMAL_DIG 10
|
||||
|
||||
/* Number of decimal digits, q, such that any floating-point number with q
|
||||
* decimal digits can be rounded into a floating-point number with p radix
|
||||
* b digits and back again without change to the q decimal digits.
|
||||
*/
|
||||
|
||||
#define FLT_DIG 6
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_DIG 15 /* 10 */
|
||||
#else
|
||||
# define DBL_DIG FLT_DIG
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_DIG DBL_DIG /* FIX ME */
|
||||
#else
|
||||
# define LDBL_DIG DBL_DIG
|
||||
#endif
|
||||
|
||||
/* Minimum negative integer such that FLT_RADIX raised to that power minus
|
||||
* 1 is a normalized floating-point number, emin.
|
||||
*/
|
||||
|
||||
#define FLT_MIN_EXP (-125)
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_MIN_EXP (-1021)
|
||||
#else
|
||||
# define DBL_MIN_EXP FLT_MIN_EXP
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_MIN_EXP DBL_MIN_EXP /* FIX ME */
|
||||
#else
|
||||
# define LDBL_MIN_EXP DBL_MIN_EXP
|
||||
#endif
|
||||
|
||||
/* inimum negative integer such that 10 raised to that power is in the range
|
||||
* of normalized floating-point numbers.
|
||||
*/
|
||||
|
||||
#define FLT_MIN_10_EXP (-37)
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_MIN_10_EXP (-307) /* -37 */
|
||||
#else
|
||||
# define DBL_MIN_10_EXP FLT_MIN_10_EXP
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_MIN_10_EXP DBL_MIN_10_EXP /* FIX ME */
|
||||
#else
|
||||
# define LDBL_MIN_10_EXP DBL_MIN_10_EXP
|
||||
#endif
|
||||
|
||||
/* Maximum integer such that FLT_RADIX raised to that power minus 1 is a
|
||||
* representable finite floating-point number, emax.
|
||||
*/
|
||||
|
||||
#define FLT_MAX_EXP 128
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_MAX_EXP 1024
|
||||
#else
|
||||
# define DBL_MAX_EXP FLT_MAX_EXP
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_MAX_EXP DBL_MAX_EXP /* FIX ME */
|
||||
#else
|
||||
# define LDBL_MAX_EXP DBL_MAX_EXP
|
||||
#endif
|
||||
|
||||
/* Maximum integer such that 10 raised to that power is in the range of
|
||||
* representable finite floating-point numbers.
|
||||
*/
|
||||
|
||||
#define FLT_MAX_10_EXP 38 /* 37 */
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_MAX_10_EXP 308 /* 37 */
|
||||
#else
|
||||
# define DBL_MAX_10_EXP FLT_MAX_10_EXP
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_MAX_10_EXP DBL_MAX_10_EXP /* FIX ME */
|
||||
#else
|
||||
# define LDBL_MAX_10_EXP DBL_MAX_10_EXP
|
||||
#endif
|
||||
|
||||
/* Maximum representable finite floating-point number. */
|
||||
|
||||
#define FLT_MAX 3.40282347e+38F /* 1E+37 */
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_MAX 1.7976931348623157e+308 /* 1E+37 */
|
||||
#else
|
||||
# define DBL_MAX FLT_MAX
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_MAX DBL_MAX /* FIX ME */
|
||||
#else
|
||||
# define LDBL_MAX DBL_MAX
|
||||
#endif
|
||||
|
||||
/* The difference between 1 and the least value greater than 1 that is
|
||||
* representable in the given floating-point type, b1-p.
|
||||
*/
|
||||
|
||||
#define FLT_EPSILON 1.1920929e-07F /* 1E-5 */
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
# define DBL_EPSILON 2.2204460492503131e-16 /* 1E-9 */
|
||||
#else
|
||||
# define DBL_EPSILON FLT_EPSILON
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_EPSILON DBL_EPSILON /* FIX ME */
|
||||
#else
|
||||
# define LDBL_EPSILON DBL_EPSILON
|
||||
#endif
|
||||
|
||||
/* Minimum normalized positive floating-point number, bemin -1. */
|
||||
|
||||
#define FLT_MIN 1.17549435e-38F /* 1E-37 */
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
#define DBL_MIN 2.2250738585072014e-308 /* 1E-37 */
|
||||
#else
|
||||
# define DBL_MIN FLT_MIN
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
# define LDBL_MIN DBL_MIN /* FIX ME */
|
||||
#else
|
||||
# define LDBL_MIN DBL_MIN
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_FLOAT_H */
|
||||
@@ -1,175 +0,0 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/input/max11802.h
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Authors: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Petteri Aimonen <jpa@nx.mail.kapsi.fi>
|
||||
*
|
||||
* References:
|
||||
* "Low-Power, Ultra-Small Resistive Touch-Screen Controllers
|
||||
* with I2C/SPI Interface" Maxim IC, Rev 3, 10/2010
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_INPUT_MAX11802_H
|
||||
#define __INCLUDE_NUTTX_INPUT_MAX11802_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/spi.h>
|
||||
#include <stdbool.h>
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_MAX11802)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
/* SPI Frequency. Default: 100KHz */
|
||||
|
||||
#ifndef CONFIG_MAX11802_FREQUENCY
|
||||
# define CONFIG_MAX11802_FREQUENCY 100000
|
||||
#endif
|
||||
|
||||
/* Maximum number of threads than can be waiting for POLL events */
|
||||
|
||||
#ifndef CONFIG_MAX11802_NPOLLWAITERS
|
||||
# define CONFIG_MAX11802_NPOLLWAITERS 2
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_MAX11802_SPIMODE
|
||||
# define CONFIG_MAX11802_SPIMODE SPIDEV_MODE0
|
||||
#endif
|
||||
|
||||
/* Thresholds */
|
||||
|
||||
#ifndef CONFIG_MAX11802_THRESHX
|
||||
# define CONFIG_MAX11802_THRESHX 12
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_MAX11802_THRESHY
|
||||
# define CONFIG_MAX11802_THRESHY 12
|
||||
#endif
|
||||
|
||||
/* Check for some required settings. This can save the user a lot of time
|
||||
* in getting the right configuration.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_DISABLE_SIGNALS
|
||||
# error "Signals are required. CONFIG_DISABLE_SIGNALS must not be selected."
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SCHED_WORKQUEUE
|
||||
# error "Work queue support required. CONFIG_SCHED_WORKQUEUE must be selected."
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* A reference to a structure of this type must be passed to the MAX11802
|
||||
* driver. This structure provides information about the configuration
|
||||
* of the MAX11802 and provides some board-specific hooks.
|
||||
*
|
||||
* Memory for this structure is provided by the caller. It is not copied
|
||||
* by the driver and is presumed to persist while the driver is active. The
|
||||
* memory must be writable because, under certain circumstances, the driver
|
||||
* may modify frequency or X plate resistance values.
|
||||
*/
|
||||
|
||||
struct max11802_config_s
|
||||
{
|
||||
/* Device characterization */
|
||||
|
||||
uint32_t frequency; /* SPI frequency */
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
||||
* callbacks to isolate the MAX11802 driver from differences in GPIO
|
||||
* interrupt handling by varying boards and MCUs. If possible,
|
||||
* interrupts should be configured on both rising and falling edges
|
||||
* so that contact and loss-of-contact events can be detected.
|
||||
*
|
||||
* attach - Attach the MAX11802 interrupt handler to the GPIO interrupt
|
||||
* enable - Enable or disable the GPIO interrupt
|
||||
* clear - Acknowledge/clear any pending GPIO interrupt
|
||||
* pendown - Return the state of the pen down GPIO input
|
||||
*/
|
||||
|
||||
int (*attach)(FAR struct max11802_config_s *state, xcpt_t isr);
|
||||
void (*enable)(FAR struct max11802_config_s *state, bool enable);
|
||||
void (*clear)(FAR struct max11802_config_s *state);
|
||||
bool (*pendown)(FAR struct max11802_config_s *state);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: max11802_register
|
||||
*
|
||||
* Description:
|
||||
* Configure the MAX11802 to use the provided SPI device instance. This
|
||||
* will register the driver as /dev/inputN where N is the minor device
|
||||
* number
|
||||
*
|
||||
* Input Parameters:
|
||||
* spi - An SPI driver instance
|
||||
* config - Persistent board configuration data
|
||||
* minor - The input device minor number
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero is returned on success. Otherwise, a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int max11802_register(FAR struct spi_dev_s *spi,
|
||||
FAR struct max11802_config_s *config,
|
||||
int minor);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_INPUT && CONFIG_INPUT_MAX11802 */
|
||||
#endif /* __INCLUDE_NUTTX_INPUT_MAX11802_H */
|
||||
@@ -1,245 +0,0 @@
|
||||
/**************************************************************************************
|
||||
* include/nuttx/lcd/ug-2864ambag01.h
|
||||
* Driver for Univision UG-2864AMBAG01 OLED display (wih SH1101A controller) in SPI
|
||||
* mode
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* References:
|
||||
* 1. Product Specification (Preliminary), Part Name: OEL Display Module, Part ID:
|
||||
* UG-2864AMBAG01, Doc No: SASI-9015-A, Univision Technology Inc.
|
||||
* 2. SH1101A, 132 X 64 Dot Matrix OLED/PLED, Preliminary Segment/Common Driver with
|
||||
* Controller, Sino Wealth
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_UG_8264AMBAG01_H
|
||||
#define __INCLUDE_NUTTX_UG_8264AMBAG01_H
|
||||
|
||||
/**************************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
#ifdef CONFIG_LCD_UG2864AMBAG01
|
||||
|
||||
/**************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
**************************************************************************************/
|
||||
/* Configuration **********************************************************************/
|
||||
/* UG-2864AMBAG01 Configuration Settings:
|
||||
*
|
||||
* CONFIG_UG2864AMBAG01_SPIMODE - Controls the SPI mode
|
||||
* CONFIG_UG2864AMBAG01_FREQUENCY - Define to use a different bus frequency
|
||||
* CONFIG_UG2864AMBAG01_NINTERFACES - Specifies the number of physical UG-2864AMBAG01
|
||||
* devices that will be supported.
|
||||
*
|
||||
* Required LCD driver settings:
|
||||
*
|
||||
* CONFIG_LCD_UG28AMBAG01 - Enable UG-2864AMBAG01 support
|
||||
* CONFIG_LCD_MAXCONTRAST should be 255, but any value >0 and <=255 will be accepted.
|
||||
* CONFIG_LCD_MAXPOWER must be 1
|
||||
*
|
||||
* Option LCD driver settings:
|
||||
* CONFIG_LCD_LANDSCAPE, CONFIG_LCD_PORTRAIT, CONFIG_LCD_RLANDSCAPE, and
|
||||
* CONFIG_LCD_RPORTRAIT - Display orientation.
|
||||
*
|
||||
* Required SPI driver settings:
|
||||
* CONFIG_SPI_CMDDATA - Include support for cmd/data selection.
|
||||
*/
|
||||
|
||||
/* SPI Interface
|
||||
*
|
||||
* "The serial interface consists of serial clock SCL, serial data SI, A0 and
|
||||
* CS . SI is shifted into an 8-bit shift register on every rising edge of
|
||||
* SCL in the order of D7, D6, … and D0. A0 is sampled on every eighth clock
|
||||
* and the data byte in the shift register is written to the display data RAM
|
||||
* or command register in the same clock."
|
||||
*
|
||||
* MODE 3:
|
||||
* Clock polarity: High (CPOL=1)
|
||||
* Clock phase: Sample on trailing (rising edge) (CPHA 1)
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_UG2864AMBAG01_SPIMODE
|
||||
# define CONFIG_UG2864AMBAG01_SPIMODE SPIDEV_MODE3
|
||||
#endif
|
||||
|
||||
/* "This module determines whether the input data is interpreted as data or
|
||||
* command. When A0 = “H”, the inputs at D7 - D0 are interpreted as data and be
|
||||
* written to display RAM. When A0 = “L”, the inputs at D7 - D0 are interpreted
|
||||
* as command, they will be decoded and be written to the corresponding command
|
||||
* registers.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_SPI_CMDDATA
|
||||
# error "CONFIG_SPI_CMDDATA must be defined in your NuttX configuration"
|
||||
#endif
|
||||
|
||||
/* CONFIG_UG2864AMBAG01_NINTERFACES determines the number of physical interfaces
|
||||
* that will be supported.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_UG2864AMBAG01_NINTERFACES
|
||||
# define CONFIG_UG2864AMBAG01_NINTERFACES 1
|
||||
#endif
|
||||
|
||||
/* Check contrast selection */
|
||||
|
||||
#if !defined(CONFIG_LCD_MAXCONTRAST)
|
||||
# define CONFIG_LCD_MAXCONTRAST 255
|
||||
#endif
|
||||
|
||||
#if CONFIG_LCD_MAXCONTRAST <= 0|| CONFIG_LCD_MAXCONTRAST > 255
|
||||
# error "CONFIG_LCD_MAXCONTRAST exceeds supported maximum"
|
||||
#endif
|
||||
|
||||
#if CONFIG_LCD_MAXCONTRAST < 255
|
||||
# warning "Optimal setting of CONFIG_LCD_MAXCONTRAST is 255"
|
||||
#endif
|
||||
|
||||
/* Check power setting */
|
||||
|
||||
#if !defined(CONFIG_LCD_MAXPOWER)
|
||||
# define CONFIG_LCD_MAXPOWER 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_LCD_MAXPOWER != 1
|
||||
# warning "CONFIG_LCD_MAXPOWER exceeds supported maximum"
|
||||
# undef CONFIG_LCD_MAXPOWER
|
||||
# define CONFIG_LCD_MAXPOWER 1
|
||||
#endif
|
||||
|
||||
/* Color is 1bpp monochrome with leftmost column contained in bits 0 */
|
||||
|
||||
#ifdef CONFIG_NX_DISABLE_1BPP
|
||||
# warning "1 bit-per-pixel support needed"
|
||||
#endif
|
||||
|
||||
/* Orientation */
|
||||
|
||||
#if defined(CONFIG_LCD_LANDSCAPE)
|
||||
# undef CONFIG_LCD_PORTRAIT
|
||||
# undef CONFIG_LCD_RLANDSCAPE
|
||||
# undef CONFIG_LCD_RPORTRAIT
|
||||
#elif defined(CONFIG_LCD_PORTRAIT)
|
||||
# undef CONFIG_LCD_LANDSCAPE
|
||||
# undef CONFIG_LCD_RLANDSCAPE
|
||||
# undef CONFIG_LCD_RPORTRAIT
|
||||
#elif defined(CONFIG_LCD_RLANDSCAPE)
|
||||
# undef CONFIG_LCD_LANDSCAPE
|
||||
# undef CONFIG_LCD_PORTRAIT
|
||||
# undef CONFIG_LCD_RPORTRAIT
|
||||
#elif defined(CONFIG_LCD_RPORTRAIT)
|
||||
# undef CONFIG_LCD_LANDSCAPE
|
||||
# undef CONFIG_LCD_PORTRAIT
|
||||
# undef CONFIG_LCD_RLANDSCAPE
|
||||
#else
|
||||
# define CONFIG_LCD_LANDSCAPE 1
|
||||
# warning "Assuming landscape orientation"
|
||||
#endif
|
||||
|
||||
/* Some important "colors" */
|
||||
|
||||
#define UG_Y1_BLACK 0
|
||||
#define UG_Y1_WHITE 1
|
||||
|
||||
/**************************************************************************************
|
||||
* Public Types
|
||||
**************************************************************************************/
|
||||
|
||||
/**************************************************************************************
|
||||
* Public Data
|
||||
**************************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**************************************************************************************
|
||||
* Public Function Prototypes
|
||||
**************************************************************************************/
|
||||
|
||||
/**************************************************************************************
|
||||
* Name: ug2864ambag01_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the UG-2864AMBAG01 video hardware. The initial state of the
|
||||
* OLED is fully initialized, display memory cleared, and the OLED ready
|
||||
* to use, but with the power setting at 0 (full off == sleep mode).
|
||||
*
|
||||
* Input Parameters:
|
||||
*
|
||||
* spi - A reference to the SPI driver instance.
|
||||
* devno - A value in the range of 0 through CONFIG_UG2864AMBAG01_NINTERFACES-1.
|
||||
* This allows support for multiple OLED devices.
|
||||
*
|
||||
* Returned Value:
|
||||
*
|
||||
* On success, this function returns a reference to the LCD object for
|
||||
* the specified OLED. NULL is returned on any failure.
|
||||
*
|
||||
**************************************************************************************/
|
||||
|
||||
struct lcd_dev_s; /* See include/nuttx/lcd/lcd.h */
|
||||
struct spi_dev_s; /* See include/nuttx/spi.h */
|
||||
FAR struct lcd_dev_s *ug2864ambag01_initialize(FAR struct spi_dev_s *spi,
|
||||
unsigned int devno);
|
||||
|
||||
/************************************************************************************************
|
||||
* Name: ug2864ambag01_fill
|
||||
*
|
||||
* Description:
|
||||
* This non-standard method can be used to clear the entire display by writing one
|
||||
* color to the display. This is much faster than writing a series of runs.
|
||||
*
|
||||
* Input Parameters:
|
||||
* priv - Reference to private driver structure
|
||||
*
|
||||
* Assumptions:
|
||||
* Caller has selected the OLED section.
|
||||
*
|
||||
**************************************************************************************/
|
||||
|
||||
void ug2864ambag01_fill(FAR struct lcd_dev_s *dev, uint8_t color);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LCD_UG2864AMBAG01 */
|
||||
#endif /* __INCLUDE_NUTTX_UG_8264AMBAG01_H */
|
||||
@@ -1,275 +0,0 @@
|
||||
#
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
config STDIO_BUFFER_SIZE
|
||||
int "C STDIO buffer size"
|
||||
default 64
|
||||
---help---
|
||||
Size of buffers using within the C buffered I/O interfaces.
|
||||
(printf, putchar, fwrite, etc.).
|
||||
|
||||
config STDIO_LINEBUFFER
|
||||
bool "STDIO line buffering"
|
||||
default y
|
||||
---help---
|
||||
Flush buffer I/O whenever a newline character is found in
|
||||
the output data stream.
|
||||
|
||||
config NUNGET_CHARS
|
||||
int "Number unget() characters"
|
||||
default 2
|
||||
---help---
|
||||
Number of characters that can be buffered by ungetc() (Only if NFILE_STREAMS > 0)
|
||||
|
||||
config LIB_HOMEDIR
|
||||
string "Home directory"
|
||||
default "/"
|
||||
depends on !DISABLE_ENVIRON
|
||||
---help---
|
||||
The home directory to use with operations like such as 'cd ~'
|
||||
|
||||
source libc/math/Kconfig
|
||||
|
||||
config NOPRINTF_FIELDWIDTH
|
||||
bool "Disable sprintf support fieldwidth"
|
||||
default n
|
||||
---help---
|
||||
sprintf-related logic is a
|
||||
little smaller if we do not support fieldwidthes
|
||||
|
||||
config LIBC_FLOATINGPOINT
|
||||
bool "Enable floating point in printf"
|
||||
default n
|
||||
---help---
|
||||
By default, floating point
|
||||
support in printf, sscanf, etc. is disabled.
|
||||
|
||||
choice
|
||||
prompt "Newline Options"
|
||||
default EOL_IS_EITHER_CRLF
|
||||
---help---
|
||||
This selection determines the line terminating character that is used.
|
||||
Some environments may return CR as end-of-line, others LF, and others
|
||||
both. If not specified, the default is either CR or LF (but not both)
|
||||
as the line terminating charactor.
|
||||
|
||||
config EOL_IS_CR
|
||||
bool "EOL is CR"
|
||||
|
||||
config EOL_IS_LF
|
||||
bool "EOL is LF"
|
||||
|
||||
config EOL_IS_BOTH_CRLF
|
||||
bool "EOL is CR and LF"
|
||||
|
||||
config EOL_IS_EITHER_CRLF
|
||||
bool "EOL is CR or LF"
|
||||
|
||||
endchoice
|
||||
|
||||
config LIBC_STRERROR
|
||||
bool "Enable strerror"
|
||||
default n
|
||||
---help---
|
||||
strerror() is useful because it decodes 'errno' values into a human readable
|
||||
strings. But it can also require a lot of memory. If this option is selected,
|
||||
strerror() will still exist in the build but it will not decode error values.
|
||||
This option should be used by other logic to decide if it should use strerror()
|
||||
or not. For example, the NSH application will not use strerror() if this
|
||||
option is not selected; perror() will not use strerror() is this option is not
|
||||
selected (see also NSH_STRERROR).
|
||||
|
||||
config LIBC_STRERROR_SHORT
|
||||
bool "Use short error descriptions in strerror()"
|
||||
default n
|
||||
depends on LIBC_STRERROR
|
||||
---help---
|
||||
If this option is selected, then strerror() will use a shortened string when
|
||||
it decodes the error. Specifically, strerror() is simply use the string that
|
||||
is the common name for the error. For example, the 'errno' value of 2 will
|
||||
produce the string "No such file or directory" is LIBC_STRERROR_SHORT
|
||||
is not defined but the string "ENOENT" is LIBC_STRERROR_SHORT is defined.
|
||||
|
||||
config LIBC_PERROR_STDOUT
|
||||
bool "perror() to stdout"
|
||||
default n
|
||||
---help---
|
||||
POSIX requires that perror() provide its output on stderr. This option may
|
||||
be defined, however, to provide perror() output that is serialized with
|
||||
other stdout messages.
|
||||
|
||||
config ARCH_LOWPUTC
|
||||
bool "Low-level console output"
|
||||
default "y"
|
||||
---help---
|
||||
architecture supports low-level, boot time console output
|
||||
|
||||
config LIB_SENDFILE_BUFSIZE
|
||||
int "sendfile() buffer size"
|
||||
default 512
|
||||
---help---
|
||||
Size of the I/O buffer to allocate in sendfile(). Default: 512b
|
||||
|
||||
config ARCH_ROMGETC
|
||||
bool "Support for ROM string access"
|
||||
default n
|
||||
---help---
|
||||
In Harvard architectures, data accesses and instruction accesses
|
||||
occur on different busses, perhaps concurrently. All data accesses
|
||||
are performed on the data bus unless special machine instructions
|
||||
are used to read data from the instruction address space. Also, in
|
||||
the typical MCU, the available SRAM data memory is much smaller that
|
||||
the non-volatile FLASH instruction memory. So if the application
|
||||
requires many constant strings, the only practical solution may be
|
||||
to store those constant strings in FLASH memory where they can only
|
||||
be accessed using architecture-specific machine instructions.
|
||||
|
||||
If ARCH_ROMGETC is defined, then the architecture logic must export
|
||||
the function up_romgetc(). up_romgetc() will simply read one byte
|
||||
of data from the instruction space.
|
||||
|
||||
If ARCH_ROMGETC, certain C stdio functions are effected: (1) All
|
||||
format strings in printf, fprintf, sprintf, etc. are assumed to lie
|
||||
in FLASH (string arguments for %s are still assumed to reside in SRAM).
|
||||
And (2), the string argument to puts and fputs is assumed to reside
|
||||
in FLASH. Clearly, these assumptions may have to modified for the
|
||||
particular needs of your environment. There is no "one-size-fits-all"
|
||||
solution for this problem.
|
||||
|
||||
config ARCH_OPTIMIZED_FUNCTIONS
|
||||
bool "Enable arch optimized functions"
|
||||
default n
|
||||
---help---
|
||||
Allow for architecture optimized implementations of certain library
|
||||
functions. Architecture-specific implementations can improve overall
|
||||
system performance.
|
||||
|
||||
if ARCH_OPTIMIZED_FUNCTIONS
|
||||
config ARCH_MEMCPY
|
||||
bool "memcpy()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of memcpy().
|
||||
|
||||
config MEMCPY_VIK
|
||||
bool "Vik memcpy()"
|
||||
default n
|
||||
depends on !ARCH_MEMCPY
|
||||
---help---
|
||||
Select this option to use the optimized memcpy() function by Daniel Vik.
|
||||
Select this option for improved performance at the expense of increased
|
||||
size. See licensing information in the top-level COPYING file.
|
||||
|
||||
if MEMCPY_VIK
|
||||
config MEMCPY_PRE_INC_PTRS
|
||||
bool "Pre-increment pointers"
|
||||
default n
|
||||
---help---
|
||||
Use pre-increment of pointers. Default is post increment of pointers.
|
||||
|
||||
config MEMCPY_INDEXED_COPY
|
||||
bool "Array indexing"
|
||||
default y
|
||||
---help---
|
||||
Copying data using array indexing. Using this option, disables the
|
||||
MEMCPY_PRE_INC_PTRS option.
|
||||
|
||||
config MEMCPY_64BIT
|
||||
bool "64-bit memcpy()"
|
||||
default n
|
||||
---help---
|
||||
Compiles memcpy() for architectures that suppport 64-bit operations
|
||||
efficiently.
|
||||
|
||||
endif
|
||||
|
||||
config ARCH_MEMCMP
|
||||
bool "memcmp()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of memcmp().
|
||||
|
||||
config ARCH_MEMMOVE
|
||||
bool "memmove()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of memmove().
|
||||
|
||||
config ARCH_MEMSET
|
||||
bool "memset()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of memset().
|
||||
|
||||
config MEMSET_OPTSPEED
|
||||
bool "Optimize memset() for speed"
|
||||
default n
|
||||
depends on !ARCH_MEMSET
|
||||
---help---
|
||||
Select this option to use a version of memcpy() optimized for speed.
|
||||
Default: memcpy() is optimized for size.
|
||||
|
||||
config MEMSET_64BIT
|
||||
bool "64-bit memset()"
|
||||
default n
|
||||
depends on MEMSET_OPTSPEED
|
||||
---help---
|
||||
Compiles memset() for architectures that suppport 64-bit operations
|
||||
efficiently.
|
||||
|
||||
config ARCH_STRCHR
|
||||
bool "strchr()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of strchr().
|
||||
|
||||
config ARCH_STRCMP
|
||||
bool "strcmp()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of strcmp().
|
||||
|
||||
config ARCH_STRCPY
|
||||
bool "strcpy()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of strcpy().
|
||||
|
||||
config ARCH_STRNCPY
|
||||
bool "strncpy()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of strncpy().
|
||||
|
||||
config ARCH_STRLEN
|
||||
bool "strlen"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of strlen().
|
||||
|
||||
config ARCH_STRNLEN
|
||||
bool "strlen()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of strnlen().
|
||||
|
||||
config ARCH_BZERO
|
||||
bool "bzero()"
|
||||
default n
|
||||
---help---
|
||||
Select this option if the architecture provides an optimized version
|
||||
of bzero().
|
||||
|
||||
endif
|
||||
@@ -1,145 +0,0 @@
|
||||
############################################################################
|
||||
# libc/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
###########################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
ASRCS =
|
||||
CSRCS =
|
||||
|
||||
DEPPATH := --dep-path .
|
||||
VPATH := .
|
||||
|
||||
include stdio/Make.defs
|
||||
include stdlib/Make.defs
|
||||
include unistd/Make.defs
|
||||
include sched/Make.defs
|
||||
include string/Make.defs
|
||||
include pthread/Make.defs
|
||||
include semaphore/Make.defs
|
||||
include signal/Make.defs
|
||||
include mqueue/Make.defs
|
||||
include math/Make.defs
|
||||
include fixedmath/Make.defs
|
||||
include net/Make.defs
|
||||
include time/Make.defs
|
||||
include libgen/Make.defs
|
||||
include dirent/Make.defs
|
||||
include termios/Make.defs
|
||||
include queue/Make.defs
|
||||
include misc/Make.defs
|
||||
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
|
||||
UBIN = libuc$(LIBEXT)
|
||||
KBIN = libkc$(LIBEXT)
|
||||
BIN = libc$(LIBEXT)
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
$(call ARCHIVE, $@, $(OBJS))
|
||||
|
||||
ifneq ($(BIN),$(UBIN))
|
||||
.userlib:
|
||||
$(Q) $(MAKE) $(UBIN) BIN=$(UBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
|
||||
$(Q) touch .userlib
|
||||
|
||||
$(UBIN): kclean .userlib
|
||||
endif
|
||||
|
||||
ifneq ($(BIN),$(KBIN))
|
||||
.kernlib:
|
||||
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) TOPDIR=$(TOPDIR) EXTRADEFINES=$(EXTRADEFINES)
|
||||
$(Q) touch .kernlib
|
||||
|
||||
$(KBIN): uclean .kernlib
|
||||
endif
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
$(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
# Clean Targets:
|
||||
# Clean user-mode temporary files (retaining the UBIN binary)
|
||||
|
||||
uclean:
|
||||
ifneq ($(OBJEXT),)
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
$(Q) if exist .userlib ]; then del *$(OBJEXT)
|
||||
else
|
||||
$(Q) ( if [ -f .userlib ]; then rm -f *$(OBJEXT); fi )
|
||||
endif
|
||||
endif
|
||||
$(call DELFILE, .userlib)
|
||||
|
||||
# Clean kernel-mode temporary files (retaining the KBIN binary)
|
||||
|
||||
kclean:
|
||||
ifneq ($(OBJEXT),)
|
||||
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
$(Q) if exist .kernlib ]; then del *$(OBJEXT)
|
||||
else
|
||||
$(Q) ( if [ -f .kernlib ]; then rm -f *$(OBJEXT); fi )
|
||||
endif
|
||||
endif
|
||||
$(call DELFILE, .kernlib)
|
||||
|
||||
# Really clean everything
|
||||
|
||||
clean: uclean kclean
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call DELFILE, $(UBIN))
|
||||
$(call DELFILE, $(KBIN))
|
||||
$(call CLEAN)
|
||||
|
||||
# Deep clean -- removes all traces of the configuration
|
||||
|
||||
distclean: clean
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
||||
@@ -1,85 +0,0 @@
|
||||
lib
|
||||
===
|
||||
|
||||
This directory contains numerous, small functions typically associated with
|
||||
what you would expect to find in a standard C library. The sub-directories
|
||||
in this directory contain standard interface that can be executed by user-
|
||||
mode programs.
|
||||
|
||||
Normally, NuttX is built with no protection and all threads running in kerne-
|
||||
mode. In that model, there is no real architectural distinction between
|
||||
what is a kernel-mode program and what is a user-mode program; the system is
|
||||
more like on multi-threaded program that all runs in kernel-mode.
|
||||
|
||||
But if the CONFIG_NUTTX_KERNEL option is selected, NuttX will be built into
|
||||
distinct user-mode and kernel-mode sections. In that case, most of the
|
||||
code in the nuttx/ directory will run in kernel-mode with with exceptions
|
||||
of (1) the user-mode "proxies" found in syscall/proxies, and (2) the
|
||||
standard C library functions found in this directory. In this build model,
|
||||
it is critical to separate the user-mode OS interfaces in this way.
|
||||
|
||||
Sub-Directories
|
||||
===============
|
||||
|
||||
The files in the libc/ directory are organized (mostly) according which file
|
||||
in the include/ directory provides the prototype for library functions. So
|
||||
we have:
|
||||
|
||||
libgen - libgen.h
|
||||
fixedmath - fixedmath.h
|
||||
math - math.h
|
||||
mqueue - pthread.h
|
||||
net - Various network-related header files: netinet/ether.h, arpa/inet.h
|
||||
pthread - pthread.h
|
||||
queue - queue.h
|
||||
sched - sched.h
|
||||
semaphore - semaphore.h
|
||||
stdio - stdio.h
|
||||
stdlib - stdlib.h
|
||||
string - string.h
|
||||
time - time.h
|
||||
unistd - unistd.h
|
||||
|
||||
There is also a misc/ subdirectory that contains various internal functions
|
||||
and interfaces from header files that are too few to warrant their own sub-
|
||||
directory:
|
||||
|
||||
misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h
|
||||
|
||||
Library Database
|
||||
================
|
||||
|
||||
Information about functions available in the NuttX C library information is
|
||||
maintained in a database. That "database" is implemented as a simple comma-
|
||||
separated-value file, lib.csv. Most spreadsheets programs will accept this
|
||||
format and can be used to maintain the library database.
|
||||
|
||||
This library database will (eventually) be used to generate symbol library
|
||||
symbol table information that can be exported to external applications.
|
||||
|
||||
The format of the CSV file for each line is:
|
||||
|
||||
Field 1: Function name
|
||||
Field 2: The header file that contains the function prototype
|
||||
Field 3: Condition for compilation
|
||||
Field 4: The type of function return value.
|
||||
Field 5 - N+5: The type of each of the N formal parameters of the function
|
||||
|
||||
Each type field has a format as follows:
|
||||
|
||||
type name:
|
||||
For all simpler types
|
||||
formal type | actual type:
|
||||
For array types where the form of the formal (eg. int parm[2])
|
||||
differs from the type of actual passed parameter (eg. int*). This
|
||||
is necessary because you cannot do simple casts to array types.
|
||||
formal type | union member actual type | union member fieldname:
|
||||
A similar situation exists for unions. For example, the formal
|
||||
parameter type union sigval -- You cannot cast a uintptr_t to
|
||||
a union sigval, but you can cast to the type of one of the union
|
||||
member types when passing the actual paramter. Similarly, we
|
||||
cannot cast a union sigval to a uinptr_t either. Rather, we need
|
||||
to cast a specific union member fieldname to uintptr_t.
|
||||
|
||||
NOTE: The tool mksymtab can be used to generate a symbol table from this CSV
|
||||
file. See nuttx/tools/README.txt for further details about the use of mksymtab.
|
||||
@@ -1,48 +0,0 @@
|
||||
############################################################################
|
||||
# libc/dirent/Make.defs
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||
|
||||
# Add the dirent C files to the build
|
||||
|
||||
CSRCS += lib_readdirr.c lib_telldir.c
|
||||
|
||||
# Add the dirent directory to the build
|
||||
|
||||
DEPPATH += --dep-path dirent
|
||||
VPATH += :dirent
|
||||
|
||||
endif
|
||||
|
||||
@@ -1,122 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libc/dirent/lib_readdirr.c
|
||||
*
|
||||
* Copyright (C) 2007-2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: readdir_r
|
||||
*
|
||||
* Description:
|
||||
* The readdir() function returns a pointer to a dirent
|
||||
* structure representing the next directory entry in the
|
||||
* directory stream pointed to by dir. It returns NULL on
|
||||
* reaching the end-of-file or if an error occurred.
|
||||
*
|
||||
* Inputs:
|
||||
* dirp -- An instance of type DIR created by a previous
|
||||
* call to opendir();
|
||||
* entry -- The storage pointed to by entry must be large
|
||||
* enough for a dirent with an array of char d_name
|
||||
* members containing at least {NAME_MAX}+1 elements.
|
||||
* result -- Upon successful return, the pointer returned
|
||||
* at *result shall have the same value as the
|
||||
* argument entry. Upon reaching the end of the directory
|
||||
* stream, this pointer shall have the value NULL.
|
||||
*
|
||||
* Return:
|
||||
* If successful, the readdir_r() function return s zero;
|
||||
* otherwise, an error number is returned to indicate the
|
||||
* error.
|
||||
*
|
||||
* EBADF - Invalid directory stream descriptor dir
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int readdir_r(FAR DIR *dirp, FAR struct dirent *entry,
|
||||
FAR struct dirent **result)
|
||||
{
|
||||
struct dirent *tmp;
|
||||
|
||||
/* NOTE: The following use or errno is *not* thread-safe */
|
||||
|
||||
set_errno(0);
|
||||
tmp = readdir(dirp);
|
||||
if (!tmp)
|
||||
{
|
||||
int error = get_errno();
|
||||
if (!error)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
*result = NULL;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
if (entry)
|
||||
{
|
||||
memcpy(entry, tmp, sizeof(struct dirent));
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
*result = entry;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libc/dirent/fs_telldir.c
|
||||
*
|
||||
* Copyright (C) 2007-2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/fs/dirent.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: telldir
|
||||
*
|
||||
* Description:
|
||||
* The telldir() function returns the current location
|
||||
* associated with the directory stream dirp.
|
||||
*
|
||||
* Inputs:
|
||||
* dirp -- An instance of type DIR created by a previous
|
||||
* call to opendir();
|
||||
*
|
||||
* Return:
|
||||
* On success, the telldir() function returns the current
|
||||
* location in the directory stream. On error, -1 is
|
||||
* returned, and errno is set appropriately.
|
||||
*
|
||||
* EBADF - Invalid directory stream descriptor dir
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
off_t telldir(FAR DIR *dirp)
|
||||
{
|
||||
struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
|
||||
|
||||
if (!idir || !idir->fd_root)
|
||||
{
|
||||
set_errno(EBADF);
|
||||
return (off_t)-1;
|
||||
}
|
||||
|
||||
/* Just return the current position */
|
||||
|
||||
return idir->fd_position;
|
||||
}
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
############################################################################
|
||||
# libc/fixedmath/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Add the fixed precision math C files to the build
|
||||
|
||||
CSRCS += lib_rint.c lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c
|
||||
|
||||
# Add the fixed precision math directory to the build
|
||||
|
||||
DEPPATH += --dep-path fixedmath
|
||||
VPATH += :fixedmath
|
||||
@@ -1,108 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libc/fixedmath/lib_b16atan2.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fixedmath.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define B16_C1 0x00000373 /* 0.013480470 */
|
||||
#define B16_C2 0x00000eb7 /* 0.057477314 */
|
||||
#define B16_C3 0x00001f0a /* 0.121239071 */
|
||||
#define B16_C4 0x00003215 /* 0.195635925 */
|
||||
#define B16_C5 0x0000553f /* 0.332994597 */
|
||||
#define B16_C6 0x00010000 /* 0.999995630 */
|
||||
#define B16_HALFPI 0x00019220 /* 1.570796327 */
|
||||
#define B16_PI 0x00032440 /* 3.141592654 */
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (a < b ? a : b)
|
||||
#endif
|
||||
|
||||
#ifndef ABS
|
||||
# define ABS(a) (a < 0 ? -a : a)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16atan2
|
||||
*
|
||||
* Description:
|
||||
* atan2 calculates the arctangent of y/x. (Based on a algorithm I saw
|
||||
* posted on the internet... now I have lost the link -- sorry).
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16atan2(b16_t y, b16_t x)
|
||||
{
|
||||
b16_t t0;
|
||||
b16_t t1;
|
||||
b16_t t2;
|
||||
b16_t t3;
|
||||
|
||||
t2 = ABS(x);
|
||||
t1 = ABS(y);
|
||||
t0 = MAX(t2, t1);
|
||||
t1 = MIN(t2, t1);
|
||||
t2 = ub16inv(t0);
|
||||
t2 = b16mulb16(t1, t2);
|
||||
|
||||
t3 = b16mulb16(t2, t2);
|
||||
t0 = - B16_C1;
|
||||
t0 = b16mulb16(t0, t3) + B16_C2;
|
||||
t0 = b16mulb16(t0, t3) - B16_C3;
|
||||
t0 = b16mulb16(t0, t3) + B16_C4;
|
||||
t0 = b16mulb16(t0, t3) - B16_C5;
|
||||
t0 = b16mulb16(t0, t3) + B16_C6;
|
||||
t2 = b16mulb16(t0, t2);
|
||||
|
||||
t2 = (ABS(y) > ABS(x)) ? B16_HALFPI - t2 : t2;
|
||||
t2 = (x < 0) ? B16_PI - t2 : t2;
|
||||
t2 = (y < 0) ? -t2 : t2;
|
||||
|
||||
return t2;
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libc/fixedmath/lib_b16cos.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fixedmath.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16cos
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16cos(b16_t rad)
|
||||
{
|
||||
/* Compute cosine: sin(rad + PI/2) = cos(rad) */
|
||||
|
||||
rad += b16HALFPI;
|
||||
if (rad > b16PI)
|
||||
{
|
||||
rad -= b16TWOPI;
|
||||
}
|
||||
return b16sin(rad);
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libc/fixedmath/lib_b16sin.c
|
||||
*
|
||||
* Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <fixedmath.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define b16_P225 0x0000399a
|
||||
#define b16_P405284735 0x000067c1
|
||||
#define b16_1P27323954 0x000145f3
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16sin
|
||||
* Ref: http://lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16sin(b16_t rad)
|
||||
{
|
||||
b16_t tmp1;
|
||||
b16_t tmp2;
|
||||
b16_t tmp3;
|
||||
|
||||
/* Force angle into the good range */
|
||||
|
||||
if (rad < -b16PI)
|
||||
{
|
||||
rad += b16TWOPI;
|
||||
}
|
||||
else if (rad > b16PI)
|
||||
{
|
||||
rad -= b16TWOPI;
|
||||
}
|
||||
|
||||
/* tmp1 = 1.27323954 * rad
|
||||
* tmp2 = .405284735 * rad * rad
|
||||
*/
|
||||
|
||||
|
||||
tmp1 = b16mulb16(b16_1P27323954, rad);
|
||||
tmp2 = b16mulb16(b16_P405284735, b16sqr(rad));
|
||||
|
||||
if (rad < 0)
|
||||
{
|
||||
/* tmp3 = 1.27323954 * rad + .405284735 * rad * rad */
|
||||
|
||||
tmp3 = tmp1 + tmp2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* tmp3 = 1.27323954 * rad - 0.405284735 * rad * rad */
|
||||
|
||||
tmp3 = tmp1 - tmp2;
|
||||
}
|
||||
|
||||
/* tmp1 = tmp3*tmp3 */
|
||||
|
||||
tmp1 = b16sqr(tmp3);
|
||||
if (tmp3 < 0)
|
||||
{
|
||||
/* tmp1 = tmp3 * -tmp3 */
|
||||
|
||||
tmp1 = -tmp1;
|
||||
}
|
||||
|
||||
/* Return sin = .225 * (tmp3 * (+/-tmp3) - tmp3) + tmp3 */
|
||||
|
||||
return b16mulb16(b16_P225, (tmp1 - tmp3)) + tmp3;
|
||||
}
|
||||
@@ -1,272 +0,0 @@
|
||||
/****************************************************************************
|
||||
* libc/math/lib_fixedmath.c
|
||||
*
|
||||
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <fixedmath.h>
|
||||
|
||||
#ifndef CONFIG_HAVE_LONG_LONG
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fixsign
|
||||
****************************************************************************/
|
||||
|
||||
static void fixsign(b16_t *parg1, b16_t *parg2, bool *pnegate)
|
||||
{
|
||||
bool negate = false;
|
||||
b16_t arg;
|
||||
|
||||
arg = *parg1;
|
||||
if (arg < 0)
|
||||
{
|
||||
*parg1 = -arg;
|
||||
negate = true;
|
||||
}
|
||||
|
||||
arg = *parg2;
|
||||
if (arg < 0)
|
||||
{
|
||||
*parg2 = -arg;
|
||||
negate ^= true;
|
||||
}
|
||||
|
||||
*pnegate = negate;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: adjustsign
|
||||
****************************************************************************/
|
||||
|
||||
static b16_t adjustsign(b16_t result, bool negate)
|
||||
{
|
||||
/* If the product is negative, then we overflowed */
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
return b16MIN;
|
||||
}
|
||||
else
|
||||
{
|
||||
return b16MAX;
|
||||
}
|
||||
}
|
||||
|
||||
/* correct the sign of the result */
|
||||
|
||||
if (negate)
|
||||
{
|
||||
return -result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16mulb16
|
||||
****************************************************************************/
|
||||
|
||||
b16_t b16mulb16(b16_t m1, b16_t m2)
|
||||
{
|
||||
bool negate;
|
||||
b16_t product;
|
||||
|
||||
fixsign(&m1, &m2, &negate);
|
||||
product = (b16_t)ub16mulub16((ub16_t)m1, (ub16_t)m2);
|
||||
return adjustsign(product, negate);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ub16mulub16
|
||||
**************************************************************************/
|
||||
|
||||
ub16_t ub16mulub16(ub16_t m1, ub16_t m2)
|
||||
{
|
||||
/* Let:
|
||||
*
|
||||
* m1 = m1i*2**16 + m1f (b16)
|
||||
* m2 = m2i*2**16 + m2f (b16)
|
||||
*
|
||||
* Then:
|
||||
*
|
||||
* m1*m2 = (m1i*m2i)*2**32 + (m1i*m2f + m2i*m1f)*2**16 + m1f*m2f (b32)
|
||||
* = (m1i*m2i)*2**16 + (m1i*m2f + m2i*m1f) + m1f*m2f*2**-16 (b16)
|
||||
* = a*2**16 + b + c*2**-16
|
||||
*/
|
||||
|
||||
uint32_t m1i = ((uint32_t)m1 >> 16);
|
||||
uint32_t m2i = ((uint32_t)m1 >> 16);
|
||||
uint32_t m1f = ((uint32_t)m1 & 0x0000ffff);
|
||||
uint32_t m2f = ((uint32_t)m2 & 0x0000ffff);
|
||||
|
||||
return (m1i*m2i << 16) + m1i*m2f + m2i*m1f + (((m1f*m2f) + b16HALF) >> 16);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16sqr
|
||||
**************************************************************************/
|
||||
|
||||
b16_t b16sqr(b16_t a)
|
||||
{
|
||||
b16_t sq;
|
||||
|
||||
/* The result is always positive. Just take the absolute value */
|
||||
|
||||
if (a < 0)
|
||||
{
|
||||
a = -a;
|
||||
}
|
||||
|
||||
/* Overflow occurred if the result is negative */
|
||||
|
||||
sq = (b16_t)ub16sqr(a);
|
||||
if (sq < 0)
|
||||
{
|
||||
sq = b16MAX;
|
||||
}
|
||||
return sq;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16divb16
|
||||
**************************************************************************/
|
||||
|
||||
ub16_t ub16sqr(ub16_t a)
|
||||
{
|
||||
/* Let:
|
||||
*
|
||||
* m = mi*2**16 + mf (b16)
|
||||
*
|
||||
* Then:
|
||||
*
|
||||
* m*m = (mi*mi)*2**32 + 2*(m1*m2)*2**16 + mf*mf (b32)
|
||||
* = (mi*mi)*2**16 + 2*(mi*mf) + mf*mf*2**-16 (b16)
|
||||
*/
|
||||
|
||||
uint32_t mi = ((uint32_t)a >> 16);
|
||||
uint32_t mf = ((uint32_t)a & 0x0000ffff);
|
||||
|
||||
return (mi*mi << 16) + (mi*mf << 1) + ((mf*mf + b16HALF) >> 16);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: b16divb16
|
||||
**************************************************************************/
|
||||
|
||||
b16_t b16divb16(b16_t num, b16_t denom)
|
||||
{
|
||||
bool negate;
|
||||
b16_t quotient;
|
||||
|
||||
fixsign(&num, &denom, &negate);
|
||||
quotient = (b16_t)ub16divub16((ub16_t)num, (ub16_t)denom);
|
||||
return adjustsign(quotient, negate);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: ub16divub16
|
||||
**************************************************************************/
|
||||
|
||||
ub16_t ub16divub16(ub16_t num, ub16_t denom)
|
||||
{
|
||||
uint32_t term1;
|
||||
uint32_t numf;
|
||||
uint32_t product;
|
||||
|
||||
/* Let:
|
||||
*
|
||||
* num = numi*2**16 + numf (b16)
|
||||
* den = deni*2**16 + denf (b16)
|
||||
*
|
||||
* Then:
|
||||
*
|
||||
* num/den = numi*2**16 / den + numf / den (b0)
|
||||
* = numi*2**32 / den + numf*2**16 /den (b16)
|
||||
*/
|
||||
|
||||
/* Check for overflow in the first part of the quotient */
|
||||
|
||||
term1 = ((uint32_t)num & 0xffff0000) / denom;
|
||||
if (term1 >= 0x00010000)
|
||||
{
|
||||
return ub16MAX; /* Will overflow */
|
||||
}
|
||||
|
||||
/* Finish the division */
|
||||
|
||||
numf = num - term1 * denom;
|
||||
term1 <<= 16;
|
||||
product = term1 + (numf + (denom >> 1)) / denom;
|
||||
|
||||
/* Check for overflow */
|
||||
|
||||
if (product < term1)
|
||||
{
|
||||
return ub16MAX; /* Overflowed */
|
||||
}
|
||||
return product;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,135 +0,0 @@
|
||||
/************************************************************
|
||||
* libc/fixedmath/lib_rint.c
|
||||
*
|
||||
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Type Declarations
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
/**********************************************************
|
||||
* Global Constant Data
|
||||
**********************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Global Variables
|
||||
************************************************************/
|
||||
|
||||
/**********************************************************
|
||||
* Private Constant Data
|
||||
**********************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Variables
|
||||
************************************************************/
|
||||
|
||||
double_t rint(double_t x)
|
||||
{
|
||||
double_t ret;
|
||||
|
||||
/* If the current rounding mode rounds toward negative
|
||||
* infinity, rint() is identical to floor(). If the current
|
||||
* rounding mode rounds toward positive infinity, rint() is
|
||||
* identical to ceil().
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_FP_ROUND_POSITIVE) && CONFIG_FP_ROUNDING_POSITIVE != 0
|
||||
|
||||
ret = ceil(x);
|
||||
|
||||
#elif defined(CONFIG_FP_ROUND_NEGATIVE) && CONFIG_FP_ROUNDING_NEGATIVE != 0
|
||||
|
||||
ret = floor(x);
|
||||
|
||||
#else
|
||||
|
||||
/* In the default rounding mode (round to nearest), rint(x) is the
|
||||
* integer nearest x with the additional stipulation that if
|
||||
* |rint(x)-x|=1/2, then rint(x) is even.
|
||||
*/
|
||||
|
||||
long dwinteger = (long)x;
|
||||
double_t fremainder = x - (double_t)dwinteger;
|
||||
|
||||
if (x < 0.0)
|
||||
{
|
||||
/* fremainder should be in range 0 .. -1 */
|
||||
|
||||
if (fremainder == -0.5)
|
||||
{
|
||||
dwinteger = ((dwinteger+1)&~1);
|
||||
}
|
||||
else if (fremainder < -0.5)
|
||||
{
|
||||
dwinteger--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* fremainder should be in range 0 .. 1 */
|
||||
|
||||
if (fremainder == 0.5)
|
||||
{
|
||||
dwinteger = ((dwinteger+1)&~1);
|
||||
}
|
||||
else if (fremainder > 0.5)
|
||||
{
|
||||
dwinteger++;
|
||||
}
|
||||
}
|
||||
|
||||
ret = (double_t)dwinteger;
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user