Arch-abstraction: a nice change that removes the need for ume_entry.S.  Instead
of using an assembly hack to find the stack pointer at startup, we find it from
argv.  It's much simpler, avoids linking games, is platform independent, and
works on PPC.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2782 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index b08cc3f..56c006f 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -30,12 +30,11 @@
 
 valgrind_SOURCES = \
 	ume.c \
-	${VG_ARCH}/ume_entry.S \
 	\
 	stage1.c \
 	${VG_ARCH}/jmp_with_stack.c 
 valgrind_DEPENDENCIES =
-valgrind_LDFLAGS=-static -g -Wl,-e,_ume_entry
+valgrind_LDFLAGS=-static -g
 valgrind_LDADD=
 
 # Where stage2 will be put.
@@ -46,7 +45,6 @@
 
 stage2_SOURCES = \
 	ume.c \
-	${VG_ARCH}/ume_entry.S \
 	\
 	vg_scheduler.c \
 	vg_default.c \
@@ -81,7 +79,7 @@
 	vg_transtab.c \
 	vg_cpuid.S
 stage2_DEPENDENCIES = $(srcdir)/valgrind.vs ${VG_ARCH}/stage2.lds
-stage2_LDFLAGS=-Wl,--export-dynamic -Wl,-e,_ume_entry  -g \
+stage2_LDFLAGS=-Wl,--export-dynamic -g \
 	-Wl,-defsym,kickstart_base=$(KICKSTART_BASE) \
 	-Wl,-T,${VG_ARCH}/stage2.lds \
 	-Wl,-version-script $(srcdir)/valgrind.vs 
diff --git a/coregrind/stage1.c b/coregrind/stage1.c
index 5b4e4db..c6ae5bc 100644
--- a/coregrind/stage1.c
+++ b/coregrind/stage1.c
@@ -46,6 +46,9 @@
 
 static int stack[SIGSTKSZ*4];
 
+// Initial stack pointer, which points to argc.
+static void* init_sp;
+
 /* Where we expect to find all our aux files (namely, stage2) */
 static const char *valgrind_lib = VG_LIBDIR;
 
@@ -257,7 +260,7 @@
    char buf[strlen(valgrind_lib) + sizeof(stage2) + 16];
 
    info.exe_base = PGROUNDUP(&_end);
-   info.exe_end  = PGROUNDDN(ume_exec_esp);
+   info.exe_end  = PGROUNDDN(init_sp);
 
    /* XXX FIXME: how can stage1 know where stage2 wants things placed?
       Options:
@@ -283,7 +286,7 @@
    padfile = as_openpadfile();
    as_pad(0, (void *)info.map_base, padfile);
    
-   esp = fix_auxv(ume_exec_esp, &info, padfile);
+   esp = fix_auxv(init_sp, &info, padfile);
 
    if (0) {
       printf("---------- launch stage 2 ----------\n");
@@ -294,7 +297,7 @@
    jmp_with_stack(info.init_eip, (addr_t)esp);   
 }
 
-int main(void)
+int main(int argc, char** argv)
 {
    struct rlimit rlim;
    const char *cp = getenv(VALGRINDLIB);
@@ -302,7 +305,9 @@
    if (cp != NULL)
       valgrind_lib = cp;
 
-   assert(ume_exec_esp != NULL);
+   // Initial stack pointer is to argc, which is immediately before argv[0]
+   // on the stack.
+   init_sp = argv - 1;
 
    /* Set the address space limit as high as it will go, since we make
       a lot of very large mappings. */
diff --git a/coregrind/ume.h b/coregrind/ume.h
index 474a0a0..a015ff0 100644
--- a/coregrind/ume.h
+++ b/coregrind/ume.h
@@ -55,8 +55,6 @@
 /* Integer type the same size as a pointer */
 typedef ESZ(Addr) addr_t;
 
-extern void *ume_exec_esp;	/* esp on entry at exec time */
-
 // Jump to a new 'ip' with the stack 'sp'.
 void jmp_with_stack(addr_t ip, addr_t sp) __attribute__((noreturn));
 
diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c
index 23c437a..cf61287 100644
--- a/coregrind/vg_main.c
+++ b/coregrind/vg_main.c
@@ -362,9 +362,9 @@
 /*====================================================================*/
 
 /* Look for our AUXV table */
-int scan_auxv(void)
+int scan_auxv(void* init_sp)
 {
-   const struct ume_auxv *auxv = find_auxv((int *)ume_exec_esp);
+   const struct ume_auxv *auxv = find_auxv((int *)init_sp);
    int padfile = -1, found = 0;
 
    for (; auxv->a_type != AT_NULL; auxv++)
@@ -908,7 +908,8 @@
                   | undefined       |
 		  :                 :
  */
-static Addr setup_client_stack(char **orig_argv, char **orig_envp, 
+static Addr setup_client_stack(void* init_sp,
+                               char **orig_argv, char **orig_envp, 
 			       const struct exeinfo *info,
                                UInt** client_auxv)
 {
@@ -928,7 +929,7 @@
    addr_t cl_esp;		/* client stack base (initial esp) */
 
    /* use our own auxv as a prototype */
-   orig_auxv = find_auxv(ume_exec_esp);
+   orig_auxv = find_auxv(init_sp);
 
    /* ==================== compute sizes ==================== */
 
@@ -2576,7 +2577,10 @@
    // Check we were launched by stage1
    //   p: n/a
    //--------------------------------------------------------------
-   padfile = scan_auxv();
+   {
+      void* init_sp = argv - 1;
+      padfile = scan_auxv(init_sp);
+   }
 
    if (0) {
       printf("========== main() ==========\n");
@@ -2650,7 +2654,11 @@
    //   p: load_client()     [for 'info']
    //   p: fix_environment() [for 'env']
    //--------------------------------------------------------------
-   esp_at_startup = setup_client_stack(cl_argv, env, &info, &client_auxv);
+   { 
+      void* init_sp = argv - 1;
+      esp_at_startup = setup_client_stack(init_sp, cl_argv, env, &info,
+                                          &client_auxv);
+   }
 
    if (0)
       printf("entry=%p client esp=%p vg_argc=%d brkbase=%p\n",
diff --git a/coregrind/x86/Makefile.am b/coregrind/x86/Makefile.am
index d104a04..17801a3 100644
--- a/coregrind/x86/Makefile.am
+++ b/coregrind/x86/Makefile.am
@@ -11,8 +11,7 @@
 noinst_LIBRARIES = libarch.a
 
 EXTRA_DIST = \
-	jmp_with_stack.c \
-	ume_entry.S
+	jmp_with_stack.c
 
 BUILT_SOURCES = stage2.lds
 CLEANFILES = stage2.lds
diff --git a/coregrind/x86/ume_entry.S b/coregrind/x86/ume_entry.S
deleted file mode 100644
index 0802baf..0000000
--- a/coregrind/x86/ume_entry.S
+++ /dev/null
@@ -1,41 +0,0 @@
-
-/*
-   This file is part of Valgrind, an extensible x86 protected-mode
-   emulator for monitoring program execution on x86-Unixes.
-
-   Copyright (C) 2000-2004 Julian Seward 
-      jseward@acm.org
-
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307, USA.
-
-   The GNU General Public License is contained in the file COPYING.
-*/
-
-	.text
-	.globl _ume_entry
-
-	/* Record the very initial value of %esp before starting the
-	   rest of the executable */
-_ume_entry:
-	movl	%esp, ume_exec_esp
-	jmp	_start
-
-	.data
-	.globl ume_exec_esp
-ume_exec_esp:	.long 0
-        
-/* Let the linker know we don't need an executable stack */
-.section .note.GNU-stack,"",@progbits