gem5  v21.0.1.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/bitfield.hh"
32 #include "base/types.hh"
33 #include "cpu/thread_context.hh"
34 #include "sim/guest_abi.hh"
35 #include "sim/syscall_return.hh"
36 
37 class SyscallDesc;
38 
40 {
41  using State = int;
42 };
43 
45 {
46  using UintPtr = uint64_t;
47 };
48 
50 {
51  using UintPtr = uint32_t;
52 
53  // Is this argument too big for a single register?
54  template <typename T, typename Enabled=void>
55  struct IsWide : public std::false_type {};
56 
57  template <typename T>
58  struct IsWide<T, std::enable_if_t<(sizeof(T) > sizeof(UintPtr))>> :
59  public std::true_type
60  {};
61 
62  // Read two registers and merge them into one value.
63  static uint64_t
64  mergeRegs(ThreadContext *tc, RegIndex low_idx, RegIndex high_idx)
65  {
66  RegVal low = tc->readIntReg(low_idx);
67  RegVal high = tc->readIntReg(high_idx);
68  return insertBits(low, 63, 32, high);
69  }
70 };
71 
72 namespace GuestABI
73 {
74 
75 // For 64 bit systems, return syscall args directly.
76 template <typename ABI, typename Arg>
77 struct Argument<ABI, Arg,
78  typename std::enable_if_t<
79  std::is_base_of<GenericSyscallABI64, ABI>::value &&
80  std::is_integral<Arg>::value>>
81 {
82  static Arg
83  get(ThreadContext *tc, typename ABI::State &state)
84  {
85  panic_if(state >= ABI::ArgumentRegs.size(),
86  "Ran out of syscall argument registers.");
87  return tc->readIntReg(ABI::ArgumentRegs[state++]);
88  }
89 };
90 
91 // For 32 bit systems, return small enough syscall args directly. Large
92 // arguments aren't handled generically.
93 template <typename ABI, typename Arg>
94 struct Argument<ABI, Arg,
95  typename std::enable_if_t<std::is_integral<Arg>::value &&
96  !ABI::template IsWide<Arg>::value>>
97 {
98  static Arg
99  get(ThreadContext *tc, typename ABI::State &state)
100  {
101  panic_if(state >= ABI::ArgumentRegs.size(),
102  "Ran out of syscall argument registers.");
103  return bits(tc->readIntReg(ABI::ArgumentRegs[state++]), 31, 0);
104  }
105 };
106 
107 } // namespace GuestABI
108 
109 #endif // __SIM_SYSCALL_ABI_HH__
RiscvISA::ArgumentRegs
const std::vector< int > ArgumentRegs
Definition: registers.hh:127
insertBits
constexpr T insertBits(T val, unsigned first, unsigned last, B bit_val)
Returns val with bits first to last set to the LSBs of bit_val.
Definition: bitfield.hh:143
GenericSyscallABI::State
int State
Definition: syscall_abi.hh:41
GenericSyscallABI64::UintPtr
uint64_t UintPtr
Definition: syscall_abi.hh:46
GenericSyscallABI64
Definition: syscall_abi.hh:44
GuestABI::Argument< ABI, Arg, typename std::enable_if_t< std::is_integral< Arg >::value &&!ABI::template IsWide< Arg >::value > >::get
static Arg get(ThreadContext *tc, typename ABI::State &state)
Definition: syscall_abi.hh:99
syscall_return.hh
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
bitfield.hh
GuestABI
Definition: aapcs32.hh:66
GenericSyscallABI32::mergeRegs
static uint64_t mergeRegs(ThreadContext *tc, RegIndex low_idx, RegIndex high_idx)
Definition: syscall_abi.hh:64
GuestABI::Argument
Definition: definition.hh:93
GenericSyscallABI32::IsWide
Definition: syscall_abi.hh:55
GuestABI::Argument< ABI, Arg, typename std::enable_if_t< std::is_base_of< GenericSyscallABI64, ABI >::value &&std::is_integral< Arg >::value > >::get
static Arg get(ThreadContext *tc, typename ABI::State &state)
Definition: syscall_abi.hh:83
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:39
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
types.hh
RegIndex
uint16_t RegIndex
Definition: types.hh:52
guest_abi.hh
GenericSyscallABI32::UintPtr
uint32_t UintPtr
Definition: syscall_abi.hh:51
bits
constexpr T bits(T val, unsigned first, unsigned last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.
Definition: bitfield.hh:73
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
GenericSyscallABI32
Definition: syscall_abi.hh:49
thread_context.hh
RegVal
uint64_t RegVal
Definition: types.hh:174
SyscallDesc
This class provides the wrapper interface for the system call implementations which are defined in th...
Definition: syscall_desc.hh:66

Generated on Tue Jun 22 2021 15:28:30 for gem5 by doxygen 1.8.17