added yours sincerely for files where I feel that I've made non-trivial contributions.
[openocd.git] / src / helper / binarybuffer.c
index 6afd6e593c23902da97705de2f3f6b20172b1e17..a3b1cbd59f07e6dce34f4fa0f5283c8decbfd7c3 100644 (file)
@@ -2,6 +2,9 @@
  *   Copyright (C) 2004, 2005 by Dominic Rath                              *
  *   Dominic.Rath@gmx.de                                                   *
  *                                                                         *
+ *   Copyright (C) 2007,2008 Ã˜yvind Harboe                                      *
+ *   oyvind.harboe@zylin.com                                               *
+ *                                                                         *
  *   This program 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 of the License, or     *
 
 #include "binarybuffer.h"
 
-int buf_set_u32(u8* buffer, unsigned int first, unsigned int num, u32 value);
-u32 buf_get_u32(u8* buffer, unsigned int first, unsigned int num);
-u32 flip_u32(u32 value, unsigned int num);
-
 const unsigned char bit_reverse_table256[] = 
 {
   0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 
@@ -53,43 +52,6 @@ const unsigned char bit_reverse_table256[] =
   0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
 };
 
-int buf_set_u32(u8* buffer, unsigned int first, unsigned int num, u32 value)
-{
-       unsigned int i;
-       
-       if (!buffer)
-               return ERROR_INVALID_ARGUMENTS;
-
-       for (i=first; i<first+num; i++)
-       {
-               if (((value >> (i-first))&1) == 1)
-                       buffer[i/8] |= 1 << (i%8);
-               else
-                       buffer[i/8] &= ~(1 << (i%8));
-       }
-       
-       return ERROR_OK;
-}
-
-u32 buf_get_u32(u8* buffer, unsigned int first, unsigned int num)
-{
-       u32 result = 0;
-       unsigned int i;
-       
-       if (!buffer)
-       {
-               ERROR("buffer not initialized");
-               return 0;
-       }
-
-       for (i=first; i<first+num; i++)
-       {
-               if (((buffer[i/8]>>(i%8))&1) == 1)
-                       result |= 1 << (i-first);
-       }
-       
-       return result;
-}
 
 u8* buf_cpy(u8 *from, u8 *to, int size)
 {
@@ -101,6 +63,12 @@ u8* buf_cpy(u8 *from, u8 *to, int size)
 
        for (i = 0; i < num_bytes; i++)
                to[i] = from[i];
+       
+       /* mask out bits that don't belong to the buffer */     
+       if (size % 8)
+       {
+               to[size / 8] &= (0xff >> (8 - (size % 8)));
+       }
 
        return to;
 }
@@ -143,8 +111,8 @@ int buf_cmp_mask(u8 *buf1, u8 *buf2, u8 *mask, int size)
                /* mask out bits that don't really belong to the buffer if size isn't a multiple of 8 bits */
                if ((size % 8) && (i == num_bytes -1 ))
                {
-                       if (((buf1[i] & ((1 << (size % 8)) - 1)) & ((1 << (size % 8)) - 1)) != 
-                               ((buf2[i] & ((1 << (size % 8)) - 1)) & ((1 << (size % 8)) - 1)))
+                       if ((buf1[i] & ((1 << (size % 8)) - 1) & mask[i]) != 
+                               (buf2[i] & ((1 << (size % 8)) - 1) & mask[i]))
                                return 1;
                }
                else
@@ -223,7 +191,7 @@ int ceil_f_to_u32(float x)
        return y;
 }
 
-char* buf_to_str(u8 *buf, int buf_len, int radix)
+char* buf_to_str(const u8 *buf, int buf_len, int radix)
 {
        const char *DIGITS = "0123456789abcdef";
        float factor;
@@ -273,7 +241,7 @@ char* buf_to_str(u8 *buf, int buf_len, int radix)
        return str;
 }
 
-int str_to_buf(char* str, int str_len, u8 *buf, int buf_len, int radix)
+int str_to_buf(const char *str, int str_len, u8 *buf, int buf_len, int radix)
 {
        char *charbuf;
        u32 tmp;
@@ -348,7 +316,12 @@ int str_to_buf(char* str, int str_len, u8 *buf, int buf_len, int radix)
        }
        
        for (j = 0; j < CEIL(buf_len, 8); j++)
-               buf[j] = b256_buf[j];
+       {
+               if (j < b256_len)
+                       buf[j] = b256_buf[j];
+               else
+                       buf[j] = 0;
+       }
 
        /* mask out bits that don't belong to the buffer */
        if (buf_len % 8)
@@ -360,7 +333,7 @@ int str_to_buf(char* str, int str_len, u8 *buf, int buf_len, int radix)
        return i;
 }
 
-int buf_to_u32_handler(u8 *in_buf, void *priv)
+int buf_to_u32_handler(u8 *in_buf, void *priv, struct scan_field_s *field)
 {
        u32 *dest = priv;
        

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)