dev: Enable Terminal output's dump to stdout

While the default option is to dump the Terminal content in a file (e.g.
m5out/system.terminal), with this patch it will be possible to choose to
dump it to standard output.

Change-Id: If51c2fd671fa3eb0867a855b5f7d3b0df9cad025
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/20639
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
diff --git a/src/dev/serial/Terminal.py b/src/dev/serial/Terminal.py
index be7fbdc..5340104 100644
--- a/src/dev/serial/Terminal.py
+++ b/src/dev/serial/Terminal.py
@@ -1,3 +1,15 @@
+# Copyright (c) 2019 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.
+#
 # Copyright (c) 2005-2007 The Regents of The University of Michigan
 # All rights reserved.
 #
@@ -32,9 +44,12 @@
 
 from m5.objects.Serial import SerialDevice
 
+class TerminalDump(Enum): vals = ["none", "stdout", "stderr", "file"]
+
 class Terminal(SerialDevice):
     type = 'Terminal'
     cxx_header = "dev/serial/terminal.hh"
     port = Param.TcpPort(3456, "listen port")
     number = Param.Int(0, "terminal number")
-    output = Param.Bool(True, "Enable output dump to file")
+    outfile = Param.TerminalDump("file",
+        "Selects if and where the terminal is dumping its output")
diff --git a/src/dev/serial/terminal.cc b/src/dev/serial/terminal.cc
index bc8c14c..002a2eb 100644
--- a/src/dev/serial/terminal.cc
+++ b/src/dev/serial/terminal.cc
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2019 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.
+ *
  * Copyright (c) 2001-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
@@ -109,7 +121,7 @@
 Terminal::Terminal(const Params *p)
     : SerialDevice(p), listenEvent(NULL), dataEvent(NULL),
       number(p->number), data_fd(-1), txbuf(16384), rxbuf(16384),
-      outfile(p->output ? simout.findOrCreate(p->name) : NULL)
+      outfile(terminalDump(p))
 #if TRACING_ON == 1
       , linebuf(16384)
 #endif
@@ -133,6 +145,22 @@
         delete dataEvent;
 }
 
+OutputStream *
+Terminal::terminalDump(const TerminalParams* p)
+{
+    switch (p->outfile) {
+      case Enums::TerminalDump::none:
+        return nullptr;
+      case Enums::TerminalDump::stdout:
+        return simout.findOrCreate("stdout");
+      case Enums::TerminalDump::stderr:
+        return simout.findOrCreate("stderr");
+      case Enums::TerminalDump::file:
+        return simout.findOrCreate(p->name);
+      default:
+        panic("Invalid option\n");
+    }
+}
 
 ///////////////////////////////////////////////////////////////////////
 // socket creation and terminal attach
diff --git a/src/dev/serial/terminal.hh b/src/dev/serial/terminal.hh
index 9e114de..bc2ebd8 100644
--- a/src/dev/serial/terminal.hh
+++ b/src/dev/serial/terminal.hh
@@ -1,4 +1,16 @@
 /*
+ * Copyright (c) 2019 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.
+ *
  * Copyright (c) 2001-2005 The Regents of The University of Michigan
  * All rights reserved.
  *
@@ -86,6 +98,7 @@
     typedef TerminalParams Params;
     Terminal(const Params *p);
     ~Terminal();
+    OutputStream * terminalDump(const TerminalParams* p);
 
   protected:
     ListenSocket listener;