anyone mind if i commit this ?  the 'dr' command now outputs hex values in
addition to the bitstring, and it accepts hex values in addition to
bitstrings.  the only difference with the hex string is that it isnt as rigid
in terms of making sure you gave the exact number of bits as required.  this
is due to hex strings being limited to multiples of 4 and there is no such
limitation in the data register length.

because of this, if you have a 16bit register, then doing:
dr 0x3
is the same as doing:
dr 0000000000000111
i think this is OK though ...

i created some utility functions for setting registers based on a string or
value.  not sure if there's anywhere else in urjtag that could be changed to
use these guys ?  i looked around but didnt really find anything ...

so the new output looks like:
jjtag> dr
00110010011111001000000011001011 (0x327C80CB)
jtag> dr 0x327c80cb
00110010011111001000000011001011 (0x327C80CB)
jtag> dr 0x3
00000000000000000000000000000011 (0x00000003)
-mike

--- include/urjtag/tap_register.h       (revision 1732)
+++ include/urjtag/tap_register.h       (working copy)
@@ -39,6 +39,8 @@ urj_tap_register_t *urj_tap_register_all
 urj_tap_register_t *urj_tap_register_duplicate (const urj_tap_register_t *tr);
 void urj_tap_register_free (urj_tap_register_t *tr);
 urj_tap_register_t *urj_tap_register_fill (urj_tap_register_t *tr, int val);
+int urj_tap_register_set_string (urj_tap_register_t *tr, const char *str);
+int urj_tap_register_set_value (urj_tap_register_t *tr, uint64_t val);
 const char *urj_tap_register_get_string (const urj_tap_register_t *tr);
 uint64_t urj_tap_register_get_value (const urj_tap_register_t *tr);
 /** @return 0 or 1 on success; -1 on error */
--- src/cmd/cmd_dr.c    (revision 1732)
+++ src/cmd/cmd_dr.c    (working copy)
@@ -24,6 +24,7 @@
 
 #include <sysdep.h>
 
+#include <inttypes.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -85,28 +86,9 @@ cmd_dr_run (urj_chain_t *chain, char *pa
             dir = 1;
         else
         {
-            unsigned int bit;
-            if (strspn (params[1], "01") != strlen (params[1]))
-            {
-                urj_error_set (URJ_ERROR_SYNTAX,
-                               "bit patterns should be 0s and 1s, not '%s'",
-                               params[1]);
-                return URJ_STATUS_FAIL;
-            }
-
-            r = dr->in;
-            if (r->len != strlen (params[1]))
-            {
-                urj_error_set (URJ_ERROR_OUT_OF_BOUNDS,
-                               _("%s: register length %d mismatch: %zd"),
-                               "dr", r->len, strlen (params[1]));
-                return URJ_STATUS_FAIL;
-            }
-            for (bit = 0; params[1][bit]; bit++)
-            {
-                r->data[r->len - 1 - bit] = (params[1][bit] == '1');
-            }
-
+            int ret = urj_tap_register_set_string (dr->in, params[1]);
+            if (ret != URJ_STATUS_OK)
+                return ret;
             dir = 0;
         }
     }
@@ -115,7 +97,9 @@ cmd_dr_run (urj_chain_t *chain, char *pa
         r = dr->out;
     else
         r = dr->in;
-    urj_log (URJ_LOG_LEVEL_NORMAL, _("%s\n"), urj_tap_register_get_string (r));
+    urj_log (URJ_LOG_LEVEL_NORMAL, "%s (0x%0*" PRIX64 ")\n",
+             urj_tap_register_get_string (r), r->len / 4,
+             urj_tap_register_get_value (r));
 
     return URJ_STATUS_OK;
 }
@@ -126,12 +110,14 @@ cmd_dr_help (void)
     urj_log (URJ_LOG_LEVEL_NORMAL,
              _("Usage: %s [DIR]\n"
                "Usage: %s BITSTRING\n"
+               "Usage: %s HEXSTRING\n"
                "Display input or output data register content or set current 
register.\n"
                "\n"
                "DIR           requested data register; possible values: 'in' 
for\n"
                "              input and 'out' for output; default is 'out'\n"
-               "BITSTRING     set current data register with BITSTRING (e.g. 
01010)\n"),
-             "dr", "dr");
+               "BITSTRING     set current data register with BITSTRING (e.g. 
01010)\n"
+               "HEXSTRING     set current data register with HEXSTRING (e.g. 
0x123)\n"),
+             "dr", "dr", "dr");
 }
 
 const urj_cmd_t urj_cmd_dr = {
--- src/tap/register.c  (revision 1732)
+++ src/tap/register.c  (working copy)
@@ -22,6 +22,9 @@
  *
  */
 
+#include <sysdep.h>
+
+#include <inttypes.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -108,6 +111,69 @@ urj_tap_register_fill (urj_tap_register_
     return tr;
 }
 
+int
+urj_tap_register_set_string (urj_tap_register_t *tr, const char *str)
+{
+    if (strncmp (str, "0x", 2) == 0)
+    {
+        /* Hex values */
+        uint64_t val;
+
+        if (sscanf (str, "%"PRIX64, &val) != 1)
+        {
+            urj_error_set (URJ_ERROR_SYNTAX,
+                           _("invalid hex string '%s'"),
+                           str);
+            return URJ_STATUS_FAIL;
+        }
+        return urj_tap_register_set_value (tr, val);
+    }
+    else
+    {
+        /* Bit string */
+        unsigned int bit;
+
+        if (strspn (str, "01") != strlen (str))
+        {
+            urj_error_set (URJ_ERROR_SYNTAX,
+                           _("bit patterns should be 0s and 1s, not '%s'"),
+                           str);
+            return URJ_STATUS_FAIL;
+        }
+        else if (tr->len != strlen (str))
+        {
+            urj_error_set (URJ_ERROR_OUT_OF_BOUNDS,
+                           _("register length %d mismatch: %zd"),
+                           tr->len, strlen (str));
+            return URJ_STATUS_FAIL;
+        }
+
+        for (bit = 0; str[bit]; ++bit)
+            tr->data[tr->len - 1 - bit] = (str[bit] == '1');
+
+        return URJ_STATUS_OK;
+    }
+}
+
+int
+urj_tap_register_set_value (urj_tap_register_t *tr, uint64_t val)
+{
+    unsigned int bit;
+
+    if (val >> tr->len)
+    {
+        urj_error_set (URJ_ERROR_OUT_OF_BOUNDS,
+                       _("register value 0x%"PRIX64" will not fit in %d bits"),
+                       val, tr->len);
+        return URJ_STATUS_FAIL;
+    }
+
+    for (bit = 0; bit < tr->len; ++bit)
+        tr->data[tr->len - 1 - bit] = !!(val & (1 << (tr->len - 1 - bit)));
+
+    return URJ_STATUS_OK;
+}
+
 const char *
 urj_tap_register_get_string (const urj_tap_register_t *tr)
 {

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development

Reply via email to