system.cc revision 2650
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
29#include "arch/sparc/system.hh"
30#include "arch/vtophys.hh"
31#include "base/remote_gdb.hh"
32#include "base/loader/object_file.hh"
33#include "base/loader/symtab.hh"
34#include "base/trace.hh"
35#include "mem/physical.hh"
36#include "sim/byteswap.hh"
37#include "sim/builder.hh"
38
39
40using namespace BigEndianGuest;
41
42SparcSystem::SparcSystem(Params *p)
43    : System(p), sysTick(0)
44
45{
46    resetSymtab = new SymbolTable;
47    hypervisorSymtab = new SymbolTable;
48    openbootSymtab = new SymbolTable;
49
50
51    /**
52     * Load the boot code, and hypervisor into memory.
53     */
54    // Read the reset binary
55    reset = createObjectFile(params()->reset_bin);
56    if (reset == NULL)
57        fatal("Could not load reset binary %s", params()->reset_bin);
58
59    // Read the openboot binary
60    openboot = createObjectFile(params()->openboot_bin);
61    if (openboot == NULL)
62        fatal("Could not load openboot bianry %s", params()->openboot_bin);
63
64    // Read the hypervisor binary
65    hypervisor = createObjectFile(params()->hypervisor_bin);
66    if (hypervisor == NULL)
67        fatal("Could not load hypervisor binary %s", params()->hypervisor_bin);
68
69
70    // Load reset binary into memory
71    reset->loadSections(&functionalPort, SparcISA::LoadAddrMask);
72    // Load the openboot binary
73    openboot->loadSections(&functionalPort, SparcISA::LoadAddrMask);
74    // Load the hypervisor binary
75    hypervisor->loadSections(&functionalPort, SparcISA::LoadAddrMask);
76
77    // load symbols
78    if (!reset->loadGlobalSymbols(reset))
79        panic("could not load reset symbols\n");
80
81    if (!openboot->loadGlobalSymbols(openbootSymtab))
82        panic("could not load openboot symbols\n");
83
84    if (!hypervisor->loadLocalSymbols(hypervisorSymtab))
85        panic("could not load hypervisor symbols\n");
86
87    // load symbols into debug table
88    if (!reset->loadGlobalSymbols(debugSymbolTable))
89        panic("could not load reset symbols\n");
90
91    if (!openboot->loadGlobalSymbols(debugSymbolTable))
92        panic("could not load openboot symbols\n");
93
94    if (!hypervisor->loadLocalSymbols(debugSymbolTable))
95        panic("could not load hypervisor symbols\n");
96
97
98    // @todo any fixup code over writing data in binaries on setting break
99    // events on functions should happen here.
100
101}
102
103SparcSystem::~SparcSystem()
104{
105    delete resetSymtab;
106    delete hypervisorSymtab;
107    delete openbootSymtab;
108    delete reset;
109    delete openboot;
110    delete hypervisor;
111}
112
113bool
114SparcSystem::breakpoint()
115{
116    panic("Need to implement");
117}
118
119void
120SparcSystem::serialize(std::ostream &os)
121{
122    System::serialize(os);
123    resetSymtab->serialize("reset_symtab", os);
124    hypervisorSymtab->serialize("hypervisor_symtab", os);
125    openbootSymtab->serialize("openboot_symtab", os);
126}
127
128
129void
130SparcSystem::unserialize(Checkpoint *cp, const std::string &section)
131{
132    System::unserialize(cp,section);
133    resetSymtab->unserialize("reset_symtab", cp, section);
134    hypervisorSymtab->unserialize("hypervisor_symtab", cp, section);
135    openbootSymtab->unserialize("openboot_symtab", cp, section);
136}
137
138
139BEGIN_DECLARE_SIM_OBJECT_PARAMS(SparcSystem)
140
141    SimObjectParam<PhysicalMemory *> physmem;
142
143    Param<std::string> kernel;
144    Param<std::string> reset_bin;
145    Param<std::string> hypervisor_bin;
146    Param<std::string> openboot_bin;
147
148    Param<std::string> boot_osflags;
149    Param<std::string> readfile;
150    Param<unsigned int> init_param;
151
152    Param<bool> bin;
153    VectorParam<std::string> binned_fns;
154    Param<bool> bin_int;
155
156END_DECLARE_SIM_OBJECT_PARAMS(SparcSystem)
157
158BEGIN_INIT_SIM_OBJECT_PARAMS(SparcSystem)
159
160    INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
161    INIT_PARAM(physmem, "phsyical memory"),
162    INIT_PARAM(kernel, "file that contains the kernel code"),
163    INIT_PARAM(reset_bin, "file that contains the reset code"),
164    INIT_PARAM(hypervisor_bin, "file that contains the hypervisor code"),
165    INIT_PARAM(openboot_bin, "file that contains the openboot code"),
166    INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
167                    "a"),
168    INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
169    INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
170    INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
171    INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10),
172    INIT_PARAM_DFLT(bin, "is this system to be binned", false),
173    INIT_PARAM(binned_fns, "functions to be broken down and binned"),
174    INIT_PARAM_DFLT(bin_int, "is interrupt code binned seperately?", true)
175
176END_INIT_SIM_OBJECT_PARAMS(SparcSystem)
177
178CREATE_SIM_OBJECT(SparcSystem)
179{
180    SparcSystem::Params *p = new SparcSystem::Params;
181    p->name = getInstanceName();
182    p->boot_cpu_frequency = boot_cpu_frequency;
183    p->physmem = physmem;
184    p->kernel_path = kernel;
185    p->reset_bin = reset_bin;
186    p->hypervisor_bin = hypervisor_bin;
187    p->openboot_bin = openboot_bin;
188    p->boot_osflags = boot_osflags;
189    p->init_param = init_param;
190    p->readfile = readfile;
191    p->system_type = system_type;
192    p->system_rev = system_rev;
193    p->bin = bin;
194    p->binned_fns = binned_fns;
195    p->bin_int = bin_int;
196    return new SparcSystem(p);
197}
198
199REGISTER_SIM_OBJECT("SparcSystem", SparcSystem)
200
201
202