system.cc (7447:3fc243687abb) system.cc (7580:6f77f379a594)
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 <sys/signal.h>
33
34#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 "mem/physical.hh"
41#include "params/AlphaSystem.hh"
42#include "sim/byteswap.hh"
43
44using namespace AlphaISA;
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);
58 if (console == NULL)
59 fatal("Could not load console file %s", params()->console);
60
61 // Load pal file
62 pal = createObjectFile(params()->pal);
63 if (pal == NULL)
64 fatal("Could not load PALcode file %s", params()->pal);
65
66
67 // Load program sections into memory
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 <sys/signal.h>
33
34#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 "mem/physical.hh"
41#include "params/AlphaSystem.hh"
42#include "sim/byteswap.hh"
43
44using namespace AlphaISA;
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);
58 if (console == NULL)
59 fatal("Could not load console file %s", params()->console);
60
61 // Load pal file
62 pal = createObjectFile(params()->pal);
63 if (pal == NULL)
64 fatal("Could not load PALcode file %s", params()->pal);
65
66
67 // Load program sections into memory
68 pal->loadSections(&functionalPort, LoadAddrMask);
69 console->loadSections(&functionalPort, LoadAddrMask);
68 pal->loadSections(&functionalPort, loadAddrMask);
69 console->loadSections(&functionalPort, 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
120AlphaSystem::~AlphaSystem()
121{
122 delete consoleSymtab;
123 delete console;
124 delete pal;
125#ifdef DEBUG
126 delete consolePanicEvent;
127#endif
128}
129
130/**
131 * This function fixes up addresses that are used to match PCs for
132 * hooking simulator events on to target function executions.
133 *
134 * Alpha binaries may have multiple global offset table (GOT)
135 * sections. A function that uses the GOT starts with a
136 * two-instruction prolog which sets the global pointer (gp == r29) to
137 * the appropriate GOT section. The proper gp value is calculated
138 * based on the function address, which must be passed by the caller
139 * in the procedure value register (pv aka t12 == r27). This sequence
140 * looks like the following:
141 *
142 * opcode Ra Rb offset
143 * ldah gp,X(pv) 09 29 27 X
144 * lda gp,Y(gp) 08 29 29 Y
145 *
146 * for some constant offsets X and Y. The catch is that the linker
147 * (or maybe even the compiler, I'm not sure) may recognize that the
148 * caller and callee are using the same GOT section, making this
149 * prolog redundant, and modify the call target to skip these
150 * instructions. If we check for execution of the first instruction
151 * of a function (the one the symbol points to) to detect when to skip
152 * it, we'll miss all these modified calls. It might work to
153 * unconditionally check for the third instruction, but not all
154 * functions have this prolog, and there's some chance that those
155 * first two instructions could have undesired consequences. So we do
156 * the Right Thing and pattern-match the first two instructions of the
157 * function to decide where to patch.
158 *
159 * Eventually this code should be moved into an ISA-specific file.
160 */
161Addr
162AlphaSystem::fixFuncEventAddr(Addr addr)
163{
164 // mask for just the opcode, Ra, and Rb fields (not the offset)
165 const uint32_t inst_mask = 0xffff0000;
166 // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27
167 const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16);
168 // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29
169 const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16);
170
171 uint32_t i1 = virtPort.read<uint32_t>(addr);
172 uint32_t i2 = virtPort.read<uint32_t>(addr + sizeof(MachInst));
173
174 if ((i1 & inst_mask) == gp_ldah_pattern &&
175 (i2 & inst_mask) == gp_lda_pattern) {
176 Addr new_addr = addr + 2 * sizeof(MachInst);
177 DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr);
178 return new_addr;
179 } else {
180 return addr;
181 }
182}
183
184void
185AlphaSystem::setAlphaAccess(Addr access)
186{
187 Addr addr = 0;
188 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) {
189 virtPort.write(addr, htog(Phys2K0Seg(access)));
190 } else {
191 panic("could not find m5AlphaAccess\n");
192 }
193}
194
195void
196AlphaSystem::serialize(std::ostream &os)
197{
198 System::serialize(os);
199 consoleSymtab->serialize("console_symtab", os);
200 palSymtab->serialize("pal_symtab", os);
201}
202
203void
204AlphaSystem::unserialize(Checkpoint *cp, const std::string &section)
205{
206 System::unserialize(cp,section);
207 consoleSymtab->unserialize("console_symtab", cp, section);
208 palSymtab->unserialize("pal_symtab", cp, section);
209}
210
211AlphaSystem *
212AlphaSystemParams::create()
213{
214 return new AlphaSystem(this);
215}
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
120AlphaSystem::~AlphaSystem()
121{
122 delete consoleSymtab;
123 delete console;
124 delete pal;
125#ifdef DEBUG
126 delete consolePanicEvent;
127#endif
128}
129
130/**
131 * This function fixes up addresses that are used to match PCs for
132 * hooking simulator events on to target function executions.
133 *
134 * Alpha binaries may have multiple global offset table (GOT)
135 * sections. A function that uses the GOT starts with a
136 * two-instruction prolog which sets the global pointer (gp == r29) to
137 * the appropriate GOT section. The proper gp value is calculated
138 * based on the function address, which must be passed by the caller
139 * in the procedure value register (pv aka t12 == r27). This sequence
140 * looks like the following:
141 *
142 * opcode Ra Rb offset
143 * ldah gp,X(pv) 09 29 27 X
144 * lda gp,Y(gp) 08 29 29 Y
145 *
146 * for some constant offsets X and Y. The catch is that the linker
147 * (or maybe even the compiler, I'm not sure) may recognize that the
148 * caller and callee are using the same GOT section, making this
149 * prolog redundant, and modify the call target to skip these
150 * instructions. If we check for execution of the first instruction
151 * of a function (the one the symbol points to) to detect when to skip
152 * it, we'll miss all these modified calls. It might work to
153 * unconditionally check for the third instruction, but not all
154 * functions have this prolog, and there's some chance that those
155 * first two instructions could have undesired consequences. So we do
156 * the Right Thing and pattern-match the first two instructions of the
157 * function to decide where to patch.
158 *
159 * Eventually this code should be moved into an ISA-specific file.
160 */
161Addr
162AlphaSystem::fixFuncEventAddr(Addr addr)
163{
164 // mask for just the opcode, Ra, and Rb fields (not the offset)
165 const uint32_t inst_mask = 0xffff0000;
166 // ldah gp,X(pv): opcode 9, Ra = 29, Rb = 27
167 const uint32_t gp_ldah_pattern = (9 << 26) | (29 << 21) | (27 << 16);
168 // lda gp,Y(gp): opcode 8, Ra = 29, rb = 29
169 const uint32_t gp_lda_pattern = (8 << 26) | (29 << 21) | (29 << 16);
170
171 uint32_t i1 = virtPort.read<uint32_t>(addr);
172 uint32_t i2 = virtPort.read<uint32_t>(addr + sizeof(MachInst));
173
174 if ((i1 & inst_mask) == gp_ldah_pattern &&
175 (i2 & inst_mask) == gp_lda_pattern) {
176 Addr new_addr = addr + 2 * sizeof(MachInst);
177 DPRINTF(Loader, "fixFuncEventAddr: %p -> %p", addr, new_addr);
178 return new_addr;
179 } else {
180 return addr;
181 }
182}
183
184void
185AlphaSystem::setAlphaAccess(Addr access)
186{
187 Addr addr = 0;
188 if (consoleSymtab->findAddress("m5AlphaAccess", addr)) {
189 virtPort.write(addr, htog(Phys2K0Seg(access)));
190 } else {
191 panic("could not find m5AlphaAccess\n");
192 }
193}
194
195void
196AlphaSystem::serialize(std::ostream &os)
197{
198 System::serialize(os);
199 consoleSymtab->serialize("console_symtab", os);
200 palSymtab->serialize("pal_symtab", os);
201}
202
203void
204AlphaSystem::unserialize(Checkpoint *cp, const std::string &section)
205{
206 System::unserialize(cp,section);
207 consoleSymtab->unserialize("console_symtab", cp, section);
208 palSymtab->unserialize("pal_symtab", cp, section);
209}
210
211AlphaSystem *
212AlphaSystemParams::create()
213{
214 return new AlphaSystem(this);
215}