Merge with head.
[gem5.git] / src / arch / sparc / system.cc
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
40
41 using namespace BigEndianGuest;
42
43 SparcSystem::SparcSystem(Params *p)
44 : System(p), sysTick(0),funcRomPort(p->name + "-fromport"),
45 funcNvramPort(p->name + "-fnvramport"),
46 funcHypDescPort(p->name + "-fhypdescport"),
47 funcPartDescPort(p->name + "-fpartdescport")
48 {
49 resetSymtab = new SymbolTable;
50 hypervisorSymtab = new SymbolTable;
51 openbootSymtab = new SymbolTable;
52 nvramSymtab = new SymbolTable;
53 hypervisorDescSymtab = new SymbolTable;
54 partitionDescSymtab = new SymbolTable;
55
56 Port *rom_port;
57 rom_port = params()->rom->getPort("functional");
58 funcRomPort.setPeer(rom_port);
59 rom_port->setPeer(&funcRomPort);
60
61 rom_port = params()->nvram->getPort("functional");
62 funcNvramPort.setPeer(rom_port);
63 rom_port->setPeer(&funcNvramPort);
64
65 rom_port = params()->hypervisor_desc->getPort("functional");
66 funcHypDescPort.setPeer(rom_port);
67 rom_port->setPeer(&funcHypDescPort);
68
69 rom_port = params()->partition_desc->getPort("functional");
70 funcPartDescPort.setPeer(rom_port);
71 rom_port->setPeer(&funcPartDescPort);
72
73 /**
74 * Load the boot code, and hypervisor into memory.
75 */
76 // Read the reset binary
77 reset = createObjectFile(params()->reset_bin, true);
78 if (reset == NULL)
79 fatal("Could not load reset binary %s", params()->reset_bin);
80
81 // Read the openboot binary
82 openboot = createObjectFile(params()->openboot_bin, true);
83 if (openboot == NULL)
84 fatal("Could not load openboot bianry %s", params()->openboot_bin);
85
86 // Read the hypervisor binary
87 hypervisor = createObjectFile(params()->hypervisor_bin, true);
88 if (hypervisor == NULL)
89 fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
90
91 // Read the nvram image
92 nvram = createObjectFile(params()->nvram_bin, true);
93 if (nvram == NULL)
94 fatal("Could not load nvram image %s", params()->nvram_bin);
95
96 // Read the hypervisor description image
97 hypervisor_desc = createObjectFile(params()->hypervisor_desc_bin, true);
98 if (hypervisor_desc == NULL)
99 fatal("Could not load hypervisor description image %s",
100 params()->hypervisor_desc_bin);
101
102 // Read the partition description image
103 partition_desc = createObjectFile(params()->partition_desc_bin, true);
104 if (partition_desc == NULL)
105 fatal("Could not load partition description image %s",
106 params()->partition_desc_bin);
107
108
109 // Load reset binary into memory
110 reset->setTextBase(params()->reset_addr);
111 reset->loadSections(&funcRomPort);
112 // Load the openboot binary
113 openboot->setTextBase(params()->openboot_addr);
114 openboot->loadSections(&funcRomPort);
115 // Load the hypervisor binary
116 hypervisor->setTextBase(params()->hypervisor_addr);
117 hypervisor->loadSections(&funcRomPort);
118 // Load the nvram image
119 nvram->setTextBase(params()->nvram_addr);
120 nvram->loadSections(&funcNvramPort);
121 // Load the hypervisor description image
122 hypervisor_desc->setTextBase(params()->hypervisor_desc_addr);
123 hypervisor_desc->loadSections(&funcHypDescPort);
124 // Load the partition description image
125 partition_desc->setTextBase(params()->partition_desc_addr);
126 partition_desc->loadSections(&funcPartDescPort);
127
128 // load symbols
129 if (!reset->loadGlobalSymbols(resetSymtab))
130 panic("could not load reset symbols\n");
131
132 if (!openboot->loadGlobalSymbols(openbootSymtab))
133 panic("could not load openboot symbols\n");
134
135 if (!hypervisor->loadLocalSymbols(hypervisorSymtab))
136 panic("could not load hypervisor symbols\n");
137
138 if (!nvram->loadLocalSymbols(nvramSymtab))
139 panic("could not load nvram symbols\n");
140
141 if (!hypervisor_desc->loadLocalSymbols(hypervisorDescSymtab))
142 panic("could not load hypervisor description symbols\n");
143
144 if (!partition_desc->loadLocalSymbols(partitionDescSymtab))
145 panic("could not load partition description symbols\n");
146
147 // load symbols into debug table
148 if (!reset->loadGlobalSymbols(debugSymbolTable))
149 panic("could not load reset symbols\n");
150
151 if (!openboot->loadGlobalSymbols(debugSymbolTable))
152 panic("could not load openboot symbols\n");
153
154 if (!hypervisor->loadLocalSymbols(debugSymbolTable))
155 panic("could not load hypervisor symbols\n");
156
157 // Strip off the rom address so when the hypervisor is copied into memory we
158 // have symbols still
159 if (!hypervisor->loadLocalSymbols(debugSymbolTable, 0xFFFFFF))
160 panic("could not load hypervisor symbols\n");
161
162 if (!nvram->loadGlobalSymbols(debugSymbolTable))
163 panic("could not load reset symbols\n");
164
165 if (!hypervisor_desc->loadGlobalSymbols(debugSymbolTable))
166 panic("could not load hypervisor description symbols\n");
167
168 if (!partition_desc->loadLocalSymbols(debugSymbolTable))
169 panic("could not load partition description symbols\n");
170
171
172 // @todo any fixup code over writing data in binaries on setting break
173 // events on functions should happen here.
174
175 }
176
177 SparcSystem::~SparcSystem()
178 {
179 delete resetSymtab;
180 delete hypervisorSymtab;
181 delete openbootSymtab;
182 delete nvramSymtab;
183 delete hypervisorDescSymtab;
184 delete partitionDescSymtab;
185 delete reset;
186 delete openboot;
187 delete hypervisor;
188 delete nvram;
189 delete hypervisor_desc;
190 delete partition_desc;
191 }
192
193 void
194 SparcSystem::serialize(std::ostream &os)
195 {
196 System::serialize(os);
197 resetSymtab->serialize("reset_symtab", os);
198 hypervisorSymtab->serialize("hypervisor_symtab", os);
199 openbootSymtab->serialize("openboot_symtab", os);
200 nvramSymtab->serialize("nvram_symtab", os);
201 hypervisorDescSymtab->serialize("hypervisor_desc_symtab", os);
202 partitionDescSymtab->serialize("partition_desc_symtab", os);
203 }
204
205
206 void
207 SparcSystem::unserialize(Checkpoint *cp, const std::string &section)
208 {
209 System::unserialize(cp,section);
210 resetSymtab->unserialize("reset_symtab", cp, section);
211 hypervisorSymtab->unserialize("hypervisor_symtab", cp, section);
212 openbootSymtab->unserialize("openboot_symtab", cp, section);
213 nvramSymtab->unserialize("nvram_symtab", cp, section);
214 hypervisorDescSymtab->unserialize("hypervisor_desc_symtab", cp, section);
215 partitionDescSymtab->unserialize("partition_desc_symtab", cp, section);
216 }
217
218 SparcSystem *
219 SparcSystemParams::create()
220 {
221 return new SparcSystem(this);
222 }