resources: create simple/m5_exit_addr.c

This program exits gem5 with the address version of the m5op.

Change-Id: Iad5c17690e44b41cdc30f8404e5cb7ef8f8e969d
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5-resources/+/36677
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: Bobby R. Bruce <bbruce@ucdavis.edu>
diff --git a/src/simple/Makefile b/src/simple/Makefile
index ed015f7..60c7fa8 100644
--- a/src/simple/Makefile
+++ b/src/simple/Makefile
@@ -54,6 +54,7 @@
 # Common to C and C++.
 CCFLAGS = \
   -I $(GEM5_ROOT)/include/ \
+  -I $(GEM5_ROOT)/util/m5/src/ \
   -O3 \
   -Wall \
   -Werror \
@@ -160,8 +161,11 @@
 	$(CC) $(CFLAGS_USER) -o '$@' $^ $(LDFLAGS_USER)
 
 $(OUT_SQUASHFS_DIR)/%$(OUT_SQUASHFS_EXT): $(OUT_USER_DIR)/%$(OUT_EXT)
-	mkdir -p '$(basename $@)/sbin'
+	@# Create dev so that the kernel can automount CONFIG_DEVTMPFS=y.
+	mkdir -p '$(basename $@)/sbin' '$(basename $@)/dev'
 	cp '$<' '$(basename $@)/sbin/init'
+	@# Existing squashfs files don't get updated otherwise.
+	rm -f '$@'
 	mksquashfs '$(basename $@)' '$@'
 
 $(OUT_BARE_DIR)/%$(OUT_EXT): %$(IN_EXT_CXX) $(M5OP_OBJ) $(BOOTLOADER_OBJ)
diff --git a/src/simple/m5_exit_addr.c b/src/simple/m5_exit_addr.c
new file mode 100644
index 0000000..18cfefa
--- /dev/null
+++ b/src/simple/m5_exit_addr.c
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2020 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder.  You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * 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 <gem5/m5ops.h>
+#include <m5_mmap.h>
+
+#include <stdio.h>
+
+int main(void) {
+#if defined(__aarch64__)
+    m5op_addr = 0x10010000;
+#endif
+    map_m5_mem();
+    m5_exit_addr(0);
+}