X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=opcodes%2Fcgen-opc.c;h=16d1d30875980ce6dd58ec875271f9445f67df07;hb=cedfc77485dbb566619dc1e2d729ce0a70d1a4ad;hp=9ca6ab50a4950fc3cc3acc377772680a4e9f7c66;hpb=f4321104139af96b8cc3d4946b4e5233d9fa1eab;p=deliverable%2Fbinutils-gdb.git diff --git a/opcodes/cgen-opc.c b/opcodes/cgen-opc.c index 9ca6ab50a4..16d1d30875 100644 --- a/opcodes/cgen-opc.c +++ b/opcodes/cgen-opc.c @@ -1,25 +1,25 @@ /* CGEN generic opcode support. - Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2005 - Free Software Foundation, Inc. + Copyright (C) 1996-2019 Free Software Foundation, Inc. - This file is part of the GNU Binutils and GDB, the GNU debugger. + This file is part of libopcodes. - 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, or (at your option) + 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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ #include "sysdep.h" +#include "alloca-conf.h" #include #include "ansidecl.h" #include "libiberty.h" @@ -28,10 +28,6 @@ #include "symcat.h" #include "opcode/cgen.h" -#ifdef HAVE_ALLOCA_H -#include -#endif - static unsigned int hash_keyword_name (const CGEN_KEYWORD *, const char *, int); static unsigned int hash_keyword_value @@ -131,7 +127,7 @@ cgen_keyword_add (CGEN_KEYWORD *kt, CGEN_KEYWORD_ENTRY *ke) && ! strchr (kt->nonalpha_chars, ke->name[i])) { size_t idx = strlen (kt->nonalpha_chars); - + /* If you hit this limit, please don't just increase the size of the field, instead look for a better algorithm. */ @@ -157,7 +153,7 @@ cgen_keyword_search_init (CGEN_KEYWORD *kt, const char *spec) { CGEN_KEYWORD_SEARCH search; - /* FIXME: Need to specify format of PARAMS. */ + /* FIXME: Need to specify format of params. */ if (spec != NULL) abort (); @@ -373,16 +369,17 @@ cgen_get_insn_value (CGEN_CPU_DESC cd, unsigned char *buf, int length) segments, and endian-convert them, one at a time. */ int i; - /* Enforce divisibility. */ + /* Enforce divisibility. */ if ((length % insn_chunk_bitsize) != 0) abort (); for (i = 0; i < length; i += insn_chunk_bitsize) /* NB: i == bits */ { - int index; + int bit_index; bfd_vma this_value; - index = i; /* NB: not dependent on endianness; opposite of cgen_put_insn_value! */ - this_value = bfd_get_bits (& buf[index / 8], insn_chunk_bitsize, big_p); + + bit_index = i; /* NB: not dependent on endianness; opposite of cgen_put_insn_value! */ + this_value = bfd_get_bits (& buf[bit_index / 8], insn_chunk_bitsize, big_p); value = (value << insn_chunk_bitsize) | this_value; } } @@ -411,15 +408,16 @@ cgen_put_insn_value (CGEN_CPU_DESC cd, segments, and endian-convert them, one at a time. */ int i; - /* Enforce divisibility. */ + /* Enforce divisibility. */ if ((length % insn_chunk_bitsize) != 0) abort (); for (i = 0; i < length; i += insn_chunk_bitsize) /* NB: i == bits */ { - int index; - index = (length - insn_chunk_bitsize - i); /* NB: not dependent on endianness! */ - bfd_put_bits ((bfd_vma) value, & buf[index / 8], insn_chunk_bitsize, big_p); + int bit_index; + + bit_index = (length - insn_chunk_bitsize - i); /* NB: not dependent on endianness! */ + bfd_put_bits ((bfd_vma) value, & buf[bit_index / 8], insn_chunk_bitsize, big_p); value >>= insn_chunk_bitsize; } } @@ -454,17 +452,14 @@ cgen_lookup_insn (CGEN_CPU_DESC cd, CGEN_FIELDS *fields, int alias_p) { - unsigned char *buf; - CGEN_INSN_INT base_insn; CGEN_EXTRACT_INFO ex_info; CGEN_EXTRACT_INFO *info; if (cd->int_insn_p) { info = NULL; - buf = (unsigned char *) alloca (cd->max_insn_bitsize / 8); - cgen_put_insn_value (cd, buf, length, insn_int_value); - base_insn = insn_int_value; + insn_bytes_value = (unsigned char *) xmalloc (cd->max_insn_bitsize / 8); + cgen_put_insn_value (cd, insn_bytes_value, length, insn_int_value); } else { @@ -472,8 +467,7 @@ cgen_lookup_insn (CGEN_CPU_DESC cd, ex_info.dis_info = NULL; ex_info.insn_bytes = insn_bytes_value; ex_info.valid = -1; - buf = insn_bytes_value; - base_insn = cgen_get_insn_value (cd, buf, length); + insn_int_value = cgen_get_insn_value (cd, insn_bytes_value, length); } if (!insn) @@ -483,7 +477,8 @@ cgen_lookup_insn (CGEN_CPU_DESC cd, /* The instructions are stored in hash lists. Pick the first one and keep trying until we find the right one. */ - insn_list = cgen_dis_lookup_insn (cd, (char *) buf, base_insn); + insn_list = cgen_dis_lookup_insn (cd, (char *) insn_bytes_value, + insn_int_value); while (insn_list != NULL) { insn = insn_list->insn; @@ -495,18 +490,18 @@ cgen_lookup_insn (CGEN_CPU_DESC cd, /* Basic bit mask must be correct. */ /* ??? May wish to allow target to defer this check until the extract handler. */ - if ((base_insn & CGEN_INSN_BASE_MASK (insn)) + if ((insn_int_value & CGEN_INSN_BASE_MASK (insn)) == CGEN_INSN_BASE_VALUE (insn)) { /* ??? 0 is passed for `pc' */ int elength = CGEN_EXTRACT_FN (cd, insn) - (cd, insn, info, base_insn, fields, (bfd_vma) 0); + (cd, insn, info, insn_int_value, fields, (bfd_vma) 0); if (elength > 0) { /* sanity check */ if (length != 0 && length != elength) abort (); - return insn; + break; } } } @@ -526,15 +521,17 @@ cgen_lookup_insn (CGEN_CPU_DESC cd, /* ??? 0 is passed for `pc' */ length = CGEN_EXTRACT_FN (cd, insn) - (cd, insn, info, base_insn, fields, (bfd_vma) 0); + (cd, insn, info, insn_int_value, fields, (bfd_vma) 0); /* Sanity check: must succeed. Could relax this later if it ever proves useful. */ if (length == 0) abort (); - return insn; } - return NULL; + if (cd->int_insn_p) + free (insn_bytes_value); + + return insn; } /* Fill in the operand instances used by INSN whose operands are FIELDS.