1 /*
2  * Copyright (c) 2015 Stefan Kristiansson
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 #include <arch/or1k-sprs.h>
11 
12 #define mtspr(_spr, _val)                       \
13     __asm__ __volatile__(                       \
14         "l.mtspr r0, %1, %0"                    \
15         :                                       \
16         : "K" (_spr), "r" (_val)                \
17     )
18 
19 #define mtspr_off(_spr, _off, _val)             \
20     __asm__ __volatile__ (                      \
21         "l.mtspr %0, %1, %2"                    \
22         :                                       \
23         : "r" (_off), "r" (_val), "K" (_spr)    \
24     )
25 
26 #define mfspr(_spr)                             \
27 ({                                              \
28     uint32_t _val;                              \
29     __asm__ __volatile__(                       \
30         "l.mfspr %0, r0, %1"                    \
31         : "=r"(_val)                            \
32         : "K" (_spr)                            \
33         );                                      \
34     _val;                                       \
35 })
36 
37 #define mfspr_off(_spr, _off)                   \
38 ({                                              \
39     uint32_t _val;                              \
40     __asm__ __volatile__ (                      \
41         "l.mfspr %0, %1, %2"                    \
42         : "=r" (_val)                           \
43         : "r" (_off), "K" (_spr)                \
44         );                                      \
45     _val;                                       \
46 })
47 
48 #ifndef ASSEMBLY
49 struct or1k_iframe {
50     uint32_t r2;
51     uint32_t r3;
52     uint32_t r4;
53     uint32_t r5;
54     uint32_t r6;
55     uint32_t r7;
56     uint32_t r8;
57     uint32_t r9;
58     uint32_t r10;
59     uint32_t r11;
60     uint32_t r12;
61     uint32_t r13;
62     uint32_t r14;
63     uint32_t r15;
64     uint32_t r16;
65     uint32_t r17;
66     uint32_t r18;
67     uint32_t r19;
68     uint32_t r20;
69     uint32_t r21;
70     uint32_t r22;
71     uint32_t r23;
72     uint32_t r24;
73     uint32_t r25;
74     uint32_t r26;
75     uint32_t r27;
76     uint32_t r28;
77     uint32_t r29;
78     uint32_t r30;
79     uint32_t r31;
80     uint32_t pc;
81     uint32_t sr;
82 };
83 #endif // !ASSEMBLY
84