From: Nicholas Nethercote Date: Mon, 29 Nov 2004 17:59:00 +0000 (+0000) Subject: Implemented jmp_with_stack for AMD64. Cleaned up the X-Git-Tag: svn/VALGRIND_3_0_0~1169 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=decc1ddb4394c927075898bcaefe8cc3e06c3d00;p=thirdparty%2Fvalgrind.git Implemented jmp_with_stack for AMD64. Cleaned up the comments/formatting of jmp_with_stack for ARM and x86, too. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3149 --- diff --git a/coregrind/amd64/jmp_with_stack.c b/coregrind/amd64/jmp_with_stack.c index b2f82f294f..8a6e23908a 100644 --- a/coregrind/amd64/jmp_with_stack.c +++ b/coregrind/amd64/jmp_with_stack.c @@ -26,33 +26,30 @@ #include "ume.h" -/* - 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 jmp_with_stack(Addr eip, Addr esp) +void jmp_with_stack(Addr rip, Addr rsp) { - // XXX: temporary only -extern int printf (__const char *__restrict __format, ...); -extern void exit (int __status); - printf("jmp_with_stack: argh\n"); - exit(1); -#if 0 - asm volatile ("movl %1, %%esp;" /* set esp */ - "pushl %%eax;" /* push esp */ - "xorl %%eax,%%eax;" /* clear registers */ - "xorl %%ebx,%%ebx;" - "xorl %%ecx,%%ecx;" - "xorl %%edx,%%edx;" - "xorl %%esi,%%esi;" - "xorl %%edi,%%edi;" - "xorl %%ebp,%%ebp;" - - "ret" /* return into entry */ - : : "a" (eip), "r" (esp)); - /* we should never get here */ + asm volatile ( + "movq %1, %%rsp;" // set rsp + "pushq %%rax;" // push rsp + "xorq %%rax,%%rax;" // clear registers + "xorq %%rbx,%%rbx;" + "xorq %%rcx,%%rcx;" + "xorq %%rdx,%%rdx;" + "xorq %%rsi,%%rsi;" + "xorq %%rdi,%%rdi;" + "xorq %%rbp,%%rbp;" + "xorq %%r8, %%r8;" + "xorq %%r9, %%r9;" + "xorq %%r10,%%r10;" + "xorq %%r11,%%r11;" + "xorq %%r12,%%r12;" + "xorq %%r13,%%r13;" + "xorq %%r14,%%r14;" + "xorq %%r15,%%r15;" + "ret" // return into entry + : : "a" (rip), "r" (rsp)); + + // we should never get here for(;;) - asm volatile("ud2"); -#endif + asm volatile("ud2"); } diff --git a/coregrind/arm/jmp_with_stack.c b/coregrind/arm/jmp_with_stack.c index b2f82f294f..0ab6cafdd5 100644 --- a/coregrind/arm/jmp_with_stack.c +++ b/coregrind/arm/jmp_with_stack.c @@ -26,11 +26,6 @@ #include "ume.h" -/* - 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 jmp_with_stack(Addr eip, Addr esp) { // XXX: temporary only @@ -38,21 +33,6 @@ extern int printf (__const char *__restrict __format, ...); extern void exit (int __status); printf("jmp_with_stack: argh\n"); exit(1); -#if 0 - asm volatile ("movl %1, %%esp;" /* set esp */ - "pushl %%eax;" /* push esp */ - "xorl %%eax,%%eax;" /* clear registers */ - "xorl %%ebx,%%ebx;" - "xorl %%ecx,%%ecx;" - "xorl %%edx,%%edx;" - "xorl %%esi,%%esi;" - "xorl %%edi,%%edi;" - "xorl %%ebp,%%ebp;" - - "ret" /* return into entry */ - : : "a" (eip), "r" (esp)); - /* we should never get here */ - for(;;) - asm volatile("ud2"); -#endif + + // XXX: see x86/jmp_with_stack.c for how to implement this } diff --git a/coregrind/ume.h b/coregrind/ume.h index 4daf504b21..a78af58b82 100644 --- a/coregrind/ume.h +++ b/coregrind/ume.h @@ -46,7 +46,9 @@ void foreach_map(int (*fn)(char *start, char *end, int maj, int min, int ino, void* extra), void* extra); -// Jump to a new 'ip' with the stack 'sp'. +// Jump to a new 'ip' with the stack 'sp'. This is intended +// to simulate the initial CPU state when the kernel starts an program +// after exec; and so should clear all the other registers. void jmp_with_stack(Addr ip, Addr sp) __attribute__((noreturn)); /*------------------------------------------------------------*/ diff --git a/coregrind/x86/jmp_with_stack.c b/coregrind/x86/jmp_with_stack.c index cc74c03fd1..0d1b15ec0f 100644 --- a/coregrind/x86/jmp_with_stack.c +++ b/coregrind/x86/jmp_with_stack.c @@ -26,26 +26,22 @@ #include "ume.h" -/* - 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 jmp_with_stack(Addr eip, Addr esp) { - asm volatile ("movl %1, %%esp;" /* set esp */ - "pushl %%eax;" /* push esp */ - "xorl %%eax,%%eax;" /* clear registers */ - "xorl %%ebx,%%ebx;" - "xorl %%ecx,%%ecx;" - "xorl %%edx,%%edx;" - "xorl %%esi,%%esi;" - "xorl %%edi,%%edi;" - "xorl %%ebp,%%ebp;" - - "ret" /* return into entry */ - : : "a" (eip), "r" (esp)); - /* we should never get here */ + asm volatile ( + "movl %1, %%esp;" // set esp */ + "pushl %%eax;" // push esp */ + "xorl %%eax,%%eax;" // clear registers + "xorl %%ebx,%%ebx;" + "xorl %%ecx,%%ecx;" + "xorl %%edx,%%edx;" + "xorl %%esi,%%esi;" + "xorl %%edi,%%edi;" + "xorl %%ebp,%%ebp;" + "ret" // return into entry + : : "a" (eip), "r" (esp)); + + // we should never get here for(;;) - asm volatile("ud2"); + asm volatile("ud2"); }