1 /*
2  * Copyright (c) 2021 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #define RISCV_IFRAME_EPC    (0 * __riscv_xlen / 8)
11 #define RISCV_IFRAME_STATUS (1 * __riscv_xlen / 8)
12 #define RISCV_IFRAME_RA     (2 * __riscv_xlen / 8)
13 #define RISCV_IFRAME_A_BASE (3 * __riscv_xlen / 8)
14 #define RISCV_IFRAME_A(n)   (RISCV_IFRAME_A_BASE + (n) * __riscv_xlen / 8)
15 #define RISCV_IFRAME_T_BASE (11 * __riscv_xlen / 8)
16 #define RISCV_IFRAME_T(n)   (RISCV_IFRAME_T_BASE + (n) * __riscv_xlen / 8)
17 #define RISCV_IFRAME_TP     (18 * __riscv_xlen / 8)
18 #define RISCV_IFRAME_GP     (19 * __riscv_xlen / 8)
19 #define RISCV_IFRAME_SP     (20 * __riscv_xlen / 8)
20 
21 #define RISCV_IFRAME_LEN    (24 * __riscv_xlen / 8)
22 
23 #ifndef ASSEMBLY
24 
25 #include <lk/compiler.h>
26 #include <assert.h>
27 
28 // keep in sync with asm.S
29 struct riscv_short_iframe {
30     unsigned long  epc;
31     unsigned long  status;
32     unsigned long  ra;
33     unsigned long  a0;
34     unsigned long  a1;
35     unsigned long  a2;
36     unsigned long  a3;
37     unsigned long  a4;
38     unsigned long  a5;
39     unsigned long  a6;
40     unsigned long  a7;
41     unsigned long  t0;
42     unsigned long  t1;
43     unsigned long  t2;
44     unsigned long  t3;
45     unsigned long  t4;
46     unsigned long  t5;
47     unsigned long  t6;
48     // if we came from user space these are valid
49     unsigned long  tp;
50     unsigned long  gp;
51     unsigned long  sp;
52     unsigned long  pad[3]; // always maintain a padding of a multiple of 16 bytes
53 };
54 
55 static_assert(sizeof(struct riscv_short_iframe) % 16 == 0, "");
56 static_assert(sizeof(struct riscv_short_iframe) == RISCV_IFRAME_LEN, "");
57 
58 static_assert(offsetof(struct riscv_short_iframe, epc) == RISCV_IFRAME_EPC, "");
59 static_assert(offsetof(struct riscv_short_iframe, status) == RISCV_IFRAME_STATUS, "");
60 static_assert(offsetof(struct riscv_short_iframe, ra) == RISCV_IFRAME_RA, "");
61 static_assert(offsetof(struct riscv_short_iframe, a0) == RISCV_IFRAME_A_BASE, "");
62 static_assert(offsetof(struct riscv_short_iframe, t0) == RISCV_IFRAME_T_BASE, "");
63 static_assert(offsetof(struct riscv_short_iframe, gp) == RISCV_IFRAME_GP, "");
64 static_assert(offsetof(struct riscv_short_iframe, sp) == RISCV_IFRAME_SP, "");
65 
66 #endif // __ASSEMBLY__
67 
68