4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Structures & definitions used for dynamically loaded modules file format.
7 * This format is a reformatted version of COFF. It optimizes the layout for
10 * .dof files, when viewed as a sequence of 32-bit integers, look the same
11 * on big-endian and little-endian machines.
13 * Copyright (C) 2005-2006 Texas Instruments, Inc.
15 * This package is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License version 2 as
17 * published by the Free Software Foundation.
19 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
21 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
28 #define BYTE_RESHUFFLE_VALUE 0x00010203
30 /* DOFF file header containing fields categorizing the remainder of the file */
31 struct doff_filehdr_t
{
33 /* string table size, including filename, in bytes */
36 /* entry point if one exists */
39 /* identifies byte ordering of file;
40 * always set to BYTE_RESHUFFLE_VALUE */
41 u32 df_byte_reshuffle
;
43 /* Size of the string table up to and including the last section name */
44 /* Size includes the name of the COFF file also */
48 /* number of symbols */
51 /* length in bytes of the longest string, including terminating NULL */
52 /* excludes the name of the file */
55 /* total number of sections including no-load ones */
58 /* number of sections containing target code allocated or downloaded */
61 /* unique id for dll file format & version */
67 /* useful file flags */
70 /* section reference for entry point, N_UNDEF for none, */
71 /* N_ABS for absolute address */
74 /* length of the longest string, including terminating NULL */
77 /* number of symbols */
80 /* number of sections containing target code allocated or downloaded */
83 /* total number of sections including no-load ones */
89 /* unique id for dll file format & version */
92 /* section reference for entry point, N_UNDEF for none, */
93 /* N_ABS for absolute address */
96 /* useful file flags */
99 /* checksum for file header record */
104 /* flags in the df_flags field */
105 #define DF_LITTLE 0x100
107 #define DF_BYTE_ORDER (DF_LITTLE | DF_BIG)
109 /* Supported processors */
110 #define TMS470_ID 0x97
112 #define TMS32060_ID 0x99
113 #define LEAD3_ID 0x9c
115 /* Primary processor for loading */
117 #define TARGET_ID TMS32060_ID
120 /* Verification record containing values used to test integrity of the bits */
121 struct doff_verify_rec_t
{
123 /* time and date stamp */
126 /* checksum for all section records */
127 u32 dv_scn_rec_checksum
;
129 /* checksum for string table */
130 u32 dv_str_tab_checksum
;
132 /* checksum for symbol table */
133 u32 dv_sym_tab_checksum
;
135 /* checksum for verification record */
136 u32 dv_verify_rec_checksum
;
140 /* String table is an array of null-terminated strings. The first entry is
141 * the filename, which is added by DLLcreate. No new structure definitions
145 /* Section Records including information on the corresponding image packets */
149 * This structure is expected to match in form ldr_section_info in
153 struct doff_scnhdr_t
{
155 s32 ds_offset
; /* offset into string table of name */
156 s32 ds_paddr
; /* RUN address, in target AU */
157 s32 ds_vaddr
; /* LOAD address, in target AU */
158 s32 ds_size
; /* section size, in target AU */
160 u16 ds_page
; /* memory page id */
161 u16 ds_flags
; /* section flags */
163 u16 ds_flags
; /* section flags */
164 u16 ds_page
; /* memory page id */
166 u32 ds_first_pkt_offset
;
167 /* Absolute byte offset into the file */
168 /* where the first image record resides */
170 s32 ds_nipacks
; /* number of image packets */
174 /* Symbol table entry */
175 struct doff_syment_t
{
177 s32 dn_offset
; /* offset into string table of name */
178 s32 dn_value
; /* value of symbol */
180 s16 dn_scnum
; /* section number */
181 s16 dn_sclass
; /* storage class */
183 s16 dn_sclass
; /* storage class */
184 s16 dn_scnum
; /* section number, 1-based */
189 /* special values for dn_scnum */
190 #define DN_UNDEF 0 /* undefined symbol */
191 #define DN_ABS (-1) /* value of symbol is absolute */
192 /* special values for dn_sclass */
194 #define DN_STATLAB 20
197 /* Default value of image bits in packet */
198 /* Configurable by user on the command line */
199 #define IMAGE_PACKET_SIZE 1024
201 /* An image packet contains a chunk of data from a section along with */
202 /* information necessary for its processing. */
203 struct image_packet_t
{
205 s32 num_relocs
; /* number of relocations for */
208 s32 packet_size
; /* number of bytes in array */
209 /* "bits" occupied by */
210 /* valid data. Could be */
211 /* < IMAGE_PACKET_SIZE to */
212 /* prevent splitting a */
213 /* relocation across packets. */
214 /* Last packet of a section */
215 /* will most likely contain */
216 /* < IMAGE_PACKET_SIZE bytes */
219 s32 img_chksum
; /* Checksum for image packet */
220 /* and the corresponding */
221 /* relocation records */
223 u8
*img_data
; /* Actual data in section */
227 /* The relocation structure definition matches the COFF version. Offsets */
228 /* however are relative to the image packet base not the section base. */
229 struct reloc_record_t
{
233 /* expressed in target AUs */
238 u8 _offset
; /* bit offset of rel fld */
239 u8 _fieldsz
; /* size of rel fld */
240 u8 _wordsz
; /* # bytes containing rel fld */
246 unsigned _wordsz
:8; /* # bytes containing rel fld */
247 unsigned _fieldsz
:8; /* size of rel fld */
248 unsigned _offset
:8; /* bit offset of rel fld */
255 u32 _spc
; /* image packet relative PC */
258 u16 _type
; /* relocation type */
260 u16 _type
; /* relocation type */
266 u32 _uval
; /* constant value */
269 u16 _type
; /* relocation type */
271 u16 _type
; /* relocation type */
277 s32 _symndx
; /* 32-bit sym tbl index */
279 u16 _disp
; /* extra addr encode data */
280 u16 _type
; /* relocation type */
282 u16 _type
; /* relocation type */
283 u16 _disp
; /* extra addr encode data */
290 /* abbreviations for convenience */
292 #define TYPE _u_reloc._r_sym._type
293 #define UVAL _u_reloc._r_uval._uval
294 #define SYMNDX _u_reloc._r_sym._symndx
295 #define OFFSET _u_reloc._r_field._offset
296 #define FIELDSZ _u_reloc._r_field._fieldsz
297 #define WORDSZ _u_reloc._r_field._wordsz
298 #define R_DISP _u_reloc._r_sym._disp
301 /**************************************************************************** */
303 /* Important DOFF macros used for file processing */
305 /**************************************************************************** */
310 /* Return the address/size >= to addr that is at a 32-bit boundary */
311 /* This assumes that a byte is 8 bits */
312 #define DOFF_ALIGN(addr) (((addr) + 3) & ~3UL)
314 /**************************************************************************** */
316 /* The DOFF section header flags field is laid out as follows: */
318 /* Bits 0-3 : Section Type */
319 /* Bit 4 : Set when section requires target memory to be allocated by DL */
320 /* Bit 5 : Set when section requires downloading */
321 /* Bits 8-11: Alignment, same as COFF */
323 /**************************************************************************** */
325 /* Enum for DOFF section types (bits 0-3 of flag): See dynamic_loader.h */
326 #define DS_SECTION_TYPE_MASK 0xF
327 /* DS_ALLOCATE indicates whether a section needs space on the target */
328 #define DS_ALLOCATE_MASK 0x10
329 /* DS_DOWNLOAD indicates that the loader needs to copy bits */
330 #define DS_DOWNLOAD_MASK 0x20
331 /* Section alignment requirement in AUs */
332 #define DS_ALIGNMENT_SHIFT 8
334 static inline bool dload_check_type(struct doff_scnhdr_t
*sptr
, u32 flag
)
336 return (sptr
->ds_flags
& DS_SECTION_TYPE_MASK
) == flag
;
338 static inline bool ds_needs_allocation(struct doff_scnhdr_t
*sptr
)
340 return sptr
->ds_flags
& DS_ALLOCATE_MASK
;
343 static inline bool ds_needs_download(struct doff_scnhdr_t
*sptr
)
345 return sptr
->ds_flags
& DS_DOWNLOAD_MASK
;
348 static inline int ds_alignment(u16 ds_flags
)
350 return 1 << ((ds_flags
>> DS_ALIGNMENT_SHIFT
) & DS_SECTION_TYPE_MASK
);