backdoor.cc revision 2114
113955Sgiacomo.gabrielli@arm.com/*
213955Sgiacomo.gabrielli@arm.com * Copyright (c) 2001-2005 The Regents of The University of Michigan
313955Sgiacomo.gabrielli@arm.com * All rights reserved.
413955Sgiacomo.gabrielli@arm.com *
513955Sgiacomo.gabrielli@arm.com * Redistribution and use in source and binary forms, with or without
613955Sgiacomo.gabrielli@arm.com * modification, are permitted provided that the following conditions are
713955Sgiacomo.gabrielli@arm.com * met: redistributions of source code must retain the above copyright
813955Sgiacomo.gabrielli@arm.com * notice, this list of conditions and the following disclaimer;
913955Sgiacomo.gabrielli@arm.com * redistributions in binary form must reproduce the above copyright
1013955Sgiacomo.gabrielli@arm.com * notice, this list of conditions and the following disclaimer in the
1113955Sgiacomo.gabrielli@arm.com * documentation and/or other materials provided with the distribution;
1213955Sgiacomo.gabrielli@arm.com * neither the name of the copyright holders nor the names of its
1313955Sgiacomo.gabrielli@arm.com * contributors may be used to endorse or promote products derived from
1413955Sgiacomo.gabrielli@arm.com * this software without specific prior written permission.
1513955Sgiacomo.gabrielli@arm.com *
1613955Sgiacomo.gabrielli@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713955Sgiacomo.gabrielli@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813955Sgiacomo.gabrielli@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913955Sgiacomo.gabrielli@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013955Sgiacomo.gabrielli@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113955Sgiacomo.gabrielli@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213955Sgiacomo.gabrielli@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313955Sgiacomo.gabrielli@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413955Sgiacomo.gabrielli@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513955Sgiacomo.gabrielli@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613955Sgiacomo.gabrielli@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713955Sgiacomo.gabrielli@arm.com */
2813955Sgiacomo.gabrielli@arm.com
2913955Sgiacomo.gabrielli@arm.com/** @file
3013955Sgiacomo.gabrielli@arm.com * Alpha Console Definition
3113955Sgiacomo.gabrielli@arm.com */
3213955Sgiacomo.gabrielli@arm.com
3313955Sgiacomo.gabrielli@arm.com#include <cstddef>
3413955Sgiacomo.gabrielli@arm.com#include <cstdio>
3513955Sgiacomo.gabrielli@arm.com#include <string>
3613955Sgiacomo.gabrielli@arm.com
3713955Sgiacomo.gabrielli@arm.com#include "base/inifile.hh"
3813955Sgiacomo.gabrielli@arm.com#include "base/str.hh"
3913955Sgiacomo.gabrielli@arm.com#include "base/trace.hh"
4013955Sgiacomo.gabrielli@arm.com#include "cpu/base.hh"
4113955Sgiacomo.gabrielli@arm.com#include "cpu/exec_context.hh"
4213955Sgiacomo.gabrielli@arm.com#include "dev/alpha_console.hh"
4313955Sgiacomo.gabrielli@arm.com#include "dev/simconsole.hh"
4413955Sgiacomo.gabrielli@arm.com#include "dev/simple_disk.hh"
4513955Sgiacomo.gabrielli@arm.com#include "dev/tsunami_io.hh"
4613955Sgiacomo.gabrielli@arm.com#include "mem/bus/bus.hh"
4713955Sgiacomo.gabrielli@arm.com#include "mem/bus/pio_interface.hh"
4813955Sgiacomo.gabrielli@arm.com#include "mem/bus/pio_interface_impl.hh"
4913955Sgiacomo.gabrielli@arm.com#include "mem/functional/memory_control.hh"
5013955Sgiacomo.gabrielli@arm.com#include "mem/functional/physical.hh"
5113955Sgiacomo.gabrielli@arm.com#include "sim/builder.hh"
5213955Sgiacomo.gabrielli@arm.com#include "sim/sim_object.hh"
5313955Sgiacomo.gabrielli@arm.com#include "sim/system.hh"
5413955Sgiacomo.gabrielli@arm.com
5513955Sgiacomo.gabrielli@arm.comusing namespace std;
5613955Sgiacomo.gabrielli@arm.com
5713955Sgiacomo.gabrielli@arm.comAlphaConsole::AlphaConsole(const string &name, SimConsole *cons, SimpleDisk *d,
5813955Sgiacomo.gabrielli@arm.com                           System *s, BaseCPU *c, Platform *p,
5913955Sgiacomo.gabrielli@arm.com                           MemoryController *mmu, Addr a,
6013955Sgiacomo.gabrielli@arm.com                           HierParams *hier, Bus *pio_bus)
6113955Sgiacomo.gabrielli@arm.com    : PioDevice(name, p), disk(d), console(cons), system(s), cpu(c), addr(a)
6213955Sgiacomo.gabrielli@arm.com{
6313955Sgiacomo.gabrielli@arm.com    mmu->add_child(this, RangeSize(addr, size));
6413955Sgiacomo.gabrielli@arm.com
6513955Sgiacomo.gabrielli@arm.com    if (pio_bus) {
6613955Sgiacomo.gabrielli@arm.com        pioInterface = newPioInterface(name + ".pio", hier, pio_bus, this,
6713955Sgiacomo.gabrielli@arm.com                                       &AlphaConsole::cacheAccess);
6813955Sgiacomo.gabrielli@arm.com        pioInterface->addAddrRange(RangeSize(addr, size));
6913955Sgiacomo.gabrielli@arm.com    }
7013955Sgiacomo.gabrielli@arm.com
7113955Sgiacomo.gabrielli@arm.com    alphaAccess = new Access;
7213955Sgiacomo.gabrielli@arm.com    alphaAccess->last_offset = size - 1;
7313955Sgiacomo.gabrielli@arm.com
7413955Sgiacomo.gabrielli@arm.com    alphaAccess->version = ALPHA_ACCESS_VERSION;
7513955Sgiacomo.gabrielli@arm.com    alphaAccess->diskUnit = 1;
7613955Sgiacomo.gabrielli@arm.com
7713955Sgiacomo.gabrielli@arm.com    alphaAccess->diskCount = 0;
7813955Sgiacomo.gabrielli@arm.com    alphaAccess->diskPAddr = 0;
7913955Sgiacomo.gabrielli@arm.com    alphaAccess->diskBlock = 0;
8013955Sgiacomo.gabrielli@arm.com    alphaAccess->diskOperation = 0;
8113955Sgiacomo.gabrielli@arm.com    alphaAccess->outputChar = 0;
8213955Sgiacomo.gabrielli@arm.com    alphaAccess->inputChar = 0;
8313955Sgiacomo.gabrielli@arm.com    bzero(alphaAccess->cpuStack, sizeof(alphaAccess->cpuStack));
8413955Sgiacomo.gabrielli@arm.com
8513955Sgiacomo.gabrielli@arm.com    system->setAlphaAccess(addr);
8613955Sgiacomo.gabrielli@arm.com}
8713955Sgiacomo.gabrielli@arm.com
8813955Sgiacomo.gabrielli@arm.comvoid
8913955Sgiacomo.gabrielli@arm.comAlphaConsole::startup()
9013955Sgiacomo.gabrielli@arm.com{
9113955Sgiacomo.gabrielli@arm.com    alphaAccess->numCPUs = system->getNumCPUs();
9213955Sgiacomo.gabrielli@arm.com    alphaAccess->kernStart = system->getKernelStart();
9313955Sgiacomo.gabrielli@arm.com    alphaAccess->kernEnd = system->getKernelEnd();
9413955Sgiacomo.gabrielli@arm.com    alphaAccess->entryPoint = system->getKernelEntry();
9513955Sgiacomo.gabrielli@arm.com    alphaAccess->mem_size = system->physmem->size();
9613955Sgiacomo.gabrielli@arm.com    alphaAccess->cpuClock = cpu->frequency() / 1000000; // In MHz
9713955Sgiacomo.gabrielli@arm.com    alphaAccess->intrClockFrequency = platform->intrFrequency();
9813955Sgiacomo.gabrielli@arm.com}
9913955Sgiacomo.gabrielli@arm.com
10013955Sgiacomo.gabrielli@arm.comFault
10113955Sgiacomo.gabrielli@arm.comAlphaConsole::read(MemReqPtr &req, uint8_t *data)
10213955Sgiacomo.gabrielli@arm.com{
10313955Sgiacomo.gabrielli@arm.com    memset(data, 0, req->size);
10413955Sgiacomo.gabrielli@arm.com
10513955Sgiacomo.gabrielli@arm.com    Addr daddr = req->paddr - (addr & EV5::PAddrImplMask);
10613955Sgiacomo.gabrielli@arm.com
10713955Sgiacomo.gabrielli@arm.com    switch (req->size)
10813955Sgiacomo.gabrielli@arm.com    {
10913955Sgiacomo.gabrielli@arm.com        case sizeof(uint32_t):
11013955Sgiacomo.gabrielli@arm.com            DPRINTF(AlphaConsole, "read: offset=%#x val=%#x\n", daddr,
11113955Sgiacomo.gabrielli@arm.com                    *(uint32_t*)data);
11213955Sgiacomo.gabrielli@arm.com            switch (daddr)
11313955Sgiacomo.gabrielli@arm.com            {
11413955Sgiacomo.gabrielli@arm.com                case offsetof(AlphaAccess, last_offset):
11513955Sgiacomo.gabrielli@arm.com                    *(uint32_t*)data = alphaAccess->last_offset;
11613955Sgiacomo.gabrielli@arm.com                    break;
117                case offsetof(AlphaAccess, version):
118                    *(uint32_t*)data = alphaAccess->version;
119                    break;
120                case offsetof(AlphaAccess, numCPUs):
121                    *(uint32_t*)data = alphaAccess->numCPUs;
122                    break;
123                case offsetof(AlphaAccess, intrClockFrequency):
124                    *(uint32_t*)data = alphaAccess->intrClockFrequency;
125                    break;
126                default:
127                    // Old console code read in everyting as a 32bit int
128                    *(uint32_t*)data = *(uint32_t*)(consoleData + daddr);
129
130            }
131            break;
132        case sizeof(uint64_t):
133            DPRINTF(AlphaConsole, "read: offset=%#x val=%#x\n", daddr,
134                    *(uint64_t*)data);
135            switch (daddr)
136            {
137                case offsetof(AlphaAccess, inputChar):
138                    *(uint64_t*)data = console->console_in();
139                    break;
140                case offsetof(AlphaAccess, cpuClock):
141                    *(uint64_t*)data = alphaAccess->cpuClock;
142                    break;
143                case offsetof(AlphaAccess, mem_size):
144                    *(uint64_t*)data = alphaAccess->mem_size;
145                    break;
146                case offsetof(AlphaAccess, kernStart):
147                    *(uint64_t*)data = alphaAccess->kernStart;
148                    break;
149                case offsetof(AlphaAccess, kernEnd):
150                    *(uint64_t*)data = alphaAccess->kernEnd;
151                    break;
152                case offsetof(AlphaAccess, entryPoint):
153                    *(uint64_t*)data = alphaAccess->entryPoint;
154                    break;
155                case offsetof(AlphaAccess, diskUnit):
156                    *(uint64_t*)data = alphaAccess->diskUnit;
157                    break;
158                case offsetof(AlphaAccess, diskCount):
159                    *(uint64_t*)data = alphaAccess->diskCount;
160                    break;
161                case offsetof(AlphaAccess, diskPAddr):
162                    *(uint64_t*)data = alphaAccess->diskPAddr;
163                    break;
164                case offsetof(AlphaAccess, diskBlock):
165                    *(uint64_t*)data = alphaAccess->diskBlock;
166                    break;
167                case offsetof(AlphaAccess, diskOperation):
168                    *(uint64_t*)data = alphaAccess->diskOperation;
169                    break;
170                case offsetof(AlphaAccess, outputChar):
171                    *(uint64_t*)data = alphaAccess->outputChar;
172                    break;
173                default:
174                    int cpunum = (daddr - offsetof(AlphaAccess, cpuStack)) /
175                                 sizeof(alphaAccess->cpuStack[0]);
176
177                    if (cpunum >= 0 && cpunum < 64)
178                        *(uint64_t*)data = alphaAccess->cpuStack[cpunum];
179                    else
180                        panic("Unknown 64bit access, %#x\n", daddr);
181            }
182            break;
183        default:
184            return Machine_Check_Fault;
185    }
186
187    return No_Fault;
188}
189
190Fault
191AlphaConsole::write(MemReqPtr &req, const uint8_t *data)
192{
193    uint64_t val;
194
195    switch (req->size) {
196      case sizeof(uint32_t):
197        val = *(uint32_t *)data;
198        break;
199
200      case sizeof(uint64_t):
201        val = *(uint64_t *)data;
202        break;
203      default:
204        return Machine_Check_Fault;
205    }
206
207    Addr daddr = req->paddr - (addr & EV5::PAddrImplMask);
208    ExecContext *other_xc;
209
210    switch (daddr) {
211      case offsetof(AlphaAccess, diskUnit):
212        alphaAccess->diskUnit = val;
213        break;
214
215      case offsetof(AlphaAccess, diskCount):
216        alphaAccess->diskCount = val;
217        break;
218
219      case offsetof(AlphaAccess, diskPAddr):
220        alphaAccess->diskPAddr = val;
221        break;
222
223      case offsetof(AlphaAccess, diskBlock):
224        alphaAccess->diskBlock = val;
225        break;
226
227      case offsetof(AlphaAccess, diskOperation):
228        if (val == 0x13)
229            disk->read(alphaAccess->diskPAddr, alphaAccess->diskBlock,
230                       alphaAccess->diskCount);
231        else
232            panic("Invalid disk operation!");
233
234        break;
235
236      case offsetof(AlphaAccess, outputChar):
237        console->out((char)(val & 0xff));
238        break;
239
240        other_xc->activate(); //Start the cpu
241        break;
242
243      default:
244        int cpunum = (daddr - offsetof(AlphaAccess, cpuStack)) /
245                     sizeof(alphaAccess->cpuStack[0]);
246        warn("%d: Trying to launch CPU number %d!", curTick, cpunum);
247        assert(val > 0 && "Must not access primary cpu");
248        if (cpunum >= 0 && cpunum < 64)
249            alphaAccess->cpuStack[cpunum] = val;
250        else
251            panic("Unknown 64bit access, %#x\n", daddr);
252    }
253
254    return No_Fault;
255}
256
257Tick
258AlphaConsole::cacheAccess(MemReqPtr &req)
259{
260    return curTick + 1000;
261}
262
263void
264AlphaConsole::Access::serialize(ostream &os)
265{
266    SERIALIZE_SCALAR(last_offset);
267    SERIALIZE_SCALAR(version);
268    SERIALIZE_SCALAR(numCPUs);
269    SERIALIZE_SCALAR(mem_size);
270    SERIALIZE_SCALAR(cpuClock);
271    SERIALIZE_SCALAR(intrClockFrequency);
272    SERIALIZE_SCALAR(kernStart);
273    SERIALIZE_SCALAR(kernEnd);
274    SERIALIZE_SCALAR(entryPoint);
275    SERIALIZE_SCALAR(diskUnit);
276    SERIALIZE_SCALAR(diskCount);
277    SERIALIZE_SCALAR(diskPAddr);
278    SERIALIZE_SCALAR(diskBlock);
279    SERIALIZE_SCALAR(diskOperation);
280    SERIALIZE_SCALAR(outputChar);
281    SERIALIZE_SCALAR(inputChar);
282    SERIALIZE_ARRAY(cpuStack,64);
283}
284
285void
286AlphaConsole::Access::unserialize(Checkpoint *cp, const std::string &section)
287{
288    UNSERIALIZE_SCALAR(last_offset);
289    UNSERIALIZE_SCALAR(version);
290    UNSERIALIZE_SCALAR(numCPUs);
291    UNSERIALIZE_SCALAR(mem_size);
292    UNSERIALIZE_SCALAR(cpuClock);
293    UNSERIALIZE_SCALAR(intrClockFrequency);
294    UNSERIALIZE_SCALAR(kernStart);
295    UNSERIALIZE_SCALAR(kernEnd);
296    UNSERIALIZE_SCALAR(entryPoint);
297    UNSERIALIZE_SCALAR(diskUnit);
298    UNSERIALIZE_SCALAR(diskCount);
299    UNSERIALIZE_SCALAR(diskPAddr);
300    UNSERIALIZE_SCALAR(diskBlock);
301    UNSERIALIZE_SCALAR(diskOperation);
302    UNSERIALIZE_SCALAR(outputChar);
303    UNSERIALIZE_SCALAR(inputChar);
304    UNSERIALIZE_ARRAY(cpuStack, 64);
305}
306
307void
308AlphaConsole::serialize(ostream &os)
309{
310    alphaAccess->serialize(os);
311}
312
313void
314AlphaConsole::unserialize(Checkpoint *cp, const std::string &section)
315{
316    alphaAccess->unserialize(cp, section);
317}
318
319BEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
320
321    SimObjectParam<SimConsole *> sim_console;
322    SimObjectParam<SimpleDisk *> disk;
323    SimObjectParam<MemoryController *> mmu;
324    Param<Addr> addr;
325    SimObjectParam<System *> system;
326    SimObjectParam<BaseCPU *> cpu;
327    SimObjectParam<Platform *> platform;
328    SimObjectParam<Bus*> pio_bus;
329    Param<Tick> pio_latency;
330    SimObjectParam<HierParams *> hier;
331
332END_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
333
334BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaConsole)
335
336    INIT_PARAM(sim_console, "The Simulator Console"),
337    INIT_PARAM(disk, "Simple Disk"),
338    INIT_PARAM(mmu, "Memory Controller"),
339    INIT_PARAM(addr, "Device Address"),
340    INIT_PARAM(system, "system object"),
341    INIT_PARAM(cpu, "Processor"),
342    INIT_PARAM(platform, "platform"),
343    INIT_PARAM(pio_bus, "The IO Bus to attach to"),
344    INIT_PARAM_DFLT(pio_latency, "Programmed IO latency", 1000),
345    INIT_PARAM_DFLT(hier, "Hierarchy global variables", &defaultHierParams)
346
347END_INIT_SIM_OBJECT_PARAMS(AlphaConsole)
348
349CREATE_SIM_OBJECT(AlphaConsole)
350{
351    return new AlphaConsole(getInstanceName(), sim_console, disk,
352                            system, cpu, platform, mmu, addr, hier, pio_bus);
353}
354
355REGISTER_SIM_OBJECT("AlphaConsole", AlphaConsole)
356