8000 Merge pull request #3094 from kamtom480/mkspk · russbot/circuitpython@3a17a79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3a17a79

Browse files
authored
Merge pull request adafruit#3094 from kamtom480/mkspk
spresense: add elf32.h for mkspk
2 parents 74ad5e8 + 436b15e commit 3a17a79

File tree

2 files changed

+186
-1
lines changed

2 files changed

+186
-1
lines changed

ports/cxd56/mkspk/elf32.h

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/****************************************************************************
2+
* include/elf32.h
3+
*
4+
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
5+
* Author: Gregory Nutt <gnutt@nuttx.org>
6+
*
7+
* Reference: System V Application Binary Interface, Edition 4.1, March 18,
8+
* 1997, The Santa Cruz Operation, Inc.
9+
*
10+
* Redistribution and use in source and binary forms, with or without
11+
* modification, are permitted provided that the following conditions
12+
* are met:
13+
*
14+
* 1. Redistributions of source code must retain the above copyright
15+
* notice, this list of conditions and the following disclaimer.
16+
* 2. Redistributions in binary form must reproduce the above copyright
17+
* notice, this list of conditions and the following disclaimer in
18+
* the documentation and/or other materials provided with the
19+
* distribution.
20+
* 3. Neither the name NuttX nor the names of its contributors may be
21+
* used to endorse or promote products derived from this software
22+
* without specific prior written permission.
23+
*
24+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
31+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
32+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35+
* POSSIBILITY OF SUCH DAMAGE.
36+
*
37+
****************************************************************************/
38+
39+
#ifndef __INCLUDE_ELF32_H
40+
#define __INCLUDE_ELF32_H
41+
42+
/****************************************************************************
43+
* Included Files
44+
****************************************************************************/
45+
46+
#include <stdint.h>
47+
48+
/****************************************************************************
49+
* Pre-processor Definitions
50+
****************************************************************************/
51+
52+
#define EI_NIDENT 16 /* Size of e_ident[] */
53+
54+
#define ELF32_ST_BIND(i) ((i) >> 4)
55+
#define ELF32_ST_TYPE(i) ((i) & 0xf)
56+
#define ELF32_ST_INFO(b,t) (((b) << 4) | ((t) & 0xf))
57+
58+
/* Definitions for Elf32_Rel*::r_info */
59+
60+
#define ELF32_R_SYM(i) ((i) >> 8)
61+
#define ELF32_R_TYPE(i) ((i) & 0xff)
62+
#define ELF32_R_INFO(s,t) (((s)<< 8) | ((t) & 0xff))
63+
64+
#define ELF_R_SYM(i) ELF32_R_SYM(i)
65+
66+
/****************************************************************************
67+
* Public Type Definitions
68+
****************************************************************************/
69+
70+
/* Figure 4.2: 32-Bit Data Types */
71+
72+
typedef uint32_t Elf32_Addr; /* Unsigned program address */
73+
typedef uint16_t Elf32_Half; /* Unsigned medium integer */
74+
typedef uint32_t Elf32_Off; /* Unsigned file offset */
75+
typedef int32_t Elf32_Sword; /* Signed large integer */
76+
typedef uint32_t Elf32_Word; /* Unsigned large integer */
77+
78+
/* Figure 4-3: ELF Header */
79+
80+
typedef struct
81+
{
82+
unsigned char e_ident[EI_NIDENT];
83+
Elf32_Half e_type;
84+
Elf32_Half e_machine;
85+
Elf32_Word e_version;
86+
Elf32_Addr e_entry;
87+
Elf32_Off e_phoff;
88+
Elf32_Off e_shoff;
89+
Elf32_Word e_flags;
90+
Elf32_Half e_ehsize;
91+
Elf32_Half e_phentsize;
92+
Elf32_Half e_phnum;
93+
Elf32_Half e_shentsize;
94+
Elf32_Half e_shnum;
95+
Elf32_Half e_shstrndx;
96+
} Elf32_Ehdr;
97+
98+
/* Figure 4-8: Section Header */
99+
100+
typedef struct
101+
{
102+
Elf32_Word sh_name;
103+
Elf32_Word sh_type;
104+
Elf32_Word sh_flags;
105+
Elf32_Addr sh_addr;
106+
Elf32_Off sh_offset;
107+
Elf32_Word sh_size;
108+
Elf32_Word sh_link;
109+
Elf32_Word sh_info;
110+
Elf32_Word sh_addralign;
111+
Elf32_Word sh_entsize;
112+
} Elf32_Shdr;
113+
114+
/* Figure 4-15: Symbol Table Entry */
115+
116+
typedef struct
117+
{
118+
Elf32_Word st_name;
119+
Elf32_Addr st_value;
120+
Elf32_Word st_size;
121+
unsigned char st_info;
122+
unsigned char st_other;
123+
Elf32_Half st_shndx;
124+
} Elf32_Sym;
125+
126+
/* Figure 4-19: Relocation Entries */
127+
128+
typedef struct
129+
{
130+
Elf32_Addr r_offset;
131+
Elf32_Word r_info;
132+
} Elf32_Rel;
133+
134+
typedef struct
135+
{
136+
Elf32_Addr r_offset;
137+
Elf32_Word r_info;
138+
Elf32_Sword r_addend;
139+
} Elf32_Rela;
140+
141+
/* Figure 5-1: Program Header */
142+
143+
typedef struct
144+
{
145+
Elf32_Word p_type;
146+
Elf32_Off p_offset;
147+
Elf32_Addr p_vaddr;
148+
Elf32_Addr p_paddr;
149+
Elf32_Word p_filesz;
150+
Elf32_Word p_memsz;
151+
Elf32_Word p_flags;
152+
Elf32_Word p_align;
153+
} Elf32_Phdr;
154+
155+
/* Figure 5-9: Dynamic Structure */
156+
157+
typedef struct
158+
{
159+
Elf32_Sword d_tag;
160+
union
161+
{
162+
Elf32_Word d_val;
163+
Elf32_Addr d_ptr;
164+
} d_un;
165+
} Elf32_Dyn;
166+
167+
typedef Elf32_Addr Elf_Addr;
168+
typedef Elf32_Ehdr Elf_Ehdr;
169+
typedef Elf32_Rel Elf_Rel;
170+
typedef Elf32_Rela Elf_Rela;
171+
typedef Elf32_Sym Elf_Sym;
172+
typedef Elf32_Shdr Elf_Shdr;
173+
typedef Elf32_Word Elf_Word;
174+
175+
#endif /* __INCLUDE_ELF32_H */

ports/cxd56/mkspk/mkspk.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,22 @@
3636
****************************************************************************/
3737

3838
#include "clefia.h"
39-
#include "elf.h"
39+
#include "elf32.h"
4040

4141
/****************************************************************************
4242
* Pre-processor Definitions
4343
****************************************************************************/
4444

45+
#define EI_MAG0 0 /* File identification */
46+
#define EI_MAG1 1
47+
#define EI_MAG2 2
48+
#define EI_MAG3 3
49+
50+
#define SHT_SYMTAB 2
51+
#define SHT_STRTAB 3
52+
53+
#define PT_LOAD 1
54+
4555
#define alignup(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
4656
#define swap(a, b) { (a) ^= (b); (b) ^= (a); (a) ^= (b); }
4757

0 commit comments

Comments
 (0)
0