From: John Darrington Date: Tue, 24 Jul 2018 10:58:43 +0000 (+0200) Subject: Add functions and macros to read and write 24 bit values. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=370e4b5079ff8d62be3adee7396948d4c5795091;p=binutils-gdb.git Add functions and macros to read and write 24 bit values. * libbfd.c (bfd_getb24, bfd_getl24): New functions. (bfd_get_24, bfd_put_24): New macros. * bfd-in2.h: Regenerate. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 7d3144999b2..d94df8065ee 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2018-07-27 John Darrington + + * libbfd.c (bfd_getb24, bfd_getl24): New functions. + (bfd_get_24, bfd_put_24): New macros. + * bfd-in2.h: Regenerate. + 2018-07-27 John Darrington * elf32-s12z.c (s12z_elf_set_mach_from_flags): Remove comment. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 34146829882..414ca545159 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -1160,6 +1160,20 @@ char *bfd_follow_build_id_debuglink (bfd *abfd, const char *dir); #define bfd_get_signed_16(abfd, ptr) \ BFD_SEND (abfd, bfd_getx_signed_16, (ptr)) +#define bfd_put_24(abfd, val, ptr) \ + do \ + if (bfd_big_endian (abfd)) \ + bfd_putb24 ((val), (ptr)); \ + else \ + bfd_putl24 ((val), (ptr)); \ + while (0) + +bfd_vma bfd_getb24 (const void *p); +bfd_vma bfd_getl24 (const void *p); + +#define bfd_get_24(abfd, ptr) \ + (bfd_big_endian (abfd) ? bfd_getb24 (ptr) : bfd_getl24 (ptr)) + #define bfd_put_32(abfd, val, ptr) \ BFD_SEND (abfd, bfd_putx32, ((val),(ptr))) #define bfd_put_signed_32 \ diff --git a/bfd/libbfd.c b/bfd/libbfd.c index 971be4f3dec..7c45d52aaf7 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -458,6 +458,20 @@ DESCRIPTION .#define bfd_get_signed_16(abfd, ptr) \ . BFD_SEND (abfd, bfd_getx_signed_16, (ptr)) . +.#define bfd_put_24(abfd, val, ptr) \ +. do \ +. if (bfd_big_endian (abfd)) \ +. bfd_putb24 ((val), (ptr)); \ +. else \ +. bfd_putl24 ((val), (ptr)); \ +. while (0) +. +.bfd_vma bfd_getb24 (const void *p); +.bfd_vma bfd_getl24 (const void *p); +. +.#define bfd_get_24(abfd, ptr) \ +. (bfd_big_endian (abfd) ? bfd_getb24 (ptr) : bfd_getl24 (ptr)) +. .#define bfd_put_32(abfd, val, ptr) \ . BFD_SEND (abfd, bfd_putx32, ((val),(ptr))) .#define bfd_put_signed_32 \ @@ -613,7 +627,6 @@ bfd_putl16 (bfd_vma data, void *p) addr[1] = (data >> 8) & 0xff; } - void bfd_putb24 (bfd_vma data, void *p) { @@ -623,7 +636,6 @@ bfd_putb24 (bfd_vma data, void *p) addr[2] = data & 0xff; } - void bfd_putl24 (bfd_vma data, void *p) { @@ -633,6 +645,29 @@ bfd_putl24 (bfd_vma data, void *p) addr[2] = (data >> 16) & 0xff; } +bfd_vma +bfd_getb24 (const void *p) +{ + const bfd_byte *addr = (const bfd_byte *) p; + unsigned long v; + + v = (unsigned long) addr[0] << 16; + v |= (unsigned long) addr[1] << 8; + v |= (unsigned long) addr[2]; + return v; +} + +bfd_vma +bfd_getl24 (const void *p) +{ + const bfd_byte *addr = (const bfd_byte *) p; + unsigned long v; + + v = (unsigned long) addr[0]; + v |= (unsigned long) addr[1] << 8; + v |= (unsigned long) addr[2] << 16; + return v; +} bfd_vma bfd_getb32 (const void *p)