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-Tag: users/ARM/embedded-binutils-master-2018q4~1245 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=370e4b5079ff8d62be3adee7396948d4c5795091;p=platform%2Fupstream%2Fbinutils.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 7d31449..d94df80 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,11 @@ 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. 2018-07-26 Alan Modra diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index 3414682..414ca54 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 971be4f..7c45d52 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)