Ruby: Add support for functional accesses
[gem5.git] / configs / example / ruby_fs.py
1 # Copyright (c) 2009-2011 Advanced Micro Devices, Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met: redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer;
8 # redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 # Authors: Brad Beckmann
28
29 #
30 # Full system configuraiton for ruby
31 #
32
33 import os
34 import optparse
35 import sys
36 from os.path import join as joinpath
37
38 import m5
39 from m5.defines import buildEnv
40 from m5.objects import *
41 from m5.util import addToPath, panic
42
43 if not buildEnv['FULL_SYSTEM']:
44 panic("This script requires full-system mode (*_FS).")
45
46 addToPath('../common')
47 addToPath('../ruby')
48
49 import Ruby
50
51 from FSConfig import *
52 from SysPaths import *
53 from Benchmarks import *
54 import Simulation
55 from Caches import *
56
57 # Get paths we might need. It's expected this file is in m5/configs/example.
58 config_path = os.path.dirname(os.path.abspath(__file__))
59 config_root = os.path.dirname(config_path)
60 m5_root = os.path.dirname(config_root)
61
62 parser = optparse.OptionParser()
63
64 # Benchmark options
65 parser.add_option("-b", "--benchmark", action="store", type="string",
66 dest="benchmark",
67 help="Specify the benchmark to run. Available benchmarks: %s"\
68 % DefinedBenchmarks)
69 parser.add_option("-o", "--options", default="",
70 help='The options to pass to the binary, use " " around the entire string')
71 parser.add_option("-i", "--input", default="", help="Read stdin from a file.")
72 parser.add_option("--output", default="", help="Redirect stdout to a file.")
73 parser.add_option("--errout", default="", help="Redirect stderr to a file.")
74
75 #
76 # Add the ruby specific and protocol specific options
77 #
78 Ruby.define_options(parser)
79
80 execfile(os.path.join(config_root, "common", "Options.py"))
81
82 (options, args) = parser.parse_args()
83
84 if args:
85 print "Error: script doesn't take any positional arguments"
86 sys.exit(1)
87
88 if options.benchmark:
89 try:
90 bm = Benchmarks[options.benchmark]
91 except KeyError:
92 print "Error benchmark %s has not been defined." % options.benchmark
93 print "Valid benchmarks are: %s" % DefinedBenchmarks
94 sys.exit(1)
95 else:
96 bm = [SysConfig()]
97
98 #
99 # currently ruby fs only works in simple timing mode because ruby does not
100 # support atomic accesses by devices. Also ruby_fs currently assumes
101 # that is running a checkpoints that were created by ALPHA_FS under atomic
102 # mode. Since switch cpus are not defined in these checkpoints, we don't
103 # fast forward with the atomic cpu and instead set the FutureClass to None.
104 # Therefore the cpus resolve to the correct names and unserialize correctly.
105 #
106 class CPUClass(TimingSimpleCPU): pass
107 test_mem_mode = 'timing'
108 FutureClass = None
109
110 CPUClass.clock = options.clock
111
112 if buildEnv['TARGET_ISA'] == "alpha":
113 system = makeLinuxAlphaRubySystem(test_mem_mode, bm[0])
114 elif buildEnv['TARGET_ISA'] == "x86":
115 system = makeLinuxX86System(test_mem_mode, options.num_cpus, bm[0], True)
116 setWorkCountOptions(system, options)
117 else:
118 fatal("incapable of building non-alpha or non-x86 full system!")
119
120 Ruby.create_system(options, system, system.piobus, system._dma_devices)
121
122 system.cpu = [CPUClass(cpu_id=i) for i in xrange(options.num_cpus)]
123
124 for (i, cpu) in enumerate(system.cpu):
125 #
126 # Tie the cpu ports to the correct ruby system ports
127 #
128 cpu.icache_port = system.ruby._cpu_ruby_ports[i].port
129 cpu.dcache_port = system.ruby._cpu_ruby_ports[i].port
130 if buildEnv['TARGET_ISA'] == "x86":
131 cpu.itb.walker.port = system.ruby._cpu_ruby_ports[i].port
132 cpu.dtb.walker.port = system.ruby._cpu_ruby_ports[i].port
133 cpu.interrupts.pio = system.piobus.port
134 cpu.interrupts.int_port = system.piobus.port
135
136 root = Root(system = system)
137
138 Simulation.run(options, root, system, FutureClass)