diff test/stackframe.c @ 676:5e71527f9fd6

*** empty log message ***
author kono
date Sun, 06 May 2007 18:48:13 +0900
parents 442e90958386
children c2c709727221
line wrap: on
line diff
--- a/test/stackframe.c	Sat May 05 14:50:39 2007 +0900
+++ b/test/stackframe.c	Sun May 06 18:48:13 2007 +0900
@@ -23,10 +23,19 @@
 
 static inline void frame_pointer(char *s)
 {
+#ifdef i386
+    void *fr,*st;
+    __asm__("\tmovl %%ebp,%0\n": "=r" (fr));
+    __asm__("\tmovl %%esp,%0\n": "=r" (st));
+    printf("fr=%08x st=%08x at %s\n",fr,st,s);
+#else
+#ifdef ppc
     void *fr,*st;
     __asm__("\tmr %0,31\n": "=r" (fr));
     __asm__("\tmr %0,1\n": "=r" (st));
     printf("fr=%08x st=%08x at %s\n",fr,st,s);
+#endif
+#endif
 }
 
 
@@ -74,12 +83,17 @@
 frame(int a0,int a1,int a2)
 {
     int l0 = L0;
-    int *top = (int *)__builtin_alloca(16);
+    int *top;
     int *p;
     int i = 0;
     int l1 = L1;
     frame_pointer("frame");
-    printf("alloca %08x\n",top);
+    if (a1==1) {
+	top = (int *)__builtin_alloca(16);
+	printf("alloca %08x\n",top);
+    } else {
+	top = &l0;
+    }
     printf("local  %08x\n",&l0);
 
     *top = L2;
@@ -88,21 +102,23 @@
     i = -OFFSET;
     for(p = top-OFFSET;p<top+0x100; ) {
 	if (*p==(int)ret) {
-	    printf("%08x: ret address\n",i);
+	    printf("%08x: %08x ret address\n",p,i);
 	} else if (*p==A0) {
-	    printf("%08x: caller arg 1\n",i);
+	    printf("%08x: %08x caller arg 1\n",p,i);
 	} else if (*p==A2) {
-	    printf("%08x: caller arg last\n",i);
+	    printf("%08x: %08x caller arg last\n",p,i);
 	} else if (*p==A3) {
-	    printf("%08x: callee arg 1\n",i);
+	    printf("%08x: %08x callee arg 1\n",p,i);
 	} else if (*p==A4) {
-	    printf("%08x: callee arg last\n",i);
+	    printf("%08x: %08x callee arg last\n",p,i);
 	} else if (*p==L0) {
-	    printf("%08x: local var top\n",i);
+	    printf("%08x: %08x local var top\n",p,i);
 	} else if (*p==L1) {
-	    printf("%08x: local var end\n",i);
+	    printf("%08x: %08x local var end\n",p,i);
 	} else if (*p==L2) {
-	    printf("%08x: stack top (alloca)\n",i);
+	    printf("%08x: %08x stack top (alloca)\n",p,i);
+	} else {
+	    // printf(" %08x",*p);
 	}
 	i+= sizeof(int);
 	p++;
@@ -116,6 +132,7 @@
     frame_pointer("main");
     ret = &&label;
     frame(A0,A1,A2);
+    frame(A0,1,A2);
     printf("\n");
     float_frame(A0);
     int_frame(A0);