]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Implemented jmp_with_stack for AMD64. Cleaned up the
authorNicholas Nethercote <njn@valgrind.org>
Mon, 29 Nov 2004 17:59:00 +0000 (17:59 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Mon, 29 Nov 2004 17:59:00 +0000 (17:59 +0000)
comments/formatting of jmp_with_stack for ARM and x86, too.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3149

coregrind/amd64/jmp_with_stack.c
coregrind/arm/jmp_with_stack.c
coregrind/ume.h
coregrind/x86/jmp_with_stack.c

index b2f82f294faf1bd78b0007b02ae0f6d09d3eaa6f..8a6e23908a65914fc1d5a5cc38455c5a67c99c27 100644 (file)
 
 #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");
 } 
index b2f82f294faf1bd78b0007b02ae0f6d09d3eaa6f..0ab6cafdd5c52725f65990d4721fc4594be2f18f 100644 (file)
 
 #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
 } 
index 4daf504b21b0dfc0a75807e8a768dc32eaf55769..a78af58b8268ec133b46c3d27726194ddd6d35f3 100644 (file)
@@ -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));
 
 /*------------------------------------------------------------*/
index cc74c03fd197cca709be25c9691a42f9b8fab6ab..0d1b15ec0ff2e6d9f839334bc0070ce057be5b74 100644 (file)
 
 #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");
 }