1 /* PEF support for BFD. 2 Copyright 1999, 2000, 2001, 2002 3 Free Software Foundation, Inc. 4 5 This file is part of BFD, the Binary File Descriptor library. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 21 #include "bfd.h" 22 23 #include <stdio.h> 24 25 struct bfd_pef_header 26 { 27 unsigned long tag1; 28 unsigned long tag2; 29 unsigned long architecture; 30 unsigned long format_version; 31 unsigned long timestamp; 32 unsigned long old_definition_version; 33 unsigned long old_implementation_version; 34 unsigned long current_version; 35 unsigned short section_count; 36 unsigned short instantiated_section_count; 37 unsigned long reserved; 38 }; 39 typedef struct bfd_pef_header bfd_pef_header; 40 41 struct bfd_pef_loader_header 42 { 43 long main_section; 44 unsigned long main_offset; 45 long init_section; 46 unsigned long init_offset; 47 long term_section; 48 unsigned long term_offset; 49 unsigned long imported_library_count; 50 unsigned long total_imported_symbol_count; 51 unsigned long reloc_section_count; 52 unsigned long reloc_instr_offset; 53 unsigned long loader_strings_offset; 54 unsigned long export_hash_offset; 55 unsigned long export_hash_table_power; 56 unsigned long exported_symbol_count; 57 }; 58 typedef struct bfd_pef_loader_header bfd_pef_loader_header; 59 60 struct bfd_pef_imported_library 61 { 62 unsigned long name_offset; 63 unsigned long old_implementation_version; 64 unsigned long current_version; 65 unsigned long imported_symbol_count; 66 unsigned long first_imported_symbol; 67 unsigned char options; 68 unsigned char reserved_a; 69 unsigned short reserved_b; 70 }; 71 typedef struct bfd_pef_imported_library bfd_pef_imported_library; 72 73 enum bfd_pef_imported_library_options 74 { 75 BFD_PEF_WEAK_IMPORT_LIB = 0x40, 76 BFD_PEF_INIT_LIB_BEFORE = 0x80 77 }; 78 79 struct bfd_pef_imported_symbol 80 { 81 unsigned char class; 82 unsigned long name; 83 }; 84 typedef struct bfd_pef_imported_symbol bfd_pef_imported_symbol; 85 86 enum bfd_pef_imported_symbol_class 87 { 88 BFD_PEF_CODE_SYMBOL = 0x00, 89 BFD_PEF_DATA_SYMBOL = 0x01, 90 BFD_PEF_TVECTOR_SYMBOL = 0x02, 91 BFD_PEF_TOC_SYMBOL = 0x03, 92 BFD_PEF_GLUE_SYMBOL = 0x04, 93 BFD_PEF_UNDEFINED_SYMBOL = 0x0F, 94 BFD_PEF_WEAK_IMPORT_SYMBOL_MASK = 0x80 95 }; 96 97 #define BFD_PEF_TAG1 0x4A6F7921 /* 'Joy!' */ 98 #define BFD_PEF_TAG2 0x70656666 /* 'peff' */ 99 100 #define BFD_PEF_VERSION 0x00000001 101 102 struct bfd_pef_section 103 { 104 long name_offset; 105 unsigned long header_offset; 106 unsigned long default_address; 107 unsigned long total_length; 108 unsigned long unpacked_length; 109 unsigned long container_length; 110 unsigned long container_offset; 111 unsigned char section_kind; 112 unsigned char share_kind; 113 unsigned char alignment; 114 unsigned char reserved; 115 asection *bfd_section; 116 }; 117 typedef struct bfd_pef_section bfd_pef_section; 118 119 #define BFD_PEF_SECTION_CODE 0 120 #define BFD_PEF_SECTION_UNPACKED_DATA 1 121 #define BFD_PEF_SECTION_PACKED_DATA 2 122 #define BFD_PEF_SECTION_CONSTANT 3 123 #define BFD_PEF_SECTION_LOADER 4 124 #define BFD_PEF_SECTION_DEBUG 5 125 #define BFD_PEF_SECTION_EXEC_DATA 6 126 #define BFD_PEF_SECTION_EXCEPTION 7 127 #define BFD_PEF_SECTION_TRACEBACK 8 128 129 #define BFD_PEF_SHARE_PROCESS 1 130 #define BFD_PEF_SHARE_GLOBAL 4 131 #define BFD_PEF_SHARE_PROTECTED 5 132 133 struct bfd_pef_data_struct 134 { 135 bfd_pef_header header; 136 bfd_pef_section *sections; 137 bfd *ibfd; 138 }; 139 typedef struct bfd_pef_data_struct bfd_pef_data_struct; 140 141 #define BFD_PEF_XLIB_TAG1 0xF04D6163 /* '?Mac' */ 142 #define BFD_PEF_VLIB_TAG2 0x564C6962 /* 'VLib' */ 143 #define BFD_PEF_BLIB_TAG2 0x424C6962 /* 'BLib' */ 144 145 #define BFD_PEF_XLIB_VERSION 0x00000001 146 147 struct bfd_pef_xlib_header 148 { 149 unsigned long tag1; 150 unsigned long tag2; 151 unsigned long current_format; 152 unsigned long container_strings_offset; 153 unsigned long export_hash_offset; 154 unsigned long export_key_offset; 155 unsigned long export_symbol_offset; 156 unsigned long export_names_offset; 157 unsigned long export_hash_table_power; 158 unsigned long exported_symbol_count; 159 160 unsigned long frag_name_offset; 161 unsigned long frag_name_length; 162 unsigned long dylib_path_offset; 163 unsigned long dylib_path_length; 164 unsigned long cpu_family; 165 unsigned long cpu_model; 166 unsigned long date_time_stamp; 167 unsigned long current_version; 168 unsigned long old_definition_version; 169 unsigned long old_implementation_version; 170 }; 171 typedef struct bfd_pef_xlib_header bfd_pef_xlib_header; 172 173 struct bfd_pef_xlib_data_struct 174 { 175 bfd_pef_xlib_header header; 176 }; 177 typedef struct bfd_pef_xlib_data_struct bfd_pef_xlib_data_struct; 178 179 int bfd_pef_parse_loader_header PARAMS ((bfd *, unsigned char *, size_t, bfd_pef_loader_header *)); 180 int bfd_pef_print_loader_section PARAMS ((bfd *, FILE *)); 181 void bfd_pef_print_loader_header PARAMS ((bfd *, bfd_pef_loader_header *, FILE *)); 182 int bfd_pef_parse_imported_library PARAMS ((bfd *, unsigned char *, size_t, bfd_pef_imported_library *)); 183 int bfd_pef_parse_imported_symbol PARAMS ((bfd *, unsigned char *, size_t, bfd_pef_imported_symbol *)); 184 int bfd_pef_scan_section PARAMS ((bfd *, bfd_pef_section *)); 185 int bfd_pef_scan_start_address PARAMS ((bfd *)); 186 int bfd_pef_scan PARAMS ((bfd *, bfd_pef_header *, bfd_pef_data_struct *)); 187