system.cc revision 5612
13534Sgblack@eecs.umich.edu/*
23534Sgblack@eecs.umich.edu * Copyright (c) 2002-2006 The Regents of The University of Michigan
33534Sgblack@eecs.umich.edu * All rights reserved.
43534Sgblack@eecs.umich.edu *
53534Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
63534Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
73534Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
83534Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
93534Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
103534Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
113534Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
123534Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
133534Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
143534Sgblack@eecs.umich.edu * this software without specific prior written permission.
153534Sgblack@eecs.umich.edu *
163534Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
173534Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
183534Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
193534Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
203534Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
213534Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
223534Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
233534Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
243534Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
253534Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
263534Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
273534Sgblack@eecs.umich.edu *
283534Sgblack@eecs.umich.edu * Authors: Ali Saidi
293534Sgblack@eecs.umich.edu */
303534Sgblack@eecs.umich.edu
313534Sgblack@eecs.umich.edu#include "arch/sparc/system.hh"
324202Sbinkertn@umich.edu#include "arch/vtophys.hh"
333534Sgblack@eecs.umich.edu#include "base/remote_gdb.hh"
344202Sbinkertn@umich.edu#include "base/loader/object_file.hh"
354486Sbinkertn@umich.edu#include "base/loader/symtab.hh"
365794Ssaidi@eecs.umich.edu#include "base/trace.hh"
374486Sbinkertn@umich.edu#include "mem/physical.hh"
384486Sbinkertn@umich.edu#include "params/SparcSystem.hh"
394486Sbinkertn@umich.edu#include "sim/byteswap.hh"
404486Sbinkertn@umich.edu
414486Sbinkertn@umich.edu
424486Sbinkertn@umich.eduusing namespace BigEndianGuest;
434486Sbinkertn@umich.edu
445478Snate@binkert.orgSparcSystem::SparcSystem(Params *p)
454486Sbinkertn@umich.edu    : System(p), sysTick(0),funcRomPort(p->name + "-fromport"),
464486Sbinkertn@umich.edu    funcNvramPort(p->name + "-fnvramport"),
474202Sbinkertn@umich.edu    funcHypDescPort(p->name + "-fhypdescport"),
485794Ssaidi@eecs.umich.edu    funcPartDescPort(p->name + "-fpartdescport")
494202Sbinkertn@umich.edu{
504202Sbinkertn@umich.edu    resetSymtab = new SymbolTable;
515485Snate@binkert.org    hypervisorSymtab = new SymbolTable;
524202Sbinkertn@umich.edu    openbootSymtab = new SymbolTable;
534202Sbinkertn@umich.edu    nvramSymtab = new SymbolTable;
544202Sbinkertn@umich.edu    hypervisorDescSymtab = new SymbolTable;
554202Sbinkertn@umich.edu    partitionDescSymtab = new SymbolTable;
564762Snate@binkert.org
574218Ssaidi@eecs.umich.edu    Port *rom_port;
584202Sbinkertn@umich.edu    rom_port = params()->rom->getPort("functional");
594202Sbinkertn@umich.edu    funcRomPort.setPeer(rom_port);
605443Sgblack@eecs.umich.edu    rom_port->setPeer(&funcRomPort);
614202Sbinkertn@umich.edu
624202Sbinkertn@umich.edu    rom_port = params()->nvram->getPort("functional");
635392Sgblack@eecs.umich.edu    funcNvramPort.setPeer(rom_port);
644202Sbinkertn@umich.edu    rom_port->setPeer(&funcNvramPort);
654202Sbinkertn@umich.edu
664202Sbinkertn@umich.edu    rom_port = params()->hypervisor_desc->getPort("functional");
674202Sbinkertn@umich.edu    funcHypDescPort.setPeer(rom_port);
684202Sbinkertn@umich.edu    rom_port->setPeer(&funcHypDescPort);
694202Sbinkertn@umich.edu
704762Snate@binkert.org    rom_port = params()->partition_desc->getPort("functional");
715478Snate@binkert.org    funcPartDescPort.setPeer(rom_port);
724202Sbinkertn@umich.edu    rom_port->setPeer(&funcPartDescPort);
734202Sbinkertn@umich.edu
745192Ssaidi@eecs.umich.edu    /**
755192Ssaidi@eecs.umich.edu     * Load the boot code, and hypervisor into memory.
765192Ssaidi@eecs.umich.edu     */
775192Ssaidi@eecs.umich.edu    // Read the reset binary
785794Ssaidi@eecs.umich.edu    reset = createObjectFile(params()->reset_bin, true);
795192Ssaidi@eecs.umich.edu    if (reset == NULL)
805192Ssaidi@eecs.umich.edu        fatal("Could not load reset binary %s", params()->reset_bin);
815192Ssaidi@eecs.umich.edu
825192Ssaidi@eecs.umich.edu    // Read the openboot binary
835192Ssaidi@eecs.umich.edu    openboot = createObjectFile(params()->openboot_bin, true);
845192Ssaidi@eecs.umich.edu    if (openboot == NULL)
855192Ssaidi@eecs.umich.edu        fatal("Could not load openboot bianry %s", params()->openboot_bin);
865192Ssaidi@eecs.umich.edu
875192Ssaidi@eecs.umich.edu    // Read the hypervisor binary
885192Ssaidi@eecs.umich.edu    hypervisor = createObjectFile(params()->hypervisor_bin, true);
895192Ssaidi@eecs.umich.edu    if (hypervisor == NULL)
905443Sgblack@eecs.umich.edu        fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
915192Ssaidi@eecs.umich.edu
925392Sgblack@eecs.umich.edu    // Read the nvram image
935192Ssaidi@eecs.umich.edu    nvram = createObjectFile(params()->nvram_bin, true);
945192Ssaidi@eecs.umich.edu    if (nvram == NULL)
955192Ssaidi@eecs.umich.edu        fatal("Could not load nvram image %s", params()->nvram_bin);
965192Ssaidi@eecs.umich.edu
975478Snate@binkert.org    // Read the hypervisor description image
985478Snate@binkert.org    hypervisor_desc = createObjectFile(params()->hypervisor_desc_bin, true);
995192Ssaidi@eecs.umich.edu    if (hypervisor_desc == NULL)
1005192Ssaidi@eecs.umich.edu        fatal("Could not load hypervisor description image %s",
1015192Ssaidi@eecs.umich.edu                params()->hypervisor_desc_bin);
1025192Ssaidi@eecs.umich.edu
1035192Ssaidi@eecs.umich.edu    // Read the partition description image
1045763Ssaidi@eecs.umich.edu    partition_desc = createObjectFile(params()->partition_desc_bin, true);
1055192Ssaidi@eecs.umich.edu    if (partition_desc == NULL)
1065192Ssaidi@eecs.umich.edu        fatal("Could not load partition description image %s",
1075192Ssaidi@eecs.umich.edu                params()->partition_desc_bin);
1085192Ssaidi@eecs.umich.edu
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