• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 The Marl Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #define MARL_REG_R1 0x00
16 #define MARL_REG_R2 0x08
17 #define MARL_REG_R13 0x10
18 #define MARL_REG_R14 0x18
19 #define MARL_REG_R15 0x20
20 #define MARL_REG_R16 0x28
21 #define MARL_REG_R17 0x30
22 #define MARL_REG_R18 0x38
23 #define MARL_REG_R19 0x40
24 #define MARL_REG_R20 0x48
25 #define MARL_REG_R21 0x50
26 #define MARL_REG_R22 0x58
27 #define MARL_REG_R23 0x60
28 #define MARL_REG_R24 0x68
29 #define MARL_REG_R25 0x70
30 #define MARL_REG_R26 0x78
31 #define MARL_REG_R27 0x80
32 #define MARL_REG_R28 0x88
33 #define MARL_REG_R29 0x90
34 #define MARL_REG_R30 0x98
35 #define MARL_REG_R31 0xa0
36 
37 #define MARL_REG_R3 0xa8
38 #define MARL_REG_R4 0xb0
39 
40 #define MARL_REG_LR 0xb8
41 #define MARL_REG_CCR 0xc0
42 
43 #define MARL_REG_FPR14 0xc8
44 #define MARL_REG_FPR15 0xd0
45 #define MARL_REG_FPR16 0xd8
46 #define MARL_REG_FPR17 0xe0
47 #define MARL_REG_FPR18 0xe8
48 #define MARL_REG_FPR19 0xf0
49 #define MARL_REG_FPR20 0xf8
50 #define MARL_REG_FPR21 0x100
51 #define MARL_REG_FPR22 0x108
52 #define MARL_REG_FPR23 0x110
53 #define MARL_REG_FPR24 0x118
54 #define MARL_REG_FPR25 0x120
55 #define MARL_REG_FPR26 0x128
56 #define MARL_REG_FPR27 0x130
57 #define MARL_REG_FPR28 0x138
58 #define MARL_REG_FPR29 0x140
59 #define MARL_REG_FPR30 0x148
60 #define MARL_REG_FPR31 0x150
61 
62 #define MARL_REG_VRSAVE 0x158
63 #define MARL_REG_VMX 0x160
64 
65 #ifndef MARL_BUILD_ASM
66 
67 #include <stdint.h>
68 
69 struct marl_fiber_context {
70   // non-volatile registers
71   uintptr_t r1;
72   uintptr_t r2;
73   uintptr_t r13;
74   uintptr_t r14;
75   uintptr_t r15;
76   uintptr_t r16;
77   uintptr_t r17;
78   uintptr_t r18;
79   uintptr_t r19;
80   uintptr_t r20;
81   uintptr_t r21;
82   uintptr_t r22;
83   uintptr_t r23;
84   uintptr_t r24;
85   uintptr_t r25;
86   uintptr_t r26;
87   uintptr_t r27;
88   uintptr_t r28;
89   uintptr_t r29;
90   uintptr_t r30;
91   uintptr_t r31;
92 
93   // first two parameter registers (r3, r4)
94   uintptr_t r3;
95   uintptr_t r4;
96 
97   // special registers
98   uintptr_t lr;
99   uintptr_t ccr;
100 
101   // non-volatile floating-point registers (f14-f31)
102   uintptr_t fpr14;
103   uintptr_t fpr15;
104   uintptr_t fpr16;
105   uintptr_t fpr17;
106   uintptr_t fpr18;
107   uintptr_t fpr19;
108   uintptr_t fpr20;
109   uintptr_t fpr21;
110   uintptr_t fpr22;
111   uintptr_t fpr23;
112   uintptr_t fpr24;
113   uintptr_t fpr25;
114   uintptr_t fpr26;
115   uintptr_t fpr27;
116   uintptr_t fpr28;
117   uintptr_t fpr29;
118   uintptr_t fpr30;
119   uintptr_t fpr31;
120 
121   // non-volatile altivec registers
122   uint32_t vrsave;
123   uintptr_t vmx[12 * 2];
124 };
125 
126 // Only the ELFv2 ABI is supported for now.
127 #if !defined(_CALL_ELF) || (_CALL_ELF != 2)
128 #error "Only the ppc64 ELFv2 ABI is supported."
129 #endif
130 
131 #ifdef __cplusplus
132 #include <cstddef>
133 static_assert(offsetof(marl_fiber_context, r1) == MARL_REG_R1,
134               "Bad register offset");
135 static_assert(offsetof(marl_fiber_context, r2) == MARL_REG_R2,
136               "Bad register offset");
137 static_assert(offsetof(marl_fiber_context, r13) == MARL_REG_R13,
138               "Bad register offset");
139 static_assert(offsetof(marl_fiber_context, r15) == MARL_REG_R15,
140               "Bad register offset");
141 static_assert(offsetof(marl_fiber_context, r16) == MARL_REG_R16,
142               "Bad register offset");
143 static_assert(offsetof(marl_fiber_context, r17) == MARL_REG_R17,
144               "Bad register offset");
145 static_assert(offsetof(marl_fiber_context, r18) == MARL_REG_R18,
146               "Bad register offset");
147 static_assert(offsetof(marl_fiber_context, r19) == MARL_REG_R19,
148               "Bad register offset");
149 static_assert(offsetof(marl_fiber_context, r20) == MARL_REG_R20,
150               "Bad register offset");
151 static_assert(offsetof(marl_fiber_context, r21) == MARL_REG_R21,
152               "Bad register offset");
153 static_assert(offsetof(marl_fiber_context, r22) == MARL_REG_R22,
154               "Bad register offset");
155 static_assert(offsetof(marl_fiber_context, r23) == MARL_REG_R23,
156               "Bad register offset");
157 static_assert(offsetof(marl_fiber_context, r24) == MARL_REG_R24,
158               "Bad register offset");
159 static_assert(offsetof(marl_fiber_context, r25) == MARL_REG_R25,
160               "Bad register offset");
161 static_assert(offsetof(marl_fiber_context, r26) == MARL_REG_R26,
162               "Bad register offset");
163 static_assert(offsetof(marl_fiber_context, r27) == MARL_REG_R27,
164               "Bad register offset");
165 static_assert(offsetof(marl_fiber_context, r28) == MARL_REG_R28,
166               "Bad register offset");
167 static_assert(offsetof(marl_fiber_context, r29) == MARL_REG_R29,
168               "Bad register offset");
169 static_assert(offsetof(marl_fiber_context, r30) == MARL_REG_R30,
170               "Bad register offset");
171 static_assert(offsetof(marl_fiber_context, r31) == MARL_REG_R31,
172               "Bad register offset");
173 static_assert(offsetof(marl_fiber_context, r14) == MARL_REG_R14,
174               "Bad register offset");
175 static_assert(offsetof(marl_fiber_context, lr) == MARL_REG_LR,
176               "Bad register offset");
177 static_assert(offsetof(marl_fiber_context, ccr) == MARL_REG_CCR,
178               "Bad register offset");
179 static_assert(offsetof(marl_fiber_context, fpr14) == MARL_REG_FPR14,
180               "Bad register offset");
181 static_assert(offsetof(marl_fiber_context, fpr15) == MARL_REG_FPR15,
182               "Bad register offset");
183 static_assert(offsetof(marl_fiber_context, fpr16) == MARL_REG_FPR16,
184               "Bad register offset");
185 static_assert(offsetof(marl_fiber_context, fpr17) == MARL_REG_FPR17,
186               "Bad register offset");
187 static_assert(offsetof(marl_fiber_context, fpr18) == MARL_REG_FPR18,
188               "Bad register offset");
189 static_assert(offsetof(marl_fiber_context, fpr19) == MARL_REG_FPR19,
190               "Bad register offset");
191 static_assert(offsetof(marl_fiber_context, fpr20) == MARL_REG_FPR20,
192               "Bad register offset");
193 static_assert(offsetof(marl_fiber_context, fpr21) == MARL_REG_FPR21,
194               "Bad register offset");
195 static_assert(offsetof(marl_fiber_context, fpr22) == MARL_REG_FPR22,
196               "Bad register offset");
197 static_assert(offsetof(marl_fiber_context, fpr23) == MARL_REG_FPR23,
198               "Bad register offset");
199 static_assert(offsetof(marl_fiber_context, fpr24) == MARL_REG_FPR24,
200               "Bad register offset");
201 static_assert(offsetof(marl_fiber_context, fpr25) == MARL_REG_FPR25,
202               "Bad register offset");
203 static_assert(offsetof(marl_fiber_context, fpr26) == MARL_REG_FPR26,
204               "Bad register offset");
205 static_assert(offsetof(marl_fiber_context, fpr27) == MARL_REG_FPR27,
206               "Bad register offset");
207 static_assert(offsetof(marl_fiber_context, fpr28) == MARL_REG_FPR28,
208               "Bad register offset");
209 static_assert(offsetof(marl_fiber_context, fpr29) == MARL_REG_FPR29,
210               "Bad register offset");
211 static_assert(offsetof(marl_fiber_context, fpr30) == MARL_REG_FPR30,
212               "Bad register offset");
213 static_assert(offsetof(marl_fiber_context, fpr31) == MARL_REG_FPR31,
214               "Bad register offset");
215 static_assert((offsetof(marl_fiber_context, vmx) % 16) == 0,
216               "VMX must be quadword aligned");
217 static_assert(offsetof(marl_fiber_context, vmx) == MARL_REG_VMX,
218               "Bad register offset");
219 static_assert(offsetof(marl_fiber_context, vrsave) == MARL_REG_VRSAVE,
220               "Bad register offset");
221 #endif  // __cplusplus
222 
223 #endif  // MARL_BUILD_ASM
224