system.cc revision 6220
16700Snate@binkert.org/*
26700Snate@binkert.org * Copyright (c) 2002-2006 The Regents of The University of Michigan
36700Snate@binkert.org * All rights reserved.
46700Snate@binkert.org *
56700Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66700Snate@binkert.org * modification, are permitted provided that the following conditions are
76700Snate@binkert.org * met: redistributions of source code must retain the above copyright
86700Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96700Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106700Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116700Snate@binkert.org * documentation and/or other materials provided with the distribution;
126700Snate@binkert.org * neither the name of the copyright holders nor the names of its
136700Snate@binkert.org * contributors may be used to endorse or promote products derived from
146700Snate@binkert.org * this software without specific prior written permission.
156700Snate@binkert.org *
166700Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176700Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186700Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196700Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206700Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216700Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226700Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236700Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246700Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256700Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266700Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276700Snate@binkert.org *
286285Snate@binkert.org * Authors: Ali Saidi
297805Snilay@cs.wisc.edu */
306285Snate@binkert.org
316285Snate@binkert.org#include "arch/sparc/system.hh"
328255SBrad.Beckmann@amd.com#include "arch/vtophys.hh"
338645Snilay@cs.wisc.edu#include "base/remote_gdb.hh"
346285Snate@binkert.org#include "base/loader/object_file.hh"
356876Ssteve.reinhardt@amd.com#include "base/loader/symtab.hh"
366876Ssteve.reinhardt@amd.com#include "base/trace.hh"
376285Snate@binkert.org#include "mem/physical.hh"
386876Ssteve.reinhardt@amd.com#include "params/SparcSystem.hh"
396876Ssteve.reinhardt@amd.com#include "sim/byteswap.hh"
406876Ssteve.reinhardt@amd.com
416876Ssteve.reinhardt@amd.com
426881SBrad.Beckmann@amd.comusing namespace BigEndianGuest;
436881SBrad.Beckmann@amd.com
447054Snate@binkert.orgSparcSystem::SparcSystem(Params *p)
456881SBrad.Beckmann@amd.com    : System(p), sysTick(0),funcRomPort(p->name + "-fromport"),
466881SBrad.Beckmann@amd.com    funcNvramPort(p->name + "-fnvramport"),
476876Ssteve.reinhardt@amd.com    funcHypDescPort(p->name + "-fhypdescport"),
486876Ssteve.reinhardt@amd.com    funcPartDescPort(p->name + "-fpartdescport")
496881SBrad.Beckmann@amd.com{
506881SBrad.Beckmann@amd.com    resetSymtab = new SymbolTable;
516881SBrad.Beckmann@amd.com    hypervisorSymtab = new SymbolTable;
528436SBrad.Beckmann@amd.com    openbootSymtab = new SymbolTable;
536285Snate@binkert.org    nvramSymtab = new SymbolTable;
546285Snate@binkert.org    hypervisorDescSymtab = new SymbolTable;
557054Snate@binkert.org    partitionDescSymtab = new SymbolTable;
567054Snate@binkert.org
576285Snate@binkert.org    Port *rom_port;
587054Snate@binkert.org    rom_port = params()->rom->getPort("functional");
596285Snate@binkert.org    funcRomPort.setPeer(rom_port);
606493STushar.Krishna@amd.com    rom_port->setPeer(&funcRomPort);
617054Snate@binkert.org
627054Snate@binkert.org    rom_port = params()->nvram->getPort("functional");
636493STushar.Krishna@amd.com    funcNvramPort.setPeer(rom_port);
647054Snate@binkert.org    rom_port->setPeer(&funcNvramPort);
657054Snate@binkert.org
667805Snilay@cs.wisc.edu    rom_port = params()->hypervisor_desc->getPort("functional");
677054Snate@binkert.org    funcHypDescPort.setPeer(rom_port);
687054Snate@binkert.org    rom_port->setPeer(&funcHypDescPort);
697054Snate@binkert.org
707054Snate@binkert.org    rom_port = params()->partition_desc->getPort("functional");
717054Snate@binkert.org    funcPartDescPort.setPeer(rom_port);
727054Snate@binkert.org    rom_port->setPeer(&funcPartDescPort);
737548SBrad.Beckmann@amd.com
747904SBrad.Beckmann@amd.com    /**
757054Snate@binkert.org     * Load the boot code, and hypervisor into memory.
767054Snate@binkert.org     */
777054Snate@binkert.org    // Read the reset binary
787054Snate@binkert.org    reset = createObjectFile(params()->reset_bin, true);
797054Snate@binkert.org    if (reset == NULL)
807054Snate@binkert.org        fatal("Could not load reset binary %s", params()->reset_bin);
817054Snate@binkert.org
827054Snate@binkert.org    // Read the openboot binary
837054Snate@binkert.org    openboot = createObjectFile(params()->openboot_bin, true);
847054Snate@binkert.org    if (openboot == NULL)
857054Snate@binkert.org        fatal("Could not load openboot bianry %s", params()->openboot_bin);
867054Snate@binkert.org
877054Snate@binkert.org    // Read the hypervisor binary
887805Snilay@cs.wisc.edu    hypervisor = createObjectFile(params()->hypervisor_bin, true);
897054Snate@binkert.org    if (hypervisor == NULL)
907054Snate@binkert.org        fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
916493STushar.Krishna@amd.com
927054Snate@binkert.org    // Read the nvram image
937454Snate@binkert.org    nvram = createObjectFile(params()->nvram_bin, true);
947054Snate@binkert.org    if (nvram == NULL)
957054Snate@binkert.org        fatal("Could not load nvram image %s", params()->nvram_bin);
967054Snate@binkert.org
977054Snate@binkert.org    // Read the hypervisor description image
98    hypervisor_desc = createObjectFile(params()->hypervisor_desc_bin, true);
99    if (hypervisor_desc == NULL)
100        fatal("Could not load hypervisor description image %s",
101                params()->hypervisor_desc_bin);
102
103    // Read the partition description image
104    partition_desc = createObjectFile(params()->partition_desc_bin, true);
105    if (partition_desc == NULL)
106        fatal("Could not load partition description image %s",
107                params()->partition_desc_bin);
108
109
110    // Load reset binary into memory
111    reset->setTextBase(params()->reset_addr);
112    reset->loadSections(&funcRomPort);
113    // Load the openboot binary
114    openboot->setTextBase(params()->openboot_addr);
115    openboot->loadSections(&funcRomPort);
116    // Load the hypervisor binary
117    hypervisor->setTextBase(params()->hypervisor_addr);
118    hypervisor->loadSections(&funcRomPort);
119    // Load the nvram image
120    nvram->setTextBase(params()->nvram_addr);
121    nvram->loadSections(&funcNvramPort);
122    // Load the hypervisor description image
123    hypervisor_desc->setTextBase(params()->hypervisor_desc_addr);
124    hypervisor_desc->loadSections(&funcHypDescPort);
125    // Load the partition description image
126    partition_desc->setTextBase(params()->partition_desc_addr);
127    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