gem5 v24.0.0.0
Loading...
Searching...
No Matches
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/pseudo_inst.hh"
36#include "sim/syscall_return.hh"
37
38namespace gem5
39{
40
41class SyscallDesc;
42
44{
45 using State = int;
46};
47
49{
50 using UintPtr = uint64_t;
51};
52
54{
55 using UintPtr = uint32_t;
56
57 // Is this argument too big for a single register?
58 template <typename T, typename Enabled=void>
59 struct IsWide : public std::false_type {};
60
61 template <typename T>
62 struct IsWide<T, std::enable_if_t<(sizeof(T) > sizeof(UintPtr))>> :
63 public std::true_type
64 {};
65
66 template <typename T>
67 static constexpr bool IsWideV = IsWide<T>::value;
68
69 // Read two registers and merge them into one value.
70 static uint64_t
71 mergeRegs(ThreadContext *tc, const RegId &low_id, const RegId &high_id)
72 {
73 RegVal low = tc->getReg(low_id);
74 RegVal high = tc->getReg(high_id);
75 return insertBits(low, 63, 32, high);
76 }
77};
78
79namespace guest_abi
80{
81
82// For 64 bit systems, return syscall args directly.
83template <typename ABI, typename Arg>
84struct Argument<ABI, Arg,
85 typename std::enable_if_t<
86 std::is_base_of_v<GenericSyscallABI64, ABI> &&
87 (std::is_integral_v<Arg> ||
88 std::is_same<Arg,pseudo_inst::GuestAddr>::value)>>
89{
90 static Arg
91 get(ThreadContext *tc, typename ABI::State &state)
92 {
93 panic_if(state >= ABI::ArgumentRegs.size(),
94 "Ran out of syscall argument registers.");
95 return (Arg)tc->getReg(ABI::ArgumentRegs[state++]);
96 }
97};
98
99// For 32 bit systems, return small enough syscall args directly. Large
100// arguments aren't handled generically.
101template <typename ABI, typename Arg>
102struct Argument<ABI, Arg,
103 typename std::enable_if_t<std::is_integral_v<Arg> &&
104 !ABI::template IsWideV<Arg>>>
105{
106 static Arg
107 get(ThreadContext *tc, typename ABI::State &state)
108 {
109 panic_if(state >= ABI::ArgumentRegs.size(),
110 "Ran out of syscall argument registers.");
111 return bits(tc->getReg(ABI::ArgumentRegs[state++]), 31, 0);
112 }
113};
114
115} // namespace guest_abi
116} // namespace gem5
117
118#endif // __SIM_SYSCALL_ABI_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Register ID: describe an architectural register with its class and index.
Definition reg_class.hh:94
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual RegVal getReg(const RegId &reg) const
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:79
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:185
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition logging.hh:214
atomic_var_t state
Definition helpers.cc:211
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t RegVal
Definition types.hh:173
Overload hash function for BasicBlockRange type.
Definition binary32.hh:81
static constexpr bool IsWideV
static uint64_t mergeRegs(ThreadContext *tc, const RegId &low_id, const RegId &high_id)

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0