• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_AARCH64_CONTEXT_LAYOUT_H
17 #define PANDA_RUNTIME_FIBERS_ARCH_AARCH64_CONTEXT_LAYOUT_H
18 
19 // NOLINTBEGIN(cppcoreguidelines-macro-usage)
20 
21 /**
22  * Memory layout of the saved context:
23  *
24  * GPRs: 14 x 8 = 112 bytes (r0, r18-r30)
25  * Special GPRs: 2 x 8 = 16 bytes (PC, SP)
26  * FP status: 4 bytes (FPSR, low 32 bits)
27  * FP control: 4 bytes (FPCR, low 32 bits)
28  * FP regs: 8 x 16 = 128 bytes (Q8-Q15)
29  * == TOTAL: 264 bytes ==
30  *
31  * OFFSET HEX | OFFSET DEC | SIZE | CONTENTS
32  * -----------------------------------------
33  * 0x0        | 0          | 8    | R18
34  * 0x8        | 8          | 8    | R19
35  * 0x10       | 16         | 8    | R20
36  * 0x18       | 24         | 8    | R21
37  * 0x20       | 32         | 8    | R22
38  * 0x28       | 40         | 8    | R23
39  * 0x30       | 48         | 8    | R24
40  * 0x38       | 56         | 8    | R25
41  * 0x40       | 64         | 8    | R26
42  * 0x48       | 72         | 8    | R27
43  * 0x50       | 80         | 8    | R28
44  * 0x58       | 88         | 8    | R29 (FP)
45  * 0x60       | 96         | 8    | R30 (LR)
46  * 0x68       | 104        | 8    | PC
47  * 0x70       | 112        | 8    | SP
48  * 0x78       | 120        | 4    | FPSR
49  * 0x7c       | 124        | 4    | FPCR
50  * 0x80       | 128        | 16   | Q8
51  * 0x90       | 144        | 16   | Q9
52  * 0xa0       | 160        | 16   | Q10
53  * 0xb0       | 176        | 16   | Q11
54  * 0xc0       | 192        | 16   | Q12
55  * 0xd0       | 208        | 16   | Q13
56  * 0xe0       | 224        | 16   | Q14
57  * 0xf0       | 240        | 16   | Q15
58  * 0x100      | 256        | 8    | R0
59  *
60  * according to the SYSV ABI (AAPCS):
61  * (saving)
62  * CALLEE-SAVED: r19-r28, q8-q15 (we save the 128 bit Q form instead of 64 bit V for simplification)
63  * SPECIAL: FP(r29), LR(r30), PC, SP, platform reg(r18)
64  * SYSTEM FP: FPCR, FPSR
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: r0-r7, v0-v7
69  * TEMPS: r8-r17, v16-v31
70  */
71 
72 #define FCTX_LEN_BYTES 264
73 
74 // gpr
75 #define FCTX_GPR_OFFSET_BYTES 0
76 #define FCTX_GPR_SIZE_BYTES 8
77 #define FCTX_GPR_OFFSET_BYTES_BY_INDEX(i) (FCTX_GPR_OFFSET_BYTES + FCTX_GPR_SIZE_BYTES * (i))
78 #define FCTX_GPR_OFFSET_BYTES_R18 FCTX_GPR_OFFSET_BYTES_BY_INDEX(0)
79 #define FCTX_GPR_OFFSET_BYTES_R19 FCTX_GPR_OFFSET_BYTES_BY_INDEX(1)
80 #define FCTX_GPR_OFFSET_BYTES_R20 FCTX_GPR_OFFSET_BYTES_BY_INDEX(2)
81 #define FCTX_GPR_OFFSET_BYTES_R21 FCTX_GPR_OFFSET_BYTES_BY_INDEX(3)
82 #define FCTX_GPR_OFFSET_BYTES_R22 FCTX_GPR_OFFSET_BYTES_BY_INDEX(4)
83 #define FCTX_GPR_OFFSET_BYTES_R23 FCTX_GPR_OFFSET_BYTES_BY_INDEX(5)
84 #define FCTX_GPR_OFFSET_BYTES_R24 FCTX_GPR_OFFSET_BYTES_BY_INDEX(6)
85 #define FCTX_GPR_OFFSET_BYTES_R25 FCTX_GPR_OFFSET_BYTES_BY_INDEX(7)
86 #define FCTX_GPR_OFFSET_BYTES_R26 FCTX_GPR_OFFSET_BYTES_BY_INDEX(8)
87 #define FCTX_GPR_OFFSET_BYTES_R27 FCTX_GPR_OFFSET_BYTES_BY_INDEX(9)
88 #define FCTX_GPR_OFFSET_BYTES_R28 FCTX_GPR_OFFSET_BYTES_BY_INDEX(10)
89 #define FCTX_GPR_OFFSET_BYTES_FP FCTX_GPR_OFFSET_BYTES_BY_INDEX(11)
90 #define FCTX_GPR_OFFSET_BYTES_LR FCTX_GPR_OFFSET_BYTES_BY_INDEX(12)
91 #define FCTX_GPR_OFFSET_BYTES_PC FCTX_GPR_OFFSET_BYTES_BY_INDEX(13)
92 #define FCTX_GPR_OFFSET_BYTES_SP FCTX_GPR_OFFSET_BYTES_BY_INDEX(14)
93 // fp
94 #define FCTX_FPSR_OFFSET_BYTES 120
95 #define FCTX_FP_OFFSET_BYTES_FPSR FCTX_FPSR_OFFSET_BYTES
96 #define FCTX_FPCR_OFFSET_BYTES 124
97 #define FCTX_FP_OFFSET_BYTES_FPCR FCTX_FPCR_OFFSET_BYTES
98 #define FCTX_FP_OFFSET_BYTES 128
99 #define FCTX_FP_SIZE_BYTES 16
100 #define FCTX_FP_OFFSET_BYTES_BY_INDEX(i) (FCTX_FP_OFFSET_BYTES + FCTX_FP_SIZE_BYTES * (i))
101 #define FCTX_FP_OFFSET_BYTES_Q8 FCTX_FP_OFFSET_BYTES_BY_INDEX(0)
102 #define FCTX_FP_OFFSET_BYTES_Q9 FCTX_FP_OFFSET_BYTES_BY_INDEX(1)
103 #define FCTX_FP_OFFSET_BYTES_Q10 FCTX_FP_OFFSET_BYTES_BY_INDEX(2)
104 #define FCTX_FP_OFFSET_BYTES_Q11 FCTX_FP_OFFSET_BYTES_BY_INDEX(3)
105 #define FCTX_FP_OFFSET_BYTES_Q12 FCTX_FP_OFFSET_BYTES_BY_INDEX(4)
106 #define FCTX_FP_OFFSET_BYTES_Q13 FCTX_FP_OFFSET_BYTES_BY_INDEX(5)
107 #define FCTX_FP_OFFSET_BYTES_Q14 FCTX_FP_OFFSET_BYTES_BY_INDEX(6)
108 #define FCTX_FP_OFFSET_BYTES_Q15 FCTX_FP_OFFSET_BYTES_BY_INDEX(7)
109 // extra: the arg register
110 #define FCTX_GPR_OFFSET_BYTES_R0 256
111 
112 // NOLINTEND(cppcoreguidelines-macro-usage)
113 
114 #endif /* PANDA_RUNTIME_FIBERS_ARCH_AARCH64_CONTEXT_LAYOUT_H */