Changeset 06b2b7f in mainline
- Timestamp:
- 2009-01-07T22:33:35Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 7ed2d8f
- Parents:
- 6974061
- Location:
- uspace/srv/loader
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/loader/elf_load.c
r6974061 r06b2b7f 58 58 #include "arch.h" 59 59 60 #define DPRINTF(...) 61 60 62 static char *error_codes[] = { 61 63 "no error", … … 107 109 int rc; 108 110 109 // printf("open and read '%s'...\n", file_name);110 111 111 fd = open(file_name, O_RDONLY); 112 112 if (fd < 0) { 113 printf("failed opening file\n");113 DPRINTF("failed opening file\n"); 114 114 return -1; 115 115 } … … 172 172 rc = my_read(elf->fd, header, sizeof(elf_header_t)); 173 173 if (rc < 0) { 174 printf("read error\n");174 DPRINTF("Read error.\n"); 175 175 return EE_INVALID; 176 176 } … … 178 178 elf->header = header; 179 179 180 // printf("ELF-load:");181 180 /* Identify ELF */ 182 181 if (header->e_ident[EI_MAG0] != ELFMAG0 || … … 184 183 header->e_ident[EI_MAG2] != ELFMAG2 || 185 184 header->e_ident[EI_MAG3] != ELFMAG3) { 186 printf("invalid header\n");185 DPRINTF("Invalid header.\n"); 187 186 return EE_INVALID; 188 187 } … … 194 193 header->e_version != EV_CURRENT || 195 194 header->e_ident[EI_CLASS] != ELF_CLASS) { 196 printf("incompatible data/version/class\n");195 DPRINTF("Incompatible data/version/class.\n"); 197 196 return EE_INCOMPATIBLE; 198 197 } 199 198 200 199 if (header->e_phentsize != sizeof(elf_segment_header_t)) { 201 printf("e_phentsize:%d != %d\n", header->e_phentsize,200 DPRINTF("e_phentsize:%d != %d\n", header->e_phentsize, 202 201 sizeof(elf_segment_header_t)); 203 202 return EE_INCOMPATIBLE; … … 205 204 206 205 if (header->e_shentsize != sizeof(elf_section_header_t)) { 207 printf("e_shentsize:%d != %d\n", header->e_shentsize,206 DPRINTF("e_shentsize:%d != %d\n", header->e_shentsize, 208 207 sizeof(elf_section_header_t)); 209 208 return EE_INCOMPATIBLE; … … 212 211 /* Check if the object type is supported. */ 213 212 if (header->e_type != ET_EXEC && header->e_type != ET_DYN) { 214 printf("Object type %d is not supported\n", header->e_type);213 DPRINTF("Object type %d is not supported\n", header->e_type); 215 214 return EE_UNSUPPORTED; 216 215 } 217 216 218 217 /* Shared objects can be loaded with a bias */ 219 // printf("Object type: %d\n", header->e_type);220 218 if (header->e_type == ET_DYN) 221 219 elf->bias = so_bias; … … 223 221 elf->bias = 0; 224 222 225 // printf("Bias set to 0x%x\n", elf->bias);226 223 elf->info->interp = NULL; 227 224 elf->info->dynamic = NULL; 228 229 // printf("parse segments\n");230 225 231 226 /* Walk through all segment headers and process them. */ … … 240 235 sizeof(elf_segment_header_t)); 241 236 if (rc < 0) { 242 printf("read error\n");237 DPRINTF("Read error.\n"); 243 238 return EE_INVALID; 244 239 } … … 249 244 } 250 245 251 // printf("parse sections\n");246 DPRINTF("Parse sections.\n"); 252 247 253 248 /* Inspect all section headers and proccess them. */ … … 262 257 sizeof(elf_section_header_t)); 263 258 if (rc < 0) { 264 printf("read error\n");259 DPRINTF("Read error.\n"); 265 260 return EE_INVALID; 266 261 } … … 274 269 (entry_point_t)((uint8_t *)header->e_entry + elf->bias); 275 270 276 // printf("done\n");271 DPRINTF("Done.\n"); 277 272 278 273 return EE_OK; … … 317 312 case PT_HIPROC: 318 313 default: 319 printf("segment p_type %d unknown\n", entry->p_type);314 DPRINTF("Segment p_type %d unknown.\n", entry->p_type); 320 315 return EE_UNSUPPORTED; 321 316 break; … … 340 335 int rc; 341 336 342 // printf("load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr,343 //entry->p_memsz);337 DPRINTF("Load segment at addr 0x%x, size 0x%x\n", entry->p_vaddr, 338 entry->p_memsz); 344 339 345 340 bias = elf->bias; … … 348 343 if ((entry->p_offset % entry->p_align) != 349 344 (entry->p_vaddr % entry->p_align)) { 350 printf("align check 1 failed offset%%align=%d, "345 DPRINTF("Align check 1 failed offset%%align=%d, " 351 346 "vaddr%%align=%d\n", 352 347 entry->p_offset % entry->p_align, … … 370 365 mem_sz = entry->p_memsz + (entry->p_vaddr - base); 371 366 372 // printf("map to p_vaddr=0x%x-0x%x...\n", entry->p_vaddr + bias,373 //entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE));367 DPRINTF("Map to p_vaddr=0x%x-0x%x.\n", entry->p_vaddr + bias, 368 entry->p_vaddr + bias + ALIGN_UP(entry->p_memsz, PAGE_SIZE)); 374 369 375 370 /* … … 380 375 AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE); 381 376 if (a == (void *)(-1)) { 382 printf("memory mapping failed\n");377 DPRINTF("Memory mapping failed.\n"); 383 378 return EE_MEMORY; 384 379 } 385 380 386 // printf("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n",387 //entry->p_vaddr+bias, entry->p_memsz, flags, (uintptr_t)a);381 DPRINTF("as_area_create(0x%lx, 0x%x, %d) -> 0x%lx\n", 382 entry->p_vaddr+bias, entry->p_memsz, flags, (uintptr_t)a); 388 383 389 384 /* 390 385 * Load segment data 391 386 */ 392 // printf("seek to %d\n", entry->p_offset);393 387 rc = lseek(elf->fd, entry->p_offset, SEEK_SET); 394 388 if (rc < 0) { … … 397 391 } 398 392 399 // printf("read 0x%x bytes to address 0x%x\n", entry->p_filesz, entry->p_vaddr+bias);400 393 /* rc = read(fd, (void *)(entry->p_vaddr + bias), entry->p_filesz); 401 394 if (rc < 0) { printf("read error\n"); return EE_INVALID; }*/ 402 395 403 /* Long reads are not possible yet. Load segment pi cewise*/396 /* Long reads are not possible yet. Load segment piecewise. */ 404 397 405 398 unsigned left, now; … … 413 406 if (now > left) now = left; 414 407 415 // printf("read %d...", now);416 408 rc = my_read(elf->fd, dp, now); 417 // printf("->%d\n", rc);418 409 419 410 if (rc < 0) { 420 printf("read error\n");411 DPRINTF("Read error.\n"); 421 412 return EE_INVALID; 422 413 } … … 426 417 } 427 418 428 // printf("set area flags to %d\n", flags);429 419 rc = as_area_change_flags((uint8_t *)entry->p_vaddr + bias, flags); 430 420 if (rc != 0) { 431 printf("failed to set memory area flags\n");421 DPRINTF("Failed to set memory area flags.\n"); 432 422 return EE_MEMORY; 433 423 } … … 466 456 elf->info->dynamic = 467 457 (void *)((uint8_t *)entry->sh_addr + elf->bias); 468 printf("dynamic section found at 0x%x\n",458 DPRINTF("Dynamic section found at 0x%x.\n", 469 459 (uintptr_t)elf->info->dynamic); 470 460 break; -
uspace/srv/loader/main.c
r6974061 r06b2b7f 60 60 #include <elf_load.h> 61 61 62 #define DPRINTF(...) 63 62 64 /** Pathname of the file that will be loaded */ 63 65 static char *pathname = NULL; … … 226 228 rc = elf_load_file(pathname, 0, &prog_info); 227 229 if (rc < 0) { 228 printf("Failed to load executable '%s'.\n", pathname);230 DPRINTF("Failed to load executable '%s'.\n", pathname); 229 231 ipc_answer_0(rid, EINVAL); 230 232 return 1; … … 245 247 rc = elf_load_file(prog_info.interp, 0, &interp_info); 246 248 if (rc < 0) { 247 printf("Failed to load interpreter '%s.'\n", prog_info.interp); 249 DPRINTF("Failed to load interpreter '%s.'\n", 250 prog_info.interp); 248 251 ipc_answer_0(rid, EINVAL); 249 252 return 1; … … 267 270 if (is_dyn_linked == true) { 268 271 /* Dynamically linked program */ 269 printf("run dynamic linker\n");270 printf("entry point: 0x%lx\n", interp_info.entry);272 DPRINTF("Run ELF interpreter.\n"); 273 DPRINTF("Entry point: 0x%lx\n", interp_info.entry); 271 274 close_console(); 272 275 … … 325 328 if ((callid & IPC_CALLID_NOTIFICATION) == 0 && 326 329 IPC_GET_METHOD(call) != IPC_M_PHONE_HUNGUP) { 327 printf("responding EINVAL to method %d\n",330 DPRINTF("Responding EINVAL to method %d.\n", 328 331 IPC_GET_METHOD(call)); 329 332 ipc_answer_0(callid, EINVAL);
Note:
See TracChangeset
for help on using the changeset viewer.