system.cc revision 8706
1/*
2 * Copyright (c) 2002-2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ali Saidi
29 */
30
31#include "arch/sparc/system.hh"
32#include "arch/vtophys.hh"
33#include "base/loader/object_file.hh"
34#include "base/loader/symtab.hh"
35#include "base/trace.hh"
36#include "mem/physical.hh"
37#include "params/SparcSystem.hh"
38#include "sim/byteswap.hh"
39
40using namespace BigEndianGuest;
41
42SparcSystem::SparcSystem(Params *p)
43    : System(p), sysTick(0)
44{
45    resetSymtab = new SymbolTable;
46    hypervisorSymtab = new SymbolTable;
47    openbootSymtab = new SymbolTable;
48    nvramSymtab = new SymbolTable;
49    hypervisorDescSymtab = new SymbolTable;
50    partitionDescSymtab = new SymbolTable;
51}
52
53void
54SparcSystem::initState()
55{
56    // Call the initialisation of the super class
57    System::initState();
58
59    /**
60     * Load the boot code, and hypervisor into memory.
61     */
62    // Read the reset binary
63    reset = createObjectFile(params()->reset_bin, true);
64    if (reset == NULL)
65        fatal("Could not load reset binary %s", params()->reset_bin);
66
67    // Read the openboot binary
68    openboot = createObjectFile(params()->openboot_bin, true);
69    if (openboot == NULL)
70        fatal("Could not load openboot bianry %s", params()->openboot_bin);
71
72    // Read the hypervisor binary
73    hypervisor = createObjectFile(params()->hypervisor_bin, true);
74    if (hypervisor == NULL)
75        fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
76
77    // Read the nvram image
78    nvram = createObjectFile(params()->nvram_bin, true);
79    if (nvram == NULL)
80        fatal("Could not load nvram image %s", params()->nvram_bin);
81
82    // Read the hypervisor description image
83    hypervisor_desc = createObjectFile(params()->hypervisor_desc_bin, true);
84    if (hypervisor_desc == NULL)
85        fatal("Could not load hypervisor description image %s",
86                params()->hypervisor_desc_bin);
87
88    // Read the partition description image
89    partition_desc = createObjectFile(params()->partition_desc_bin, true);
90    if (partition_desc == NULL)
91        fatal("Could not load partition description image %s",
92                params()->partition_desc_bin);
93
94
95    // Load reset binary into memory
96    reset->setTextBase(params()->reset_addr);
97    reset->loadSections(physProxy);
98    // Load the openboot binary
99    openboot->setTextBase(params()->openboot_addr);
100    openboot->loadSections(physProxy);
101    // Load the hypervisor binary
102    hypervisor->setTextBase(params()->hypervisor_addr);
103    hypervisor->loadSections(physProxy);
104    // Load the nvram image
105    nvram->setTextBase(params()->nvram_addr);
106    nvram->loadSections(physProxy);
107    // Load the hypervisor description image
108    hypervisor_desc->setTextBase(params()->hypervisor_desc_addr);
109    hypervisor_desc->loadSections(physProxy);
110    // Load the partition description image
111    partition_desc->setTextBase(params()->partition_desc_addr);
112    partition_desc->loadSections(physProxy);
113
114    // load symbols
115    if (!reset->loadGlobalSymbols(resetSymtab))
116        panic("could not load reset symbols\n");
117
118    if (!openboot->loadGlobalSymbols(openbootSymtab))
119        panic("could not load openboot symbols\n");
120
121    if (!hypervisor->loadLocalSymbols(hypervisorSymtab))
122        panic("could not load hypervisor symbols\n");
123
124    if (!nvram->loadLocalSymbols(nvramSymtab))
125        panic("could not load nvram symbols\n");
126
127    if (!hypervisor_desc->loadLocalSymbols(hypervisorDescSymtab))
128        panic("could not load hypervisor description symbols\n");
129
130    if (!partition_desc->loadLocalSymbols(partitionDescSymtab))
131        panic("could not load partition description symbols\n");
132
133    // load symbols into debug table
134    if (!reset->loadGlobalSymbols(debugSymbolTable))
135        panic("could not load reset symbols\n");
136
137    if (!openboot->loadGlobalSymbols(debugSymbolTable))
138        panic("could not load openboot symbols\n");
139
140    if (!hypervisor->loadLocalSymbols(debugSymbolTable))
141        panic("could not load hypervisor symbols\n");
142
143    // Strip off the rom address so when the hypervisor is copied into memory we
144    // have symbols still
145    if (!hypervisor->loadLocalSymbols(debugSymbolTable, 0xFFFFFF))
146        panic("could not load hypervisor symbols\n");
147
148    if (!nvram->loadGlobalSymbols(debugSymbolTable))
149        panic("could not load reset symbols\n");
150
151    if (!hypervisor_desc->loadGlobalSymbols(debugSymbolTable))
152        panic("could not load hypervisor description symbols\n");
153
154    if (!partition_desc->loadLocalSymbols(debugSymbolTable))
155        panic("could not load partition description symbols\n");
156
157
158    // @todo any fixup code over writing data in binaries on setting break
159    // events on functions should happen here.
160
161}
162
163SparcSystem::~SparcSystem()
164{
165    delete resetSymtab;
166    delete hypervisorSymtab;
167    delete openbootSymtab;
168    delete nvramSymtab;
169    delete hypervisorDescSymtab;
170    delete partitionDescSymtab;
171    delete reset;
172    delete openboot;
173    delete hypervisor;
174    delete nvram;
175    delete hypervisor_desc;
176    delete partition_desc;
177}
178
179void
180SparcSystem::serialize(std::ostream &os)
181{
182    System::serialize(os);
183    resetSymtab->serialize("reset_symtab", os);
184    hypervisorSymtab->serialize("hypervisor_symtab", os);
185    openbootSymtab->serialize("openboot_symtab", os);
186    nvramSymtab->serialize("nvram_symtab", os);
187    hypervisorDescSymtab->serialize("hypervisor_desc_symtab", os);
188    partitionDescSymtab->serialize("partition_desc_symtab", os);
189}
190
191
192void
193SparcSystem::unserialize(Checkpoint *cp, const std::string &section)
194{
195    System::unserialize(cp,section);
196    resetSymtab->unserialize("reset_symtab", cp, section);
197    hypervisorSymtab->unserialize("hypervisor_symtab", cp, section);
198    openbootSymtab->unserialize("openboot_symtab", cp, section);
199    nvramSymtab->unserialize("nvram_symtab", cp, section);
200    hypervisorDescSymtab->unserialize("hypervisor_desc_symtab", cp, section);
201    partitionDescSymtab->unserialize("partition_desc_symtab", cp, section);
202}
203
204SparcSystem *
205SparcSystemParams::create()
206{
207    return new SparcSystem(this);
208}
209