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 "params/AlphaSystem.hh"
43 #include "sim/byteswap.hh"
45 using namespace AlphaISA
;
47 AlphaSystem::AlphaSystem(Params
*p
)
50 consoleSymtab
= new SymbolTable
;
51 palSymtab
= new SymbolTable
;
55 * Load the pal, and console code into memory
58 console
= createObjectFile(params()->console
);
60 fatal("Could not load console file %s", params()->console
);
63 pal
= createObjectFile(params()->pal
);
65 fatal("Could not load PALcode file %s", params()->pal
);
68 // Load program sections into memory
69 pal
->loadSections(&functionalPort
, LoadAddrMask
);
70 console
->loadSections(&functionalPort
, LoadAddrMask
);
73 if (!console
->loadGlobalSymbols(consoleSymtab
))
74 panic("could not load console symbols\n");
76 if (!pal
->loadGlobalSymbols(palSymtab
))
77 panic("could not load pal symbols\n");
79 if (!pal
->loadLocalSymbols(palSymtab
))
80 panic("could not load pal symbols\n");
82 if (!console
->loadGlobalSymbols(debugSymbolTable
))
83 panic("could not load console symbols\n");
85 if (!pal
->loadGlobalSymbols(debugSymbolTable
))
86 panic("could not load pal symbols\n");
88 if (!pal
->loadLocalSymbols(debugSymbolTable
))
89 panic("could not load pal symbols\n");
93 consolePanicEvent
= addConsoleFuncEvent
<BreakPCEvent
>("panic");
97 * Copy the osflags (kernel arguments) into the consoles
98 * memory. (Presently Linux does not use the console service
99 * routine to get these command line arguments, but Tru64 and
102 if (consoleSymtab
->findAddress("env_booted_osflags", addr
)) {
103 virtPort
.writeBlob(addr
, (uint8_t*)params()->boot_osflags
.c_str(),
104 strlen(params()->boot_osflags
.c_str()));
108 * Set the hardware reset parameter block system type and revision
109 * information to Tsunami.
111 if (consoleSymtab
->findAddress("m5_rpb", addr
)) {
113 data
= htog(params()->system_type
);
114 virtPort
.write(addr
+0x50, data
);
115 data
= htog(params()->system_rev
);
116 virtPort
.write(addr
+0x58, data
);
118 panic("could not find hwrpb\n");
121 AlphaSystem::~AlphaSystem()
123 delete consoleSymtab
;
127 delete consolePanicEvent
;
132 * This function fixes up addresses that are used to match PCs for
133 * hooking simulator events on to target function executions.
135 * Alpha binaries may have multiple global offset table (GOT)
136 * sections. A function that uses the GOT starts with a
137 * two-instruction prolog which sets the global pointer (gp == r29) to
138 * the appropriate GOT section. The proper gp value is calculated
139 * based on the function address, which must be passed by the caller
140 * in the procedure value register (pv aka t12 == r27). This sequence
141 * looks like the following:
143 * opcode Ra Rb offset
144 * ldah gp,X(pv) 09 29 27 X
145 * lda gp,Y(gp) 08 29 29 Y
147 * for some constant offsets X and Y. The catch is that the linker
148 * (or maybe even the compiler, I'm not sure) may recognize that the
149 * caller and callee are using the same GOT section, making this
150 * prolog redundant, and modify the call target to skip these
151 * instructions. If we check for execution of the first instruction
152 * of a function (the one the symbol points to) to detect when to skip
153 * it, we'll miss all these modified calls. It might work to
154 * unconditionally check for the third instruction, but not all
155 * functions have this prolog, and there's some chance that those
156 * first two instructions could have undesired consequences. So we do
157 * the Right Thing and pattern-match the first two instructions of the
158 * function to decide where to patch.
160 * Eventually this code should be moved into an ISA-specific file.
163 AlphaSystem::fixFuncEventAddr(Addr addr
)
165 // mask for just the opcode, Ra, and Rb fields (not the offset)
166 const uint32_t inst_mask
= 0xffff0000;
167 // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27
168 const uint32_t gp_ldah_pattern
= (9 << 26) | (29 << 21) | (27 << 16);
169 // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29
170 const uint32_t gp_lda_pattern
= (8 << 26) | (29 << 21) | (29 << 16);
172 uint32_t i1
= virtPort
.read
<uint32_t>(addr
);
173 uint32_t i2
= virtPort
.read
<uint32_t>(addr
+ sizeof(MachInst
));
175 if ((i1
& inst_mask
) == gp_ldah_pattern
&&
176 (i2
& inst_mask
) == gp_lda_pattern
) {
177 Addr new_addr
= addr
+ 2 * sizeof(MachInst
);
178 DPRINTF(Loader
, "fixFuncEventAddr: %p -> %p", addr
, new_addr
);
186 AlphaSystem::setAlphaAccess(Addr access
)
189 if (consoleSymtab
->findAddress("m5AlphaAccess", addr
)) {
190 virtPort
.write(addr
, htog(Phys2K0Seg(access
)));
192 panic("could not find m5AlphaAccess\n");
197 AlphaSystem::serialize(std::ostream
&os
)
199 System::serialize(os
);
200 consoleSymtab
->serialize("console_symtab", os
);
201 palSymtab
->serialize("pal_symtab", os
);
205 AlphaSystem::unserialize(Checkpoint
*cp
, const std::string
§ion
)
207 System::unserialize(cp
,section
);
208 consoleSymtab
->unserialize("console_symtab", cp
, section
);
209 palSymtab
->unserialize("pal_symtab", cp
, section
);
213 AlphaSystemParams::create()
215 return new AlphaSystem(this);