system.cc revision 3745
12567SN/A/*
22567SN/A * Copyright (c) 2002-2006 The Regents of The University of Michigan
32567SN/A * All rights reserved.
42567SN/A *
52567SN/A * Redistribution and use in source and binary forms, with or without
62567SN/A * modification, are permitted provided that the following conditions are
72567SN/A * met: redistributions of source code must retain the above copyright
82567SN/A * notice, this list of conditions and the following disclaimer;
92567SN/A * redistributions in binary form must reproduce the above copyright
102567SN/A * notice, this list of conditions and the following disclaimer in the
112567SN/A * documentation and/or other materials provided with the distribution;
122567SN/A * neither the name of the copyright holders nor the names of its
132567SN/A * contributors may be used to endorse or promote products derived from
142567SN/A * this software without specific prior written permission.
152567SN/A *
162567SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172567SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182567SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192567SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202567SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212567SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222567SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232567SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242567SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252567SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262567SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu *
282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi
292567SN/A */
302567SN/A
312567SN/A#include "arch/sparc/system.hh"
322567SN/A#include "arch/vtophys.hh"
332567SN/A#include "base/remote_gdb.hh"
342567SN/A#include "base/loader/object_file.hh"
352567SN/A#include "base/loader/symtab.hh"
362567SN/A#include "base/trace.hh"
372567SN/A#include "mem/physical.hh"
382567SN/A#include "sim/byteswap.hh"
392567SN/A#include "sim/builder.hh"
402567SN/A
412567SN/A
422567SN/Ausing namespace BigEndianGuest;
432567SN/A
442567SN/ASparcSystem::SparcSystem(Params *p)
453745Sgblack@eecs.umich.edu    : System(p), sysTick(0),funcRomPort(p->name + "-fromport"),
463745Sgblack@eecs.umich.edu    funcNvramPort(p->name + "-fnvramport"),
473745Sgblack@eecs.umich.edu    funcHypDescPort(p->name + "-fhypdescport"),
483745Sgblack@eecs.umich.edu    funcPartDescPort(p->name + "-fpartdescport")
492567SN/A{
502567SN/A    resetSymtab = new SymbolTable;
512567SN/A    hypervisorSymtab = new SymbolTable;
522567SN/A    openbootSymtab = new SymbolTable;
533745Sgblack@eecs.umich.edu    nvramSymtab = new SymbolTable;
543745Sgblack@eecs.umich.edu    hypervisorDescSymtab = new SymbolTable;
553745Sgblack@eecs.umich.edu    partitionDescSymtab = new SymbolTable;
562567SN/A
573584Ssaidi@eecs.umich.edu    Port *rom_port;
583584Ssaidi@eecs.umich.edu    rom_port = params()->rom->getPort("functional");
593584Ssaidi@eecs.umich.edu    funcRomPort.setPeer(rom_port);
603584Ssaidi@eecs.umich.edu    rom_port->setPeer(&funcRomPort);
612567SN/A
623745Sgblack@eecs.umich.edu    rom_port = params()->nvram->getPort("functional");
633745Sgblack@eecs.umich.edu    funcNvramPort.setPeer(rom_port);
643745Sgblack@eecs.umich.edu    rom_port->setPeer(&funcNvramPort);
653745Sgblack@eecs.umich.edu
663745Sgblack@eecs.umich.edu    rom_port = params()->hypervisor_desc->getPort("functional");
673745Sgblack@eecs.umich.edu    funcHypDescPort.setPeer(rom_port);
683745Sgblack@eecs.umich.edu    rom_port->setPeer(&funcHypDescPort);
693745Sgblack@eecs.umich.edu
703745Sgblack@eecs.umich.edu    rom_port = params()->partition_desc->getPort("functional");
713745Sgblack@eecs.umich.edu    funcPartDescPort.setPeer(rom_port);
723745Sgblack@eecs.umich.edu    rom_port->setPeer(&funcPartDescPort);
733745Sgblack@eecs.umich.edu
742567SN/A    /**
752567SN/A     * Load the boot code, and hypervisor into memory.
762567SN/A     */
772567SN/A    // Read the reset binary
783584Ssaidi@eecs.umich.edu    reset = createObjectFile(params()->reset_bin, true);
792567SN/A    if (reset == NULL)
802567SN/A        fatal("Could not load reset binary %s", params()->reset_bin);
812567SN/A
822567SN/A    // Read the openboot binary
833584Ssaidi@eecs.umich.edu    openboot = createObjectFile(params()->openboot_bin, true);
842567SN/A    if (openboot == NULL)
852567SN/A        fatal("Could not load openboot bianry %s", params()->openboot_bin);
862567SN/A
872567SN/A    // Read the hypervisor binary
883584Ssaidi@eecs.umich.edu    hypervisor = createObjectFile(params()->hypervisor_bin, true);
892567SN/A    if (hypervisor == NULL)
902567SN/A        fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
912567SN/A
923745Sgblack@eecs.umich.edu    // Read the nvram image
933745Sgblack@eecs.umich.edu    nvram = createObjectFile(params()->nvram_bin, true);
943745Sgblack@eecs.umich.edu    if (nvram == NULL)
953745Sgblack@eecs.umich.edu        fatal("Could not load nvram image %s", params()->nvram_bin);
963745Sgblack@eecs.umich.edu
973745Sgblack@eecs.umich.edu    // Read the hypervisor description image
983745Sgblack@eecs.umich.edu    hypervisor_desc = createObjectFile(params()->hypervisor_desc_bin, true);
993745Sgblack@eecs.umich.edu    if (hypervisor_desc == NULL)
1003745Sgblack@eecs.umich.edu        fatal("Could not load hypervisor description image %s",
1013745Sgblack@eecs.umich.edu                params()->hypervisor_desc_bin);
1023745Sgblack@eecs.umich.edu
1033745Sgblack@eecs.umich.edu    // Read the partition description image
1043745Sgblack@eecs.umich.edu    partition_desc = createObjectFile(params()->partition_desc_bin, true);
1053745Sgblack@eecs.umich.edu    if (partition_desc == NULL)
1063745Sgblack@eecs.umich.edu        fatal("Could not load partition description image %s",
1073745Sgblack@eecs.umich.edu                params()->partition_desc_bin);
1083745Sgblack@eecs.umich.edu
1092567SN/A
1102567SN/A    // Load reset binary into memory
1113584Ssaidi@eecs.umich.edu    reset->setTextBase(params()->reset_addr);
1123584Ssaidi@eecs.umich.edu    reset->loadSections(&funcRomPort);
1132567SN/A    // Load the openboot binary
1143584Ssaidi@eecs.umich.edu    openboot->setTextBase(params()->openboot_addr);
1153584Ssaidi@eecs.umich.edu    openboot->loadSections(&funcRomPort);
1162567SN/A    // Load the hypervisor binary
1173584Ssaidi@eecs.umich.edu    hypervisor->setTextBase(params()->hypervisor_addr);
1183584Ssaidi@eecs.umich.edu    hypervisor->loadSections(&funcRomPort);
1193745Sgblack@eecs.umich.edu    // Load the nvram image
1203745Sgblack@eecs.umich.edu    nvram->setTextBase(params()->nvram_addr);
1213745Sgblack@eecs.umich.edu    nvram->loadSections(&funcNvramPort);
1223745Sgblack@eecs.umich.edu    // Load the hypervisor description image
1233745Sgblack@eecs.umich.edu    hypervisor_desc->setTextBase(params()->hypervisor_desc_addr);
1243745Sgblack@eecs.umich.edu    hypervisor_desc->loadSections(&funcHypDescPort);
1253745Sgblack@eecs.umich.edu    // Load the partition description image
1263745Sgblack@eecs.umich.edu    partition_desc->setTextBase(params()->partition_desc_addr);
1273745Sgblack@eecs.umich.edu    partition_desc->loadSections(&funcPartDescPort);
1282567SN/A
1292567SN/A    // load symbols
1303527Sgblack@eecs.umich.edu    if (!reset->loadGlobalSymbols(resetSymtab))
1312567SN/A        panic("could not load reset symbols\n");
1322567SN/A
1332567SN/A    if (!openboot->loadGlobalSymbols(openbootSymtab))
1342567SN/A        panic("could not load openboot symbols\n");
1352567SN/A
1362567SN/A    if (!hypervisor->loadLocalSymbols(hypervisorSymtab))
1372567SN/A        panic("could not load hypervisor symbols\n");
1382567SN/A
1393745Sgblack@eecs.umich.edu    if (!nvram->loadLocalSymbols(nvramSymtab))
1403745Sgblack@eecs.umich.edu        panic("could not load nvram symbols\n");
1413745Sgblack@eecs.umich.edu
1423745Sgblack@eecs.umich.edu    if (!hypervisor_desc->loadLocalSymbols(hypervisorDescSymtab))
1433745Sgblack@eecs.umich.edu        panic("could not load hypervisor description symbols\n");
1443745Sgblack@eecs.umich.edu
1453745Sgblack@eecs.umich.edu    if (!partition_desc->loadLocalSymbols(partitionDescSymtab))
1463745Sgblack@eecs.umich.edu        panic("could not load partition description symbols\n");
1473745Sgblack@eecs.umich.edu
1482567SN/A    // load symbols into debug table
1492567SN/A    if (!reset->loadGlobalSymbols(debugSymbolTable))
1502567SN/A        panic("could not load reset symbols\n");
1512567SN/A
1522567SN/A    if (!openboot->loadGlobalSymbols(debugSymbolTable))
1532567SN/A        panic("could not load openboot symbols\n");
1542567SN/A
1552567SN/A    if (!hypervisor->loadLocalSymbols(debugSymbolTable))
1562567SN/A        panic("could not load hypervisor symbols\n");
1572567SN/A
1583745Sgblack@eecs.umich.edu    if (!nvram->loadGlobalSymbols(debugSymbolTable))
1593745Sgblack@eecs.umich.edu        panic("could not load reset symbols\n");
1603745Sgblack@eecs.umich.edu
1613745Sgblack@eecs.umich.edu    if (!hypervisor_desc->loadGlobalSymbols(debugSymbolTable))
1623745Sgblack@eecs.umich.edu        panic("could not load hypervisor description symbols\n");
1633745Sgblack@eecs.umich.edu
1643745Sgblack@eecs.umich.edu    if (!partition_desc->loadLocalSymbols(debugSymbolTable))
1653745Sgblack@eecs.umich.edu        panic("could not load partition description symbols\n");
1663745Sgblack@eecs.umich.edu
1672567SN/A
1682567SN/A    // @todo any fixup code over writing data in binaries on setting break
1692567SN/A    // events on functions should happen here.
1702567SN/A
1712567SN/A}
1722567SN/A
1732567SN/ASparcSystem::~SparcSystem()
1742567SN/A{
1752567SN/A    delete resetSymtab;
1762567SN/A    delete hypervisorSymtab;
1772567SN/A    delete openbootSymtab;
1783745Sgblack@eecs.umich.edu    delete nvramSymtab;
1793745Sgblack@eecs.umich.edu    delete hypervisorDescSymtab;
1803745Sgblack@eecs.umich.edu    delete partitionDescSymtab;
1812567SN/A    delete reset;
1822567SN/A    delete openboot;
1832567SN/A    delete hypervisor;
1843745Sgblack@eecs.umich.edu    delete nvram;
1853745Sgblack@eecs.umich.edu    delete hypervisor_desc;
1863745Sgblack@eecs.umich.edu    delete partition_desc;
1872567SN/A}
1882567SN/A
1892567SN/Abool
1902567SN/ASparcSystem::breakpoint()
1912567SN/A{
1922567SN/A    panic("Need to implement");
1932567SN/A}
1942567SN/A
1952567SN/Avoid
1962567SN/ASparcSystem::serialize(std::ostream &os)
1972567SN/A{
1982567SN/A    System::serialize(os);
1992567SN/A    resetSymtab->serialize("reset_symtab", os);
2002567SN/A    hypervisorSymtab->serialize("hypervisor_symtab", os);
2012567SN/A    openbootSymtab->serialize("openboot_symtab", os);
2023745Sgblack@eecs.umich.edu    nvramSymtab->serialize("nvram_symtab", os);
2033745Sgblack@eecs.umich.edu    hypervisorDescSymtab->serialize("hypervisor_desc_symtab", os);
2043745Sgblack@eecs.umich.edu    partitionDescSymtab->serialize("partition_desc_symtab", os);
2052567SN/A}
2062567SN/A
2072567SN/A
2082567SN/Avoid
2092567SN/ASparcSystem::unserialize(Checkpoint *cp, const std::string &section)
2102567SN/A{
2112567SN/A    System::unserialize(cp,section);
2122567SN/A    resetSymtab->unserialize("reset_symtab", cp, section);
2132567SN/A    hypervisorSymtab->unserialize("hypervisor_symtab", cp, section);
2142567SN/A    openbootSymtab->unserialize("openboot_symtab", cp, section);
2153745Sgblack@eecs.umich.edu    nvramSymtab->unserialize("nvram_symtab", cp, section);
2163745Sgblack@eecs.umich.edu    hypervisorDescSymtab->unserialize("hypervisor_desc_symtab", cp, section);
2173745Sgblack@eecs.umich.edu    partitionDescSymtab->unserialize("partition_desc_symtab", cp, section);
2182567SN/A}
2192567SN/A
2202567SN/A
2212567SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(SparcSystem)
2222567SN/A
2232567SN/A    SimObjectParam<PhysicalMemory *> physmem;
2243584Ssaidi@eecs.umich.edu    SimObjectParam<PhysicalMemory *> rom;
2253745Sgblack@eecs.umich.edu    SimObjectParam<PhysicalMemory *> nvram;
2263745Sgblack@eecs.umich.edu    SimObjectParam<PhysicalMemory *> hypervisor_desc;
2273745Sgblack@eecs.umich.edu    SimObjectParam<PhysicalMemory *> partition_desc;
2282902Ssaidi@eecs.umich.edu    SimpleEnumParam<System::MemoryMode> mem_mode;
2292567SN/A
2303584Ssaidi@eecs.umich.edu    Param<Addr> reset_addr;
2313584Ssaidi@eecs.umich.edu    Param<Addr> hypervisor_addr;
2323584Ssaidi@eecs.umich.edu    Param<Addr> openboot_addr;
2333745Sgblack@eecs.umich.edu    Param<Addr> nvram_addr;
2343745Sgblack@eecs.umich.edu    Param<Addr> hypervisor_desc_addr;
2353745Sgblack@eecs.umich.edu    Param<Addr> partition_desc_addr;
2363584Ssaidi@eecs.umich.edu
2372567SN/A    Param<std::string> kernel;
2382567SN/A    Param<std::string> reset_bin;
2392567SN/A    Param<std::string> hypervisor_bin;
2402567SN/A    Param<std::string> openboot_bin;
2413745Sgblack@eecs.umich.edu    Param<std::string> nvram_bin;
2423745Sgblack@eecs.umich.edu    Param<std::string> hypervisor_desc_bin;
2433745Sgblack@eecs.umich.edu    Param<std::string> partition_desc_bin;
2442567SN/A
2453527Sgblack@eecs.umich.edu    Param<Tick> boot_cpu_frequency;
2462567SN/A    Param<std::string> boot_osflags;
2472567SN/A    Param<std::string> readfile;
2482567SN/A    Param<unsigned int> init_param;
2492567SN/A
2502567SN/AEND_DECLARE_SIM_OBJECT_PARAMS(SparcSystem)
2512567SN/A
2522567SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(SparcSystem)
2532567SN/A
2542567SN/A    INIT_PARAM(physmem, "phsyical memory"),
2553584Ssaidi@eecs.umich.edu    INIT_PARAM(rom, "ROM for boot code"),
2563745Sgblack@eecs.umich.edu    INIT_PARAM(nvram, "Non-volatile RAM for the nvram"),
2573745Sgblack@eecs.umich.edu    INIT_PARAM(hypervisor_desc, "ROM for the hypervisor description"),
2583745Sgblack@eecs.umich.edu    INIT_PARAM(partition_desc, "ROM for the partition description"),
2592902Ssaidi@eecs.umich.edu    INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)",
2602902Ssaidi@eecs.umich.edu            System::MemoryModeStrings),
2613584Ssaidi@eecs.umich.edu
2623584Ssaidi@eecs.umich.edu    INIT_PARAM(reset_addr, "Address that reset should be loaded at"),
2633584Ssaidi@eecs.umich.edu    INIT_PARAM(hypervisor_addr, "Address that hypervisor should be loaded at"),
2643584Ssaidi@eecs.umich.edu    INIT_PARAM(openboot_addr, "Address that openboot should be loaded at"),
2653745Sgblack@eecs.umich.edu    INIT_PARAM(nvram_addr, "Address that nvram should be loaded at"),
2663745Sgblack@eecs.umich.edu    INIT_PARAM(hypervisor_desc_addr,
2673745Sgblack@eecs.umich.edu            "Address that hypervisor description should be loaded at"),
2683745Sgblack@eecs.umich.edu    INIT_PARAM(partition_desc_addr,
2693745Sgblack@eecs.umich.edu            "Address that partition description should be loaded at"),
2703584Ssaidi@eecs.umich.edu
2712567SN/A    INIT_PARAM(kernel, "file that contains the kernel code"),
2722567SN/A    INIT_PARAM(reset_bin, "file that contains the reset code"),
2732567SN/A    INIT_PARAM(hypervisor_bin, "file that contains the hypervisor code"),
2742567SN/A    INIT_PARAM(openboot_bin, "file that contains the openboot code"),
2753745Sgblack@eecs.umich.edu    INIT_PARAM(nvram_bin, "file that contains the nvram image"),
2763745Sgblack@eecs.umich.edu    INIT_PARAM(hypervisor_desc_bin,
2773745Sgblack@eecs.umich.edu            "file that contains the hypervisor description image"),
2783745Sgblack@eecs.umich.edu    INIT_PARAM(partition_desc_bin,
2793745Sgblack@eecs.umich.edu            "file that contains the partition description image"),
2803527Sgblack@eecs.umich.edu    INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
2812567SN/A    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
2822567SN/A                    "a"),
2832567SN/A    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
2843527Sgblack@eecs.umich.edu    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0)
2852567SN/A
2862567SN/AEND_INIT_SIM_OBJECT_PARAMS(SparcSystem)
2872567SN/A
2882567SN/ACREATE_SIM_OBJECT(SparcSystem)
2892567SN/A{
2902567SN/A    SparcSystem::Params *p = new SparcSystem::Params;
2912567SN/A    p->name = getInstanceName();
2922567SN/A    p->boot_cpu_frequency = boot_cpu_frequency;
2932567SN/A    p->physmem = physmem;
2943584Ssaidi@eecs.umich.edu    p->rom = rom;
2953745Sgblack@eecs.umich.edu    p->nvram = nvram;
2963745Sgblack@eecs.umich.edu    p->hypervisor_desc = hypervisor_desc;
2973745Sgblack@eecs.umich.edu    p->partition_desc = partition_desc;
2982902Ssaidi@eecs.umich.edu    p->mem_mode = mem_mode;
2992567SN/A    p->kernel_path = kernel;
3003584Ssaidi@eecs.umich.edu    p->reset_addr = reset_addr;
3013584Ssaidi@eecs.umich.edu    p->hypervisor_addr = hypervisor_addr;
3023584Ssaidi@eecs.umich.edu    p->openboot_addr = openboot_addr;
3033745Sgblack@eecs.umich.edu    p->nvram_addr = nvram_addr;
3043745Sgblack@eecs.umich.edu    p->hypervisor_desc_addr = hypervisor_desc_addr;
3053745Sgblack@eecs.umich.edu    p->partition_desc_addr = partition_desc_addr;
3062567SN/A    p->reset_bin = reset_bin;
3072567SN/A    p->hypervisor_bin = hypervisor_bin;
3082567SN/A    p->openboot_bin = openboot_bin;
3093745Sgblack@eecs.umich.edu    p->nvram_bin = nvram_bin;
3103745Sgblack@eecs.umich.edu    p->hypervisor_desc_bin = hypervisor_desc_bin;
3113745Sgblack@eecs.umich.edu    p->partition_desc_bin = partition_desc_bin;
3122567SN/A    p->boot_osflags = boot_osflags;
3132567SN/A    p->init_param = init_param;
3142567SN/A    p->readfile = readfile;
3152567SN/A    return new SparcSystem(p);
3162567SN/A}
3172567SN/A
3182567SN/AREGISTER_SIM_OBJECT("SparcSystem", SparcSystem)
3192567SN/A
3202567SN/A
321