]> gitweb.factorcode.org Git - factor.git/commitdiff
x86 compiled stack traces working
authorslava <slava@factorcode.org>
Thu, 16 Nov 2006 05:12:43 +0000 (05:12 +0000)
committerslava <slava@factorcode.org>
Thu, 16 Nov 2006 05:12:43 +0000 (05:12 +0000)
Makefile
library/compiler/generator/architecture.factor
library/compiler/x86/architecture.factor
library/compiler/x86/assembler.factor
vm/Config.linux.x86 [new file with mode: 0644]
vm/Config.macosx.x86 [new file with mode: 0644]
vm/Config.windows
vm/Config.x86 [new file with mode: 0644]
vm/cpu-x86.S [new file with mode: 0644]
vm/cpu-x86.h
vm/run.c

index df4e31bd19b52b4cab4bd2dd48d6b5508bac7e43..fff465cfde3ed7f7ed5a4bf5c2c6667db9fe9bb4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ ifdef DEBUG
        CFLAGS = -g
        STRIP = touch
 else
-       CFLAGS = -Wall -O3 -ffast-math -fomit-frame-pointer $(SITE_CFLAGS)
+       CFLAGS = -Wall -O3 -ffast-math $(SITE_CFLAGS)
        STRIP = strip
 endif
 
@@ -73,11 +73,11 @@ macosx-ppc: macosx-freetype
        $(MAKE) $(BINARY) CONFIG=vm/Config.macosx.ppc
 
 macosx-x86: macosx-freetype
-       $(MAKE) $(BINARY) CONFIG=vm/Config.macosx
+       $(MAKE) $(BINARY) CONFIG=vm/Config.macosx.x86
 
 linux-x86:
-       $(MAKE) $(BINARY) CONFIG=vm/Config.linux
-       $(STRIP) $(BINARY)
+       $(MAKE) $(BINARY) CONFIG=vm/Config.linux.x86
+       $(STRIP) $(BINARY)
 
 linux-amd64:
        $(MAKE) $(BINARY) CONFIG=vm/Config.linux.amd64
index 04bf6010876a54c281b1a8497b0b4ebc2f074787..f1d30c9dd01317f9020acf25b505e482696b9caa 100644 (file)
@@ -36,11 +36,11 @@ DEFER: literal-template ( literals -- template )
 ! Load a literal (immediate or indirect)
 G: load-literal ( obj vreg -- ) 1 standard-combination ;
 
-! Set up caller stack frame (PowerPC and AMD64)
-: %prologue ( n -- ) drop ; inline
+! Set up caller stack frame
+DEFER: %prologue ( n -- )
 
-! Tear down stack frame (PowerPC and AMD64)
-: %epilogue ( -- ) ; inline
+! Tear down stack frame
+DEFER: %epilogue ( -- )
 
 ! Tail call another word
 DEFER: %jump ( label -- )
index 75832c9ec81b2d21c2ca129e6079749d1ef1473b..6d486c99f424ac18f34d693f3f1559f99fafe816 100644 (file)
@@ -96,6 +96,14 @@ M: immediate load-literal
 M: object load-literal
     v>operand load-indirect ;
 
+: %prologue ( n -- )
+    drop
+    EBP PUSH
+    EBP ESP MOV ;
+
+: %epilogue ( -- )
+    LEAVE ;
+
 : (%call) ( label -- label )
     dup (compile) dup primitive? [ address-operand ] when ;
 
index 62a423898c9e595cf7de27424524388f957a3f70..dc7ef5a0610629d04fcbc45af8a4490c389f90bd 100644 (file)
@@ -323,6 +323,7 @@ M: label JUMPcc (JUMPcc) rel-label ;
 : JLE HEX: 8e JUMPcc ;
 : JG  HEX: 8f JUMPcc ;
 
+: LEAVE ( -- ) HEX: c9 , ;
 : RET ( -- ) HEX: c3 , ;
 
 ! Arithmetic
diff --git a/vm/Config.linux.x86 b/vm/Config.linux.x86
new file mode 100644 (file)
index 0000000..313b999
--- /dev/null
@@ -0,0 +1,2 @@
+include vm/Config.linux
+include vm/Config.x86
diff --git a/vm/Config.macosx.x86 b/vm/Config.macosx.x86
new file mode 100644 (file)
index 0000000..27c47fc
--- /dev/null
@@ -0,0 +1,2 @@
+include vm/Config.macosx
+include vm/Config.x86
index 75dd8d1f12a5b461a6676169e84230ea978cb767..1f44eb30493560f1acb1dee322176f914d6b080a 100644 (file)
@@ -2,3 +2,4 @@ CFLAGS += -DWINDOWS
 LIBS = -lm
 PLAF_SUFFIX = .exe
 PLAF_OBJS = vm/os-windows.o
+include wm/Config.x86
diff --git a/vm/Config.x86 b/vm/Config.x86
new file mode 100644 (file)
index 0000000..709cbe1
--- /dev/null
@@ -0,0 +1 @@
+PLAF_OBJS += vm/cpu-x86.o
diff --git a/vm/cpu-x86.S b/vm/cpu-x86.S
new file mode 100644 (file)
index 0000000..469af44
--- /dev/null
@@ -0,0 +1,6 @@
+/* Callable from C as
+void *native_stack_pointer(void) */
+       .globl native_stack_pointer
+native_stack_pointer:
+       mov %ebp,%eax
+       ret
index 335398eb987ca6963c63afc6358bb141dffcec3a..ee0472f9f78a7ace8e390e1652f5f225a7072cad 100644 (file)
@@ -6,12 +6,7 @@ CELL cards_offset;
 
 INLINE void flush_icache(CELL start, CELL len) {}
 
-INLINE void *native_stack_pointer(void)
-{
-       void *ptr;
-       asm("mov %%ebp, %0" : "=r" (ptr));
-       return ptr;
-}
+void *native_stack_pointer(void);
 
 typedef struct _F_STACK_FRAME {
        struct _F_STACK_FRAME *previous;
index 97d66506a106b04464d009ced0724265833c2df6..17cc2d123fb20e90a56ba96830f45a2b5a050347 100644 (file)
--- a/vm/run.c
+++ b/vm/run.c
@@ -263,13 +263,16 @@ CELL native_stack_trace(void)
 
        while((CELL)frame < (CELL)stack_chain->native_stack_pointer)
        {
-               fflush(stdout);
                REGISTER_ARRAY(array);
                CELL cell = allot_cell((CELL)frame->return_address);
                UNREGISTER_ARRAY(array);
                GROWABLE_ADD(array,cell);
                if((CELL)frame->previous <= (CELL)frame)
-                       critical_error("C stack is busted",(CELL)frame);
+               {
+                       fprintf(stderr,"Factor warning: unusual C stack layout\n");
+                       fflush(stderr);
+                       break;
+               }
                frame = frame->previous;
        }