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_EBX 0x00 16 #define MARL_REG_EBP 0x04 17 #define MARL_REG_ESI 0x08 18 #define MARL_REG_EDI 0x0c 19 #define MARL_REG_ESP 0x10 20 #define MARL_REG_EIP 0x14 21 22 #ifndef MARL_BUILD_ASM 23 #include <stdint.h> 24 25 // Assumes cdecl calling convention. 26 // Registers EAX, ECX, and EDX are caller-saved, and the rest are callee-saved. 27 struct marl_fiber_context { 28 // callee-saved registers 29 uintptr_t EBX; 30 uintptr_t EBP; 31 uintptr_t ESI; 32 uintptr_t EDI; 33 34 // stack and instruction registers 35 uintptr_t ESP; 36 uintptr_t EIP; 37 }; 38 39 #ifdef __cplusplus 40 #include <cstddef> 41 static_assert(offsetof(marl_fiber_context, EBX) == MARL_REG_EBX, 42 "Bad register offset"); 43 static_assert(offsetof(marl_fiber_context, EBP) == MARL_REG_EBP, 44 "Bad register offset"); 45 static_assert(offsetof(marl_fiber_context, ESI) == MARL_REG_ESI, 46 "Bad register offset"); 47 static_assert(offsetof(marl_fiber_context, EDI) == MARL_REG_EDI, 48 "Bad register offset"); 49 static_assert(offsetof(marl_fiber_context, ESP) == MARL_REG_ESP, 50 "Bad register offset"); 51 static_assert(offsetof(marl_fiber_context, EIP) == MARL_REG_EIP, 52 "Bad register offset"); 53 #endif // __cplusplus 54 55 #endif // MARL_BUILD_ASM 56