annotate test/stackframe.c @ 676:5e71527f9fd6

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