LIBS = @LIBS@
LEX = @LEX@
AR = @AR@
+AS = @AS@
GTK_CFLAGS = @GTK_CFLAGS@
GTK_LIBS = @GTK_LIBS@
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
#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 */
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)
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
AC_SUBST(AR)
+AC_SUBST(AS)
AC_SUBST(XVERSION)
AC_SUBST(XPACKAGE)
AC_SUBST(XGNOKIIDIR)
#! /bin/sh
-#target_m68k=1
+target_m68k=1
enable_debug=1
-#stack_check=1
+stackcheck=60000
cfg_port="ttyS0"
exec 2>&1
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 \
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
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)
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);
}
}
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 */
+++ /dev/null
-#ifdef GNOKII_MAIN
-#include "config.h"
-#endif
-
-#ifdef STACKCHECK
-
-#include <stdio.h>
-
-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 */