667
|
1 extern int printf(const char *,...);
|
|
2 // extern void *alloca(int);
|
|
3
|
|
4 #define A0 0xa0a0a0a0
|
|
5 #define A1 0xa1a1a1a1
|
|
6 #define A2 0xa2a2a2a2
|
|
7 #define A3 0xa3a3a3a3
|
|
8 #define A4 0xa4a4a4a4
|
|
9
|
|
10 #define L0 0xb0b0b0b0
|
|
11 #define L1 0xb1b1b1b1
|
|
12 #define L2 0xb2b2b2b2
|
|
13 #define L3 0xb3b3b3b3
|
|
14 #define L4 0xb4b4b4b4
|
|
15
|
|
16 void *ret;
|
|
17
|
669
|
18 int dum;
|
|
19
|
673
|
20 void *float_frame(int a0);
|
|
21
|
|
22 static inline void frame_pointer(char *s) __attribute__((always_inline));
|
|
23
|
|
24 static inline void frame_pointer(char *s)
|
|
25 {
|
676
|
26 #ifdef i386
|
|
27 void *fr,*st;
|
|
28 __asm__("\tmovl %%ebp,%0\n": "=r" (fr));
|
|
29 __asm__("\tmovl %%esp,%0\n": "=r" (st));
|
|
30 printf("fr=%08x st=%08x at %s\n",fr,st,s);
|
|
31 #else
|
|
32 #ifdef ppc
|
673
|
33 void *fr,*st;
|
|
34 __asm__("\tmr %0,31\n": "=r" (fr));
|
|
35 __asm__("\tmr %0,1\n": "=r" (st));
|
|
36 printf("fr=%08x st=%08x at %s\n",fr,st,s);
|
676
|
37 #endif
|
|
38 #endif
|
673
|
39 }
|
|
40
|
|
41
|
|
42 int
|
|
43 int_frame(int a0)
|
|
44 {
|
|
45 int i0;
|
|
46 int f0;
|
|
47 int *p;
|
|
48 int i1;
|
|
49 frame_pointer("int frame");
|
|
50
|
|
51 i0 = f0 = 0.3;
|
|
52 printf("int 0 offset: %08x\n",&a0-&i0);
|
|
53 printf("int 1 offset: %08x\n",&a0-&i1);
|
|
54 printf("int 1 offset: %08x\n",&a0-(int*)float_frame(A1));
|
|
55 printf("%d\n",f0);
|
|
56 return i0;
|
|
57 }
|
|
58
|
|
59 void *
|
|
60 float_frame(int a0)
|
|
61 {
|
|
62 int i0;
|
|
63 double f0;
|
|
64 int *p;
|
|
65 int i1;
|
|
66 frame_pointer("float frame");
|
|
67
|
|
68 f0 = 0.3;
|
|
69 printf("local0 offset: %08x\n",&a0-&i0);
|
|
70 printf("local1 offset: %08x\n",&a0-&i1);
|
|
71 printf("%g\n",f0);
|
|
72 return &i0;
|
|
73 }
|
|
74
|
669
|
75 void
|
|
76 called(int a0,int a1,int a2)
|
|
77 {
|
673
|
78 frame_pointer("called");
|
669
|
79 dum = a0+a1+a2;
|
|
80 }
|
|
81
|
667
|
82 void
|
|
83 frame(int a0,int a1,int a2)
|
|
84 {
|
|
85 int l0 = L0;
|
676
|
86 int *top;
|
667
|
87 int *p;
|
|
88 int i = 0;
|
|
89 int l1 = L1;
|
673
|
90 frame_pointer("frame");
|
676
|
91 if (a1==1) {
|
|
92 top = (int *)__builtin_alloca(16);
|
|
93 printf("alloca %08x\n",top);
|
|
94 } else {
|
|
95 top = &l0;
|
|
96 }
|
673
|
97 printf("local %08x\n",&l0);
|
667
|
98
|
|
99 *top = L2;
|
669
|
100 called(A3,A1,A4);
|
|
101 #define OFFSET 16
|
|
102 i = -OFFSET;
|
|
103 for(p = top-OFFSET;p<top+0x100; ) {
|
667
|
104 if (*p==(int)ret) {
|
676
|
105 printf("%08x: %08x ret address\n",p,i);
|
667
|
106 } else if (*p==A0) {
|
676
|
107 printf("%08x: %08x caller arg 1\n",p,i);
|
667
|
108 } else if (*p==A2) {
|
676
|
109 printf("%08x: %08x caller arg last\n",p,i);
|
669
|
110 } else if (*p==A3) {
|
676
|
111 printf("%08x: %08x callee arg 1\n",p,i);
|
669
|
112 } else if (*p==A4) {
|
676
|
113 printf("%08x: %08x callee arg last\n",p,i);
|
667
|
114 } else if (*p==L0) {
|
676
|
115 printf("%08x: %08x local var top\n",p,i);
|
667
|
116 } else if (*p==L1) {
|
676
|
117 printf("%08x: %08x local var end\n",p,i);
|
667
|
118 } else if (*p==L2) {
|
676
|
119 printf("%08x: %08x stack top (alloca)\n",p,i);
|
|
120 } else {
|
|
121 // printf(" %08x",*p);
|
667
|
122 }
|
|
123 i+= sizeof(int);
|
|
124 p++;
|
|
125 }
|
|
126 }
|
|
127
|
|
128
|
|
129 int
|
|
130 main()
|
|
131 {
|
673
|
132 frame_pointer("main");
|
667
|
133 ret = &&label;
|
|
134 frame(A0,A1,A2);
|
676
|
135 frame(A0,1,A2);
|
673
|
136 printf("\n");
|
|
137 float_frame(A0);
|
|
138 int_frame(A0);
|
667
|
139 label:
|
|
140 return 0;
|
|
141 }
|