x86 compiled stack traces working

darcs
slava 2006-11-16 05:12:43 +00:00
parent 5293a6c637
commit c4ddcf54df
11 changed files with 35 additions and 16 deletions

View File

@ -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

View 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 -- )

View 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 ;

View 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

2
vm/Config.linux.x86 Normal file
View File

@ -0,0 +1,2 @@
include vm/Config.linux
include vm/Config.x86

2
vm/Config.macosx.x86 Normal file
View File

@ -0,0 +1,2 @@
include vm/Config.macosx
include vm/Config.x86

View File

@ -2,3 +2,4 @@ CFLAGS += -DWINDOWS
LIBS = -lm
PLAF_SUFFIX = .exe
PLAF_OBJS = vm/os-windows.o
include wm/Config.x86

1
vm/Config.x86 Normal file
View File

@ -0,0 +1 @@
PLAF_OBJS += vm/cpu-x86.o

6
vm/cpu-x86.S Normal file
View File

@ -0,0 +1,6 @@
/* Callable from C as
void *native_stack_pointer(void) */
.globl native_stack_pointer
native_stack_pointer:
mov %ebp,%eax
ret

View 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;

View File

@ -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;
}