system.cc revision 3812
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
1583812Ssaidi@eecs.umich.edu    // Strip off the rom address so when the hypervisor is copied into memory we
1593812Ssaidi@eecs.umich.edu    // have symbols still
1603812Ssaidi@eecs.umich.edu    if (!hypervisor->loadLocalSymbols(debugSymbolTable, 0xFFFFFF))
1613812Ssaidi@eecs.umich.edu        panic("could not load hypervisor symbols\n");
1623812Ssaidi@eecs.umich.edu
1633745Sgblack@eecs.umich.edu    if (!nvram->loadGlobalSymbols(debugSymbolTable))
1643745Sgblack@eecs.umich.edu        panic("could not load reset symbols\n");
1653745Sgblack@eecs.umich.edu
1663745Sgblack@eecs.umich.edu    if (!hypervisor_desc->loadGlobalSymbols(debugSymbolTable))
1673745Sgblack@eecs.umich.edu        panic("could not load hypervisor description symbols\n");
1683745Sgblack@eecs.umich.edu
1693745Sgblack@eecs.umich.edu    if (!partition_desc->loadLocalSymbols(debugSymbolTable))
1703745Sgblack@eecs.umich.edu        panic("could not load partition description symbols\n");
1713745Sgblack@eecs.umich.edu
1722567SN/A
1732567SN/A    // @todo any fixup code over writing data in binaries on setting break
1742567SN/A    // events on functions should happen here.
1752567SN/A
1762567SN/A}
1772567SN/A
1782567SN/ASparcSystem::~SparcSystem()
1792567SN/A{
1802567SN/A    delete resetSymtab;
1812567SN/A    delete hypervisorSymtab;
1822567SN/A    delete openbootSymtab;
1833745Sgblack@eecs.umich.edu    delete nvramSymtab;
1843745Sgblack@eecs.umich.edu    delete hypervisorDescSymtab;
1853745Sgblack@eecs.umich.edu    delete partitionDescSymtab;
1862567SN/A    delete reset;
1872567SN/A    delete openboot;
1882567SN/A    delete hypervisor;
1893745Sgblack@eecs.umich.edu    delete nvram;
1903745Sgblack@eecs.umich.edu    delete hypervisor_desc;
1913745Sgblack@eecs.umich.edu    delete partition_desc;
1922567SN/A}
1932567SN/A
1942567SN/Abool
1952567SN/ASparcSystem::breakpoint()
1962567SN/A{
1972567SN/A    panic("Need to implement");
1982567SN/A}
1992567SN/A
2002567SN/Avoid
2012567SN/ASparcSystem::serialize(std::ostream &os)
2022567SN/A{
2032567SN/A    System::serialize(os);
2042567SN/A    resetSymtab->serialize("reset_symtab", os);
2052567SN/A    hypervisorSymtab->serialize("hypervisor_symtab", os);
2062567SN/A    openbootSymtab->serialize("openboot_symtab", os);
2073745Sgblack@eecs.umich.edu    nvramSymtab->serialize("nvram_symtab", os);
2083745Sgblack@eecs.umich.edu    hypervisorDescSymtab->serialize("hypervisor_desc_symtab", os);
2093745Sgblack@eecs.umich.edu    partitionDescSymtab->serialize("partition_desc_symtab", os);
2102567SN/A}
2112567SN/A
2122567SN/A
2132567SN/Avoid
2142567SN/ASparcSystem::unserialize(Checkpoint *cp, const std::string &section)
2152567SN/A{
2162567SN/A    System::unserialize(cp,section);
2172567SN/A    resetSymtab->unserialize("reset_symtab", cp, section);
2182567SN/A    hypervisorSymtab->unserialize("hypervisor_symtab", cp, section);
2192567SN/A    openbootSymtab->unserialize("openboot_symtab", cp, section);
2203745Sgblack@eecs.umich.edu    nvramSymtab->unserialize("nvram_symtab", cp, section);
2213745Sgblack@eecs.umich.edu    hypervisorDescSymtab->unserialize("hypervisor_desc_symtab", cp, section);
2223745Sgblack@eecs.umich.edu    partitionDescSymtab->unserialize("partition_desc_symtab", cp, section);
2232567SN/A}
2242567SN/A
2252567SN/A
2262567SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(SparcSystem)
2272567SN/A
2282567SN/A    SimObjectParam<PhysicalMemory *> physmem;
2293584Ssaidi@eecs.umich.edu    SimObjectParam<PhysicalMemory *> rom;
2303745Sgblack@eecs.umich.edu    SimObjectParam<PhysicalMemory *> nvram;
2313745Sgblack@eecs.umich.edu    SimObjectParam<PhysicalMemory *> hypervisor_desc;
2323745Sgblack@eecs.umich.edu    SimObjectParam<PhysicalMemory *> partition_desc;
2332902Ssaidi@eecs.umich.edu    SimpleEnumParam<System::MemoryMode> mem_mode;
2342567SN/A
2353584Ssaidi@eecs.umich.edu    Param<Addr> reset_addr;
2363584Ssaidi@eecs.umich.edu    Param<Addr> hypervisor_addr;
2373584Ssaidi@eecs.umich.edu    Param<Addr> openboot_addr;
2383745Sgblack@eecs.umich.edu    Param<Addr> nvram_addr;
2393745Sgblack@eecs.umich.edu    Param<Addr> hypervisor_desc_addr;
2403745Sgblack@eecs.umich.edu    Param<Addr> partition_desc_addr;
2413584Ssaidi@eecs.umich.edu
2422567SN/A    Param<std::string> kernel;
2432567SN/A    Param<std::string> reset_bin;
2442567SN/A    Param<std::string> hypervisor_bin;
2452567SN/A    Param<std::string> openboot_bin;
2463745Sgblack@eecs.umich.edu    Param<std::string> nvram_bin;
2473745Sgblack@eecs.umich.edu    Param<std::string> hypervisor_desc_bin;
2483745Sgblack@eecs.umich.edu    Param<std::string> partition_desc_bin;
2492567SN/A
2503527Sgblack@eecs.umich.edu    Param<Tick> boot_cpu_frequency;
2512567SN/A    Param<std::string> boot_osflags;
2522567SN/A    Param<std::string> readfile;
2532567SN/A    Param<unsigned int> init_param;
2542567SN/A
2552567SN/AEND_DECLARE_SIM_OBJECT_PARAMS(SparcSystem)
2562567SN/A
2572567SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(SparcSystem)
2582567SN/A
2592567SN/A    INIT_PARAM(physmem, "phsyical memory"),
2603584Ssaidi@eecs.umich.edu    INIT_PARAM(rom, "ROM for boot code"),
2613745Sgblack@eecs.umich.edu    INIT_PARAM(nvram, "Non-volatile RAM for the nvram"),
2623745Sgblack@eecs.umich.edu    INIT_PARAM(hypervisor_desc, "ROM for the hypervisor description"),
2633745Sgblack@eecs.umich.edu    INIT_PARAM(partition_desc, "ROM for the partition description"),
2642902Ssaidi@eecs.umich.edu    INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)",
2652902Ssaidi@eecs.umich.edu            System::MemoryModeStrings),
2663584Ssaidi@eecs.umich.edu
2673584Ssaidi@eecs.umich.edu    INIT_PARAM(reset_addr, "Address that reset should be loaded at"),
2683584Ssaidi@eecs.umich.edu    INIT_PARAM(hypervisor_addr, "Address that hypervisor should be loaded at"),
2693584Ssaidi@eecs.umich.edu    INIT_PARAM(openboot_addr, "Address that openboot should be loaded at"),
2703745Sgblack@eecs.umich.edu    INIT_PARAM(nvram_addr, "Address that nvram should be loaded at"),
2713745Sgblack@eecs.umich.edu    INIT_PARAM(hypervisor_desc_addr,
2723745Sgblack@eecs.umich.edu            "Address that hypervisor description should be loaded at"),
2733745Sgblack@eecs.umich.edu    INIT_PARAM(partition_desc_addr,
2743745Sgblack@eecs.umich.edu            "Address that partition description should be loaded at"),
2753584Ssaidi@eecs.umich.edu
2762567SN/A    INIT_PARAM(kernel, "file that contains the kernel code"),
2772567SN/A    INIT_PARAM(reset_bin, "file that contains the reset code"),
2782567SN/A    INIT_PARAM(hypervisor_bin, "file that contains the hypervisor code"),
2792567SN/A    INIT_PARAM(openboot_bin, "file that contains the openboot code"),
2803745Sgblack@eecs.umich.edu    INIT_PARAM(nvram_bin, "file that contains the nvram image"),
2813745Sgblack@eecs.umich.edu    INIT_PARAM(hypervisor_desc_bin,
2823745Sgblack@eecs.umich.edu            "file that contains the hypervisor description image"),
2833745Sgblack@eecs.umich.edu    INIT_PARAM(partition_desc_bin,
2843745Sgblack@eecs.umich.edu            "file that contains the partition description image"),
2853527Sgblack@eecs.umich.edu    INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
2862567SN/A    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
2872567SN/A                    "a"),
2882567SN/A    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
2893527Sgblack@eecs.umich.edu    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0)
2902567SN/A
2912567SN/AEND_INIT_SIM_OBJECT_PARAMS(SparcSystem)
2922567SN/A
2932567SN/ACREATE_SIM_OBJECT(SparcSystem)
2942567SN/A{
2952567SN/A    SparcSystem::Params *p = new SparcSystem::Params;
2962567SN/A    p->name = getInstanceName();
2972567SN/A    p->boot_cpu_frequency = boot_cpu_frequency;
2982567SN/A    p->physmem = physmem;
2993584Ssaidi@eecs.umich.edu    p->rom = rom;
3003745Sgblack@eecs.umich.edu    p->nvram = nvram;
3013745Sgblack@eecs.umich.edu    p->hypervisor_desc = hypervisor_desc;
3023745Sgblack@eecs.umich.edu    p->partition_desc = partition_desc;
3032902Ssaidi@eecs.umich.edu    p->mem_mode = mem_mode;
3042567SN/A    p->kernel_path = kernel;
3053584Ssaidi@eecs.umich.edu    p->reset_addr = reset_addr;
3063584Ssaidi@eecs.umich.edu    p->hypervisor_addr = hypervisor_addr;
3073584Ssaidi@eecs.umich.edu    p->openboot_addr = openboot_addr;
3083745Sgblack@eecs.umich.edu    p->nvram_addr = nvram_addr;
3093745Sgblack@eecs.umich.edu    p->hypervisor_desc_addr = hypervisor_desc_addr;
3103745Sgblack@eecs.umich.edu    p->partition_desc_addr = partition_desc_addr;
3112567SN/A    p->reset_bin = reset_bin;
3122567SN/A    p->hypervisor_bin = hypervisor_bin;
3132567SN/A    p->openboot_bin = openboot_bin;
3143745Sgblack@eecs.umich.edu    p->nvram_bin = nvram_bin;
3153745Sgblack@eecs.umich.edu    p->hypervisor_desc_bin = hypervisor_desc_bin;
3163745Sgblack@eecs.umich.edu    p->partition_desc_bin = partition_desc_bin;
3172567SN/A    p->boot_osflags = boot_osflags;
3182567SN/A    p->init_param = init_param;
3192567SN/A    p->readfile = readfile;
3202567SN/A    return new SparcSystem(p);
3212567SN/A}
3222567SN/A
3232567SN/AREGISTER_SIM_OBJECT("SparcSystem", SparcSystem)
3242567SN/A
3252567SN/A
326