• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 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_s8 0x50
26 #define MARL_REG_fs0 0x58
27 #define MARL_REG_fs1 0x60
28 #define MARL_REG_fs2 0x68
29 #define MARL_REG_fs3 0x70
30 #define MARL_REG_fs4 0x78
31 #define MARL_REG_fs5 0x80
32 #define MARL_REG_fs6 0x88
33 #define MARL_REG_fs7 0x90
34 #define MARL_REG_ra 0x98
35 #define MARL_REG_sp 0xa0
36 #define MARL_REG_fp 0xa8
37 
38 #ifndef MARL_BUILD_ASM
39 
40 #include <stdint.h>
41 
42 // Procedure Call Standard for the LoongArch 64-bit Architecture
43 // https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html
44 struct marl_fiber_context {
45   // parameter registers (First two)
46   uintptr_t a0;
47   uintptr_t a1;
48 
49   // callee-saved registers
50   uintptr_t s0;
51   uintptr_t s1;
52   uintptr_t s2;
53   uintptr_t s3;
54   uintptr_t s4;
55   uintptr_t s5;
56   uintptr_t s6;
57   uintptr_t s7;
58   uintptr_t s8;
59 
60   uintptr_t fs0;
61   uintptr_t fs1;
62   uintptr_t fs2;
63   uintptr_t fs3;
64   uintptr_t fs4;
65   uintptr_t fs5;
66   uintptr_t fs6;
67   uintptr_t fs7;
68 
69   uintptr_t ra;
70   uintptr_t sp;
71   uintptr_t fp;
72 };
73 
74 #ifdef __cplusplus
75 #include <cstddef>
76 static_assert(offsetof(marl_fiber_context, a0) == MARL_REG_a0,
77               "Bad register offset");
78 static_assert(offsetof(marl_fiber_context, a1) == MARL_REG_a1,
79               "Bad register offset");
80 static_assert(offsetof(marl_fiber_context, s0) == MARL_REG_s0,
81               "Bad register offset");
82 static_assert(offsetof(marl_fiber_context, s1) == MARL_REG_s1,
83               "Bad register offset");
84 static_assert(offsetof(marl_fiber_context, s2) == MARL_REG_s2,
85               "Bad register offset");
86 static_assert(offsetof(marl_fiber_context, s3) == MARL_REG_s3,
87               "Bad register offset");
88 static_assert(offsetof(marl_fiber_context, s4) == MARL_REG_s4,
89               "Bad register offset");
90 static_assert(offsetof(marl_fiber_context, s5) == MARL_REG_s5,
91               "Bad register offset");
92 static_assert(offsetof(marl_fiber_context, s6) == MARL_REG_s6,
93               "Bad register offset");
94 static_assert(offsetof(marl_fiber_context, s7) == MARL_REG_s7,
95               "Bad register offset");
96 static_assert(offsetof(marl_fiber_context, s8) == MARL_REG_s8,
97               "Bad register offset");
98 static_assert(offsetof(marl_fiber_context, fs0) == MARL_REG_fs0,
99               "Bad register offset");
100 static_assert(offsetof(marl_fiber_context, fs1) == MARL_REG_fs1,
101               "Bad register offset");
102 static_assert(offsetof(marl_fiber_context, fs2) == MARL_REG_fs2,
103               "Bad register offset");
104 static_assert(offsetof(marl_fiber_context, fs3) == MARL_REG_fs3,
105               "Bad register offset");
106 static_assert(offsetof(marl_fiber_context, fs4) == MARL_REG_fs4,
107               "Bad register offset");
108 static_assert(offsetof(marl_fiber_context, fs5) == MARL_REG_fs5,
109               "Bad register offset");
110 static_assert(offsetof(marl_fiber_context, fs6) == MARL_REG_fs6,
111               "Bad register offset");
112 static_assert(offsetof(marl_fiber_context, fs7) == MARL_REG_fs7,
113               "Bad register offset");
114 static_assert(offsetof(marl_fiber_context, ra) == MARL_REG_ra,
115               "Bad register offset");
116 static_assert(offsetof(marl_fiber_context, sp) == MARL_REG_sp,
117               "Bad register offset");
118 static_assert(offsetof(marl_fiber_context, fp) == MARL_REG_fp,
119               "Bad register offset");
120 #endif // __cplusplus
121 
122 #endif // MARL_BUILD_ASM
123