gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
78  bool
79  copyIn(PortProxy &memproxy)
80  {
81  memproxy.readBlob(addr, bufPtr, size);
82  return true; // no EFAULT detection for now
83  }
84 
88  bool
89  copyOut(PortProxy &memproxy)
90  {
91  memproxy.writeBlob(addr, bufPtr, size);
92  return true; // no EFAULT detection for now
93  }
94 
95  protected:
96  const Addr addr;
97  const int size;
98  uint8_t * const bufPtr;
99 };
100 
105 class BufferArg : public BaseBufferArg
106 {
107  public:
112  BufferArg(Addr _addr, int _size) : BaseBufferArg(_addr, _size) { }
113 
117  void *bufferPtr() { return bufPtr; }
118 };
119 
129 template <class T>
131 {
132  public:
139  TypedBufferArg(Addr _addr, int _size = sizeof(T))
140  : BaseBufferArg(_addr, _size)
141  { }
142 
147  operator T*() { return (T *)bufPtr; }
148 
153  T &operator*() { return *((T *)bufPtr); }
154 
155 
160  T* operator->() { return (T *)bufPtr; }
161 
166  T &operator[](int i) { return ((T *)bufPtr)[i]; }
167 };
168 
169 
170 #endif // __SIM_SYSCALL_EMUL_BUF_HH__
BufferArg(Addr _addr, int _size)
Allocate a buffer of size &#39;size&#39; representing the memory at target address &#39;addr&#39;.
BaseBufferArg(Addr _addr, int _size)
Allocate a buffer of size &#39;size&#39; representing the memory at target address &#39;addr&#39;.
Bitfield< 7 > i
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(PortProxy &memproxy)
copy data into simulator space (read from target memory)
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 &#39;[]&#39; to reference fields where T is an array type.
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
Definition: port_proxy.hh:189
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
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:179
Base class for BufferArg and TypedBufferArg, Not intended to be used directly.
This object is a proxy for a port or other object which implements the functional response protocol...
Definition: port_proxy.hh:82
bool copyOut(PortProxy &memproxy)
copy data out of simulator space (write to target memory)
TranslatingPortProxy Object Declaration for SE.
T * operator->()
Enable the use of &#39;->&#39; 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 &#39;addr&#39;.

Generated on Fri Feb 28 2020 16:27:03 for gem5 by doxygen 1.8.13