backdoor.cc revision 11793
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 2001-2005 The Regents of The University of Michigan
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org *
286145Snate@binkert.org * Authors: Nathan Binkert
296145Snate@binkert.org *          Ali Saidi
306145Snate@binkert.org *          Steve Reinhardt
316145Snate@binkert.org *          Erik Hallnor
326145Snate@binkert.org */
336154Snate@binkert.org
346154Snate@binkert.org/** @file
356154Snate@binkert.org * Alpha Console Backdoor Definition
366145Snate@binkert.org */
376145Snate@binkert.org
386145Snate@binkert.org#include "dev/alpha/backdoor.hh"
396145Snate@binkert.org
406145Snate@binkert.org#include <cstddef>
416145Snate@binkert.org#include <string>
426145Snate@binkert.org
436145Snate@binkert.org#include "arch/alpha/system.hh"
446145Snate@binkert.org#include "base/inifile.hh"
456145Snate@binkert.org#include "base/str.hh"
466145Snate@binkert.org#include "base/trace.hh"
476145Snate@binkert.org#include "cpu/base.hh"
486145Snate@binkert.org#include "cpu/thread_context.hh"
496145Snate@binkert.org#include "debug/AlphaBackdoor.hh"
506145Snate@binkert.org#include "dev/alpha/tsunami.hh"
516145Snate@binkert.org#include "dev/alpha/tsunami_cchip.hh"
526145Snate@binkert.org#include "dev/alpha/tsunami_io.hh"
536145Snate@binkert.org#include "dev/platform.hh"
546145Snate@binkert.org#include "dev/storage/simple_disk.hh"
556145Snate@binkert.org#include "dev/terminal.hh"
566145Snate@binkert.org#include "mem/packet.hh"
576145Snate@binkert.org#include "mem/packet_access.hh"
586145Snate@binkert.org#include "mem/physical.hh"
596145Snate@binkert.org#include "params/AlphaBackdoor.hh"
606145Snate@binkert.org#include "sim/sim_object.hh"
616145Snate@binkert.org
626145Snate@binkert.orgusing namespace std;
636145Snate@binkert.orgusing namespace AlphaISA;
646145Snate@binkert.org
656145Snate@binkert.orgAlphaBackdoor::AlphaBackdoor(const Params *p)
666145Snate@binkert.org    : BasicPioDevice(p, sizeof(struct AlphaAccess)),
676145Snate@binkert.org      disk(p->disk), terminal(p->terminal),
686145Snate@binkert.org      system(p->system), cpu(p->cpu)
696145Snate@binkert.org{
706145Snate@binkert.org    alphaAccess = new Access();
716145Snate@binkert.org    alphaAccess->last_offset = pioSize - 1;
726145Snate@binkert.org
736145Snate@binkert.org    alphaAccess->version = ALPHA_ACCESS_VERSION;
746145Snate@binkert.org    alphaAccess->diskUnit = 1;
756145Snate@binkert.org
766145Snate@binkert.org    alphaAccess->diskCount = 0;
776145Snate@binkert.org    alphaAccess->diskPAddr = 0;
786145Snate@binkert.org    alphaAccess->diskBlock = 0;
796145Snate@binkert.org    alphaAccess->diskOperation = 0;
806145Snate@binkert.org    alphaAccess->outputChar = 0;
816145Snate@binkert.org    alphaAccess->inputChar = 0;
826145Snate@binkert.org    std::memset(alphaAccess->cpuStack, 0, sizeof(alphaAccess->cpuStack));
83
84}
85
86void
87AlphaBackdoor::startup()
88{
89    system->setAlphaAccess(pioAddr);
90    alphaAccess->numCPUs = system->numContexts();
91    alphaAccess->kernStart = system->getKernelStart();
92    alphaAccess->kernEnd = system->getKernelEnd();
93    alphaAccess->entryPoint = system->getKernelEntry();
94    alphaAccess->mem_size = system->memSize();
95    alphaAccess->cpuClock = cpu->frequency() / 1000000; // In MHz
96    Tsunami *tsunami = dynamic_cast<Tsunami *>(params()->platform);
97    if (!tsunami)
98        fatal("Platform is not Tsunami.\n");
99    alphaAccess->intrClockFrequency = tsunami->io->frequency();
100}
101
102Tick
103AlphaBackdoor::read(PacketPtr pkt)
104{
105
106    /** XXX Do we want to push the addr munging to a bus brige or something? So
107     * the device has it's physical address and then the bridge adds on whatever
108     * machine dependent address swizzle is required?
109     */
110
111    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
112
113    Addr daddr = pkt->getAddr() - pioAddr;
114
115    pkt->makeAtomicResponse();
116
117    switch (pkt->getSize())
118    {
119        case sizeof(uint32_t):
120            switch (daddr)
121            {
122                case offsetof(AlphaAccess, last_offset):
123                    pkt->set(alphaAccess->last_offset);
124                    break;
125                case offsetof(AlphaAccess, version):
126                    pkt->set(alphaAccess->version);
127                    break;
128                case offsetof(AlphaAccess, numCPUs):
129                    pkt->set(alphaAccess->numCPUs);
130                    break;
131                case offsetof(AlphaAccess, intrClockFrequency):
132                    pkt->set(alphaAccess->intrClockFrequency);
133                    break;
134                default:
135                    /* Old console code read in everyting as a 32bit int
136                     * we now break that for better error checking.
137                     */
138                  pkt->setBadAddress();
139            }
140            DPRINTF(AlphaBackdoor, "read: offset=%#x val=%#x\n", daddr,
141                    pkt->get<uint32_t>());
142            break;
143        case sizeof(uint64_t):
144            switch (daddr)
145            {
146                case offsetof(AlphaAccess, inputChar):
147                    pkt->set(terminal->console_in());
148                    break;
149                case offsetof(AlphaAccess, cpuClock):
150                    pkt->set(alphaAccess->cpuClock);
151                    break;
152                case offsetof(AlphaAccess, mem_size):
153                    pkt->set(alphaAccess->mem_size);
154                    break;
155                case offsetof(AlphaAccess, kernStart):
156                    pkt->set(alphaAccess->kernStart);
157                    break;
158                case offsetof(AlphaAccess, kernEnd):
159                    pkt->set(alphaAccess->kernEnd);
160                    break;
161                case offsetof(AlphaAccess, entryPoint):
162                    pkt->set(alphaAccess->entryPoint);
163                    break;
164                case offsetof(AlphaAccess, diskUnit):
165                    pkt->set(alphaAccess->diskUnit);
166                    break;
167                case offsetof(AlphaAccess, diskCount):
168                    pkt->set(alphaAccess->diskCount);
169                    break;
170                case offsetof(AlphaAccess, diskPAddr):
171                    pkt->set(alphaAccess->diskPAddr);
172                    break;
173                case offsetof(AlphaAccess, diskBlock):
174                    pkt->set(alphaAccess->diskBlock);
175                    break;
176                case offsetof(AlphaAccess, diskOperation):
177                    pkt->set(alphaAccess->diskOperation);
178                    break;
179                case offsetof(AlphaAccess, outputChar):
180                    pkt->set(alphaAccess->outputChar);
181                    break;
182                default:
183                    int cpunum = (daddr - offsetof(AlphaAccess, cpuStack)) /
184                                 sizeof(alphaAccess->cpuStack[0]);
185
186                    if (cpunum >= 0 && cpunum < 64)
187                        pkt->set(alphaAccess->cpuStack[cpunum]);
188                    else
189                        panic("Unknown 64bit access, %#x\n", daddr);
190            }
191            DPRINTF(AlphaBackdoor, "read: offset=%#x val=%#x\n", daddr,
192                    pkt->get<uint64_t>());
193            break;
194        default:
195          pkt->setBadAddress();
196    }
197    return pioDelay;
198}
199
200Tick
201AlphaBackdoor::write(PacketPtr pkt)
202{
203    assert(pkt->getAddr() >= pioAddr && pkt->getAddr() < pioAddr + pioSize);
204    Addr daddr = pkt->getAddr() - pioAddr;
205
206    uint64_t val = pkt->get<uint64_t>();
207    assert(pkt->getSize() == sizeof(uint64_t));
208
209    switch (daddr) {
210      case offsetof(AlphaAccess, diskUnit):
211        alphaAccess->diskUnit = val;
212        break;
213
214      case offsetof(AlphaAccess, diskCount):
215        alphaAccess->diskCount = val;
216        break;
217
218      case offsetof(AlphaAccess, diskPAddr):
219        alphaAccess->diskPAddr = val;
220        break;
221
222      case offsetof(AlphaAccess, diskBlock):
223        alphaAccess->diskBlock = val;
224        break;
225
226      case offsetof(AlphaAccess, diskOperation):
227        if (val == 0x13)
228            disk->read(alphaAccess->diskPAddr, alphaAccess->diskBlock,
229                       alphaAccess->diskCount);
230        else
231            panic("Invalid disk operation!");
232
233        break;
234
235      case offsetof(AlphaAccess, outputChar):
236        terminal->out((char)(val & 0xff));
237        break;
238
239      default:
240        int cpunum = (daddr - offsetof(AlphaAccess, cpuStack)) /
241                     sizeof(alphaAccess->cpuStack[0]);
242        inform("Launching CPU %d @ %d", cpunum, curTick());
243        assert(val > 0 && "Must not access primary cpu");
244        if (cpunum >= 0 && cpunum < 64)
245            alphaAccess->cpuStack[cpunum] = val;
246        else
247            panic("Unknown 64bit access, %#x\n", daddr);
248    }
249
250    pkt->makeAtomicResponse();
251
252    return pioDelay;
253}
254
255void
256AlphaBackdoor::Access::serialize(CheckpointOut &cp) const
257{
258    SERIALIZE_SCALAR(last_offset);
259    SERIALIZE_SCALAR(version);
260    SERIALIZE_SCALAR(numCPUs);
261    SERIALIZE_SCALAR(mem_size);
262    SERIALIZE_SCALAR(cpuClock);
263    SERIALIZE_SCALAR(intrClockFrequency);
264    SERIALIZE_SCALAR(kernStart);
265    SERIALIZE_SCALAR(kernEnd);
266    SERIALIZE_SCALAR(entryPoint);
267    SERIALIZE_SCALAR(diskUnit);
268    SERIALIZE_SCALAR(diskCount);
269    SERIALIZE_SCALAR(diskPAddr);
270    SERIALIZE_SCALAR(diskBlock);
271    SERIALIZE_SCALAR(diskOperation);
272    SERIALIZE_SCALAR(outputChar);
273    SERIALIZE_SCALAR(inputChar);
274    SERIALIZE_ARRAY(cpuStack,64);
275}
276
277void
278AlphaBackdoor::Access::unserialize(CheckpointIn &cp)
279{
280    UNSERIALIZE_SCALAR(last_offset);
281    UNSERIALIZE_SCALAR(version);
282    UNSERIALIZE_SCALAR(numCPUs);
283    UNSERIALIZE_SCALAR(mem_size);
284    UNSERIALIZE_SCALAR(cpuClock);
285    UNSERIALIZE_SCALAR(intrClockFrequency);
286    UNSERIALIZE_SCALAR(kernStart);
287    UNSERIALIZE_SCALAR(kernEnd);
288    UNSERIALIZE_SCALAR(entryPoint);
289    UNSERIALIZE_SCALAR(diskUnit);
290    UNSERIALIZE_SCALAR(diskCount);
291    UNSERIALIZE_SCALAR(diskPAddr);
292    UNSERIALIZE_SCALAR(diskBlock);
293    UNSERIALIZE_SCALAR(diskOperation);
294    UNSERIALIZE_SCALAR(outputChar);
295    UNSERIALIZE_SCALAR(inputChar);
296    UNSERIALIZE_ARRAY(cpuStack, 64);
297}
298
299void
300AlphaBackdoor::serialize(CheckpointOut &cp) const
301{
302    alphaAccess->serialize(cp);
303}
304
305void
306AlphaBackdoor::unserialize(CheckpointIn &cp)
307{
308    alphaAccess->unserialize(cp);
309}
310
311AlphaBackdoor *
312AlphaBackdoorParams::create()
313{
314    return new AlphaBackdoor(this);
315}
316