se_translating_port_proxy.cc revision 2404
112027Sjungma@eit.uni-kl.de/*
212027Sjungma@eit.uni-kl.de * Copyright (c) 2001-2005 The Regents of The University of Michigan
312027Sjungma@eit.uni-kl.de * All rights reserved.
412027Sjungma@eit.uni-kl.de *
512027Sjungma@eit.uni-kl.de * Redistribution and use in source and binary forms, with or without
612027Sjungma@eit.uni-kl.de * modification, are permitted provided that the following conditions are
712027Sjungma@eit.uni-kl.de * met: redistributions of source code must retain the above copyright
812027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer;
912027Sjungma@eit.uni-kl.de * redistributions in binary form must reproduce the above copyright
1012027Sjungma@eit.uni-kl.de * notice, this list of conditions and the following disclaimer in the
1112027Sjungma@eit.uni-kl.de * documentation and/or other materials provided with the distribution;
1212027Sjungma@eit.uni-kl.de * neither the name of the copyright holders nor the names of its
1312027Sjungma@eit.uni-kl.de * contributors may be used to endorse or promote products derived from
1412027Sjungma@eit.uni-kl.de * this software without specific prior written permission.
1512027Sjungma@eit.uni-kl.de *
1612027Sjungma@eit.uni-kl.de * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712027Sjungma@eit.uni-kl.de * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812027Sjungma@eit.uni-kl.de * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912027Sjungma@eit.uni-kl.de * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012027Sjungma@eit.uni-kl.de * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112027Sjungma@eit.uni-kl.de * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212027Sjungma@eit.uni-kl.de * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312027Sjungma@eit.uni-kl.de * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412027Sjungma@eit.uni-kl.de * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512027Sjungma@eit.uni-kl.de * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612027Sjungma@eit.uni-kl.de * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712027Sjungma@eit.uni-kl.de */
2812027Sjungma@eit.uni-kl.de
2912027Sjungma@eit.uni-kl.de#include <string>
3012027Sjungma@eit.uni-kl.de#include "base/chunk_generator.hh"
3112027Sjungma@eit.uni-kl.de#include "mem/port.hh"
3212027Sjungma@eit.uni-kl.de#include "mem/translating_port.hh"
3312027Sjungma@eit.uni-kl.de#include "mem/page_table.hh"
3412027Sjungma@eit.uni-kl.de
3512027Sjungma@eit.uni-kl.deTranslatingPort::TranslatingPort(Port *_port, PageTable *p_table)
3612027Sjungma@eit.uni-kl.de    : port(_port), pTable(p_table)
3712027Sjungma@eit.uni-kl.de{ }
3812027Sjungma@eit.uni-kl.de
3912027Sjungma@eit.uni-kl.deTranslatingPort::~TranslatingPort()
4012027Sjungma@eit.uni-kl.de{ }
4112027Sjungma@eit.uni-kl.de
4212027Sjungma@eit.uni-kl.deFault
4312027Sjungma@eit.uni-kl.deTranslatingPort::readBlobFunctional(Addr addr, uint8_t *p, int size)
4412027Sjungma@eit.uni-kl.de{
4512027Sjungma@eit.uni-kl.de    Addr paddr;
4612027Sjungma@eit.uni-kl.de    int prevSize = 0;
4712027Sjungma@eit.uni-kl.de
4812027Sjungma@eit.uni-kl.de    for (ChunkGenerator gen(addr, size, VMPageSize); !gen.done(); gen.next()) {
4912027Sjungma@eit.uni-kl.de
5012027Sjungma@eit.uni-kl.de       if (!pTable->translate(gen.addr(),paddr))
5112027Sjungma@eit.uni-kl.de           return Machine_Check_Fault;
5212027Sjungma@eit.uni-kl.de
5312027Sjungma@eit.uni-kl.de       port->readBlobFunctional(paddr, p + prevSize, gen.size());
5412027Sjungma@eit.uni-kl.de       prevSize += gen.size();
5512027Sjungma@eit.uni-kl.de    }
5612027Sjungma@eit.uni-kl.de
5712027Sjungma@eit.uni-kl.de    return No_Fault;
5812027Sjungma@eit.uni-kl.de}
5912027Sjungma@eit.uni-kl.de
6012027Sjungma@eit.uni-kl.deFault
6112027Sjungma@eit.uni-kl.deTranslatingPort::writeBlobFunctional(Addr addr, uint8_t *p, int size)
6212027Sjungma@eit.uni-kl.de{
6312027Sjungma@eit.uni-kl.de    Addr paddr;
6412027Sjungma@eit.uni-kl.de    int prevSize = 0;
6512027Sjungma@eit.uni-kl.de
6612027Sjungma@eit.uni-kl.de    for (ChunkGenerator gen(addr, size, VMPageSize); !gen.done(); gen.next()) {
6712027Sjungma@eit.uni-kl.de
6812027Sjungma@eit.uni-kl.de       if (!pTable->translate(gen.addr(),paddr))
6912027Sjungma@eit.uni-kl.de           return Machine_Check_Fault;
7012027Sjungma@eit.uni-kl.de
7112027Sjungma@eit.uni-kl.de       port->writeBlobFunctional(paddr, p + prevSize, gen.size());
7212027Sjungma@eit.uni-kl.de       prevSize += gen.size();
7312027Sjungma@eit.uni-kl.de    }
7412027Sjungma@eit.uni-kl.de
7512027Sjungma@eit.uni-kl.de    return No_Fault;
7612027Sjungma@eit.uni-kl.de}
7712027Sjungma@eit.uni-kl.de
7812027Sjungma@eit.uni-kl.deFault
7912027Sjungma@eit.uni-kl.deTranslatingPort::memsetBlobFunctional(Addr addr, uint8_t val, int size)
8012027Sjungma@eit.uni-kl.de{
8112027Sjungma@eit.uni-kl.de    Addr paddr;
8212027Sjungma@eit.uni-kl.de
8312027Sjungma@eit.uni-kl.de    for (ChunkGenerator gen(addr, size, VMPageSize); !gen.done(); gen.next()) {
8412027Sjungma@eit.uni-kl.de
8512027Sjungma@eit.uni-kl.de       if (!pTable->translate(gen.addr(),paddr))
8612027Sjungma@eit.uni-kl.de           return Machine_Check_Fault;
8712027Sjungma@eit.uni-kl.de
8812027Sjungma@eit.uni-kl.de       port->memsetBlobFunctional(paddr, val, gen.size());
8912027Sjungma@eit.uni-kl.de    }
9012027Sjungma@eit.uni-kl.de
9112027Sjungma@eit.uni-kl.de    return No_Fault;
9212027Sjungma@eit.uni-kl.de}
9312027Sjungma@eit.uni-kl.de
9412027Sjungma@eit.uni-kl.deFault
9512027Sjungma@eit.uni-kl.deTranslatingPort::writeStringFunctional(Addr addr, const char *str)
9612027Sjungma@eit.uni-kl.de{
9712027Sjungma@eit.uni-kl.de    Addr paddr,vaddr;
9812027Sjungma@eit.uni-kl.de    uint8_t c;
9912027Sjungma@eit.uni-kl.de
10012027Sjungma@eit.uni-kl.de    vaddr = addr;
10112027Sjungma@eit.uni-kl.de
10212027Sjungma@eit.uni-kl.de    do {
10312027Sjungma@eit.uni-kl.de        c = *str++;
10412027Sjungma@eit.uni-kl.de        if (!pTable->translate(vaddr++,paddr))
10512027Sjungma@eit.uni-kl.de            return Machine_Check_Fault;
10612027Sjungma@eit.uni-kl.de
10712027Sjungma@eit.uni-kl.de        port->writeBlobFunctional(paddr, &c, 1);
10812027Sjungma@eit.uni-kl.de    } while (c);
10912027Sjungma@eit.uni-kl.de
11012027Sjungma@eit.uni-kl.de    return No_Fault;
11112027Sjungma@eit.uni-kl.de}
11212027Sjungma@eit.uni-kl.de
11312027Sjungma@eit.uni-kl.deFault
11412027Sjungma@eit.uni-kl.deTranslatingPort::readStringFunctional(std::string &str, Addr addr)
11512027Sjungma@eit.uni-kl.de{
11612027Sjungma@eit.uni-kl.de    Addr paddr,vaddr;
11712027Sjungma@eit.uni-kl.de    uint8_t c;
11812027Sjungma@eit.uni-kl.de
11912027Sjungma@eit.uni-kl.de    vaddr = addr;
12012027Sjungma@eit.uni-kl.de
12112027Sjungma@eit.uni-kl.de    do {
12212027Sjungma@eit.uni-kl.de        if (!pTable->translate(vaddr++,paddr))
12312027Sjungma@eit.uni-kl.de            return Machine_Check_Fault;
12412027Sjungma@eit.uni-kl.de
12512027Sjungma@eit.uni-kl.de        port->readBlobFunctional(paddr, &c, 1);
12612027Sjungma@eit.uni-kl.de        str += c;
12712027Sjungma@eit.uni-kl.de    } while (c);
12812027Sjungma@eit.uni-kl.de
12912027Sjungma@eit.uni-kl.de    return No_Fault;
13012027Sjungma@eit.uni-kl.de}
13112027Sjungma@eit.uni-kl.de
13212027Sjungma@eit.uni-kl.de