Index: TODO
===================================================================
RCS file: /sources/simulavr/simulavrxx/TODO,v
retrieving revision 1.1
diff -u -r1.1 TODO
--- TODO	9 Mar 2009 15:32:36 -0000	1.1
+++ TODO	10 Mar 2009 16:08:55 -0000
@@ -7,9 +7,11 @@
   - Mingw: Uses BSD sockets.  Need to have WinSock as alternative
 
 + Feature parity with avrtest.  Known issues:
-  - abort magic address
-  - exit magic address
-  - instructions executed limit
+  - Support avrtest magic addresses 
+    #define STDIO_PORT      0x52
+    #define EXIT_PORT       0x4F
+    #define ABORT_PORT      0x49
+  - instructions executed limit (-m)
 
 + Feature parity with simulavr.  Known issues:
   - ?
Index: configure.ac
===================================================================
RCS file: /sources/simulavr/simulavrxx/configure.ac,v
retrieving revision 1.34
diff -u -r1.34 configure.ac
--- configure.ac	10 Mar 2009 15:31:53 -0000	1.34
+++ configure.ac	10 Mar 2009 16:08:55 -0000
@@ -116,6 +116,7 @@
 AC_CONFIG_FILES([\
   Makefile src/Makefile doc/Makefile \
   regress/Makefile regress/modules/Makefile regress/test_opcodes/Makefile \
+  regress/avrtest/Makefile \
   examples/Makefile examples/anacomp/Makefile examples/simple_ex1/Makefile \
 ])
 AC_OUTPUT
Index: doc/simulavrxx.texinfo
===================================================================
RCS file: /sources/simulavr/simulavrxx/doc/simulavrxx.texinfo,v
retrieving revision 1.12
diff -u -r1.12 simulavrxx.texinfo
--- doc/simulavrxx.texinfo	9 Mar 2009 21:13:17 -0000	1.12
+++ doc/simulavrxx.texinfo	10 Mar 2009 16:08:56 -0000
@@ -165,6 +165,8 @@
 load ELF-file <name> for simulation in simulated target.
 @item -F --cpufrequency <value>
 set the CPU frequence to <Hz>
+@item -m --maxruntime <nanoseconds>
+set the maximum simulated run time in <nanoseconds>
 @item -g --gdbserver
 running as avr-gdb-server
 @item -G
@@ -642,6 +644,7 @@
 @item --prefix
 Use this option to specify the root directory to install simulavrxx
 to. /usr/local is the default.
+
 @item --with-bfd-path
 If configure tells you it can't find libbfd, try
 --with-bfd-path=/your/path/. Notice that you are expected to point to
@@ -660,6 +663,11 @@
 requiring the Tcl GUI will be built.  By default, Tcl is enabled
 but if Tcl is not installed on your computer, Tcl will be automatically
 disabled.
+
+@item --with-tclconfig-path
+If configure tells you it can't find tclConfig.sh, try
+--with-tclconfig-path=/your/path/.
+
 @end table
 
 
Index: doc/version.texi
===================================================================
RCS file: /sources/simulavr/simulavrxx/doc/version.texi,v
retrieving revision 1.7
diff -u -r1.7 version.texi
--- doc/version.texi	9 Mar 2009 15:32:40 -0000	1.7
+++ doc/version.texi	10 Mar 2009 16:08:56 -0000
@@ -1,4 +1,4 @@
-@set UPDATED 9 March 2009
+@set UPDATED 10 March 2009
 @set UPDATED-MONTH March 2009
 @set EDITION 0.8.007-WR_b
 @set VERSION 0.8.007-WR_b
Index: regress/Makefile.am
===================================================================
RCS file: /sources/simulavr/simulavrxx/regress/Makefile.am,v
retrieving revision 1.2
diff -u -r1.2 Makefile.am
--- regress/Makefile.am	6 Mar 2009 11:28:22 -0000	1.2
+++ regress/Makefile.am	10 Mar 2009 16:08:56 -0000
@@ -6,7 +6,7 @@
 
 EXTRA_DIST           = README regress.py.in
 
-SUBDIRS              = modules test_opcodes
+SUBDIRS              = modules test_opcodes avrtest
 
 all:
 
Index: regress/avrtest/.cvsignore
===================================================================
RCS file: regress/avrtest/.cvsignore
diff -N regress/avrtest/.cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ regress/avrtest/.cvsignore	10 Mar 2009 16:08:56 -0000
@@ -0,0 +1,3 @@
+Makefile
+Makefile.in
+endless
Index: regress/avrtest/Makefile.am
===================================================================
RCS file: regress/avrtest/Makefile.am
diff -N regress/avrtest/Makefile.am
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ regress/avrtest/Makefile.am	10 Mar 2009 16:08:56 -0000
@@ -0,0 +1,23 @@
+#
+#  $Id: Makefile.am,v 1.3 2009/03/09 15:16:47 joelsherrill Exp $
+#
+
+AVR_GCC=@AVR_GCC@
+
+noinst_DATA = endless
+
+CLEANFILES = endless endless.o trace
+
+## If you want a listing and map, uncomment these
+## LIST_ARG=-Wa,-adhl=$@.lst
+## MAP_ARG=-Wl,-M,-Map=$@.map
+
+endless.o : $(srcdir)/endless.c
+	$(AVR_GCC) $(LIST_ARG) -g -O2 -mmcu=atmega128 -c -o $@ $< 
+
+endless : endless.o
+	$(AVR_GCC) $(MAP_ARG) -mmcu=atmega128 -o $@ $<
+
+run_sim: endless
+	../../src/simulavr --device atmega128 -f endless \
+	    -W 0x20,- -R 0x22,- -T exit -m 100000
Index: regress/avrtest/endless.c
===================================================================
RCS file: regress/avrtest/endless.c
diff -N regress/avrtest/endless.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ regress/avrtest/endless.c	10 Mar 2009 16:08:56 -0000
@@ -0,0 +1,49 @@
+/*
+ *  This is a test program to demonstrate the program run limit feature.
+ *
+ *  $Id: fred.c,v 1.2 2009/03/09 17:20:58 joelsherrill Exp $
+ */
+
+/*
+ *  This port correponds to the "-W 0x20,-" command line option.
+ */
+#define special_output_port (*( (volatile char *)0x20))
+
+/*
+ *  This port correponds to the "-R 0x22,-" command line option.
+ */
+#define special_input_port  (*( (volatile char *)0x22))
+
+/*
+ *  Poll the specified string out the debug port.
+ */
+void debug_puts(const char *str)
+{
+  const char *c;
+
+  for ( c=str ; *c ; c++ )
+    special_output_port = *c;
+}
+
+/*
+ *  Main for test program.  Enter a string and echo it.
+ */
+int main()
+{
+  volatile char in_char;
+
+  /*
+   * Output the prompt string
+   */
+  debug_puts(
+    "\n"
+    "This program goes into an infinite loop after these messages.\n"
+    "When run with the -m XXX option, the simulator should kill us.\n"
+    "\n"
+  );
+
+  while (1) 
+    ;
+
+  return 0;
+}
Index: src/main.cpp
===================================================================
RCS file: /sources/simulavr/simulavrxx/src/main.cpp,v
retrieving revision 1.16
diff -u -r1.16 main.cpp
--- src/main.cpp	24 Feb 2009 14:09:26 -0000	1.16
+++ src/main.cpp	10 Mar 2009 16:08:56 -0000
@@ -2,7 +2,7 @@
  ****************************************************************************
  *
  * simulavr - A simulator for the Atmel AVR family of microcontrollers.
- * Copyright (C) 2001, 2002, 2003   Klaus Rudolph		
+ * Copyright (C) 2001, 2002, 2003   Klaus Rudolph
  * 
  * 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
@@ -61,6 +61,7 @@
     bool globalWaitForGdbConnection=true; //please wait for gdb connection
     int userinterface_flag=0;
     unsigned long long fcpu=4000000;
+    unsigned long long maxRunTime=0;
     UserInterface *ui;
 
     global_trace_on=0;
@@ -82,9 +83,10 @@
             {"file", 1, 0, 'f'},
             {"device", 1, 0, 'd'},
             {"gdbserver", 1, 0, 'g'},
+            {"maxruntime", 1,0,'m'},
+            {"nogdbwait",0,0,'n'},
             {"trace", 1, 0, 't'},
             {"version",0,0,'v'},
-            {"nogdbwait",0,0,'n'},
             {"cpufrequency", 1,0,'F'},
             {"readfrompipe", 1,0,'R'},
             {"writetopipe", 1,0,'W'},
@@ -93,7 +95,7 @@
             {0, 0, 0, 0}
         };
 
-        c = getopt_long (argc, argv, "f:d:gGd:p:t:uxyzhvniF:R:W:VT:", long_options, &option_index);
+        c = getopt_long (argc, argv, "f:d:gGd:m:p:t:uxyzhvniF:R:W:VT:", long_options, &option_index);
         if (c == -1)
             break;
 
@@ -126,6 +128,12 @@
                 if (global_verbose_on) cout << "Running with CPU frequency: " << fcpu<<endl;
                 break;
 
+            case 'm':
+                maxRunTime=strtoll(optarg, NULL, 10);
+                if (global_verbose_on)
+                  cout << "Maximum Run Time: " << maxRunTime << endl;
+                break;
+
             case 'u':
                 if (global_verbose_on) cout << "Run with User Interface at Port 7777" << endl;
                 userinterface_flag=1;
@@ -186,6 +194,7 @@
                 cout << "-d --device <device name>    simulate <device name> " << endl;
                 cout << "-g --gdbserver               run as gdb-server" << endl;
                 cout << "-G                           run as gdb-server and write debug info for gdb-connection" << endl;                             
+                cout << "-m  <nanoseconds>            maximum run time of <nanoseconds>" << endl;
                 cout << "-p  <port>                   us <port> for gdb server" << endl;
                 cout << "-t --trace <file name>       enable trace outputs to <file name>" << endl;
                 cout << "-n --nogdbwait               do not wait for gdb connection" << endl;
@@ -244,10 +253,22 @@
 
     if (gdbserver_flag==0) {
         SystemClock::Instance().Add(dev1);
-        while (1) { //for ever
+        if (maxRunTime == 0) {
+          while (1) {                                     // forever
             bool untilCoreStepFinished=false;
             SystemClock::Instance().Step(untilCoreStepFinished);
-        }
+          }
+       } else {                                           // limited
+          while (SystemClock::Instance().GetCurrentTime() < maxRunTime) {
+            bool untilCoreStepFinished=false;
+            SystemClock::Instance().Step(untilCoreStepFinished);
+          }
+          if (SystemClock::Instance().GetCurrentTime() >= maxRunTime) {
+            cout << endl
+                 << "Ran too long.  Terminated after " << maxRunTime <<
+                    " simulated nanoseconds." << endl;
+          }
+       }
     } else { //gdb should be activated
         cout << "Going to gdb..." << endl;
         GdbServer gdb1(dev1, global_gdbserver_port, global_gdb_debug, globalWaitForGdbConnection);
