From: Nicholas Nethercote Date: Wed, 13 Oct 2004 17:55:31 +0000 (+0000) Subject: Some combined cleaning up and arch-abstraction, involving UME and start-up: X-Git-Tag: svn/VALGRIND_3_0_0~1536 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7942c92bd6a48d25b51a4ea9aa8ef9adf8850474;p=thirdparty%2Fvalgrind.git Some combined cleaning up and arch-abstraction, involving UME and start-up: - removed some assumptions that arch==x86 in Makefile.am files - removed ume_arch.h; moved its contents into ume.h. There was no need for these to be separate. - moved ume_go.c into an x86/ subdir; gave it the more meaningful name jmp_with_stack.c in the process (the corresponding function also got the name change) git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2757 --- diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am index e61bd1ec28..685d4a242d 100644 --- a/coregrind/Makefile.am +++ b/coregrind/Makefile.am @@ -29,10 +29,11 @@ BUILT_SOURCES = vg_toolint.c vg_toolint.h CLEANFILES = vg_toolint.c vg_toolint.h vg_replace_malloc.c vg_intercept.c valgrind_SOURCES = \ - stage1.c \ ume.c \ - x86/ume_entry.S \ - x86/ume_go.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_LDADD= @@ -45,7 +46,7 @@ KICKSTART_BASE=0xb0000000 stage2_SOURCES = \ ume.c \ - x86/ume_entry.S \ + ${VG_ARCH}/ume_entry.S \ \ vg_scheduler.c \ vg_default.c \ @@ -141,7 +142,6 @@ noinst_HEADERS = \ core.h \ core_asm.h \ ume.h \ - ume_arch.h \ vg_symtab2.h \ vg_symtypes.h \ vg_toolint.h \ diff --git a/coregrind/stage1.c b/coregrind/stage1.c index 6e8d56dc9c..d056a1a161 100644 --- a/coregrind/stage1.c +++ b/coregrind/stage1.c @@ -42,9 +42,7 @@ #include #include "core.h" - #include "ume.h" -#include "ume_arch.h" static int stack[SIGSTKSZ*4]; @@ -293,7 +291,7 @@ static void hoops(void) foreach_map(prmap, /*dummy*/NULL); } - ume_go(info.init_eip, (addr_t)esp); + jmp_with_stack(info.init_eip, (addr_t)esp); } int main(void) @@ -313,7 +311,7 @@ int main(void) setrlimit(RLIMIT_AS, &rlim); /* move onto another stack so we can play with the main one */ - ume_go((addr_t)hoops, (addr_t)stack + sizeof(stack)); + jmp_with_stack((addr_t)hoops, (addr_t)stack + sizeof(stack)); } /*--------------------------------------------------------------------*/ diff --git a/coregrind/ume.c b/coregrind/ume.c index a2cbc3e49a..7fe3146d27 100644 --- a/coregrind/ume.c +++ b/coregrind/ume.c @@ -1,6 +1,7 @@ /*--------------------------------------------------------------------*/ -/*--- User-mode execve() ume.c ---*/ +/*--- User-mode execve(), and other stuff shared between stage1 ---*/ +/*--- and stage2. ume.c ---*/ /*--------------------------------------------------------------------*/ /* diff --git a/coregrind/ume.h b/coregrind/ume.h index 1d7cef93b9..76f4ef5514 100644 --- a/coregrind/ume.h +++ b/coregrind/ume.h @@ -44,10 +44,6 @@ void foreach_map(int (*fn)(char *start, char *end, int maj, int min, int ino, void* extra), void* extra); -/*------------------------------------------------------------*/ -/*--- Loading ELF files ---*/ -/*------------------------------------------------------------*/ - #if ELFSZ == 64 #define ESZ(x) Elf64_##x #elif ELFSZ == 32 @@ -59,6 +55,20 @@ void foreach_map(int (*fn)(char *start, char *end, /* 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)); + +void foreach_map(int (*fn)(char *start, char *end, + const char *perm, off_t offset, + int maj, int min, int ino, void* extra), + void* extra); + +/*------------------------------------------------------------*/ +/*--- Loading ELF files ---*/ +/*------------------------------------------------------------*/ + // Info needed to load and run a program. IN/INOUT/OUT refers to the // inputs/outputs of do_exec(). struct exeinfo diff --git a/coregrind/ume_arch.h b/coregrind/ume_arch.h deleted file mode 100644 index 52cdabfd0f..0000000000 --- a/coregrind/ume_arch.h +++ /dev/null @@ -1,36 +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. -*/ - -#ifndef UME_ARCH -#define UME_ARCH - -#include "ume.h" - -void ume_go(addr_t eip, addr_t esp) __attribute__((noreturn)); - -extern void *ume_exec_esp; /* esp on entry at exec time */ - -#endif /* UME_ARCH */ diff --git a/coregrind/vg_main.c b/coregrind/vg_main.c index bf7063db03..5fb775b7c3 100644 --- a/coregrind/vg_main.c +++ b/coregrind/vg_main.c @@ -32,7 +32,6 @@ #include "core.h" #include "ume.h" -#include "ume_arch.h" #include #include diff --git a/coregrind/x86/Makefile.am b/coregrind/x86/Makefile.am index af552acfb0..ec16264032 100644 --- a/coregrind/x86/Makefile.am +++ b/coregrind/x86/Makefile.am @@ -10,9 +10,9 @@ noinst_HEADERS = \ noinst_LIBRARIES = libarch.a -EXTRA_DIST = \ - ume_entry.S \ - ume_go.c +EXTRA_DIST = \ + jmp_with_stack.c \ + ume_entry.S BUILT_SOURCES = stage2.lds CLEANFILES = stage2.lds diff --git a/coregrind/x86/ume_go.c b/coregrind/x86/jmp_with_stack.c similarity index 92% rename from coregrind/x86/ume_go.c rename to coregrind/x86/jmp_with_stack.c index 038a27057b..1e8a55fd2c 100644 --- a/coregrind/x86/ume_go.c +++ b/coregrind/x86/jmp_with_stack.c @@ -24,14 +24,14 @@ The GNU General Public License is contained in the file COPYING. */ -#include "ume_arch.h" +#include "ume.h" /* - Jump to a particular EIP with a particular ESP. This is intended + Jump to a particular IP with a particular SP. This is intended to simulate the initial CPU state when the kernel starts an program after exec; it therefore also clears all the other registers. */ -void ume_go(addr_t eip, addr_t esp) +void jmp_with_stack(addr_t eip, addr_t esp) { asm volatile ("movl %1, %%esp;" /* set esp */ "pushl %%eax;" /* push esp */