Changeset 412 for trunk/softs/tsar_boot/src/boot_elf_loader.c
- Timestamp:
- Jun 17, 2013, 7:10:20 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/softs/tsar_boot/src/boot_elf_loader.c
r388 r412 37 37 unsigned int i; 38 38 unsigned int segment_req; 39 39 40 40 /* 41 41 * Loader state machine definition 42 */ 42 */ 43 43 enum 44 44 { … … 48 48 ELF_SEGMENT_STATE, 49 49 ELF_END_STATE 50 } init_state; 50 } init_state 51 #if (BOOT_DEBUG ==1) 52 , init_state_debug 53 #endif 54 ; 55 56 #if (BOOT_DEBUG == 1) 57 char* init_state_str[] = { 58 "ELF_HEADER_STATE", 59 "ELF_PROGRAM_HEADER_STATE", 60 "ELF_OFFSET_STATE", 61 "ELF_SEGMENT_STATE", 62 "ELF_END_STATE" 63 }; 64 #endif 65 51 66 52 67 boot_puts("Starting boot_elf_loader function...\n\r"); … … 63 78 64 79 init_state = ELF_HEADER_STATE; 80 #if (BOOT_DEBUG == 1) 81 init_state_debug = ELF_END_STATE; 82 #endif 65 83 66 84 while(init_state != ELF_END_STATE) … … 88 106 offset += nb_read; 89 107 108 #if (BOOT_DEBUG == 1) 109 if (init_state != init_state_debug) 110 { 111 boot_puts("init_state = "); 112 boot_puts(init_state_str[init_state]); 113 boot_puts("\n"); 114 init_state_debug = init_state; 115 } 116 #endif 117 90 118 switch(init_state) 91 119 { … … 113 141 "Input file does not use ELF format" 114 142 "\n" 115 ); 143 ); 116 144 117 145 boot_exit(); 118 146 } 119 147 120 /* 148 /* 121 149 * Verification of Program Headers table size. It must be 122 * smaller than the work size allocated for the 150 * smaller than the work size allocated for the 123 151 * elf_pht[PHDR_ARRAY_SIZE] array 124 152 **/ … … 142 170 /** 143 171 * Reading ELF program headers 144 */ 172 */ 145 173 case ELF_PROGRAM_HEADER_STATE: 146 174 boot_memcpy(elf_pht_ptr, buffer_ptr, nb_read); … … 160 188 if(elf_pht_ptr[pseg].p_type == PT_LOAD) 161 189 { 162 nb_rest = elf_pht_ptr[pseg].p_offset - offset; 190 #if (BOOT_DEBUG == 1) 191 boot_puts("found a loadable segment:\n"); 192 boot_puts("- type : "); boot_putx(elf_pht_ptr[pseg].p_type); boot_puts("\n"); 193 boot_puts("- offset : "); boot_putx(elf_pht_ptr[pseg].p_offset); boot_puts("\n"); 194 boot_puts("- vaddr : "); boot_putx(elf_pht_ptr[pseg].p_vaddr); boot_puts("\n"); 195 boot_puts("- paddr : "); boot_putx(elf_pht_ptr[pseg].p_paddr); boot_puts("\n"); 196 boot_puts("- filesz : "); boot_putx(elf_pht_ptr[pseg].p_filesz); boot_puts("\n"); 197 boot_puts("- memsz : "); boot_putx(elf_pht_ptr[pseg].p_memsz); boot_puts("\n"); 198 boot_puts("- flags : "); boot_putx(elf_pht_ptr[pseg].p_flags); boot_puts("\n"); 199 boot_puts("- align : "); boot_putx(elf_pht_ptr[pseg].p_align); boot_puts("\n"); 200 #endif 201 if (elf_pht_ptr[pseg].p_offset < offset) 202 { 203 /* case where the segment to load includes the elf and program headers */ 204 nb_rest = elf_pht_ptr[pseg].p_filesz - offset; 205 init_state = ELF_SEGMENT_STATE; 206 } 207 else 208 { 209 /* segment to load is further away in memory */ 210 nb_rest = elf_pht_ptr[pseg].p_offset - offset; 211 init_state = ELF_OFFSET_STATE; 212 } 163 213 break; 164 214 } 165 215 } 166 216 167 init_state = ELF_OFFSET_STATE; 217 if (pseg == elf_header_ptr->e_phnum) 218 { 219 boot_puts( 220 "ERROR: " 221 "No PT_LOAD found" 222 "\n" 223 ); 224 boot_exit(); 225 } 226 168 227 } 169 228 … … 191 250 * Copying ELF segment data in memory segments using the virtual 192 251 * address got from the ELF file 193 */ 252 */ 194 253 segment_req = ((elf_pht_ptr[pseg].p_vaddr & 0xBFC00000) != 0xBFC00000); 195 254 … … 201 260 nb_read); 202 261 } 203 262 204 263 nb_rest -= nb_read; 205 264 … … 237 296 /* 238 297 * Program loading finished 239 */ 298 */ 240 299 if(pseg == elf_header_ptr->e_phnum) 241 300 {
Note: See TracChangeset
for help on using the changeset viewer.