gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
syscall_emul_buf.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2005 The Regents of The University of Michigan
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * Authors: Steve Reinhardt
29  */
30 
31 #ifndef __SIM_SYSCALL_EMUL_BUF_HH__
32 #define __SIM_SYSCALL_EMUL_BUF_HH__
33 
39 
40 #include <cstring>
41 
42 #include "base/types.hh"
44 
57 
58  public:
59 
64  BaseBufferArg(Addr _addr, int _size)
65  : addr(_addr), size(_size), bufPtr(new uint8_t[size])
66  {
67  // clear out buffer: in case we only partially populate this,
68  // and then do a copyOut(), we want to make sure we don't
69  // introduce any random junk into the simulated address space
70  memset(bufPtr, 0, size);
71  }
72 
73  ~BaseBufferArg() { delete [] bufPtr; }
74 
79  {
80  memproxy.readBlob(addr, bufPtr, size);
81  return true; // no EFAULT detection for now
82  }
83 
88  {
89  memproxy.writeBlob(addr, bufPtr, size);
90  return true; // no EFAULT detection for now
91  }
92 
93  protected:
94  const Addr addr;
95  const int size;
96  uint8_t * const bufPtr;
97 };
98 
103 class BufferArg : public BaseBufferArg
104 {
105  public:
110  BufferArg(Addr _addr, int _size) : BaseBufferArg(_addr, _size) { }
111 
115  void *bufferPtr() { return bufPtr; }
116 };
117 
127 template <class T>
129 {
130  public:
137  TypedBufferArg(Addr _addr, int _size = sizeof(T))
138  : BaseBufferArg(_addr, _size)
139  { }
140 
145  operator T*() { return (T *)bufPtr; }
146 
151  T &operator*() { return *((T *)bufPtr); }
152 
153 
158  T* operator->() { return (T *)bufPtr; }
159 
164  T &operator[](int i) { return ((T *)bufPtr)[i]; }
165 };
166 
167 
168 #endif // __SIM_SYSCALL_EMUL_BUF_HH__
BufferArg(Addr _addr, int _size)
Allocate a buffer of size 'size' representing the memory at target address 'addr'.
BaseBufferArg(Addr _addr, int _size)
Allocate a buffer of size 'size' representing the memory at target address 'addr'.
Bitfield< 7 > i
Definition: miscregs.hh:1378
T & operator*()
Convert TypedBufferArg<T> to a reference to T that references the internal buffer value...
uint8_t *const bufPtr
pointer to buffer in simulator space
bool copyIn(SETranslatingPortProxy &memproxy)
copy data into simulator space (read from target memory)
virtual void readBlob(Addr addr, uint8_t *p, int size) const
Read size bytes memory at address and store in p.
TypedBufferArg is a class template; instances of this template represent typed buffers in target user...
const int size
buffer size
T & operator[](int i)
Enable the use of '[]' to reference fields where T is an array type.
bool copyOut(SETranslatingPortProxy &memproxy)
copy data out of simulator space (write to target memory)
const Addr addr
address of buffer in target address space
void * bufferPtr()
Return a pointer to the internal simulator-space buffer.
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Base class for BufferArg and TypedBufferArg, Not intended to be used directly.
TranslatingPortProxy Object Declaration for SE.
T * operator->()
Enable the use of '->' to reference fields where T is a struct type.
BufferArg represents an untyped buffer in target user space that is passed by reference to an (emulat...
TypedBufferArg(Addr _addr, int _size=sizeof(T))
Allocate a buffer of type T representing the memory at target address 'addr'.
virtual void writeBlob(Addr addr, const uint8_t *p, int size) const
Write size bytes from p to address.

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6