• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* <copyright>
2  This file is provided under a dual BSD/GPLv2 license.  When using or
3  redistributing this file, you may do so under either license.
4
5  GPL LICENSE SUMMARY
6
7  Copyright (c) 2017-2020 Intel Corporation. All rights reserved.
8
9  This program is free software; you can redistribute it and/or modify
10  it under the terms of version 2 of the GNU General Public License as
11  published by the Free Software Foundation.
12
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21  The full GNU General Public License is included in this distribution
22  in the file called LICENSE.GPL.
23
24  Contact Information:
25  http://software.intel.com/en-us/articles/intel-vtune-amplifier-xe/
26
27  BSD LICENSE
28
29  Copyright (c) 2017-2020 Intel Corporation. All rights reserved.
30  All rights reserved.
31
32  Redistribution and use in source and binary forms, with or without
33  modification, are permitted provided that the following conditions
34  are met:
35
36    * Redistributions of source code must retain the above copyright
37      notice, this list of conditions and the following disclaimer.
38    * Redistributions in binary form must reproduce the above copyright
39      notice, this list of conditions and the following disclaimer in
40      the documentation and/or other materials provided with the
41      distribution.
42    * Neither the name of Intel Corporation nor the names of its
43      contributors may be used to endorse or promote products derived
44      from this software without specific prior written permission.
45
46  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
49  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
50  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
51  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
52  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
56  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57</copyright> */
58
59
60// /////////////////////////////////////////////////////////////////////////
61////// Intel Processor Trace Marker Functionality
62////////////////////////////////////////////////////////////////////////////
63
64        .text
65        .align  16
66        .globl  __itt_pt_mark
67        .globl  __itt_pt_event
68        .globl  __itt_pt_mark_event
69        .globl  __itt_pt_mark_threshold
70        .globl  __itt_pt_byte
71        .globl  __itt_pt_write
72
73/// void __itt_pt_mark(unsigned char index);
74__itt_pt_mark:
75        movzbl  4(%esp), %eax
76//        and     $0xff, %eax
77        lea     __itt_pt_mark_call_table(,%eax,4), %eax
78        jmp     *%eax
79        .align  4
80
81        .long   0, 1, 2, 3      // GUID
82        .long   0xfadefade
83
84__itt_pt_mark_call_table:
85///        .fill 256,4,(0x0000c2c3 | (( . - __itt_pt_mark_call_table) << 14))
86        ret
87        ret    $0x0
88        ret
89        ret    $0x1
90        ret
91        ret    $0x2
92        ret
93        ret    $0x3
94        ret
95        ret    $0x4
96        ret
97        ret    $0x5
98        ret
99        ret    $0x6
100        ret
101        ret    $0x7
102        ret
103        ret    $0x8
104        ret
105        ret    $0x9
106        ret
107        ret    $0xa
108        ret
109        ret    $0xb
110        ret
111        ret    $0xc
112        ret
113        ret    $0xd
114        ret
115        ret    $0xe
116        ret
117        ret    $0xf
118
119        ret
120        ret    $0x10
121        ret
122        ret    $0x11
123        ret
124        ret    $0x12
125        ret
126        ret    $0x13
127        ret
128        ret    $0x14
129        ret
130        ret    $0x15
131        ret
132        ret    $0x16
133        ret
134        ret    $0x17
135        ret
136        ret    $0x18
137        ret
138        ret    $0x19
139        ret
140        ret    $0x1a
141        ret
142        ret    $0x1b
143        ret
144        ret    $0x1c
145        ret
146        ret    $0x1d
147        ret
148        ret    $0x1e
149        ret
150        ret    $0x1f
151
152        ret
153        ret    $0x20
154        ret
155        ret    $0x21
156        ret
157        ret    $0x22
158        ret
159        ret    $0x23
160        ret
161        ret    $0x24
162        ret
163        ret    $0x25
164        ret
165        ret    $0x26
166        ret
167        ret    $0x27
168        ret
169        ret    $0x28
170        ret
171        ret    $0x29
172        ret
173        ret    $0x2a
174        ret
175        ret    $0x2b
176        ret
177        ret    $0x2c
178        ret
179        ret    $0x2d
180        ret
181        ret    $0x2e
182        ret
183        ret    $0x2f
184
185        ret
186        ret    $0x30
187        ret
188        ret    $0x31
189        ret
190        ret    $0x32
191        ret
192        ret    $0x33
193        ret
194        ret    $0x34
195        ret
196        ret    $0x35
197        ret
198        ret    $0x36
199        ret
200        ret    $0x37
201        ret
202        ret    $0x38
203        ret
204        ret    $0x39
205        ret
206        ret    $0x3a
207        ret
208        ret    $0x3b
209        ret
210        ret    $0x3c
211        ret
212        ret    $0x3d
213        ret
214        ret    $0x3e
215        ret
216        ret    $0x3f
217
218        ret
219        ret    $0x40
220        ret
221        ret    $0x41
222        ret
223        ret    $0x42
224        ret
225        ret    $0x43
226        ret
227        ret    $0x44
228        ret
229        ret    $0x45
230        ret
231        ret    $0x46
232        ret
233        ret    $0x47
234        ret
235        ret    $0x48
236        ret
237        ret    $0x49
238        ret
239        ret    $0x4a
240        ret
241        ret    $0x4b
242        ret
243        ret    $0x4c
244        ret
245        ret    $0x4d
246        ret
247        ret    $0x4e
248        ret
249        ret    $0x4f
250
251        ret
252        ret    $0x50
253        ret
254        ret    $0x51
255        ret
256        ret    $0x52
257        ret
258        ret    $0x53
259        ret
260        ret    $0x54
261        ret
262        ret    $0x55
263        ret
264        ret    $0x56
265        ret
266        ret    $0x57
267        ret
268        ret    $0x58
269        ret
270        ret    $0x59
271        ret
272        ret    $0x5a
273        ret
274        ret    $0x5b
275        ret
276        ret    $0x5c
277        ret
278        ret    $0x5d
279        ret
280        ret    $0x5e
281        ret
282        ret    $0x5f
283
284        ret
285        ret    $0x60
286        ret
287        ret    $0x61
288        ret
289        ret    $0x62
290        ret
291        ret    $0x63
292        ret
293        ret    $0x64
294        ret
295        ret    $0x65
296        ret
297        ret    $0x66
298        ret
299        ret    $0x67
300        ret
301        ret    $0x68
302        ret
303        ret    $0x69
304        ret
305        ret    $0x6a
306        ret
307        ret    $0x6b
308        ret
309        ret    $0x6c
310        ret
311        ret    $0x6d
312        ret
313        ret    $0x6e
314        ret
315        ret    $0x6f
316
317        ret
318        ret    $0x70
319        ret
320        ret    $0x71
321        ret
322        ret    $0x72
323        ret
324        ret    $0x73
325        ret
326        ret    $0x74
327        ret
328        ret    $0x75
329        ret
330        ret    $0x76
331        ret
332        ret    $0x77
333        ret
334        ret    $0x78
335        ret
336        ret    $0x79
337        ret
338        ret    $0x7a
339        ret
340        ret    $0x7b
341        ret
342        ret    $0x7c
343        ret
344        ret    $0x7d
345        ret
346        ret    $0x7e
347        ret
348        ret    $0x7f
349
350        ret
351        ret    $0x80
352        ret
353        ret    $0x81
354        ret
355        ret    $0x82
356        ret
357        ret    $0x83
358        ret
359        ret    $0x84
360        ret
361        ret    $0x85
362        ret
363        ret    $0x86
364        ret
365        ret    $0x87
366        ret
367        ret    $0x88
368        ret
369        ret    $0x89
370        ret
371        ret    $0x8a
372        ret
373        ret    $0x8b
374        ret
375        ret    $0x8c
376        ret
377        ret    $0x8d
378        ret
379        ret    $0x8e
380        ret
381        ret    $0x8f
382
383        ret
384        ret    $0x90
385        ret
386        ret    $0x91
387        ret
388        ret    $0x92
389        ret
390        ret    $0x93
391        ret
392        ret    $0x94
393        ret
394        ret    $0x95
395        ret
396        ret    $0x96
397        ret
398        ret    $0x97
399        ret
400        ret    $0x98
401        ret
402        ret    $0x99
403        ret
404        ret    $0x9a
405        ret
406        ret    $0x9b
407        ret
408        ret    $0x9c
409        ret
410        ret    $0x9d
411        ret
412        ret    $0x9e
413        ret
414        ret    $0x9f
415
416        ret
417        ret    $0xa0
418        ret
419        ret    $0xa1
420        ret
421        ret    $0xa2
422        ret
423        ret    $0xa3
424        ret
425        ret    $0xa4
426        ret
427        ret    $0xa5
428        ret
429        ret    $0xa6
430        ret
431        ret    $0xa7
432        ret
433        ret    $0xa8
434        ret
435        ret    $0xa9
436        ret
437        ret    $0xaa
438        ret
439        ret    $0xab
440        ret
441        ret    $0xac
442        ret
443        ret    $0xad
444        ret
445        ret    $0xae
446        ret
447        ret    $0xaf
448
449        ret
450        ret    $0xb0
451        ret
452        ret    $0xb1
453        ret
454        ret    $0xb2
455        ret
456        ret    $0xb3
457        ret
458        ret    $0xb4
459        ret
460        ret    $0xb5
461        ret
462        ret    $0xb6
463        ret
464        ret    $0xb7
465        ret
466        ret    $0xb8
467        ret
468        ret    $0xb9
469        ret
470        ret    $0xba
471        ret
472        ret    $0xbb
473        ret
474        ret    $0xbc
475        ret
476        ret    $0xbd
477        ret
478        ret    $0xbe
479        ret
480        ret    $0xbf
481
482        ret
483        ret    $0xc0
484        ret
485        ret    $0xc1
486        ret
487        ret    $0xc2
488        ret
489        ret    $0xc3
490        ret
491        ret    $0xc4
492        ret
493        ret    $0xc5
494        ret
495        ret    $0xc6
496        ret
497        ret    $0xc7
498        ret
499        ret    $0xc8
500        ret
501        ret    $0xc9
502        ret
503        ret    $0xca
504        ret
505        ret    $0xcb
506        ret
507        ret    $0xcc
508        ret
509        ret    $0xcd
510        ret
511        ret    $0xce
512        ret
513        ret    $0xcf
514
515        ret
516        ret    $0xd0
517        ret
518        ret    $0xd1
519        ret
520        ret    $0xd2
521        ret
522        ret    $0xd3
523        ret
524        ret    $0xd4
525        ret
526        ret    $0xd5
527        ret
528        ret    $0xd6
529        ret
530        ret    $0xd7
531        ret
532        ret    $0xd8
533        ret
534        ret    $0xd9
535        ret
536        ret    $0xda
537        ret
538        ret    $0xdb
539        ret
540        ret    $0xdc
541        ret
542        ret    $0xdd
543        ret
544        ret    $0xde
545        ret
546        ret    $0xdf
547
548        ret
549        ret    $0xe0
550        ret
551        ret    $0xe1
552        ret
553        ret    $0xe2
554        ret
555        ret    $0xe3
556        ret
557        ret    $0xe4
558        ret
559        ret    $0xe5
560        ret
561        ret    $0xe6
562        ret
563        ret    $0xe7
564        ret
565        ret    $0xe8
566        ret
567        ret    $0xe9
568        ret
569        ret    $0xea
570        ret
571        ret    $0xeb
572        ret
573        ret    $0xec
574        ret
575        ret    $0xed
576        ret
577        ret    $0xee
578        ret
579        ret    $0xef
580
581        ret
582        ret    $0xf0
583        ret
584        ret    $0xf1
585        ret
586        ret    $0xf2
587        ret
588        ret    $0xf3
589        ret
590        ret    $0xf4
591        ret
592        ret    $0xf5
593        ret
594        ret    $0xf6
595        ret
596        ret    $0xf7
597        ret
598        ret    $0xf8
599        ret
600        ret    $0xf9
601        ret
602        ret    $0xfa
603        ret
604        ret    $0xfb
605        ret
606        ret    $0xfc
607        ret
608        ret    $0xfd
609        ret
610        ret    $0xfe
611        ret
612        ret    $0xff
613
614        .align  16
615
616__itt_pt_byte:
617
618        movl    4(%esp), %ecx
619
620__itt_pt_byte_:
621
622        and     $0xff, %ecx
623        lea     __itt_pt_byte_call_table(,%ecx,1), %ecx
624        jmp     *%ecx
625
626        .align  4
627
628        .long   0, 1, 2, 3      // GUID
629        .long   0xfadedeaf
630
631__itt_pt_byte_call_table:
632
633        .fill   256,1,0xc3
634
635        .align  16
636
637__itt_pt_event:
638
639        push   %ecx
640        mov    8(%esp), %ecx
641        rdpmc
642
643        mov     %al,%cl
644        call    __itt_pt_byte_
645        shr     $8,%eax
646        mov     %al,%cl
647        call    __itt_pt_byte_
648        shr     $8,%eax
649        mov     %al,%cl
650        call    __itt_pt_byte_
651        shr     $8,%eax
652        mov     %al,%cl
653        call    __itt_pt_byte_
654
655        mov     %dl,%cl
656        call    __itt_pt_byte_
657        shr     $8,%edx
658        mov     %dl,%cl
659        call    __itt_pt_byte_
660        shr     $8,%edx
661        mov     %dl,%cl
662        call    __itt_pt_byte_
663        shr     $8,%edx
664        mov     %dl,%cl
665        call    __itt_pt_byte_
666
667        pop    %ecx
668        ret
669
670        .align  16
671
672__itt_pt_mark_event:
673
674        testl   $1,4(%esp)
675        jnz     odd
676        pushl   $0
677        call    __itt_pt_event
678        add     $2,%esp
679        jmp     __itt_pt_mark
680
681odd:
682        pushl  4(%esp)
683        call    __itt_pt_mark
684        add     $2,%esp
685        movl    $0,4(%esp)
686        jmp     __itt_pt_event
687
688
689        .align  16
690
691__itt_pt_flush:
692
693        lea     __itt_pt_mark_flush_1,%eax
694        jmp     *%eax
695
696        .align   16
697        nop
698__itt_pt_mark_flush_1:
699        lea     __itt_pt_mark_flush_2,%eax
700        jmp     *%eax
701
702        .align   16
703        nop
704        nop
705__itt_pt_mark_flush_2:
706        lea     __itt_pt_mark_flush_3,%eax
707        jmp     *%eax
708
709        .align   16
710        nop
711        nop
712        nop
713__itt_pt_mark_flush_3:
714        ret
715
716        .align  16
717
718// int __itt_pt_mark_threshold(unsigned char index, unsigned long long* tmp, int threshold);
719
720__itt_pt_mark_threshold:
721        //  4(%esp) == index
722        //  8(%esp) == tmp
723        // 12(%esp) == threshold
724        xor     %edx,%edx
725        xor     %eax,%eax
726
727        testl   $1,4(%esp)
728        jnz     mark_end
729mark_begin:
730        mov     $((1 << 30) + 1),%ecx
731        rdpmc
732        mov     8(%esp), %ecx
733        mov     %eax, (%ecx)
734        mov     %edx,4(%ecx)
735        jmp     __itt_pt_mark
736mark_end:
737        mov     $((1 << 30) + 1),%ecx
738        rdpmc
739        mov     8(%esp), %ecx
740        sub      (%ecx), %eax
741        sbb     4(%ecx), %edx
742
743        sub     12(%esp), %eax // threshold
744        jnc     found
745        sbb     $0, %edx
746        jnc     found
747        jmp     __itt_pt_mark
748found:
749        call    __itt_pt_mark
750        jmp     __itt_pt_flush
751
752// PTWRITE
753
754        .align  16
755
756// void __itt_pt_write(unsigned long long value);
757
758        .long   0, 1, 2, 3      // GUID
759
760__itt_pt_write:
761
762//        ptwrite dword ptr [esp + 4]
763        .byte   0xF3, 0x0F, 0xAE, 0x64, 0x24, 0x04
764        ret
765