gem5  v22.1.0.0
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 
29 #ifndef __SIM_SYSCALL_EMUL_BUF_HH__
30 #define __SIM_SYSCALL_EMUL_BUF_HH__
31 
37 
38 #include <cstring>
39 
40 #include "base/types.hh"
42 
43 namespace gem5
44 {
45 
58 {
59 
60  public:
61 
66  BaseBufferArg(Addr _addr, int _size)
67  : addr(_addr), size(_size), bufPtr(new uint8_t[size])
68  {
69  // clear out buffer: in case we only partially populate this,
70  // and then do a copyOut(), we want to make sure we don't
71  // introduce any random junk into the simulated address space
72  memset(bufPtr, 0, size);
73  }
74 
75  ~BaseBufferArg() { delete [] bufPtr; }
76 
80  bool
81  copyIn(const PortProxy &memproxy)
82  {
83  memproxy.readBlob(addr, bufPtr, size);
84  return true; // no EFAULT detection for now
85  }
86 
90  bool
91  copyOut(const PortProxy &memproxy)
92  {
93  memproxy.writeBlob(addr, bufPtr, size);
94  return true; // no EFAULT detection for now
95  }
96 
97  protected:
98  const Addr addr;
99  const int size;
100  uint8_t * const bufPtr;
101 };
102 
107 class BufferArg : public BaseBufferArg
108 {
109  public:
114  BufferArg(Addr _addr, int _size) : BaseBufferArg(_addr, _size) { }
115 
119  void *bufferPtr() { return bufPtr; }
120 };
121 
131 template <class T>
133 {
134  public:
141  TypedBufferArg(Addr _addr, int _size = sizeof(T))
142  : BaseBufferArg(_addr, _size)
143  { }
144 
149  operator T*() { return (T *)bufPtr; }
150 
155  T &operator*() { return *((T *)bufPtr); }
156 
157 
162  T* operator->() { return (T *)bufPtr; }
163 
168  T &operator[](int i) { return ((T *)bufPtr)[i]; }
169 };
170 
171 } // namespace gem5
172 
173 #endif // __SIM_SYSCALL_EMUL_BUF_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Base class for BufferArg and TypedBufferArg, Not intended to be used directly.
bool copyIn(const PortProxy &memproxy)
copy data into simulator space (read from target memory)
const Addr addr
address of buffer in target address space
const int size
buffer size
BaseBufferArg(Addr _addr, int _size)
Allocate a buffer of size 'size' representing the memory at target address 'addr'.
uint8_t *const bufPtr
pointer to buffer in simulator space
bool copyOut(const PortProxy &memproxy)
copy data out of simulator space (write to target memory)
BufferArg represents an untyped buffer in target user space that is passed by reference to an (emulat...
BufferArg(Addr _addr, int _size)
Allocate a buffer of size 'size' representing the memory at target address 'addr'.
void * bufferPtr()
Return a pointer to the internal simulator-space buffer.
This object is a proxy for a port or other object which implements the functional response protocol,...
Definition: port_proxy.hh:87
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
Definition: port_proxy.hh:192
void readBlob(Addr addr, void *p, int size) const
Higher level interfaces based on the above.
Definition: port_proxy.hh:182
TypedBufferArg is a class template; instances of this template represent typed buffers in target user...
TypedBufferArg(Addr _addr, int _size=sizeof(T))
Allocate a buffer of type T representing the memory at target address 'addr'.
T * operator->()
Enable the use of '->' to reference fields where T is a struct type.
T & operator*()
Convert TypedBufferArg<T> to a reference to T that references the internal buffer value.
T & operator[](int i)
Enable the use of '[]' to reference fields where T is an array type.
Bitfield< 7 > i
Definition: misc_types.hh:67
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1