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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#define IN_FRAMEWORK
#ifdef VFP
#define D0 0
#define D1 8
#define D2 16
#define D3 24
#define D4 32
#define D5 40
#define D6 48
#define D7 56
#define S0 64
#define S1 68
#define S2 72
#define S3 76
#define S4 80
#define S5 84
#define S6 88
#define S7 92
#define S8 86
#define S9 100
#define S10 104
#define S11 108
#define S12 112
#define S13 116
#define S14 120
#define S15 124
#define R0 128
#define R1 132
#define R2 136
#define R3 140
#define STACK 144
#else
#define R0 0
#define R1 4
#define R2 8
#define R3 12
#define STACK 16
#endif
extern void abort (void);
__attribute__((naked)) void dumpregs () __asm("myfunc");
__attribute__((naked)) void dumpregs ()
{
asm(
"mov ip, sp\n\t"
"stmfd sp!, {r0-r3}\n\t"
#ifdef VFP
"fstmdbs sp!, {s0-s15}\n\t"
"fstmdbd sp!, {d0-d7}\n\t"
#endif
"mov r0, sp\n\t"
"stmfd sp!, {ip, r14}\n\t"
"bl testfunc\n\t"
"ldmfd sp!, {r0, r14}\n\t"
"mov sp, r0\n\t"
"bx lr");
}
#define LAST_ARG(type,val,offset) { type __x = val; if (memcmp(&__x, stack+offset, sizeof(type)) != 0) abort(); }
#define ARG(type,val,offset) LAST_ARG(type, val, offset)
#define ANON(type,val,offset) LAST_ARG(type, val, offset)
#define LAST_ANON(type,val,offset) LAST_ARG(type, val, offset)
#define DOTS
void testfunc(char* stack)
{
#include TESTFILE
return;
}
#undef LAST_ARG
#undef ARG
#undef DOTS
#undef ANON
#undef LAST_ANON
#define LAST_ARG(type,val,offset) type
#define ARG(type,val,offset) LAST_ARG(type, val, offset),
#define DOTS ...
#define ANON(type,val, offset)
#define LAST_ANON(type,val, offset)
#ifndef MYFUNCTYPE
#define MYFUNCTYPE void
#endif
#ifndef PCSATTR
#define PCSATTR
#endif
MYFUNCTYPE myfunc(
#include TESTFILE
) PCSATTR;
#undef LAST_ARG
#undef ARG
#undef DOTS
#undef ANON
#undef LAST_ANON
#define LAST_ARG(type,val,offset) val
#define ARG(type,val,offset) LAST_ARG(type, val, offset),
#define DOTS
#define LAST_ANON(type,val,offset) LAST_ARG(type, val, offset)
#define ANON(type,val,offset) LAST_ARG(type, val, offset),
int main()
{
myfunc(
#include TESTFILE
);
return 0;
}
|