FSConfig.py revision 8919:c1366a30d5eb
19651SAndreas.Sandberg@ARM.com# Copyright (c) 2010-2012 ARM Limited
29651SAndreas.Sandberg@ARM.com# All rights reserved.
39651SAndreas.Sandberg@ARM.com#
49651SAndreas.Sandberg@ARM.com# The license below extends only to copyright in the software and shall
59651SAndreas.Sandberg@ARM.com# not be construed as granting a license to any other intellectual
69651SAndreas.Sandberg@ARM.com# property including but not limited to intellectual property relating
79651SAndreas.Sandberg@ARM.com# to a hardware implementation of the functionality of the software
89651SAndreas.Sandberg@ARM.com# licensed hereunder.  You may use the software subject to the license
99651SAndreas.Sandberg@ARM.com# terms below provided that you ensure that this notice is replicated
109651SAndreas.Sandberg@ARM.com# unmodified and in its entirety in all distributions of the software,
119651SAndreas.Sandberg@ARM.com# modified or unmodified, in source code or in binary form.
129651SAndreas.Sandberg@ARM.com#
139651SAndreas.Sandberg@ARM.com# Copyright (c) 2010-2011 Advanced Micro Devices, Inc.
149651SAndreas.Sandberg@ARM.com# Copyright (c) 2006-2008 The Regents of The University of Michigan
159651SAndreas.Sandberg@ARM.com# All rights reserved.
169651SAndreas.Sandberg@ARM.com#
179651SAndreas.Sandberg@ARM.com# Redistribution and use in source and binary forms, with or without
189651SAndreas.Sandberg@ARM.com# modification, are permitted provided that the following conditions are
199651SAndreas.Sandberg@ARM.com# met: redistributions of source code must retain the above copyright
209651SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer;
219651SAndreas.Sandberg@ARM.com# redistributions in binary form must reproduce the above copyright
229651SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer in the
239651SAndreas.Sandberg@ARM.com# documentation and/or other materials provided with the distribution;
249651SAndreas.Sandberg@ARM.com# neither the name of the copyright holders nor the names of its
259651SAndreas.Sandberg@ARM.com# contributors may be used to endorse or promote products derived from
269651SAndreas.Sandberg@ARM.com# this software without specific prior written permission.
279651SAndreas.Sandberg@ARM.com#
289651SAndreas.Sandberg@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
299651SAndreas.Sandberg@ARM.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
309651SAndreas.Sandberg@ARM.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
319651SAndreas.Sandberg@ARM.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
329651SAndreas.Sandberg@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
339651SAndreas.Sandberg@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
349651SAndreas.Sandberg@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
359651SAndreas.Sandberg@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
369651SAndreas.Sandberg@ARM.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
379651SAndreas.Sandberg@ARM.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
389651SAndreas.Sandberg@ARM.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
399651SAndreas.Sandberg@ARM.com#
409651SAndreas.Sandberg@ARM.com# Authors: Kevin Lim
419651SAndreas.Sandberg@ARM.com
429651SAndreas.Sandberg@ARM.comfrom m5.objects import *
439651SAndreas.Sandberg@ARM.comfrom Benchmarks import *
449651SAndreas.Sandberg@ARM.comfrom m5.util import convert
459651SAndreas.Sandberg@ARM.com
469651SAndreas.Sandberg@ARM.comclass CowIdeDisk(IdeDisk):
479651SAndreas.Sandberg@ARM.com    image = CowDiskImage(child=RawDiskImage(read_only=True),
489651SAndreas.Sandberg@ARM.com                         read_only=False)
499651SAndreas.Sandberg@ARM.com
509651SAndreas.Sandberg@ARM.com    def childImage(self, ci):
519651SAndreas.Sandberg@ARM.com        self.image.child.image_file = ci
529651SAndreas.Sandberg@ARM.com
539651SAndreas.Sandberg@ARM.comclass MemBus(Bus):
549651SAndreas.Sandberg@ARM.com    badaddr_responder = BadAddr()
559651SAndreas.Sandberg@ARM.com    default = Self.badaddr_responder.pio
569651SAndreas.Sandberg@ARM.com
579651SAndreas.Sandberg@ARM.com
589651SAndreas.Sandberg@ARM.comdef makeLinuxAlphaSystem(mem_mode, mdesc = None):
599651SAndreas.Sandberg@ARM.com    IO_address_space_base = 0x80000000000
609651SAndreas.Sandberg@ARM.com    class BaseTsunami(Tsunami):
619651SAndreas.Sandberg@ARM.com        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
629651SAndreas.Sandberg@ARM.com        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
639651SAndreas.Sandberg@ARM.com                            pci_func=0, pci_dev=0, pci_bus=0)
649651SAndreas.Sandberg@ARM.com
659651SAndreas.Sandberg@ARM.com    self = LinuxAlphaSystem()
669651SAndreas.Sandberg@ARM.com    if not mdesc:
679651SAndreas.Sandberg@ARM.com        # generic system
689651SAndreas.Sandberg@ARM.com        mdesc = SysConfig()
699651SAndreas.Sandberg@ARM.com    self.readfile = mdesc.script()
709651SAndreas.Sandberg@ARM.com    self.iobus = Bus(bus_id=0)
719651SAndreas.Sandberg@ARM.com    self.membus = MemBus(bus_id=1)
729651SAndreas.Sandberg@ARM.com    # By default the bridge responds to all addresses above the I/O
739651SAndreas.Sandberg@ARM.com    # base address (including the PCI config space)
749651SAndreas.Sandberg@ARM.com    self.bridge = Bridge(delay='50ns', nack_delay='4ns',
759651SAndreas.Sandberg@ARM.com                         ranges = [AddrRange(IO_address_space_base, Addr.max)])
769651SAndreas.Sandberg@ARM.com    self.physmem = PhysicalMemory(range = AddrRange(mdesc.mem()))
779651SAndreas.Sandberg@ARM.com    self.bridge.master = self.iobus.slave
789651SAndreas.Sandberg@ARM.com    self.bridge.slave = self.membus.master
799651SAndreas.Sandberg@ARM.com    self.physmem.port = self.membus.master
809651SAndreas.Sandberg@ARM.com    self.disk0 = CowIdeDisk(driveID='master')
819651SAndreas.Sandberg@ARM.com    self.disk2 = CowIdeDisk(driveID='master')
829651SAndreas.Sandberg@ARM.com    self.disk0.childImage(mdesc.disk())
839651SAndreas.Sandberg@ARM.com    self.disk2.childImage(disk('linux-bigswap2.img'))
849651SAndreas.Sandberg@ARM.com    self.tsunami = BaseTsunami()
859651SAndreas.Sandberg@ARM.com    self.tsunami.attachIO(self.iobus)
869651SAndreas.Sandberg@ARM.com    self.tsunami.ide.pio = self.iobus.master
879651SAndreas.Sandberg@ARM.com    self.tsunami.ide.config = self.iobus.master
889651SAndreas.Sandberg@ARM.com    self.tsunami.ide.dma = self.iobus.slave
899651SAndreas.Sandberg@ARM.com    self.tsunami.ethernet.pio = self.iobus.master
909651SAndreas.Sandberg@ARM.com    self.tsunami.ethernet.config = self.iobus.master
919651SAndreas.Sandberg@ARM.com    self.tsunami.ethernet.dma = self.iobus.slave
929651SAndreas.Sandberg@ARM.com    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
939651SAndreas.Sandberg@ARM.com                                               read_only = True))
949651SAndreas.Sandberg@ARM.com    self.intrctrl = IntrControl()
959651SAndreas.Sandberg@ARM.com    self.mem_mode = mem_mode
969651SAndreas.Sandberg@ARM.com    self.terminal = Terminal()
979651SAndreas.Sandberg@ARM.com    self.kernel = binary('vmlinux')
989651SAndreas.Sandberg@ARM.com    self.pal = binary('ts_osfpal')
999651SAndreas.Sandberg@ARM.com    self.console = binary('console')
1009651SAndreas.Sandberg@ARM.com    self.boot_osflags = 'root=/dev/hda1 console=ttyS0'
1019651SAndreas.Sandberg@ARM.com
1029651SAndreas.Sandberg@ARM.com    self.system_port = self.membus.slave
1039651SAndreas.Sandberg@ARM.com
1049651SAndreas.Sandberg@ARM.com    return self
1059651SAndreas.Sandberg@ARM.com
1069651SAndreas.Sandberg@ARM.comdef makeLinuxAlphaRubySystem(mem_mode, mdesc = None):
1079651SAndreas.Sandberg@ARM.com    class BaseTsunami(Tsunami):
1089651SAndreas.Sandberg@ARM.com        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
1099651SAndreas.Sandberg@ARM.com        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
1109651SAndreas.Sandberg@ARM.com                            pci_func=0, pci_dev=0, pci_bus=0)
1119651SAndreas.Sandberg@ARM.com
1129651SAndreas.Sandberg@ARM.com    physmem = PhysicalMemory(range = AddrRange(mdesc.mem()))
1139651SAndreas.Sandberg@ARM.com    self = LinuxAlphaSystem(physmem = physmem)
1149651SAndreas.Sandberg@ARM.com    if not mdesc:
1159651SAndreas.Sandberg@ARM.com        # generic system
1169651SAndreas.Sandberg@ARM.com        mdesc = SysConfig()
1179651SAndreas.Sandberg@ARM.com    self.readfile = mdesc.script()
1189651SAndreas.Sandberg@ARM.com
1199651SAndreas.Sandberg@ARM.com    # Create pio bus to connect all device pio ports to rubymem's pio port
1209651SAndreas.Sandberg@ARM.com    self.piobus = Bus(bus_id=0)
1219651SAndreas.Sandberg@ARM.com
1229651SAndreas.Sandberg@ARM.com    #
1239651SAndreas.Sandberg@ARM.com    # Pio functional accesses from devices need direct access to memory
1249651SAndreas.Sandberg@ARM.com    # RubyPort currently does support functional accesses.  Therefore provide
1259651SAndreas.Sandberg@ARM.com    # the piobus a direct connection to physical memory
1269651SAndreas.Sandberg@ARM.com    #
1279651SAndreas.Sandberg@ARM.com    self.piobus.master = physmem.port
1289651SAndreas.Sandberg@ARM.com
1299651SAndreas.Sandberg@ARM.com    self.disk0 = CowIdeDisk(driveID='master')
1309651SAndreas.Sandberg@ARM.com    self.disk2 = CowIdeDisk(driveID='master')
1319651SAndreas.Sandberg@ARM.com    self.disk0.childImage(mdesc.disk())
1329651SAndreas.Sandberg@ARM.com    self.disk2.childImage(disk('linux-bigswap2.img'))
1339651SAndreas.Sandberg@ARM.com    self.tsunami = BaseTsunami()
1349651SAndreas.Sandberg@ARM.com    self.tsunami.attachIO(self.piobus)
1359651SAndreas.Sandberg@ARM.com    self.tsunami.ide.pio = self.piobus.master
1369651SAndreas.Sandberg@ARM.com    self.tsunami.ide.config = self.piobus.master
1379651SAndreas.Sandberg@ARM.com    self.tsunami.ide.dma = self.piobus.slave
1389651SAndreas.Sandberg@ARM.com    self.tsunami.ethernet.pio = self.piobus.master
1399651SAndreas.Sandberg@ARM.com    self.tsunami.ethernet.config = self.piobus.master
1409651SAndreas.Sandberg@ARM.com    self.tsunami.ethernet.dma = self.piobus.slave
1419651SAndreas.Sandberg@ARM.com
1429651SAndreas.Sandberg@ARM.com    #
1439651SAndreas.Sandberg@ARM.com    # Store the dma devices for later connection to dma ruby ports.
1449651SAndreas.Sandberg@ARM.com    # Append an underscore to dma_devices to avoid the SimObjectVector check.
1459651SAndreas.Sandberg@ARM.com    #
1469651SAndreas.Sandberg@ARM.com    self._dma_devices = [self.tsunami.ide, self.tsunami.ethernet]
1479651SAndreas.Sandberg@ARM.com
1489651SAndreas.Sandberg@ARM.com    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
1499651SAndreas.Sandberg@ARM.com                                               read_only = True))
1509651SAndreas.Sandberg@ARM.com    self.intrctrl = IntrControl()
1519651SAndreas.Sandberg@ARM.com    self.mem_mode = mem_mode
1529651SAndreas.Sandberg@ARM.com    self.terminal = Terminal()
1539651SAndreas.Sandberg@ARM.com    self.kernel = binary('vmlinux')
1549651SAndreas.Sandberg@ARM.com    self.pal = binary('ts_osfpal')
1559651SAndreas.Sandberg@ARM.com    self.console = binary('console')
1569651SAndreas.Sandberg@ARM.com    self.boot_osflags = 'root=/dev/hda1 console=ttyS0'
1579651SAndreas.Sandberg@ARM.com
1589651SAndreas.Sandberg@ARM.com    return self
1599651SAndreas.Sandberg@ARM.com
1609651SAndreas.Sandberg@ARM.comdef makeSparcSystem(mem_mode, mdesc = None):
1619651SAndreas.Sandberg@ARM.com    # Constants from iob.cc and uart8250.cc
1629651SAndreas.Sandberg@ARM.com    iob_man_addr = 0x9800000000
1639651SAndreas.Sandberg@ARM.com    uart_pio_size = 8
1649651SAndreas.Sandberg@ARM.com
1659651SAndreas.Sandberg@ARM.com    class CowMmDisk(MmDisk):
1669651SAndreas.Sandberg@ARM.com        image = CowDiskImage(child=RawDiskImage(read_only=True),
1679651SAndreas.Sandberg@ARM.com                             read_only=False)
1689651SAndreas.Sandberg@ARM.com
1699651SAndreas.Sandberg@ARM.com        def childImage(self, ci):
1709651SAndreas.Sandberg@ARM.com            self.image.child.image_file = ci
1719651SAndreas.Sandberg@ARM.com
1729651SAndreas.Sandberg@ARM.com    self = SparcSystem()
1739651SAndreas.Sandberg@ARM.com    if not mdesc:
1749651SAndreas.Sandberg@ARM.com        # generic system
1759651SAndreas.Sandberg@ARM.com        mdesc = SysConfig()
1769651SAndreas.Sandberg@ARM.com    self.readfile = mdesc.script()
1779651SAndreas.Sandberg@ARM.com    self.iobus = Bus(bus_id=0)
1789651SAndreas.Sandberg@ARM.com    self.membus = MemBus(bus_id=1)
1799651SAndreas.Sandberg@ARM.com    self.bridge = Bridge(delay='50ns', nack_delay='4ns')
1809651SAndreas.Sandberg@ARM.com    self.t1000 = T1000()
1819651SAndreas.Sandberg@ARM.com    self.t1000.attachOnChipIO(self.membus)
1829651SAndreas.Sandberg@ARM.com    self.t1000.attachIO(self.iobus)
1839651SAndreas.Sandberg@ARM.com    self.physmem = PhysicalMemory(range = AddrRange(Addr('1MB'), size = '64MB'), zero = True)
1849651SAndreas.Sandberg@ARM.com    self.physmem2 = PhysicalMemory(range = AddrRange(Addr('2GB'), size ='256MB'), zero = True)
1859651SAndreas.Sandberg@ARM.com    self.bridge.master = self.iobus.slave
1869651SAndreas.Sandberg@ARM.com    self.bridge.slave = self.membus.master
1879651SAndreas.Sandberg@ARM.com    self.physmem.port = self.membus.master
1889651SAndreas.Sandberg@ARM.com    self.physmem2.port = self.membus.master
1899651SAndreas.Sandberg@ARM.com    self.rom.port = self.membus.master
1909651SAndreas.Sandberg@ARM.com    self.nvram.port = self.membus.master
1919651SAndreas.Sandberg@ARM.com    self.hypervisor_desc.port = self.membus.master
1929651SAndreas.Sandberg@ARM.com    self.partition_desc.port = self.membus.master
1939651SAndreas.Sandberg@ARM.com    self.intrctrl = IntrControl()
1949651SAndreas.Sandberg@ARM.com    self.disk0 = CowMmDisk()
1959651SAndreas.Sandberg@ARM.com    self.disk0.childImage(disk('disk.s10hw2'))
1969651SAndreas.Sandberg@ARM.com    self.disk0.pio = self.iobus.master
1979651SAndreas.Sandberg@ARM.com
1989651SAndreas.Sandberg@ARM.com    # The puart0 and hvuart are placed on the IO bus, so create ranges
1999651SAndreas.Sandberg@ARM.com    # for them. The remaining IO range is rather fragmented, so poke
2009651SAndreas.Sandberg@ARM.com    # holes for the iob and partition descriptors etc.
2019651SAndreas.Sandberg@ARM.com    self.bridge.ranges = \
2029651SAndreas.Sandberg@ARM.com        [
2039651SAndreas.Sandberg@ARM.com        AddrRange(self.t1000.puart0.pio_addr,
2049651SAndreas.Sandberg@ARM.com                  self.t1000.puart0.pio_addr + uart_pio_size - 1),
2059651SAndreas.Sandberg@ARM.com        AddrRange(self.disk0.pio_addr,
2069651SAndreas.Sandberg@ARM.com                  self.t1000.fake_jbi.pio_addr +
2079651SAndreas.Sandberg@ARM.com                  self.t1000.fake_jbi.pio_size - 1),
2089651SAndreas.Sandberg@ARM.com        AddrRange(self.t1000.fake_clk.pio_addr,
2099651SAndreas.Sandberg@ARM.com                  iob_man_addr - 1),
2109651SAndreas.Sandberg@ARM.com        AddrRange(self.t1000.fake_l2_1.pio_addr,
2119651SAndreas.Sandberg@ARM.com                  self.t1000.fake_ssi.pio_addr +
2129651SAndreas.Sandberg@ARM.com                  self.t1000.fake_ssi.pio_size - 1),
2139651SAndreas.Sandberg@ARM.com        AddrRange(self.t1000.hvuart.pio_addr,
2149651SAndreas.Sandberg@ARM.com                  self.t1000.hvuart.pio_addr + uart_pio_size - 1)
2159651SAndreas.Sandberg@ARM.com        ]
2169651SAndreas.Sandberg@ARM.com    self.reset_bin = binary('reset_new.bin')
2179651SAndreas.Sandberg@ARM.com    self.hypervisor_bin = binary('q_new.bin')
2189651SAndreas.Sandberg@ARM.com    self.openboot_bin = binary('openboot_new.bin')
2199651SAndreas.Sandberg@ARM.com    self.nvram_bin = binary('nvram1')
2209651SAndreas.Sandberg@ARM.com    self.hypervisor_desc_bin = binary('1up-hv.bin')
2219651SAndreas.Sandberg@ARM.com    self.partition_desc_bin = binary('1up-md.bin')
2229651SAndreas.Sandberg@ARM.com
2239651SAndreas.Sandberg@ARM.com    self.system_port = self.membus.slave
2249651SAndreas.Sandberg@ARM.com
2259651SAndreas.Sandberg@ARM.com    return self
2269651SAndreas.Sandberg@ARM.com
2279651SAndreas.Sandberg@ARM.comdef makeArmSystem(mem_mode, machine_type, mdesc = None, bare_metal=False):
2289651SAndreas.Sandberg@ARM.com    assert machine_type
2299651SAndreas.Sandberg@ARM.com
2309651SAndreas.Sandberg@ARM.com    if bare_metal:
2319651SAndreas.Sandberg@ARM.com        self = ArmSystem()
2329651SAndreas.Sandberg@ARM.com    else:
2339651SAndreas.Sandberg@ARM.com        self = LinuxArmSystem()
2349651SAndreas.Sandberg@ARM.com
2359651SAndreas.Sandberg@ARM.com    if not mdesc:
2369651SAndreas.Sandberg@ARM.com        # generic system
2379651SAndreas.Sandberg@ARM.com        mdesc = SysConfig()
2389651SAndreas.Sandberg@ARM.com
2399651SAndreas.Sandberg@ARM.com    self.readfile = mdesc.script()
2409651SAndreas.Sandberg@ARM.com    self.iobus = Bus(bus_id=0)
2419651SAndreas.Sandberg@ARM.com    self.membus = MemBus(bus_id=1)
2429651SAndreas.Sandberg@ARM.com    self.membus.badaddr_responder.warn_access = "warn"
2439651SAndreas.Sandberg@ARM.com    self.bridge = Bridge(delay='50ns', nack_delay='4ns')
2449651SAndreas.Sandberg@ARM.com    self.bridge.master = self.iobus.slave
24511321Ssteve.reinhardt@amd.com    self.bridge.slave = self.membus.master
2469651SAndreas.Sandberg@ARM.com
247    self.mem_mode = mem_mode
248
249    if machine_type == "RealView_PBX":
250        self.realview = RealViewPBX()
251    elif machine_type == "RealView_EB":
252        self.realview = RealViewEB()
253    elif machine_type == "VExpress_ELT":
254        self.realview = VExpress_ELT()
255    elif machine_type == "VExpress_EMM":
256        self.realview = VExpress_EMM()
257        self.load_addr_mask = 0xffffffff
258    else:
259        print "Unknown Machine Type"
260        sys.exit(1)
261
262    self.cf0 = CowIdeDisk(driveID='master')
263    self.cf0.childImage(mdesc.disk())
264    # default to an IDE controller rather than a CF one
265    # assuming we've got one
266    try:
267        self.realview.ide.disks = [self.cf0]
268    except:
269        self.realview.cf_ctrl.disks = [self.cf0]
270
271    if bare_metal:
272        # EOT character on UART will end the simulation
273        self.realview.uart.end_on_eot = True
274        self.physmem = PhysicalMemory(range = AddrRange(Addr(mdesc.mem())),
275                                      zero = True)
276    else:
277        self.kernel = binary('vmlinux.arm.smp.fb.2.6.38.8')
278        self.machine_type = machine_type
279        if convert.toMemorySize(mdesc.mem()) > int(self.realview.max_mem_size):
280            print "The currently selected ARM platforms doesn't support"
281            print " the amount of DRAM you've selected. Please try"
282            print " another platform"
283            sys.exit(1)
284
285        boot_flags = 'earlyprintk console=ttyAMA0 lpj=19988480 norandmaps ' + \
286                     'rw loglevel=8 mem=%s root=/dev/sda1' % mdesc.mem()
287
288        self.physmem = PhysicalMemory(range = AddrRange(self.realview.mem_start_addr,
289                                                        size = mdesc.mem()))
290        self.realview.setupBootLoader(self.membus, self, binary)
291        self.gic_cpu_addr = self.realview.gic.cpu_addr
292        self.flags_addr = self.realview.realview_io.pio_addr + 0x30
293
294        if mdesc.disk().lower().count('android'):
295            boot_flags += " init=/init "
296        self.boot_osflags = boot_flags
297
298    self.physmem.port = self.membus.master
299    self.realview.attachOnChipIO(self.membus, self.bridge)
300    self.realview.attachIO(self.iobus)
301    self.intrctrl = IntrControl()
302    self.terminal = Terminal()
303    self.vncserver = VncServer()
304
305    self.system_port = self.membus.slave
306
307    return self
308
309
310def makeLinuxMipsSystem(mem_mode, mdesc = None):
311    class BaseMalta(Malta):
312        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
313        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
314                            pci_func=0, pci_dev=0, pci_bus=0)
315
316    self = LinuxMipsSystem()
317    if not mdesc:
318        # generic system
319        mdesc = SysConfig()
320    self.readfile = mdesc.script()
321    self.iobus = Bus(bus_id=0)
322    self.membus = MemBus(bus_id=1)
323    self.bridge = Bridge(delay='50ns', nack_delay='4ns')
324    self.physmem = PhysicalMemory(range = AddrRange('1GB'))
325    self.bridge.master = self.iobus.slave
326    self.bridge.slave = self.membus.master
327    self.physmem.port = self.membus.master
328    self.disk0 = CowIdeDisk(driveID='master')
329    self.disk2 = CowIdeDisk(driveID='master')
330    self.disk0.childImage(mdesc.disk())
331    self.disk2.childImage(disk('linux-bigswap2.img'))
332    self.malta = BaseMalta()
333    self.malta.attachIO(self.iobus)
334    self.malta.ide.pio = self.iobus.master
335    self.malta.ide.config = self.iobus.master
336    self.malta.ide.dma = self.iobus.slave
337    self.malta.ethernet.pio = self.iobus.master
338    self.malta.ethernet.config = self.iobus.master
339    self.malta.ethernet.dma = self.iobus.slave
340    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
341                                               read_only = True))
342    self.intrctrl = IntrControl()
343    self.mem_mode = mem_mode
344    self.terminal = Terminal()
345    self.kernel = binary('mips/vmlinux')
346    self.console = binary('mips/console')
347    self.boot_osflags = 'root=/dev/hda1 console=ttyS0'
348
349    self.system_port = self.membus.slave
350
351    return self
352
353def x86IOAddress(port):
354    IO_address_space_base = 0x8000000000000000
355    return IO_address_space_base + port
356
357def connectX86ClassicSystem(x86_sys, numCPUs):
358    # Constants similar to x86_traits.hh
359    IO_address_space_base = 0x8000000000000000
360    pci_config_address_space_base = 0xc000000000000000
361    interrupts_address_space_base = 0xa000000000000000
362    APIC_range_size = 1 << 12;
363
364    x86_sys.membus = MemBus(bus_id=1)
365    x86_sys.physmem.port = x86_sys.membus.master
366
367    # North Bridge
368    x86_sys.iobus = Bus(bus_id=0)
369    x86_sys.bridge = Bridge(delay='50ns', nack_delay='4ns')
370    x86_sys.bridge.master = x86_sys.iobus.slave
371    x86_sys.bridge.slave = x86_sys.membus.master
372    # Allow the bridge to pass through the IO APIC (two pages),
373    # everything in the IO address range up to the local APIC, and
374    # then the entire PCI address space and beyond
375    x86_sys.bridge.ranges = \
376        [
377        AddrRange(x86_sys.pc.south_bridge.io_apic.pio_addr,
378                  x86_sys.pc.south_bridge.io_apic.pio_addr +
379                  APIC_range_size - 1),
380        AddrRange(IO_address_space_base,
381                  interrupts_address_space_base - 1),
382        AddrRange(pci_config_address_space_base,
383                  Addr.max)
384        ]
385
386    # Create a bridge from the IO bus to the memory bus to allow access to
387    # the local APIC (two pages)
388    x86_sys.apicbridge = Bridge(delay='50ns', nack_delay='4ns')
389    x86_sys.apicbridge.slave = x86_sys.iobus.master
390    x86_sys.apicbridge.master = x86_sys.membus.slave
391    x86_sys.apicbridge.ranges = [AddrRange(interrupts_address_space_base,
392                                           interrupts_address_space_base +
393                                           numCPUs * APIC_range_size
394                                           - 1)]
395
396    # connect the io bus
397    x86_sys.pc.attachIO(x86_sys.iobus)
398
399    x86_sys.system_port = x86_sys.membus.slave
400
401def connectX86RubySystem(x86_sys):
402    # North Bridge
403    x86_sys.piobus = Bus(bus_id=0)
404
405    #
406    # Pio functional accesses from devices need direct access to memory
407    # RubyPort currently does support functional accesses.  Therefore provide
408    # the piobus a direct connection to physical memory
409    #
410    x86_sys.piobus.master = x86_sys.physmem.port
411
412    x86_sys.pc.attachIO(x86_sys.piobus)
413
414
415def makeX86System(mem_mode, numCPUs = 1, mdesc = None, self = None, Ruby = False):
416    if self == None:
417        self = X86System()
418
419    if not mdesc:
420        # generic system
421        mdesc = SysConfig()
422    self.readfile = mdesc.script()
423
424    self.mem_mode = mem_mode
425
426    # Physical memory
427    self.physmem = PhysicalMemory(range = AddrRange(mdesc.mem()))
428
429    # Platform
430    self.pc = Pc()
431
432    # Create and connect the busses required by each memory system
433    if Ruby:
434        connectX86RubySystem(self)
435        # add the ide to the list of dma devices that later need to attach to
436        # dma controllers
437        self._dma_devices = [self.pc.south_bridge.ide]
438    else:
439        connectX86ClassicSystem(self, numCPUs)
440
441    self.intrctrl = IntrControl()
442
443    # Disks
444    disk0 = CowIdeDisk(driveID='master')
445    disk2 = CowIdeDisk(driveID='master')
446    disk0.childImage(mdesc.disk())
447    disk2.childImage(disk('linux-bigswap2.img'))
448    self.pc.south_bridge.ide.disks = [disk0, disk2]
449
450    # Add in a Bios information structure.
451    structures = [X86SMBiosBiosInformation()]
452    self.smbios_table.structures = structures
453
454    # Set up the Intel MP table
455    base_entries = []
456    ext_entries = []
457    for i in xrange(numCPUs):
458        bp = X86IntelMPProcessor(
459                local_apic_id = i,
460                local_apic_version = 0x14,
461                enable = True,
462                bootstrap = (i == 0))
463        base_entries.append(bp)
464    io_apic = X86IntelMPIOAPIC(
465            id = numCPUs,
466            version = 0x11,
467            enable = True,
468            address = 0xfec00000)
469    self.pc.south_bridge.io_apic.apic_id = io_apic.id
470    base_entries.append(io_apic)
471    isa_bus = X86IntelMPBus(bus_id = 0, bus_type='ISA')
472    base_entries.append(isa_bus)
473    pci_bus = X86IntelMPBus(bus_id = 1, bus_type='PCI')
474    base_entries.append(pci_bus)
475    connect_busses = X86IntelMPBusHierarchy(bus_id=0,
476            subtractive_decode=True, parent_bus=1)
477    ext_entries.append(connect_busses)
478    pci_dev4_inta = X86IntelMPIOIntAssignment(
479            interrupt_type = 'INT',
480            polarity = 'ConformPolarity',
481            trigger = 'ConformTrigger',
482            source_bus_id = 1,
483            source_bus_irq = 0 + (4 << 2),
484            dest_io_apic_id = io_apic.id,
485            dest_io_apic_intin = 16)
486    base_entries.append(pci_dev4_inta)
487    def assignISAInt(irq, apicPin):
488        assign_8259_to_apic = X86IntelMPIOIntAssignment(
489                interrupt_type = 'ExtInt',
490                polarity = 'ConformPolarity',
491                trigger = 'ConformTrigger',
492                source_bus_id = 0,
493                source_bus_irq = irq,
494                dest_io_apic_id = io_apic.id,
495                dest_io_apic_intin = 0)
496        base_entries.append(assign_8259_to_apic)
497        assign_to_apic = X86IntelMPIOIntAssignment(
498                interrupt_type = 'INT',
499                polarity = 'ConformPolarity',
500                trigger = 'ConformTrigger',
501                source_bus_id = 0,
502                source_bus_irq = irq,
503                dest_io_apic_id = io_apic.id,
504                dest_io_apic_intin = apicPin)
505        base_entries.append(assign_to_apic)
506    assignISAInt(0, 2)
507    assignISAInt(1, 1)
508    for i in range(3, 15):
509        assignISAInt(i, i)
510    self.intel_mp_table.base_entries = base_entries
511    self.intel_mp_table.ext_entries = ext_entries
512
513def makeLinuxX86System(mem_mode, numCPUs = 1, mdesc = None, Ruby = False):
514    self = LinuxX86System()
515
516    # Build up the x86 system and then specialize it for Linux
517    makeX86System(mem_mode, numCPUs, mdesc, self, Ruby)
518
519    # We assume below that there's at least 1MB of memory. We'll require 2
520    # just to avoid corner cases.
521    assert(self.physmem.range.second.getValue() >= 0x200000)
522
523    self.e820_table.entries = \
524       [
525        # Mark the first megabyte of memory as reserved
526        X86E820Entry(addr = 0, size = '1MB', range_type = 2),
527        # Mark the rest as available
528        X86E820Entry(addr = 0x100000,
529                size = '%dB' % (self.physmem.range.second - 0x100000 + 1),
530                range_type = 1)
531        ]
532
533    # Command line
534    self.boot_osflags = 'earlyprintk=ttyS0 console=ttyS0 lpj=7999923 ' + \
535                        'root=/dev/hda1'
536    return self
537
538
539def makeDualRoot(full_system, testSystem, driveSystem, dumpfile):
540    self = Root(full_system = full_system)
541    self.testsys = testSystem
542    self.drivesys = driveSystem
543    self.etherlink = EtherLink()
544    self.etherlink.int0 = Parent.testsys.tsunami.ethernet.interface
545    self.etherlink.int1 = Parent.drivesys.tsunami.ethernet.interface
546
547    if hasattr(testSystem, 'realview'):
548        self.etherlink.int0 = Parent.testsys.realview.ethernet.interface
549        self.etherlink.int1 = Parent.drivesys.realview.ethernet.interface
550    elif hasattr(testSystem, 'tsunami'):
551        self.etherlink.int0 = Parent.testsys.tsunami.ethernet.interface
552        self.etherlink.int1 = Parent.drivesys.tsunami.ethernet.interface
553    else:
554        fatal("Don't know how to connect these system together")
555
556    if dumpfile:
557        self.etherdump = EtherDump(file=dumpfile)
558        self.etherlink.dump = Parent.etherdump
559
560    return self
561
562def setMipsOptions(TestCPUClass):
563        #CP0 Configuration
564        TestCPUClass.CoreParams.CP0_PRId_CompanyOptions = 0
565        TestCPUClass.CoreParams.CP0_PRId_CompanyID = 1
566        TestCPUClass.CoreParams.CP0_PRId_ProcessorID = 147
567        TestCPUClass.CoreParams.CP0_PRId_Revision = 0
568
569        #CP0 Interrupt Control
570        TestCPUClass.CoreParams.CP0_IntCtl_IPTI = 7
571        TestCPUClass.CoreParams.CP0_IntCtl_IPPCI = 7
572
573        # Config Register
574        #TestCPUClass.CoreParams.CP0_Config_K23 = 0 # Since TLB
575        #TestCPUClass.CoreParams.CP0_Config_KU = 0 # Since TLB
576        TestCPUClass.CoreParams.CP0_Config_BE = 0 # Little Endian
577        TestCPUClass.CoreParams.CP0_Config_AR = 1 # Architecture Revision 2
578        TestCPUClass.CoreParams.CP0_Config_AT = 0 # MIPS32
579        TestCPUClass.CoreParams.CP0_Config_MT = 1 # TLB MMU
580        #TestCPUClass.CoreParams.CP0_Config_K0 = 2 # Uncached
581
582        #Config 1 Register
583        TestCPUClass.CoreParams.CP0_Config1_M = 1 # Config2 Implemented
584        TestCPUClass.CoreParams.CP0_Config1_MMU = 63 # TLB Size
585        # ***VERY IMPORTANT***
586        # Remember to modify CP0_Config1 according to cache specs
587        # Examine file ../common/Cache.py
588        TestCPUClass.CoreParams.CP0_Config1_IS = 1 # I-Cache Sets Per Way, 16KB cache, i.e., 1 (128)
589        TestCPUClass.CoreParams.CP0_Config1_IL = 5 # I-Cache Line Size, default in Cache.py is 64, i.e 5
590        TestCPUClass.CoreParams.CP0_Config1_IA = 1 # I-Cache Associativity, default in Cache.py is 2, i.e, a value of 1
591        TestCPUClass.CoreParams.CP0_Config1_DS = 2 # D-Cache Sets Per Way (see below), 32KB cache, i.e., 2
592        TestCPUClass.CoreParams.CP0_Config1_DL = 5 # D-Cache Line Size, default is 64, i.e., 5
593        TestCPUClass.CoreParams.CP0_Config1_DA = 1 # D-Cache Associativity, default is 2, i.e. 1
594        TestCPUClass.CoreParams.CP0_Config1_C2 = 0 # Coprocessor 2 not implemented(?)
595        TestCPUClass.CoreParams.CP0_Config1_MD = 0 # MDMX ASE not implemented in Mips32
596        TestCPUClass.CoreParams.CP0_Config1_PC = 1 # Performance Counters Implemented
597        TestCPUClass.CoreParams.CP0_Config1_WR = 0 # Watch Registers Implemented
598        TestCPUClass.CoreParams.CP0_Config1_CA = 0 # Mips16e NOT implemented
599        TestCPUClass.CoreParams.CP0_Config1_EP = 0 # EJTag Not Implemented
600        TestCPUClass.CoreParams.CP0_Config1_FP = 0 # FPU Implemented
601
602        #Config 2 Register
603        TestCPUClass.CoreParams.CP0_Config2_M = 1 # Config3 Implemented
604        TestCPUClass.CoreParams.CP0_Config2_TU = 0 # Tertiary Cache Control
605        TestCPUClass.CoreParams.CP0_Config2_TS = 0 # Tertiary Cache Sets Per Way
606        TestCPUClass.CoreParams.CP0_Config2_TL = 0 # Tertiary Cache Line Size
607        TestCPUClass.CoreParams.CP0_Config2_TA = 0 # Tertiary Cache Associativity
608        TestCPUClass.CoreParams.CP0_Config2_SU = 0 # Secondary Cache Control
609        TestCPUClass.CoreParams.CP0_Config2_SS = 0 # Secondary Cache Sets Per Way
610        TestCPUClass.CoreParams.CP0_Config2_SL = 0 # Secondary Cache Line Size
611        TestCPUClass.CoreParams.CP0_Config2_SA = 0 # Secondary Cache Associativity
612
613
614        #Config 3 Register
615        TestCPUClass.CoreParams.CP0_Config3_M = 0 # Config4 Not Implemented
616        TestCPUClass.CoreParams.CP0_Config3_DSPP = 1 # DSP ASE Present
617        TestCPUClass.CoreParams.CP0_Config3_LPA = 0 # Large Physical Addresses Not supported in Mips32
618        TestCPUClass.CoreParams.CP0_Config3_VEIC = 0 # EIC Supported
619        TestCPUClass.CoreParams.CP0_Config3_VInt = 0 # Vectored Interrupts Implemented
620        TestCPUClass.CoreParams.CP0_Config3_SP = 0 # Small Pages Supported (PageGrain reg. exists)
621        TestCPUClass.CoreParams.CP0_Config3_MT = 0 # MT Not present
622        TestCPUClass.CoreParams.CP0_Config3_SM = 0 # SmartMIPS ASE Not implemented
623        TestCPUClass.CoreParams.CP0_Config3_TL = 0 # TraceLogic Not implemented
624
625        #SRS Ctl - HSS
626        TestCPUClass.CoreParams.CP0_SrsCtl_HSS = 3 # Four shadow register sets implemented
627
628
629        #TestCPUClass.CoreParams.tlb = TLB()
630        #TestCPUClass.CoreParams.UnifiedTLB = 1
631