first take on the save ip on x86-32
[ust.git] / include / ust / processor.h
index 2ee7efa68c15dfa470cffe802536200a9ba31174..6f0b9491be99f1f4b3b858f883925ad2279d0ce0 100644 (file)
 extern __thread long ust_reg_stack[500];
 extern volatile __thread long *ust_reg_stack_ptr;
 
-#ifndef CONFIG_UST_GDB_INTEGRATION
-static inline save_ip(void)
-{
-}
-#endif
-
-
-#ifndef x86_64
+#ifndef __x86_64
 
 struct registers {
-       long eax;
-       long ebx;
-       long ecx;
-       long edx;
-       long ebp;
-       long esp;
+       short ss;
+       short cs;
        long esi;
+       long ebp;
+       long edx;
+       long ecx;
        long edi;
-       int  xds;
-       int  xes;
-       int  xfs;
-       int  xgs;
-       long eip;
-       int  xcs;
+       long ebx;
+       long eax;
        long eflags;
-       int  xss;
+       long esp;
 };
 
-#ifdef CONFIG_UST_GDB_ITEGRATION
+#ifdef CONFIG_UST_GDB_INTEGRATION
 
-#error "GDB integration not supported for x86-32 yet."
+//#error "GDB integration not supported for x86-32 yet."
 
-#define save_ip()
-#define save_registers(a)
+#define save_registers(regsptr) \
+       asm volatile ( \
+            /* save original esp */ \
+            "pushl %%esp\n\t" \
+            /* push original eflags */ \
+            "pushfl\n\t" \
+             /* eax will hold the ptr to the private stack bottom */ \
+            "pushl %%eax\n\t" \
+            /* ebx will be used to temporarily hold the stack bottom addr */ \
+            "pushl %%ebx\n\t" \
+            /* rdi is the input to __tls_get_addr, and also a temp var */ \
+            "pushl %%edi\n\t" \
+            /* Start TLS access of private reg stack pointer */ \
+            "leal ust_reg_stack_ptr@tlsgd(,%%ebx,1),%%eax\n\t" \
+            "call ___tls_get_addr@plt\n\t" \
+            /* --- End TLS access */ \
+            /* check if ust_reg_stack_ptr has been initialized */ \
+            "movl (%%eax),%%ebx\n\t" \
+            "testl %%ebx,%%ebx\n\t" \
+            "jne 1f\n\t" \
+            "movl %%eax,%%ebx\n\t" \
+            /* Start TLS access of private reg stack */ \
+            "leal ust_reg_stack@tlsgd(,%%ebx,1),%%eax\n\t" \
+            "call ___tls_get_addr@plt\n\t" \
+            /* --- End TLS access */ \
+            "addl $500,%%eax\n\t" \
+            "movl %%eax,(%%ebx)\n\t" \
+            "movl %%ebx,%%eax\n\t" \
+            /* now the pointer to the private stack is in eax. \
+               must add stack size so the ptr points to the stack bottom. */ \
+       "1:\n\t" \
+            /* Manually push esp to private stack */ \
+            "addl $-4,(%%eax)\n\t" \
+            "movl 16(%%esp), %%edi\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%edi, (%%ebx)\n\t" \
+            /* Manually push eflags to private stack */ \
+            "addl $-4,(%%eax)\n\t" \
+            "movl 12(%%esp), %%edi\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%edi, (%%ebx)\n\t" \
+            /* Manually push eax to private stack */ \
+            "addl $-4,(%%eax)\n\t" \
+            "movl 8(%%esp), %%edi\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%edi, (%%ebx)\n\t" \
+            /* Manually push ebx to private stack */ \
+            "addl $-4,(%%eax)\n\t" \
+            "movl 4(%%esp), %%edi\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%edi, (%%ebx)\n\t" \
+            /* Manually push edi to private stack */ \
+            "addl $-4,(%%eax)\n\t" \
+            "movl 0(%%esp), %%edi\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%edi, (%%ebx)\n\t" \
+            /* now push regs to tls */ \
+            /* -- esp already pushed -- */ \
+            /* -- eax already pushed -- */ \
+            /* -- ebx already pushed -- */ \
+            /* -- edi already pushed -- */ \
+            "addl $-4,(%%eax)\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%ecx,(%%ebx)\n\t" \
+            "addl $-4,(%%eax)\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%edx,(%%ebx)\n\t" \
+            "addl $-4,(%%eax)\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%ebp,(%%ebx)\n\t" \
+            "addl $-4,(%%eax)\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movl %%esi,(%%ebx)\n\t" \
+            /* push cs */ \
+            "addl $-2,(%%eax)\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movw %%cs, (%%ebx)\n\t" \
+            /* push ss */ \
+            "addl $-2,(%%eax)\n\t" \
+            "movl (%%eax), %%ebx\n\t" \
+            "movw %%ss, (%%ebx)\n\t" \
+            /* restore original values of regs that were used internally */ \
+            "popl %%edi\n\t" \
+            "popl %%ebx\n\t" \
+            "popl %%eax\n\t" \
+            /* cancel push of rsp */ \
+            "addl $4,%%esp\n\t" \
+            /* cancel push of eflags */ \
+            "addl $4,%%esp\n\t" \
+            ::: "memory"); \
+       memcpy(regsptr, (void *)ust_reg_stack_ptr, sizeof(struct registers)); \
+       ust_reg_stack_ptr = (void *)(((long)ust_reg_stack_ptr) + sizeof(struct registers));
+
+#define save_ip(channel,name)
 
-#else /* CONFIG_UST_GDB_ITEGRATION */
+#else /* CONFIG_UST_GDB_INTEGRATION */
 
-#define save_ip()
 #define save_registers(a)
 
-#endif /* CONFIG_UST_GDB_ITEGRATION */
+#endif /* CONFIG_UST_GDB_INTEGRATION */
 
 #define RELATIVE_ADDRESS(__rel_label__) __rel_label__
 
@@ -78,13 +157,7 @@ struct registers {
        unsigned long rsp;
 };
 
-#ifdef CONFIG_UST_GDB_ITEGRATION
-#define save_ip() \
-       asm (".section __marker_addr,\"aw\",@progbits\n\t"      \
-              _ASM_PTR "%c[marker_struct], (1f)\n\t"           \
-              ".previous\n\t"                                  \
-              "1:\n\t"                                         \
-               :: [marker_struct] "i" (&__mark_##channel##_##name));\
+#ifdef CONFIG_UST_GDB_INTEGRATION
 
 #define save_registers(regsptr) \
        asm volatile ( \
@@ -211,7 +284,11 @@ struct registers {
        memcpy(regsptr, (void *)ust_reg_stack_ptr, sizeof(struct registers)); \
        ust_reg_stack_ptr = (void *)(((long)ust_reg_stack_ptr) + sizeof(struct registers));
 
-#endif /* CONFIG_UST_GDB_ITEGRATION */
+#else /* CONFIG_UST_GDB_INTEGRATION */
+
+#define save_registers(a)
+
+#endif /* CONFIG_UST_GDB_INTEGRATION */
 
 /* Macro to insert the address of a relative jump in an assembly stub,
  * in a relocatable way. On x86-64, this uses a special (%rip) notation. */
This page took 0.030713 seconds and 4 git commands to generate.