Print this page
OS-7095 Want risc-v disassembler


   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 */


 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 




   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  * Copyright 2018, Joyent, Inc.
  30  */
  31 
  32 #include <ctype.h>
  33 #include <getopt.h>
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <string.h>
  37 #include <sys/sysmacros.h>
  38 #include <sys/elf_SPARC.h>
  39 
  40 #include <libdisasm.h>
  41 
  42 #include "dis_target.h"
  43 #include "dis_util.h"
  44 #include "dis_list.h"
  45 
  46 int g_demangle;         /* Demangle C++ names */
  47 int g_quiet;            /* Quiet mode */
  48 int g_numeric;          /* Numeric mode */
  49 int g_flags;            /* libdisasm language flags */


 561                 case EM_S390:
 562                         /*
 563                          * Both 390 and z/Architecture use EM_S390, the only
 564                          * differences is the class: ELFCLASS32 for plain
 565                          * old s390 and ELFCLASS64 for z/Architecture (aka.
 566                          * s390x).
 567                          */
 568                         if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) {
 569                                 g_flags |= DIS_S390_31;
 570                         } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) {
 571                                 g_flags |= DIS_S390_64;
 572                         } else {
 573                                 warn("invalid E_IDENT field for S390 object");
 574                                 return;
 575                         }
 576 
 577                         if (ehdr.e_ident[EI_DATA] != ELFDATA2MSB) {
 578                                 warn("invalid E_IDENT field for S390 object");
 579                                 return;
 580                         }
 581                         break;
 582 
 583                 case EM_RISCV:
 584                         /*
 585                          * RISC-V is defined to be litle endian. The current ISA
 586                          * makes it clear that the 64-bit instructions can
 587                          * co-eixst with the 32-bit ones and therefore we don't
 588                          * need a separate elf class at this time.
 589                          */
 590                         if (ehdr.e_ident[EI_DATA] != ELFDATA2LSB) {
 591                                 warn("invalid EI_DATA field for RISC-V object");
 592                                 return;
 593                         }
 594 
 595                         if (ehdr.e_ident[EI_CLASS] == ELFCLASS32) {
 596                                 g_flags |= DIS_RISCV_32;
 597                         } else if (ehdr.e_ident[EI_CLASS] == ELFCLASS64) {
 598                                 g_flags |= DIS_RISCV_64;
 599                         } else {
 600                                 warn("invalid EI_CLASS field for RISC-V "
 601                                     "object");
 602                                 return;
 603                         }
 604                         break;
 605 
 606                 default:
 607                         die("%s: unsupported ELF machine 0x%x", filename,
 608                             ehdr.e_machine);
 609                 }
 610 
 611                 /*
 612                  * If ET_REL (.o), printing immediate symbols is likely to
 613                  * result in garbage, as symbol lookups on unrelocated
 614                  * immediates find false and useless matches.
 615                  */
 616 
 617                 if (ehdr.e_type == ET_REL)
 618                         g_flags |= DIS_NOIMMSYM;
 619 
 620                 if (!g_quiet && dis_tgt_member(current) != NULL)
 621                         (void) printf("\narchive member %s\n",
 622                             dis_tgt_member(current));
 623