#include #include int fd; typedef unsigned long bit32; #define FAST_FLAG (1L<<31) #define CHIP_FLAG (1L<<30) main(argc,argv) int argc; char *argv[]; { bit32 hunk_type, arg, first, last, size; int ok_to_end = 0; if(argc!=2) { printf("Useage: %s objectfile\n",argv[0]); exit(30); } if(-1==(fd=open(argv[1],O_RDONLY))) { printf("Unable to open input file.\n"); exit(20); } while(1) { size = read(fd,&hunk_type,4); if(!size && ok_to_end) { close(fd); exit(0); } if(size != 4) { printf("\nERROR: Unexpected end of file.\n"); close(fd); exit(10); } ok_to_end = 0; switch(hunk_type) { case 999: printf("hunk_unit\n \042"); showname(); puts("\042"); break; case 1000: printf("hunk_name\n \042"); showname(); puts("\042"); break; case 1001 | FAST_FLAG: printf("hunk_code_fast\n"); goto generic_code; case 1001 | CHIP_FLAG: printf("hunk_code_chip\n"); goto generic_code; case 1001: printf("hunk_code\n"); generic_code: getbytes(&arg,4); skip(4*arg); printf(" Contains %ld bytes of code.\n",4*arg); break; case 1002 | FAST_FLAG: printf("hunk_data_fast\n"); goto generic_data; case 1002 | CHIP_FLAG: printf("hunk_data_chip\n"); goto generic_data; case 1002: printf("hunk_data\n"); generic_data: getbytes(&arg,4); skip(4*arg); printf(" Contains %ld bytes of data.\n",4*arg); break; case 1003 | FAST_FLAG: printf("hunk_bss_fast\n"); goto generic_bss; case 1003 | CHIP_FLAG: printf("hunk_bss_chip\n"); goto generic_bss; case 1003: printf("hunk_bss\n"); generic_bss: getbytes(&arg,4); printf(" Specifies %ld bytes of uninitialized data.\n",arg*4); break; case 1004: printf("hunk_reloc32\n"); showreloc(); break; case 1005: printf("hunk_reloc16\n"); showreloc(); break; case 1006: printf("hunk_reloc8\n"); showreloc(); break; case 1007: printf("hunk_ext\n"); showsdu(); break; case 1008: printf("hunk_symbol\n"); showsdu(); break; case 1009: printf("hunk_debug\n"); getbytes(&arg,4); skip(4*arg); printf(" %ld longwords of debug data.\n",arg); break; case 1010: printf("hunk_end\n"); ok_to_end = 1; break; case 1011: printf("hunk_header\n"); getbytes(&arg,4); if(arg) { printf(" Resident library list:\n"); while(arg) { printf(" \042"); print_name(arg); printf("\042\n"); getbytes(&arg,4); } } else printf(" No resident library list.\n"); getbytes(&arg,4); printf(" Hunk table size is %ld\n",arg); getbytes(&first,4); getbytes(&last,4); printf(" Use slots %ld to %ld of hunk table.\n", first, last); for(arg=first;arg<=last;++arg) { getbytes(&size,4); printf(" Hunk %ld requires %ld longwords", arg, size & 0x3fffffff); switch(size >> 30) { case 0: putchar('.\n'); break; case 1: printf(" of chip memory.\n"); break; case 2: printf(" of fast memory.\n"); break; default: printf("\n\nERROR: Invalid memory type.\n"); close(fd); exit(10); } } break; case 1013: printf("hunk_overlay\n"); getbytes(&arg,4); skip(4*arg+4); printf(" Overlay table block.\n"); break; case 1014: printf("hunk_break\n"); ok_to_end = 1; break; default: printf("\nERROR: Unknown hunk type %ld encountered.\n", hunk_type); close(fd); exit(10); } } } char *plural(arg) bit32 arg; { if(arg==1) return 0; else return "s"; } showsdu() { bit32 sdu_header, arg, arg1; while(1) { getbytes(&sdu_header,4); if(!sdu_header) return; printf(" \042"); print_name(sdu_header & 0xffffff); printf("\042, "); switch(sdu_header >> 24) { case 0: getbytes(&arg,4); printf("ext_symb, value = %ld\n",arg); break; case 1: getbytes(&arg,4); printf("ext_def, value = %ld\n",arg); break; case 2: getbytes(&arg,4); printf("ext_abs, value = %ld\n",arg); break; case 3: getbytes(&arg,4); printf("ext_res, value = %ld\n",arg); break; case 129: getbytes(&arg,4); skip(4*arg); printf("ext_ref32, %ld reference%s\n",arg,plural(arg)); break; case 130: getbytes(&arg,4); getbytes(&arg1,4); skip(4*arg1); printf("ext_common, %ld reference%s to %ld byte common block.\n", arg1, plural(arg1), arg); break; case 131: getbytes(&arg,4); skip(4*arg); printf("ext_ref16, %ld reference%s\n",arg,plural(arg)); break; case 132: getbytes(&arg,4); skip(4*arg); printf("ext_ref8, %ld reference%s\n",arg,plural(arg)); break; default: printf("\n\nERROR: Bad symbol data unit type %ld", sdu_header >> 24); fclose(fd); exit(10); } } } showreloc() { bit32 n,hunk_number; while(1) { getbytes(&n,4); if(!n) return; getbytes(&hunk_number,4); skip(4*n); printf(" Location%s of %ld reference%s to hunk %ld\n", plural(n),n,plural(n),hunk_number); } } skip(number) bit32 number; { if(-1==lseek(fd,number,1)) { printf("\nERROR: Unexpected end of file.\n"); close(fd); exit(10); } } showname() { bit32 length; getbytes(&length,4); print_name(length); } print_name(length) bit32 length; { int x; char c; for(x=4*length;x;x--) { getbytes(&c,1); if(c) putchar(c); } } getbytes(where,howmany) bit32 where; int howmany; { if(howmany!=read(fd,where,howmany)) { printf("\nERROR: Unexpected end of file.\n"); close(fd); exit(10); } }