system.cc revision 5268
12139SN/A/*
22139SN/A * Copyright (c) 2002-2006 The Regents of The University of Michigan
32139SN/A * All rights reserved.
42139SN/A *
52139SN/A * Redistribution and use in source and binary forms, with or without
62139SN/A * modification, are permitted provided that the following conditions are
72139SN/A * met: redistributions of source code must retain the above copyright
82139SN/A * notice, this list of conditions and the following disclaimer;
92139SN/A * redistributions in binary form must reproduce the above copyright
102139SN/A * notice, this list of conditions and the following disclaimer in the
112139SN/A * documentation and/or other materials provided with the distribution;
122139SN/A * neither the name of the copyright holders nor the names of its
132139SN/A * contributors may be used to endorse or promote products derived from
142139SN/A * this software without specific prior written permission.
152139SN/A *
162139SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172139SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182139SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192139SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202139SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212139SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222139SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232139SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242139SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252139SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262139SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272139SN/A *
282665Ssaidi@eecs.umich.edu * Authors: Ali Saidi
292665Ssaidi@eecs.umich.edu */
302139SN/A
314202Sbinkertn@umich.edu#include "arch/sparc/system.hh"
322139SN/A#include "arch/vtophys.hh"
334202Sbinkertn@umich.edu#include "base/remote_gdb.hh"
342152SN/A#include "base/loader/object_file.hh"
352152SN/A#include "base/loader/symtab.hh"
362139SN/A#include "base/trace.hh"
372139SN/A#include "mem/physical.hh"
382139SN/A#include "params/SparcSystem.hh"
392139SN/A#include "sim/byteswap.hh"
402139SN/A
412152SN/A
422152SN/Ausing namespace BigEndianGuest;
432139SN/A
442139SN/ASparcSystem::SparcSystem(Params *p)
452139SN/A    : System(p), sysTick(0),funcRomPort(p->name + "-fromport"),
462984Sgblack@eecs.umich.edu    funcNvramPort(p->name + "-fnvramport"),
472439SN/A    funcHypDescPort(p->name + "-fhypdescport"),
483520Sgblack@eecs.umich.edu    funcPartDescPort(p->name + "-fpartdescport")
492139SN/A{
503565Sgblack@eecs.umich.edu    resetSymtab = new SymbolTable;
513170Sstever@eecs.umich.edu    hypervisorSymtab = new SymbolTable;
523806Ssaidi@eecs.umich.edu    openbootSymtab = new SymbolTable;
532439SN/A    nvramSymtab = new SymbolTable;
544182Sgblack@eecs.umich.edu    hypervisorDescSymtab = new SymbolTable;
552460SN/A    partitionDescSymtab = new SymbolTable;
563536Sgblack@eecs.umich.edu
572439SN/A    Port *rom_port;
582972Sgblack@eecs.umich.edu    rom_port = params()->rom->getPort("functional");
592171SN/A    funcRomPort.setPeer(rom_port);
602439SN/A    rom_port->setPeer(&funcRomPort);
612439SN/A
622170SN/A    rom_port = params()->nvram->getPort("functional");
632139SN/A    funcNvramPort.setPeer(rom_port);
642139SN/A    rom_port->setPeer(&funcNvramPort);
653546Sgblack@eecs.umich.edu
664202Sbinkertn@umich.edu    rom_port = params()->hypervisor_desc->getPort("functional");
672152SN/A    funcHypDescPort.setPeer(rom_port);
682152SN/A    rom_port->setPeer(&funcHypDescPort);
692152SN/A
702152SN/A    rom_port = params()->partition_desc->getPort("functional");
712152SN/A    funcPartDescPort.setPeer(rom_port);
722152SN/A    rom_port->setPeer(&funcPartDescPort);
732152SN/A
742152SN/A    /**
752152SN/A     * Load the boot code, and hypervisor into memory.
762152SN/A     */
772152SN/A    // Read the reset binary
782152SN/A    reset = createObjectFile(params()->reset_bin, true);
792504SN/A    if (reset == NULL)
802504SN/A        fatal("Could not load reset binary %s", params()->reset_bin);
812504SN/A
822504SN/A    // Read the openboot binary
832152SN/A    openboot = createObjectFile(params()->openboot_bin, true);
842504SN/A    if (openboot == NULL)
852152SN/A        fatal("Could not load openboot bianry %s", params()->openboot_bin);
862152SN/A
872152SN/A    // Read the hypervisor binary
882152SN/A    hypervisor = createObjectFile(params()->hypervisor_bin, true);
892152SN/A    if (hypervisor == NULL)
902152SN/A        fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
912152SN/A
922152SN/A    // Read the nvram image
932632Sstever@eecs.umich.edu    nvram = createObjectFile(params()->nvram_bin, true);
942155SN/A    if (nvram == NULL)
952155SN/A        fatal("Could not load nvram image %s", params()->nvram_bin);
962155SN/A
972155SN/A    // Read the hypervisor description image
982155SN/A    hypervisor_desc = createObjectFile(params()->hypervisor_desc_bin, true);
992155SN/A    if (hypervisor_desc == NULL)
1004202Sbinkertn@umich.edu        fatal("Could not load hypervisor description image %s",
1012155SN/A                params()->hypervisor_desc_bin);
1022155SN/A
1032155SN/A    // Read the partition description image
1042152SN/A    partition_desc = createObjectFile(params()->partition_desc_bin, true);
1052766Sktlim@umich.edu    if (partition_desc == NULL)
1062766Sktlim@umich.edu        fatal("Could not load partition description image %s",
1072766Sktlim@umich.edu                params()->partition_desc_bin);
1082766Sktlim@umich.edu
1092766Sktlim@umich.edu
1102152SN/A    // Load reset binary into memory
1112152SN/A    reset->setTextBase(params()->reset_addr);
1122152SN/A    reset->loadSections(&funcRomPort);
1132155SN/A    // Load the openboot binary
1142152SN/A    openboot->setTextBase(params()->openboot_addr);
1152152SN/A    openboot->loadSections(&funcRomPort);
1162718Sstever@eecs.umich.edu    // Load the hypervisor binary
1172921Sktlim@umich.edu    hypervisor->setTextBase(params()->hypervisor_addr);
1182921Sktlim@umich.edu    hypervisor->loadSections(&funcRomPort);
1192921Sktlim@umich.edu    // Load the nvram image
1202921Sktlim@umich.edu    nvram->setTextBase(params()->nvram_addr);
1212921Sktlim@umich.edu    nvram->loadSections(&funcNvramPort);
1222921Sktlim@umich.edu    // Load the hypervisor description image
1232921Sktlim@umich.edu    hypervisor_desc->setTextBase(params()->hypervisor_desc_addr);
1242921Sktlim@umich.edu    hypervisor_desc->loadSections(&funcHypDescPort);
1252921Sktlim@umich.edu    // Load the partition description image
1262152SN/A    partition_desc->setTextBase(params()->partition_desc_addr);
1272152SN/A    partition_desc->loadSections(&funcPartDescPort);
128
129    // load symbols
130    if (!reset->loadGlobalSymbols(resetSymtab))
131        panic("could not load reset symbols\n");
132
133    if (!openboot->loadGlobalSymbols(openbootSymtab))
134        panic("could not load openboot symbols\n");
135
136    if (!hypervisor->loadLocalSymbols(hypervisorSymtab))
137        panic("could not load hypervisor symbols\n");
138
139    if (!nvram->loadLocalSymbols(nvramSymtab))
140        panic("could not load nvram symbols\n");
141
142    if (!hypervisor_desc->loadLocalSymbols(hypervisorDescSymtab))
143        panic("could not load hypervisor description symbols\n");
144
145    if (!partition_desc->loadLocalSymbols(partitionDescSymtab))
146        panic("could not load partition description symbols\n");
147
148    // load symbols into debug table
149    if (!reset->loadGlobalSymbols(debugSymbolTable))
150        panic("could not load reset symbols\n");
151
152    if (!openboot->loadGlobalSymbols(debugSymbolTable))
153        panic("could not load openboot symbols\n");
154
155    if (!hypervisor->loadLocalSymbols(debugSymbolTable))
156        panic("could not load hypervisor symbols\n");
157
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