From c4ddcf54dfc59bf79dd3831d55a86360f324d616 Mon Sep 17 00:00:00 2001 From: slava Date: Thu, 16 Nov 2006 05:12:43 +0000 Subject: [PATCH] x86 compiled stack traces working --- Makefile | 8 ++++---- library/compiler/generator/architecture.factor | 8 ++++---- library/compiler/x86/architecture.factor | 8 ++++++++ library/compiler/x86/assembler.factor | 1 + vm/Config.linux.x86 | 2 ++ vm/Config.macosx.x86 | 2 ++ vm/Config.windows | 1 + vm/Config.x86 | 1 + vm/cpu-x86.S | 6 ++++++ vm/cpu-x86.h | 7 +------ vm/run.c | 7 +++++-- 11 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 vm/Config.linux.x86 create mode 100644 vm/Config.macosx.x86 create mode 100644 vm/Config.x86 create mode 100644 vm/cpu-x86.S diff --git a/Makefile b/Makefile index df4e31bd19..fff465cfde 100644 --- 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 diff --git a/library/compiler/generator/architecture.factor b/library/compiler/generator/architecture.factor index 04bf601087..f1d30c9dd0 100644 --- a/library/compiler/generator/architecture.factor +++ b/library/compiler/generator/architecture.factor @@ -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 -- ) diff --git a/library/compiler/x86/architecture.factor b/library/compiler/x86/architecture.factor index 75832c9ec8..6d486c99f4 100644 --- a/library/compiler/x86/architecture.factor +++ b/library/compiler/x86/architecture.factor @@ -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 ; diff --git a/library/compiler/x86/assembler.factor b/library/compiler/x86/assembler.factor index 62a423898c..dc7ef5a061 100644 --- a/library/compiler/x86/assembler.factor +++ b/library/compiler/x86/assembler.factor @@ -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 index 0000000000..313b999133 --- /dev/null +++ b/vm/Config.linux.x86 @@ -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 index 0000000000..27c47fcb63 --- /dev/null +++ b/vm/Config.macosx.x86 @@ -0,0 +1,2 @@ +include vm/Config.macosx +include vm/Config.x86 diff --git a/vm/Config.windows b/vm/Config.windows index 75dd8d1f12..1f44eb3049 100644 --- a/vm/Config.windows +++ b/vm/Config.windows @@ -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 index 0000000000..709cbe1b72 --- /dev/null +++ b/vm/Config.x86 @@ -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 index 0000000000..469af4473a --- /dev/null +++ b/vm/cpu-x86.S @@ -0,0 +1,6 @@ +/* Callable from C as +void *native_stack_pointer(void) */ + .globl native_stack_pointer +native_stack_pointer: + mov %ebp,%eax + ret diff --git a/vm/cpu-x86.h b/vm/cpu-x86.h index 335398eb98..ee0472f9f7 100644 --- a/vm/cpu-x86.h +++ b/vm/cpu-x86.h @@ -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; diff --git a/vm/run.c b/vm/run.c index 97d66506a1..17cc2d123f 100644 --- 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; }