FSConfig.py revision 10735:071996521ce6
17150Sgblack@eecs.umich.edu# Copyright (c) 2010-2012 ARM Limited
27150Sgblack@eecs.umich.edu# All rights reserved.
37150Sgblack@eecs.umich.edu#
47150Sgblack@eecs.umich.edu# The license below extends only to copyright in the software and shall
57150Sgblack@eecs.umich.edu# not be construed as granting a license to any other intellectual
67150Sgblack@eecs.umich.edu# property including but not limited to intellectual property relating
77150Sgblack@eecs.umich.edu# to a hardware implementation of the functionality of the software
87150Sgblack@eecs.umich.edu# licensed hereunder.  You may use the software subject to the license
97150Sgblack@eecs.umich.edu# terms below provided that you ensure that this notice is replicated
107150Sgblack@eecs.umich.edu# unmodified and in its entirety in all distributions of the software,
117150Sgblack@eecs.umich.edu# modified or unmodified, in source code or in binary form.
127150Sgblack@eecs.umich.edu#
137150Sgblack@eecs.umich.edu# Copyright (c) 2010-2011 Advanced Micro Devices, Inc.
147150Sgblack@eecs.umich.edu# Copyright (c) 2006-2008 The Regents of The University of Michigan
157150Sgblack@eecs.umich.edu# All rights reserved.
167150Sgblack@eecs.umich.edu#
177150Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without
187150Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are
197150Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright
207150Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer;
217150Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright
227150Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the
237150Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution;
247150Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its
257150Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from
267150Sgblack@eecs.umich.edu# this software without specific prior written permission.
277150Sgblack@eecs.umich.edu#
287150Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
297150Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
307150Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
317150Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
327150Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
337150Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
347150Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
357150Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
367150Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
377150Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
387150Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
397150Sgblack@eecs.umich.edu#
407150Sgblack@eecs.umich.edu# Authors: Kevin Lim
417150Sgblack@eecs.umich.edu
427150Sgblack@eecs.umich.edufrom m5.objects import *
437150Sgblack@eecs.umich.edufrom Benchmarks import *
447150Sgblack@eecs.umich.edufrom m5.util import *
457150Sgblack@eecs.umich.edu
467150Sgblack@eecs.umich.educlass CowIdeDisk(IdeDisk):
477150Sgblack@eecs.umich.edu    image = CowDiskImage(child=RawDiskImage(read_only=True),
487150Sgblack@eecs.umich.edu                         read_only=False)
497150Sgblack@eecs.umich.edu
507150Sgblack@eecs.umich.edu    def childImage(self, ci):
517150Sgblack@eecs.umich.edu        self.image.child.image_file = ci
527150Sgblack@eecs.umich.edu
537150Sgblack@eecs.umich.educlass MemBus(SystemXBar):
547150Sgblack@eecs.umich.edu    badaddr_responder = BadAddr()
557150Sgblack@eecs.umich.edu    default = Self.badaddr_responder.pio
567848SAli.Saidi@ARM.com
577848SAli.Saidi@ARM.com
587848SAli.Saidi@ARM.comdef fillInCmdline(mdesc, template, **kwargs):
597848SAli.Saidi@ARM.com    kwargs.setdefault('disk', mdesc.disk())
608146SAli.Saidi@ARM.com    kwargs.setdefault('rootdev', mdesc.rootdev())
618146SAli.Saidi@ARM.com    kwargs.setdefault('mem', mdesc.mem())
628146SAli.Saidi@ARM.com    kwargs.setdefault('script', mdesc.script())
637848SAli.Saidi@ARM.com    return template % kwargs
648146SAli.Saidi@ARM.com
657150Sgblack@eecs.umich.edudef makeLinuxAlphaSystem(mem_mode, mdesc=None, ruby=False, cmdline=None):
667150Sgblack@eecs.umich.edu
677150Sgblack@eecs.umich.edu    class BaseTsunami(Tsunami):
687150Sgblack@eecs.umich.edu        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
697150Sgblack@eecs.umich.edu        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
707150Sgblack@eecs.umich.edu                            pci_func=0, pci_dev=0, pci_bus=0)
717150Sgblack@eecs.umich.edu
727150Sgblack@eecs.umich.edu    self = LinuxAlphaSystem()
737150Sgblack@eecs.umich.edu    if not mdesc:
747150Sgblack@eecs.umich.edu        # generic system
757150Sgblack@eecs.umich.edu        mdesc = SysConfig()
768146SAli.Saidi@ARM.com    self.readfile = mdesc.script()
777150Sgblack@eecs.umich.edu
787150Sgblack@eecs.umich.edu    self.tsunami = BaseTsunami()
797150Sgblack@eecs.umich.edu
807150Sgblack@eecs.umich.edu    # Create the io bus to connect all device ports
817150Sgblack@eecs.umich.edu    self.iobus = IOXBar()
827150Sgblack@eecs.umich.edu    self.tsunami.attachIO(self.iobus)
837150Sgblack@eecs.umich.edu
847150Sgblack@eecs.umich.edu    self.tsunami.ide.pio = self.iobus.master
857150Sgblack@eecs.umich.edu    self.tsunami.ide.config = self.iobus.master
867150Sgblack@eecs.umich.edu
877150Sgblack@eecs.umich.edu    self.tsunami.ethernet.pio = self.iobus.master
887848SAli.Saidi@ARM.com    self.tsunami.ethernet.config = self.iobus.master
897848SAli.Saidi@ARM.com
907848SAli.Saidi@ARM.com    if ruby:
917848SAli.Saidi@ARM.com        # Store the dma devices for later connection to dma ruby ports.
928146SAli.Saidi@ARM.com        # Append an underscore to dma_ports to avoid the SimObjectVector check.
938146SAli.Saidi@ARM.com        self._dma_ports = [self.tsunami.ide.dma, self.tsunami.ethernet.dma]
948146SAli.Saidi@ARM.com    else:
957848SAli.Saidi@ARM.com        self.membus = MemBus()
967150Sgblack@eecs.umich.edu
977150Sgblack@eecs.umich.edu        # By default the bridge responds to all addresses above the I/O
987150Sgblack@eecs.umich.edu        # base address (including the PCI config space)
997150Sgblack@eecs.umich.edu        IO_address_space_base = 0x80000000000
1007150Sgblack@eecs.umich.edu        self.bridge = Bridge(delay='50ns',
1017150Sgblack@eecs.umich.edu                         ranges = [AddrRange(IO_address_space_base, Addr.max)])
1027150Sgblack@eecs.umich.edu        self.bridge.master = self.iobus.slave
1037150Sgblack@eecs.umich.edu        self.bridge.slave = self.membus.master
1047150Sgblack@eecs.umich.edu
1057150Sgblack@eecs.umich.edu        self.tsunami.ide.dma = self.iobus.slave
1067150Sgblack@eecs.umich.edu        self.tsunami.ethernet.dma = self.iobus.slave
1077150Sgblack@eecs.umich.edu
1087150Sgblack@eecs.umich.edu        self.system_port = self.membus.slave
1097150Sgblack@eecs.umich.edu
1107150Sgblack@eecs.umich.edu    self.mem_ranges = [AddrRange(mdesc.mem())]
1117150Sgblack@eecs.umich.edu    self.disk0 = CowIdeDisk(driveID='master')
1127150Sgblack@eecs.umich.edu    self.disk2 = CowIdeDisk(driveID='master')
1137150Sgblack@eecs.umich.edu    self.disk0.childImage(mdesc.disk())
1147150Sgblack@eecs.umich.edu    self.disk2.childImage(disk('linux-bigswap2.img'))
1157848SAli.Saidi@ARM.com    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
1167848SAli.Saidi@ARM.com                                               read_only = True))
1177848SAli.Saidi@ARM.com    self.intrctrl = IntrControl()
1187848SAli.Saidi@ARM.com    self.mem_mode = mem_mode
1198146SAli.Saidi@ARM.com    self.terminal = Terminal()
1208146SAli.Saidi@ARM.com    self.kernel = binary('vmlinux')
1218146SAli.Saidi@ARM.com    self.pal = binary('ts_osfpal')
1227848SAli.Saidi@ARM.com    self.console = binary('console')
1238203SAli.Saidi@ARM.com    if not cmdline:
1248203SAli.Saidi@ARM.com        cmdline = 'root=/dev/hda1 console=ttyS0'
1257150Sgblack@eecs.umich.edu    self.boot_osflags = fillInCmdline(mdesc, cmdline)
1267150Sgblack@eecs.umich.edu
1277150Sgblack@eecs.umich.edu    return self
1287150Sgblack@eecs.umich.edu
1297150Sgblack@eecs.umich.edudef makeSparcSystem(mem_mode, mdesc=None):
1307150Sgblack@eecs.umich.edu    # Constants from iob.cc and uart8250.cc
1317150Sgblack@eecs.umich.edu    iob_man_addr = 0x9800000000
1327150Sgblack@eecs.umich.edu    uart_pio_size = 8
1337150Sgblack@eecs.umich.edu
1347150Sgblack@eecs.umich.edu    class CowMmDisk(MmDisk):
1357150Sgblack@eecs.umich.edu        image = CowDiskImage(child=RawDiskImage(read_only=True),
1367150Sgblack@eecs.umich.edu                             read_only=False)
1377150Sgblack@eecs.umich.edu
1387150Sgblack@eecs.umich.edu        def childImage(self, ci):
1397150Sgblack@eecs.umich.edu            self.image.child.image_file = ci
1407150Sgblack@eecs.umich.edu
1417150Sgblack@eecs.umich.edu    self = SparcSystem()
1427150Sgblack@eecs.umich.edu    if not mdesc:
1437150Sgblack@eecs.umich.edu        # generic system
1447150Sgblack@eecs.umich.edu        mdesc = SysConfig()
1457150Sgblack@eecs.umich.edu    self.readfile = mdesc.script()
1467150Sgblack@eecs.umich.edu    self.iobus = IOXBar()
1477848SAli.Saidi@ARM.com    self.membus = MemBus()
1487848SAli.Saidi@ARM.com    self.bridge = Bridge(delay='50ns')
1497848SAli.Saidi@ARM.com    self.t1000 = T1000()
1507848SAli.Saidi@ARM.com    self.t1000.attachOnChipIO(self.membus)
1518146SAli.Saidi@ARM.com    self.t1000.attachIO(self.iobus)
1528146SAli.Saidi@ARM.com    self.mem_ranges = [AddrRange(Addr('1MB'), size = '64MB'),
1538146SAli.Saidi@ARM.com                       AddrRange(Addr('2GB'), size ='256MB')]
1547848SAli.Saidi@ARM.com    self.bridge.master = self.iobus.slave
1558203SAli.Saidi@ARM.com    self.bridge.slave = self.membus.master
1568203SAli.Saidi@ARM.com    self.rom.port = self.membus.master
1577150Sgblack@eecs.umich.edu    self.nvram.port = self.membus.master
1587150Sgblack@eecs.umich.edu    self.hypervisor_desc.port = self.membus.master
1597150Sgblack@eecs.umich.edu    self.partition_desc.port = self.membus.master
1607150Sgblack@eecs.umich.edu    self.intrctrl = IntrControl()
1617150Sgblack@eecs.umich.edu    self.disk0 = CowMmDisk()
1627150Sgblack@eecs.umich.edu    self.disk0.childImage(disk('disk.s10hw2'))
1637150Sgblack@eecs.umich.edu    self.disk0.pio = self.iobus.master
1647150Sgblack@eecs.umich.edu
1657150Sgblack@eecs.umich.edu    # The puart0 and hvuart are placed on the IO bus, so create ranges
1667150Sgblack@eecs.umich.edu    # for them. The remaining IO range is rather fragmented, so poke
1677150Sgblack@eecs.umich.edu    # holes for the iob and partition descriptors etc.
1687150Sgblack@eecs.umich.edu    self.bridge.ranges = \
1697150Sgblack@eecs.umich.edu        [
1707150Sgblack@eecs.umich.edu        AddrRange(self.t1000.puart0.pio_addr,
1717150Sgblack@eecs.umich.edu                  self.t1000.puart0.pio_addr + uart_pio_size - 1),
1727150Sgblack@eecs.umich.edu        AddrRange(self.disk0.pio_addr,
1737150Sgblack@eecs.umich.edu                  self.t1000.fake_jbi.pio_addr +
1747150Sgblack@eecs.umich.edu                  self.t1000.fake_jbi.pio_size - 1),
1757150Sgblack@eecs.umich.edu        AddrRange(self.t1000.fake_clk.pio_addr,
1767150Sgblack@eecs.umich.edu                  iob_man_addr - 1),
1777150Sgblack@eecs.umich.edu        AddrRange(self.t1000.fake_l2_1.pio_addr,
1787150Sgblack@eecs.umich.edu                  self.t1000.fake_ssi.pio_addr +
1797150Sgblack@eecs.umich.edu                  self.t1000.fake_ssi.pio_size - 1),
1807150Sgblack@eecs.umich.edu        AddrRange(self.t1000.hvuart.pio_addr,
1817150Sgblack@eecs.umich.edu                  self.t1000.hvuart.pio_addr + uart_pio_size - 1)
1827150Sgblack@eecs.umich.edu        ]
1837150Sgblack@eecs.umich.edu    self.reset_bin = binary('reset_new.bin')
1847150Sgblack@eecs.umich.edu    self.hypervisor_bin = binary('q_new.bin')
1857150Sgblack@eecs.umich.edu    self.openboot_bin = binary('openboot_new.bin')
1867150Sgblack@eecs.umich.edu    self.nvram_bin = binary('nvram1')
1877150Sgblack@eecs.umich.edu    self.hypervisor_desc_bin = binary('1up-hv.bin')
1887150Sgblack@eecs.umich.edu    self.partition_desc_bin = binary('1up-md.bin')
1897150Sgblack@eecs.umich.edu
1907150Sgblack@eecs.umich.edu    self.system_port = self.membus.slave
1917150Sgblack@eecs.umich.edu
1927150Sgblack@eecs.umich.edu    return self
1937848SAli.Saidi@ARM.com
1947848SAli.Saidi@ARM.comdef makeArmSystem(mem_mode, machine_type, num_cpus=1, mdesc=None,
1957848SAli.Saidi@ARM.com                  dtb_filename=None, bare_metal=False, cmdline=None):
1967848SAli.Saidi@ARM.com    assert machine_type
1978146SAli.Saidi@ARM.com
1988146SAli.Saidi@ARM.com    if bare_metal:
1998146SAli.Saidi@ARM.com        self = ArmSystem()
2007848SAli.Saidi@ARM.com    else:
2017150Sgblack@eecs.umich.edu        self = LinuxArmSystem()
2027150Sgblack@eecs.umich.edu
2037150Sgblack@eecs.umich.edu    if not mdesc:
2047150Sgblack@eecs.umich.edu        # generic system
2057150Sgblack@eecs.umich.edu        mdesc = SysConfig()
2067150Sgblack@eecs.umich.edu
2077150Sgblack@eecs.umich.edu    self.readfile = mdesc.script()
2087150Sgblack@eecs.umich.edu    self.iobus = IOXBar()
2097150Sgblack@eecs.umich.edu    self.membus = MemBus()
2107150Sgblack@eecs.umich.edu    self.membus.badaddr_responder.warn_access = "warn"
2117150Sgblack@eecs.umich.edu    self.bridge = Bridge(delay='50ns')
2127150Sgblack@eecs.umich.edu    self.bridge.master = self.iobus.slave
2137150Sgblack@eecs.umich.edu    self.bridge.slave = self.membus.master
2147150Sgblack@eecs.umich.edu
2158892Sb.grayson@samsung.com    self.mem_mode = mem_mode
2168892Sb.grayson@samsung.com
2177150Sgblack@eecs.umich.edu    if machine_type == "RealView_PBX":
2187150Sgblack@eecs.umich.edu        self.realview = RealViewPBX()
2197150Sgblack@eecs.umich.edu    elif machine_type == "RealView_EB":
2207150Sgblack@eecs.umich.edu        self.realview = RealViewEB()
2217150Sgblack@eecs.umich.edu    elif machine_type == "VExpress_EMM":
2227150Sgblack@eecs.umich.edu        self.realview = VExpress_EMM()
2237150Sgblack@eecs.umich.edu        if not dtb_filename:
2248892Sb.grayson@samsung.com            dtb_filename = 'vexpress.aarch32.ll_20131205.0-gem5.%dcpu.dtb' % num_cpus
2257150Sgblack@eecs.umich.edu    elif machine_type == "VExpress_EMM64":
2267150Sgblack@eecs.umich.edu        self.realview = VExpress_EMM64()
2278146SAli.Saidi@ARM.com        if os.path.split(mdesc.disk())[-1] == 'linux-aarch32-ael.img':
2288146SAli.Saidi@ARM.com            print "Selected 64-bit ARM architecture, updating default disk image..."
2298146SAli.Saidi@ARM.com            mdesc.diskname = 'linaro-minimal-aarch64.img'
2308146SAli.Saidi@ARM.com        if not dtb_filename:
2318146SAli.Saidi@ARM.com            dtb_filename = 'vexpress.aarch64.20140821.dtb'
2328146SAli.Saidi@ARM.com    else:
2338146SAli.Saidi@ARM.com        print "Unknown Machine Type"
2348146SAli.Saidi@ARM.com        sys.exit(1)
2358146SAli.Saidi@ARM.com
2368146SAli.Saidi@ARM.com    self.cf0 = CowIdeDisk(driveID='master')
2378146SAli.Saidi@ARM.com    self.cf0.childImage(mdesc.disk())
2388146SAli.Saidi@ARM.com
2398146SAli.Saidi@ARM.com    # Attach any PCI devices this platform supports
2408146SAli.Saidi@ARM.com    self.realview.attachPciDevices()
2418146SAli.Saidi@ARM.com    # default to an IDE controller rather than a CF one
2428146SAli.Saidi@ARM.com    try:
2438146SAli.Saidi@ARM.com        self.realview.ide.disks = [self.cf0]
244    except:
245        self.realview.cf_ctrl.disks = [self.cf0]
246
247    self.mem_ranges = []
248    size_remain = long(Addr(mdesc.mem()))
249    for region in self.realview._mem_regions:
250        if size_remain > long(region[1]):
251            self.mem_ranges.append(AddrRange(region[0], size=region[1]))
252            size_remain = size_remain - long(region[1])
253        else:
254            self.mem_ranges.append(AddrRange(region[0], size=size_remain))
255            size_remain = 0
256            break
257        warn("Memory size specified spans more than one region. Creating" \
258             " another memory controller for that range.")
259
260    if size_remain > 0:
261        fatal("The currently selected ARM platforms doesn't support" \
262              " the amount of DRAM you've selected. Please try" \
263              " another platform")
264
265    if bare_metal:
266        # EOT character on UART will end the simulation
267        self.realview.uart.end_on_eot = True
268    else:
269        if machine_type == "VExpress_EMM64":
270            self.kernel = binary('vmlinux.aarch64.20140821')
271        elif machine_type == "VExpress_EMM":
272            self.kernel = binary('vmlinux.aarch32.ll_20131205.0-gem5')
273        else:
274            self.kernel = binary('vmlinux.arm.smp.fb.2.6.38.8')
275
276        if dtb_filename:
277            self.dtb_filename = binary(dtb_filename)
278        self.machine_type = machine_type
279        # Ensure that writes to the UART actually go out early in the boot
280        if not cmdline:
281            cmdline = 'earlyprintk=pl011,0x1c090000 console=ttyAMA0 ' + \
282                      'lpj=19988480 norandmaps rw loglevel=8 ' + \
283                      'mem=%(mem)s root=%(rootdev)s'
284
285        self.realview.setupBootLoader(self.membus, self, binary)
286        self.gic_cpu_addr = self.realview.gic.cpu_addr
287        self.flags_addr = self.realview.realview_io.pio_addr + 0x30
288
289        # Android disk images must have 'android' keyword in the disk name
290        # Look for 'android' in disk name and append /init to boot_osflags
291        if (os.path.split(mdesc.disk())[-1]).lower().count('android'):
292            cmdline += " init=/init "
293        self.boot_osflags = fillInCmdline(mdesc, cmdline)
294    self.realview.attachOnChipIO(self.membus, self.bridge)
295    self.realview.attachIO(self.iobus)
296    self.intrctrl = IntrControl()
297    self.terminal = Terminal()
298    self.vncserver = VncServer()
299
300    self.system_port = self.membus.slave
301
302    return self
303
304
305def makeLinuxMipsSystem(mem_mode, mdesc=None, cmdline=None):
306    class BaseMalta(Malta):
307        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
308        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
309                            pci_func=0, pci_dev=0, pci_bus=0)
310
311    self = LinuxMipsSystem()
312    if not mdesc:
313        # generic system
314        mdesc = SysConfig()
315    self.readfile = mdesc.script()
316    self.iobus = IOXBar()
317    self.membus = MemBus()
318    self.bridge = Bridge(delay='50ns')
319    self.mem_ranges = [AddrRange('1GB')]
320    self.bridge.master = self.iobus.slave
321    self.bridge.slave = self.membus.master
322    self.disk0 = CowIdeDisk(driveID='master')
323    self.disk2 = CowIdeDisk(driveID='master')
324    self.disk0.childImage(mdesc.disk())
325    self.disk2.childImage(disk('linux-bigswap2.img'))
326    self.malta = BaseMalta()
327    self.malta.attachIO(self.iobus)
328    self.malta.ide.pio = self.iobus.master
329    self.malta.ide.config = self.iobus.master
330    self.malta.ide.dma = self.iobus.slave
331    self.malta.ethernet.pio = self.iobus.master
332    self.malta.ethernet.config = self.iobus.master
333    self.malta.ethernet.dma = self.iobus.slave
334    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
335                                               read_only = True))
336    self.intrctrl = IntrControl()
337    self.mem_mode = mem_mode
338    self.terminal = Terminal()
339    self.kernel = binary('mips/vmlinux')
340    self.console = binary('mips/console')
341    if not cmdline:
342        cmdline = 'root=/dev/hda1 console=ttyS0'
343    self.boot_osflags = fillInCmdline(mdesc, cmdline)
344
345    self.system_port = self.membus.slave
346
347    return self
348
349def x86IOAddress(port):
350    IO_address_space_base = 0x8000000000000000
351    return IO_address_space_base + port
352
353def connectX86ClassicSystem(x86_sys, numCPUs):
354    # Constants similar to x86_traits.hh
355    IO_address_space_base = 0x8000000000000000
356    pci_config_address_space_base = 0xc000000000000000
357    interrupts_address_space_base = 0xa000000000000000
358    APIC_range_size = 1 << 12;
359
360    x86_sys.membus = MemBus()
361
362    # North Bridge
363    x86_sys.iobus = IOXBar()
364    x86_sys.bridge = Bridge(delay='50ns')
365    x86_sys.bridge.master = x86_sys.iobus.slave
366    x86_sys.bridge.slave = x86_sys.membus.master
367    # Allow the bridge to pass through:
368    #  1) kernel configured PCI device memory map address: address range
369    #     [0xC0000000, 0xFFFF0000). (The upper 64kB are reserved for m5ops.)
370    #  2) the bridge to pass through the IO APIC (two pages, already contained in 1),
371    #  3) everything in the IO address range up to the local APIC, and
372    #  4) then the entire PCI address space and beyond.
373    x86_sys.bridge.ranges = \
374        [
375        AddrRange(0xC0000000, 0xFFFF0000),
376        AddrRange(IO_address_space_base,
377                  interrupts_address_space_base - 1),
378        AddrRange(pci_config_address_space_base,
379                  Addr.max)
380        ]
381
382    # Create a bridge from the IO bus to the memory bus to allow access to
383    # the local APIC (two pages)
384    x86_sys.apicbridge = Bridge(delay='50ns')
385    x86_sys.apicbridge.slave = x86_sys.iobus.master
386    x86_sys.apicbridge.master = x86_sys.membus.slave
387    x86_sys.apicbridge.ranges = [AddrRange(interrupts_address_space_base,
388                                           interrupts_address_space_base +
389                                           numCPUs * APIC_range_size
390                                           - 1)]
391
392    # connect the io bus
393    x86_sys.pc.attachIO(x86_sys.iobus)
394
395    x86_sys.system_port = x86_sys.membus.slave
396
397def connectX86RubySystem(x86_sys):
398    # North Bridge
399    x86_sys.iobus = IOXBar()
400
401    # add the ide to the list of dma devices that later need to attach to
402    # dma controllers
403    x86_sys._dma_ports = [x86_sys.pc.south_bridge.ide.dma]
404    x86_sys.pc.attachIO(x86_sys.iobus, x86_sys._dma_ports)
405
406
407def makeX86System(mem_mode, numCPUs=1, mdesc=None, self=None, Ruby=False):
408    if self == None:
409        self = X86System()
410
411    if not mdesc:
412        # generic system
413        mdesc = SysConfig()
414    self.readfile = mdesc.script()
415
416    self.mem_mode = mem_mode
417
418    # Physical memory
419    # On the PC platform, the memory region 0xC0000000-0xFFFFFFFF is reserved
420    # for various devices.  Hence, if the physical memory size is greater than
421    # 3GB, we need to split it into two parts.
422    excess_mem_size = \
423        convert.toMemorySize(mdesc.mem()) - convert.toMemorySize('3GB')
424    if excess_mem_size <= 0:
425        self.mem_ranges = [AddrRange(mdesc.mem())]
426    else:
427        warn("Physical memory size specified is %s which is greater than " \
428             "3GB.  Twice the number of memory controllers would be " \
429             "created."  % (mdesc.mem()))
430
431        self.mem_ranges = [AddrRange('3GB'),
432            AddrRange(Addr('4GB'), size = excess_mem_size)]
433
434    # Platform
435    self.pc = Pc()
436
437    # Create and connect the busses required by each memory system
438    if Ruby:
439        connectX86RubySystem(self)
440    else:
441        connectX86ClassicSystem(self, numCPUs)
442
443    self.intrctrl = IntrControl()
444
445    # Disks
446    disk0 = CowIdeDisk(driveID='master')
447    disk2 = CowIdeDisk(driveID='master')
448    disk0.childImage(mdesc.disk())
449    disk2.childImage(disk('linux-bigswap2.img'))
450    self.pc.south_bridge.ide.disks = [disk0, disk2]
451
452    # Add in a Bios information structure.
453    structures = [X86SMBiosBiosInformation()]
454    self.smbios_table.structures = structures
455
456    # Set up the Intel MP table
457    base_entries = []
458    ext_entries = []
459    for i in xrange(numCPUs):
460        bp = X86IntelMPProcessor(
461                local_apic_id = i,
462                local_apic_version = 0x14,
463                enable = True,
464                bootstrap = (i == 0))
465        base_entries.append(bp)
466    io_apic = X86IntelMPIOAPIC(
467            id = numCPUs,
468            version = 0x11,
469            enable = True,
470            address = 0xfec00000)
471    self.pc.south_bridge.io_apic.apic_id = io_apic.id
472    base_entries.append(io_apic)
473    # In gem5 Pc::calcPciConfigAddr(), it required "assert(bus==0)",
474    # but linux kernel cannot config PCI device if it was not connected to PCI bus,
475    # so we fix PCI bus id to 0, and ISA bus id to 1.
476    pci_bus = X86IntelMPBus(bus_id = 0, bus_type='PCI')
477    base_entries.append(pci_bus)
478    isa_bus = X86IntelMPBus(bus_id = 1, bus_type='ISA')
479    base_entries.append(isa_bus)
480    connect_busses = X86IntelMPBusHierarchy(bus_id=1,
481            subtractive_decode=True, parent_bus=0)
482    ext_entries.append(connect_busses)
483    pci_dev4_inta = X86IntelMPIOIntAssignment(
484            interrupt_type = 'INT',
485            polarity = 'ConformPolarity',
486            trigger = 'ConformTrigger',
487            source_bus_id = 0,
488            source_bus_irq = 0 + (4 << 2),
489            dest_io_apic_id = io_apic.id,
490            dest_io_apic_intin = 16)
491    base_entries.append(pci_dev4_inta)
492    def assignISAInt(irq, apicPin):
493        assign_8259_to_apic = X86IntelMPIOIntAssignment(
494                interrupt_type = 'ExtInt',
495                polarity = 'ConformPolarity',
496                trigger = 'ConformTrigger',
497                source_bus_id = 1,
498                source_bus_irq = irq,
499                dest_io_apic_id = io_apic.id,
500                dest_io_apic_intin = 0)
501        base_entries.append(assign_8259_to_apic)
502        assign_to_apic = X86IntelMPIOIntAssignment(
503                interrupt_type = 'INT',
504                polarity = 'ConformPolarity',
505                trigger = 'ConformTrigger',
506                source_bus_id = 1,
507                source_bus_irq = irq,
508                dest_io_apic_id = io_apic.id,
509                dest_io_apic_intin = apicPin)
510        base_entries.append(assign_to_apic)
511    assignISAInt(0, 2)
512    assignISAInt(1, 1)
513    for i in range(3, 15):
514        assignISAInt(i, i)
515    self.intel_mp_table.base_entries = base_entries
516    self.intel_mp_table.ext_entries = ext_entries
517
518def makeLinuxX86System(mem_mode, numCPUs=1, mdesc=None, Ruby=False,
519                       cmdline=None):
520    self = LinuxX86System()
521
522    # Build up the x86 system and then specialize it for Linux
523    makeX86System(mem_mode, numCPUs, mdesc, self, Ruby)
524
525    # We assume below that there's at least 1MB of memory. We'll require 2
526    # just to avoid corner cases.
527    phys_mem_size = sum(map(lambda r: r.size(), self.mem_ranges))
528    assert(phys_mem_size >= 0x200000)
529    assert(len(self.mem_ranges) <= 2)
530
531    entries = \
532       [
533        # Mark the first megabyte of memory as reserved
534        X86E820Entry(addr = 0, size = '639kB', range_type = 1),
535        X86E820Entry(addr = 0x9fc00, size = '385kB', range_type = 2),
536        # Mark the rest of physical memory as available
537        X86E820Entry(addr = 0x100000,
538                size = '%dB' % (self.mem_ranges[0].size() - 0x100000),
539                range_type = 1),
540        ]
541
542    # Mark [mem_size, 3GB) as reserved if memory less than 3GB, which force
543    # IO devices to be mapped to [0xC0000000, 0xFFFF0000). Requests to this
544    # specific range can pass though bridge to iobus.
545    if len(self.mem_ranges) == 1:
546        entries.append(X86E820Entry(addr = self.mem_ranges[0].size(),
547            size='%dB' % (0xC0000000 - self.mem_ranges[0].size()),
548            range_type=2))
549
550    # Reserve the last 16kB of the 32-bit address space for the m5op interface
551    entries.append(X86E820Entry(addr=0xFFFF0000, size='64kB', range_type=2))
552
553    # In case the physical memory is greater than 3GB, we split it into two
554    # parts and add a separate e820 entry for the second part.  This entry
555    # starts at 0x100000000,  which is the first address after the space
556    # reserved for devices.
557    if len(self.mem_ranges) == 2:
558        entries.append(X86E820Entry(addr = 0x100000000,
559            size = '%dB' % (self.mem_ranges[1].size()), range_type = 1))
560
561    self.e820_table.entries = entries
562
563    # Command line
564    if not cmdline:
565        cmdline = 'earlyprintk=ttyS0 console=ttyS0 lpj=7999923 root=/dev/hda1'
566    self.boot_osflags = fillInCmdline(mdesc, cmdline)
567    self.kernel = binary('x86_64-vmlinux-2.6.22.9')
568    return self
569
570
571def makeDualRoot(full_system, testSystem, driveSystem, dumpfile):
572    self = Root(full_system = full_system)
573    self.testsys = testSystem
574    self.drivesys = driveSystem
575    self.etherlink = EtherLink()
576
577    if hasattr(testSystem, 'realview'):
578        self.etherlink.int0 = Parent.testsys.realview.ethernet.interface
579        self.etherlink.int1 = Parent.drivesys.realview.ethernet.interface
580    elif hasattr(testSystem, 'tsunami'):
581        self.etherlink.int0 = Parent.testsys.tsunami.ethernet.interface
582        self.etherlink.int1 = Parent.drivesys.tsunami.ethernet.interface
583    else:
584        fatal("Don't know how to connect these system together")
585
586    if dumpfile:
587        self.etherdump = EtherDump(file=dumpfile)
588        self.etherlink.dump = Parent.etherdump
589
590    return self
591