X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Fverilog.c;h=9f22bc36bbeb672539e1094c877f7831a6a10489;hb=refs%2Fheads%2Fconcurrent-displaced-stepping-2020-04-01;hp=6d1e7d496ceba472010efd64ed25e1b1ac56a587;hpb=219d1afa89d0d53ca93a684cac341f16470f3ca0;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/verilog.c b/bfd/verilog.c index 6d1e7d496c..9f22bc36bb 100644 --- a/bfd/verilog.c +++ b/bfd/verilog.c @@ -1,5 +1,5 @@ /* BFD back-end for verilog hex memory dump files. - Copyright (C) 2009-2018 Free Software Foundation, Inc. + Copyright (C) 2009-2020 Free Software Foundation, Inc. Written by Anthony Green This file is part of BFD, the Binary File Descriptor library. @@ -58,12 +58,16 @@ #include "libiberty.h" #include "safe-ctype.h" +/* Modified by obcopy.c + Data width in bytes. */ +unsigned int VerilogDataWidth = 1; + /* Macros for converting between hex and binary. */ static const char digs[] = "0123456789ABCDEF"; -#define NIBBLE(x) hex_value(x) -#define HEX(buffer) ((NIBBLE ((buffer)[0])<<4) + NIBBLE ((buffer)[1])) +#define NIBBLE(x) hex_value (x) +#define HEX(buffer) ((NIBBLE ((buffer)[0]) << 4) + NIBBLE ((buffer)[1])) #define TOHEX(d, x) \ d[1] = digs[(x) & 0xf]; \ d[0] = digs[((x) >> 4) & 0xf]; @@ -183,26 +187,82 @@ verilog_write_address (bfd *abfd, bfd_vma address) } /* Write a record of type, of the supplied number of bytes. The - supplied bytes and length don't have a checksum. That's worked out - here. */ + supplied bytes and length don't have a checksum. That's worked + out here. */ static bfd_boolean verilog_write_record (bfd *abfd, const bfd_byte *data, const bfd_byte *end) { - char buffer[50]; + char buffer[52]; const bfd_byte *src = data; char *dst = buffer; bfd_size_type wrlen; - /* Write the data. */ - for (src = data; src < end; src++) + /* Paranoia - check that we will not overflow "buffer". */ + if (((end - data) * 2) /* Number of hex characters we want to emit. */ + + ((end - data) / VerilogDataWidth) /* Number of spaces we want to emit. */ + + 2 /* The carriage return & line feed characters. */ + > (long) sizeof (buffer)) { - TOHEX (dst, *src); - dst += 2; - *dst++ = ' '; + /* FIXME: Should we generate an error message ? */ + return FALSE; + } + + /* Write the data. + FIXME: Under some circumstances we can emit a space at the end of + the line. This is not really necessary, but catching these cases + would make the code more complicated. */ + if (VerilogDataWidth == 1) + { + for (src = data; src < end;) + { + TOHEX (dst, *src); + dst += 2; + src ++; + if (src < end) + *dst++ = ' '; + } } + else if (bfd_little_endian (abfd)) + { + /* If the input byte stream contains: + 05 04 03 02 01 00 + and VerilogDataWidth is 4 then we want to emit: + 02030405 0001 */ + int i; + + for (src = data; src < (end - VerilogDataWidth); src += VerilogDataWidth) + { + for (i = VerilogDataWidth - 1; i >= 0; i--) + { + TOHEX (dst, src[i]); + dst += 2; + } + *dst++ = ' '; + } + + /* Emit any remaining bytes. Be careful not to read beyond "end". */ + while (end > src) + { + -- end; + TOHEX (dst, *end); + dst += 2; + } + } + else + { + for (src = data; src < end;) + { + TOHEX (dst, *src); + dst += 2; + ++ src; + if ((src - data) % VerilogDataWidth == 0) + *dst++ = ' '; + } + } + *dst++ = '\r'; *dst++ = '\n'; wrlen = dst - buffer; @@ -293,7 +353,7 @@ verilog_mkobject (bfd *abfd) #define verilog_close_and_cleanup _bfd_generic_close_and_cleanup #define verilog_bfd_free_cached_info _bfd_generic_bfd_free_cached_info #define verilog_new_section_hook _bfd_generic_new_section_hook -#define verilog_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) +#define verilog_bfd_is_target_special_symbol _bfd_bool_bfd_asymbol_false #define verilog_bfd_is_local_label_name bfd_generic_is_local_label_name #define verilog_get_lineno _bfd_nosymbols_get_lineno #define verilog_find_nearest_line _bfd_nosymbols_find_nearest_line @@ -308,6 +368,7 @@ verilog_mkobject (bfd *abfd) #define verilog_bfd_gc_sections bfd_generic_gc_sections #define verilog_bfd_merge_sections bfd_generic_merge_sections #define verilog_bfd_is_group_section bfd_generic_is_group_section +#define verilog_bfd_group_name bfd_generic_group_name #define verilog_bfd_discard_group bfd_generic_discard_group #define verilog_section_already_linked _bfd_generic_section_already_linked #define verilog_bfd_link_hash_table_create _bfd_generic_link_hash_table_create @@ -345,16 +406,16 @@ const bfd_target verilog_vec = _bfd_dummy_target, }, { - bfd_false, + _bfd_bool_bfd_false_error, verilog_mkobject, - bfd_false, - bfd_false, + _bfd_bool_bfd_false_error, + _bfd_bool_bfd_false_error, }, { /* bfd_write_contents. */ - bfd_false, + _bfd_bool_bfd_false_error, verilog_write_object_contents, - bfd_false, - bfd_false, + _bfd_bool_bfd_false_error, + _bfd_bool_bfd_false_error, }, BFD_JUMP_TABLE_GENERIC (_bfd_generic),