2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
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.
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.
32 #include <sys/signal.h>
34 #include "arch/alpha/ev5.hh"
35 #include "arch/alpha/system.hh"
36 #include "arch/alpha/remote_gdb.hh"
37 #include "arch/vtophys.hh"
38 #include "base/loader/object_file.hh"
39 #include "base/loader/symtab.hh"
40 #include "base/trace.hh"
41 #include "mem/physical.hh"
42 #include "sim/byteswap.hh"
43 #include "sim/builder.hh"
46 using namespace LittleEndianGuest
;
48 AlphaSystem::AlphaSystem(Params
*p
)
51 consoleSymtab
= new SymbolTable
;
52 palSymtab
= new SymbolTable
;
56 * Load the pal, and console code into memory
59 console
= createObjectFile(params()->console_path
);
61 fatal("Could not load console file %s", params()->console_path
);
64 pal
= createObjectFile(params()->palcode
);
66 fatal("Could not load PALcode file %s", params()->palcode
);
69 // Load program sections into memory
70 pal
->loadSections(&functionalPort
, AlphaISA::LoadAddrMask
);
71 console
->loadSections(&functionalPort
, AlphaISA::LoadAddrMask
);
74 if (!console
->loadGlobalSymbols(consoleSymtab
))
75 panic("could not load console symbols\n");
77 if (!pal
->loadGlobalSymbols(palSymtab
))
78 panic("could not load pal symbols\n");
80 if (!pal
->loadLocalSymbols(palSymtab
))
81 panic("could not load pal symbols\n");
83 if (!console
->loadGlobalSymbols(debugSymbolTable
))
84 panic("could not load console symbols\n");
86 if (!pal
->loadGlobalSymbols(debugSymbolTable
))
87 panic("could not load pal symbols\n");
89 if (!pal
->loadLocalSymbols(debugSymbolTable
))
90 panic("could not load pal symbols\n");
94 consolePanicEvent
= addConsoleFuncEvent
<BreakPCEvent
>("panic");
98 * Copy the osflags (kernel arguments) into the consoles
99 * memory. (Presently Linux does not use the console service
100 * routine to get these command line arguments, but Tru64 and
103 if (consoleSymtab
->findAddress("env_booted_osflags", addr
)) {
104 virtPort
.writeBlob(addr
, (uint8_t*)params()->boot_osflags
.c_str(),
105 strlen(params()->boot_osflags
.c_str()));
109 * Set the hardware reset parameter block system type and revision
110 * information to Tsunami.
112 if (consoleSymtab
->findAddress("m5_rpb", addr
)) {
114 data
= htog(params()->system_type
);
115 virtPort
.write(addr
+0x50, data
);
116 data
= htog(params()->system_rev
);
117 virtPort
.write(addr
+0x58, data
);
119 panic("could not find hwrpb\n");
123 AlphaSystem::~AlphaSystem()
125 delete consoleSymtab
;
129 delete consolePanicEvent
;
134 * This function fixes up addresses that are used to match PCs for
135 * hooking simulator events on to target function executions.
137 * Alpha binaries may have multiple global offset table (GOT)
138 * sections. A function that uses the GOT starts with a
139 * two-instruction prolog which sets the global pointer (gp == r29) to
140 * the appropriate GOT section. The proper gp value is calculated
141 * based on the function address, which must be passed by the caller
142 * in the procedure value register (pv aka t12 == r27). This sequence
143 * looks like the following:
145 * opcode Ra Rb offset
146 * ldah gp,X(pv) 09 29 27 X
147 * lda gp,Y(gp) 08 29 29 Y
149 * for some constant offsets X and Y. The catch is that the linker
150 * (or maybe even the compiler, I'm not sure) may recognize that the
151 * caller and callee are using the same GOT section, making this
152 * prolog redundant, and modify the call target to skip these
153 * instructions. If we check for execution of the first instruction
154 * of a function (the one the symbol points to) to detect when to skip
155 * it, we'll miss all these modified calls. It might work to
156 * unconditionally check for the third instruction, but not all
157 * functions have this prolog, and there's some chance that those
158 * first two instructions could have undesired consequences. So we do
159 * the Right Thing and pattern-match the first two instructions of the
160 * function to decide where to patch.
162 * Eventually this code should be moved into an ISA-specific file.
165 AlphaSystem::fixFuncEventAddr(Addr addr
)
167 // mask for just the opcode, Ra, and Rb fields (not the offset)
168 const uint32_t inst_mask
= 0xffff0000;
169 // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27
170 const uint32_t gp_ldah_pattern
= (9 << 26) | (29 << 21) | (27 << 16);
171 // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29
172 const uint32_t gp_lda_pattern
= (8 << 26) | (29 << 21) | (29 << 16);
174 uint32_t i1
= virtPort
.read
<uint32_t>(addr
);
175 uint32_t i2
= virtPort
.read
<uint32_t>(addr
+ sizeof(AlphaISA::MachInst
));
177 if ((i1
& inst_mask
) == gp_ldah_pattern
&&
178 (i2
& inst_mask
) == gp_lda_pattern
) {
179 Addr new_addr
= addr
+ 2* sizeof(AlphaISA::MachInst
);
180 DPRINTF(Loader
, "fixFuncEventAddr: %p -> %p", addr
, new_addr
);
189 AlphaSystem::setAlphaAccess(Addr access
)
192 if (consoleSymtab
->findAddress("m5AlphaAccess", addr
)) {
193 virtPort
.write(addr
, htog(EV5::Phys2K0Seg(access
)));
195 panic("could not find m5AlphaAccess\n");
199 AlphaSystem::breakpoint()
201 return remoteGDB
[0]->trap(SIGTRAP
);
205 AlphaSystem::serialize(std::ostream
&os
)
207 System::serialize(os
);
208 consoleSymtab
->serialize("console_symtab", os
);
209 palSymtab
->serialize("pal_symtab", os
);
214 AlphaSystem::unserialize(Checkpoint
*cp
, const std::string
§ion
)
216 System::unserialize(cp
,section
);
217 consoleSymtab
->unserialize("console_symtab", cp
, section
);
218 palSymtab
->unserialize("pal_symtab", cp
, section
);
222 BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaSystem
)
224 Param
<Tick
> boot_cpu_frequency
;
225 SimObjectParam
<PhysicalMemory
*> physmem
;
226 SimpleEnumParam
<System::MemoryMode
> mem_mode
;
228 Param
<std::string
> kernel
;
229 Param
<std::string
> console
;
230 Param
<std::string
> pal
;
232 Param
<std::string
> boot_osflags
;
233 Param
<std::string
> readfile
;
234 Param
<std::string
> symbolfile
;
235 Param
<unsigned int> init_param
;
237 Param
<uint64_t> system_type
;
238 Param
<uint64_t> system_rev
;
240 END_DECLARE_SIM_OBJECT_PARAMS(AlphaSystem
)
242 BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaSystem
)
244 INIT_PARAM(boot_cpu_frequency
, "Frequency of the boot CPU"),
245 INIT_PARAM(physmem
, "phsyical memory"),
246 INIT_ENUM_PARAM(mem_mode
, "Memory Mode, (1=atomic, 2=timing)",
247 System::MemoryModeStrings
),
248 INIT_PARAM(kernel
, "file that contains the kernel code"),
249 INIT_PARAM(console
, "file that contains the console code"),
250 INIT_PARAM(pal
, "file that contains palcode"),
251 INIT_PARAM_DFLT(boot_osflags
, "flags to pass to the kernel during boot",
253 INIT_PARAM_DFLT(readfile
, "file to read startup script from", ""),
254 INIT_PARAM_DFLT(symbolfile
, "file to read symbols from", ""),
255 INIT_PARAM_DFLT(init_param
, "numerical value to pass into simulator", 0),
256 INIT_PARAM_DFLT(system_type
, "Type of system we are emulating", 34),
257 INIT_PARAM_DFLT(system_rev
, "Revision of system we are emulating", 1<<10)
259 END_INIT_SIM_OBJECT_PARAMS(AlphaSystem
)
261 CREATE_SIM_OBJECT(AlphaSystem
)
263 AlphaSystem::Params
*p
= new AlphaSystem::Params
;
264 p
->name
= getInstanceName();
265 p
->boot_cpu_frequency
= boot_cpu_frequency
;
266 p
->physmem
= physmem
;
267 p
->mem_mode
= mem_mode
;
268 p
->kernel_path
= kernel
;
269 p
->console_path
= console
;
271 p
->boot_osflags
= boot_osflags
;
272 p
->init_param
= init_param
;
273 p
->readfile
= readfile
;
274 p
->symbolfile
= symbolfile
;
275 p
->system_type
= system_type
;
276 p
->system_rev
= system_rev
;
277 return new AlphaSystem(p
);
280 REGISTER_SIM_OBJECT("AlphaSystem", AlphaSystem
)