asm.h
1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* -----------------------------------------------------------------------------
* Copyright (C) 2019 daiteq s.r.o. http://www.daiteq.com
*
* This program is distributed WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE.
*
* -----------------------------------------------------------------------------
* Filename : asm.h
* Authors : Martin Danek
* Description : inline assembly routines
* Release :
* Version : 1.0
* Date : 9.4.2019
* -----------------------------------------------------------------------------
*/
#ifndef ASM_H
#define ASM_H
#define str(s) #s
#define asm_rd_asr(A,R) \
__asm__ volatile ( \
"\t rd " str(A) ", %0\n" \
: "=r" (R) \
) \
#define asm_wr_asr(A,O) \
__asm__ volatile ( \
"\t nop\n" \
"\t wr %0, 0, " str(A) " \n" \
"\t nop\n" \
: \
: "r" (O) \
) \
\
#define asm_swar(A, B, RES) \
__asm__ volatile ( \
"\t swar %1, %2, %0 \n" \
: "=r" (RES) \
: "Ir" (A), "Ir" (B) \
) \
\
#define asm_swarcc(A, B, RES) \
__asm__ volatile ( \
"\t swarcc %1, %2, %0 \n" \
: "=r" (RES) \
: "Ir" (A), "Ir" (B) \
: "cc" \
) \
\
#endif