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