FSConfig.py revision 10588
11689SN/A# Copyright (c) 2010-2012 ARM Limited
21689SN/A# All rights reserved.
39919Ssteve.reinhardt@amd.com#
41689SN/A# The license below extends only to copyright in the software and shall
51689SN/A# not be construed as granting a license to any other intellectual
61689SN/A# property including but not limited to intellectual property relating
71689SN/A# to a hardware implementation of the functionality of the software
81689SN/A# licensed hereunder.  You may use the software subject to the license
91689SN/A# terms below provided that you ensure that this notice is replicated
101689SN/A# unmodified and in its entirety in all distributions of the software,
111689SN/A# modified or unmodified, in source code or in binary form.
121689SN/A#
131689SN/A# Copyright (c) 2010-2011 Advanced Micro Devices, Inc.
141689SN/A# Copyright (c) 2006-2008 The Regents of The University of Michigan
151689SN/A# All rights reserved.
161689SN/A#
171689SN/A# Redistribution and use in source and binary forms, with or without
181689SN/A# modification, are permitted provided that the following conditions are
191689SN/A# met: redistributions of source code must retain the above copyright
201689SN/A# notice, this list of conditions and the following disclaimer;
211689SN/A# redistributions in binary form must reproduce the above copyright
221689SN/A# notice, this list of conditions and the following disclaimer in the
231689SN/A# documentation and/or other materials provided with the distribution;
241689SN/A# neither the name of the copyright holders nor the names of its
251689SN/A# contributors may be used to endorse or promote products derived from
261689SN/A# this software without specific prior written permission.
271689SN/A#
282665Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292665Ssaidi@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
301689SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
311464SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3211793Sbrandon.potter@amd.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3311793Sbrandon.potter@amd.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
341464SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
351060SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
368232Snate@binkert.org# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
371060SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
381464SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
391464SN/A#
409919Ssteve.reinhardt@amd.com# Authors: Kevin Lim
411060SN/A
429919Ssteve.reinhardt@amd.comfrom m5.objects import *
4310537Sandreas.hansson@arm.comfrom Benchmarks import *
441060SN/Afrom m5.util import *
452292SN/A
462292SN/Aclass CowIdeDisk(IdeDisk):
471061SN/A    image = CowDiskImage(child=RawDiskImage(read_only=True),
481060SN/A                         read_only=False)
499919Ssteve.reinhardt@amd.com
509919Ssteve.reinhardt@amd.com    def childImage(self, ci):
511060SN/A        self.image.child.image_file = ci
529919Ssteve.reinhardt@amd.com
539919Ssteve.reinhardt@amd.comclass MemBus(CoherentXBar):
549919Ssteve.reinhardt@amd.com    badaddr_responder = BadAddr()
559919Ssteve.reinhardt@amd.com    default = Self.badaddr_responder.pio
569919Ssteve.reinhardt@amd.com
579919Ssteve.reinhardt@amd.com
581060SN/Adef makeLinuxAlphaSystem(mem_mode, mdesc=None, ruby=False):
591060SN/A
601060SN/A    class BaseTsunami(Tsunami):
611060SN/A        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
621060SN/A        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
631060SN/A                            pci_func=0, pci_dev=0, pci_bus=0)
641060SN/A
659919Ssteve.reinhardt@amd.com    self = LinuxAlphaSystem()
669919Ssteve.reinhardt@amd.com    if not mdesc:
679919Ssteve.reinhardt@amd.com        # generic system
681060SN/A        mdesc = SysConfig()
699919Ssteve.reinhardt@amd.com    self.readfile = mdesc.script()
709919Ssteve.reinhardt@amd.com
719919Ssteve.reinhardt@amd.com    self.tsunami = BaseTsunami()
729919Ssteve.reinhardt@amd.com
731060SN/A    # Create the io bus to connect all device ports
749919Ssteve.reinhardt@amd.com    self.iobus = NoncoherentXBar()
751060SN/A    self.tsunami.attachIO(self.iobus)
769919Ssteve.reinhardt@amd.com
779919Ssteve.reinhardt@amd.com    self.tsunami.ide.pio = self.iobus.master
789919Ssteve.reinhardt@amd.com    self.tsunami.ide.config = self.iobus.master
791060SN/A
801060SN/A    self.tsunami.ethernet.pio = self.iobus.master
813867Sbinkertn@umich.edu    self.tsunami.ethernet.config = self.iobus.master
823867Sbinkertn@umich.edu
833867Sbinkertn@umich.edu    if ruby:
841060SN/A        # Store the dma devices for later connection to dma ruby ports.
851060SN/A        # Append an underscore to dma_ports to avoid the SimObjectVector check.
861060SN/A        self._dma_ports = [self.tsunami.ide.dma, self.tsunami.ethernet.dma]
879919Ssteve.reinhardt@amd.com    else:
889919Ssteve.reinhardt@amd.com        self.membus = MemBus()
899919Ssteve.reinhardt@amd.com
909919Ssteve.reinhardt@amd.com        # By default the bridge responds to all addresses above the I/O
919919Ssteve.reinhardt@amd.com        # base address (including the PCI config space)
929919Ssteve.reinhardt@amd.com        IO_address_space_base = 0x80000000000
939919Ssteve.reinhardt@amd.com        self.bridge = Bridge(delay='50ns',
949919Ssteve.reinhardt@amd.com                         ranges = [AddrRange(IO_address_space_base, Addr.max)])
959919Ssteve.reinhardt@amd.com        self.bridge.master = self.iobus.slave
969919Ssteve.reinhardt@amd.com        self.bridge.slave = self.membus.master
979919Ssteve.reinhardt@amd.com
989919Ssteve.reinhardt@amd.com        self.tsunami.ide.dma = self.iobus.slave
999919Ssteve.reinhardt@amd.com        self.tsunami.ethernet.dma = self.iobus.slave
1009919Ssteve.reinhardt@amd.com
1019920Syasuko.eckert@amd.com        self.system_port = self.membus.slave
10210897Snilay@cs.wisc.edu
1039919Ssteve.reinhardt@amd.com    self.mem_ranges = [AddrRange(mdesc.mem())]
1049919Ssteve.reinhardt@amd.com    self.disk0 = CowIdeDisk(driveID='master')
1059919Ssteve.reinhardt@amd.com    self.disk2 = CowIdeDisk(driveID='master')
1069919Ssteve.reinhardt@amd.com    self.disk0.childImage(mdesc.disk())
1079919Ssteve.reinhardt@amd.com    self.disk2.childImage(disk('linux-bigswap2.img'))
1089919Ssteve.reinhardt@amd.com    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
1099919Ssteve.reinhardt@amd.com                                               read_only = True))
1109919Ssteve.reinhardt@amd.com    self.intrctrl = IntrControl()
1119919Ssteve.reinhardt@amd.com    self.mem_mode = mem_mode
1129919Ssteve.reinhardt@amd.com    self.terminal = Terminal()
1139919Ssteve.reinhardt@amd.com    self.kernel = binary('vmlinux')
1149919Ssteve.reinhardt@amd.com    self.pal = binary('ts_osfpal')
1159919Ssteve.reinhardt@amd.com    self.console = binary('console')
1169919Ssteve.reinhardt@amd.com    self.boot_osflags = 'root=/dev/hda1 console=ttyS0'
1179919Ssteve.reinhardt@amd.com
1189920Syasuko.eckert@amd.com    return self
1199920Syasuko.eckert@amd.com
1209920Syasuko.eckert@amd.comdef makeSparcSystem(mem_mode, mdesc=None):
1219919Ssteve.reinhardt@amd.com    # Constants from iob.cc and uart8250.cc
1229919Ssteve.reinhardt@amd.com    iob_man_addr = 0x9800000000
1239919Ssteve.reinhardt@amd.com    uart_pio_size = 8
1249919Ssteve.reinhardt@amd.com
1259919Ssteve.reinhardt@amd.com    class CowMmDisk(MmDisk):
1269919Ssteve.reinhardt@amd.com        image = CowDiskImage(child=RawDiskImage(read_only=True),
1279919Ssteve.reinhardt@amd.com                             read_only=False)
1289919Ssteve.reinhardt@amd.com
1299919Ssteve.reinhardt@amd.com        def childImage(self, ci):
1309919Ssteve.reinhardt@amd.com            self.image.child.image_file = ci
1311060SN/A
1329919Ssteve.reinhardt@amd.com    self = SparcSystem()
1331060SN/A    if not mdesc:
1349919Ssteve.reinhardt@amd.com        # generic system
1351060SN/A        mdesc = SysConfig()
1369919Ssteve.reinhardt@amd.com    self.readfile = mdesc.script()
1379919Ssteve.reinhardt@amd.com    self.iobus = NoncoherentXBar()
1389919Ssteve.reinhardt@amd.com    self.membus = MemBus()
1399919Ssteve.reinhardt@amd.com    self.bridge = Bridge(delay='50ns')
1409919Ssteve.reinhardt@amd.com    self.t1000 = T1000()
1419919Ssteve.reinhardt@amd.com    self.t1000.attachOnChipIO(self.membus)
1429919Ssteve.reinhardt@amd.com    self.t1000.attachIO(self.iobus)
1439920Syasuko.eckert@amd.com    self.mem_ranges = [AddrRange(Addr('1MB'), size = '64MB'),
1449920Syasuko.eckert@amd.com                       AddrRange(Addr('2GB'), size ='256MB')]
1459920Syasuko.eckert@amd.com    self.bridge.master = self.iobus.slave
1469919Ssteve.reinhardt@amd.com    self.bridge.slave = self.membus.master
1479919Ssteve.reinhardt@amd.com    self.rom.port = self.membus.master
1489919Ssteve.reinhardt@amd.com    self.nvram.port = self.membus.master
1499919Ssteve.reinhardt@amd.com    self.hypervisor_desc.port = self.membus.master
1509919Ssteve.reinhardt@amd.com    self.partition_desc.port = self.membus.master
1519919Ssteve.reinhardt@amd.com    self.intrctrl = IntrControl()
1521060SN/A    self.disk0 = CowMmDisk()
1531060SN/A    self.disk0.childImage(disk('disk.s10hw2'))
1541060SN/A    self.disk0.pio = self.iobus.master
1551060SN/A
1569919Ssteve.reinhardt@amd.com    # The puart0 and hvuart are placed on the IO bus, so create ranges
1571060SN/A    # for them. The remaining IO range is rather fragmented, so poke
1589919Ssteve.reinhardt@amd.com    # holes for the iob and partition descriptors etc.
1591060SN/A    self.bridge.ranges = \
1609919Ssteve.reinhardt@amd.com        [
1619919Ssteve.reinhardt@amd.com        AddrRange(self.t1000.puart0.pio_addr,
1629919Ssteve.reinhardt@amd.com                  self.t1000.puart0.pio_addr + uart_pio_size - 1),
1631060SN/A        AddrRange(self.disk0.pio_addr,
1649919Ssteve.reinhardt@amd.com                  self.t1000.fake_jbi.pio_addr +
1659919Ssteve.reinhardt@amd.com                  self.t1000.fake_jbi.pio_size - 1),
1669919Ssteve.reinhardt@amd.com        AddrRange(self.t1000.fake_clk.pio_addr,
1679920Syasuko.eckert@amd.com                  iob_man_addr - 1),
1689920Syasuko.eckert@amd.com        AddrRange(self.t1000.fake_l2_1.pio_addr,
1699920Syasuko.eckert@amd.com                  self.t1000.fake_ssi.pio_addr +
1709919Ssteve.reinhardt@amd.com                  self.t1000.fake_ssi.pio_size - 1),
1719919Ssteve.reinhardt@amd.com        AddrRange(self.t1000.hvuart.pio_addr,
1729919Ssteve.reinhardt@amd.com                  self.t1000.hvuart.pio_addr + uart_pio_size - 1)
1739919Ssteve.reinhardt@amd.com        ]
1749919Ssteve.reinhardt@amd.com    self.reset_bin = binary('reset_new.bin')
1759919Ssteve.reinhardt@amd.com    self.hypervisor_bin = binary('q_new.bin')
1769919Ssteve.reinhardt@amd.com    self.openboot_bin = binary('openboot_new.bin')
1779919Ssteve.reinhardt@amd.com    self.nvram_bin = binary('nvram1')
1789919Ssteve.reinhardt@amd.com    self.hypervisor_desc_bin = binary('1up-hv.bin')
1799919Ssteve.reinhardt@amd.com    self.partition_desc_bin = binary('1up-md.bin')
1809919Ssteve.reinhardt@amd.com
1811060SN/A    self.system_port = self.membus.slave
1821060SN/A
183    return self
184
185def makeArmSystem(mem_mode, machine_type, num_cpus=1, mdesc=None,
186                  dtb_filename=None, bare_metal=False):
187    assert machine_type
188
189    if bare_metal:
190        self = ArmSystem()
191    else:
192        self = LinuxArmSystem()
193
194    if not mdesc:
195        # generic system
196        mdesc = SysConfig()
197
198    self.readfile = mdesc.script()
199    self.iobus = NoncoherentXBar()
200    self.membus = MemBus()
201    self.membus.badaddr_responder.warn_access = "warn"
202    self.bridge = Bridge(delay='50ns')
203    self.bridge.master = self.iobus.slave
204    self.bridge.slave = self.membus.master
205
206    self.mem_mode = mem_mode
207
208    if machine_type == "RealView_PBX":
209        self.realview = RealViewPBX()
210    elif machine_type == "RealView_EB":
211        self.realview = RealViewEB()
212    elif machine_type == "VExpress_EMM":
213        self.realview = VExpress_EMM()
214        if not dtb_filename:
215            dtb_filename = 'vexpress.aarch32.ll_20131205.0-gem5.%dcpu.dtb' % num_cpus
216    elif machine_type == "VExpress_EMM64":
217        self.realview = VExpress_EMM64()
218        if os.path.split(mdesc.disk())[-1] == 'linux-aarch32-ael.img':
219            print "Selected 64-bit ARM architecture, updating default disk image..."
220            mdesc.diskname = 'linaro-minimal-aarch64.img'
221        if not dtb_filename:
222            dtb_filename = 'vexpress.aarch64.20140821.dtb'
223    else:
224        print "Unknown Machine Type"
225        sys.exit(1)
226
227    self.cf0 = CowIdeDisk(driveID='master')
228    self.cf0.childImage(mdesc.disk())
229
230    # Attach any PCI devices this platform supports
231    self.realview.attachPciDevices()
232    # default to an IDE controller rather than a CF one
233    try:
234        self.realview.ide.disks = [self.cf0]
235    except:
236        self.realview.cf_ctrl.disks = [self.cf0]
237
238    self.mem_ranges = []
239    size_remain = long(Addr(mdesc.mem()))
240    for region in self.realview._mem_regions:
241        if size_remain > long(region[1]):
242            self.mem_ranges.append(AddrRange(region[0], size=region[1]))
243            size_remain = size_remain - long(region[1])
244        else:
245            self.mem_ranges.append(AddrRange(region[0], size=size_remain))
246            size_remain = 0
247            break
248        warn("Memory size specified spans more than one region. Creating" \
249             " another memory controller for that range.")
250
251    if size_remain > 0:
252        fatal("The currently selected ARM platforms doesn't support" \
253              " the amount of DRAM you've selected. Please try" \
254              " another platform")
255
256    if bare_metal:
257        # EOT character on UART will end the simulation
258        self.realview.uart.end_on_eot = True
259    else:
260        if machine_type == "VExpress_EMM64":
261            self.kernel = binary('vmlinux.aarch64.20140821')
262        elif machine_type == "VExpress_EMM":
263            self.kernel = binary('vmlinux.aarch32.ll_20131205.0-gem5')
264        else:
265            self.kernel = binary('vmlinux.arm.smp.fb.2.6.38.8')
266
267        if dtb_filename:
268            self.dtb_filename = binary(dtb_filename)
269        self.machine_type = machine_type
270        # Ensure that writes to the UART actually go out early in the boot
271        boot_flags = 'earlyprintk=pl011,0x1c090000 console=ttyAMA0 ' + \
272                     'lpj=19988480 norandmaps rw loglevel=8 ' + \
273                     'mem=%s root=/dev/sda1' % mdesc.mem()
274
275        self.realview.setupBootLoader(self.membus, self, binary)
276        self.gic_cpu_addr = self.realview.gic.cpu_addr
277        self.flags_addr = self.realview.realview_io.pio_addr + 0x30
278
279        if mdesc.disk().lower().count('android'):
280            boot_flags += " init=/init "
281        self.boot_osflags = boot_flags
282    self.realview.attachOnChipIO(self.membus, self.bridge)
283    self.realview.attachIO(self.iobus)
284    self.intrctrl = IntrControl()
285    self.terminal = Terminal()
286    self.vncserver = VncServer()
287
288    self.system_port = self.membus.slave
289
290    return self
291
292
293def makeLinuxMipsSystem(mem_mode, mdesc=None):
294    class BaseMalta(Malta):
295        ethernet = NSGigE(pci_bus=0, pci_dev=1, pci_func=0)
296        ide = IdeController(disks=[Parent.disk0, Parent.disk2],
297                            pci_func=0, pci_dev=0, pci_bus=0)
298
299    self = LinuxMipsSystem()
300    if not mdesc:
301        # generic system
302        mdesc = SysConfig()
303    self.readfile = mdesc.script()
304    self.iobus = NoncoherentXBar()
305    self.membus = MemBus()
306    self.bridge = Bridge(delay='50ns')
307    self.mem_ranges = [AddrRange('1GB')]
308    self.bridge.master = self.iobus.slave
309    self.bridge.slave = self.membus.master
310    self.disk0 = CowIdeDisk(driveID='master')
311    self.disk2 = CowIdeDisk(driveID='master')
312    self.disk0.childImage(mdesc.disk())
313    self.disk2.childImage(disk('linux-bigswap2.img'))
314    self.malta = BaseMalta()
315    self.malta.attachIO(self.iobus)
316    self.malta.ide.pio = self.iobus.master
317    self.malta.ide.config = self.iobus.master
318    self.malta.ide.dma = self.iobus.slave
319    self.malta.ethernet.pio = self.iobus.master
320    self.malta.ethernet.config = self.iobus.master
321    self.malta.ethernet.dma = self.iobus.slave
322    self.simple_disk = SimpleDisk(disk=RawDiskImage(image_file = mdesc.disk(),
323                                               read_only = True))
324    self.intrctrl = IntrControl()
325    self.mem_mode = mem_mode
326    self.terminal = Terminal()
327    self.kernel = binary('mips/vmlinux')
328    self.console = binary('mips/console')
329    self.boot_osflags = 'root=/dev/hda1 console=ttyS0'
330
331    self.system_port = self.membus.slave
332
333    return self
334
335def x86IOAddress(port):
336    IO_address_space_base = 0x8000000000000000
337    return IO_address_space_base + port
338
339def connectX86ClassicSystem(x86_sys, numCPUs):
340    # Constants similar to x86_traits.hh
341    IO_address_space_base = 0x8000000000000000
342    pci_config_address_space_base = 0xc000000000000000
343    interrupts_address_space_base = 0xa000000000000000
344    APIC_range_size = 1 << 12;
345
346    x86_sys.membus = MemBus()
347
348    # North Bridge
349    x86_sys.iobus = NoncoherentXBar()
350    x86_sys.bridge = Bridge(delay='50ns')
351    x86_sys.bridge.master = x86_sys.iobus.slave
352    x86_sys.bridge.slave = x86_sys.membus.master
353    # Allow the bridge to pass through:
354    #  1) kernel configured PCI device memory map address: address range
355    #     [0xC0000000, 0xFFFF0000). (The upper 64kB are reserved for m5ops.)
356    #  2) the bridge to pass through the IO APIC (two pages, already contained in 1),
357    #  3) everything in the IO address range up to the local APIC, and
358    #  4) then the entire PCI address space and beyond.
359    x86_sys.bridge.ranges = \
360        [
361        AddrRange(0xC0000000, 0xFFFF0000),
362        AddrRange(IO_address_space_base,
363                  interrupts_address_space_base - 1),
364        AddrRange(pci_config_address_space_base,
365                  Addr.max)
366        ]
367
368    # Create a bridge from the IO bus to the memory bus to allow access to
369    # the local APIC (two pages)
370    x86_sys.apicbridge = Bridge(delay='50ns')
371    x86_sys.apicbridge.slave = x86_sys.iobus.master
372    x86_sys.apicbridge.master = x86_sys.membus.slave
373    x86_sys.apicbridge.ranges = [AddrRange(interrupts_address_space_base,
374                                           interrupts_address_space_base +
375                                           numCPUs * APIC_range_size
376                                           - 1)]
377
378    # connect the io bus
379    x86_sys.pc.attachIO(x86_sys.iobus)
380
381    x86_sys.system_port = x86_sys.membus.slave
382
383def connectX86RubySystem(x86_sys):
384    # North Bridge
385    x86_sys.iobus = NoncoherentXBar()
386
387    # add the ide to the list of dma devices that later need to attach to
388    # dma controllers
389    x86_sys._dma_ports = [x86_sys.pc.south_bridge.ide.dma]
390    x86_sys.pc.attachIO(x86_sys.iobus, x86_sys._dma_ports)
391
392
393def makeX86System(mem_mode, numCPUs=1, mdesc=None, self=None, Ruby=False):
394    if self == None:
395        self = X86System()
396
397    if not mdesc:
398        # generic system
399        mdesc = SysConfig()
400    self.readfile = mdesc.script()
401
402    self.mem_mode = mem_mode
403
404    # Physical memory
405    # On the PC platform, the memory region 0xC0000000-0xFFFFFFFF is reserved
406    # for various devices.  Hence, if the physical memory size is greater than
407    # 3GB, we need to split it into two parts.
408    excess_mem_size = \
409        convert.toMemorySize(mdesc.mem()) - convert.toMemorySize('3GB')
410    if excess_mem_size <= 0:
411        self.mem_ranges = [AddrRange(mdesc.mem())]
412    else:
413        warn("Physical memory size specified is %s which is greater than " \
414             "3GB.  Twice the number of memory controllers would be " \
415             "created."  % (mdesc.mem()))
416
417        self.mem_ranges = [AddrRange('3GB'),
418            AddrRange(Addr('4GB'), size = excess_mem_size)]
419
420    # Platform
421    self.pc = Pc()
422
423    # Create and connect the busses required by each memory system
424    if Ruby:
425        connectX86RubySystem(self)
426    else:
427        connectX86ClassicSystem(self, numCPUs)
428
429    self.intrctrl = IntrControl()
430
431    # Disks
432    disk0 = CowIdeDisk(driveID='master')
433    disk2 = CowIdeDisk(driveID='master')
434    disk0.childImage(mdesc.disk())
435    disk2.childImage(disk('linux-bigswap2.img'))
436    self.pc.south_bridge.ide.disks = [disk0, disk2]
437
438    # Add in a Bios information structure.
439    structures = [X86SMBiosBiosInformation()]
440    self.smbios_table.structures = structures
441
442    # Set up the Intel MP table
443    base_entries = []
444    ext_entries = []
445    for i in xrange(numCPUs):
446        bp = X86IntelMPProcessor(
447                local_apic_id = i,
448                local_apic_version = 0x14,
449                enable = True,
450                bootstrap = (i == 0))
451        base_entries.append(bp)
452    io_apic = X86IntelMPIOAPIC(
453            id = numCPUs,
454            version = 0x11,
455            enable = True,
456            address = 0xfec00000)
457    self.pc.south_bridge.io_apic.apic_id = io_apic.id
458    base_entries.append(io_apic)
459    # In gem5 Pc::calcPciConfigAddr(), it required "assert(bus==0)",
460    # but linux kernel cannot config PCI device if it was not connected to PCI bus,
461    # so we fix PCI bus id to 0, and ISA bus id to 1.
462    pci_bus = X86IntelMPBus(bus_id = 0, bus_type='PCI')
463    base_entries.append(pci_bus)
464    isa_bus = X86IntelMPBus(bus_id = 1, bus_type='ISA')
465    base_entries.append(isa_bus)
466    connect_busses = X86IntelMPBusHierarchy(bus_id=1,
467            subtractive_decode=True, parent_bus=0)
468    ext_entries.append(connect_busses)
469    pci_dev4_inta = X86IntelMPIOIntAssignment(
470            interrupt_type = 'INT',
471            polarity = 'ConformPolarity',
472            trigger = 'ConformTrigger',
473            source_bus_id = 0,
474            source_bus_irq = 0 + (4 << 2),
475            dest_io_apic_id = io_apic.id,
476            dest_io_apic_intin = 16)
477    base_entries.append(pci_dev4_inta)
478    def assignISAInt(irq, apicPin):
479        assign_8259_to_apic = X86IntelMPIOIntAssignment(
480                interrupt_type = 'ExtInt',
481                polarity = 'ConformPolarity',
482                trigger = 'ConformTrigger',
483                source_bus_id = 1,
484                source_bus_irq = irq,
485                dest_io_apic_id = io_apic.id,
486                dest_io_apic_intin = 0)
487        base_entries.append(assign_8259_to_apic)
488        assign_to_apic = X86IntelMPIOIntAssignment(
489                interrupt_type = 'INT',
490                polarity = 'ConformPolarity',
491                trigger = 'ConformTrigger',
492                source_bus_id = 1,
493                source_bus_irq = irq,
494                dest_io_apic_id = io_apic.id,
495                dest_io_apic_intin = apicPin)
496        base_entries.append(assign_to_apic)
497    assignISAInt(0, 2)
498    assignISAInt(1, 1)
499    for i in range(3, 15):
500        assignISAInt(i, i)
501    self.intel_mp_table.base_entries = base_entries
502    self.intel_mp_table.ext_entries = ext_entries
503
504def makeLinuxX86System(mem_mode, numCPUs=1, mdesc=None, Ruby=False):
505    self = LinuxX86System()
506
507    # Build up the x86 system and then specialize it for Linux
508    makeX86System(mem_mode, numCPUs, mdesc, self, Ruby)
509
510    # We assume below that there's at least 1MB of memory. We'll require 2
511    # just to avoid corner cases.
512    phys_mem_size = sum(map(lambda r: r.size(), self.mem_ranges))
513    assert(phys_mem_size >= 0x200000)
514    assert(len(self.mem_ranges) <= 2)
515
516    entries = \
517       [
518        # Mark the first megabyte of memory as reserved
519        X86E820Entry(addr = 0, size = '639kB', range_type = 1),
520        X86E820Entry(addr = 0x9fc00, size = '385kB', range_type = 2),
521        # Mark the rest of physical memory as available
522        X86E820Entry(addr = 0x100000,
523                size = '%dB' % (self.mem_ranges[0].size() - 0x100000),
524                range_type = 1),
525        ]
526
527    # Mark [mem_size, 3GB) as reserved if memory less than 3GB, which force
528    # IO devices to be mapped to [0xC0000000, 0xFFFF0000). Requests to this
529    # specific range can pass though bridge to iobus.
530    if len(self.mem_ranges) == 1:
531        entries.append(X86E820Entry(addr = self.mem_ranges[0].size(),
532            size='%dB' % (0xC0000000 - self.mem_ranges[0].size()),
533            range_type=2))
534
535    # Reserve the last 16kB of the 32-bit address space for the m5op interface
536    entries.append(X86E820Entry(addr=0xFFFF0000, size='64kB', range_type=2))
537
538    # In case the physical memory is greater than 3GB, we split it into two
539    # parts and add a separate e820 entry for the second part.  This entry
540    # starts at 0x100000000,  which is the first address after the space
541    # reserved for devices.
542    if len(self.mem_ranges) == 2:
543        entries.append(X86E820Entry(addr = 0x100000000,
544            size = '%dB' % (self.mem_ranges[1].size()), range_type = 1))
545
546    self.e820_table.entries = entries
547
548    # Command line
549    self.boot_osflags = 'earlyprintk=ttyS0 console=ttyS0 lpj=7999923 ' + \
550                        'root=/dev/hda1'
551    self.kernel = binary('x86_64-vmlinux-2.6.22.9')
552    return self
553
554
555def makeDualRoot(full_system, testSystem, driveSystem, dumpfile):
556    self = Root(full_system = full_system)
557    self.testsys = testSystem
558    self.drivesys = driveSystem
559    self.etherlink = EtherLink()
560
561    if hasattr(testSystem, 'realview'):
562        self.etherlink.int0 = Parent.testsys.realview.ethernet.interface
563        self.etherlink.int1 = Parent.drivesys.realview.ethernet.interface
564    elif hasattr(testSystem, 'tsunami'):
565        self.etherlink.int0 = Parent.testsys.tsunami.ethernet.interface
566        self.etherlink.int1 = Parent.drivesys.tsunami.ethernet.interface
567    else:
568        fatal("Don't know how to connect these system together")
569
570    if dumpfile:
571        self.etherdump = EtherDump(file=dumpfile)
572        self.etherlink.dump = Parent.etherdump
573
574    return self
575