• 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_r0 0x00
16 #define MARL_REG_r1 0x08
17 #define MARL_REG_r16 0x10
18 #define MARL_REG_r17 0x18
19 #define MARL_REG_r18 0x20
20 #define MARL_REG_r19 0x28
21 #define MARL_REG_r20 0x30
22 #define MARL_REG_r21 0x38
23 #define MARL_REG_r22 0x40
24 #define MARL_REG_r23 0x48
25 #define MARL_REG_r24 0x50
26 #define MARL_REG_r25 0x58
27 #define MARL_REG_r26 0x60
28 #define MARL_REG_r27 0x68
29 #define MARL_REG_r28 0x70
30 #define MARL_REG_r29 0x78
31 #define MARL_REG_v8 0x80
32 #define MARL_REG_v9 0x88
33 #define MARL_REG_v10 0x90
34 #define MARL_REG_v11 0x98
35 #define MARL_REG_v12 0xa0
36 #define MARL_REG_v13 0xa8
37 #define MARL_REG_v14 0xb0
38 #define MARL_REG_v15 0xb8
39 #define MARL_REG_SP 0xc0
40 #define MARL_REG_LR 0xc8
41 
42 #if defined(__APPLE__)
43 #define MARL_ASM_SYMBOL(x) _##x
44 #else
45 #define MARL_ASM_SYMBOL(x) x
46 #endif
47 
48 #ifndef MARL_BUILD_ASM
49 
50 #include <stdint.h>
51 
52 // Procedure Call Standard for the ARM 64-bit Architecture
53 // http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf
54 struct marl_fiber_context {
55   // parameter registers
56   uintptr_t r0;
57   uintptr_t r1;
58 
59   // special purpose registers
60   uintptr_t r16;
61   uintptr_t r17;
62   uintptr_t r18;  // platform specific (maybe inter-procedural state)
63 
64   // callee-saved registers
65   uintptr_t r19;
66   uintptr_t r20;
67   uintptr_t r21;
68   uintptr_t r22;
69   uintptr_t r23;
70   uintptr_t r24;
71   uintptr_t r25;
72   uintptr_t r26;
73   uintptr_t r27;
74   uintptr_t r28;
75   uintptr_t r29;
76 
77   uintptr_t v8;
78   uintptr_t v9;
79   uintptr_t v10;
80   uintptr_t v11;
81   uintptr_t v12;
82   uintptr_t v13;
83   uintptr_t v14;
84   uintptr_t v15;
85 
86   uintptr_t SP;  // stack pointer
87   uintptr_t LR;  // link register (R30)
88 };
89 
90 #ifdef __cplusplus
91 #include <cstddef>
92 static_assert(offsetof(marl_fiber_context, r0) == MARL_REG_r0,
93               "Bad register offset");
94 static_assert(offsetof(marl_fiber_context, r1) == MARL_REG_r1,
95               "Bad register offset");
96 static_assert(offsetof(marl_fiber_context, r16) == MARL_REG_r16,
97               "Bad register offset");
98 static_assert(offsetof(marl_fiber_context, r17) == MARL_REG_r17,
99               "Bad register offset");
100 static_assert(offsetof(marl_fiber_context, r18) == MARL_REG_r18,
101               "Bad register offset");
102 static_assert(offsetof(marl_fiber_context, r19) == MARL_REG_r19,
103               "Bad register offset");
104 static_assert(offsetof(marl_fiber_context, r20) == MARL_REG_r20,
105               "Bad register offset");
106 static_assert(offsetof(marl_fiber_context, r21) == MARL_REG_r21,
107               "Bad register offset");
108 static_assert(offsetof(marl_fiber_context, r22) == MARL_REG_r22,
109               "Bad register offset");
110 static_assert(offsetof(marl_fiber_context, r23) == MARL_REG_r23,
111               "Bad register offset");
112 static_assert(offsetof(marl_fiber_context, r24) == MARL_REG_r24,
113               "Bad register offset");
114 static_assert(offsetof(marl_fiber_context, r25) == MARL_REG_r25,
115               "Bad register offset");
116 static_assert(offsetof(marl_fiber_context, r26) == MARL_REG_r26,
117               "Bad register offset");
118 static_assert(offsetof(marl_fiber_context, r27) == MARL_REG_r27,
119               "Bad register offset");
120 static_assert(offsetof(marl_fiber_context, r28) == MARL_REG_r28,
121               "Bad register offset");
122 static_assert(offsetof(marl_fiber_context, r29) == MARL_REG_r29,
123               "Bad register offset");
124 static_assert(offsetof(marl_fiber_context, v8) == MARL_REG_v8,
125               "Bad register offset");
126 static_assert(offsetof(marl_fiber_context, v9) == MARL_REG_v9,
127               "Bad register offset");
128 static_assert(offsetof(marl_fiber_context, v10) == MARL_REG_v10,
129               "Bad register offset");
130 static_assert(offsetof(marl_fiber_context, v11) == MARL_REG_v11,
131               "Bad register offset");
132 static_assert(offsetof(marl_fiber_context, v12) == MARL_REG_v12,
133               "Bad register offset");
134 static_assert(offsetof(marl_fiber_context, v13) == MARL_REG_v13,
135               "Bad register offset");
136 static_assert(offsetof(marl_fiber_context, v14) == MARL_REG_v14,
137               "Bad register offset");
138 static_assert(offsetof(marl_fiber_context, v15) == MARL_REG_v15,
139               "Bad register offset");
140 static_assert(offsetof(marl_fiber_context, SP) == MARL_REG_SP,
141               "Bad register offset");
142 static_assert(offsetof(marl_fiber_context, LR) == MARL_REG_LR,
143               "Bad register offset");
144 #endif  // __cplusplus
145 
146 #endif  // MARL_BUILD_ASM
147