From: Liu Yuan <[email protected]>

Signed-off-by: Liu Yuan <[email protected]>
---
 include/util.h       |    2 +
 sheep/trace/mcount.S |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sheep/trace/trace.h  |   10 +++++++
 3 files changed, 78 insertions(+), 0 deletions(-)
 create mode 100644 sheep/trace/mcount.S
 create mode 100644 sheep/trace/trace.h

diff --git a/include/util.h b/include/util.h
index 725c8f8..ff86a00 100644
--- a/include/util.h
+++ b/include/util.h
@@ -28,6 +28,8 @@
 #define __cpu_to_le32(x) bswap_32(x)
 #endif
 
+#define notrace __attribute__((no_instrument_function))
+
 static inline int before(uint32_t seq1, uint32_t seq2)
 {
         return (int32_t)(seq1 - seq2) < 0;
diff --git a/sheep/trace/mcount.S b/sheep/trace/mcount.S
new file mode 100644
index 0000000..c16e5ae
--- /dev/null
+++ b/sheep/trace/mcount.S
@@ -0,0 +1,66 @@
+#define __ASSEMBLY__
+#include "trace.h"
+
+#define _ALIGN_TEXT .align 16, 0x90
+
+#define ENTRY(x) \
+        .text; _ALIGN_TEXT; .globl x; .type x,@function; x:
+
+ENTRY(mcount)
+       subq $0x38, %rsp
+       movq %rax, (%rsp)
+       movq %rcx, 8(%rsp)
+       movq %rdx, 16(%rsp)
+       movq %rsi, 24(%rsp)
+       movq %rdi, 32(%rsp)
+       movq %r8, 40(%rsp)
+       movq %r9, 48(%rsp)
+
+       movq 0x38(%rsp), %rdi
+       subq $INSN_SIZE, %rdi
+
+.globl mcount_call
+mcount_call:
+       call trace_stub
+
+       movq 48(%rsp), %r9
+       movq 40(%rsp), %r8
+       movq 32(%rsp), %rdi
+       movq 24(%rsp), %rsi
+       movq 16(%rsp), %rdx
+       movq 8(%rsp), %rcx
+       movq (%rsp), %rax
+       addq $0x38, %rsp
+
+       retq
+
+ENTRY(trace_caller)
+       subq $0x38, %rsp
+       movq %rax, (%rsp)
+       movq %rcx, 8(%rsp)
+       movq %rdx, 16(%rsp)
+       movq %rsi, 24(%rsp)
+       movq %rdi, 32(%rsp)
+       movq %r8, 40(%rsp)
+       movq %r9, 48(%rsp)
+
+       movq 0x38(%rsp), %rdi
+       movq 8(%rbp), %rsi
+       subq $INSN_SIZE, %rdi
+
+.globl trace_call
+trace_call:
+       call trace_stub
+
+       movq 48(%rsp), %r9
+       movq 40(%rsp), %r8
+       movq 32(%rsp), %rdi
+       movq 24(%rsp), %rsi
+       movq 16(%rsp), %rdx
+       movq 8(%rsp), %rcx
+       movq (%rsp), %rax
+       addq $0x38, %rsp
+
+.globl trace_stub
+trace_stub:
+       retq
diff --git a/sheep/trace/trace.h b/sheep/trace/trace.h
new file mode 100644
index 0000000..3e675e1
--- /dev/null
+++ b/sheep/trace/trace.h
@@ -0,0 +1,10 @@
+#ifndef TRACE_H
+#define TRACE_H
+
+/* mcount.S */
+extern void mcount(void);
+extern void mcount_call(void);
+extern void trace_caller(void);
+extern void trace_call(unsigned long, unsigned long *);
+
+#endif
-- 
1.7.8.2

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to