backdoor.cc revision 217
112838Sgabeblack@google.com/*
212838Sgabeblack@google.com * Copyright (c) 2003 The Regents of The University of Michigan
312838Sgabeblack@google.com * All rights reserved.
412838Sgabeblack@google.com *
512838Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
612838Sgabeblack@google.com * modification, are permitted provided that the following conditions are
712838Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
812838Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
912838Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1012838Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1112838Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1212838Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1312838Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1412838Sgabeblack@google.com * this software without specific prior written permission.
1512838Sgabeblack@google.com *
1612838Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712838Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812838Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912838Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012838Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112838Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212838Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312838Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412838Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512838Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612838Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712838Sgabeblack@google.com */
2812838Sgabeblack@google.com
2912838Sgabeblack@google.com/* @file
3012838Sgabeblack@google.com * System Console Definition
3112838Sgabeblack@google.com */
3212838Sgabeblack@google.com
3312838Sgabeblack@google.com#include <cstddef>
3412838Sgabeblack@google.com#include <cstdio>
3512838Sgabeblack@google.com#include <string>
3613128Sgabeblack@google.com
3713128Sgabeblack@google.com#include "base/inifile.hh"
3813087Sgabeblack@google.com#include "base/str.hh"	// for to_number()
3912852Sgabeblack@google.com#include "base/trace.hh"
4012852Sgabeblack@google.com#include "cpu/base_cpu.hh"
4112852Sgabeblack@google.com#include "cpu/exec_context.hh"
4212852Sgabeblack@google.com#include "dev/alpha_console.hh"
4312852Sgabeblack@google.com#include "dev/console.hh"
4412952Sgabeblack@google.com#include "dev/simple_disk.hh"
4512952Sgabeblack@google.com#include "dev/tlaser_clock.hh"
4612952Sgabeblack@google.com#include "mem/functional_mem/memory_control.hh"
4712952Sgabeblack@google.com#include "sim/builder.hh"
4812952Sgabeblack@google.com#include "sim/system.hh"
4912952Sgabeblack@google.com
5012952Sgabeblack@google.comusing namespace std;
5112952Sgabeblack@google.com
5212952Sgabeblack@google.comAlphaConsole::AlphaConsole(const string &name, SimConsole *cons,
5312952Sgabeblack@google.com                           SimpleDisk *d, int size, System *system,
5412952Sgabeblack@google.com                           BaseCPU *cpu, TlaserClock *clock, int num_cpus,
5512952Sgabeblack@google.com                           Addr addr, Addr mask, MemoryController *mmu)
5612952Sgabeblack@google.com    : MmapDevice(name, addr, mask, mmu), disk(d), console(cons)
5712952Sgabeblack@google.com{
5812952Sgabeblack@google.com    consoleData = new uint8_t[size];
5912952Sgabeblack@google.com    memset(consoleData, 0, size);
6012952Sgabeblack@google.com
6112952Sgabeblack@google.com    alphaAccess->last_offset = size - 1;
6212952Sgabeblack@google.com    alphaAccess->kernStart = system->getKernelStart();
6312952Sgabeblack@google.com    alphaAccess->kernEnd = system->getKernelEnd();
6412952Sgabeblack@google.com    alphaAccess->entryPoint = system->getKernelEntry();
6512952Sgabeblack@google.com
6612952Sgabeblack@google.com    alphaAccess->version = ALPHA_ACCESS_VERSION;
6712952Sgabeblack@google.com    alphaAccess->numCPUs = num_cpus;
6812952Sgabeblack@google.com    alphaAccess->mem_size = system->physmem->getSize();
6912952Sgabeblack@google.com    alphaAccess->cpuClock = cpu->getFreq() / 1000000;
7012952Sgabeblack@google.com    alphaAccess->intrClockFrequency = clock->frequency();
7112952Sgabeblack@google.com
7212952Sgabeblack@google.com    alphaAccess->diskUnit = 1;
7312952Sgabeblack@google.com}
7412952Sgabeblack@google.com
7512952Sgabeblack@google.comFault
7612952Sgabeblack@google.comAlphaConsole::read(MemReqPtr req, uint8_t *data)
7712952Sgabeblack@google.com{
7812852Sgabeblack@google.com    memset(data, 0, req->size);
7912852Sgabeblack@google.com
8012838Sgabeblack@google.com    if (req->size == sizeof(uint32_t)) {
8112838Sgabeblack@google.com        Addr daddr = req->paddr & addr_mask;
8212838Sgabeblack@google.com        *(uint32_t *)data = *(uint32_t *)(consoleData + daddr);
8312838Sgabeblack@google.com
8412838Sgabeblack@google.com#if 0
8512838Sgabeblack@google.com        DPRINTF(AlphaConsole, "read: offset=%#x val=%#x\n",
8612838Sgabeblack@google.com                daddr, *(uint32_t *)data);
8712838Sgabeblack@google.com#endif
8812838Sgabeblack@google.com    }
8912838Sgabeblack@google.com
9012838Sgabeblack@google.com    return No_Fault;
9112838Sgabeblack@google.com}
9212838Sgabeblack@google.com
9312838Sgabeblack@google.comFault
9412838Sgabeblack@google.comAlphaConsole::write(MemReqPtr req, const uint8_t *data)
9512838Sgabeblack@google.com{
9612838Sgabeblack@google.com    uint64_t val;
9712838Sgabeblack@google.com
9812838Sgabeblack@google.com    switch (req->size) {
9912838Sgabeblack@google.com      case sizeof(uint32_t):
10012838Sgabeblack@google.com        val = *(uint32_t *)data;
10112838Sgabeblack@google.com        break;
10212838Sgabeblack@google.com      case sizeof(uint64_t):
10312838Sgabeblack@google.com        val = *(uint64_t *)data;
10412838Sgabeblack@google.com        break;
10512898Sgabeblack@google.com      default:
10612898Sgabeblack@google.com        return Machine_Check_Fault;
10712898Sgabeblack@google.com    }
10812898Sgabeblack@google.com
10912898Sgabeblack@google.com    Addr paddr = req->paddr & addr_mask;
11012898Sgabeblack@google.com
11112898Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, diskUnit)) {
11212838Sgabeblack@google.com        alphaAccess->diskUnit = val;
11312994Sgabeblack@google.com        return No_Fault;
11412838Sgabeblack@google.com    }
11512838Sgabeblack@google.com
11612838Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, diskCount)) {
11712939Sgabeblack@google.com        alphaAccess->diskCount = val;
11812939Sgabeblack@google.com        return No_Fault;
11913087Sgabeblack@google.com    }
12012939Sgabeblack@google.com
12112939Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, diskPAddr)) {
12213087Sgabeblack@google.com        alphaAccess->diskPAddr = val;
12313087Sgabeblack@google.com        return No_Fault;
12413087Sgabeblack@google.com    }
12513087Sgabeblack@google.com
12612939Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, diskBlock)) {
12712939Sgabeblack@google.com        alphaAccess->diskBlock = val;
12812939Sgabeblack@google.com        return No_Fault;
12912939Sgabeblack@google.com    }
13013087Sgabeblack@google.com
13113087Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, diskOperation)) {
13213087Sgabeblack@google.com        if (val == 0x13)
13312939Sgabeblack@google.com            disk->read(alphaAccess->diskPAddr, alphaAccess->diskBlock,
13412939Sgabeblack@google.com                       alphaAccess->diskCount);
13512939Sgabeblack@google.com        else
13612939Sgabeblack@google.com            panic("Invalid disk operation!");
13712939Sgabeblack@google.com
13812939Sgabeblack@google.com        return No_Fault;
13912939Sgabeblack@google.com    }
14012939Sgabeblack@google.com
14112939Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, outputChar)) {
14212939Sgabeblack@google.com        console->out((char)(val & 0xff), false);
14312939Sgabeblack@google.com        return No_Fault;
14412939Sgabeblack@google.com    }
14512939Sgabeblack@google.com
14612939Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, bootStrapImpure)) {
14712939Sgabeblack@google.com        alphaAccess->bootStrapImpure = val;
14812939Sgabeblack@google.com        return No_Fault;
14912939Sgabeblack@google.com    }
15012838Sgabeblack@google.com
15112838Sgabeblack@google.com    if (paddr == offsetof(AlphaAccess, bootStrapCPU)) {
15212852Sgabeblack@google.com        warn("%d: Trying to launch another CPU!", curTick);
15312852Sgabeblack@google.com        int cpu = val;
15412852Sgabeblack@google.com        assert(cpu > 0 && "Must not access primary cpu");
15512838Sgabeblack@google.com
15612838Sgabeblack@google.com        ExecContext *other_xc = req->xc->system->execContexts[cpu];
15712838Sgabeblack@google.com        other_xc->regs.intRegFile[16] = cpu;
15812838Sgabeblack@google.com        other_xc->regs.ipr[TheISA::IPR_PALtemp16] = cpu;
15912838Sgabeblack@google.com        other_xc->regs.intRegFile[0] = cpu;
16012838Sgabeblack@google.com        other_xc->regs.intRegFile[30] = alphaAccess->bootStrapImpure;
16112852Sgabeblack@google.com        other_xc->setStatus(ExecContext::Active); //Start the cpu
16212852Sgabeblack@google.com        return No_Fault;
16312852Sgabeblack@google.com    }
16412852Sgabeblack@google.com
16512852Sgabeblack@google.com    return No_Fault;
16612852Sgabeblack@google.com}
16712852Sgabeblack@google.com
16812852Sgabeblack@google.comvoid
16912852Sgabeblack@google.comAlphaAccess::serialize(ostream &os)
17012852Sgabeblack@google.com{
17112852Sgabeblack@google.com    SERIALIZE_MEMBER(last_offset);
17212838Sgabeblack@google.com    SERIALIZE_MEMBER(version);
17312838Sgabeblack@google.com    SERIALIZE_MEMBER(numCPUs);
17412838Sgabeblack@google.com    SERIALIZE_MEMBER(mem_size);
17512838Sgabeblack@google.com    SERIALIZE_MEMBER(cpuClock);
17612838Sgabeblack@google.com    SERIALIZE_MEMBER(intrClockFrequency);
17712838Sgabeblack@google.com    SERIALIZE_MEMBER(kernStart);
17812952Sgabeblack@google.com    SERIALIZE_MEMBER(kernEnd);
17912838Sgabeblack@google.com    SERIALIZE_MEMBER(entryPoint);
18012838Sgabeblack@google.com    SERIALIZE_MEMBER(diskUnit);
18112838Sgabeblack@google.com    SERIALIZE_MEMBER(diskCount);
18212838Sgabeblack@google.com    SERIALIZE_MEMBER(diskPAddr);
18312838Sgabeblack@google.com    SERIALIZE_MEMBER(diskBlock);
18412838Sgabeblack@google.com    SERIALIZE_MEMBER(diskOperation);
18512838Sgabeblack@google.com    SERIALIZE_MEMBER(outputChar);
18612838Sgabeblack@google.com    SERIALIZE_MEMBER(bootStrapImpure);
18712838Sgabeblack@google.com    SERIALIZE_MEMBER(bootStrapCPU);
18812838Sgabeblack@google.com}
18912838Sgabeblack@google.com
19012838Sgabeblack@google.comvoid
19112838Sgabeblack@google.comAlphaAccess::unserialize(IniFile &db, const std::string &section)
19212838Sgabeblack@google.com{
19312838Sgabeblack@google.com    UNSERIALIZE_MEMBER(last_offset);
19412838Sgabeblack@google.com    UNSERIALIZE_MEMBER(version);
19512838Sgabeblack@google.com    UNSERIALIZE_MEMBER(numCPUs);
19612838Sgabeblack@google.com    UNSERIALIZE_MEMBER(mem_size);
19712838Sgabeblack@google.com    UNSERIALIZE_MEMBER(cpuClock);
19812838Sgabeblack@google.com    UNSERIALIZE_MEMBER(intrClockFrequency);
19912838Sgabeblack@google.com    UNSERIALIZE_MEMBER(kernStart);
20012838Sgabeblack@google.com    UNSERIALIZE_MEMBER(kernEnd);
20112838Sgabeblack@google.com    UNSERIALIZE_MEMBER(entryPoint);
20212838Sgabeblack@google.com    UNSERIALIZE_MEMBER(diskUnit);
20312838Sgabeblack@google.com    UNSERIALIZE_MEMBER(diskCount);
20412838Sgabeblack@google.com    UNSERIALIZE_MEMBER(diskPAddr);
20512838Sgabeblack@google.com    UNSERIALIZE_MEMBER(diskBlock);
20612838Sgabeblack@google.com    UNSERIALIZE_MEMBER(diskOperation);
20712838Sgabeblack@google.com    UNSERIALIZE_MEMBER(outputChar);
20812838Sgabeblack@google.com    UNSERIALIZE_MEMBER(bootStrapImpure);
20912838Sgabeblack@google.com    UNSERIALIZE_MEMBER(bootStrapCPU);
21012838Sgabeblack@google.com}
21112952Sgabeblack@google.com
21212952Sgabeblack@google.comvoid
21312952Sgabeblack@google.comAlphaConsole::serialize(ostream &os)
21412952Sgabeblack@google.com{
21512838Sgabeblack@google.com    alphaAccess->serialize(os);
21613128Sgabeblack@google.com}
21713128Sgabeblack@google.com
21813128Sgabeblack@google.comvoid
21913128Sgabeblack@google.comAlphaConsole::unserialize(IniFile &db, const std::string &section)
22013128Sgabeblack@google.com{
22112952Sgabeblack@google.com    alphaAccess->unserialize(db, section);
22212952Sgabeblack@google.com}
22312952Sgabeblack@google.com
22412838Sgabeblack@google.comBEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
22512838Sgabeblack@google.com
22612838Sgabeblack@google.com    SimObjectParam<SimConsole *> sim_console;
22712838Sgabeblack@google.com    SimObjectParam<SimpleDisk *> disk;
22812838Sgabeblack@google.com    Param<int> size;
22912838Sgabeblack@google.com    Param<int> num_cpus;
23012899Sgabeblack@google.com    SimObjectParam<MemoryController *> mmu;
23112899Sgabeblack@google.com    Param<Addr> addr;
23212899Sgabeblack@google.com    Param<Addr> mask;
23312899Sgabeblack@google.com    SimObjectParam<System *> system;
23412899Sgabeblack@google.com    SimObjectParam<BaseCPU *> cpu;
23512899Sgabeblack@google.com    SimObjectParam<TlaserClock *> clock;
23612838Sgabeblack@google.com
23712838Sgabeblack@google.comEND_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
23812838Sgabeblack@google.com
239BEGIN_INIT_SIM_OBJECT_PARAMS(AlphaConsole)
240
241    INIT_PARAM(sim_console, "The Simulator Console"),
242    INIT_PARAM(disk, "Simple Disk"),
243    INIT_PARAM_DFLT(size, "AlphaConsole size", sizeof(AlphaAccess)),
244    INIT_PARAM_DFLT(num_cpus, "Number of CPU's", 1),
245    INIT_PARAM(mmu, "Memory Controller"),
246    INIT_PARAM(addr, "Device Address"),
247    INIT_PARAM(mask, "Address Mask"),
248    INIT_PARAM(system, "system object"),
249    INIT_PARAM(cpu, "Processor"),
250    INIT_PARAM(clock, "Turbolaser Clock")
251
252END_INIT_SIM_OBJECT_PARAMS(AlphaConsole)
253
254CREATE_SIM_OBJECT(AlphaConsole)
255{
256    return  new AlphaConsole(getInstanceName(), sim_console,
257                             disk, size, system,
258                             cpu, clock, num_cpus,
259                             addr, mask, mmu);
260}
261
262REGISTER_SIM_OBJECT("AlphaConsole", AlphaConsole)
263