gem5  v20.1.0.0
syscall_abi.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Google, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met: redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer;
8  * redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution;
11  * neither the name of the copyright holders nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef __SIM_SYSCALL_ABI_HH__
29 #define __SIM_SYSCALL_ABI_HH__
30 
31 #include "base/types.hh"
32 #include "cpu/thread_context.hh"
33 #include "sim/guest_abi.hh"
34 #include "sim/syscall_return.hh"
35 
36 class SyscallDesc;
37 
38 namespace GuestABI
39 {
40 
41 // Does this normally 64 bit data type shrink down to 32 bits for 32 bit ABIs?
42 template <typename T, typename Enabled=void>
43 struct IsConforming : public std::false_type {};
44 
45 template <>
46 struct IsConforming<Addr> : public std::true_type {};
47 
48 } // namespace GuestABI
49 
51 {
52  using State = int;
53 };
54 
56 {};
57 
59 {
60  // Is this argument too big for a single register?
61  template <typename T, typename Enabled=void>
62  struct IsWide;
63 
64  template <typename T>
65  struct IsWide<T, typename std::enable_if<
66  std::is_integral<T>::value &&
67  (sizeof(T) < sizeof(uint64_t) ||
68  GuestABI::IsConforming<T>::value)>::type>
69  {
70  static const bool value = false;
71  };
72 
73  template <typename T>
74  struct IsWide<T, typename std::enable_if<
75  std::is_integral<T>::value &&
76  sizeof(T) == sizeof(uint64_t) &&
77  !GuestABI::IsConforming<T>::value>::type>
78  {
79  static const bool value = true;
80  };
81 
82  // Read two registers and merge them into one value.
83  static uint64_t
84  mergeRegs(ThreadContext *tc, RegIndex low_idx, RegIndex high_idx)
85  {
86  RegVal low = tc->readIntReg(low_idx);
87  RegVal high = tc->readIntReg(high_idx);
88  return insertBits(low, 63, 32, high);
89  }
90 };
91 
92 namespace GuestABI
93 {
94 
95 // For 64 bit systems, return syscall args directly.
96 template <typename ABI, typename Arg>
97 struct Argument<ABI, Arg,
98  typename std::enable_if<
99  std::is_base_of<GenericSyscallABI64, ABI>::value &&
100  std::is_integral<Arg>::value>::type>
101 {
102  static Arg
103  get(ThreadContext *tc, typename ABI::State &state)
104  {
105  panic_if(state >= ABI::ArgumentRegs.size(),
106  "Ran out of syscall argument registers.");
107  return tc->readIntReg(ABI::ArgumentRegs[state++]);
108  }
109 };
110 
111 // For 32 bit systems, return small enough syscall args directly. Large
112 // arguments aren't handled generically.
113 template <typename ABI, typename Arg>
114 struct Argument<ABI, Arg,
115  typename std::enable_if<!ABI::template IsWide<Arg>::value>::type>
116 {
117  static Arg
118  get(ThreadContext *tc, typename ABI::State &state)
119  {
120  panic_if(state >= ABI::ArgumentRegs.size(),
121  "Ran out of syscall argument registers.");
122  return bits(tc->readIntReg(ABI::ArgumentRegs[state++]), 31, 0);
123  }
124 };
125 
126 } // namespace GuestABI
127 
128 #endif // __SIM_SYSCALL_ABI_HH__
RiscvISA::ArgumentRegs
const std::vector< int > ArgumentRegs
Definition: registers.hh:100
GuestABI::IsConforming
Definition: syscall_abi.hh:43
GenericSyscallABI::State
int State
Definition: syscall_abi.hh:52
GenericSyscallABI64
Definition: syscall_abi.hh:55
type
uint8_t type
Definition: inet.hh:421
syscall_return.hh
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
GuestABI
Definition: aapcs32.hh:66
GenericSyscallABI32::mergeRegs
static uint64_t mergeRegs(ThreadContext *tc, RegIndex low_idx, RegIndex high_idx)
Definition: syscall_abi.hh:84
GuestABI::Argument
Definition: definition.hh:93
GenericSyscallABI32::IsWide
Definition: syscall_abi.hh:62
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
GenericSyscallABI
Definition: syscall_abi.hh:50
GuestABI::Argument< ABI, Arg, typename std::enable_if< std::is_base_of< GenericSyscallABI64, ABI >::value &&std::is_integral< Arg >::value >::type >::get
static Arg get(ThreadContext *tc, typename ABI::State &state)
Definition: syscall_abi.hh:103
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
types.hh
RegIndex
uint16_t RegIndex
Definition: types.hh:52
insertBits
T insertBits(T val, int first, int last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
Definition: bitfield.hh:147
guest_abi.hh
GuestABI::Argument< ABI, Arg, typename std::enable_if<!ABI::template IsWide< Arg >::value >::type >::get
static Arg get(ThreadContext *tc, typename ABI::State &state)
Definition: syscall_abi.hh:118
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
GenericSyscallABI32
Definition: syscall_abi.hh:58
thread_context.hh
RegVal
uint64_t RegVal
Definition: types.hh:168
SyscallDesc
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:66
bits
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:75

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17