Author: scottl
Date: Thu Nov 13 22:11:44 2014
New Revision: 274489
URL: https://svnweb.freebsd.org/changeset/base/274489

Log:
  Extend earlier addition of stack frames to most of support.S.  This makes
  stack traces in KDB, HWPMC, and DTrace much more reliable and useful.
  
  Reviewed by:  kan, kib
  Obtained from:        Netflix, Inc.
  MFC after:    5 days

Modified:
  head/sys/amd64/amd64/support.S
  head/sys/amd64/include/asmacros.h

Modified: head/sys/amd64/amd64/support.S
==============================================================================
--- head/sys/amd64/amd64/support.S      Thu Nov 13 22:06:57 2014        
(r274488)
+++ head/sys/amd64/amd64/support.S      Thu Nov 13 22:11:44 2014        
(r274489)
@@ -47,6 +47,7 @@
 
 /* done */
 ENTRY(bzero)
+       PUSH_FRAME_POINTER
        movq    %rsi,%rcx
        xorl    %eax,%eax
        shrq    $3,%rcx
@@ -57,11 +58,13 @@ ENTRY(bzero)
        andq    $7,%rcx
        rep
        stosb
+       POP_FRAME_POINTER
        ret
 END(bzero)
 
 /* Address: %rdi */
 ENTRY(pagezero)
+       PUSH_FRAME_POINTER
        movq    $-PAGE_SIZE,%rdx
        subq    %rdx,%rdi
        xorl    %eax,%eax
@@ -73,10 +76,12 @@ ENTRY(pagezero)
        addq    $32,%rdx
        jne     1b
        sfence
+       POP_FRAME_POINTER
        ret
 END(pagezero)
 
 ENTRY(bcmp)
+       PUSH_FRAME_POINTER
        movq    %rdx,%rcx
        shrq    $3,%rcx
        cld                                     /* compare forwards */
@@ -91,6 +96,7 @@ ENTRY(bcmp)
 1:
        setne   %al
        movsbl  %al,%eax
+       POP_FRAME_POINTER
        ret
 END(bcmp)
 
@@ -100,8 +106,7 @@ END(bcmp)
  *  w...@tools.de     (Wolfgang Solfrank, TooLs GmbH) +49-228-985800
  */
 ENTRY(bcopy)
-       pushq   %rbp
-       movq    %rsp,%rbp
+       PUSH_FRAME_POINTER
        xchgq   %rsi,%rdi
        movq    %rdx,%rcx
 
@@ -118,7 +123,7 @@ ENTRY(bcopy)
        andq    $7,%rcx                         /* any bytes left? */
        rep
        movsb
-       popq    %rbp
+       POP_FRAME_POINTER
        ret
 
        /* ALIGN_TEXT */
@@ -138,7 +143,7 @@ ENTRY(bcopy)
        rep
        movsq
        cld
-       popq    %rbp
+       POP_FRAME_POINTER
        ret
 END(bcopy)
 
@@ -146,6 +151,7 @@ END(bcopy)
  * Note: memcpy does not support overlapping copies
  */
 ENTRY(memcpy)
+       PUSH_FRAME_POINTER
        movq    %rdx,%rcx
        shrq    $3,%rcx                         /* copy by 64-bit words */
        cld                                     /* copy forwards */
@@ -155,6 +161,7 @@ ENTRY(memcpy)
        andq    $7,%rcx                         /* any bytes left? */
        rep
        movsb
+       POP_FRAME_POINTER
        ret
 END(memcpy)
 
@@ -162,6 +169,7 @@ END(memcpy)
  * pagecopy(%rdi=from, %rsi=to)
  */
 ENTRY(pagecopy)
+       PUSH_FRAME_POINTER
        movq    $-PAGE_SIZE,%rax
        movq    %rax,%rdx
        subq    %rax,%rdi
@@ -182,18 +190,21 @@ ENTRY(pagecopy)
        addq    $32,%rdx
        jne     2b
        sfence
+       POP_FRAME_POINTER
        ret
 END(pagecopy)
 
 /* fillw(pat, base, cnt) */
 /*       %rdi,%rsi, %rdx */
 ENTRY(fillw)
+       PUSH_FRAME_POINTER
        movq    %rdi,%rax
        movq    %rsi,%rdi
        movq    %rdx,%rcx
        cld
        rep
        stosw
+       POP_FRAME_POINTER
        ret
 END(fillw)
 
@@ -214,6 +225,7 @@ END(fillw)
  *         %rdi,        %rsi,    %rdx
  */
 ENTRY(copyout)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rax
        movq    $copyout_fault,PCB_ONFAULT(%rax)
        testq   %rdx,%rdx                       /* anything to do? */
@@ -259,6 +271,7 @@ done_copyout:
        xorl    %eax,%eax
        movq    PCPU(CURPCB),%rdx
        movq    %rax,PCB_ONFAULT(%rdx)
+       POP_FRAME_POINTER
        ret
 
        ALIGN_TEXT
@@ -266,6 +279,7 @@ copyout_fault:
        movq    PCPU(CURPCB),%rdx
        movq    $0,PCB_ONFAULT(%rdx)
        movq    $EFAULT,%rax
+       POP_FRAME_POINTER
        ret
 END(copyout)
 
@@ -274,6 +288,7 @@ END(copyout)
  *        %rdi,      %rsi,      %rdx
  */
 ENTRY(copyin)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rax
        movq    $copyin_fault,PCB_ONFAULT(%rax)
        testq   %rdx,%rdx                       /* anything to do? */
@@ -305,6 +320,7 @@ done_copyin:
        xorl    %eax,%eax
        movq    PCPU(CURPCB),%rdx
        movq    %rax,PCB_ONFAULT(%rdx)
+       POP_FRAME_POINTER
        ret
 
        ALIGN_TEXT
@@ -312,6 +328,7 @@ copyin_fault:
        movq    PCPU(CURPCB),%rdx
        movq    $0,PCB_ONFAULT(%rdx)
        movq    $EFAULT,%rax
+       POP_FRAME_POINTER
        ret
 END(copyin)
 
@@ -321,6 +338,7 @@ END(copyin)
  *        dst = %rdi, old = %esi, oldp = %rdx, new = %ecx
  */
 ENTRY(casueword32)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%r8
        movq    $fusufault,PCB_ONFAULT(%r8)
 
@@ -349,6 +367,7 @@ ENTRY(casueword32)
         * catch corrupted pointer.
         */
        movl    %esi,(%rdx)                     /* oldp = %rdx */
+       POP_FRAME_POINTER
        ret
 END(casueword32)
 
@@ -358,6 +377,7 @@ END(casueword32)
  *        dst = %rdi, old = %rsi, oldp = %rdx, new = %rcx
  */
 ENTRY(casueword)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%r8
        movq    $fusufault,PCB_ONFAULT(%r8)
 
@@ -380,6 +400,7 @@ ENTRY(casueword)
        xorl    %eax,%eax
        movq    %rax,PCB_ONFAULT(%r8)
        movq    %rsi,(%rdx)
+       POP_FRAME_POINTER
        ret
 END(casueword)
 
@@ -391,6 +412,7 @@ END(casueword)
 
 ALTENTRY(fueword64)
 ENTRY(fueword)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -402,11 +424,13 @@ ENTRY(fueword)
        movq    (%rdi),%r11
        movq    %rax,PCB_ONFAULT(%rcx)
        movq    %r11,(%rsi)
+       POP_FRAME_POINTER
        ret
 END(fuword64)
 END(fuword)
 
 ENTRY(fueword32)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -418,6 +442,7 @@ ENTRY(fueword32)
        movl    (%rdi),%r11d
        movq    %rax,PCB_ONFAULT(%rcx)
        movl    %r11d,(%rsi)
+       POP_FRAME_POINTER
        ret
 END(fueword32)
 
@@ -436,6 +461,7 @@ END(suswintr)
 END(fuswintr)
 
 ENTRY(fuword16)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -445,10 +471,12 @@ ENTRY(fuword16)
 
        movzwl  (%rdi),%eax
        movq    $0,PCB_ONFAULT(%rcx)
+       POP_FRAME_POINTER
        ret
 END(fuword16)
 
 ENTRY(fubyte)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -458,6 +486,7 @@ ENTRY(fubyte)
 
        movzbl  (%rdi),%eax
        movq    $0,PCB_ONFAULT(%rcx)
+       POP_FRAME_POINTER
        ret
 END(fubyte)
 
@@ -467,6 +496,7 @@ fusufault:
        xorl    %eax,%eax
        movq    %rax,PCB_ONFAULT(%rcx)
        decq    %rax
+       POP_FRAME_POINTER
        ret
 
 /*
@@ -476,6 +506,7 @@ fusufault:
  */
 ALTENTRY(suword64)
 ENTRY(suword)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -487,11 +518,13 @@ ENTRY(suword)
        xorl    %eax,%eax
        movq    PCPU(CURPCB),%rcx
        movq    %rax,PCB_ONFAULT(%rcx)
+       POP_FRAME_POINTER
        ret
 END(suword64)
 END(suword)
 
 ENTRY(suword32)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -503,10 +536,12 @@ ENTRY(suword32)
        xorl    %eax,%eax
        movq    PCPU(CURPCB),%rcx
        movq    %rax,PCB_ONFAULT(%rcx)
+       POP_FRAME_POINTER
        ret
 END(suword32)
 
 ENTRY(suword16)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -518,10 +553,12 @@ ENTRY(suword16)
        xorl    %eax,%eax
        movq    PCPU(CURPCB),%rcx               /* restore trashed register */
        movq    %rax,PCB_ONFAULT(%rcx)
+       POP_FRAME_POINTER
        ret
 END(suword16)
 
 ENTRY(subyte)
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%rcx
        movq    $fusufault,PCB_ONFAULT(%rcx)
 
@@ -534,6 +571,7 @@ ENTRY(subyte)
        xorl    %eax,%eax
        movq    PCPU(CURPCB),%rcx               /* restore trashed register */
        movq    %rax,PCB_ONFAULT(%rcx)
+       POP_FRAME_POINTER
        ret
 END(subyte)
 
@@ -547,6 +585,7 @@ END(subyte)
  *     return the actual length in *lencopied.
  */
 ENTRY(copyinstr)
+       PUSH_FRAME_POINTER
        movq    %rdx,%r8                        /* %r8 = maxlen */
        movq    %rcx,%r9                        /* %r9 = *len */
        xchgq   %rdi,%rsi                       /* %rdi = from, %rsi = to */
@@ -603,6 +642,7 @@ cpystrflt_x:
        subq    %rdx,%r8
        movq    %r8,(%r9)
 1:
+       POP_FRAME_POINTER
        ret
 END(copyinstr)
 
@@ -611,6 +651,7 @@ END(copyinstr)
  *         %rdi, %rsi, %rdx, %rcx
  */
 ENTRY(copystr)
+       PUSH_FRAME_POINTER
        movq    %rdx,%r8                        /* %r8 = maxlen */
 
        xchgq   %rdi,%rsi
@@ -640,6 +681,7 @@ ENTRY(copystr)
        subq    %rdx,%r8
        movq    %r8,(%rcx)
 7:
+       POP_FRAME_POINTER
        ret
 END(copystr)
 
@@ -709,6 +751,7 @@ END(longjmp)
  */
 ENTRY(rdmsr_safe)
 /* int rdmsr_safe(u_int msr, uint64_t *data) */
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%r8
        movq    $msr_onfault,PCB_ONFAULT(%r8)
        movl    %edi,%ecx
@@ -720,6 +763,7 @@ ENTRY(rdmsr_safe)
        movq    %rax,(%rsi)
        xorq    %rax,%rax
        movq    %rax,PCB_ONFAULT(%r8)
+       POP_FRAME_POINTER
        ret
 
 /*
@@ -727,6 +771,7 @@ ENTRY(rdmsr_safe)
  */
 ENTRY(wrmsr_safe)
 /* int wrmsr_safe(u_int msr, uint64_t data) */
+       PUSH_FRAME_POINTER
        movq    PCPU(CURPCB),%r8
        movq    $msr_onfault,PCB_ONFAULT(%r8)
        movl    %edi,%ecx
@@ -737,6 +782,7 @@ ENTRY(wrmsr_safe)
                                   hi byte in edx, lo in %eax. */
        xorq    %rax,%rax
        movq    %rax,PCB_ONFAULT(%r8)
+       POP_FRAME_POINTER
        ret
 
 /*
@@ -746,4 +792,5 @@ ENTRY(wrmsr_safe)
 msr_onfault:
        movq    $0,PCB_ONFAULT(%r8)
        movl    $EFAULT,%eax
+       POP_FRAME_POINTER
        ret

Modified: head/sys/amd64/include/asmacros.h
==============================================================================
--- head/sys/amd64/include/asmacros.h   Thu Nov 13 22:06:57 2014        
(r274488)
+++ head/sys/amd64/include/asmacros.h   Thu Nov 13 22:11:44 2014        
(r274489)
@@ -132,6 +132,16 @@
 #define MEXITCOUNT
 #endif /* GPROF */
 
+/*
+ * Convenience for adding frame pointers to hand-coded ASM.  Useful for
+ * DTrace, HWPMC, and KDB.
+ */
+#define PUSH_FRAME_POINTER     \
+       pushq   %rbp ;          \
+       movq    %rsp, %rbp ;
+#define POP_FRAME_POINTER      \
+       popq    %rbp
+
 #ifdef LOCORE
 /*
  * Convenience macro for declaring interrupt entry points.
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to