8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2011 Jason King. All rights reserved.
27 * Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
28 */
29
30 #include <ctype.h>
31 #include <getopt.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <sys/sysmacros.h>
36 #include <sys/elf_SPARC.h>
37
38 #include <libdisasm.h>
39
40 #include "dis_target.h"
41 #include "dis_util.h"
42 #include "dis_list.h"
43
44 int g_demangle; /* Demangle C++ names */
45 int g_quiet; /* Quiet mode */
46 int g_numeric; /* Numeric mode */
47 int g_flags; /* libdisasm language flags */
529 }
530
531 case EM_SPARCV9:
532 if (ehdr.e_ident[EI_CLASS] != ELFCLASS64 ||
533 ehdr.e_ident[EI_DATA] != ELFDATA2MSB) {
534 warn("invalid E_IDENT field for SPARC object");
535 return;
536 }
537
538 g_flags |= DIS_SPARC_V9 | DIS_SPARC_V9_SGI;
539 break;
540
541 case EM_386:
542 g_flags |= DIS_X86_SIZE32;
543 break;
544
545 case EM_AMD64:
546 g_flags |= DIS_X86_SIZE64;
547 break;
548
549 default:
550 die("%s: unsupported ELF machine 0x%x", filename,
551 ehdr.e_machine);
552 }
553
554 /*
555 * If ET_REL (.o), printing immediate symbols is likely to
556 * result in garbage, as symbol lookups on unrelocated
557 * immediates find false and useless matches.
558 */
559
560 if (ehdr.e_type == ET_REL)
561 g_flags |= DIS_NOIMMSYM;
562
563 if (!g_quiet && dis_tgt_member(current) != NULL)
564 (void) printf("\narchive member %s\n",
565 dis_tgt_member(current));
566
567 /*
568 * Instantiate a libdisasm handle based on the file type.
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2011 Jason King. All rights reserved.
27 * Copyright 2012 Joshua M. Clulow <josh@sysmgr.org>
28 * Copyright 2015 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
29 */
30
31 #include <ctype.h>
32 #include <getopt.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <sys/sysmacros.h>
37 #include <sys/elf_SPARC.h>
38
39 #include <libdisasm.h>
40
41 #include "dis_target.h"
42 #include "dis_util.h"
43 #include "dis_list.h"
44
45 int g_demangle; /* Demangle C++ names */
46 int g_quiet; /* Quiet mode */
47 int g_numeric; /* Numeric mode */
48 int g_flags; /* libdisasm language flags */
530 }
531
532 case EM_SPARCV9:
533 if (ehdr.e_ident[EI_CLASS] != ELFCLASS64 ||
534 ehdr.e_ident[EI_DATA] != ELFDATA2MSB) {
535 warn("invalid E_IDENT field for SPARC object");
536 return;
537 }
538
539 g_flags |= DIS_SPARC_V9 | DIS_SPARC_V9_SGI;
540 break;
541
542 case EM_386:
543 g_flags |= DIS_X86_SIZE32;
544 break;
545
546 case EM_AMD64:
547 g_flags |= DIS_X86_SIZE64;
548 break;
549
550 case EM_S370:
551 g_flags |= DIS_S370;
552
553 if (ehdr.e_ident[EI_CLASS] != ELFCLASS32 ||
554 ehdr.e_ident[EI_DATA] != ELFDATA2MSB) {
555 warn("invalid E_IDENT field for S370 object");
556 return;
557 }
558 break;
559
560 case EM_S390:
561 /*
562 * Both 390 and z/Architecture use EM_S390, the only
563 * differences is the class: ELFCLASS32 for plain
564 * old s390 and ELFCLASS64 for z/Architecture (aka.
565 * s390x).
566 */
567 if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) {
568 g_flags |= DIS_S390_31;
569 } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) {
570 g_flags |= DIS_S390_64;
571 } else {
572 warn("invalid E_IDENT field for S390 object");
573 return;
574 }
575
576 if (ehdr.e_ident[EI_DATA] != ELFDATA2MSB) {
577 warn("invalid E_IDENT field for S390 object");
578 return;
579 }
580 break;
581
582 default:
583 die("%s: unsupported ELF machine 0x%x", filename,
584 ehdr.e_machine);
585 }
586
587 /*
588 * If ET_REL (.o), printing immediate symbols is likely to
589 * result in garbage, as symbol lookups on unrelocated
590 * immediates find false and useless matches.
591 */
592
593 if (ehdr.e_type == ET_REL)
594 g_flags |= DIS_NOIMMSYM;
595
596 if (!g_quiet && dis_tgt_member(current) != NULL)
597 (void) printf("\narchive member %s\n",
598 dis_tgt_member(current));
599
600 /*
601 * Instantiate a libdisasm handle based on the file type.
|