On Sunday, 03 Mar 2013 11:33:42 Jeremy Bennett wrote:
> 2. Could you supply a git patch if at all possible. The main repo is at
> https://github.com/openrisc/or1ksim.

commit-704b13d against or1k-master.
commit-2e91d08 against or32-master.

> Note that there are now two branches of Or1ksim, to deal with the new
> style OpenRISC architecture naming (targets called or1k-* rather than
> or32-*). Could you check if this affects you code (I'm not sure if the
> constant OR32_BIG_ENDIAN becomes OR1K_BIG_ENDIAN for example). If it
> does, I'll ideally need two patches, one for each branch (sigh). One day
> the problem will go away, when we can drop the or32 branch.

one thing to note: OR32_BIG_ENDIAN did not change from or32-master to 
or1k-master.

:{)}
commit 704b13d909747a9e6fcb6895abec4b5c8ca8ca7b
Author: Jack Thomasson <[email protected]>
Date:   Tue Mar 5 07:43:48 2013 -0700

    add "type=file" to "section memory"
    set the memory values to be the contents of the file specified by "name="
    handle different byte order between host and target

diff --git a/ChangeLog b/ChangeLog
index 49c6fee..4143f63 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-02-27  Jack Thomasson  <[email protected]>
+
+       * peripheral/memory.c: add "type=file" to "section memory"
+       handle different byte order between host and target, important for
+       a seamless user experience
+
 2013-01-30  Jeremy Bennett  <[email protected]>
 
        * README.md: Updated to explain about the or1k variant.
diff --git a/configure.ac b/configure.ac
index 53afa15..a0fa34a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,7 +106,7 @@ AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h string.h 
strings.h      \
                 sys/ptem.h sys/pte.h sys/stream.h sys/stropts.h sys/select.h \
                 termcap.h termios.h termio.h sys/file.h locale.h getopt.h    \
                 net/ethernet.h sys/ethernet.h malloc.h inttypes.h libintl.h  \
-                 limits.h linux/if_tun.h)
+                 limits.h linux/if_tun.h arpa/inet.h)
 AC_CHECK_FUNCS(strcasecmp select setenv putenv tcgetattr setlocale lstat)
 AC_CHECK_FUNCS(grantpt unlockpt ptsname on_exit)
 AC_CHECK_FUNCS(basename)
diff --git a/doc/or1ksim.texi b/doc/or1ksim.texi
index 6afc5f6..58d0d3e 100644
--- a/doc/or1ksim.texi
+++ b/doc/or1ksim.texi
@@ -1950,7 +1950,7 @@ The following parameters may be specified.
 
 @table @code
 
-@item type=random|pattern|unknown|zero|exitnops
+@item type=random|pattern|unknown|zero|exitnops|file
 @cindex @code{type} (memory configuration)
 Specifies the values to which memory should be initialized.  The
 default value is @code{unknown}.
@@ -1993,6 +1993,13 @@ Set the memory values to be an instruction used to 
signal end of
 simulation. This is useful for causing immediate end of simulation
 when PC corruption occurs.
 
+@item file
+@cindex @code{type=file} (memory configuration)
+Set the memory values to be the contents of the file specified by
+@code{name}.  If the file is smaller than @code{size} the remaining
+values are initialized to 0.  If the file is larger than @code{size}
+only @code{size} values are initialized to avoid overflow.
+
 @end table
 
 @item random_seed = @var{value}
diff --git a/peripheral/memory.c b/peripheral/memory.c
index e70e98f..a232361 100644
--- a/peripheral/memory.c
+++ b/peripheral/memory.c
@@ -33,6 +33,13 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <time.h>
+#include <fcntl.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
 
 /* Package includes */
 #include "arch.h"
@@ -64,7 +71,8 @@ struct mem_config
     MT_UNKNOWN,
     MT_PATTERN,
     MT_RANDOM,
-    MT_EXITNOPS
+    MT_EXITNOPS,
+    MT_FILE,
   } type;
 };
 
@@ -226,6 +234,37 @@ mem_reset (void *dat)
          break;
        }
       break;
+    case MT_FILE:
+      seed = open(mem->name, O_RDONLY, 0);
+      if (-1 == seed) {
+       perror(mem->name);
+       exit(1);
+      }
+      i = read(seed, mem_area, mem->size);
+      if (-1 == i) {
+       perror(mem->name);
+       close(seed);
+       exit(1);
+      }
+      close(seed);
+      memset(mem_area+i, 0, mem->size-i);
+      /* check host vs target byte ordering
+       * probably fails with OR32_LITTLE_ENDIAN on PDP_ENDIAN */
+      if (OR32_BIG_ENDIAN ^ (*(uint32_t*)"\1\2\3\4" == 0x01020304)) {
+       while (i > 0) {
+         uint32_t x = htonl(*(uint32_t*)mem_area);
+#ifdef OR32_LITTLE_ENDIAN
+         x = ((x & 0xff000000) >> 24 |
+              (x & 0x00ff0000) >> 8 |
+              (x & 0x0000ff00) << 8 |
+              (x & 0x000000ff) << 24);
+#endif
+         *(uint32_t*)mem_area = x;
+         mem_area += sizeof(uint32_t);
+         i -= sizeof(uint32_t);
+       }
+      }
+      break;
     default:
       fprintf (stderr, "Invalid memory configuration type.\n");
       exit (1);
@@ -266,7 +305,7 @@ memory_pattern (union param_val val, void *dat)
 /*---------------------------------------------------------------------------*/
 /*!Set the memory type
 
-   Value must be one of unknown, random, pattern or zero (case
+   Value must be one of unknown, random, pattern, zero, exitnops or file (case
    insensitive). Unrecognized values are ignored with a warning.
 
    @param[in] val  The value to use
@@ -299,6 +338,10 @@ memory_type (union param_val val, void *dat)
       mem->type = MT_EXITNOPS;
       mem->pattern = 0;
     }
+  else if (0 == strcasecmp (val.str_val, "file"))
+    {
+      mem->type = MT_FILE;
+    }
   else
     {
       fprintf (stderr, "Warning: memory type invalid. Ignored");
diff --git a/sim.cfg b/sim.cfg
index 200a983..971c70c 100755
--- a/sim.cfg
+++ b/sim.cfg
@@ -130,7 +130,7 @@ end
 
 /* Memory section
 
-   type        = unknown|random|unknown|pattern
+   type        = unknown|random|pattern|zero|exitnops|file
    random_seed = <value> (default: -1)
    pattern     = <value> (default: 0)
    baseaddr    = <hex_value> (default: 0)
commit 2e91d08979d91e4e115e97eb85329dd852a997bb
Author: Jack Thomasson <[email protected]>
Date:   Tue Mar 5 08:04:13 2013 -0700

    add "type=file" to "section memory"
    set the memory values to be the contents of the file specified by "name="
    handle different byte order between host and target

diff --git a/ChangeLog b/ChangeLog
index 85c9333..7f1450e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2013-02-27  Jack Thomasson  <[email protected]>
+
+       * peripheral/memory.c: add "type=file" to "section memory"
+       handle different byte order between host and target, important for
+       a seamless user experience
+
 2012-04-27  Peter Gavin  <[email protected]>
 
        * configure: Regenerated.
diff --git a/configure.ac b/configure.ac
index eb9a258..12c0571 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,7 +99,7 @@ AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h string.h 
strings.h      \
                 sys/ptem.h sys/pte.h sys/stream.h sys/stropts.h sys/select.h \
                 termcap.h termios.h termio.h sys/file.h locale.h getopt.h    \
                 net/ethernet.h sys/ethernet.h malloc.h inttypes.h libintl.h  \
-                 limits.h linux/if_tun.h)
+                 limits.h linux/if_tun.h arpa/inet.h)
 AC_CHECK_FUNCS(strcasecmp select setenv putenv tcgetattr setlocale lstat)
 AC_CHECK_FUNCS(grantpt unlockpt ptsname on_exit)
 AC_CHECK_FUNCS(basename)
diff --git a/doc/or1ksim.texi b/doc/or1ksim.texi
index 56949db..c5745b5 100644
--- a/doc/or1ksim.texi
+++ b/doc/or1ksim.texi
@@ -1935,7 +1935,7 @@ The following parameters may be specified.
 
 @table @code
 
-@item type=random|pattern|unknown|zero|exitnops
+@item type=random|pattern|unknown|zero|exitnops|file
 @cindex @code{type} (memory configuration)
 Specifies the values to which memory should be initialized.  The
 default value is @code{unknown}.
@@ -1978,6 +1978,13 @@ Set the memory values to be an instruction used to 
signal end of
 simulation. This is useful for causing immediate end of simulation
 when PC corruption occurs.
 
+@item file
+@cindex @code{type=file} (memory configuration)
+Set the memory values to be the contents of the file specified by
+@code{name}.  If the file is smaller than @code{size} the remaining
+values are initialized to 0.  If the file is larger than @code{size}
+only @code{size} values are initialized to avoid overflow.
+
 @end table
 
 @item random_seed = @var{value}
diff --git a/peripheral/memory.c b/peripheral/memory.c
index e70e98f..a232361 100644
--- a/peripheral/memory.c
+++ b/peripheral/memory.c
@@ -33,6 +33,13 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <time.h>
+#include <fcntl.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
 
 /* Package includes */
 #include "arch.h"
@@ -64,7 +71,8 @@ struct mem_config
     MT_UNKNOWN,
     MT_PATTERN,
     MT_RANDOM,
-    MT_EXITNOPS
+    MT_EXITNOPS,
+    MT_FILE,
   } type;
 };
 
@@ -226,6 +234,37 @@ mem_reset (void *dat)
          break;
        }
       break;
+    case MT_FILE:
+      seed = open(mem->name, O_RDONLY, 0);
+      if (-1 == seed) {
+       perror(mem->name);
+       exit(1);
+      }
+      i = read(seed, mem_area, mem->size);
+      if (-1 == i) {
+       perror(mem->name);
+       close(seed);
+       exit(1);
+      }
+      close(seed);
+      memset(mem_area+i, 0, mem->size-i);
+      /* check host vs target byte ordering
+       * probably fails with OR32_LITTLE_ENDIAN on PDP_ENDIAN */
+      if (OR32_BIG_ENDIAN ^ (*(uint32_t*)"\1\2\3\4" == 0x01020304)) {
+       while (i > 0) {
+         uint32_t x = htonl(*(uint32_t*)mem_area);
+#ifdef OR32_LITTLE_ENDIAN
+         x = ((x & 0xff000000) >> 24 |
+              (x & 0x00ff0000) >> 8 |
+              (x & 0x0000ff00) << 8 |
+              (x & 0x000000ff) << 24);
+#endif
+         *(uint32_t*)mem_area = x;
+         mem_area += sizeof(uint32_t);
+         i -= sizeof(uint32_t);
+       }
+      }
+      break;
     default:
       fprintf (stderr, "Invalid memory configuration type.\n");
       exit (1);
@@ -266,7 +305,7 @@ memory_pattern (union param_val val, void *dat)
 /*---------------------------------------------------------------------------*/
 /*!Set the memory type
 
-   Value must be one of unknown, random, pattern or zero (case
+   Value must be one of unknown, random, pattern, zero, exitnops or file (case
    insensitive). Unrecognized values are ignored with a warning.
 
    @param[in] val  The value to use
@@ -299,6 +338,10 @@ memory_type (union param_val val, void *dat)
       mem->type = MT_EXITNOPS;
       mem->pattern = 0;
     }
+  else if (0 == strcasecmp (val.str_val, "file"))
+    {
+      mem->type = MT_FILE;
+    }
   else
     {
       fprintf (stderr, "Warning: memory type invalid. Ignored");
diff --git a/sim.cfg b/sim.cfg
index 4dfbb03..379999c 100755
--- a/sim.cfg
+++ b/sim.cfg
@@ -130,7 +130,7 @@ end
 
 /* Memory section
 
-   type        = unknown|random|unknown|pattern
+   type        = unknown|random|pattern|zero|exitnops|file
    random_seed = <value> (default: -1)
    pattern     = <value> (default: 0)
    baseaddr    = <hex_value> (default: 0)
_______________________________________________
OpenRISC mailing list
[email protected]
http://lists.openrisc.net/listinfo/openrisc

Reply via email to