fs_translating_port_proxy.cc revision 10564:a8c16e2d466a
12086SN/A/*
22086SN/A * Copyright (c) 2011,2013 ARM Limited
32086SN/A * All rights reserved
42086SN/A *
52086SN/A * The license below extends only to copyright in the software and shall
62086SN/A * not be construed as granting a license to any other intellectual
72086SN/A * property including but not limited to intellectual property relating
82086SN/A * to a hardware implementation of the functionality of the software
92086SN/A * licensed hereunder.  You may use the software subject to the license
102086SN/A * terms below provided that you ensure that this notice is replicated
112086SN/A * unmodified and in its entirety in all distributions of the software,
122086SN/A * modified or unmodified, in source code or in binary form.
132086SN/A *
142086SN/A * Copyright (c) 2006 The Regents of The University of Michigan
152086SN/A * All rights reserved.
162086SN/A *
172086SN/A * Redistribution and use in source and binary forms, with or without
182086SN/A * modification, are permitted provided that the following conditions are
192086SN/A * met: redistributions of source code must retain the above copyright
202086SN/A * notice, this list of conditions and the following disclaimer;
212086SN/A * redistributions in binary form must reproduce the above copyright
222086SN/A * notice, this list of conditions and the following disclaimer in the
232086SN/A * documentation and/or other materials provided with the distribution;
242086SN/A * neither the name of the copyright holders nor the names of its
252086SN/A * contributors may be used to endorse or promote products derived from
262086SN/A * this software without specific prior written permission.
272086SN/A *
282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292665Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302665Ssaidi@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312086SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
324202Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332086SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
344202Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
354202Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
364202Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
378745Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386313Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
398778Sgblack@eecs.umich.edu *
408778Sgblack@eecs.umich.edu * Authors: Ali Saidi
418778Sgblack@eecs.umich.edu *          Andreas Hansson
426365Sgblack@eecs.umich.edu */
434997Sgblack@eecs.umich.edu
448778Sgblack@eecs.umich.edu/**
454202Sbinkertn@umich.edu * @file
468778Sgblack@eecs.umich.edu * Port object definitions.
478778Sgblack@eecs.umich.edu */
488778Sgblack@eecs.umich.edu
494997Sgblack@eecs.umich.edu#include "arch/vtophys.hh"
508747Sgblack@eecs.umich.edu#include "base/chunk_generator.hh"
514826Ssaidi@eecs.umich.edu#include "cpu/base.hh"
528760Sgblack@eecs.umich.edu#include "cpu/thread_context.hh"
532086SN/A#include "mem/fs_translating_port_proxy.hh"
548745Sgblack@eecs.umich.edu#include "sim/system.hh"
556365Sgblack@eecs.umich.edu
568778Sgblack@eecs.umich.eduusing namespace TheISA;
578745Sgblack@eecs.umich.edu
586365Sgblack@eecs.umich.eduFSTranslatingPortProxy::FSTranslatingPortProxy(ThreadContext *tc)
598335Snate@binkert.org    : PortProxy(tc->getCpuPtr()->getDataPort(),
608335Snate@binkert.org                tc->getSystemPtr()->cacheLineSize()), _tc(tc)
614997Sgblack@eecs.umich.edu{
624202Sbinkertn@umich.edu}
634202Sbinkertn@umich.edu
644202Sbinkertn@umich.eduFSTranslatingPortProxy::FSTranslatingPortProxy(MasterPort &port,
654202Sbinkertn@umich.edu                                               unsigned int cacheLineSize)
664202Sbinkertn@umich.edu    : PortProxy(port, cacheLineSize), _tc(NULL)
674202Sbinkertn@umich.edu{
68}
69
70FSTranslatingPortProxy::~FSTranslatingPortProxy()
71{
72}
73
74void
75FSTranslatingPortProxy::readBlob(Addr addr, uint8_t *p, int size) const
76{
77    Addr paddr;
78    for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done();
79         gen.next())
80    {
81        if (_tc)
82            paddr = TheISA::vtophys(_tc,gen.addr());
83        else
84            paddr = TheISA::vtophys(gen.addr());
85
86        PortProxy::readBlob(paddr, p, gen.size());
87        p += gen.size();
88    }
89}
90
91void
92FSTranslatingPortProxy::writeBlob(Addr addr, const uint8_t *p, int size) const
93{
94    Addr paddr;
95    for (ChunkGenerator gen(addr, size, TheISA::PageBytes); !gen.done();
96         gen.next())
97    {
98        if (_tc)
99            paddr = TheISA::vtophys(_tc,gen.addr());
100        else
101            paddr = TheISA::vtophys(gen.addr());
102
103        PortProxy::writeBlob(paddr, p, gen.size());
104        p += gen.size();
105    }
106}
107
108void
109FSTranslatingPortProxy::memsetBlob(Addr address, uint8_t v, int size) const
110{
111    Addr paddr;
112    for (ChunkGenerator gen(address, size, TheISA::PageBytes); !gen.done();
113         gen.next())
114    {
115        if (_tc)
116            paddr = TheISA::vtophys(_tc,gen.addr());
117        else
118            paddr = TheISA::vtophys(gen.addr());
119
120        PortProxy::memsetBlob(paddr, v, gen.size());
121    }
122}
123
124void
125CopyOut(ThreadContext *tc, void *dest, Addr src, size_t cplen)
126{
127    uint8_t *dst = (uint8_t *)dest;
128    tc->getVirtProxy().readBlob(src, dst, cplen);
129}
130
131void
132CopyIn(ThreadContext *tc, Addr dest, const void *source, size_t cplen)
133{
134    uint8_t *src = (uint8_t *)source;
135    tc->getVirtProxy().writeBlob(dest, src, cplen);
136}
137
138void
139CopyStringOut(ThreadContext *tc, char *dst, Addr vaddr, size_t maxlen)
140{
141    char *start = dst;
142    FSTranslatingPortProxy &vp = tc->getVirtProxy();
143
144    bool foundNull = false;
145    while ((dst - start + 1) < maxlen && !foundNull) {
146        vp.readBlob(vaddr++, (uint8_t*)dst, 1);
147        if (*dst == '\0')
148            foundNull = true;
149        dst++;
150    }
151
152    if (!foundNull)
153        *dst = '\0';
154}
155
156void
157CopyStringIn(ThreadContext *tc, const char *src, Addr vaddr)
158{
159    FSTranslatingPortProxy &vp = tc->getVirtProxy();
160    for (ChunkGenerator gen(vaddr, strlen(src), TheISA::PageBytes); !gen.done();
161         gen.next())
162    {
163        vp.writeBlob(gen.addr(), (uint8_t*)src, gen.size());
164        src += gen.size();
165    }
166}
167