diff options
author | Nick Clifton <nickc@redhat.com> | 2000-12-21 18:20:04 +0000 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2000-12-21 18:20:04 +0000 |
commit | 8c603c85a1a36ac618c2f03d69686a7985a5ab77 (patch) | |
tree | 03569d99c89b225bf5b6cb262f616cffb6d1fe94 /bfd/libbfd.c | |
parent | dafc8383e875d59fe601526f4787a12e88f4a69e (diff) | |
download | gdb-8c603c85a1a36ac618c2f03d69686a7985a5ab77.zip gdb-8c603c85a1a36ac618c2f03d69686a7985a5ab77.tar.gz gdb-8c603c85a1a36ac618c2f03d69686a7985a5ab77.tar.bz2 |
Add bfd_get_bits() and bfd_put_bits().
Diffstat (limited to 'bfd/libbfd.c')
-rw-r--r-- | bfd/libbfd.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/bfd/libbfd.c b/bfd/libbfd.c index 47f1ebb..c570ddf 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -1190,6 +1190,54 @@ bfd_putl64 (data, addr) BFD_FAIL(); #endif } + +void +bfd_put_bits (data, addr, bits, big_p) + bfd_vma data; + bfd_byte *addr; + int bits; + boolean big_p; +{ + int i; + int bytes; + + if (bits % 8 != 0) + abort (); + + bytes = bits / 8; + for (i = 0; i < bytes; i++) + { + int index = big_p ? bytes - i - 1 : i; + + addr[index] = (bfd_byte) data; + data >>= 8; + } +} + +bfd_vma +bfd_get_bits (addr, bits, big_p) + bfd_byte *addr; + int bits; + boolean big_p; +{ + bfd_vma data; + int i; + int bytes; + + if (bits % 8 != 0) + abort (); + + data = 0; + bytes = bits / 8; + for (i = 0; i < bytes; i++) + { + int index = big_p ? i : bytes - i - 1; + + data = (data << 8) | addr[index]; + } + + return data; +} /* Default implementation */ |