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_RBX 0x00 |
16 | #define MARL_REG_RBP 0x08 |
17 | #define MARL_REG_R12 0x10 |
18 | #define MARL_REG_R13 0x18 |
19 | #define MARL_REG_R14 0x20 |
20 | #define MARL_REG_R15 0x28 |
21 | #define MARL_REG_RDI 0x30 |
22 | #define MARL_REG_RSI 0x38 |
23 | #define MARL_REG_RSP 0x40 |
24 | #define MARL_REG_RIP 0x48 |
25 | |
26 | #if defined(__APPLE__) |
27 | #define MARL_ASM_SYMBOL(x) _##x |
28 | #else |
29 | #define MARL_ASM_SYMBOL(x) x |
30 | #endif |
31 | |
32 | #ifndef MARL_BUILD_ASM |
33 | |
34 | #include <stdint.h> |
35 | |
36 | struct marl_fiber_context { |
37 | // callee-saved registers |
38 | uintptr_t RBX; |
39 | uintptr_t RBP; |
40 | uintptr_t R12; |
41 | uintptr_t R13; |
42 | uintptr_t R14; |
43 | uintptr_t R15; |
44 | |
45 | // parameter registers |
46 | uintptr_t RDI; |
47 | uintptr_t RSI; |
48 | |
49 | // stack and instruction registers |
50 | uintptr_t RSP; |
51 | uintptr_t RIP; |
52 | }; |
53 | |
54 | #ifdef __cplusplus |
55 | #include <cstddef> |
56 | static_assert(offsetof(marl_fiber_context, RBX) == MARL_REG_RBX, |
57 | "Bad register offset" ); |
58 | static_assert(offsetof(marl_fiber_context, RBP) == MARL_REG_RBP, |
59 | "Bad register offset" ); |
60 | static_assert(offsetof(marl_fiber_context, R12) == MARL_REG_R12, |
61 | "Bad register offset" ); |
62 | static_assert(offsetof(marl_fiber_context, R13) == MARL_REG_R13, |
63 | "Bad register offset" ); |
64 | static_assert(offsetof(marl_fiber_context, R14) == MARL_REG_R14, |
65 | "Bad register offset" ); |
66 | static_assert(offsetof(marl_fiber_context, R15) == MARL_REG_R15, |
67 | "Bad register offset" ); |
68 | static_assert(offsetof(marl_fiber_context, RDI) == MARL_REG_RDI, |
69 | "Bad register offset" ); |
70 | static_assert(offsetof(marl_fiber_context, RSI) == MARL_REG_RSI, |
71 | "Bad register offset" ); |
72 | static_assert(offsetof(marl_fiber_context, RSP) == MARL_REG_RSP, |
73 | "Bad register offset" ); |
74 | static_assert(offsetof(marl_fiber_context, RIP) == MARL_REG_RIP, |
75 | "Bad register offset" ); |
76 | #endif // __cplusplus |
77 | |
78 | #endif // MARL_BUILD_ASM |
79 | |