resources: Add the m5-exit-repeat resource

Change-Id: I10ef7dc9a0a7de7bdf9cd04175587a07e15aa6a4
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5-resources/+/62731
Tested-by: Bobby Bruce <bbruce@ucdavis.edu>
Reviewed-by: Bobby Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
diff --git a/resources.json b/resources.json
index c51d0e7..d9117e4 100644
--- a/resources.json
+++ b/resources.json
@@ -78,6 +78,16 @@
         },
         {
             "type" : "resource",
+            "name" : "x86-m5-exit-repeat",
+            "documentation" : "A simple binary which will run `m5 exit` in an infinite loop. Compiled to the X86 ISA.",
+            "architecture" : "X86",
+            "is_zipped" : false,
+            "md5sum" : "0a19604f669c4b9e468cc2bedee62199",
+            "url" : "{url_base}/test-progs/m5-exit-repeat/x86-m5-exit-repeat-20220825",
+            "source" : "src/m5-exit-repeat"
+        },
+        {
+            "type" : "resource",
             "name" : "x86-parsec",
             "documentation" : "A disk image containing the PARSEC benchmark suite, compiled to X86, built on top of Ubuntu 18.04.",
             "architecture" : "X86",
diff --git a/src/m5-exit-repeat/Makefile b/src/m5-exit-repeat/Makefile
new file mode 100644
index 0000000..7387121
--- /dev/null
+++ b/src/m5-exit-repeat/Makefile
@@ -0,0 +1,41 @@
+# Copyright (c) 2022 The Regents of the University of California
+# All Rights Reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+.DEFAULT_GOAL := m5-exit-repeat
+
+m5-exit-repeat: gem5/util/m5/build/x86/out/m5 m5-exit-repeat.c
+	gcc -o m5-exit-repeat m5-exit-repeat.c -L./gem5/util/m5/build/x86/out -lm5 -I./gem5/include --static
+
+gem5/util/m5/build/x86/out/m5: gem5
+	cd gem5/util/m5 && scons build/x86/out/m5 -j `nproc`
+
+gem5:
+	git clone https://gem5.googlesource.com/public/gem5
+	- rm gem5/build
+
+clean:
+	- rm -rf gem5
+	- rm m5-exit-repeat
diff --git a/src/m5-exit-repeat/README.md b/src/m5-exit-repeat/README.md
new file mode 100644
index 0000000..894a0bc
--- /dev/null
+++ b/src/m5-exit-repeat/README.md
@@ -0,0 +1,65 @@
+---
+title: The 'm5-exit-repeat' binary
+layout: default
+permalink: resources/m5-exit-repeat
+shortdoc: >
+    Source for 'm5-exit-repeat'. A 'm5-exit-repeat' binary runs the `m5_exit(0)` command in an infinite loop. This is useful for testing exit event handlers.
+author: ["Bobby R. Bruce"]
+---
+
+This 'm5-exit-repeat' resource runs the `m5_exit` function in an infinite loop.
+This resource is deliberately kept simple and is used primarily for testing purposes.
+
+## Building Instructions
+
+Run `make`.
+
+**Note:** This will automatically clone the gem5 repository to the `src/m5-exit-repeat` directory.
+If this is not desired, please ensure the gem5 repository is present in this directory before running make.
+
+This will only compile the binary to the X86 ISA.
+
+## Cleaning Instructions
+
+Run `make clean` in the Makefile directory.
+
+## Usage
+
+As this binary utilizes the `m5_exit` function, it should be run within a gem5 simulation.
+Its purpose is to test exit events handler and other situations where it's desirable for a simulation to continually run an `m5_exit` command.
+It should be run in SE Mode.
+
+### Example
+
+The following code snippet utilizes the standard library:
+
+```py
+
+board.set_se_workload(Resource("x86-m5-exit-repeat"))
+
+def unique_exit_event():
+    print("Handling the first exit event.")
+    yield False
+    print("Handling the second exit event.")
+    yield False
+    print("Handling the third exit event. We'll exit now.")
+    yield True
+
+simulator = Simulator(
+    board = board,
+    on_exit_event = {
+        ExitEvent.Exit : unique_exit_event(),
+    },
+)
+
+```
+
+This will handle the exit event three times.
+
+## Pre-built binaries
+
+Compiled to the X86 ISA: http://dist.gem5.org/dist/develop/test-progs/m5-exit-repeat/x86-m5-exit-repeat-20220825
+
+## License
+
+This code is covered by By the [03-Clause BSD License (BSD-3-Clause)](https://opensource.org/licenses/BSD-3-Clause).
diff --git a/src/m5-exit-repeat/m5-exit-repeat.c b/src/m5-exit-repeat/m5-exit-repeat.c
new file mode 100644
index 0000000..90a872c
--- /dev/null
+++ b/src/m5-exit-repeat/m5-exit-repeat.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2022 The Regents of the University of California
+ * All rights reserved
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdio.h>
+#include "gem5/m5ops.h"
+
+int main()
+{
+    printf("The program has started!\n");
+
+    int exit_count = 0;
+    while(1)
+    {
+        exit_count++;
+        printf(
+            "About to exit the simulation for the %d st/nd/rd/th time\n",
+            exit_count
+        );
+        m5_exit(0);
+    };
+
+    return 0;
+}