X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=opcodes%2Fz8k-dis.c;h=4ae73230cc6d2694edd6ed371067f6f64a6b2492;hb=e90426589d7c783b7e458162baaac1431fc33bd5;hp=d375e6908d223fc4170487d9ebe5cf6d58d1a11a;hpb=3c25c5f6e8cec6d81e1576e2680767e30a17518f;p=deliverable%2Fbinutils-gdb.git diff --git a/opcodes/z8k-dis.c b/opcodes/z8k-dis.c index d375e6908d..4ae73230cc 100644 --- a/opcodes/z8k-dis.c +++ b/opcodes/z8k-dis.c @@ -1,32 +1,31 @@ /* Disassemble z8000 code. - Copyright 1992, 1993, 1998, 2000, 2001, 2002 - Free Software Foundation, Inc. + Copyright (C) 1992-2018 Free Software Foundation, Inc. - This file is part of GNU Binutils. + This file is part of the GNU opcodes library. - This program is free software; you can redistribute it and/or modify + This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation; either version 3, or (at your option) + any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - USA. */ + along with this file; see the file COPYING. If not, write to the + Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, + MA 02110-1301, USA. */ #include "sysdep.h" -#include "dis-asm.h" +#include "disassemble.h" #define DEFINE_TABLE #include "z8k-opc.h" - + #include - + typedef struct { /* These are all indexed by nibble number (i.e only every other entry @@ -38,9 +37,9 @@ typedef struct /* Nibble number of first word not yet fetched. */ int max_fetched; bfd_vma insn_start; - jmp_buf bailout; + OPCODES_SIGJMP_BUF bailout; - long tabl_index; + int tabl_index; char instr_asmsrc[80]; unsigned long arg_reg[0x0f]; unsigned long immediate; @@ -53,9 +52,6 @@ typedef struct } instr_data_s; -static int fetch_data PARAMS ((struct disassemble_info *, int)); - - /* Make sure that bytes from INFO->PRIVATE_DATA->BUFFER (inclusive) to ADDR (exclusive) are valid. Returns 1 for success, longjmps on error. */ @@ -64,9 +60,7 @@ static int fetch_data PARAMS ((struct disassemble_info *, int)); ? 1 : fetch_data ((info), (nibble))) static int -fetch_data (info, nibble) - struct disassemble_info *info; - int nibble; +fetch_data (struct disassemble_info *info, int nibble) { unsigned char mybuf[20]; int status; @@ -82,7 +76,7 @@ fetch_data (info, nibble) if (status != 0) { (*info->memory_error_func) (status, priv->insn_start, info); - longjmp (priv->bailout, 1); + OPCODES_SIGLONGJMP (priv->bailout, 1); } { @@ -142,25 +136,20 @@ static char *ctrl_names[8] = }; static int seg_length; -static int print_insn_z8k PARAMS ((bfd_vma, disassemble_info *, int)); -int z8k_lookup_instr PARAMS ((unsigned char *, disassemble_info *)); -static void output_instr - PARAMS ((instr_data_s *, unsigned long, disassemble_info *)); -static void unpack_instr PARAMS ((instr_data_s *, int, disassemble_info *)); -static void unparse_instr PARAMS ((instr_data_s *, int)); +int z8k_lookup_instr (unsigned char *, disassemble_info *); +static void output_instr (instr_data_s *, unsigned long, disassemble_info *); +static void unpack_instr (instr_data_s *, int, disassemble_info *); +static void unparse_instr (instr_data_s *, int); static int -print_insn_z8k (addr, info, is_segmented) - bfd_vma addr; - disassemble_info *info; - int is_segmented; +print_insn_z8k (bfd_vma addr, disassemble_info *info, int is_segmented) { instr_data_s instr_data; info->private_data = (PTR) &instr_data; instr_data.max_fetched = 0; instr_data.insn_start = addr; - if (setjmp (instr_data.bailout) != 0) + if (OPCODES_SIGSETJMP (instr_data.bailout) != 0) /* Error return. */ return -1; @@ -169,7 +158,7 @@ print_insn_z8k (addr, info, is_segmented) info->display_endian = BFD_ENDIAN_BIG; instr_data.tabl_index = z8k_lookup_instr (instr_data.nibbles, info); - if (instr_data.tabl_index > 0) + if (instr_data.tabl_index >= 0) { unpack_instr (&instr_data, is_segmented, info); unparse_instr (&instr_data, is_segmented); @@ -186,34 +175,29 @@ print_insn_z8k (addr, info, is_segmented) } int -print_insn_z8001 (addr, info) - bfd_vma addr; - disassemble_info *info; +print_insn_z8001 (bfd_vma addr, disassemble_info *info) { return print_insn_z8k (addr, info, 1); } int -print_insn_z8002 (addr, info) - bfd_vma addr; - disassemble_info *info; +print_insn_z8002 (bfd_vma addr, disassemble_info *info) { return print_insn_z8k (addr, info, 0); } int -z8k_lookup_instr (nibbles, info) - unsigned char *nibbles; - disassemble_info *info; +z8k_lookup_instr (unsigned char *nibbles, disassemble_info *info) { - int nibl_index, tabl_index; int nibl_matched; + int need_fetch = 0; unsigned short instr_nibl; unsigned short tabl_datum, datum_class, datum_value; nibl_matched = 0; tabl_index = 0; + FETCH_DATA (info, 4); while (!nibl_matched && z8k_table[tabl_index].name) { nibl_matched = 1; @@ -222,8 +206,15 @@ z8k_lookup_instr (nibbles, info) nibl_index++) { if ((nibl_index % 4) == 0) - /* Fetch one word at a time. */ - FETCH_DATA (info, nibl_index + 4); + { + /* Fetch data only if it isn't already there. */ + if (nibl_index >= 4 || (nibl_index < 4 && need_fetch)) + FETCH_DATA (info, nibl_index + 4); /* Fetch one word at a time. */ + if (nibl_index < 4) + need_fetch = 0; + else + need_fetch = 1; + } instr_nibl = nibbles[nibl_index]; tabl_datum = z8k_table[tabl_index].byte_info[nibl_index]; @@ -286,10 +277,9 @@ z8k_lookup_instr (nibbles, info) } static void -output_instr (instr_data, addr, info) - instr_data_s *instr_data; - unsigned long addr ATTRIBUTE_UNUSED; - disassemble_info *info; +output_instr (instr_data_s *instr_data, + unsigned long addr ATTRIBUTE_UNUSED, + disassemble_info *info) { int num_bytes; char out_str[100]; @@ -305,10 +295,7 @@ output_instr (instr_data, addr, info) } static void -unpack_instr (instr_data, is_segmented, info) - instr_data_s *instr_data; - int is_segmented; - disassemble_info *info; +unpack_instr (instr_data_s *instr_data, int is_segmented, disassemble_info *info) { int nibl_count, loop; unsigned short instr_nibl, instr_byte, instr_word; @@ -414,14 +401,14 @@ unpack_instr (instr_data, is_segmented, info) FETCH_DATA (info, nibl_count + 8); instr_long = (instr_data->words[nibl_count] << 16) | (instr_data->words[nibl_count + 4]); - instr_data->address = ((instr_word & 0x7f00) << 8) + instr_data->address = ((instr_word & 0x7f00) << 16) + (instr_long & 0xffff); nibl_count += 7; seg_length = 2; } else { - instr_data->address = ((instr_word & 0x7f00) << 8) + instr_data->address = ((instr_word & 0x7f00) << 16) + (instr_word & 0x00ff); nibl_count += 3; } @@ -485,9 +472,55 @@ unpack_instr (instr_data, is_segmented, info) } static void -unparse_instr (instr_data, is_segmented) - instr_data_s *instr_data; - int is_segmented; +print_intr(char *tmp_str, unsigned long interrupts) +{ + int comma = 0; + + *tmp_str = 0; + if (! (interrupts & 2)) + { + strcat (tmp_str, "vi"); + comma = 1; + } + if (! (interrupts & 1)) + { + if (comma) strcat (tmp_str, ","); + strcat (tmp_str, "nvi"); + } +} + +static void +print_flags(char *tmp_str, unsigned long flags) +{ + int comma = 0; + + *tmp_str = 0; + if (flags & 8) + { + strcat (tmp_str, "c"); + comma = 1; + } + if (flags & 4) + { + if (comma) strcat (tmp_str, ","); + strcat (tmp_str, "z"); + comma = 1; + } + if (flags & 2) + { + if (comma) strcat (tmp_str, ","); + strcat (tmp_str, "s"); + comma = 1; + } + if (flags & 1) + { + if (comma) strcat (tmp_str, ","); + strcat (tmp_str, "p"); + } +} + +static void +unparse_instr (instr_data_s *instr_data, int is_segmented) { unsigned short datum_value; unsigned int tabl_datum, datum_class; @@ -515,10 +548,10 @@ unparse_instr (instr_data, is_segmented) break; case CLASS_BA: if (is_segmented) - sprintf (tmp_str, "rr%ld(#%lx)", instr_data->arg_reg[datum_value], + sprintf (tmp_str, "rr%ld(#0x%lx)", instr_data->arg_reg[datum_value], instr_data->immediate); else - sprintf (tmp_str, "r%ld(#%lx)", instr_data->arg_reg[datum_value], + sprintf (tmp_str, "r%ld(#0x%lx)", instr_data->arg_reg[datum_value], instr_data->immediate); strcat (out_str, tmp_str); break; @@ -536,6 +569,12 @@ unparse_instr (instr_data, is_segmented) strcat (out_str, tmp_str); break; case CLASS_IMM: + if (datum_value == ARG_IMM2) /* True with EI/DI instructions only. */ + { + print_intr (tmp_str, instr_data->interrupts); + strcat (out_str, tmp_str); + break; + } sprintf (tmp_str, "#0x%0lx", instr_data->immediate); strcat (out_str, tmp_str); break; @@ -559,8 +598,12 @@ unparse_instr (instr_data, is_segmented) sprintf (tmp_str, "@r%ld", instr_data->arg_reg[datum_value]); strcat (out_str, tmp_str); break; + case CLASS_IRO: + sprintf (tmp_str, "@r%ld", instr_data->arg_reg[datum_value]); + strcat (out_str, tmp_str); + break; case CLASS_FLAGS: - sprintf (tmp_str, "0x%0lx", instr_data->flags); + print_flags(tmp_str, instr_data->flags); strcat (out_str, tmp_str); break; case CLASS_REG_BYTE: