system.cc (10905:a6ca6831e775) system.cc (11793:ef606668d247)
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
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/system.hh"
33
32#include <sys/signal.h>
33
34#include "arch/alpha/ev5.hh"
34#include <sys/signal.h>
35
36#include "arch/alpha/ev5.hh"
35#include "arch/alpha/system.hh"
36#include "arch/vtophys.hh"
37#include "base/loader/object_file.hh"
38#include "base/loader/symtab.hh"
39#include "base/trace.hh"
40#include "debug/Loader.hh"
41#include "mem/fs_translating_port_proxy.hh"
42#include "params/AlphaSystem.hh"
43#include "sim/byteswap.hh"
44
45using namespace AlphaISA;
46
47AlphaSystem::AlphaSystem(Params *p)
48 : System(p), intrFreq(0), virtProxy(getSystemPort(), p->cache_line_size)
49{
50 consoleSymtab = new SymbolTable;
51 palSymtab = new SymbolTable;
52
53
54 /**
55 * Load the pal, and console code into memory
56 */
57 // Load Console Code
58 console = createObjectFile(params()->console);
59 if (console == NULL)
60 fatal("Could not load console file %s", params()->console);
61
62 // Load pal file
63 pal = createObjectFile(params()->pal);
64 if (pal == NULL)
65 fatal("Could not load PALcode file %s", params()->pal);
66
67 // load symbols
68 if (!console->loadGlobalSymbols(consoleSymtab))
69 panic("could not load console symbols\n");
70
71 if (!pal->loadGlobalSymbols(palSymtab))
72 panic("could not load pal symbols\n");
73
74 if (!pal->loadLocalSymbols(palSymtab))
75 panic("could not load pal symbols\n");
76
77 if (!console->loadGlobalSymbols(debugSymbolTable))
78 panic("could not load console symbols\n");
79
80 if (!pal->loadGlobalSymbols(debugSymbolTable))
81 panic("could not load pal symbols\n");
82
83 if (!pal->loadLocalSymbols(debugSymbolTable))
84 panic("could not load pal symbols\n");
85
86
87}
88
89AlphaSystem::~AlphaSystem()
90{
91 delete consoleSymtab;
92 delete console;
93 delete pal;
94#ifdef DEBUG
95 delete consolePanicEvent;
96#endif
97}
98
99void
100AlphaSystem::initState()
101{
102 Addr addr = 0;
103
104 // Moved from the constructor to here since it relies on the
105 // address map being resolved in the interconnect
106
107 // Call the initialisation of the super class
108 System::initState();
109
110 // Load program sections into memory
111 pal->loadSections(physProxy, loadAddrMask);
112 console->loadSections(physProxy, loadAddrMask);
113
114 /**
115 * Copy the osflags (kernel arguments) into the consoles
116 * memory. (Presently Linux does not use the console service
117 * routine to get these command line arguments, but Tru64 and
118 * others do.)
119 */
120 if (consoleSymtab->findAddress("env_booted_osflags", addr)) {
121 virtProxy.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(),
122 strlen(params()->boot_osflags.c_str()));
123 }
124
125 /**
126 * Set the hardware reset parameter block system type and revision
127 * information to Tsunami.
128 */
129 if (consoleSymtab->findAddress("m5_rpb", addr)) {
130 uint64_t data;
131 data = htog(params()->system_type);
132 virtProxy.write(addr+0x50, data);
133 data = htog(params()->system_rev);
134 virtProxy.write(addr+0x58, data);
135 } else
136 panic("could not find hwrpb\n");
137}
138
139void
140AlphaSystem::startup()
141{
142 // Setup all the function events now that we have a system and a symbol
143 // table
144 setupFuncEvents();
145}
146
147void
148AlphaSystem::setupFuncEvents()
149{
150#ifndef NDEBUG
151 consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic");
152#endif
153}
154
155/**
156 * This function fixes up addresses that are used to match PCs for
157 * hooking simulator events on to target function executions.
158 *
159 * Alpha binaries may have multiple global offset table (GOT)
160 * sections. A function that uses the GOT starts with a
161 * two-instruction prolog which sets the global pointer (gp == r29) to
162 * the appropriate GOT section. The proper gp value is calculated
163 * based on the function address, which must be passed by the caller
164 * in the procedure value register (pv aka t12 == r27). This sequence
165 * looks like the following:
166 *
167 * opcode Ra Rb offset
168 * ldah gp,X(pv) 09 29 27 X
169 * lda gp,Y(gp) 08 29 29 Y
170 *
171 * for some constant offsets X and Y. The catch is that the linker
172 * (or maybe even the compiler, I'm not sure) may recognize that the
173 * caller and callee are using the same GOT section, making this
174 * prolog redundant, and modify the call target to skip these
175 * instructions. If we check for execution of the first instruction
176 * of a function (the one the symbol points to) to detect when to skip
177 * it, we'll miss all these modified calls. It might work to
178 * unconditionally check for the third instruction, but not all
179 * functions have this prolog, and there's some chance that those
180 * first two instructions could have undesired consequences. So we do
181 * the Right Thing and pattern-match the first two instructions of the
182 * function to decide where to patch.
183 *
184 * Eventually this code should be moved into an ISA-specific file.
185 */
186Addr
187AlphaSystem::fixFuncEventAddr(Addr addr)
188{
189 // mask for just the opcode, Ra, and Rb fields (not the offset)
190 const uint32_t inst_mask = 0xffff0000;
191 // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27
192 const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16);
193 // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29
194 const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16);
195
196 uint32_t i1 = virtProxy.read<uint32_t>(addr);
197 uint32_t i2 = virtProxy.read<uint32_t>(addr + sizeof(MachInst));
198
199 if ((i1 & inst_mask) == gp_ldah_pattern &&
200 (i2 & inst_mask) == gp_lda_pattern) {
201 Addr new_addr = addr + 2 * sizeof(MachInst);
202 DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr);
203 return new_addr;
204 } else {
205 return addr;
206 }
207}
208
209void
210AlphaSystem::setAlphaAccess(Addr access)
211{
212 Addr addr = 0;
213 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) {
214 virtProxy.write(addr, htog(Phys2K0Seg(access)));
215 } else {
216 panic("could not find m5AlphaAccess\n");
217 }
218}
219
220void
221AlphaSystem::serializeSymtab(CheckpointOut &cp) const
222{
223 consoleSymtab->serialize("console_symtab", cp);
224 palSymtab->serialize("pal_symtab", cp);
225}
226
227void
228AlphaSystem::unserializeSymtab(CheckpointIn &cp)
229{
230 consoleSymtab->unserialize("console_symtab", cp);
231 palSymtab->unserialize("pal_symtab", cp);
232}
233
234AlphaSystem *
235AlphaSystemParams::create()
236{
237 return new AlphaSystem(this);
238}
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 "debug/Loader.hh"
42#include "mem/fs_translating_port_proxy.hh"
43#include "params/AlphaSystem.hh"
44#include "sim/byteswap.hh"
45
46using namespace AlphaISA;
47
48AlphaSystem::AlphaSystem(Params *p)
49 : System(p), intrFreq(0), virtProxy(getSystemPort(), p->cache_line_size)
50{
51 consoleSymtab = new SymbolTable;
52 palSymtab = new SymbolTable;
53
54
55 /**
56 * Load the pal, and console code into memory
57 */
58 // Load Console Code
59 console = createObjectFile(params()->console);
60 if (console == NULL)
61 fatal("Could not load console file %s", params()->console);
62
63 // Load pal file
64 pal = createObjectFile(params()->pal);
65 if (pal == NULL)
66 fatal("Could not load PALcode file %s", params()->pal);
67
68 // load symbols
69 if (!console->loadGlobalSymbols(consoleSymtab))
70 panic("could not load console symbols\n");
71
72 if (!pal->loadGlobalSymbols(palSymtab))
73 panic("could not load pal symbols\n");
74
75 if (!pal->loadLocalSymbols(palSymtab))
76 panic("could not load pal symbols\n");
77
78 if (!console->loadGlobalSymbols(debugSymbolTable))
79 panic("could not load console symbols\n");
80
81 if (!pal->loadGlobalSymbols(debugSymbolTable))
82 panic("could not load pal symbols\n");
83
84 if (!pal->loadLocalSymbols(debugSymbolTable))
85 panic("could not load pal symbols\n");
86
87
88}
89
90AlphaSystem::~AlphaSystem()
91{
92 delete consoleSymtab;
93 delete console;
94 delete pal;
95#ifdef DEBUG
96 delete consolePanicEvent;
97#endif
98}
99
100void
101AlphaSystem::initState()
102{
103 Addr addr = 0;
104
105 // Moved from the constructor to here since it relies on the
106 // address map being resolved in the interconnect
107
108 // Call the initialisation of the super class
109 System::initState();
110
111 // Load program sections into memory
112 pal->loadSections(physProxy, loadAddrMask);
113 console->loadSections(physProxy, loadAddrMask);
114
115 /**
116 * Copy the osflags (kernel arguments) into the consoles
117 * memory. (Presently Linux does not use the console service
118 * routine to get these command line arguments, but Tru64 and
119 * others do.)
120 */
121 if (consoleSymtab->findAddress("env_booted_osflags", addr)) {
122 virtProxy.writeBlob(addr, (uint8_t*)params()->boot_osflags.c_str(),
123 strlen(params()->boot_osflags.c_str()));
124 }
125
126 /**
127 * Set the hardware reset parameter block system type and revision
128 * information to Tsunami.
129 */
130 if (consoleSymtab->findAddress("m5_rpb", addr)) {
131 uint64_t data;
132 data = htog(params()->system_type);
133 virtProxy.write(addr+0x50, data);
134 data = htog(params()->system_rev);
135 virtProxy.write(addr+0x58, data);
136 } else
137 panic("could not find hwrpb\n");
138}
139
140void
141AlphaSystem::startup()
142{
143 // Setup all the function events now that we have a system and a symbol
144 // table
145 setupFuncEvents();
146}
147
148void
149AlphaSystem::setupFuncEvents()
150{
151#ifndef NDEBUG
152 consolePanicEvent = addConsoleFuncEvent<BreakPCEvent>("panic");
153#endif
154}
155
156/**
157 * This function fixes up addresses that are used to match PCs for
158 * hooking simulator events on to target function executions.
159 *
160 * Alpha binaries may have multiple global offset table (GOT)
161 * sections. A function that uses the GOT starts with a
162 * two-instruction prolog which sets the global pointer (gp == r29) to
163 * the appropriate GOT section. The proper gp value is calculated
164 * based on the function address, which must be passed by the caller
165 * in the procedure value register (pv aka t12 == r27). This sequence
166 * looks like the following:
167 *
168 * opcode Ra Rb offset
169 * ldah gp,X(pv) 09 29 27 X
170 * lda gp,Y(gp) 08 29 29 Y
171 *
172 * for some constant offsets X and Y. The catch is that the linker
173 * (or maybe even the compiler, I'm not sure) may recognize that the
174 * caller and callee are using the same GOT section, making this
175 * prolog redundant, and modify the call target to skip these
176 * instructions. If we check for execution of the first instruction
177 * of a function (the one the symbol points to) to detect when to skip
178 * it, we'll miss all these modified calls. It might work to
179 * unconditionally check for the third instruction, but not all
180 * functions have this prolog, and there's some chance that those
181 * first two instructions could have undesired consequences. So we do
182 * the Right Thing and pattern-match the first two instructions of the
183 * function to decide where to patch.
184 *
185 * Eventually this code should be moved into an ISA-specific file.
186 */
187Addr
188AlphaSystem::fixFuncEventAddr(Addr addr)
189{
190 // mask for just the opcode, Ra, and Rb fields (not the offset)
191 const uint32_t inst_mask = 0xffff0000;
192 // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27
193 const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16);
194 // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29
195 const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16);
196
197 uint32_t i1 = virtProxy.read<uint32_t>(addr);
198 uint32_t i2 = virtProxy.read<uint32_t>(addr + sizeof(MachInst));
199
200 if ((i1 & inst_mask) == gp_ldah_pattern &&
201 (i2 & inst_mask) == gp_lda_pattern) {
202 Addr new_addr = addr + 2 * sizeof(MachInst);
203 DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr);
204 return new_addr;
205 } else {
206 return addr;
207 }
208}
209
210void
211AlphaSystem::setAlphaAccess(Addr access)
212{
213 Addr addr = 0;
214 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) {
215 virtProxy.write(addr, htog(Phys2K0Seg(access)));
216 } else {
217 panic("could not find m5AlphaAccess\n");
218 }
219}
220
221void
222AlphaSystem::serializeSymtab(CheckpointOut &cp) const
223{
224 consoleSymtab->serialize("console_symtab", cp);
225 palSymtab->serialize("pal_symtab", cp);
226}
227
228void
229AlphaSystem::unserializeSymtab(CheckpointIn &cp)
230{
231 consoleSymtab->unserialize("console_symtab", cp);
232 palSymtab->unserialize("pal_symtab", cp);
233}
234
235AlphaSystem *
236AlphaSystemParams::create()
237{
238 return new AlphaSystem(this);
239}