system.cc (3125:febd811bccc6) system.cc (3536:89aa06409e4d)
1/*
2 * Copyright (c) 2002-2005 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 * Nathan Binkert
30 */
31
32#include "arch/alpha/ev5.hh"
33#include "arch/alpha/system.hh"
1/*
2 * Copyright (c) 2002-2005 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 * Nathan Binkert
30 */
31
32#include "arch/alpha/ev5.hh"
33#include "arch/alpha/system.hh"
34#include "arch/alpha/remote_gdb.hh"
34#include "arch/vtophys.hh"
35#include "arch/vtophys.hh"
35#include "base/remote_gdb.hh"
36#include "base/loader/object_file.hh"
37#include "base/loader/symtab.hh"
38#include "base/trace.hh"
39#include "mem/physical.hh"
40#include "sim/byteswap.hh"
41#include "sim/builder.hh"
42
43
44using namespace LittleEndianGuest;
45
46AlphaSystem::AlphaSystem(Params *p)
47 : System(p)
48{
49 consoleSymtab = new SymbolTable;
50 palSymtab = new SymbolTable;
51
52
53 /**
54 * Load the pal, and console code into memory
55 */
56 // Load Console Code
57 console = createObjectFile(params()->console_path);
58 if (console == NULL)
59 fatal("Could not load console file %s", params()->console_path);
60
61 // Load pal file
62 pal = createObjectFile(params()->palcode);
63 if (pal == NULL)
64 fatal("Could not load PALcode file %s", params()->palcode);
65
66
67 // Load program sections into memory
68 pal->loadSections(&functionalPort, AlphaISA::LoadAddrMask);
69 console->loadSections(&functionalPort, AlphaISA::LoadAddrMask);
70
71 // load symbols
72 if (!console->loadGlobalSymbols(consoleSymtab))
73 panic("could not load console symbols\n");
74
75 if (!pal->loadGlobalSymbols(palSymtab))
76 panic("could not load pal symbols\n");
77
78 if (!pal->loadLocalSymbols(palSymtab))
79 panic("could not load pal symbols\n");
80
81 if (!console->loadGlobalSymbols(debugSymbolTable))
82 panic("could not load console symbols\n");
83
84 if (!pal->loadGlobalSymbols(debugSymbolTable))
85 panic("could not load pal symbols\n");
86
87 if (!pal->loadLocalSymbols(debugSymbolTable))
88 panic("could not load pal symbols\n");
89
90 Addr addr = 0;
91#ifndef NDEBUG
92 consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic");
93#endif
94
95 /**
96 * Copy the osflags (kernel arguments) into the consoles
97 * memory. (Presently Linux does not use the console service
98 * routine to get these command line arguments, but Tru64 and
99 * others do.)
100 */
101 if (consoleSymtab->findAddress("env_booted_osflags", addr)) {
102 virtPort.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(),
103 strlen(params()->boot_osflags.c_str()));
104 }
105
106 /**
107 * Set the hardware reset parameter block system type and revision
108 * information to Tsunami.
109 */
110 if (consoleSymtab->findAddress("m5_rpb", addr)) {
111 uint64_t data;
112 data = htog(params()->system_type);
113 virtPort.write(addr+0x50, data);
114 data = htog(params()->system_rev);
115 virtPort.write(addr+0x58, data);
116 } else
117 panic("could not find hwrpb\n");
118
119}
120
121AlphaSystem::~AlphaSystem()
122{
123 delete consoleSymtab;
124 delete console;
125 delete pal;
126#ifdef DEBUG
127 delete consolePanicEvent;
128#endif
129}
130
131/**
132 * This function fixes up addresses that are used to match PCs for
133 * hooking simulator events on to target function executions.
134 *
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:
142 *
143 * opcode Ra Rb offset
144 * ldah gp,X(pv) 09 29 27 X
145 * lda gp,Y(gp) 08 29 29 Y
146 *
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.
159 *
160 * Eventually this code should be moved into an ISA-specific file.
161 */
162Addr
163AlphaSystem::fixFuncEventAddr(Addr addr)
164{
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);
171
172 uint32_t i1 = virtPort.read<uint32_t>(addr);
173 uint32_t i2 = virtPort.read<uint32_t>(addr + sizeof(AlphaISA::MachInst));
174
175 if ((i1 & inst_mask) == gp_ldah_pattern &&
176 (i2 & inst_mask) == gp_lda_pattern) {
177 Addr new_addr = addr + 2* sizeof(AlphaISA::MachInst);
178 DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr);
179 return new_addr;
180 } else {
181 return addr;
182 }
183}
184
185
186void
187AlphaSystem::setAlphaAccess(Addr access)
188{
189 Addr addr = 0;
190 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) {
191 virtPort.write(addr, htog(EV5::Phys2K0Seg(access)));
192 } else
193 panic("could not find m5AlphaAccess\n");
194}
195
196bool
197AlphaSystem::breakpoint()
198{
199 return remoteGDB[0]->trap(ALPHA_KENTRY_INT);
200}
201
202void
203AlphaSystem::serialize(std::ostream &os)
204{
205 System::serialize(os);
206 consoleSymtab->serialize("console_symtab", os);
207 palSymtab->serialize("pal_symtab", os);
208}
209
210
211void
212AlphaSystem::unserialize(Checkpoint *cp, const std::string &section)
213{
214 System::unserialize(cp,section);
215 consoleSymtab->unserialize("console_symtab", cp, section);
216 palSymtab->unserialize("pal_symtab", cp, section);
217}
218
219
220BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaSystem)
221
222 Param<Tick> boot_cpu_frequency;
223 SimObjectParam<PhysicalMemory *> physmem;
224 SimpleEnumParam<System::MemoryMode> mem_mode;
225
226 Param<std::string> kernel;
227 Param<std::string> console;
228 Param<std::string> pal;
229
230 Param<std::string> boot_osflags;
231 Param<std::string> readfile;
232 Param<std::string> symbolfile;
233 Param<unsigned int> init_param;
234
235 Param<uint64_t> system_type;
236 Param<uint64_t> system_rev;
237
238END_DECLARE_SIM_OBJECT_PARAMS(AlphaSystem)
239
240BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaSystem)
241
242 INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
243 INIT_PARAM(physmem, "phsyical memory"),
244 INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)",
245 System::MemoryModeStrings),
246 INIT_PARAM(kernel, "file that contains the kernel code"),
247 INIT_PARAM(console, "file that contains the console code"),
248 INIT_PARAM(pal, "file that contains palcode"),
249 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
250 "a"),
251 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
252 INIT_PARAM_DFLT(symbolfile, "file to read symbols from", ""),
253 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
254 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
255 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10)
256
257END_INIT_SIM_OBJECT_PARAMS(AlphaSystem)
258
259CREATE_SIM_OBJECT(AlphaSystem)
260{
261 AlphaSystem::Params *p = new AlphaSystem::Params;
262 p->name = getInstanceName();
263 p->boot_cpu_frequency = boot_cpu_frequency;
264 p->physmem = physmem;
265 p->mem_mode = mem_mode;
266 p->kernel_path = kernel;
267 p->console_path = console;
268 p->palcode = pal;
269 p->boot_osflags = boot_osflags;
270 p->init_param = init_param;
271 p->readfile = readfile;
272 p->symbolfile = symbolfile;
273 p->system_type = system_type;
274 p->system_rev = system_rev;
275 return new AlphaSystem(p);
276}
277
278REGISTER_SIM_OBJECT("AlphaSystem", AlphaSystem)
279
280
36#include "base/loader/object_file.hh"
37#include "base/loader/symtab.hh"
38#include "base/trace.hh"
39#include "mem/physical.hh"
40#include "sim/byteswap.hh"
41#include "sim/builder.hh"
42
43
44using namespace LittleEndianGuest;
45
46AlphaSystem::AlphaSystem(Params *p)
47 : System(p)
48{
49 consoleSymtab = new SymbolTable;
50 palSymtab = new SymbolTable;
51
52
53 /**
54 * Load the pal, and console code into memory
55 */
56 // Load Console Code
57 console = createObjectFile(params()->console_path);
58 if (console == NULL)
59 fatal("Could not load console file %s", params()->console_path);
60
61 // Load pal file
62 pal = createObjectFile(params()->palcode);
63 if (pal == NULL)
64 fatal("Could not load PALcode file %s", params()->palcode);
65
66
67 // Load program sections into memory
68 pal->loadSections(&functionalPort, AlphaISA::LoadAddrMask);
69 console->loadSections(&functionalPort, AlphaISA::LoadAddrMask);
70
71 // load symbols
72 if (!console->loadGlobalSymbols(consoleSymtab))
73 panic("could not load console symbols\n");
74
75 if (!pal->loadGlobalSymbols(palSymtab))
76 panic("could not load pal symbols\n");
77
78 if (!pal->loadLocalSymbols(palSymtab))
79 panic("could not load pal symbols\n");
80
81 if (!console->loadGlobalSymbols(debugSymbolTable))
82 panic("could not load console symbols\n");
83
84 if (!pal->loadGlobalSymbols(debugSymbolTable))
85 panic("could not load pal symbols\n");
86
87 if (!pal->loadLocalSymbols(debugSymbolTable))
88 panic("could not load pal symbols\n");
89
90 Addr addr = 0;
91#ifndef NDEBUG
92 consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic");
93#endif
94
95 /**
96 * Copy the osflags (kernel arguments) into the consoles
97 * memory. (Presently Linux does not use the console service
98 * routine to get these command line arguments, but Tru64 and
99 * others do.)
100 */
101 if (consoleSymtab->findAddress("env_booted_osflags", addr)) {
102 virtPort.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(),
103 strlen(params()->boot_osflags.c_str()));
104 }
105
106 /**
107 * Set the hardware reset parameter block system type and revision
108 * information to Tsunami.
109 */
110 if (consoleSymtab->findAddress("m5_rpb", addr)) {
111 uint64_t data;
112 data = htog(params()->system_type);
113 virtPort.write(addr+0x50, data);
114 data = htog(params()->system_rev);
115 virtPort.write(addr+0x58, data);
116 } else
117 panic("could not find hwrpb\n");
118
119}
120
121AlphaSystem::~AlphaSystem()
122{
123 delete consoleSymtab;
124 delete console;
125 delete pal;
126#ifdef DEBUG
127 delete consolePanicEvent;
128#endif
129}
130
131/**
132 * This function fixes up addresses that are used to match PCs for
133 * hooking simulator events on to target function executions.
134 *
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:
142 *
143 * opcode Ra Rb offset
144 * ldah gp,X(pv) 09 29 27 X
145 * lda gp,Y(gp) 08 29 29 Y
146 *
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.
159 *
160 * Eventually this code should be moved into an ISA-specific file.
161 */
162Addr
163AlphaSystem::fixFuncEventAddr(Addr addr)
164{
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);
171
172 uint32_t i1 = virtPort.read<uint32_t>(addr);
173 uint32_t i2 = virtPort.read<uint32_t>(addr + sizeof(AlphaISA::MachInst));
174
175 if ((i1 & inst_mask) == gp_ldah_pattern &&
176 (i2 & inst_mask) == gp_lda_pattern) {
177 Addr new_addr = addr + 2* sizeof(AlphaISA::MachInst);
178 DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr);
179 return new_addr;
180 } else {
181 return addr;
182 }
183}
184
185
186void
187AlphaSystem::setAlphaAccess(Addr access)
188{
189 Addr addr = 0;
190 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) {
191 virtPort.write(addr, htog(EV5::Phys2K0Seg(access)));
192 } else
193 panic("could not find m5AlphaAccess\n");
194}
195
196bool
197AlphaSystem::breakpoint()
198{
199 return remoteGDB[0]->trap(ALPHA_KENTRY_INT);
200}
201
202void
203AlphaSystem::serialize(std::ostream &os)
204{
205 System::serialize(os);
206 consoleSymtab->serialize("console_symtab", os);
207 palSymtab->serialize("pal_symtab", os);
208}
209
210
211void
212AlphaSystem::unserialize(Checkpoint *cp, const std::string &section)
213{
214 System::unserialize(cp,section);
215 consoleSymtab->unserialize("console_symtab", cp, section);
216 palSymtab->unserialize("pal_symtab", cp, section);
217}
218
219
220BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaSystem)
221
222 Param<Tick> boot_cpu_frequency;
223 SimObjectParam<PhysicalMemory *> physmem;
224 SimpleEnumParam<System::MemoryMode> mem_mode;
225
226 Param<std::string> kernel;
227 Param<std::string> console;
228 Param<std::string> pal;
229
230 Param<std::string> boot_osflags;
231 Param<std::string> readfile;
232 Param<std::string> symbolfile;
233 Param<unsigned int> init_param;
234
235 Param<uint64_t> system_type;
236 Param<uint64_t> system_rev;
237
238END_DECLARE_SIM_OBJECT_PARAMS(AlphaSystem)
239
240BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaSystem)
241
242 INIT_PARAM(boot_cpu_frequency, "Frequency of the boot CPU"),
243 INIT_PARAM(physmem, "phsyical memory"),
244 INIT_ENUM_PARAM(mem_mode, "Memory Mode, (1=atomic, 2=timing)",
245 System::MemoryModeStrings),
246 INIT_PARAM(kernel, "file that contains the kernel code"),
247 INIT_PARAM(console, "file that contains the console code"),
248 INIT_PARAM(pal, "file that contains palcode"),
249 INIT_PARAM_DFLT(boot_osflags, "flags to pass to the kernel during boot",
250 "a"),
251 INIT_PARAM_DFLT(readfile, "file to read startup script from", ""),
252 INIT_PARAM_DFLT(symbolfile, "file to read symbols from", ""),
253 INIT_PARAM_DFLT(init_param, "numerical value to pass into simulator", 0),
254 INIT_PARAM_DFLT(system_type, "Type of system we are emulating", 34),
255 INIT_PARAM_DFLT(system_rev, "Revision of system we are emulating", 1<<10)
256
257END_INIT_SIM_OBJECT_PARAMS(AlphaSystem)
258
259CREATE_SIM_OBJECT(AlphaSystem)
260{
261 AlphaSystem::Params *p = new AlphaSystem::Params;
262 p->name = getInstanceName();
263 p->boot_cpu_frequency = boot_cpu_frequency;
264 p->physmem = physmem;
265 p->mem_mode = mem_mode;
266 p->kernel_path = kernel;
267 p->console_path = console;
268 p->palcode = pal;
269 p->boot_osflags = boot_osflags;
270 p->init_param = init_param;
271 p->readfile = readfile;
272 p->symbolfile = symbolfile;
273 p->system_type = system_type;
274 p->system_rev = system_rev;
275 return new AlphaSystem(p);
276}
277
278REGISTER_SIM_OBJECT("AlphaSystem", AlphaSystem)
279
280