• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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 
16 #define MARL_REG_a0 0x00
17 #define MARL_REG_a1 0x08
18 #define MARL_REG_s0 0x10
19 #define MARL_REG_s1 0x18
20 #define MARL_REG_s2 0x20
21 #define MARL_REG_s3 0x28
22 #define MARL_REG_s4 0x30
23 #define MARL_REG_s5 0x38
24 #define MARL_REG_s6 0x40
25 #define MARL_REG_s7 0x48
26 #define MARL_REG_s8 0x50
27 #define MARL_REG_s9 0x58
28 #define MARL_REG_s10 0x60
29 #define MARL_REG_s11 0x68
30 #define MARL_REG_fs0 0x70
31 #define MARL_REG_fs1 0x78
32 #define MARL_REG_fs2 0x80
33 #define MARL_REG_fs3 0x88
34 #define MARL_REG_fs4 0x90
35 #define MARL_REG_fs5 0x98
36 #define MARL_REG_fs6 0xa0
37 #define MARL_REG_fs7 0xa8
38 #define MARL_REG_fs8 0xb0
39 #define MARL_REG_fs9 0xb8
40 #define MARL_REG_fs10 0xc0
41 #define MARL_REG_fs11 0xc8
42 #define MARL_REG_sp 0xd0
43 #define MARL_REG_ra 0xd8
44 
45 #ifndef MARL_BUILD_ASM
46 
47 #include <stdint.h>
48 
49 struct marl_fiber_context {
50   // parameter registers (First two)
51   uintptr_t a0;
52   uintptr_t a1;
53 
54   // callee-saved registers
55   uintptr_t s0;
56   uintptr_t s1;
57   uintptr_t s2;
58   uintptr_t s3;
59   uintptr_t s4;
60   uintptr_t s5;
61   uintptr_t s6;
62   uintptr_t s7;
63   uintptr_t s8;
64   uintptr_t s9;
65   uintptr_t s10;
66   uintptr_t s11;
67 
68   uintptr_t fs0;
69   uintptr_t fs1;
70   uintptr_t fs2;
71   uintptr_t fs3;
72   uintptr_t fs4;
73   uintptr_t fs5;
74   uintptr_t fs6;
75   uintptr_t fs7;
76   uintptr_t fs8;
77   uintptr_t fs9;
78   uintptr_t fs10;
79   uintptr_t fs11;
80 
81   uintptr_t sp;
82   uintptr_t ra;
83 };
84 
85 #ifdef __cplusplus
86 #include <cstddef>
87 static_assert(offsetof(marl_fiber_context, a0) == MARL_REG_a0,
88               "Bad register offset");
89 static_assert(offsetof(marl_fiber_context, a1) == MARL_REG_a1,
90               "Bad register offset");
91 static_assert(offsetof(marl_fiber_context, s0) == MARL_REG_s0,
92               "Bad register offset");
93 static_assert(offsetof(marl_fiber_context, s1) == MARL_REG_s1,
94               "Bad register offset");
95 static_assert(offsetof(marl_fiber_context, s2) == MARL_REG_s2,
96               "Bad register offset");
97 static_assert(offsetof(marl_fiber_context, s3) == MARL_REG_s3,
98               "Bad register offset");
99 static_assert(offsetof(marl_fiber_context, s4) == MARL_REG_s4,
100               "Bad register offset");
101 static_assert(offsetof(marl_fiber_context, s5) == MARL_REG_s5,
102               "Bad register offset");
103 static_assert(offsetof(marl_fiber_context, s6) == MARL_REG_s6,
104               "Bad register offset");
105 static_assert(offsetof(marl_fiber_context, s7) == MARL_REG_s7,
106               "Bad register offset");
107 static_assert(offsetof(marl_fiber_context, s8) == MARL_REG_s8,
108               "Bad register offset");
109 static_assert(offsetof(marl_fiber_context, s9) == MARL_REG_s9,
110               "Bad register offset");
111 static_assert(offsetof(marl_fiber_context, s10) == MARL_REG_s10,
112               "Bad register offset");
113 static_assert(offsetof(marl_fiber_context, s11) == MARL_REG_s11,
114               "Bad register offset");
115 static_assert(offsetof(marl_fiber_context, fs0) == MARL_REG_fs0,
116               "Bad register offset");
117 static_assert(offsetof(marl_fiber_context, fs1) == MARL_REG_fs1,
118               "Bad register offset");
119 static_assert(offsetof(marl_fiber_context, fs2) == MARL_REG_fs2,
120               "Bad register offset");
121 static_assert(offsetof(marl_fiber_context, fs3) == MARL_REG_fs3,
122               "Bad register offset");
123 static_assert(offsetof(marl_fiber_context, fs4) == MARL_REG_fs4,
124               "Bad register offset");
125 static_assert(offsetof(marl_fiber_context, fs5) == MARL_REG_fs5,
126               "Bad register offset");
127 static_assert(offsetof(marl_fiber_context, fs6) == MARL_REG_fs6,
128               "Bad register offset");
129 static_assert(offsetof(marl_fiber_context, fs7) == MARL_REG_fs7,
130               "Bad register offset");
131 static_assert(offsetof(marl_fiber_context, fs8) == MARL_REG_fs8,
132               "Bad register offset");
133 static_assert(offsetof(marl_fiber_context, fs9) == MARL_REG_fs9,
134               "Bad register offset");
135 static_assert(offsetof(marl_fiber_context, fs10) == MARL_REG_fs10,
136               "Bad register offset");
137 static_assert(offsetof(marl_fiber_context, fs11) == MARL_REG_fs11,
138               "Bad register offset");
139 static_assert(offsetof(marl_fiber_context, sp) == MARL_REG_sp,
140               "Bad register offset");
141 static_assert(offsetof(marl_fiber_context, ra) == MARL_REG_ra,
142               "Bad register offset");
143 #endif  // __cplusplus
144 
145 #endif  // MARL_BUILD_ASM
146