OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / loader / elfload.h
1 /* Header for simple ELF loader
2  *
3  * Copyright (c) 1998 Red Hat
4  *
5  * The authors hereby grant permission to use, copy, modify, distribute,
6  * and license this software and its documentation for any purpose, provided
7  * that existing copyright notices are retained in all copies and that this
8  * notice is included verbatim in any distributions. No written agreement,
9  * license, or royalty fee is required for any of the authorized uses.
10  * Modifications to this software may be copyrighted by their authors
11  * and need not follow the licensing terms described here, provided that
12  * the new terms are clearly indicated on the first page of each file where
13  * they apply.
14  */
15 #ifndef ELF_LOAD_H
16 #define ELF_LOAD_H
17
18 #define BYTE(X,offset) (((X)[offset]) & 255)
19 #define fetchShortLittle(addr) (BYTE((addr),1)*256+BYTE((addr),0))
20 #define fetchWordLittle(addr) (fetchShortLittle (addr) + fetchShortLittle((addr) + 2) * 65536)
21 #define fetchShortBig(addr) (BYTE((addr),0)*256+BYTE((addr),1))
22 #define fetchWordBig(addr) (fetchShortBig (addr) * 65536 + fetchShortBig((addr) + 2))
23 #define fetchWord(ADDR,LITTLE) ((LITTLE) ? fetchWordLittle((ADDR)) : fetchWordBig((ADDR)))
24 #define fetchShort(ADDR,LITTLE) ((LITTLE) ? fetchShortLittle((ADDR)) : fetchShortBig((ADDR)))
25
26 /* 
27    PFLOAD represents a function that will read file data. 
28    DEST or DEST2 is used as the destination address to be written with the
29    raw file data. If DEST is NULL, then DEST2 should be used.
30    OFFSET is the byte offset into the file to be read.
31    AMOUNT is the number of bytes to read.
32
33    If OFFSET and AMOUNT are both negative, then the file should be
34    closed (any remaining bytes are to be ignored). */
35
36 typedef int (*PFLOAD)(char *dest, char *dest2, int offset, int amount);
37 /* Load an ELF executable into memory. FUNC is used to actually read the
38    file. */
39 extern int readElfFile(PFLOAD func, unsigned*, int*);
40
41 #define EI_DATA 5
42 #define ELFDATA2LSB 1 /* little endian */
43 #define ELFDATA2MSB 2 /* big endian */
44
45 #endif