1 // Copyright 2020 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_a0 0x00 16 #define MARL_REG_a1 0x08 17 #define MARL_REG_s0 0x10 18 #define MARL_REG_s1 0x18 19 #define MARL_REG_s2 0x20 20 #define MARL_REG_s3 0x28 21 #define MARL_REG_s4 0x30 22 #define MARL_REG_s5 0x38 23 #define MARL_REG_s6 0x40 24 #define MARL_REG_s7 0x48 25 #define MARL_REG_f24 0x50 26 #define MARL_REG_f25 0x58 27 #define MARL_REG_f26 0x60 28 #define MARL_REG_f27 0x68 29 #define MARL_REG_f28 0x70 30 #define MARL_REG_f29 0x78 31 #define MARL_REG_f30 0x80 32 #define MARL_REG_f31 0x88 33 #define MARL_REG_gp 0x90 34 #define MARL_REG_sp 0x98 35 #define MARL_REG_fp 0xa0 36 #define MARL_REG_ra 0xa8 37 38 #if defined(__APPLE__) 39 #define MARL_ASM_SYMBOL(x) _##x 40 #else 41 #define MARL_ASM_SYMBOL(x) x 42 #endif 43 44 #ifndef MARL_BUILD_ASM 45 46 #include <stdint.h> 47 48 struct marl_fiber_context { 49 // parameter registers (First two) 50 uintptr_t a0; 51 uintptr_t a1; 52 53 // callee-saved registers 54 uintptr_t s0; 55 uintptr_t s1; 56 uintptr_t s2; 57 uintptr_t s3; 58 uintptr_t s4; 59 uintptr_t s5; 60 uintptr_t s6; 61 uintptr_t s7; 62 63 uintptr_t f24; 64 uintptr_t f25; 65 uintptr_t f26; 66 uintptr_t f27; 67 uintptr_t f28; 68 uintptr_t f29; 69 uintptr_t f30; 70 uintptr_t f31; 71 72 uintptr_t gp; 73 uintptr_t sp; 74 uintptr_t fp; 75 uintptr_t ra; 76 }; 77 78 #ifdef __cplusplus 79 #include <cstddef> 80 static_assert(offsetof(marl_fiber_context, a0) == MARL_REG_a0, 81 "Bad register offset"); 82 static_assert(offsetof(marl_fiber_context, a1) == MARL_REG_a1, 83 "Bad register offset"); 84 static_assert(offsetof(marl_fiber_context, s0) == MARL_REG_s0, 85 "Bad register offset"); 86 static_assert(offsetof(marl_fiber_context, s1) == MARL_REG_s1, 87 "Bad register offset"); 88 static_assert(offsetof(marl_fiber_context, s2) == MARL_REG_s2, 89 "Bad register offset"); 90 static_assert(offsetof(marl_fiber_context, s3) == MARL_REG_s3, 91 "Bad register offset"); 92 static_assert(offsetof(marl_fiber_context, s4) == MARL_REG_s4, 93 "Bad register offset"); 94 static_assert(offsetof(marl_fiber_context, s5) == MARL_REG_s5, 95 "Bad register offset"); 96 static_assert(offsetof(marl_fiber_context, s6) == MARL_REG_s6, 97 "Bad register offset"); 98 static_assert(offsetof(marl_fiber_context, s7) == MARL_REG_s7, 99 "Bad register offset"); 100 static_assert(offsetof(marl_fiber_context, f24) == MARL_REG_f24, 101 "Bad register offset"); 102 static_assert(offsetof(marl_fiber_context, f25) == MARL_REG_f25, 103 "Bad register offset"); 104 static_assert(offsetof(marl_fiber_context, f26) == MARL_REG_f26, 105 "Bad register offset"); 106 static_assert(offsetof(marl_fiber_context, f27) == MARL_REG_f27, 107 "Bad register offset"); 108 static_assert(offsetof(marl_fiber_context, f28) == MARL_REG_f28, 109 "Bad register offset"); 110 static_assert(offsetof(marl_fiber_context, f29) == MARL_REG_f29, 111 "Bad register offset"); 112 static_assert(offsetof(marl_fiber_context, f30) == MARL_REG_f30, 113 "Bad register offset"); 114 static_assert(offsetof(marl_fiber_context, f31) == MARL_REG_f31, 115 "Bad register offset"); 116 static_assert(offsetof(marl_fiber_context, gp) == MARL_REG_gp, 117 "Bad register offset"); 118 static_assert(offsetof(marl_fiber_context, sp) == MARL_REG_sp, 119 "Bad register offset"); 120 static_assert(offsetof(marl_fiber_context, fp) == MARL_REG_fp, 121 "Bad register offset"); 122 static_assert(offsetof(marl_fiber_context, ra) == MARL_REG_ra, 123 "Bad register offset"); 124 #endif // __cplusplus 125 126 #endif // MARL_BUILD_ASM 127