1 /** 2 * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 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 * http://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 16 #ifndef PANDA_RUNTIME_FIBERS_ARCH_ARM_CONTEXT_LAYOUT_H 17 #define PANDA_RUNTIME_FIBERS_ARCH_ARM_CONTEXT_LAYOUT_H 18 19 // NOLINTBEGIN(cppcoreguidelines-macro-usage) 20 21 /** 22 * Memory layout of the saved context: 23 * 24 * GPRs: 9 x 4 = 36 bytes (r0, r4-r11) 25 * Special registers: 4 x 4 = 16 bytes (r12-r15) 26 * if PANDA_TARGET_ARM32_ABI_SOFT: 27 * == TOTAL: 52 bytes == 28 * 29 * else: 30 * FP status and control: 4 bytes (FPSCR) 31 * FP regs: 8 x 8 = 64 bytes (D8-D15) 32 * == TOTAL: 120 bytes == 33 * 34 * OFFSET HEX | OFFSET DEC | SIZE | CONTENTS 35 * ----------------------------------------- 36 * 0x0 | 0 | 4 | R0 37 * 0x4 | 4 | 4 | R4 38 * 0x8 | 8 | 4 | R5 39 * 0xc | 12 | 4 | R6 40 * 0x10 | 16 | 4 | R7 41 * 0x14 | 20 | 4 | R8 42 * 0x18 | 24 | 4 | R9 43 * 0x1c | 28 | 4 | R10 44 * 0x20 | 32 | 4 | R11 (FP) 45 * 0x24 | 36 | 4 | R12 (IP) 46 * 0x28 | 40 | 4 | R13 (SP) 47 * 0x2c | 44 | 4 | R14 (LR) 48 * 0x30 | 48 | 4 | R15 (PC) 49 * ----------------------------------------- 50 * 0x34 | 52 | 4 | FPSCR 51 * 0x38 | 56 | 8 | D8 52 * 0x40 | 64 | 8 | D9 53 * 0x48 | 72 | 8 | D10 54 * 0x50 | 80 | 8 | D11 55 * 0x58 | 88 | 8 | D12 56 * 0x60 | 96 | 8 | D13 57 * 0x68 | 104 | 8 | D14 58 * 0x70 | 112 | 8 | D15 59 * 60 * according to the SYSV ABI (AAPCS): 61 * (saving) 62 * CALLEE-SAVED: r4-r11, d8-d15 63 * SPECIAL: IP(r12), SP(r13), LR(r14), PC(r15) 64 * SYSTEM FP: FPSCR 65 * ARG: r0 (so we are able to set r0 for the target func with UpdateContext()) 66 * 67 * (skipping, because we emulate function call by the context switch) 68 * ARGS/SCRATCH: r0-r3 69 */ 70 71 #ifndef PANDA_TARGET_ARM32_ABI_SOFT 72 #define FCTX_LEN_BYTES 120 73 #else 74 #define FCTX_LEN_BYTES 52 75 #endif 76 77 // gpr 78 #define FCTX_GPR_OFFSET_BYTES 0 79 #define FCTX_GPR_SIZE_BYTES 4 80 #define FCTX_GPR_OFFSET_BYTES_BY_INDEX(i) (FCTX_GPR_OFFSET_BYTES + FCTX_GPR_SIZE_BYTES * (i)) 81 #define FCTX_GPR_OFFSET_BYTES_R0 FCTX_GPR_OFFSET_BYTES_BY_INDEX(0) 82 #define FCTX_GPR_OFFSET_BYTES_R4 FCTX_GPR_OFFSET_BYTES_BY_INDEX(1) 83 #define FCTX_GPR_OFFSET_BYTES_R5 FCTX_GPR_OFFSET_BYTES_BY_INDEX(2) 84 #define FCTX_GPR_OFFSET_BYTES_R6 FCTX_GPR_OFFSET_BYTES_BY_INDEX(3) 85 #define FCTX_GPR_OFFSET_BYTES_R7 FCTX_GPR_OFFSET_BYTES_BY_INDEX(4) 86 #define FCTX_GPR_OFFSET_BYTES_R8 FCTX_GPR_OFFSET_BYTES_BY_INDEX(5) 87 #define FCTX_GPR_OFFSET_BYTES_R9 FCTX_GPR_OFFSET_BYTES_BY_INDEX(6) 88 #define FCTX_GPR_OFFSET_BYTES_R10 FCTX_GPR_OFFSET_BYTES_BY_INDEX(7) 89 #define FCTX_GPR_OFFSET_BYTES_R11 FCTX_GPR_OFFSET_BYTES_BY_INDEX(8) 90 #define FCTX_GPR_OFFSET_BYTES_R12 FCTX_GPR_OFFSET_BYTES_BY_INDEX(9) 91 #define FCTX_GPR_OFFSET_BYTES_SP FCTX_GPR_OFFSET_BYTES_BY_INDEX(10) 92 #define FCTX_GPR_OFFSET_BYTES_LR FCTX_GPR_OFFSET_BYTES_BY_INDEX(11) 93 #define FCTX_GPR_OFFSET_BYTES_PC FCTX_GPR_OFFSET_BYTES_BY_INDEX(12) 94 // fp 95 #define FCTX_FP_OFFSET_BYTES_FPSCR 52 96 #define FCTX_FP_OFFSET_BYTES 56 97 #define FCTX_FP_SIZE_BYTES 8 98 #define FCTX_FP_OFFSET_BYTES_BY_INDEX(i) (FCTX_FP_OFFSET_BYTES + FCTX_FP_SIZE_BYTES * (i)) 99 #define FCTX_FP_OFFSET_BYTES_D8 FCTX_FP_OFFSET_BYTES_BY_INDEX(0) 100 #define FCTX_FP_OFFSET_BYTES_D9 FCTX_FP_OFFSET_BYTES_BY_INDEX(1) 101 #define FCTX_FP_OFFSET_BYTES_D10 FCTX_FP_OFFSET_BYTES_BY_INDEX(2) 102 #define FCTX_FP_OFFSET_BYTES_D11 FCTX_FP_OFFSET_BYTES_BY_INDEX(3) 103 #define FCTX_FP_OFFSET_BYTES_D12 FCTX_FP_OFFSET_BYTES_BY_INDEX(4) 104 #define FCTX_FP_OFFSET_BYTES_D13 FCTX_FP_OFFSET_BYTES_BY_INDEX(5) 105 #define FCTX_FP_OFFSET_BYTES_D14 FCTX_FP_OFFSET_BYTES_BY_INDEX(6) 106 #define FCTX_FP_OFFSET_BYTES_D15 FCTX_FP_OFFSET_BYTES_BY_INDEX(7) 107 108 // NOLINTEND(cppcoreguidelines-macro-usage) 109 110 #endif /* PANDA_RUNTIME_FIBERS_ARCH_ARM_CONTEXT_LAYOUT_H */