[gem5-dev] Change in gem5/gem5[develop]: util: Add support for multiple call types in the m5 utility.

2020-05-02 Thread Gabe Black (Gerrit) via gem5-dev
Gabe Black has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27242 )


Change subject: util: Add support for multiple call types in the m5 utility.
..

util: Add support for multiple call types in the m5 utility.

Using mechanisms added in previous CLs, this change modifies the m5
utility so that it can use any of the back ends enabled and implemented
by each variant, defaulting to one particular implementation if not is
selected explicitly.

On x86, the default mechanism is the magic address. All other variants
default to the magic instruction since they don't have a well
established address to use or even in most cases an implementation to
use.

The ability to override the particular magic address the utility wants
to use (necessary on variants such as aarch64) will be added in a future
CL.

Change-Id: I5fc414740e30759e7dde719cddcc8d5d41f8cc74
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27242
Reviewed-by: Jason Lowe-Power 
Reviewed-by: Pouya Fotouhi 
Maintainer: Gabe Black 
Tested-by: kokoro 
---
M util/m5/SConstruct
M util/m5/src/SConscript
M util/m5/src/aarch64/SConsopts
M util/m5/src/aarch64/m5op.S
A util/m5/src/aarch64/m5op_addr.S
M util/m5/src/addr_call_type.c
M util/m5/src/arm/SConsopts
M util/m5/src/m5.c
M util/m5/src/semi_call_type.c
M util/m5/src/sparc/SConsopts
M util/m5/src/thumb/SConsopts
M util/m5/src/x86/SConsopts
M util/m5/src/x86/m5op.S
A util/m5/src/x86/m5op_addr.S
14 files changed, 251 insertions(+), 98 deletions(-)

Approvals:
  Jason Lowe-Power: Looks good to me, approved
  Pouya Fotouhi: Looks good to me, but someone else must approve
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/util/m5/SConstruct b/util/m5/SConstruct
index 83d46aa..48073d2 100644
--- a/util/m5/SConstruct
+++ b/util/m5/SConstruct
@@ -23,6 +23,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+import copy
 import os

 main = Environment()
@@ -59,11 +60,34 @@
 # Use soft links instead of hard links when setting up a build directory.
 main.SetOption('duplicate', 'soft-copy')

+class CallType(object):
+def __init__(self, name):
+self.name = name
+self.impl_file = None
+self.enabled = False
+self.default = False
+
+def impl(self, impl, default=False):
+self.impl_file = impl
+self.enabled = True
+self.default = default
+
+call_types = {
+# Magic instruction.
+'inst': CallType('inst'),
+# Magic address.
+'addr': CallType('addr'),
+# Semihosting extension.
+'semi': CallType('semi'),
+}
+
 for root, dirs, files in os.walk(abspath(src_dir)):
 # Each SConsopts file describes a variant of the m5 utility.
 if 'SConsopts' in files:
 env = main.Clone()

+env['CALL_TYPE'] = copy.deepcopy(call_types)
+
 # The user may override variant settings by setting environment
 # variables of the form ${VARIANT}.${OPTION}. For instance, to set  
the
 # CROSS_COMPILE prefix for variant foo to bar-, the user would set  
an

diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript
index 392ac9e..c2a3ede 100644
--- a/util/m5/src/SConscript
+++ b/util/m5/src/SConscript
@@ -29,30 +29,47 @@

 # Raw source files.
 m5_mmap = 'm5_mmap.c'
-m5op = '${VARIANT}/m5op.S'
 m5 = 'm5.c'
 jni = 'jni_gem5Op.c'
 lua = 'lua_gem5Op.c'

+all_call_types = list(env['CALL_TYPE'].values())
+call_types = list([ ct for ct in all_call_types if ct.enabled ])
+m5ops = list([ '${VARIANT}/%s' % ct.impl_file for ct in call_types ])
+
+default_call_type = list([ ct for ct in call_types if ct.default ])
+assert len(default_call_type) == 1, \
+'There should be exactly one default call type for %s, found %d' %  
\

+(env['VARIANT'], len(default_call_type))
+default_call_type = default_call_type[0]
+
 static_env = env.Clone()
 static_env.Append(LINKFLAGS=[ '-no-pie', '-static' ])

+for ct in all_call_types:
+static_env.Append(CFLAGS='-DENABLE_CT_%s=%d' %
+(ct.name, 1 if ct.enabled else 0))
+static_env.Append(CFLAGS='-DDEFAULT_CT_%s=%d' %
+(ct.name, 1 if ct.default else 0))
+static_env.Append(CFLAGS='-DDEFAULT_CALL_TYPE=%s' % default_call_type.name)
+
 #
 # The m5 library for use in other C/C++ programs.
 #
-libm5 = static_env.StaticLibrary('out/m5', [ m5op, m5_mmap ])
+libm5 = static_env.StaticLibrary('out/m5', [ m5_mmap ] + m5ops)


 #
 # The m5 stand alone command line utility.
 #
-m5_bin = static_env.Program('out/m5', [ m5, m5_mmap, libm5 ])
+ct_support = list([ File('%s_call_type.c' % ct.name) for ct in call_types  
])

+m5_bin = static_env.Program('out/m5', ct_support + [ m5, m5_mmap, libm5 ])


 # The shared version of the m5 op call sights, used by mutliple targets  
below.

 shared_env = env.Clone()
 

[gem5-dev] Change in gem5/gem5[develop]: util: Add support for multiple call types in the m5 utility.

2020-03-27 Thread Gabe Black (Gerrit)
Gabe Black has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/27242 )



Change subject: util: Add support for multiple call types in the m5 utility.
..

util: Add support for multiple call types in the m5 utility.

Using mechanisms added in previous CLs, this change modifies the m5
utility so that it can use any of the back ends enabled and implemented
by each variant, defaulting to one particular implementation if not is
selected explicitly.

On x86, the default mechanism is the magic address. All other variants
default to the magic instruction since they don't have a well
established address to use or even in most cases an implementation to
use.

The ability to override the particular magic address the utility wants
to use (necessary on variants such as aarch64) will be added in a future
CL.

Change-Id: I5fc414740e30759e7dde719cddcc8d5d41f8cc74
---
M util/m5/SConstruct
M util/m5/src/SConscript
M util/m5/src/aarch64/SConsopts
M util/m5/src/aarch64/m5op.S
A util/m5/src/aarch64/m5op_addr.S
M util/m5/src/addr_call_type.c
M util/m5/src/arm/SConsopts
M util/m5/src/m5.c
M util/m5/src/semi_call_type.c
M util/m5/src/sparc/SConsopts
M util/m5/src/thumb/SConsopts
M util/m5/src/x86/SConsopts
M util/m5/src/x86/m5op.S
A util/m5/src/x86/m5op_addr.S
14 files changed, 221 insertions(+), 96 deletions(-)



diff --git a/util/m5/SConstruct b/util/m5/SConstruct
index 822ba7a..d007925 100644
--- a/util/m5/SConstruct
+++ b/util/m5/SConstruct
@@ -23,6 +23,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+import copy
 import os

 main = Environment()
@@ -60,11 +61,34 @@
 # Use soft links instead of hard links when setting up a build directory.
 main.SetOption('duplicate', 'soft-copy')

+class CallType(object):
+def __init__(self, name):
+self.name = name
+self.impl_file = None
+self.enabled = False
+self.default = False
+
+def impl(self, impl, default=False):
+self.impl_file = impl
+self.enabled = True
+self.default = default
+
+call_types = {
+# Magic instruction.
+'inst': CallType('inst'),
+# Magic address.
+'addr': CallType('addr'),
+# Semihosting extension.
+'semi': CallType('semi'),
+}
+
 for root, dirs, files in os.walk(abspath(src_dir)):
 # Each SConsopts file describes a variant of the m5 utility.
 if 'SConsopts' in files:
 env = main.Clone()

+env['CALL_TYPE'] = copy.deepcopy(call_types)
+
 # The user may override variant settings by setting environment
 # variables of the form ${VARIANT}.${OPTION}. For instance, to set  
the
 # CROSS_COMPILE prefix for viarant foo to bar-, the user would set  
an

diff --git a/util/m5/src/SConscript b/util/m5/src/SConscript
index e5ead1a..4ae2f6d 100644
--- a/util/m5/src/SConscript
+++ b/util/m5/src/SConscript
@@ -29,30 +29,45 @@

 # Raw source files.
 m5_mmap = 'm5_mmap.c'
-m5op = '${VARIANT}/m5op.S'
 m5 = 'm5.c'
 jni = 'jni_gem5Op.c'
 lua = 'lua_gem5Op.c'

+all_call_types = list(env['CALL_TYPE'].values())
+call_types = list([ ct for ct in all_call_types if ct.enabled ])
+m5ops = list([ '${VARIANT}/%s' % ct.impl_file for ct in call_types ])
+
+default_call_type = list([ ct for ct in call_types if ct.default ])
+assert len(default_call_type) == 1, \
+'There should be exactly one default call type for %s, found %d' %  
\

+(env['VARIANT'], len(default_call_type))
+default_call_type = default_call_type[0]
+
 static_env = env.Clone()
 static_env.Append(LINKFLAGS='-no-pie')

+for ct in all_call_types:
+static_env.Append(CFLAGS='-DENABLE_CT_%s=%d' %
+(ct.name, 1 if ct.enabled else 0))
+static_env.Append(CFLAGS='-DDEFAULT_CALL_TYPE=%s' % default_call_type.name)
+
 #
 # The m5 library for use in other C/C++ programs.
 #
-libm5 = static_env.StaticLibrary('out/m5', [ m5op, m5_mmap ])
+libm5 = static_env.StaticLibrary('out/m5', [ m5_mmap ] + m5ops)


 #
 # The m5 stand alone command line utility.
 #
-m5_bin = static_env.Program('out/m5', [ m5, m5_mmap, libm5 ])
+ct_support = list([ File('%s_call_type.c' % ct.name) for ct in call_types  
])

+m5_bin = static_env.Program('out/m5', ct_support + [ m5, m5_mmap, libm5 ])


 # The shared version of the m5 op call sights, used by mutliple targets  
below.

 shared_env = env.Clone()
 shared_env.Append(ASFLAGS='-DM5OP_PIC')
-m5op_shared = shared_env.SharedObject(m5op)
+m5op_shared = shared_env.SharedObject(m5ops)

 if env['HAVE_JAVA']:
 #
@@ -71,7 +86,7 @@
  OUT=Dir('out'), CWD=Dir('.'))
 # Set include paths to the C headers from the JDK which scons found  
for us.

 java_env.Append(CPPPATH='${JAVAINCLUDES}')
-java_env.SharedLibrary('out/gem5OpJni', [ jni, m5op_shared ])
+java_env.SharedLibrary('out/gem5OpJni', [ jni ] + m5op_shared)