fs.py revision 7586:da93206873dc
1# Copyright (c) 2010 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder.  You may use the software subject to the license
9# terms below provided that you ensure that this notice is replicated
10# unmodified and in its entirety in all distributions of the software,
11# modified or unmodified, in source code or in binary form.
12#
13# Copyright (c) 2006-2007 The Regents of The University of Michigan
14# All rights reserved.
15#
16# Redistribution and use in source and binary forms, with or without
17# modification, are permitted provided that the following conditions are
18# met: redistributions of source code must retain the above copyright
19# notice, this list of conditions and the following disclaimer;
20# redistributions in binary form must reproduce the above copyright
21# notice, this list of conditions and the following disclaimer in the
22# documentation and/or other materials provided with the distribution;
23# neither the name of the copyright holders nor the names of its
24# contributors may be used to endorse or promote products derived from
25# this software without specific prior written permission.
26#
27# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38#
39# Authors: Ali Saidi
40
41import optparse
42import os
43import sys
44
45import m5
46from m5.defines import buildEnv
47from m5.objects import *
48from m5.util import addToPath, fatal
49
50if not buildEnv['FULL_SYSTEM']:
51    fatal("This script requires full-system mode (*_FS).")
52
53addToPath('../common')
54
55from FSConfig import *
56from SysPaths import *
57from Benchmarks import *
58import Simulation
59import CacheConfig
60from Caches import *
61
62# Get paths we might need.  It's expected this file is in m5/configs/example.
63config_path = os.path.dirname(os.path.abspath(__file__))
64config_root = os.path.dirname(config_path)
65
66parser = optparse.OptionParser()
67
68# System options
69parser.add_option("--kernel", action="store", type="string")
70parser.add_option("--script", action="store", type="string")
71if buildEnv['TARGET_ISA'] == "arm":
72    parser.add_option("--bare-metal", action="store_true",
73               help="Provide the raw system without the linux specific bits")
74    parser.add_option("--machine-type", action="store", type="choice",
75            choices=ArmMachineType.map.keys(), default="RealView_PBX")
76# Benchmark options
77parser.add_option("--dual", action="store_true",
78                  help="Simulate two systems attached with an ethernet link")
79parser.add_option("-b", "--benchmark", action="store", type="string",
80                  dest="benchmark",
81                  help="Specify the benchmark to run. Available benchmarks: %s"\
82                  % DefinedBenchmarks)
83
84# Metafile options
85parser.add_option("--etherdump", action="store", type="string", dest="etherdump",
86                  help="Specify the filename to dump a pcap capture of the" \
87                  "ethernet traffic")
88
89execfile(os.path.join(config_root, "common", "Options.py"))
90
91(options, args) = parser.parse_args()
92
93if args:
94    print "Error: script doesn't take any positional arguments"
95    sys.exit(1)
96
97# driver system CPU is always simple... note this is an assignment of
98# a class, not an instance.
99DriveCPUClass = AtomicSimpleCPU
100drive_mem_mode = 'atomic'
101
102# system under test can be any CPU
103(TestCPUClass, test_mem_mode, FutureClass) = Simulation.setCPUClass(options)
104
105TestCPUClass.clock = '2GHz'
106DriveCPUClass.clock = '2GHz'
107
108if options.benchmark:
109    try:
110        bm = Benchmarks[options.benchmark]
111    except KeyError:
112        print "Error benchmark %s has not been defined." % options.benchmark
113        print "Valid benchmarks are: %s" % DefinedBenchmarks
114        sys.exit(1)
115else:
116    if options.dual:
117        bm = [SysConfig(), SysConfig()]
118    else:
119        bm = [SysConfig()]
120
121np = options.num_cpus
122
123if buildEnv['TARGET_ISA'] == "alpha":
124    test_sys = makeLinuxAlphaSystem(test_mem_mode, bm[0])
125elif buildEnv['TARGET_ISA'] == "mips":
126    test_sys = makeLinuxMipsSystem(test_mem_mode, bm[0])
127elif buildEnv['TARGET_ISA'] == "sparc":
128    test_sys = makeSparcSystem(test_mem_mode, bm[0])
129elif buildEnv['TARGET_ISA'] == "x86":
130    test_sys = makeLinuxX86System(test_mem_mode, np, bm[0])
131elif buildEnv['TARGET_ISA'] == "arm":
132    test_sys = makeLinuxArmSystem(test_mem_mode, bm[0],
133            bare_metal=options.bare_metal, machine_type=options.machine_type)
134else:
135    fatal("incapable of building non-alpha or non-sparc full system!")
136
137if options.kernel is not None:
138    test_sys.kernel = binary(options.kernel)
139
140if options.script is not None:
141    test_sys.readfile = options.script
142
143test_sys.cpu = [TestCPUClass(cpu_id=i) for i in xrange(np)]
144
145CacheConfig.config_cache(options, test_sys)
146
147if options.caches or options.l2cache:
148    if bm[0]:
149        mem_size = bm[0].mem()
150    else:
151        mem_size = SysConfig().mem()
152    test_sys.bridge.filter_ranges_a=[AddrRange(0, Addr.max)]
153    test_sys.bridge.filter_ranges_b=[AddrRange(mem_size)]
154    test_sys.iocache = IOCache(addr_range=mem_size)
155    test_sys.iocache.cpu_side = test_sys.iobus.port
156    test_sys.iocache.mem_side = test_sys.membus.port
157
158for i in xrange(np):
159    if options.fastmem:
160        test_sys.cpu[i].physmem_port = test_sys.physmem.port
161
162if buildEnv['TARGET_ISA'] == 'mips':
163    setMipsOptions(TestCPUClass)
164
165if len(bm) == 2:
166    if buildEnv['TARGET_ISA'] == 'alpha':
167        drive_sys = makeLinuxAlphaSystem(drive_mem_mode, bm[1])
168    elif buildEnv['TARGET_ISA'] == 'mips':
169        drive_sys = makeLinuxMipsSystem(drive_mem_mode, bm[1])
170    elif buildEnv['TARGET_ISA'] == 'sparc':
171        drive_sys = makeSparcSystem(drive_mem_mode, bm[1])
172    elif buildEnv['TARGET_ISA'] == 'x86':
173        drive_sys = makeX86System(drive_mem_mode, np, bm[1])
174    elif buildEnv['TARGET_ISA'] == 'arm':
175        drive_sys = makeLinuxArmSystem(drive_mem_mode, bm[1])
176    drive_sys.cpu = DriveCPUClass(cpu_id=0)
177    drive_sys.cpu.connectMemPorts(drive_sys.membus)
178    if options.fastmem:
179        drive_sys.cpu.physmem_port = drive_sys.physmem.port
180    if options.kernel is not None:
181        drive_sys.kernel = binary(options.kernel)
182
183    root = makeDualRoot(test_sys, drive_sys, options.etherdump)
184elif len(bm) == 1:
185    root = Root(system=test_sys)
186else:
187    print "Error I don't know how to create more than 2 systems."
188    sys.exit(1)
189
190Simulation.run(options, root, test_sys, FutureClass)
191