gcc SVC 寫法
gcc SVC 寫法
SVC_M_N
M 代表參數個數
N 代表 return :
0 : 沒有 return,
1 : 有 return
---
#define SVC_ArgN(n) \
register int __r##n __asm("r"#n);
#define SVC_ArgR(n,t,a) \
register t __r##n __asm("r"#n) = a;
#define SVC_Arg0() \
SVC_ArgN(0) \
SVC_ArgN(1) \
SVC_ArgN(2) \
SVC_ArgN(3)
#define SVC_Arg1(t1) \
SVC_ArgR(0,t1,a1) \
SVC_ArgN(1) \
SVC_ArgN(2) \
SVC_ArgN(3)
#define SVC_Arg2(t1,t2) \
SVC_ArgR(0,t1,a1) \
SVC_ArgR(1,t2,a2) \
SVC_ArgN(2) \
SVC_ArgN(3)
#define SVC_Arg3(t1,t2,t3) \
SVC_ArgR(0,t1,a1) \
SVC_ArgR(1,t2,a2) \
SVC_ArgR(2,t3,a3) \
SVC_ArgN(3)
#define SVC_Arg4(t1,t2,t3,t4) \
SVC_ArgR(0,t1,a1) \
SVC_ArgR(1,t2,a2) \
SVC_ArgR(2,t3,a3) \
SVC_ArgR(3,t4,a4)
#if (defined (__CORTEX_M0))
#define SVC_Call(f) \
__asm volatile \
( \
"ldr r7,="#f"\n\t" \
"mov r12,r7\n\t" \
"svc 0" \
: "=r" (__r0), "=r" (__r1), "=r" (__r2), "=r" (__r3) \
: "r" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) \
: "r7", "r12", "lr", "cc" \
);
#else
#define SVC_Call(f) \
__asm volatile \
( \
"ldr r12,="#f"\n\t" \
"svc 0" \
: "=r" (__r0), "=r" (__r1), "=r" (__r2), "=r" (__r3) \
: "r" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) \
: "r12", "lr", "cc" \
);
#endif
#define SVC_0_1(f,t,rv) \
__attribute__((always_inline)) \
static inline t __##f (void) { \
SVC_Arg0(); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_1_0(f,t,t1) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1) { \
SVC_Arg1(t1); \
SVC_Call(f); \
}
#define SVC_1_1(f,t,t1,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1) { \
SVC_Arg1(t1); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_2_1(f,t,t1,t2,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1, t2 a2) { \
SVC_Arg2(t1,t2); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_3_1(f,t,t1,t2,t3,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1, t2 a2, t3 a3) { \
SVC_Arg3(t1,t2,t3); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_4_1(f,t,t1,t2,t3,t4,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1, t2 a2, t3 a3, t4 a4) { \
SVC_Arg4(t1,t2,t3,t4); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_1_2 SVC_1_1
#define SVC_1_3 SVC_1_1
#define SVC_2_3 SVC_2_1
SVC_M_N
M 代表參數個數
N 代表 return :
0 : 沒有 return,
1 : 有 return
---
#define SVC_ArgN(n) \
register int __r##n __asm("r"#n);
#define SVC_ArgR(n,t,a) \
register t __r##n __asm("r"#n) = a;
#define SVC_Arg0() \
SVC_ArgN(0) \
SVC_ArgN(1) \
SVC_ArgN(2) \
SVC_ArgN(3)
#define SVC_Arg1(t1) \
SVC_ArgR(0,t1,a1) \
SVC_ArgN(1) \
SVC_ArgN(2) \
SVC_ArgN(3)
#define SVC_Arg2(t1,t2) \
SVC_ArgR(0,t1,a1) \
SVC_ArgR(1,t2,a2) \
SVC_ArgN(2) \
SVC_ArgN(3)
#define SVC_Arg3(t1,t2,t3) \
SVC_ArgR(0,t1,a1) \
SVC_ArgR(1,t2,a2) \
SVC_ArgR(2,t3,a3) \
SVC_ArgN(3)
#define SVC_Arg4(t1,t2,t3,t4) \
SVC_ArgR(0,t1,a1) \
SVC_ArgR(1,t2,a2) \
SVC_ArgR(2,t3,a3) \
SVC_ArgR(3,t4,a4)
#if (defined (__CORTEX_M0))
#define SVC_Call(f) \
__asm volatile \
( \
"ldr r7,="#f"\n\t" \
"mov r12,r7\n\t" \
"svc 0" \
: "=r" (__r0), "=r" (__r1), "=r" (__r2), "=r" (__r3) \
: "r" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) \
: "r7", "r12", "lr", "cc" \
);
#else
#define SVC_Call(f) \
__asm volatile \
( \
"ldr r12,="#f"\n\t" \
"svc 0" \
: "=r" (__r0), "=r" (__r1), "=r" (__r2), "=r" (__r3) \
: "r" (__r0), "r" (__r1), "r" (__r2), "r" (__r3) \
: "r12", "lr", "cc" \
);
#endif
#define SVC_0_1(f,t,rv) \
__attribute__((always_inline)) \
static inline t __##f (void) { \
SVC_Arg0(); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_1_0(f,t,t1) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1) { \
SVC_Arg1(t1); \
SVC_Call(f); \
}
#define SVC_1_1(f,t,t1,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1) { \
SVC_Arg1(t1); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_2_1(f,t,t1,t2,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1, t2 a2) { \
SVC_Arg2(t1,t2); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_3_1(f,t,t1,t2,t3,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1, t2 a2, t3 a3) { \
SVC_Arg3(t1,t2,t3); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_4_1(f,t,t1,t2,t3,t4,rv) \
__attribute__((always_inline)) \
static inline t __##f (t1 a1, t2 a2, t3 a3, t4 a4) { \
SVC_Arg4(t1,t2,t3,t4); \
SVC_Call(f); \
return (t) rv; \
}
#define SVC_1_2 SVC_1_1
#define SVC_1_3 SVC_1_1
#define SVC_2_3 SVC_2_1
---
留言
張貼留言