1 /* This file is part of the dynarmic project.
2  * Copyright (c) 2016 MerryMage
3  * This software may be used and distributed according to the terms of the GNU
4  * General Public License version 2 or any later version.
5  */
6 #pragma once
7 
8 #include <array>
9 
10 #include "backend/A64/block_of_code.h"
11 #include "backend/A64/hostloc.h"
12 
13 namespace Dynarmic::BackendA64 {
14 
15 constexpr HostLoc ABI_RETURN = HostLoc::X0;
16 
17 constexpr HostLoc ABI_PARAM1 = HostLoc::X0;
18 constexpr HostLoc ABI_PARAM2 = HostLoc::X1;
19 constexpr HostLoc ABI_PARAM3 = HostLoc::X2;
20 constexpr HostLoc ABI_PARAM4 = HostLoc::X3;
21 constexpr HostLoc ABI_PARAM5 = HostLoc::X4;
22 constexpr HostLoc ABI_PARAM6 = HostLoc::X5;
23 constexpr HostLoc ABI_PARAM7 = HostLoc::X6;
24 constexpr HostLoc ABI_PARAM8 = HostLoc::X7;
25 
26 constexpr std::array<HostLoc, 43> ABI_ALL_CALLER_SAVE = {
27     HostLoc::X0,
28     HostLoc::X1,
29     HostLoc::X2,
30     HostLoc::X3,
31     HostLoc::X4,
32     HostLoc::X5,
33     HostLoc::X6,
34     HostLoc::X7,
35     HostLoc::X8,
36     HostLoc::X9,
37     HostLoc::X10,
38     HostLoc::X11,
39     HostLoc::X12,
40     HostLoc::X13,
41     HostLoc::X14,
42     HostLoc::X15,
43     HostLoc::X16,
44     HostLoc::X17,
45     HostLoc::X18,
46 
47     HostLoc::Q0,
48     HostLoc::Q1,
49     HostLoc::Q2,
50     HostLoc::Q3,
51     HostLoc::Q4,
52     HostLoc::Q5,
53     HostLoc::Q6,
54     HostLoc::Q7,
55 
56     HostLoc::Q16,
57     HostLoc::Q17,
58     HostLoc::Q18,
59     HostLoc::Q19,
60     HostLoc::Q20,
61     HostLoc::Q21,
62     HostLoc::Q22,
63     HostLoc::Q23,
64     HostLoc::Q24,
65     HostLoc::Q25,
66     HostLoc::Q26,
67     HostLoc::Q27,
68     HostLoc::Q28,
69     HostLoc::Q29,
70     HostLoc::Q30,
71     HostLoc::Q31,
72 };
73 
74 constexpr std::array<HostLoc, 20> ABI_ALL_CALLEE_SAVE = {
75     HostLoc::X19,
76     HostLoc::X20,
77     HostLoc::X21,
78     HostLoc::X22,
79     HostLoc::X23,
80     HostLoc::X24,
81     HostLoc::X25,
82     HostLoc::X26,
83     HostLoc::X27,
84     HostLoc::X28,
85     HostLoc::X29,
86     HostLoc::X30,
87 
88     HostLoc::Q8,
89     HostLoc::Q9,
90     HostLoc::Q10,
91     HostLoc::Q11,
92     HostLoc::Q12,
93     HostLoc::Q13,
94     HostLoc::Q14,
95     HostLoc::Q15,
96 };
97 
98 constexpr size_t ABI_SHADOW_SPACE = 0; // bytes
99 
100 static_assert(ABI_ALL_CALLER_SAVE.size() + ABI_ALL_CALLEE_SAVE.size() == 63, "Invalid total number of registers");
101 
102 void ABI_PushCalleeSaveRegistersAndAdjustStack(BlockOfCode& code);
103 void ABI_PopCalleeSaveRegistersAndAdjustStack(BlockOfCode& code);
104 void ABI_PushCallerSaveRegistersAndAdjustStack(BlockOfCode& code);
105 void ABI_PopCallerSaveRegistersAndAdjustStack(BlockOfCode& code);
106 
107 void ABI_PushCallerSaveRegistersAndAdjustStackExcept(BlockOfCode& code, HostLoc exception);
108 void ABI_PopCallerSaveRegistersAndAdjustStackExcept(BlockOfCode& code, HostLoc exception);
109 
110 } // namespace Dynarmic::BackendX64
111