system.cc revision 5222
112855Sgabeblack@google.com/*
212855Sgabeblack@google.com * Copyright (c) 2002-2006 The Regents of The University of Michigan
312855Sgabeblack@google.com * All rights reserved.
412855Sgabeblack@google.com *
512855Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612855Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712855Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912855Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012855Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112855Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212855Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312855Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412855Sgabeblack@google.com * this software without specific prior written permission.
1512855Sgabeblack@google.com *
1612855Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712855Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812855Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912855Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012855Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112855Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212855Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312855Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412855Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512855Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612855Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712855Sgabeblack@google.com *
2812855Sgabeblack@google.com * Authors: Ali Saidi
2912855Sgabeblack@google.com */
3012855Sgabeblack@google.com
3112855Sgabeblack@google.com#include "arch/sparc/system.hh"
3212855Sgabeblack@google.com#include "arch/vtophys.hh"
3312855Sgabeblack@google.com#include "base/remote_gdb.hh"
3412855Sgabeblack@google.com#include "base/loader/object_file.hh"
3512855Sgabeblack@google.com#include "base/loader/symtab.hh"
3612855Sgabeblack@google.com#include "base/trace.hh"
3712855Sgabeblack@google.com#include "mem/physical.hh"
3812855Sgabeblack@google.com#include "params/SparcSystem.hh"
3912855Sgabeblack@google.com#include "sim/byteswap.hh"
4012855Sgabeblack@google.com
4112855Sgabeblack@google.com
4212855Sgabeblack@google.comusing namespace BigEndianGuest;
4312855Sgabeblack@google.com
4412855Sgabeblack@google.comSparcSystem::SparcSystem(Params *p)
4512855Sgabeblack@google.com    : System(p), sysTick(0),funcRomPort(p->name + "-fromport"),
4612855Sgabeblack@google.com    funcNvramPort(p->name + "-fnvramport"),
4712855Sgabeblack@google.com    funcHypDescPort(p->name + "-fhypdescport"),
4812855Sgabeblack@google.com    funcPartDescPort(p->name + "-fpartdescport")
4912855Sgabeblack@google.com{
5012855Sgabeblack@google.com    resetSymtab = new SymbolTable;
5112855Sgabeblack@google.com    hypervisorSymtab = new SymbolTable;
5212855Sgabeblack@google.com    openbootSymtab = new SymbolTable;
5312855Sgabeblack@google.com    nvramSymtab = new SymbolTable;
5412855Sgabeblack@google.com    hypervisorDescSymtab = new SymbolTable;
5512855Sgabeblack@google.com    partitionDescSymtab = new SymbolTable;
5612855Sgabeblack@google.com
5712855Sgabeblack@google.com    Port *rom_port;
5812855Sgabeblack@google.com    rom_port = params()->rom->getPort("functional");
5912855Sgabeblack@google.com    funcRomPort.setPeer(rom_port);
6012855Sgabeblack@google.com    rom_port->setPeer(&funcRomPort);
6112855Sgabeblack@google.com
6212855Sgabeblack@google.com    rom_port = params()->nvram->getPort("functional");
6312855Sgabeblack@google.com    funcNvramPort.setPeer(rom_port);
6412855Sgabeblack@google.com    rom_port->setPeer(&funcNvramPort);
6512855Sgabeblack@google.com
6612855Sgabeblack@google.com    rom_port = params()->hypervisor_desc->getPort("functional");
6712855Sgabeblack@google.com    funcHypDescPort.setPeer(rom_port);
6812855Sgabeblack@google.com    rom_port->setPeer(&funcHypDescPort);
6912855Sgabeblack@google.com
7012855Sgabeblack@google.com    rom_port = params()->partition_desc->getPort("functional");
7112855Sgabeblack@google.com    funcPartDescPort.setPeer(rom_port);
7212855Sgabeblack@google.com    rom_port->setPeer(&funcPartDescPort);
7312855Sgabeblack@google.com
7412855Sgabeblack@google.com    /**
7512855Sgabeblack@google.com     * Load the boot code, and hypervisor into memory.
7612855Sgabeblack@google.com     */
7712855Sgabeblack@google.com    // Read the reset binary
7812855Sgabeblack@google.com    reset = createObjectFile(params()->reset_bin, true);
7912855Sgabeblack@google.com    if (reset == NULL)
8012855Sgabeblack@google.com        fatal("Could not load reset binary %s", params()->reset_bin);
8112855Sgabeblack@google.com
8212855Sgabeblack@google.com    // Read the openboot binary
8312855Sgabeblack@google.com    openboot = createObjectFile(params()->openboot_bin, true);
8412855Sgabeblack@google.com    if (openboot == NULL)
8512855Sgabeblack@google.com        fatal("Could not load openboot bianry %s", params()->openboot_bin);
8612855Sgabeblack@google.com
8712855Sgabeblack@google.com    // Read the hypervisor binary
8812855Sgabeblack@google.com    hypervisor = createObjectFile(params()->hypervisor_bin, true);
8912855Sgabeblack@google.com    if (hypervisor == NULL)
9012855Sgabeblack@google.com        fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
9112855Sgabeblack@google.com
9212855Sgabeblack@google.com    // Read the nvram image
9312855Sgabeblack@google.com    nvram = createObjectFile(params()->nvram_bin, true);
9412855Sgabeblack@google.com    if (nvram == NULL)
9512855Sgabeblack@google.com        fatal("Could not load nvram image %s", params()->nvram_bin);
9612855Sgabeblack@google.com
9712855Sgabeblack@google.com    // Read the hypervisor description image
9812855Sgabeblack@google.com    hypervisor_desc = createObjectFile(params()->hypervisor_desc_bin, true);
9912855Sgabeblack@google.com    if (hypervisor_desc == NULL)
10012855Sgabeblack@google.com        fatal("Could not load hypervisor description image %s",
10112855Sgabeblack@google.com                params()->hypervisor_desc_bin);
10212855Sgabeblack@google.com
10312855Sgabeblack@google.com    // Read the partition description image
10412855Sgabeblack@google.com    partition_desc = createObjectFile(params()->partition_desc_bin, true);
10512855Sgabeblack@google.com    if (partition_desc == NULL)
10612855Sgabeblack@google.com        fatal("Could not load partition description image %s",
10712855Sgabeblack@google.com                params()->partition_desc_bin);
10812855Sgabeblack@google.com
10912855Sgabeblack@google.com
11012855Sgabeblack@google.com    // Load reset binary into memory
11112855Sgabeblack@google.com    reset->setTextBase(params()->reset_addr);
11212855Sgabeblack@google.com    reset->loadSections(&funcRomPort);
11312855Sgabeblack@google.com    // Load the openboot binary
11412855Sgabeblack@google.com    openboot->setTextBase(params()->openboot_addr);
11512855Sgabeblack@google.com    openboot->loadSections(&funcRomPort);
11612855Sgabeblack@google.com    // Load the hypervisor binary
11712855Sgabeblack@google.com    hypervisor->setTextBase(params()->hypervisor_addr);
11812855Sgabeblack@google.com    hypervisor->loadSections(&funcRomPort);
11912855Sgabeblack@google.com    // Load the nvram image
12012855Sgabeblack@google.com    nvram->setTextBase(params()->nvram_addr);
12112855Sgabeblack@google.com    nvram->loadSections(&funcNvramPort);
12212855Sgabeblack@google.com    // Load the hypervisor description image
12312855Sgabeblack@google.com    hypervisor_desc->setTextBase(params()->hypervisor_desc_addr);
12412855Sgabeblack@google.com    hypervisor_desc->loadSections(&funcHypDescPort);
12512855Sgabeblack@google.com    // Load the partition description image
12612855Sgabeblack@google.com    partition_desc->setTextBase(params()->partition_desc_addr);
12712855Sgabeblack@google.com    partition_desc->loadSections(&funcPartDescPort);
12812855Sgabeblack@google.com
12912855Sgabeblack@google.com    // load symbols
13012855Sgabeblack@google.com    if (!reset->loadGlobalSymbols(resetSymtab))
13112855Sgabeblack@google.com        panic("could not load reset symbols\n");
13212855Sgabeblack@google.com
13312855Sgabeblack@google.com    if (!openboot->loadGlobalSymbols(openbootSymtab))
13412855Sgabeblack@google.com        panic("could not load openboot symbols\n");
13512855Sgabeblack@google.com
13612855Sgabeblack@google.com    if (!hypervisor->loadLocalSymbols(hypervisorSymtab))
13712855Sgabeblack@google.com        panic("could not load hypervisor symbols\n");
13812855Sgabeblack@google.com
13912855Sgabeblack@google.com    if (!nvram->loadLocalSymbols(nvramSymtab))
14012855Sgabeblack@google.com        panic("could not load nvram symbols\n");
14112855Sgabeblack@google.com
14212855Sgabeblack@google.com    if (!hypervisor_desc->loadLocalSymbols(hypervisorDescSymtab))
14312855Sgabeblack@google.com        panic("could not load hypervisor description symbols\n");
14412855Sgabeblack@google.com
14512855Sgabeblack@google.com    if (!partition_desc->loadLocalSymbols(partitionDescSymtab))
14612855Sgabeblack@google.com        panic("could not load partition description symbols\n");
14712855Sgabeblack@google.com
14812855Sgabeblack@google.com    // load symbols into debug table
14912855Sgabeblack@google.com    if (!reset->loadGlobalSymbols(debugSymbolTable))
15012855Sgabeblack@google.com        panic("could not load reset symbols\n");
15112855Sgabeblack@google.com
15212855Sgabeblack@google.com    if (!openboot->loadGlobalSymbols(debugSymbolTable))
15312855Sgabeblack@google.com        panic("could not load openboot symbols\n");
15412855Sgabeblack@google.com
15512855Sgabeblack@google.com    if (!hypervisor->loadLocalSymbols(debugSymbolTable))
15612855Sgabeblack@google.com        panic("could not load hypervisor symbols\n");
15712855Sgabeblack@google.com
158    // Strip off the rom address so when the hypervisor is copied into memory we
159    // have symbols still
160    if (!hypervisor->loadLocalSymbols(debugSymbolTable, 0xFFFFFF))
161        panic("could not load hypervisor symbols\n");
162
163    if (!nvram->loadGlobalSymbols(debugSymbolTable))
164        panic("could not load reset symbols\n");
165
166    if (!hypervisor_desc->loadGlobalSymbols(debugSymbolTable))
167        panic("could not load hypervisor description symbols\n");
168
169    if (!partition_desc->loadLocalSymbols(debugSymbolTable))
170        panic("could not load partition description symbols\n");
171
172
173    // @todo any fixup code over writing data in binaries on setting break
174    // events on functions should happen here.
175
176}
177
178SparcSystem::~SparcSystem()
179{
180    delete resetSymtab;
181    delete hypervisorSymtab;
182    delete openbootSymtab;
183    delete nvramSymtab;
184    delete hypervisorDescSymtab;
185    delete partitionDescSymtab;
186    delete reset;
187    delete openboot;
188    delete hypervisor;
189    delete nvram;
190    delete hypervisor_desc;
191    delete partition_desc;
192}
193
194void
195SparcSystem::serialize(std::ostream &os)
196{
197    System::serialize(os);
198    resetSymtab->serialize("reset_symtab", os);
199    hypervisorSymtab->serialize("hypervisor_symtab", os);
200    openbootSymtab->serialize("openboot_symtab", os);
201    nvramSymtab->serialize("nvram_symtab", os);
202    hypervisorDescSymtab->serialize("hypervisor_desc_symtab", os);
203    partitionDescSymtab->serialize("partition_desc_symtab", os);
204}
205
206
207void
208SparcSystem::unserialize(Checkpoint *cp, const std::string &section)
209{
210    System::unserialize(cp,section);
211    resetSymtab->unserialize("reset_symtab", cp, section);
212    hypervisorSymtab->unserialize("hypervisor_symtab", cp, section);
213    openbootSymtab->unserialize("openboot_symtab", cp, section);
214    nvramSymtab->unserialize("nvram_symtab", cp, section);
215    hypervisorDescSymtab->unserialize("hypervisor_desc_symtab", cp, section);
216    partitionDescSymtab->unserialize("partition_desc_symtab", cp, section);
217}
218
219SparcSystem *
220SparcSystemParams::create()
221{
222    return new SparcSystem(this);
223}
224