backdoor.cc revision 10565:23593fdaadcd
1/*
2 * Copyright (c) 2001-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: Nathan Binkert
29 *          Ali Saidi
30 *          Steve Reinhardt
31 *          Erik Hallnor
32 */
33
34/** @file
35 * Alpha Console Backdoor Definition
36 */
37
38#include <cstddef>
39#include <string>
40
41#include "arch/alpha/system.hh"
42#include "base/inifile.hh"
43#include "base/str.hh"
44#include "base/trace.hh"
45#include "cpu/base.hh"
46#include "cpu/thread_context.hh"
47#include "debug/AlphaBackdoor.hh"
48#include "dev/alpha/backdoor.hh"
49#include "dev/alpha/tsunami.hh"
50#include "dev/alpha/tsunami_cchip.hh"
51#include "dev/alpha/tsunami_io.hh"
52#include "dev/platform.hh"
53#include "dev/simple_disk.hh"
54#include "dev/terminal.hh"
55#include "mem/packet.hh"
56#include "mem/packet_access.hh"
57#include "mem/physical.hh"
58#include "params/AlphaBackdoor.hh"
59#include "sim/sim_object.hh"
60
61using namespace std;
62using namespace AlphaISA;
63
64AlphaBackdoor::AlphaBackdoor(const Params *p)
65    : BasicPioDevice(p, sizeof(struct AlphaAccess)),
66      disk(p->disk), terminal(p->terminal),
67      system(p->system), cpu(p->cpu)
68{
69    alphaAccess = new Access();
70    alphaAccess->last_offset = pioSize - 1;
71
72    alphaAccess->version = ALPHA_ACCESS_VERSION;
73    alphaAccess->diskUnit = 1;
74
75    alphaAccess->diskCount = 0;
76    alphaAccess->diskPAddr = 0;
77    alphaAccess->diskBlock = 0;
78    alphaAccess->diskOperation = 0;
79    alphaAccess->outputChar = 0;
80    alphaAccess->inputChar = 0;
81    std::memset(alphaAccess->cpuStack, 0, sizeof(alphaAccess->cpuStack));
82
83}
84
85void
86AlphaBackdoor::startup()
87{
88    system->setAlphaAccess(pioAddr);
89    alphaAccess->numCPUs = system->numContexts();
90    alphaAccess->kernStart = system->getKernelStart();
91    alphaAccess->kernEnd = system->getKernelEnd();
92    alphaAccess->entryPoint = system->getKernelEntry();
93    alphaAccess->mem_size = system->memSize();
94    alphaAccess->cpuClock = cpu->frequency() / 1000000; // In MHz
95    Tsunami *tsunami = dynamic_cast<Tsunami *>(params()->platform);
96    if (!tsunami)
97        fatal("Platform is not Tsunami.\n");
98    alphaAccess->intrClockFrequency = tsunami->io->frequency();
99}
100
101Tick
102AlphaBackdoor::read(PacketPtr pkt)
103{
104
105    /** XXX Do we want to push the addr munging to a bus brige or something? So
106     * the device has it's physical address and then the bridge adds on whatever
107     * machine dependent address swizzle is required?
108     */
109
110    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
111
112    Addr daddr = pkt->getAddr() - pioAddr;
113
114    pkt->makeAtomicResponse();
115
116    switch (pkt->getSize())
117    {
118        case sizeof(uint32_t):
119            switch (daddr)
120            {
121                case offsetof(AlphaAccess, last_offset):
122                    pkt->set(alphaAccess->last_offset);
123                    break;
124                case offsetof(AlphaAccess, version):
125                    pkt->set(alphaAccess->version);
126                    break;
127                case offsetof(AlphaAccess, numCPUs):
128                    pkt->set(alphaAccess->numCPUs);
129                    break;
130                case offsetof(AlphaAccess, intrClockFrequency):
131                    pkt->set(alphaAccess->intrClockFrequency);
132                    break;
133                default:
134                    /* Old console code read in everyting as a 32bit int
135                     * we now break that for better error checking.
136                     */
137                  pkt->setBadAddress();
138            }
139            DPRINTF(AlphaBackdoor, "read: offset=%#x val=%#x\n", daddr,
140                    pkt->get<uint32_t>());
141            break;
142        case sizeof(uint64_t):
143            switch (daddr)
144            {
145                case offsetof(AlphaAccess, inputChar):
146                    pkt->set(terminal->console_in());
147                    break;
148                case offsetof(AlphaAccess, cpuClock):
149                    pkt->set(alphaAccess->cpuClock);
150                    break;
151                case offsetof(AlphaAccess, mem_size):
152                    pkt->set(alphaAccess->mem_size);
153                    break;
154                case offsetof(AlphaAccess, kernStart):
155                    pkt->set(alphaAccess->kernStart);
156                    break;
157                case offsetof(AlphaAccess, kernEnd):
158                    pkt->set(alphaAccess->kernEnd);
159                    break;
160                case offsetof(AlphaAccess, entryPoint):
161                    pkt->set(alphaAccess->entryPoint);
162                    break;
163                case offsetof(AlphaAccess, diskUnit):
164                    pkt->set(alphaAccess->diskUnit);
165                    break;
166                case offsetof(AlphaAccess, diskCount):
167                    pkt->set(alphaAccess->diskCount);
168                    break;
169                case offsetof(AlphaAccess, diskPAddr):
170                    pkt->set(alphaAccess->diskPAddr);
171                    break;
172                case offsetof(AlphaAccess, diskBlock):
173                    pkt->set(alphaAccess->diskBlock);
174                    break;
175                case offsetof(AlphaAccess, diskOperation):
176                    pkt->set(alphaAccess->diskOperation);
177                    break;
178                case offsetof(AlphaAccess, outputChar):
179                    pkt->set(alphaAccess->outputChar);
180                    break;
181                default:
182                    int cpunum = (daddr - offsetof(AlphaAccess, cpuStack)) /
183                                 sizeof(alphaAccess->cpuStack[0]);
184
185                    if (cpunum >= 0 && cpunum < 64)
186                        pkt->set(alphaAccess->cpuStack[cpunum]);
187                    else
188                        panic("Unknown 64bit access, %#x\n", daddr);
189            }
190            DPRINTF(AlphaBackdoor, "read: offset=%#x val=%#x\n", daddr,
191                    pkt->get<uint64_t>());
192            break;
193        default:
194          pkt->setBadAddress();
195    }
196    return pioDelay;
197}
198
199Tick
200AlphaBackdoor::write(PacketPtr pkt)
201{
202    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
203    Addr daddr = pkt->getAddr() - pioAddr;
204
205    uint64_t val = pkt->get<uint64_t>();
206    assert(pkt->getSize() == sizeof(uint64_t));
207
208    switch (daddr) {
209      case offsetof(AlphaAccess, diskUnit):
210        alphaAccess->diskUnit = val;
211        break;
212
213      case offsetof(AlphaAccess, diskCount):
214        alphaAccess->diskCount = val;
215        break;
216
217      case offsetof(AlphaAccess, diskPAddr):
218        alphaAccess->diskPAddr = val;
219        break;
220
221      case offsetof(AlphaAccess, diskBlock):
222        alphaAccess->diskBlock = val;
223        break;
224
225      case offsetof(AlphaAccess, diskOperation):
226        if (val == 0x13)
227            disk->read(alphaAccess->diskPAddr, alphaAccess->diskBlock,
228                       alphaAccess->diskCount);
229        else
230            panic("Invalid disk operation!");
231
232        break;
233
234      case offsetof(AlphaAccess, outputChar):
235        terminal->out((char)(val & 0xff));
236        break;
237
238      default:
239        int cpunum = (daddr - offsetof(AlphaAccess, cpuStack)) /
240                     sizeof(alphaAccess->cpuStack[0]);
241        inform("Launching CPU %d @ %d", cpunum, curTick());
242        assert(val > 0 && "Must not access primary cpu");
243        if (cpunum >= 0 && cpunum < 64)
244            alphaAccess->cpuStack[cpunum] = val;
245        else
246            panic("Unknown 64bit access, %#x\n", daddr);
247    }
248
249    pkt->makeAtomicResponse();
250
251    return pioDelay;
252}
253
254void
255AlphaBackdoor::Access::serialize(ostream &os)
256{
257    SERIALIZE_SCALAR(last_offset);
258    SERIALIZE_SCALAR(version);
259    SERIALIZE_SCALAR(numCPUs);
260    SERIALIZE_SCALAR(mem_size);
261    SERIALIZE_SCALAR(cpuClock);
262    SERIALIZE_SCALAR(intrClockFrequency);
263    SERIALIZE_SCALAR(kernStart);
264    SERIALIZE_SCALAR(kernEnd);
265    SERIALIZE_SCALAR(entryPoint);
266    SERIALIZE_SCALAR(diskUnit);
267    SERIALIZE_SCALAR(diskCount);
268    SERIALIZE_SCALAR(diskPAddr);
269    SERIALIZE_SCALAR(diskBlock);
270    SERIALIZE_SCALAR(diskOperation);
271    SERIALIZE_SCALAR(outputChar);
272    SERIALIZE_SCALAR(inputChar);
273    SERIALIZE_ARRAY(cpuStack,64);
274}
275
276void
277AlphaBackdoor::Access::unserialize(Checkpoint *cp, const std::string &section)
278{
279    UNSERIALIZE_SCALAR(last_offset);
280    UNSERIALIZE_SCALAR(version);
281    UNSERIALIZE_SCALAR(numCPUs);
282    UNSERIALIZE_SCALAR(mem_size);
283    UNSERIALIZE_SCALAR(cpuClock);
284    UNSERIALIZE_SCALAR(intrClockFrequency);
285    UNSERIALIZE_SCALAR(kernStart);
286    UNSERIALIZE_SCALAR(kernEnd);
287    UNSERIALIZE_SCALAR(entryPoint);
288    UNSERIALIZE_SCALAR(diskUnit);
289    UNSERIALIZE_SCALAR(diskCount);
290    UNSERIALIZE_SCALAR(diskPAddr);
291    UNSERIALIZE_SCALAR(diskBlock);
292    UNSERIALIZE_SCALAR(diskOperation);
293    UNSERIALIZE_SCALAR(outputChar);
294    UNSERIALIZE_SCALAR(inputChar);
295    UNSERIALIZE_ARRAY(cpuStack, 64);
296}
297
298void
299AlphaBackdoor::serialize(ostream &os)
300{
301    alphaAccess->serialize(os);
302}
303
304void
305AlphaBackdoor::unserialize(Checkpoint *cp, const std::string &section)
306{
307    alphaAccess->unserialize(cp, section);
308}
309
310AlphaBackdoor *
311AlphaBackdoorParams::create()
312{
313    return new AlphaBackdoor(this);
314}
315