From 945be3cc1ae0f7739a3d28722d07f7d17b2690bf Mon Sep 17 00:00:00 2001 From: short <> Date: Sat, 2 Mar 2002 22:28:27 +0000 Subject: [PATCH] m68k stack checking implemented, not tested yet on uClinux --- Makefile.global.in | 16 ++++++++++++++++ acconfig.h | 6 ++++-- configure.in | 4 ++++ do | 16 +++++++--------- gnokii/Makefile | 12 +++--------- gnokii/cleanup.c | 36 +++++++++++++++++++++++++++++------- gnokii/mcount.c | 26 -------------------------- 7 files changed, 63 insertions(+), 53 deletions(-) delete mode 100644 gnokii/mcount.c diff --git a/Makefile.global.in b/Makefile.global.in index 92fea11..8c106b1 100644 --- a/Makefile.global.in +++ b/Makefile.global.in @@ -47,6 +47,7 @@ CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ LEX = @LEX@ AR = @AR@ +AS = @AS@ GTK_CFLAGS = @GTK_CFLAGS@ GTK_LIBS = @GTK_LIBS@ @@ -76,3 +77,18 @@ endif CFLAGS += -I$(GNOKII_INCLUDE) -DGNOKII_MAIN=1 LDFLAGS = $(LIBS) -Wl,--rpath -Wl,$(libdir) +%.o: %.c +ifneq "" "$(findstring -DSTACKCHECK,$(CPPFLAGS))" + @echo "$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -S -o - $< | sed '#hidden' | $(AS) $(ASFLAGS) $(TARGET_MACH) -o $@" + @$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -S -o - $< | sed \ + 's!^ link\.w %a6,#\(-\?[0-9]\+\)$$!\ +moveml %d0-%d7/%a0-%a6,%sp@-; \ +lea stackcheck-.-8,%a0; \ +movel #\1,%d0; \ +jsr 0(%pc,%a0); \ +moveml %sp@+,%d0-%d7/%a0-%a6; \ +&!' | \ + $(AS) $(ASFLAGS) $(TARGET_MACH) -o $@ +else + $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $< +endif diff --git a/acconfig.h b/acconfig.h index 9bbd4bb..590cc87 100644 --- a/acconfig.h +++ b/acconfig.h @@ -80,13 +80,15 @@ #include "uccompat.h" #ifdef STACKCHECK -extern void live_check(const char *file,int line); +extern void live_check(const char *file,int line,int alloc); extern void live_disable(int how); -#define LIVE live_check(__FILE__,__LINE__) +#define LIVE live_check(__FILE__,__LINE__,-1) +#define LIVE_ALLOC(n) live_check(__FILE__,__LINE__,(n)) #define LIVE_DISABLE live_disable(1) #define LIVE_ENABLE live_disable(-1) #else /* STACKCHECK */ #define LIVE +#define LIVE_ALLOC(n) #define LIVE_DISABLE #define LIVE_ENABLE #endif /* STACKCHECK */ diff --git a/configure.in b/configure.in index 7ad1b9c..827924e 100644 --- a/configure.in +++ b/configure.in @@ -26,6 +26,9 @@ AC_PROG_LEX if test -z "$AR";then AC_PATH_PROG(AR, ar, no) fi +if test -z "$AS";then + AC_PATH_PROG(AS, as, no) +fi AC_PATH_PROG(RM, rm, no) AC_PATH_PROG(FIND, find, no) AC_CHECK_PROGS(MAKE, gmake make) @@ -486,6 +489,7 @@ AC_CONFIG_HEADER(include/config.h) AC_SUBST(PACKAGE) AC_SUBST(VERSION) AC_SUBST(AR) +AC_SUBST(AS) AC_SUBST(XVERSION) AC_SUBST(XPACKAGE) AC_SUBST(XGNOKIIDIR) diff --git a/do b/do index 1923407..345f2c0 100755 --- a/do +++ b/do @@ -1,8 +1,8 @@ #! /bin/sh -#target_m68k=1 +target_m68k=1 enable_debug=1 -#stack_check=1 +stackcheck=60000 cfg_port="ttyS0" exec 2>&1 @@ -14,16 +14,14 @@ autoconf if [ -n "$target_m68k" ];then test -n "$CC" || export CC="m68k-pic-coff-gcc" test -n "$AR" || export AR="m68k-pic-coff-ar" + test -n "$AS" || export AS="m68k-pic-coff-as" test -n "$CFLAGS" || export CFLAGS="-O2 -Wall -fPIC" test -n "$CPPFLAGS" || export CPPFLAGS="-DUCCOMPAT=1 $CPPFLAGS" - if [ -n "$stack_check" -a -n "$enable_debug" ];then - export CPPFLAGS="-DSTACKCHECK=1 $CPPFLAGS" - fi test -n "$LDFLAGS" || export LDFLAGS="gnokii/cleanup.c" -# if [ -n "$enable_debug" ];then -# export CFLAGS="-pg $CFLAGS" -# export LDFLAGS="gnokii/mcount.c $LDFLAGS" -# fi + if [ -n "$stackcheck" ];then + export CPPFLAGS="-DSTACKCHECK=$stackcheck $CPPFLAGS" + export CFLAGS="$CFLAGS -fno-omit-frame-pointer" + fi fi export CPPFLAGS="-DUCLINUX=1 $CPPFLAGS" ./configure --with-cfg-model=5110 --with-cfg-port=/dev/"$cfg_port" --without-x \ diff --git a/gnokii/Makefile b/gnokii/Makefile index e6d7b5f..f46dc45 100644 --- a/gnokii/Makefile +++ b/gnokii/Makefile @@ -23,24 +23,18 @@ endif all: gnokii -gnokii: $(OBJS) $(TOPDIR)/common/data.a $(TOPDIR)/common/common.a cleanup.o mcount.o # $(TOPDIR)/common/gsm-filetypes.o +gnokii: $(OBJS) $(TOPDIR)/common/data.a $(TOPDIR)/common/common.a cleanup.o # $(TOPDIR)/common/gsm-filetypes.o $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ -o $@ ifneq "" "$(findstring -DUCCOMPAT,$(CPPFLAGS))" /opt/uClinux/m68k-pic-coff/bin/coff2flt -o gnokii -s $(STACKSIZE) gnokii.coff endif -hello: hello.o cleanup.o mcount.o +hello: hello.o cleanup.o $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ -o $@ -hello.o: hello.c - $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $^ -o $@ - cleanup.o: cleanup.c $(CC) $(filter-out -pg,$(CFLAGS)) $(CPPFLAGS) $(TARGET_ARCH) -c $^ -o $@ -mcount.o: mcount.c - $(CC) $(filter-out -pg,$(CFLAGS)) $(CPPFLAGS) $(TARGET_ARCH) -c $^ -o $@ - $(TOPDIR)/common/common.a: $(MAKE) -C $(TOPDIR)/common common.a @@ -62,7 +56,7 @@ gnokiilib: $(OBJS) $(TOPDIR)/common/libmygnokii.so makelib: gnokiilib clean: - $(RM) $(OBJS) cleanup.o mcount.o *~ depend gnokii gnokiilib *.exe core *.bak + $(RM) $(OBJS) cleanup.o *~ depend gnokii gnokiilib *.exe core *.bak install: all $(INSTALL) -d $(bindir) diff --git a/gnokii/cleanup.c b/gnokii/cleanup.c index 1900733..2a0b51e 100644 --- a/gnokii/cleanup.c +++ b/gnokii/cleanup.c @@ -7,35 +7,40 @@ void _cleanup(void) { /* hack for pic32 gcc */ + +#ifdef LIVE + LIVE; +#endif /* LIVE */ } #ifdef STACKCHECK static volatile int live_check_disable=0; -void live_check(const char *file,int line) +void live_check(const char *file,int line,int alloc) { static volatile char *top=NULL,*top_printed=NULL; static volatile size_t largest=0,largest_printed=0; volatile char mark; +volatile char *will=&mark-(alloc==-1 ? 0 : alloc); - if (&mark > top) - top=&mark; + if (will > top) + top=will; if (live_check_disable<=0 && top!=top_printed) { printf("live_check [%s:%d]: new top=0x%08lX\n",file,line,(long)top); fflush(stdout); top_printed=top; } - if (largest < top-&mark) - largest = top-&mark; + if (largest < top-will) + largest = top-will; if (live_check_disable<=0 && largest!=largest_printed) { printf("live_check [%s:%d]: largest=%ld\n",file,line,(long)largest); fflush(stdout); largest_printed=largest; } - if (largest >= 12000) { + if (largest >= STACKCHECK) { if (live_check_disable<=0) - puts("live_check - aborting!"); + printf("live_check - aborting: limit=%d < largest=%ld!\n",STACKCHECK,(long)largest); _exit(99); } } @@ -45,4 +50,21 @@ void live_disable(int how) live_check_disable+=how; } +#define STACKCHECK_HEADER_PC_OFFSET 16 + +void stackcheck(void) +{ +volatile void *func; +volatile int fp_alloc; + + asm("movel %%d0,%0" : "=r" (fp_alloc) : /* input */ : "d0"); + asm("movel %%sp@,%0" : "=r" (func) : /* input */); + + if (live_check_disable<=0) + printf("mcount(func=0x%08lX,fp_alloc=%d)\n",((long)func)-STACKCHECK_HEADER_PC_OFFSET,-fp_alloc); +#ifdef LIVE_ALLOC + LIVE_ALLOC((-fp_alloc)+4); +#endif /* LIVE_ALLOC */ +} + #endif /* STACKCHECK */ diff --git a/gnokii/mcount.c b/gnokii/mcount.c deleted file mode 100644 index cf40629..0000000 --- a/gnokii/mcount.c +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef GNOKII_MAIN -#include "config.h" -#endif - -#ifdef STACKCHECK - -#include - -void mcount(void) -{ -#ifdef __m68k__X -static void *arg; - -#if 0 - asm("movel %%a0,%0" : "=r" (arg) : /* input */ : "a0"); -#endif - asm("movel %%fp@(+4),%0" : "=r" (arg) : /* input */); - - printf("mcount(0x%08lX)\n",(long)arg); -#endif /* __m68k__ */ -#ifdef LIVEX - LIVE; -#endif /* LIVE */ -} - -#endif /* STACKCHECK */ -- 1.8.3.1