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
60
61
62
63
64
65
66
67
|
/* Do not directly include this file. Include feather_trace.h instead */
/* regparm is the default on x86_64 */
#define feather_callback
# define _EVENT_TABLE(id,from,to) \
".section __event_table, \"aw\"\n\t" \
".balign 8\n\t" \
".quad " #id ", 0, " #from ", " #to " \n\t" \
".previous \n\t"
/*
* x86_64 callee only owns rbp, rbx, r12 -> r15
* the called can freely modify the others
*/
#define CLOBBER_LIST "memory", "cc", "rdi", "rsi", "rdx", "rcx", \
"r8", "r9", "r10", "r11", "rax"
#define ft_event(id, callback) \
__asm__ __volatile__( \
"1: jmp 2f \n\t" \
" call " #callback " \n\t" \
_EVENT_TABLE(id,1b,2f) \
"2: \n\t" \
: : : CLOBBER_LIST)
#define ft_event0(id, callback) \
__asm__ __volatile__( \
"1: jmp 2f \n\t" \
" movq $" #id ", %%rdi \n\t" \
" call " #callback " \n\t" \
_EVENT_TABLE(id,1b,2f) \
"2: \n\t" \
: : : CLOBBER_LIST)
#define ft_event1(id, callback, param) \
__asm__ __volatile__( \
"1: jmp 2f \n\t" \
" movq %0, %%rsi \n\t" \
" movq $" #id ", %%rdi \n\t" \
" call " #callback " \n\t" \
_EVENT_TABLE(id,1b,2f) \
"2: \n\t" \
: : "r" (param) : CLOBBER_LIST)
#define ft_event2(id, callback, param, param2) \
__asm__ __volatile__( \
"1: jmp 2f \n\t" \
" movq %1, %%rdx \n\t" \
" movq %0, %%rsi \n\t" \
" movq $" #id ", %%rdi \n\t" \
" call " #callback " \n\t" \
_EVENT_TABLE(id,1b,2f) \
"2: \n\t" \
: : "r" (param), "r" (param2) : CLOBBER_LIST)
#define ft_event3(id, callback, p, p2, p3) \
__asm__ __volatile__( \
"1: jmp 2f \n\t" \
" movq %2, %%rcx \n\t" \
" movq %1, %%rdx \n\t" \
" movq %0, %%rsi \n\t" \
" movq $" #id ", %%rdi \n\t" \
" call " #callback " \n\t" \
_EVENT_TABLE(id,1b,2f) \
"2: \n\t" \
: : "r" (p), "r" (p2), "r" (p3) : CLOBBER_LIST)
|