backdoor.cc revision 430
1955SN/A/*
2955SN/A * Copyright (c) 2003 The Regents of The University of Michigan
37816Ssteve.reinhardt@amd.com * All rights reserved.
45871Snate@binkert.org *
51762SN/A * Redistribution and use in source and binary forms, with or without
6955SN/A * modification, are permitted provided that the following conditions are
7955SN/A * met: redistributions of source code must retain the above copyright
8955SN/A * notice, this list of conditions and the following disclaimer;
9955SN/A * redistributions in binary form must reproduce the above copyright
10955SN/A * notice, this list of conditions and the following disclaimer in the
11955SN/A * documentation and/or other materials provided with the distribution;
12955SN/A * neither the name of the copyright holders nor the names of its
13955SN/A * contributors may be used to endorse or promote products derived from
14955SN/A * this software without specific prior written permission.
15955SN/A *
16955SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17955SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18955SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19955SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20955SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21955SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22955SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23955SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24955SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25955SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26955SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27955SN/A */
28955SN/A
29955SN/A/* @file
302665Ssaidi@eecs.umich.edu * System Console Definition
312665Ssaidi@eecs.umich.edu */
325863Snate@binkert.org
33955SN/A#include <cstddef>
34955SN/A#include <cstdio>
35955SN/A#include <string>
36955SN/A
37955SN/A#include "base/inifile.hh"
388878Ssteve.reinhardt@amd.com#include "base/str.hh"	// for to_number()
392632Sstever@eecs.umich.edu#include "base/trace.hh"
408878Ssteve.reinhardt@amd.com#include "cpu/base_cpu.hh"
412632Sstever@eecs.umich.edu#include "cpu/exec_context.hh"
42955SN/A#include "dev/alpha_console.hh"
438878Ssteve.reinhardt@amd.com#include "dev/console.hh"
442632Sstever@eecs.umich.edu#include "dev/simple_disk.hh"
452761Sstever@eecs.umich.edu#include "dev/tlaser_clock.hh"
462632Sstever@eecs.umich.edu#include "mem/functional_mem/memory_control.hh"
472632Sstever@eecs.umich.edu#include "sim/builder.hh"
482632Sstever@eecs.umich.edu#include "sim/system.hh"
492761Sstever@eecs.umich.edu
502761Sstever@eecs.umich.eduusing namespace std;
512761Sstever@eecs.umich.edu
528878Ssteve.reinhardt@amd.comAlphaConsole::AlphaConsole(const string &name, SimConsole *cons,
538878Ssteve.reinhardt@amd.com                           SimpleDisk *d, int size, System *system,
542761Sstever@eecs.umich.edu                           BaseCPU *cpu, TlaserClock *clock, int num_cpus,
552761Sstever@eecs.umich.edu                           Addr addr, Addr mask, MemoryController *mmu)
562761Sstever@eecs.umich.edu    : MmapDevice(name, addr, mask, mmu), disk(d), console(cons)
572761Sstever@eecs.umich.edu{
582761Sstever@eecs.umich.edu    consoleData = new uint8_t[size];
598878Ssteve.reinhardt@amd.com    memset(consoleData, 0, size);
608878Ssteve.reinhardt@amd.com
612632Sstever@eecs.umich.edu    alphaAccess->last_offset = size - 1;
622632Sstever@eecs.umich.edu    alphaAccess->kernStart = system->getKernelStart();
638878Ssteve.reinhardt@amd.com    alphaAccess->kernEnd = system->getKernelEnd();
648878Ssteve.reinhardt@amd.com    alphaAccess->entryPoint = system->getKernelEntry();
652632Sstever@eecs.umich.edu
66955SN/A    alphaAccess->version = ALPHA_ACCESS_VERSION;
67955SN/A    alphaAccess->numCPUs = num_cpus;
68955SN/A    alphaAccess->mem_size = system->physmem->getSize();
695863Snate@binkert.org    alphaAccess->cpuClock = cpu->getFreq() / 1000000;
705863Snate@binkert.org    alphaAccess->intrClockFrequency = clock->frequency();
715863Snate@binkert.org
725863Snate@binkert.org    alphaAccess->diskUnit = 1;
735863Snate@binkert.org}
745863Snate@binkert.org
755863Snate@binkert.orgFault
765863Snate@binkert.orgAlphaConsole::read(MemReqPtr req, uint8_t *data)
775863Snate@binkert.org{
785863Snate@binkert.org    memset(data, 0, req->size);
795863Snate@binkert.org    uint64_t val;
808878Ssteve.reinhardt@amd.com
815863Snate@binkert.org    Addr daddr = req->paddr & addr_mask;
825863Snate@binkert.org    switch (daddr) {
835863Snate@binkert.org      case offsetof(AlphaAccess, inputChar):
845863Snate@binkert.org        val = console->in();
855863Snate@binkert.org        break;
865863Snate@binkert.org
875863Snate@binkert.org      default:
885863Snate@binkert.org        val = *(uint64_t *)(consoleData + daddr);
895863Snate@binkert.org        break;
905863Snate@binkert.org    }
915863Snate@binkert.org
925863Snate@binkert.org    DPRINTF(AlphaConsole, "read: offset=%#x val=%#x\n", daddr, val);
935863Snate@binkert.org
945863Snate@binkert.org    switch (req->size) {
955863Snate@binkert.org      case sizeof(uint32_t):
968878Ssteve.reinhardt@amd.com        *(uint32_t *)data = (uint32_t)val;
975863Snate@binkert.org        break;
985863Snate@binkert.org
995863Snate@binkert.org      case sizeof(uint64_t):
1006654Snate@binkert.org        *(uint64_t *)data = val;
101955SN/A        break;
1025396Ssaidi@eecs.umich.edu
1035863Snate@binkert.org      default:
1045863Snate@binkert.org        return Machine_Check_Fault;
1054202Sbinkertn@umich.edu    }
1065863Snate@binkert.org
1075863Snate@binkert.org
1085863Snate@binkert.org    return No_Fault;
1095863Snate@binkert.org}
110955SN/A
1116654Snate@binkert.orgFault
1125273Sstever@gmail.comAlphaConsole::write(MemReqPtr req, const uint8_t *data)
1135871Snate@binkert.org{
1145273Sstever@gmail.com    uint64_t val;
1156655Snate@binkert.org
1168878Ssteve.reinhardt@amd.com    switch (req->size) {
1176655Snate@binkert.org      case sizeof(uint32_t):
1186655Snate@binkert.org        val = *(uint32_t *)data;
1199219Spower.jg@gmail.com        break;
1206655Snate@binkert.org
1215871Snate@binkert.org      case sizeof(uint64_t):
1226654Snate@binkert.org        val = *(uint64_t *)data;
1238947Sandreas.hansson@arm.com        break;
1245396Ssaidi@eecs.umich.edu      default:
1258120Sgblack@eecs.umich.edu        return Machine_Check_Fault;
1268120Sgblack@eecs.umich.edu    }
1278120Sgblack@eecs.umich.edu
1288120Sgblack@eecs.umich.edu    Addr daddr = req->paddr & addr_mask;
1298120Sgblack@eecs.umich.edu    ExecContext *other_xc;
1308120Sgblack@eecs.umich.edu
1318120Sgblack@eecs.umich.edu    switch (daddr) {
1328120Sgblack@eecs.umich.edu      case offsetof(AlphaAccess, diskUnit):
1338879Ssteve.reinhardt@amd.com        alphaAccess->diskUnit = val;
1348879Ssteve.reinhardt@amd.com        break;
1358879Ssteve.reinhardt@amd.com
1368879Ssteve.reinhardt@amd.com      case offsetof(AlphaAccess, diskCount):
1378879Ssteve.reinhardt@amd.com        alphaAccess->diskCount = val;
1388879Ssteve.reinhardt@amd.com        break;
1398879Ssteve.reinhardt@amd.com
1408879Ssteve.reinhardt@amd.com      case offsetof(AlphaAccess, diskPAddr):
1418879Ssteve.reinhardt@amd.com        alphaAccess->diskPAddr = val;
1428879Ssteve.reinhardt@amd.com        break;
1438879Ssteve.reinhardt@amd.com
1448879Ssteve.reinhardt@amd.com      case offsetof(AlphaAccess, diskBlock):
1458879Ssteve.reinhardt@amd.com        alphaAccess->diskBlock = val;
1468120Sgblack@eecs.umich.edu        break;
1478120Sgblack@eecs.umich.edu
1488120Sgblack@eecs.umich.edu      case offsetof(AlphaAccess, diskOperation):
1498120Sgblack@eecs.umich.edu        if (val == 0x13)
1508120Sgblack@eecs.umich.edu            disk->read(alphaAccess->diskPAddr, alphaAccess->diskBlock,
1518120Sgblack@eecs.umich.edu                       alphaAccess->diskCount);
1528120Sgblack@eecs.umich.edu        else
1538120Sgblack@eecs.umich.edu            panic("Invalid disk operation!");
1548120Sgblack@eecs.umich.edu
1558120Sgblack@eecs.umich.edu        break;
1568120Sgblack@eecs.umich.edu
1578120Sgblack@eecs.umich.edu      case offsetof(AlphaAccess, outputChar):
1588120Sgblack@eecs.umich.edu        console->out((char)(val & 0xff), false);
1598120Sgblack@eecs.umich.edu        break;
1608879Ssteve.reinhardt@amd.com
1618879Ssteve.reinhardt@amd.com      case offsetof(AlphaAccess, bootStrapImpure):
1628879Ssteve.reinhardt@amd.com        alphaAccess->bootStrapImpure = val;
1638879Ssteve.reinhardt@amd.com        break;
1648879Ssteve.reinhardt@amd.com
1658879Ssteve.reinhardt@amd.com      case offsetof(AlphaAccess, bootStrapCPU):
1668879Ssteve.reinhardt@amd.com        warn("%d: Trying to launch another CPU!", curTick);
1678879Ssteve.reinhardt@amd.com        assert(val > 0 && "Must not access primary cpu");
1689227Sandreas.hansson@arm.com
1699227Sandreas.hansson@arm.com        other_xc = req->xc->system->execContexts[val];
1708879Ssteve.reinhardt@amd.com        other_xc->regs.intRegFile[16] = val;
1718879Ssteve.reinhardt@amd.com        other_xc->regs.ipr[TheISA::IPR_PALtemp16] = val;
1728879Ssteve.reinhardt@amd.com        other_xc->regs.intRegFile[0] = val;
1738879Ssteve.reinhardt@amd.com        other_xc->regs.intRegFile[30] = alphaAccess->bootStrapImpure;
1748120Sgblack@eecs.umich.edu        other_xc->activate(); //Start the cpu
1758947Sandreas.hansson@arm.com        break;
1767816Ssteve.reinhardt@amd.com
1775871Snate@binkert.org      default:
1785871Snate@binkert.org        return Machine_Check_Fault;
1796121Snate@binkert.org    }
1805871Snate@binkert.org
1815871Snate@binkert.org    return No_Fault;
1829119Sandreas.hansson@arm.com}
1839396Sandreas.hansson@arm.com
1849396Sandreas.hansson@arm.comvoid
185955SN/AAlphaAccess::serialize(ostream &os)
1865871Snate@binkert.org{
1875871Snate@binkert.org    SERIALIZE_SCALAR(last_offset);
1885871Snate@binkert.org    SERIALIZE_SCALAR(version);
1895871Snate@binkert.org    SERIALIZE_SCALAR(numCPUs);
190955SN/A    SERIALIZE_SCALAR(mem_size);
1916121Snate@binkert.org    SERIALIZE_SCALAR(cpuClock);
1928881Smarc.orr@gmail.com    SERIALIZE_SCALAR(intrClockFrequency);
1936121Snate@binkert.org    SERIALIZE_SCALAR(kernStart);
1946121Snate@binkert.org    SERIALIZE_SCALAR(kernEnd);
1951533SN/A    SERIALIZE_SCALAR(entryPoint);
1969239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(diskUnit);
1979239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(diskCount);
1989239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(diskPAddr);
1999239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(diskBlock);
2009239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(diskOperation);
2019239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(outputChar);
2029239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(inputChar);
2039239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(bootStrapImpure);
2049239Sandreas.hansson@arm.com    SERIALIZE_SCALAR(bootStrapCPU);
2059239Sandreas.hansson@arm.com}
2069239Sandreas.hansson@arm.com
2079239Sandreas.hansson@arm.comvoid
2086655Snate@binkert.orgAlphaAccess::unserialize(Checkpoint *cp, const std::string &section)
2096655Snate@binkert.org{
2106655Snate@binkert.org    UNSERIALIZE_SCALAR(last_offset);
2116655Snate@binkert.org    UNSERIALIZE_SCALAR(version);
2125871Snate@binkert.org    UNSERIALIZE_SCALAR(numCPUs);
2135871Snate@binkert.org    UNSERIALIZE_SCALAR(mem_size);
2145863Snate@binkert.org    UNSERIALIZE_SCALAR(cpuClock);
2155871Snate@binkert.org    UNSERIALIZE_SCALAR(intrClockFrequency);
2168878Ssteve.reinhardt@amd.com    UNSERIALIZE_SCALAR(kernStart);
2175871Snate@binkert.org    UNSERIALIZE_SCALAR(kernEnd);
2185871Snate@binkert.org    UNSERIALIZE_SCALAR(entryPoint);
2195871Snate@binkert.org    UNSERIALIZE_SCALAR(diskUnit);
2205863Snate@binkert.org    UNSERIALIZE_SCALAR(diskCount);
2216121Snate@binkert.org    UNSERIALIZE_SCALAR(diskPAddr);
2225863Snate@binkert.org    UNSERIALIZE_SCALAR(diskBlock);
2235871Snate@binkert.org    UNSERIALIZE_SCALAR(diskOperation);
2248336Ssteve.reinhardt@amd.com    UNSERIALIZE_SCALAR(outputChar);
2258336Ssteve.reinhardt@amd.com    UNSERIALIZE_SCALAR(inputChar);
2268336Ssteve.reinhardt@amd.com    UNSERIALIZE_SCALAR(bootStrapImpure);
2278336Ssteve.reinhardt@amd.com    UNSERIALIZE_SCALAR(bootStrapCPU);
2284678Snate@binkert.org}
2298336Ssteve.reinhardt@amd.com
2308336Ssteve.reinhardt@amd.comvoid
2318336Ssteve.reinhardt@amd.comAlphaConsole::serialize(ostream &os)
2324678Snate@binkert.org{
2334678Snate@binkert.org    alphaAccess->serialize(os);
2344678Snate@binkert.org}
2354678Snate@binkert.org
2367827Snate@binkert.orgvoid
2377827Snate@binkert.orgAlphaConsole::unserialize(Checkpoint *cp, const std::string &section)
2388336Ssteve.reinhardt@amd.com{
2394678Snate@binkert.org    alphaAccess->unserialize(cp, section);
2408336Ssteve.reinhardt@amd.com}
2418336Ssteve.reinhardt@amd.com
2428336Ssteve.reinhardt@amd.comBEGIN_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
2438336Ssteve.reinhardt@amd.com
2448336Ssteve.reinhardt@amd.com    SimObjectParam<SimConsole *> sim_console;
2458336Ssteve.reinhardt@amd.com    SimObjectParam<SimpleDisk *> disk;
2465871Snate@binkert.org    Param<int> size;
2475871Snate@binkert.org    Param<int> num_cpus;
2488336Ssteve.reinhardt@amd.com    SimObjectParam<MemoryController *> mmu;
2498336Ssteve.reinhardt@amd.com    Param<Addr> addr;
2508336Ssteve.reinhardt@amd.com    Param<Addr> mask;
2518336Ssteve.reinhardt@amd.com    SimObjectParam<System *> system;
2528336Ssteve.reinhardt@amd.com    SimObjectParam<BaseCPU *> cpu;
2535871Snate@binkert.org    SimObjectParam<TlaserClock *> clock;
2548336Ssteve.reinhardt@amd.com
2558336Ssteve.reinhardt@amd.comEND_DECLARE_SIM_OBJECT_PARAMS(AlphaConsole)
2568336Ssteve.reinhardt@amd.com
2578336Ssteve.reinhardt@amd.comBEGIN_INIT_SIM_OBJECT_PARAMS(AlphaConsole)
2588336Ssteve.reinhardt@amd.com
2594678Snate@binkert.org    INIT_PARAM(sim_console, "The Simulator Console"),
2605871Snate@binkert.org    INIT_PARAM(disk, "Simple Disk"),
2614678Snate@binkert.org    INIT_PARAM_DFLT(size, "AlphaConsole size", sizeof(AlphaAccess)),
2628336Ssteve.reinhardt@amd.com    INIT_PARAM_DFLT(num_cpus, "Number of CPU's", 1),
2638336Ssteve.reinhardt@amd.com    INIT_PARAM(mmu, "Memory Controller"),
2648336Ssteve.reinhardt@amd.com    INIT_PARAM(addr, "Device Address"),
2658336Ssteve.reinhardt@amd.com    INIT_PARAM(mask, "Address Mask"),
2668336Ssteve.reinhardt@amd.com    INIT_PARAM(system, "system object"),
2678336Ssteve.reinhardt@amd.com    INIT_PARAM(cpu, "Processor"),
2688336Ssteve.reinhardt@amd.com    INIT_PARAM(clock, "Turbolaser Clock")
2698336Ssteve.reinhardt@amd.com
2708336Ssteve.reinhardt@amd.comEND_INIT_SIM_OBJECT_PARAMS(AlphaConsole)
2718336Ssteve.reinhardt@amd.com
2728336Ssteve.reinhardt@amd.comCREATE_SIM_OBJECT(AlphaConsole)
2738336Ssteve.reinhardt@amd.com{
2748336Ssteve.reinhardt@amd.com    return  new AlphaConsole(getInstanceName(), sim_console,
2758336Ssteve.reinhardt@amd.com                             disk, size, system,
2768336Ssteve.reinhardt@amd.com                             cpu, clock, num_cpus,
2778336Ssteve.reinhardt@amd.com                             addr, mask, mmu);
2788336Ssteve.reinhardt@amd.com}
2795871Snate@binkert.org
2806121Snate@binkert.orgREGISTER_SIM_OBJECT("AlphaConsole", AlphaConsole)
281955SN/A