├── .gitignore ├── LICENSE ├── README.md ├── SECURITY.md ├── examples ├── MT │ ├── pinball.mt │ │ ├── log.log.txt │ │ ├── log_0.0.dyn_text.bz2 │ │ ├── log_0.0.race.bz2 │ │ ├── log_0.0.reg.bz2 │ │ ├── log_0.0.result │ │ ├── log_0.0.sel.bz2 │ │ ├── log_0.0.sync_text.bz2 │ │ ├── log_0.1.dyn_text.bz2 │ │ ├── log_0.1.race.bz2 │ │ ├── log_0.1.reg.bz2 │ │ ├── log_0.1.result │ │ ├── log_0.1.sel.bz2 │ │ ├── log_0.1.sync_text.bz2 │ │ ├── log_0.2.dyn_text.bz2 │ │ ├── log_0.2.race.bz2 │ │ ├── log_0.2.reg.bz2 │ │ ├── log_0.2.result │ │ ├── log_0.2.sel.bz2 │ │ ├── log_0.2.sync_text.bz2 │ │ ├── log_0.3.dyn_text.bz2 │ │ ├── log_0.3.race.bz2 │ │ ├── log_0.3.reg.bz2 │ │ ├── log_0.3.result │ │ ├── log_0.3.sel.bz2 │ │ ├── log_0.3.sync_text.bz2 │ │ ├── log_0.4.dyn_text.bz2 │ │ ├── log_0.4.race.bz2 │ │ ├── log_0.4.reg.bz2 │ │ ├── log_0.4.result │ │ ├── log_0.4.sel.bz2 │ │ ├── log_0.4.sync_text.bz2 │ │ ├── log_0.address │ │ ├── log_0.global.log │ │ ├── log_0.procinfo.xml │ │ └── log_0.text.bz2 │ └── testMT.sh └── ST │ ├── README.SSE4.2 │ ├── pinball.SSE4.2 │ ├── region.0.dyn_text │ ├── region.0.reg │ ├── region.0.result │ ├── region.0.sel │ ├── region.address │ ├── region.cpuid.def │ ├── region.global.log │ ├── region.log.txt │ ├── region.procinfo.xml │ └── region.text │ ├── pinball.st │ ├── list │ ├── log.log.txt │ ├── log_0.0.dyn_text │ ├── log_0.0.race │ ├── log_0.0.reg │ ├── log_0.0.result │ ├── log_0.0.sel │ ├── log_0.0.sync_text │ ├── log_0.address │ ├── log_0.global.log │ ├── log_0.procinfo.xml │ └── log_0.text │ ├── testSSE4.2.sh │ └── testST.sh ├── instrumentation ├── basic_callbacks.c ├── environ.c ├── perf_callbacks.alt.c ├── perf_callbacks.c ├── set_heap.c └── sim_callbacks.c ├── pintools ├── EventCounter │ ├── README │ ├── event_counter.cpp │ ├── makefile │ └── makefile.rules ├── PinballSYSState │ ├── makefile │ ├── makefile.rules │ ├── pinball-sysstate.H │ ├── pinball-sysstate.cpp │ ├── pinplay-debugger-shell.H │ └── pinplay-debugger-shell.cpp ├── ProcessControl │ ├── HOWTO.criu │ ├── Makefile │ ├── README │ ├── pstree-icount.c │ ├── pstree-pccount.c │ ├── pstree-threadperf.c │ ├── pstree-timedrun.c │ ├── pstree.c │ ├── pstree.h │ └── startpaused.sh ├── README.sde.mbuild ├── ROIProbe │ ├── README.ROIperf │ ├── README.probe_control │ ├── ROIperf.cpp │ ├── environ.c │ ├── makefile │ ├── makefile.rules │ ├── probe_control.H │ ├── probe_control.cpp │ └── testls.sh └── build_kit.py ├── scripts ├── pinball.entry-addr.sh ├── pinball2elf.alt.perf.sh ├── pinball2elf.basic.sh ├── pinball2elf.perf.sh └── pinball2elf.sim.sh └── src ├── .cproject ├── .project ├── Makefile ├── lib ├── Makefile ├── libcle.s ├── libcle_c.c ├── libperfle.c ├── lte_lc.h └── lte_perf.h ├── lit2elf.cpp ├── lte_arch_state.cpp ├── lte_arch_state.h ├── lte_config.cpp ├── lte_config.h ├── lte_defs.h ├── lte_elf.cpp ├── lte_elf.h ├── lte_entry_point.cpp ├── lte_entry_point.h ├── lte_memimg.cpp ├── lte_memimg.h ├── lte_pinball.cpp ├── lte_pinball.h ├── lte_portability.cpp ├── lte_portability.h ├── lte_reg_enum.cpp ├── lte_reg_enum.h ├── lte_string.cpp ├── lte_string.h ├── lte_strtab.cpp ├── lte_strtab.h ├── lte_syself.h ├── lte_types.h ├── lte_utils.cpp ├── lte_utils.h ├── lte_x86.h ├── lte_x86_cr.h ├── lte_x86_fpu.h ├── lte_x86_gpr.cpp ├── lte_x86_gpr.h ├── lte_x86_ldt.h ├── lte_x86_sr.h ├── lte_x86_state.cpp ├── lte_x86_state.h ├── lte_x86_xstate.h └── startup ├── Makefile ├── dumpstart.pl ├── litstart32.s ├── litstart32_defs.s ├── litstart32_lit.s ├── litstart32_state.s ├── litstart32mt.s ├── litstart32mt_defs.s ├── litstart32mt_lit.s ├── litstart32mt_state.s ├── litstart64.s ├── litstart64_defs.s ├── litstart64_lit.s ├── litstart64_state.s ├── litstart64mt.s ├── litstart64mt_defs.s ├── litstart64mt_lit.s └── litstart64mt_state.s /.gitignore: -------------------------------------------------------------------------------- 1 | src/obj 2 | src/lib/*.o 3 | src/lib/*.a 4 | src/pinball2elf 5 | src/pinball2elfd 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | All Intel-developed code is released under BSD 3-clause "New" or "Revised" License 2 | 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | Intel is committed to rapidly addressing security vulnerabilities affecting our customers and providing clear guidance on the solution, impact, severity and mitigation. 3 | 4 | ## Reporting a Vulnerability 5 | Please report any security vulnerabilities in this project utilizing the guidelines [here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html). 6 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log.log.txt: -------------------------------------------------------------------------------- 1 | Enabled messages [UnixVersion()] 30 info: Informational messages (enabled by default) 2 | Logger finished sanity check 3 | Logger first configuration phase completed 4 | Region selector activated 5 | [0] Pinball basename: /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/thread/pinball/log 6 | Found VDSO area from Pin AUXV at 0x2aaaaaaca000:0x2aaaaaacb000 7 | Loading /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/thread/thread(0x000400000:0x000402213) 8 | Loading /lib64/ld-linux-x86-64.so.2(0x2aaaaaaab000:0x2aaaaaac9cbf) 9 | [0] Started logging thread OSPid: 174776 OSTid: 174776 10 | Replacing AT_SYSINFO_EHDR 11 | from AT_SYSINFO_EHDR, 0x2aaaaaaca000 12 | to AT_IGNORE,0 13 | Loading /lib64/libpthread.so.0(0x2aaac07d5000:0x2aaac09f13af) 14 | Loading /lib64/libc.so.6(0x2aaac0a73000:0x2aaac0dee8b7) 15 | [0] region-start 16 | [0] + RECEIVED AND PROCESSED START event: ip:0x2aaac0b517b8 time:Wed Jan 6 19:39:10 2021 17 | [1] Started logging thread OSPid: 174776 OSTid: 174783 18 | [2] Started logging thread OSPid: 174776 OSTid: 174782 19 | [0] Stopping all threads - processing controller event 20 | [0] Stopping all threads succeeded 21 | [0] + STARTING NEW REGION at: ip:0x2aaac0b517b8 time:Wed Jan 6 19:39:10 2021 22 | [0] Region# : 0 23 | [0] Region has 3 existing threads(s) 24 | [0] Resuming all threads - complied processing controller event 25 | [0] InitRegion : 0 26 | [2] InitRegion : 2 27 | [1] InitRegion : 1 28 | [3] Started logging thread OSPid: 174776 OSTid: 174794 29 | [3] InitRegion : 3 30 | [4] Started logging thread OSPid: 174776 OSTid: 174795 31 | [4] InitRegion : 4 32 | [2] ThreadFini: inside region. thread at 0x2aaac07dc8c4 @icount 2721 33 | [2] EndRegion called for pp_id: 2 34 | [2] End of Region at icount: 2721 35 | [2] ThreadFini: logger thread at 0x2aaac07dc8c4 36 | [1] ThreadFini: inside region. thread at 0x2aaac07dc8c4 @icount 6115 37 | [1] EndRegion called for pp_id: 1 38 | [1] End of Region at icount: 6115 39 | [1] ThreadFini: logger thread at 0x2aaac07dc8c4 40 | [4] ThreadFini: inside region. thread at 0x2aaac07dc8c4 @icount 3436 41 | [4] EndRegion called for pp_id: 4 42 | [4] End of Region at icount: 3436 43 | [4] ThreadFini: logger thread at 0x2aaac07dc8c4 44 | [3] ThreadFini: inside region. thread at 0x2aaac07dc8c4 @icount 3441 45 | [3] EndRegion called for pp_id: 3 46 | [3] End of Region at icount: 3441 47 | [3] ThreadFini: logger thread at 0x2aaac07dc8c4 48 | [0] ThreadFini: inside region. thread at 0x2aaac0b1ea56 @icount 10887 49 | [0] EndRegion called for pp_id: 0 50 | [0] End of Region at icount: 10887 51 | [0] ThreadFini: logger thread at 0x2aaac0b1ea56 52 | [0] Closing global resources. 53 | [0] RemoveVsyscallFromRanges: removed pages: 0 54 | [0] Wrote address ranges: pagecount: 560. Logged text pages count:560 Logged data pages count:0 (total logged pages:560) 55 | RemoveTextFileDuplications for /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/thread/pinball/log_0 56 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.0.dyn_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.0.dyn_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.0.race.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.0.race.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.0.reg.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.0.reg.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.0.result: -------------------------------------------------------------------------------- 1 | -- start of image-load-log --------------------------------------- 2 | Loading /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/thread/thread(0x000400000:0x000402213) 3 | Loading /lib64/ld-linux-x86-64.so.2(0x2aaaaaaab000:0x2aaaaaac9cbf) 4 | Loading /lib64/libpthread.so.0(0x2aaac07d5000:0x2aaac09f13af) 5 | Loading /lib64/libc.so.6(0x2aaac0a73000:0x2aaac0dee8b7) 6 | preloaded_image: 1 1 0x000000000 0x2aaaae792310 0x000403df8 0x000000000 /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/thread/thread 7 | preloaded_image: 2 0 0x2aaaaaaab000 0x2aaaae792310 0x2aaaaaccae70 0x2aaaaaaab000 /lib64/ld-linux-x86-64.so.2 8 | preloaded_image: 4 0 0x2aaac07d5000 0x2aaaae792310 0x2aaac09ecdb0 0x2aaac07d5000 /lib64/libpthread.so.0 9 | preloaded_image: 5 0 0x2aaac0a73000 0x2aaaae792310 0x2aaac0de8b60 0x2aaac0a73000 /lib64/libc.so.6 10 | -- end of image-load-log ----------------------------------------- 11 | copy_images: 0 12 | OSTid: 174776 13 | log_entries: 4 14 | ended_before_sc: 0 15 | num_logged_true_dependencies (RAW): 15 16 | num_logged_false_dependencies (WAR/WAW): 25 17 | num_signals 0 18 | num_syscalls: 20 19 | inscount: 10887 20 | ip_type:last_pc: 0x2aaac0b1ea56 21 | internal_repcount: 0 22 | ip_type: init_pc: 0x2aaac07dbf88 23 | restore_text_pc: 1 24 | ip_entry:restoretext_pc: 0x2aaac0aee961 25 | ip_entry:restoretext_pc: 0x2aaaaaab417b 26 | ip_entry:restoretext_pc: 0x2aaac0af9319 27 | ip_entry:restoretext_pc: 0x2aaac07dbb42 28 | ip_entry:restoretext_pc: 0x2aaac07dbb49 29 | ip_entry:restoretext_pc: 0x2aaac07dbb68 30 | ip_entry:restoretext_pc: 0x2aaac0b5ec38 31 | ip_entry:restoretext_pc: 0x2aaac0b4a8c7 32 | ip_entry:restoretext_pc: 0x2aaac0adc22d 33 | ip_entry:restoretext_pc: 0x2aaac0adc23a 34 | ip_entry:restoretext_pc: 0x2aaac0af6732 35 | ip_entry:restoretext_pc: 0x2aaac0adc252 36 | ip_entry:restoretext_pc: 0x2aaac0adc293 37 | ip_entry:restoretext_pc: 0x2aaac0af0789 38 | ip_entry:restoretext_pc: 0x2aaac0b51795 39 | ip_entry:restoretext_pc: 0x2aaac07dbfa7 40 | ip_entry:restoretext_pc: 0x2aaac07dc02d 41 | ip_entry:restoretext_pc: 0x00040135c 42 | ip_entry:restoretext_pc: 0x00040136b 43 | ip_entry:restoretext_pc: 0x000401380 44 | ip_entry:restoretext_pc: 0x2aaaaaac21b0 45 | ip_entry:restoretext_pc: 0x2aaaaaac16f0 46 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.0.sel.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.0.sel.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.0.sync_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.0.sync_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.1.dyn_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.1.dyn_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.1.race.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.1.race.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.1.reg.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.1.reg.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.1.result: -------------------------------------------------------------------------------- 1 | -- start of image-load-log --------------------------------------- 2 | -- end of image-load-log ----------------------------------------- 3 | copy_images: 0 4 | OSTid: 174783 5 | log_entries: 0 6 | ended_before_sc: 0 7 | num_logged_true_dependencies (RAW): 21 8 | num_logged_false_dependencies (WAR/WAW): 10 9 | num_signals 0 10 | num_syscalls: 8 11 | inscount: 6115 12 | ip_type:last_pc: 0x2aaac07dc8c4 13 | internal_repcount: 0 14 | ip_type: init_pc: 0x2aaac0b5e92e 15 | restore_text_pc: 1 16 | ip_entry:restoretext_pc: 0x2aaac0ac22b1 17 | ip_entry:restoretext_pc: 0x2aaac07d9fc6 18 | ip_entry:restoretext_pc: 0x2aaac0b5e92e 19 | ip_entry:restoretext_pc: 0x2aaac0b5e936 20 | ip_entry:restoretext_pc: 0x2aaac0b5e939 21 | ip_entry:restoretext_pc: 0x2aaac0b5e970 22 | ip_entry:restoretext_pc: 0x2aaaaaab417b 23 | ip_entry:restoretext_pc: 0x2aaac0ae7d6d 24 | ip_entry:restoretext_pc: 0x2aaac0ab9fcc 25 | ip_entry:restoretext_pc: 0x2aaaaaab41f6 26 | ip_entry:restoretext_pc: 0x2aaac07da1e0 27 | ip_entry:restoretext_pc: 0x2aaac07da1eb 28 | ip_entry:restoretext_pc: 0x2aaac07da230 29 | ip_entry:restoretext_pc: 0x2aaac0ae7efe 30 | ip_entry:restoretext_pc: 0x2aaac0ab9591 31 | ip_entry:restoretext_pc: 0x2aaac07daf2a 32 | ip_entry:restoretext_pc: 0x2aaaaaab8c2e 33 | ip_entry:restoretext_pc: 0x2aaac0abba27 34 | ip_entry:restoretext_pc: 0x2aaac0a918a0 35 | ip_entry:restoretext_pc: 0x2aaaaaab4422 36 | ip_entry:restoretext_pc: 0x2aaaaaab8c59 37 | ip_entry:restoretext_pc: 0x2aaaaaab4455 38 | ip_entry:restoretext_pc: 0x2aaac07dc80f 39 | ip_entry:restoretext_pc: 0x2aaac0ae988f 40 | ip_entry:restoretext_pc: 0x2aaaaaab44c5 41 | ip_entry:restoretext_pc: 0x2aaaaaab8cf3 42 | ip_entry:restoretext_pc: 0x2aaaaaabed50 43 | ip_entry:restoretext_pc: 0x2aaac0ab72eb 44 | ip_entry:restoretext_pc: 0x2aaaaaabed7e 45 | ip_entry:restoretext_pc: 0x2aaac0ab7321 46 | ip_entry:restoretext_pc: 0x2aaac0ab73aa 47 | ip_entry:restoretext_pc: 0x000401040 48 | ip_entry:restoretext_pc: 0x2aaac0ab73d7 49 | ip_entry:restoretext_pc: 0x000401080 50 | ip_entry:restoretext_pc: 0x2aaac0ab98c9 51 | ip_entry:restoretext_pc: 0x2aaac0ab74df 52 | ip_entry:restoretext_pc: 0x2aaac0ab759b 53 | ip_entry:restoretext_pc: 0x000401258 54 | ip_entry:restoretext_pc: 0x2aaaaaab9c10 55 | ip_entry:restoretext_pc: 0x2aaac0ab7779 56 | ip_entry:restoretext_pc: 0x2aaac0abcbf5 57 | ip_entry:restoretext_pc: 0x2aaaaaab4a25 58 | ip_entry:restoretext_pc: 0x2aaaaaac16f0 59 | ip_entry:restoretext_pc: 0x2aaaaaac16f2 60 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.1.sel.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.1.sel.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.1.sync_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.1.sync_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.2.dyn_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.2.dyn_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.2.race.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.2.race.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.2.reg.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.2.reg.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.2.result: -------------------------------------------------------------------------------- 1 | -- start of image-load-log --------------------------------------- 2 | -- end of image-load-log ----------------------------------------- 3 | copy_images: 0 4 | OSTid: 174782 5 | log_entries: 0 6 | ended_before_sc: 0 7 | num_logged_true_dependencies (RAW): 23 8 | num_logged_false_dependencies (WAR/WAW): 6 9 | num_signals 0 10 | num_syscalls: 8 11 | inscount: 2721 12 | ip_type:last_pc: 0x2aaac07dc8c4 13 | internal_repcount: 0 14 | ip_type: init_pc: 0x2aaac0ab7370 15 | restore_text_pc: 1 16 | ip_entry:restoretext_pc: 0x2aaaaaab4c18 17 | ip_entry:restoretext_pc: 0x2aaac0ac22b1 18 | ip_entry:restoretext_pc: 0x2aaac07d9fc6 19 | ip_entry:restoretext_pc: 0x2aaac0b5e948 20 | ip_entry:restoretext_pc: 0x2aaac0ab9fcc 21 | ip_entry:restoretext_pc: 0x2aaac07da1eb 22 | ip_entry:restoretext_pc: 0x2aaac07da230 23 | ip_entry:restoretext_pc: 0x2aaac0ae7efe 24 | ip_entry:restoretext_pc: 0x2aaac07da2d0 25 | ip_entry:restoretext_pc: 0x2aaaaaab4384 26 | ip_entry:restoretext_pc: 0x2aaac0a91860 27 | ip_entry:restoretext_pc: 0x2aaac07daf2a 28 | ip_entry:restoretext_pc: 0x2aaaaaab8c17 29 | ip_entry:restoretext_pc: 0x2aaaaaab8c1f 30 | ip_entry:restoretext_pc: 0x2aaaaaab8c2e 31 | ip_entry:restoretext_pc: 0x2aaac0a918a0 32 | ip_entry:restoretext_pc: 0x2aaac0ab721c 33 | ip_entry:restoretext_pc: 0x2aaaaaab8c59 34 | ip_entry:restoretext_pc: 0x2aaaaaab8c7b 35 | ip_entry:restoretext_pc: 0x2aaac0ab7250 36 | ip_entry:restoretext_pc: 0x2aaaaaab8c97 37 | ip_entry:restoretext_pc: 0x2aaac07dc80f 38 | ip_entry:restoretext_pc: 0x2aaaaaab44c5 39 | ip_entry:restoretext_pc: 0x2aaaaaab8cf3 40 | ip_entry:restoretext_pc: 0x2aaaaaabed50 41 | ip_entry:restoretext_pc: 0x2aaac0ab72eb 42 | ip_entry:restoretext_pc: 0x2aaaaaabed7e 43 | ip_entry:restoretext_pc: 0x2aaac0ab7321 44 | ip_entry:restoretext_pc: 0x2aaac0ab7370 45 | ip_entry:restoretext_pc: 0x2aaac0ab7373 46 | ip_entry:restoretext_pc: 0x2aaac0ab73aa 47 | ip_entry:restoretext_pc: 0x000401040 48 | ip_entry:restoretext_pc: 0x2aaac0ab73d7 49 | ip_entry:restoretext_pc: 0x000401080 50 | ip_entry:restoretext_pc: 0x2aaac0ab98c9 51 | ip_entry:restoretext_pc: 0x2aaac0adc293 52 | ip_entry:restoretext_pc: 0x000401258 53 | ip_entry:restoretext_pc: 0x2aaaaaab9c10 54 | ip_entry:restoretext_pc: 0x2aaac0abcc04 55 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.2.sel.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.2.sel.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.2.sync_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.2.sync_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.3.dyn_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.3.dyn_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.3.race.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.3.race.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.3.reg.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.3.reg.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.3.result: -------------------------------------------------------------------------------- 1 | -- start of image-load-log --------------------------------------- 2 | -- end of image-load-log ----------------------------------------- 3 | copy_images: 0 4 | OSTid: 174794 5 | log_entries: 0 6 | ended_before_sc: 0 7 | num_logged_true_dependencies (RAW): 19 8 | num_logged_false_dependencies (WAR/WAW): 9 9 | num_signals 0 10 | num_syscalls: 11 11 | inscount: 3441 12 | ip_type:last_pc: 0x2aaac07dc8c4 13 | internal_repcount: 0 14 | ip_type: init_pc: 0x2aaac0b517b1 15 | restore_text_pc: 1 16 | ip_entry:restoretext_pc: 0x2aaac0ac22a5 17 | ip_entry:restoretext_pc: 0x2aaac0ab9fcc 18 | ip_entry:restoretext_pc: 0x2aaac07da170 19 | ip_entry:restoretext_pc: 0x2aaac07da1e0 20 | ip_entry:restoretext_pc: 0x2aaac07da230 21 | ip_entry:restoretext_pc: 0x2aaac0ae7efe 22 | ip_entry:restoretext_pc: 0x2aaac07da2d0 23 | ip_entry:restoretext_pc: 0x2aaac0ab9591 24 | ip_entry:restoretext_pc: 0x2aaac0a91860 25 | ip_entry:restoretext_pc: 0x2aaac07daf2a 26 | ip_entry:restoretext_pc: 0x2aaac0abba27 27 | ip_entry:restoretext_pc: 0x2aaac0a918a0 28 | ip_entry:restoretext_pc: 0x2aaac0ab721c 29 | ip_entry:restoretext_pc: 0x2aaac0ab7250 30 | ip_entry:restoretext_pc: 0x2aaac07dc7c7 31 | ip_entry:restoretext_pc: 0x2aaac07dc7fe 32 | ip_entry:restoretext_pc: 0x2aaac0ab729e 33 | ip_entry:restoretext_pc: 0x2aaac0ae988f 34 | ip_entry:restoretext_pc: 0x2aaac0ab72eb 35 | ip_entry:restoretext_pc: 0x2aaac0ab7321 36 | ip_entry:restoretext_pc: 0x000401040 37 | ip_entry:restoretext_pc: 0x000401050 38 | ip_entry:restoretext_pc: 0x000401080 39 | ip_entry:restoretext_pc: 0x2aaac0ab98c9 40 | ip_entry:restoretext_pc: 0x2aaac0b517b1 41 | ip_entry:restoretext_pc: 0x2aaac0b517eb 42 | ip_entry:restoretext_pc: 0x2aaac0ab9b6c 43 | ip_entry:restoretext_pc: 0x2aaac0abcbe9 44 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.3.sel.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.3.sel.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.3.sync_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.3.sync_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.4.dyn_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.4.dyn_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.4.race.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.4.race.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.4.reg.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.4.reg.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.4.result: -------------------------------------------------------------------------------- 1 | -- start of image-load-log --------------------------------------- 2 | -- end of image-load-log ----------------------------------------- 3 | copy_images: 0 4 | OSTid: 174795 5 | log_entries: 0 6 | ended_before_sc: 0 7 | num_logged_true_dependencies (RAW): 14 8 | num_logged_false_dependencies (WAR/WAW): 9 9 | num_signals 0 10 | num_syscalls: 11 11 | inscount: 3436 12 | ip_type:last_pc: 0x2aaac07dc8c4 13 | internal_repcount: 0 14 | ip_type: init_pc: 0x2aaac0b517b1 15 | restore_text_pc: 1 16 | ip_entry:restoretext_pc: 0x2aaac0ac22a5 17 | ip_entry:restoretext_pc: 0x2aaac0ab9fcc 18 | ip_entry:restoretext_pc: 0x2aaac07da170 19 | ip_entry:restoretext_pc: 0x2aaac07da1e0 20 | ip_entry:restoretext_pc: 0x2aaac07da230 21 | ip_entry:restoretext_pc: 0x2aaac0ae7efe 22 | ip_entry:restoretext_pc: 0x2aaac07da2d0 23 | ip_entry:restoretext_pc: 0x2aaac0ab9591 24 | ip_entry:restoretext_pc: 0x2aaac0a91860 25 | ip_entry:restoretext_pc: 0x2aaac07daf2a 26 | ip_entry:restoretext_pc: 0x2aaac0abba27 27 | ip_entry:restoretext_pc: 0x2aaac0a918a0 28 | ip_entry:restoretext_pc: 0x2aaac0ab721c 29 | ip_entry:restoretext_pc: 0x2aaac0ab7250 30 | ip_entry:restoretext_pc: 0x2aaac07dc7c7 31 | ip_entry:restoretext_pc: 0x2aaac07dc7fe 32 | ip_entry:restoretext_pc: 0x2aaac0ab729e 33 | ip_entry:restoretext_pc: 0x2aaac0ae988f 34 | ip_entry:restoretext_pc: 0x2aaac0ab72eb 35 | ip_entry:restoretext_pc: 0x2aaac0ab7321 36 | ip_entry:restoretext_pc: 0x000401040 37 | ip_entry:restoretext_pc: 0x000401050 38 | ip_entry:restoretext_pc: 0x000401080 39 | ip_entry:restoretext_pc: 0x2aaac0ab98c9 40 | ip_entry:restoretext_pc: 0x2aaac0b517b1 41 | ip_entry:restoretext_pc: 0x2aaac0b517eb 42 | ip_entry:restoretext_pc: 0x2aaac0ab9b6c 43 | ip_entry:restoretext_pc: 0x2aaac0abcbe9 44 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.4.sel.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.4.sel.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.4.sync_text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.4.sync_text.bz2 -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.address: -------------------------------------------------------------------------------- 1 | 0x000400000 0x000467000 data 0 2 | 0x2aaaaaaab000 0x2aaaaaaca000 text 0 3 | 0x2aaaaacca000 0x2aaaaaccd000 text 0 4 | 0x2aaac05f4000 0x2aaac05f5000 text 0 5 | 0x2aaac07d5000 0x2aaac07ec000 text 0 6 | 0x2aaac09ec000 0x2aaac09f2000 data 0 7 | 0x2aaac0a0f000 0x2aaac0a10000 text 0 8 | 0x2aaac0a19000 0x2aaac0a1a000 text 0 9 | 0x2aaac0a73000 0x2aaac0be5000 text 0 10 | 0x2aaac0de5000 0x2aaac0def000 data 0 11 | 0x2aaac0e20000 0x2aaac0e21000 data 0 12 | 0x2aaac1bf1000 0x2aaac1bf3000 text 0 13 | 0x2aaac279b000 0x2aaac279d000 text 0 14 | 0x2aaacb783000 0x2aaacb785000 text 0 15 | 0x2aaacc455000 0x2aaacc457000 data 0 16 | 0x7fffffff8000 0x7fffffff9000 text 0 17 | 0x7fffffffa000 0x7fffffffb000 data 0 18 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.global.log: -------------------------------------------------------------------------------- 1 | pin-command-line: /nfs/mmdc/disks/tpi4/proj/ThreadPoints/NUSingapore/pinplay-7-3-2020-pin-3.13-98189-g60a6ef199-gcc-linux/intel64/bin/pinbin -p32 /nfs/mmdc/disks/tpi4/proj/ThreadPoints/NUSingapore/pinplay-7-3-2020-pin-3.13-98189-g60a6ef199-gcc-linux/ia32/bin/pinbin -follow_execv -t /nfs/mmdc/disks/tpi4/proj/ThreadPoints/NUSingapore/pinplay-7-3-2020-pin-3.13-98189-g60a6ef199-gcc-linux/extras/pinplay/bin/intel64/pinplay-driver.so -log -xyzzy -log:basename pinball/log -log:mt 1 -log:compressed bzip2 -log:region_id -log:whole_image -log:pages_early 1 -log:control start:exit_func:__clone:count3 2 | app-command-line: thread 4 3 | OSPid: 174776 4 | fat: 1 5 | lit: 0 6 | user_name: hgpatil 7 | OS_info: Linux hdcr0109 3.0.101-108.87-default #1 SMP Fri Feb 22 16:42:57 UTC 2019 (10e85a8) intel64 8 | relogged: 0 9 | arch: x86_64 10 | num_static_threads: 5 11 | num_dynamic_threads: 3 12 | num_threads_started: 5 13 | log creation date/time: Wed Jan 6 19:39:11 2021 14 | log format version: 2.11 15 | charm revision: 98189 16 | linker_break_address: 0x2aaaaaab9b70 17 | data_page_size: 4096 18 | text_page_size: 4096 19 | vdso_address: 0x2aaaaaaca000 0x2aaaaaacb000 20 | ip_entry:syscall: 0x2aaac07dc793 L64 21 | ip_entry:syscall: 0x2aaac07dc8c4 L64 22 | ip_entry:syscall: 0x2aaac07dcfe3 L64 23 | ip_entry:syscall: 0x2aaac0b1ea56 L64 24 | ip_entry:syscall: 0x2aaac0b43d8b L64 25 | ip_entry:syscall: 0x2aaac0b4e398 L64 26 | ip_entry:syscall: 0x2aaac0b4e3f5 L64 27 | ip_entry:syscall: 0x2aaac0b4e485 L64 28 | ip_entry:syscall: 0x2aaac0b517af L64 29 | ip_entry:syscall: 0x2aaac0b5e92c L64 30 | ip_entry:syscall: 0x2aaac0b5e95d L64 31 | num_reg_descs: 132 32 | rax 0 8 33 | eax 1 4 34 | ax 2 2 35 | ah 3 1 36 | al 4 1 37 | rcx 5 8 38 | ecx 6 4 39 | cx 7 2 40 | ch 8 1 41 | cl 9 1 42 | rdx 10 8 43 | edx 11 4 44 | dx 12 2 45 | dh 13 1 46 | dl 14 1 47 | rbx 15 8 48 | ebx 16 4 49 | bx 17 2 50 | bh 18 1 51 | bl 19 1 52 | rsp 20 8 53 | esp 21 4 54 | sp 22 2 55 | spl 23 1 56 | rbp 24 8 57 | ebp 25 4 58 | bp 26 2 59 | bpl 27 1 60 | rsi 28 8 61 | esi 29 4 62 | si 30 2 63 | sil 31 1 64 | rdi 32 8 65 | edi 33 4 66 | di 34 2 67 | dil 35 1 68 | r8 36 8 69 | r8d 37 4 70 | r8w 38 2 71 | r8b 39 1 72 | r9 40 8 73 | r9d 41 4 74 | r9w 42 2 75 | r9b 43 1 76 | r10 44 8 77 | r10d 45 4 78 | r10w 46 2 79 | r10b 47 1 80 | r11 48 8 81 | r11d 49 4 82 | r11w 50 2 83 | r11b 51 1 84 | r12 52 8 85 | r12d 53 4 86 | r12w 54 2 87 | r12b 55 1 88 | r13 56 8 89 | r13d 57 4 90 | r13w 58 2 91 | r13b 59 1 92 | r14 60 8 93 | r14d 61 4 94 | r14w 62 2 95 | r14b 63 1 96 | r15 64 8 97 | r15d 65 4 98 | r15w 66 2 99 | r15b 67 1 100 | rip 68 8 101 | eip 69 4 102 | ip 70 2 103 | rflags 71 8 104 | eflags 72 4 105 | flags 73 2 106 | cs 74 2 107 | ds 75 2 108 | es 76 2 109 | ss 77 2 110 | fs 78 2 111 | gs 79 2 112 | fs-base 80 8 113 | gs-base 81 8 114 | fcw 82 2 115 | fsw 83 2 116 | ftw 84 1 117 | fop 85 2 118 | fpuip 86 4 119 | x87cs 87 2 120 | fpudp 88 4 121 | x87ds 89 2 122 | st0 90 10 123 | st1 91 10 124 | st2 92 10 125 | st3 93 10 126 | st4 94 10 127 | st5 95 10 128 | st6 96 10 129 | st7 97 10 130 | mxcsr 98 4 131 | xcr0 99 8 132 | XMM0 100 16 133 | YMM0 101 32 134 | XMM1 102 16 135 | YMM1 103 32 136 | XMM2 104 16 137 | YMM2 105 32 138 | XMM3 106 16 139 | YMM3 107 32 140 | XMM4 108 16 141 | YMM4 109 32 142 | XMM5 110 16 143 | YMM5 111 32 144 | XMM6 112 16 145 | YMM6 113 32 146 | XMM7 114 16 147 | YMM7 115 32 148 | XMM8 116 16 149 | YMM8 117 32 150 | XMM9 118 16 151 | YMM9 119 32 152 | XMM10 120 16 153 | YMM10 121 32 154 | XMM11 122 16 155 | YMM11 123 32 156 | XMM12 124 16 157 | YMM12 125 32 158 | XMM13 126 16 159 | YMM13 127 32 160 | XMM14 128 16 161 | YMM14 129 32 162 | XMM15 130 16 163 | YMM15 131 32 164 | ip_entry:image_load: 0x00040135c 165 | ip_entry:image_load: 0x2aaaaaabed20 166 | ip_entry:image_load: 0x2aaac07dbf88 167 | ip_entry:image_load: 0x2aaac0ab7370 168 | smc_granularity: 128 169 | -------------------------------------------------------------------------------- /examples/MT/pinball.mt/log_0.text.bz2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/MT/pinball.mt/log_0.text.bz2 -------------------------------------------------------------------------------- /examples/MT/testMT.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export ELFIE_COREBASE=0 3 | if [ -e ../../scripts ]; 4 | then 5 | SCRIPTLOC=../../scripts/ 6 | BASICSCRIPT=$SCRIPTLOC/pinball2elf.basic.sh 7 | PERFSCRIPT=$SCRIPTLOC/pinball2elf.perf.sh 8 | else 9 | which pinball2elf.basic.sh 10 | if [ $? -ne 0 ]; 11 | then 12 | echo " Please put PINBALL2ELFKIT/scripts in your PATH" 13 | exit 14 | fi 15 | BASICSCRIPT=`which pinball2elf.basic.sh` 16 | PERFSCRIPT=`which pinball2elf.perf.sh` 17 | fi 18 | 19 | pinball=pinball.mt/log_0 20 | pbname=`basename $pinball` 21 | 22 | echo " Running $PERFSCRIPT $pinball" 23 | $PERFSCRIPT $pinball mt > /dev/null 2>&1 24 | if ! test "$( find . -name "$pbname.perf.elfie" -print -quit)" 25 | then 26 | echo "**Failed command: '$PERFSCRIPT $pinball'" 27 | exit 28 | fi 29 | elfie=`find . -name "$pbname.perf.elfie"` 30 | export ELFIE_PERFLIST="0:0,0:1,1:1" 31 | echo " export ELFIE_PERFLIST=$ELFIE_PERFLIST" 32 | echo " [ based on /usr/include/linux/perf_event.h" 33 | echo " Comma separeted pairs 'perftype:counter'" 34 | echo " perftype: 0 --> HW 1 --> SW" 35 | echo " HW counter: 0 --> PERF_COUNT_HW_CPU_CYCLES" 36 | echo " HW counter: 1 --> PERF_COUNT_HW_CPU_INSTRUCTIONS" 37 | echo " SW counter: 0 --> PERF_COUNT_SW_CPU_CLOCK" 38 | echo " ... Output 14 | # EAX ECX => EAX EBX ECX EDX 15 | 00000000 ******** => 0000000b 756e6547 6c65746e 49656e69 16 | 00000001 ******** => 000106a5 06100800 009ce3bd bfebfbff 17 | 00000002 ******** => 55035a01 00f0b2e4 00000000 09ca212c 18 | 00000004 00000000 => 1c004121 01c0003f 0000003f 00000000 19 | 00000004 00000001 => 1c004122 00c0003f 0000007f 00000000 20 | 00000004 00000002 => 1c004143 01c0003f 000001ff 00000000 21 | 00000004 00000003 => 1c03c163 03c0003f 00001fff 00000002 22 | 00000005 ******** => 00000040 00000040 00000003 00001120 23 | 00000006 ******** => 00000003 00000002 00000001 00000000 24 | 00000007 00000000 => 00000000 00000000 00000000 00000000 25 | 0000000a ******** => 07300403 00000044 00000000 00000603 26 | 0000000b 00000000 => 00000001 00000002 00000100 00000006 27 | 0000000b 00000001 => 00000004 00000008 00000201 00000006 28 | 0000000b 00000002 => 00000000 00000000 00000002 00000006 29 | 0000000b 00000003 => 00000000 00000000 00000003 00000006 30 | 0000000b 00000004 => 00000000 00000000 00000004 00000006 31 | 80000000 ******** => 80000008 00000000 00000000 00000000 32 | 80000001 ******** => 00000000 00000000 00000001 28100800 33 | 80000002 ******** => 65746e49 2952286c 6f655820 2952286e 34 | 80000003 ******** => 55504320 20202020 20202020 45202020 35 | 80000004 ******** => 30323535 20402020 37322e32 007a4847 36 | 80000006 ******** => 00000000 00000000 01006040 00000000 37 | 80000007 ******** => 00000000 00000000 00000000 00000100 38 | 80000008 ******** => 00003028 00000000 00000000 00000000 39 | -------------------------------------------------------------------------------- /examples/ST/pinball.SSE4.2/region.global.log: -------------------------------------------------------------------------------- 1 | sde-command-line: $SDEHOME/sde -nhm -control start:icount:50000000 -control stop:icount:50010000 -early_out -log -log:basename pinball.SSE4.2/region -log:fat -- ./base.exe 300 reference.dat 0 1 100_100_130_cf_b.of 2 | pin-command-line: $SDEHOME/intel64/pinbin -p32 $SDEHOME/ia32/pinbin -waiting_process 23260 -waiting_injector 23263 -sigchld_handler 1 -logfile hidden-path/pin-log.txt -xyzzy -bridge-save-mxcsr 0 -bridge-set-mxcsr 1 -cc_memory_size_64 1073741824 -use_sahf 0 -follow-execv -virtual_segments 1 -xed_ignore_unknown_reg -t64 $SDEHOME/intel64/sde-mix-mt.so -t $SDEHOME/ia32/sde-mix-mt.so -logfile hidden-path/pin-tool-log.txt -work-dir hidden-path -pinplay:work-dir hidden-path -chip-check NEHALEM -log -log:early-out -sync-avx512-state 0 -cpuid-in $SDEHOME/misc/cpuid/nhm/cpuid.def -control start:icount:50000000 -control stop:icount:50010000 -log:basename pinball.SSE4.2/region -log:fat 3 | app-command-line: ./base.exe 300 reference.dat 0 1 100_100_130_cf_b.of 4 | OSPid: 23260 5 | fat: 1 6 | lit: 0 7 | user_name: someone 8 | OS_info: some info 9 | relogged: 0 10 | arch: x86_64 11 | num_static_threads: 1 12 | num_dynamic_threads: 1 13 | num_threads_started: 1 14 | log creation date/time: Mon Apr 10 20:13:09 2023 15 | log format version: 2.16 16 | charm revision: 98650 17 | linker_break_address: 0x2aaaaaaba6d0 18 | data_page_size: 4096 19 | text_page_size: 4096 20 | vdso_address: 0x2aaaaaacf000 0x2aaaaaad1000 21 | num_reg_descs: 115 22 | RAX 0 8 23 | EAX 1 4 24 | AX 2 2 25 | AH 3 1 26 | AL 4 1 27 | RCX 5 8 28 | ECX 6 4 29 | CX 7 2 30 | CH 8 1 31 | CL 9 1 32 | RDX 10 8 33 | EDX 11 4 34 | DX 12 2 35 | DH 13 1 36 | DL 14 1 37 | RBX 15 8 38 | EBX 16 4 39 | BX 17 2 40 | BH 18 1 41 | BL 19 1 42 | RSP 20 8 43 | ESP 21 4 44 | SP 22 2 45 | SPL 23 1 46 | RBP 24 8 47 | EBP 25 4 48 | BP 26 2 49 | BPL 27 1 50 | RSI 28 8 51 | ESI 29 4 52 | SI 30 2 53 | SIL 31 1 54 | RDI 32 8 55 | EDI 33 4 56 | DI 34 2 57 | DIL 35 1 58 | R8 36 8 59 | R8D 37 4 60 | R8W 38 2 61 | R8B 39 1 62 | R9 40 8 63 | R9D 41 4 64 | R9W 42 2 65 | R9B 43 1 66 | R10 44 8 67 | R10D 45 4 68 | R10W 46 2 69 | R10B 47 1 70 | R11 48 8 71 | R11D 49 4 72 | R11W 50 2 73 | R11B 51 1 74 | R12 52 8 75 | R12D 53 4 76 | R12W 54 2 77 | R12B 55 1 78 | R13 56 8 79 | R13D 57 4 80 | R13W 58 2 81 | R13B 59 1 82 | R14 60 8 83 | R14D 61 4 84 | R14W 62 2 85 | R14B 63 1 86 | R15 64 8 87 | R15D 65 4 88 | R15W 66 2 89 | R15B 67 1 90 | RIP 68 8 91 | EIP 69 4 92 | IP 70 2 93 | RFLAGS 71 8 94 | EFLAGS 72 4 95 | FLAGS 73 2 96 | CS 74 2 97 | DS 75 2 98 | ES 76 2 99 | SS 77 2 100 | FS 78 2 101 | GS 79 2 102 | FS-BASE 80 8 103 | GS-BASE 81 8 104 | MXCSR 82 4 105 | FCW 84 2 106 | FSW 85 2 107 | FTW 86 1 108 | FOP 87 2 109 | FPUIP 88 4 110 | X87CS 89 2 111 | FPUDP 90 4 112 | X87DS 91 2 113 | ST0 92 10 114 | ST1 93 10 115 | ST2 94 10 116 | ST3 95 10 117 | ST4 96 10 118 | ST5 97 10 119 | ST6 98 10 120 | ST7 99 10 121 | XMM0 100 16 122 | XMM1 101 16 123 | XMM2 102 16 124 | XMM3 103 16 125 | XMM4 104 16 126 | XMM5 105 16 127 | XMM6 106 16 128 | XMM7 107 16 129 | XMM8 108 16 130 | XMM9 109 16 131 | XMM10 110 16 132 | XMM11 111 16 133 | XMM12 112 16 134 | XMM13 113 16 135 | XMM14 114 16 136 | XMM15 115 16 137 | ip_entry:image_load: 0x00040158e 138 | ip_entry:image_load: 0x2aaaf0dd3b00 139 | mem_injections_ip_optimization: 1 140 | smc_granularity: 128 141 | xinuse_emulate: 1 142 | -------------------------------------------------------------------------------- /examples/ST/pinball.SSE4.2/region.log.txt: -------------------------------------------------------------------------------- 1 | Enabled messages [UnixVersion()] 52 info: Informational messages (enabled by default) 2 | Logger finished sanity check 3 | Logger first configuration phase completed 4 | Region selector activated 5 | [0] Pinball basename: hidden-path/pinball.SSE4.2/region 6 | Found VDSO area from Pin AUXV at 0x2aaaaaacf000:0x2aaaaaad1000 7 | Loading hidden-path/base.exe(0x000400000:0x00040cafb) 8 | Loading /lib64/ld-linux-x86-64.so.2(0x2aaaaaaab000:0x2aaaaaacbda3) 9 | [0] Started logging thread OSPid: 23260 OSTid: 23260 10 | Replacing AT_SYSINFO_EHDR 11 | from AT_SYSINFO_EHDR, 0x2aaaaaacf000 12 | to AT_IGNORE,0 13 | Loading /lib64/libm.so.6(0x2aaaf0747000:0x2aaaf0a43147) 14 | Loading /lib64/libgcc_s.so.1(0x2aaaf0b46000:0x2aaaf0d5d447) 15 | Loading /lib64/libc.so.6(0x2aaaf0d5e000:0x2aaaf1102a77) 16 | Loading /lib64/libdl.so.2(0x2aaaf1103000:0x2aaaf13060ef) 17 | [0] region-start 18 | [0] + RECEIVED AND PROCESSED START event: ip:0x0004015ab time:Mon Apr 10 20:13:09 2023 19 | [0] Stopping all threads - processing controller event 20 | [0] Stopping all threads succeeded 21 | [0] + STARTING NEW REGION at: ip:0x0004015b0 time:Mon Apr 10 20:13:09 2023 22 | [0] Region# : 0 23 | [0] Region has 1 existing threads(s) 24 | [0] SyncThreads clear pending event 25 | [0] Resuming all threads - complied processing controller event 26 | [0] InitRegion : 0 27 | [0] region-end 28 | [0] + RECEIVED STOP event: icount: 9997 time:Mon Apr 10 20:13:09 2023 29 | [0] Stopping all threads - processing controller event 30 | [0] Stopping all threads succeeded 31 | [0] EndRegion called for pp_id: 0 32 | [0] End of Region at icount: 10009 33 | [0] Closing global resources. 34 | [0] RemoveVsyscallFromRanges: removed pages: 0 35 | [0] Wrote address ranges: pagecount: 758. Logged text pages count:758 Logged data pages count:0 (total logged pages:758) 36 | RemoveTextFileDuplications for hidden-path/pinball.SSE4.2/region 37 | [0] SUCCESSFULLY CLOSED ALL TRACE FILES AT REGION END. 38 | [0] Exiting due to log:early_out ic: 10009 39 | [0] ThreadFini: logger thread at 0x2aaaf0e4155e 40 | [0] Unloading hidden-path/base.exe image id 1 icount 10009 41 | [0] Unloading /lib64/ld-linux-x86-64.so.2 image id 2 icount 10009 42 | [0] Unloading [vdso] image id 3 icount 10009 43 | [0] Unloading /lib64/libm.so.6 image id 4 icount 10009 44 | [0] Unloading /lib64/libgcc_s.so.1 image id 5 icount 10009 45 | [0] Unloading /lib64/libc.so.6 image id 6 icount 10009 46 | [0] Unloading /lib64/libdl.so.2 image id 7 icount 10009 47 | [0] EndRegion called for pp_id: 0 48 | -------------------------------------------------------------------------------- /examples/ST/pinball.st/list: -------------------------------------------------------------------------------- 1 | log_0.0.dyn_text.bz2 2 | log_0.0.race.bz2 3 | log_0.0.reg.bz2 4 | log_0.0.sel.bz2 5 | log_0.0.sync_text.bz2 6 | log_0.text.bz2 7 | -------------------------------------------------------------------------------- /examples/ST/pinball.st/log.log.txt: -------------------------------------------------------------------------------- 1 | Enabled messages [UnixVersion()] 30 info: Informational messages (enabled by default) 2 | Logger finished sanity check 3 | Logger parsed command line arguments 4 | Logger initialized PIN symbols 5 | Memory logger configured 6 | Logger configured user name and host name 7 | Logger first configuration phase completed 8 | Region selector activated 9 | [0] Pinball basename: /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/hello/pinball.main/log 10 | Found VDSO area from Pin AUXV at 0x7ffff7ffb000:0x7ffff7ffc000 11 | Loading /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/hello/hello(0x000400000:0x0004006eb) 12 | Loading /lib64/ld-linux-x86-64.so.2(0x7ffff7ddd000:0x7ffff7dfbc47) 13 | [0] Started logging thread OSPid: 4786 OSTid: 4786 14 | Replacing AT_SYSINFO_EHDR 15 | from AT_SYSINFO_EHDR, 0x7ffff7ffb000 16 | to AT_IGNORE,0 17 | Loading /lib64/libc.so.6(0x7fffe2fcb000:0x7fffe33468b7) 18 | [0] region-start 19 | [0] + RECEIVED AND PROCESSED START event: ip:0x000400500 icount: 0 time:Wed Feb 8 08:24:25 2017 20 | [0] Stopping all threads - processing controller event 21 | [0] Stopping all threads succeeded 22 | [0] + STARTING NEW REGION at: ip:0x00040051e icount: 0 time:Wed Feb 8 08:24:25 2017 23 | [0] Region# : 0 24 | [0] Region has 1 existing threads(s) 25 | [0] Resuming all threads - complied processing controller event 26 | [0] InitRegion : 0 27 | [0] EndRegion called for pp_id: 0 28 | [0] ThreadFini: logger thread at 0x7fffe3076996 @icount 3922 29 | [0] Closing global resources. 30 | [0] RemoveSyscallFromRanges: removed pages: 0 31 | [0] Wrote address ranges: pagecount: 421. Logged text pages count:421 Logged data pages count:0 (total logged pages:421) 32 | -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.0.dyn_text: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/ST/pinball.st/log_0.0.dyn_text -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.0.race: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/ST/pinball.st/log_0.0.race -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.0.reg: -------------------------------------------------------------------------------- 1 | ic ;0 60 2 | 0 0 3 | 5 0 4 | 10 38d6ffffff7f 5 | 15 400540 6 | 20 38d5ffffff7f 7 | 24 50d5ffffff7f 8 | 28 01 9 | 32 e40540 10 | 36 202334e3ff7f 11 | 40 80b6def7ff7f 12 | 44 b0d3ffffff7f 13 | 48 509bfee2ff7f 14 | 52 f00340 15 | 56 20d6ffffff7f 16 | 60 0 17 | 64 0 18 | 68 d00340 19 | 71 0202 20 | 74 33 21 | 75 0 22 | 76 0 23 | 77 2b 24 | 78 0 25 | 79 0 26 | 80 0087f4e2ff7f 27 | 81 0 28 | 82 7f03 29 | 83 0 30 | 84 0 31 | 85 0 32 | 86 0 33 | 87 0 34 | 88 0 35 | 89 0 36 | 90 0 37 | 91 0 38 | 92 0 39 | 93 0 40 | 94 0 41 | 95 0 42 | 96 0 43 | 97 0 44 | 98 801f 45 | 99 07 46 | 101 00000000000000000000000000ff 47 | 103 2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f2f 48 | 105 0 49 | 107 00000000ff 50 | 109 0 51 | 111 0 52 | 113 0 53 | 115 0 54 | 117 0 55 | 119 0 56 | 121 0 57 | 123 0 58 | 125 0 59 | 127 0 60 | 129 0 61 | 131 0 62 | sc ;997 2 63 | 0 0 64 | 68 e4b009e3ff7f 65 | sc ;38 2 66 | 0 00a0eedeff7f 67 | 68 6a650ae3ff7f 68 | sc ;1212 2 69 | 0 0e 70 | 68 40bf09e3ff7f 71 | end_marker 3922 0 72 | -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.0.result: -------------------------------------------------------------------------------- 1 | -- start of image-load-log --------------------------------------- 2 | Loading /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/hello/hello(0x000400000:0x0004006eb) 3 | Loading /lib64/ld-linux-x86-64.so.2(0x7ffff7ddd000:0x7ffff7dfbc47) 4 | Loading /lib64/libc.so.6(0x7fffe2fcb000:0x7fffe33468b7) 5 | preloaded_image: 1 1 0x000000000 0x7ffff51fbb20 0x000600708 0x000000000 /nfs/mmdc/disks/tpi4/proj/ThreadPoints/test/hello/hello 6 | preloaded_image: 2 0 0x7ffff7ddd000 0x7ffff51fbb20 0x7ffff7ffce70 0x7ffff7ddd000 /lib64/ld-linux-x86-64.so.2 7 | preloaded_image: 3 0 0x7fffe2fcb000 0x7ffff51fbb20 0x7fffe3340b60 0x7fffe2fcb000 /lib64/libc.so.6 8 | -- end of image-load-log ----------------------------------------- 9 | copy_images: 0 10 | inscount: 3922 11 | OSTid: 4786 12 | log_entries: 3 13 | ended_before_sc: 0 14 | num_logged_true_dependencies (RAW): 0 15 | num_logged_false_dependencies (WAR/WAW): 0 16 | num_signals 0 17 | num_syscalls: 4 18 | ip_type: init_pc: 0x0004003d0 19 | ip_type:last_pc: 0x7fffe3076996 20 | restore_text_pc: 1 21 | ip_entry:restoretext_pc: 0x7ffff7de6bd3 22 | ip_entry:restoretext_pc: 0x7ffff7de610b 23 | ip_entry:restoretext_pc: 0x7ffff7de6186 24 | ip_entry:restoretext_pc: 0x7fffe304074c 25 | ip_entry:restoretext_pc: 0x7fffe301a282 26 | ip_entry:restoretext_pc: 0x7ffff7deaba7 27 | ip_entry:restoretext_pc: 0x7ffff7de6392 28 | ip_entry:restoretext_pc: 0x7ffff7deabbe 29 | ip_entry:restoretext_pc: 0x7ffff7de63b2 30 | ip_entry:restoretext_pc: 0x7ffff7de63e5 31 | ip_entry:restoretext_pc: 0x7ffff7deac27 32 | ip_entry:restoretext_pc: 0x7ffff7deac33 33 | ip_entry:restoretext_pc: 0x7ffff7deb865 34 | ip_entry:restoretext_pc: 0x7fffe300f178 35 | ip_entry:restoretext_pc: 0x0004003d0 36 | ip_entry:restoretext_pc: 0x0004003d6 37 | ip_entry:restoretext_pc: 0x7fffe300f222 38 | ip_entry:restoretext_pc: 0x7fffe300f261 39 | ip_entry:restoretext_pc: 0x7fffe300f4bf 40 | ip_entry:restoretext_pc: 0x7ffff7de6999 41 | ip_entry:restoretext_pc: 0x7ffff7de69b5 42 | ip_entry:restoretext_pc: 0x7ffff7df36a0 43 | ip_entry:restoretext_pc: 0x7ffff7df36a2 44 | ip_entry:restoretext_pc: 0x7ffff7de6ba8 45 | -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.0.sel: -------------------------------------------------------------------------------- 1 | /x1005 4 0x2190 0x7fffffffcbe8 2 | /x;4 8 0x8805 ;16 3 | /y;11 0x400 ;16 4 | end_marker 3922 0 5 | -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.0.sync_text: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intel/pinball2elf/825bdf8c3897cd714497eb816fae55ec1fe851ff/examples/ST/pinball.st/log_0.0.sync_text -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.address: -------------------------------------------------------------------------------- 1 | 0x000400000 0x000401000 text 0 2 | 0x000600000 0x000601000 text 0 3 | 0x7fffdeeea000 0x7fffdeeeb000 text 0 4 | 0x7fffe2f48000 0x7fffe2f49000 text 0 5 | 0x7fffe2fcb000 0x7fffe313d000 text 0 6 | 0x7fffe333d000 0x7fffe3347000 data 0 7 | 0x7fffe33fe000 0x7fffe33ff000 text 0 8 | 0x7ffff7ddd000 0x7ffff7dfc000 text 0 9 | 0x7ffff7ffc000 0x7ffff7fff000 data 0 10 | 0x7fffffffc000 0x7fffffffe000 text 0 11 | -------------------------------------------------------------------------------- /examples/ST/pinball.st/log_0.global.log: -------------------------------------------------------------------------------- 1 | pin-command-line: /nfs/mmdc/disks/tpi6/proj/PinPlayExternal/DrDebug/pinplay-drdebug-internal-pin-3.0-76991-gcc-linux/intel64/bin/pinbin -p32 /nfs/mmdc/disks/tpi6/proj/PinPlayExternal/DrDebug/pinplay-drdebug-internal-pin-3.0-76991-gcc-linux/ia32/bin/pinbin -follow_execv -t /nfs/mmdc/disks/tpi6/proj/PinPlayExternal/DrDebug/pinplay-drdebug-internal-pin-3.0-76991-gcc-linux/extras/pinplay/bin/intel64/pinplay-driver.so -log -xyzzy -log:basename pinball.main/log -log:mt 1 -log:compressed bzip2 -log:region_id -log:whole_image -log:pages_early 1 -log:start_address main 2 | app-command-line: hello 3 | OSPid: 4786 4 | file_type: text 5 | fat: 1 6 | lit: 0 7 | user_name: hgpatil 8 | OS_info: Linux hdci2309 3.0.101-68-default #1 SMP Tue Dec 1 16:21:37 UTC 2015 (ed01a9f) intel64 9 | relogged: 0 10 | arch: x86_64 11 | num_static_threads: 1 12 | num_dynamic_threads: 1 13 | num_threads_started: 1 14 | log creation date/time: Wed Feb 8 08:24:26 2017 15 | log format version: 2.6 16 | charm revision: 76887 17 | linker_break_address: 0x7ffff7debb00 18 | data_page_size: 4096 19 | text_page_size: 4096 20 | smc_detected_info_contained: 21 | vdso_address: 0x7ffff7ffb000 0x7ffff7ffc000 22 | ip_entry:syscall: 0x7fffe3076996 L64 23 | ip_entry:syscall: 0x7fffe309b0e2 L64 24 | ip_entry:syscall: 0x7fffe309bf3e L64 25 | ip_entry:syscall: 0x7fffe30a6568 L64 26 | num_reg_descs: 132 27 | rax 0 8 28 | eax 1 4 29 | ax 2 2 30 | ah 3 1 31 | al 4 1 32 | rcx 5 8 33 | ecx 6 4 34 | cx 7 2 35 | ch 8 1 36 | cl 9 1 37 | rdx 10 8 38 | edx 11 4 39 | dx 12 2 40 | dh 13 1 41 | dl 14 1 42 | rbx 15 8 43 | ebx 16 4 44 | bx 17 2 45 | bh 18 1 46 | bl 19 1 47 | rsp 20 8 48 | esp 21 4 49 | sp 22 2 50 | spl 23 1 51 | rbp 24 8 52 | ebp 25 4 53 | bp 26 2 54 | bpl 27 1 55 | rsi 28 8 56 | esi 29 4 57 | si 30 2 58 | sil 31 1 59 | rdi 32 8 60 | edi 33 4 61 | di 34 2 62 | dil 35 1 63 | r8 36 8 64 | r8d 37 4 65 | r8w 38 2 66 | r8b 39 1 67 | r9 40 8 68 | r9d 41 4 69 | r9w 42 2 70 | r9b 43 1 71 | r10 44 8 72 | r10d 45 4 73 | r10w 46 2 74 | r10b 47 1 75 | r11 48 8 76 | r11d 49 4 77 | r11w 50 2 78 | r11b 51 1 79 | r12 52 8 80 | r12d 53 4 81 | r12w 54 2 82 | r12b 55 1 83 | r13 56 8 84 | r13d 57 4 85 | r13w 58 2 86 | r13b 59 1 87 | r14 60 8 88 | r14d 61 4 89 | r14w 62 2 90 | r14b 63 1 91 | r15 64 8 92 | r15d 65 4 93 | r15w 66 2 94 | r15b 67 1 95 | rip 68 8 96 | eip 69 4 97 | ip 70 2 98 | rflags 71 8 99 | eflags 72 4 100 | flags 73 2 101 | cs 74 2 102 | ds 75 2 103 | es 76 2 104 | ss 77 2 105 | fs 78 2 106 | gs 79 2 107 | fs-base 80 8 108 | gs-base 81 8 109 | fcw 82 2 110 | fsw 83 2 111 | ftw 84 1 112 | fop 85 2 113 | fpuip 86 4 114 | x87cs 87 2 115 | fpudp 88 4 116 | x87ds 89 2 117 | st0 90 10 118 | st1 91 10 119 | st2 92 10 120 | st3 93 10 121 | st4 94 10 122 | st5 95 10 123 | st6 96 10 124 | st7 97 10 125 | mxcsr 98 4 126 | xcr0 99 8 127 | XMM0 100 16 128 | YMM0 101 32 129 | XMM1 102 16 130 | YMM1 103 32 131 | XMM2 104 16 132 | YMM2 105 32 133 | XMM3 106 16 134 | YMM3 107 32 135 | XMM4 108 16 136 | YMM4 109 32 137 | XMM5 110 16 138 | YMM5 111 32 139 | XMM6 112 16 140 | YMM6 113 32 141 | XMM7 114 16 142 | YMM7 115 32 143 | XMM8 116 16 144 | YMM8 117 32 145 | XMM9 118 16 146 | YMM9 119 32 147 | XMM10 120 16 148 | YMM10 121 32 149 | XMM11 122 16 150 | YMM11 123 32 151 | XMM12 124 16 152 | YMM12 125 32 153 | XMM13 126 16 154 | YMM13 127 32 155 | XMM14 128 16 156 | YMM14 129 32 157 | XMM15 130 16 158 | YMM15 131 32 159 | ip_entry:image_load: 0x0004003d0 160 | ip_entry:image_load: 0x7fffe301a1f0 161 | ip_entry:image_load: 0x7ffff7df0cd0 162 | -------------------------------------------------------------------------------- /examples/ST/testSSE4.2.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | export ELFIE_COREBASE=0 3 | if [ -e ../../scripts ]; 4 | then 5 | SCRIPTLOC=../../scripts/ 6 | BASICSCRIPT=$SCRIPTLOC/pinball2elf.basic.sh 7 | PERFSCRIPT=$SCRIPTLOC/pinball2elf.perf.sh 8 | else 9 | which pinball2elf.basic.sh 10 | if [ $? -ne 0 ]; 11 | then 12 | echo " Please put PINBALL2ELFKIT/scripts in your PATH" 13 | exit 14 | fi 15 | BASICSCRIPT=`which pinball2elf.basic.sh` 16 | PERFSCRIPT=`which pinball2elf.perf.sh` 17 | fi 18 | pinball=pinball.SSE4.2/region 19 | pbname=`basename $pinball` 20 | if test "$( find . -name "$pbname.basic.elfie" -print -quit)" 21 | then 22 | elfie=`find . -name "$pbname.basic.elfie"` 23 | echo " Deleting old elfie: $elfie" 24 | rm -f $elfie 25 | fi 26 | 27 | echo " Running $BASICSCRIPT $pinball" 28 | $BASICSCRIPT $pinball > /dev/null 2>&1 29 | if ! test "$( find . -name "$pbname.basic.elfie" -print -quit)" 30 | then 31 | echo "**Failed command: '$BASICSCRIPT $pinball'" 32 | exit 33 | fi 34 | elfie=`find . -name "$pbname.basic.elfie"` 35 | echo " Running $elfie" 36 | $elfie 37 | echo "---------------------" 38 | if test "$( find . -name "$pbname.perf.elfie" -print -quit)" 39 | then 40 | elfie=`find . -name "$pbname.perf.elfie"` 41 | echo " Deleting old elfie: $elfie" 42 | rm -f $elfie 43 | fi 44 | echo " Running $PERFSCRIPT $pinball SSE4.2" 45 | $PERFSCRIPT $pinball SSE4.2 > /dev/null 2>&1 46 | if ! test "$( find . -name "$pbname.perf.elfie" -print -quit)" 47 | then 48 | echo "**Failed command: '$PERFSCRIPT $pinball'" 49 | exit 50 | fi 51 | elfie=`find . -name "$pbname.perf.elfie"` 52 | export ELFIE_PERFLIST="0:0,0:1,1:1" 53 | echo " export ELFIE_PERFLIST=$ELFIE_PERFLIST" 54 | echo " [ based on /usr/include/linux/perf_event.h" 55 | echo " Comma separeted pairs 'perftype:counter'" 56 | echo " perftype: 0 --> HW 1 --> SW" 57 | echo " HW counter: 0 --> PERF_COUNT_HW_CPU_CYCLES" 58 | echo " HW counter: 1 --> PERF_COUNT_HW_CPU_INSTRUCTIONS" 59 | echo " SW counter: 0 --> PERF_COUNT_SW_CPU_CLOCK" 60 | echo " ... /dev/null 2>&1 29 | if ! test "$( find . -name "$pbname.basic.elfie" -print -quit)" 30 | then 31 | echo "**Failed command: '$BASICSCRIPT $pinball'" 32 | exit 33 | fi 34 | elfie=`find . -name "$pbname.basic.elfie"` 35 | echo " Running $elfie" 36 | $elfie 37 | echo "---------------------" 38 | if test "$( find . -name "$pbname.perf.elfie" -print -quit)" 39 | then 40 | elfie=`find . -name "$pbname.perf.elfie"` 41 | echo " Deleting old elfie: $elfie" 42 | rm -f $elfie 43 | fi 44 | echo " Running $PERFSCRIPT $pinball st" 45 | $PERFSCRIPT $pinball st > /dev/null 2>&1 46 | if ! test "$( find . -name "$pbname.perf.elfie" -print -quit)" 47 | then 48 | echo "**Failed command: '$PERFSCRIPT $pinball'" 49 | exit 50 | fi 51 | elfie=`find . -name "$pbname.perf.elfie"` 52 | export ELFIE_PERFLIST="0:0,0:1,1:1" 53 | echo " export ELFIE_PERFLIST=$ELFIE_PERFLIST" 54 | echo " [ based on /usr/include/linux/perf_event.h" 55 | echo " Comma separeted pairs 'perftype:counter'" 56 | echo " perftype: 0 --> HW 1 --> SW" 57 | echo " HW counter: 0 --> PERF_COUNT_HW_CPU_CYCLES" 58 | echo " HW counter: 1 --> PERF_COUNT_HW_CPU_INSTRUCTIONS" 59 | echo " SW counter: 0 --> PERF_COUNT_SW_CPU_CLOCK" 60 | echo " ... 2 | #include 3 | #include 4 | #include "lte_perf.h" 5 | #include 6 | #include 7 | __lte_static char s_pid[] = " pid: "; 8 | __lte_static char s_tid[] = " tid: "; 9 | __lte_static char strp[] = "process_callback() [ inside ELFie] called. Num_threads: "; 10 | __lte_static char strt[] = "thread_callback() [ inside ELFie] called for thread "; 11 | 12 | void preopen_files(); // function to be added by pinball2elf*.sh scripts 13 | void set_heap(); // function to be added by pinball2elf*.sh scripts 14 | void read_environ(); // function to be added by pinball2elf*.sh scripts 15 | __lte_static int core_base=0; 16 | __lte_static int verbose=0; 17 | __lte_static int use_pccount=0; // not used for 'basic' 18 | __lte_static int use_warmup=0; // not used for 'basic' 19 | __lte_static int hw_event_enabled[PERF_COUNT_HW_MAX]={0}; // not used for 'basic' 20 | __lte_static int sw_event_enabled[PERF_COUNT_SW_MAX]={0}; // not used for 'basic' 21 | 22 | void elfie_on_start(uint64_t num_threads, void* context) 23 | { 24 | pid_t pid = lte_getpid(); 25 | read_environ(); 26 | lte_write(1, "core_base: ", lte_strlen("core_base: ")-1); lte_diprintfe(1, core_base, '\n'); 27 | lte_write(1, s_pid, lte_strlen(s_pid)-1); lte_diprintfe(1, pid, '\n'); 28 | lte_fsync(1); 29 | lte_syscall(__NR_write, 2, (uint64_t)strp, lte_strlen(strp)-1, 0, 0, 0); 30 | lte_fsync(2); 31 | lte_diprintfe(1, num_threads, '\n'); 32 | 33 | // preopen_files() and set_heap() definitions to be added by pinball2elf*.sh script 34 | preopen_files(); 35 | set_heap(); 36 | lte_fsync(1); 37 | return; 38 | } 39 | 40 | lte_td_t elfie_on_thread_start(uint64_t tnum, void* context, uint64_t icount) 41 | { 42 | pid_t tid = lte_gettid(); 43 | lte_write(1, s_tid, lte_strlen(s_tid)-1); lte_diprintfe(1, tid, '\n'); 44 | lte_syscall(__NR_write, 2, (uint64_t)strt, lte_strlen(strt)-1, 0, 0, 0); 45 | lte_fsync(2); 46 | lte_diprintfe(1, tnum, '\n'); 47 | lte_fsync(1); 48 | return NULL; 49 | } 50 | void __stack_chk_fail() {} 51 | 52 | // preopen_files() to be added by pinball2elf*.sh script 53 | // set_heap() to be added by pinball2elf*.sh script 54 | -------------------------------------------------------------------------------- /instrumentation/set_heap.c: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c) 2016-2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | 32 | #define STATBUFLEN 2048 33 | __lte_static char statbuf[STATBUFLEN]; 34 | uint64_t mystr2dec(char *inptr) 35 | { 36 | uint64_t retval=0; 37 | while( (*inptr != 0) && (*inptr != ' ' )) 38 | { 39 | retval=10*retval + (*inptr) - '0'; 40 | inptr++; 41 | } 42 | return retval; 43 | } 44 | 45 | char * mystrchr(char * inptr, char c) 46 | { 47 | while( (*inptr != 0) && (*inptr != c)) inptr++; 48 | return inptr; 49 | } 50 | 51 | __lte_static struct prctl_mm_map prctl_map; 52 | void set_heap() 53 | { 54 | int statfd = lte_syscall(__NR_open, (uint64_t)"/proc/self/stat", (uint64_t)O_RDONLY|O_CLOEXEC, 0, 0, 0, 0); 55 | int read_count = lte_syscall(__NR_read, (uint64_t)statfd, (uint64_t)statbuf, (uint64_t) STATBUFLEN, 0, 0, 0); 56 | statbuf[read_count]=0; 57 | char * sptr = mystrchr(statbuf, ' '); 58 | // skip fields 1--25 59 | for (int i =0; i < 24; i++) 60 | { 61 | sptr = mystrchr(sptr+1, ' '); 62 | } 63 | // read fields 26, 27, 28 64 | uint64_t start_code = mystr2dec(sptr+1); 65 | sptr = mystrchr(sptr+1, ' '); 66 | uint64_t end_code = mystr2dec(sptr+1); 67 | sptr = mystrchr(sptr+1, ' '); 68 | uint64_t start_stack = mystr2dec(sptr+1); 69 | sptr = mystrchr(sptr+1, ' '); 70 | // skip 16 fields 29--44 71 | for (int i =0; i < 16; i++) 72 | { 73 | sptr = mystrchr(sptr+1, ' '); 74 | } 75 | // read fields 45--51 76 | uint64_t start_data = mystr2dec(sptr+1); 77 | sptr = mystrchr(sptr+1, ' '); 78 | uint64_t end_data = mystr2dec(sptr+1); 79 | sptr = mystrchr(sptr+1, ' '); 80 | uint64_t start_brk = mystr2dec(sptr+1); 81 | sptr = mystrchr(sptr+1, ' '); 82 | uint64_t arg_start = mystr2dec(sptr+1); 83 | sptr = mystrchr(sptr+1, ' '); 84 | uint64_t arg_end = mystr2dec(sptr+1); 85 | sptr = mystrchr(sptr+1, ' '); 86 | uint64_t env_start = mystr2dec(sptr+1); 87 | sptr = mystrchr(sptr+1, ' '); 88 | uint64_t env_end = mystr2dec(sptr+1); 89 | sptr = mystrchr(sptr+1, ' '); 90 | prctl_map.start_code = start_code; 91 | prctl_map.end_code = end_code; 92 | prctl_map.start_data = start_data; 93 | prctl_map.end_data = end_data; 94 | prctl_map.start_brk = start_brk; 95 | prctl_map.start_stack = start_stack; 96 | prctl_map.arg_start = arg_start; 97 | prctl_map.arg_end = arg_end; 98 | prctl_map.env_start = env_start; 99 | prctl_map.env_end = env_end; 100 | prctl_map.auxv = NULL; 101 | prctl_map.auxv_size = 0; 102 | prctl_map.exe_fd = -1; 103 | uint64_t retval = lte_syscall(__NR_brk, 0, 0, 0, 0, 0, 0); 104 | prctl_map.start_data = prctl_map.end_code; 105 | prctl_map.end_data = FIRST_BRK_ADDR-0x1000; 106 | prctl_map.start_brk = FIRST_BRK_ADDR; 107 | prctl_map.brk = LAST_BRK_ADDR; 108 | retval = lte_syscall(__NR_prctl, PR_SET_MM, 109 | (uint64_t)(PR_SET_MM_MAP), (uint64_t)(&prctl_map), 110 | (uint64_t)(sizeof(prctl_map)), (uint64_t)0, (uint64_t)0); 111 | } 112 | -------------------------------------------------------------------------------- /instrumentation/sim_callbacks.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "lte_perf.h" 7 | #include 8 | #include 9 | #define PERF_COUNT_SW_MAX 11 10 | #define PERF_COUNT_HW_MAX 10 11 | 12 | __lte_static char mlockerrmesg[] = "mlockall() failed\n"; 13 | 14 | void preopen_files(); // function to be added by pinball2elf*.sh scripts 15 | void set_heap(); // function to be added by pinball2elf*.sh scripts 16 | void read_environ(); // function to be added by pinball2elf*.sh scripts 17 | __lte_static int core_base=0; 18 | __lte_static int verbose=0; 19 | __lte_static int use_pccount=0; // not used for 'sim' 20 | __lte_static int use_warmup=0; // not used for 'sim' 21 | __lte_static int hw_event_enabled[PERF_COUNT_HW_MAX]={0}; // not used for 'sim' 22 | __lte_static int sw_event_enabled[PERF_COUNT_SW_MAX]={0}; // not used for 'sim' 23 | 24 | void elfie_on_start(uint64_t num_threads, void* context) 25 | { 26 | int retval = 0; 27 | read_environ(); 28 | if(verbose) 29 | { 30 | lte_write(2, "elfie_on_start() num_threads: ", lte_strlen("elfie_on_start() num_threads: ")-1); 31 | lte_diprintfe(2, num_threads, '\n'); 32 | } 33 | if (core_base >= 0) 34 | { 35 | lte_syscall(__NR_write, 2, (uint64_t)"Will set affinity using ", lte_strlen("Will set affinity using ")-1, 0, 0, 0); 36 | lte_write(1, "core_base: ", lte_strlen("core_base: ")-1); lte_diprintfe(1, core_base, '\n'); 37 | lte_write(1, " elfie tid: 0 ", lte_strlen(" elfie tid: 0 ")-1); 38 | lte_write(1, " core id: ", lte_strlen(" core id: ")-1); lte_diprintfe(1, core_base, '\n'); 39 | } 40 | else 41 | { 42 | lte_syscall(__NR_write, 2, (uint64_t)"Will skip affinity setting as core_base is negative \n", lte_strlen("Will skip affinity setting as core_base is negative \n")-1, 0, 0, 0); 43 | } 44 | lte_syscall(__NR_write, 2, (uint64_t)str, lte_strlen(str)-1, 0, 0, 0); 45 | retval = lte_syscall(__NR_mlockall, MCL_CURRENT | MCL_FUTURE, 0, 0, 0, 0, 0); 46 | if (retval !=0 ) 47 | lte_syscall(__NR_write, 2, (uint64_t)mlockerrmesg, lte_strlen(mlockerrmesg)-1, 0, 0, 0); 48 | // preopen_files() definition to be added by pinball2elf*.sh script 49 | preopen_files(); 50 | // set_heap() definition to be added by pinball2elf*.sh script 51 | set_heap(); 52 | return; 53 | } 54 | 55 | __lte_static char errmesg[] = "sched_setaffinity() failed\n"; 56 | __lte_static cpu_set_t my_set; 57 | lte_td_t elfie_on_thread_start(uint64_t tnum, void* context, uint64_t icount) 58 | { 59 | int retval = 0; 60 | int tid = lte_syscall(__NR_gettid, 0, 0, 0, 0, 0, 0); // OS assigned tid 61 | if(verbose) 62 | { 63 | lte_write(2, "elfie_on_thread_start() elfie_tid: ", lte_strlen("elfie_on_thread_start() elfie_tid: ")-1); 64 | lte_diprintfe(2, tnum, ' '); 65 | lte_write(2, "icount: ", lte_strlen("icount: ")-1); 66 | lte_diprintfe(2, icount, '\n'); 67 | } 68 | if (core_base >= 0) 69 | { 70 | CPU_ZERO(&my_set); 71 | CPU_SET((int)core_base+tnum, &my_set); // 'id' ranges from 0... 72 | retval = lte_syscall(SYS_sched_setaffinity,tid, sizeof(cpu_set_t), (uint64_t)(&my_set), 0, 0, 0); 73 | if (retval !=0 ) 74 | { 75 | lte_syscall(__NR_write, 2, (uint64_t)errmesg, lte_strlen(errmesg)-1, 0, 0, 0); 76 | } 77 | } 78 | return lte_pe_get_thread_desc(tnum); 79 | } 80 | void __stack_chk_fail() {} 81 | // preopen_files() to be added by pinball2elf*.sh script 82 | // set_heap() to be added by pinball2elf*.sh script 83 | -------------------------------------------------------------------------------- /pintools/EventCounter/README: -------------------------------------------------------------------------------- 1 | o set SDE_BUILD_KIT to point to the latest SDE 9.* kit. 2 | o Type 'make' 3 | o $SDE_BUILD_KIT/sde64 -t64 $SDE_BUILD_KIT/intel64/sde-event-counter.so -thread_count 1 -prefix ls -- /bin/ls 4 | global icount 0 Sim-Start 5 | global icount 0 Late-Sim-Start 6 | o more ls.event_icount.0.txt 7 | Sim-Start global_icount: 0 8 | Sim-Start tid: 0 icount 0 9 | Fini global_icount: 447359 10 | Fini tid: 0 icount 447359 11 | 12 | -------------------------------------------------------------------------------- /pintools/EventCounter/makefile: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | # 3 | # Copyright (C) 2021-2021 Intel Corporation. 4 | # SPDX-License-Identifier: MIT 5 | # 6 | ############################################################## 7 | # 8 | # DO NOT EDIT THIS FILE! 9 | # 10 | ############################################################## 11 | 12 | # If the tool is built out of the kit, PIN_ROOT must be specified in the make 13 | # invocation and point to the kit root. 14 | ifdef SDE_BUILD_KIT 15 | PIN_ROOT := $(SDE_BUILD_KIT)/pinkit 16 | SDE_ROOT := $(PIN_ROOT)/sde-example 17 | PINPLAY_ROOT := $(PIN_ROOT)/pinplay 18 | CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config 19 | else 20 | SDE_BUILD_KIT := ../../.. 21 | PIN_ROOT := $(SDE_BUILD_KIT)/pinkit 22 | SDE_ROOT := $(PIN_ROOT)/sde-example 23 | PINPLAY_ROOT := $(PIN_ROOT)/pinplay 24 | CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config 25 | CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config 26 | endif 27 | 28 | include $(CONFIG_ROOT)/makefile.config 29 | include makefile.rules 30 | include $(TOOLS_ROOT)/Config/makefile.default.rules 31 | 32 | ############################################################## 33 | # 34 | # DO NOT EDIT THIS FILE! 35 | # 36 | ############################################################## 37 | -------------------------------------------------------------------------------- /pintools/EventCounter/makefile.rules: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | # 3 | # Copyright (C) 2021-2021 Intel Corporation. 4 | # SPDX-License-Identifier: MIT 5 | # 6 | ############################################################## 7 | # 8 | # This file includes all the test targets as well as all the 9 | # non-default build rules and test recipes. 10 | # 11 | ############################################################## 12 | 13 | 14 | ############################################################## 15 | # 16 | # Test targets 17 | # 18 | ############################################################## 19 | 20 | all:build 21 | 22 | ###### Place all generic definitions here ###### 23 | 24 | # Define the SDE example pin tools to build 25 | PB2ELF := $(PINBALL2ELF) 26 | DCFG := ../Profiler/DCFG/ 27 | SDE_TOOLS := 28 | PINPLAY_TOOLS := event_counter 29 | 30 | TOOL_ROOTS := $(SDE_TOOLS) $(PINPLAY_TOOLS) 31 | 32 | ############################################################## 33 | # 34 | # Build rules 35 | # 36 | ############################################################## 37 | 38 | # See makefile.default.rules for the default build rules. 39 | TOOL_CXXFLAGS := -I$(SDE_ROOT)/include $(TOOL_CXXFLAGS) 40 | TOOL_CXXFLAGS += -DSDE_INIT -DPINPLAY -I$(PINPLAY_ROOT)/include -I ../RegionControllers/PCcount -I../RegionControllers/Icount -I$(PB2ELF)/pintools/PinballSYSState/ -I$(DCFG) 41 | 42 | ifeq ($(OS),Windows_NT) 43 | TOOL_LPATHS += /LIBPATH:$(SDE_ROOT)/lib/$(TARGET) /LIBPATH:$(PINPLAY_ROOT)/$(TARGET) 44 | TOOL_LPATHS += libpinplay.lib libsde.lib bz2.lib zlib.lib 45 | else 46 | # sde and pinplay libraries appears twice to avoid circular dependency 47 | TOOL_LPATHS += -L$(SDE_ROOT)/lib/$(TARGET) -L$(PINPLAY_ROOT)/$(TARGET) 48 | TOOL_LPATHS += -lpinplay -lsde -lpinplay -lsde -lbz2 -lzlib 49 | endif 50 | 51 | build: obj-$(TARGET)/event_counter.so 52 | cp obj-$(TARGET)/event_counter.so $(SDE_BUILD_KIT)/$(TARGET)/sde-event-counter.so 53 | 54 | -------------------------------------------------------------------------------- /pintools/PinballSYSState/makefile: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | # 3 | # Copyright (C) 2021-2021 Intel Corporation. 4 | # SPDX-License-Identifier: MIT 5 | # 6 | ############################################################## 7 | # 8 | # DO NOT EDIT THIS FILE! 9 | # 10 | ############################################################## 11 | 12 | # If the tool is built out of the kit, PIN_ROOT must be specified in the make 13 | # invocation and point to the kit root. 14 | ifdef SDE_BUILD_KIT 15 | PIN_ROOT := $(SDE_BUILD_KIT)/pinkit 16 | SDE_ROOT := $(PIN_ROOT)/sde-example 17 | PINPLAY_ROOT := $(PIN_ROOT)/pinplay 18 | CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config 19 | else 20 | SDE_BUILD_KIT := ../../.. 21 | PIN_ROOT := $(SDE_BUILD_KIT)/pinkit 22 | SDE_ROOT := $(PIN_ROOT)/sde-example 23 | PINPLAY_ROOT := $(PIN_ROOT)/pinplay 24 | CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config 25 | CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config 26 | endif 27 | 28 | include $(CONFIG_ROOT)/makefile.config 29 | include makefile.rules 30 | include $(TOOLS_ROOT)/Config/makefile.default.rules 31 | 32 | ############################################################## 33 | # 34 | # DO NOT EDIT THIS FILE! 35 | # 36 | ############################################################## 37 | -------------------------------------------------------------------------------- /pintools/PinballSYSState/makefile.rules: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | # 3 | # Copyright (C) 2021-2021 Intel Corporation. 4 | # SPDX-License-Identifier: MIT 5 | # 6 | ############################################################## 7 | # 8 | # This file includes all the test targets as well as all the 9 | # non-default build rules and test recipes. 10 | # 11 | ############################################################## 12 | 13 | 14 | ############################################################## 15 | # 16 | # Test targets 17 | # 18 | ############################################################## 19 | 20 | ###### Place all generic definitions here ###### 21 | 22 | # Define the SDE example pin tools to build 23 | SDE_TOOLS := pinball-sysstate 24 | PINPLAY_TOOLS := 25 | 26 | ifneq ($(OS),Windows_NT) 27 | PINPLAY_TOOLS += 28 | endif 29 | 30 | TOOL_ROOTS := $(SDE_TOOLS) $(PINPLAY_TOOLS) 31 | 32 | ############################################################## 33 | # 34 | # Build rules 35 | # 36 | ############################################################## 37 | 38 | all:build 39 | 40 | # See makefile.default.rules for the default build rules. 41 | TOOL_CXXFLAGS += -DSDE_INIT -DPINPLAY -I$(SDE_ROOT)/include -I$(PINPLAY_ROOT)/include 42 | 43 | ifeq ($(OS),Windows_NT) 44 | TOOL_LPATHS += /LIBPATH:$(SDE_ROOT)/lib/$(TARGET) /LIBPATH:$(PINPLAY_ROOT)/$(TARGET) 45 | TOOL_LPATHS += libpinplay.lib libsde.lib bz2.lib zlib.lib 46 | else 47 | # sde and pinplay libraries appears twice to avoid circular dependency 48 | TOOL_LPATHS += -L$(SDE_ROOT)/lib/$(TARGET) -L$(PINPLAY_ROOT)/$(TARGET) 49 | TOOL_LPATHS += -lpinplay -lsde -lpinplay -lsde -lbz2 -lzlib 50 | endif 51 | 52 | build: obj-$(TARGET)/pinball-sysstate.so 53 | cp obj-$(TARGET)/pinball-sysstate.so $(SDE_BUILD_KIT)/$(TARGET)/sde-pinball-sysstate.so 54 | -------------------------------------------------------------------------------- /pintools/PinballSYSState/pinball-sysstate.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c) 2020 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. Redistributions 12 | in binary form must reproduce the above copyright notice, this list of 13 | conditions and the following disclaimer in the documentation and/or 14 | other materials provided with the distribution. Neither the name of 15 | the Intel Corporation nor the names of its contributors may be used to 16 | endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR 23 | ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | END_LEGAL */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "pin.H" 37 | #if defined(SDE_INIT) 38 | # include "sde-init.H" 39 | #endif 40 | 41 | 42 | #include "pinball-sysstate.H" 43 | 44 | #if defined(SDE_INIT) 45 | #include "sde-pinplay-supp.H" 46 | #endif 47 | 48 | 49 | #include "pinplay.H" 50 | #include "pinplay-debugger-shell.H" 51 | PINPLAY_ENGINE *my_pinplay_engine; 52 | static PINPLAY_ENGINE pp_pinplay_engine; 53 | 54 | DR_DEBUGGER_SHELL::ICUSTOM_INSTRUMENTOR * 55 | CreatePinPlayInstrumentor(DR_DEBUGGER_SHELL::ISHELL *); 56 | DR_DEBUGGER_SHELL::ISHELL *shell = NULL; 57 | 58 | DR_DEBUGGER_SHELL::ICUSTOM_INSTRUMENTOR 59 | *CreatePinPlayInstrumentor(DR_DEBUGGER_SHELL::ISHELL *shell) 60 | { 61 | return new PINPLAY_DEBUGGER_INSTRUMENTOR(shell); 62 | } 63 | 64 | 65 | PINBALL_SYSSTATE::SYSSTATE pbsysstate; 66 | 67 | #if ! defined(SDE_INIT) 68 | #define KNOB_LOG_NAME "log" 69 | #define KNOB_REPLAY_NAME "replay" 70 | #define KNOB_FAMILY "pintool:pinplay-driver" 71 | 72 | KNOB_COMMENT pinplay_driver_knob_family(KNOB_FAMILY, "PinPlay Driver Knobs"); 73 | 74 | KNOBKnobPinPlayReplayer(KNOB_MODE_WRITEONCE, KNOB_FAMILY, 75 | KNOB_REPLAY_NAME, "0", "Replay a pinball"); 76 | KNOBKnobPinPlayLogger(KNOB_MODE_WRITEONCE, KNOB_FAMILY, 77 | KNOB_LOG_NAME, "0", "Create a pinball"); 78 | 79 | #endif 80 | 81 | 82 | 83 | #if ! defined(SDE_INIT) 84 | LOCALFUN INT32 Usage(CHAR *prog) 85 | { 86 | cerr << "Usage: " << prog << " Args -- app appargs ..." << endl; 87 | cerr << "Arguments:" << endl; 88 | cerr << KNOB_BASE::StringKnobSummary(); 89 | cerr << endl; 90 | 91 | return -1; 92 | } 93 | #endif 94 | 95 | // argc, argv are the entire command line, including pin -t -- ... 96 | int main(int argc, char * argv[]) 97 | { 98 | #if defined(SDE_INIT) 99 | sde_pin_init(argc,argv); 100 | sde_init(); 101 | #else 102 | if( PIN_Init(argc,argv) ) 103 | { 104 | return Usage(argv[0]); 105 | } 106 | #endif 107 | PIN_InitSymbols(); 108 | 109 | #if defined(SDE_INIT) 110 | // This is a replay-only tool (for now) 111 | my_pinplay_engine = sde_tracing_get_pinplay_engine(); 112 | #else 113 | my_pinplay_engine = &pp_pinplay_engine; 114 | my_pinplay_engine->Activate(argc, argv, KnobPinPlayLogger, KnobPinPlayReplayer); 115 | #endif 116 | 117 | #if ! defined(SDE_INIT) 118 | DEBUG_STATUS debugStatus = PIN_GetDebugStatus(); 119 | 120 | if (debugStatus != DEBUG_STATUS_DISABLED) 121 | { 122 | shell = DR_DEBUGGER_SHELL::CreatePinPlayShell(); 123 | DR_DEBUGGER_SHELL::STARTUP_ARGUMENTS args; 124 | if (my_pinplay_engine->IsReplayerActive()) 125 | { 126 | args._customInstrumentor = CreatePinPlayInstrumentor(shell); 127 | } 128 | if (!shell->Enable(args)) 129 | return 1; 130 | } 131 | #endif 132 | 133 | if(pbsysstate.Activate(my_pinplay_engine) == 0) 134 | { 135 | cerr << "SYSSTATE activation failed. Returning without replay. \n"; 136 | return 1; 137 | } 138 | 139 | 140 | // Start the program, never returns 141 | PIN_StartProgram(); 142 | 143 | return 0; 144 | } 145 | -------------------------------------------------------------------------------- /pintools/ProcessControl/HOWTO.criu: -------------------------------------------------------------------------------- 1 | This document explains a sample application of ProcessControl. 2 | It runs 'base.exe' (on host) for 70 billion instructions and captures a 3 | criu checkpoint there. It then restores the criu checkpoints (on target) 4 | and runs it for 200 million instructions. 5 | 6 | Input: region-of-intrest for 505.mcf_r for SPEC-CPU2017 7 | # (start) Icount = 70000001532 Length = 200000006 8 | 9 | bash shell assumed. 10 | export PROCHOME= inp.out 2> inp.err 19 | 20 | 2. On host: use the instruction controller to get to the desired point 21 | Our region of interest is at the 70B instruction mark. Let us use a polling interval of 10000 us: 22 | $PROCHOME/pstree-icount `cat mcf.procid ` 10000 70000001532 > mcf.ctrl.out 2> mcf.ctrl.err 23 | 24 | 3. On host: dump the paused application onto the disk using CRIU 25 | sudo criu dump -vvvv -o mcf.chkpt.log -t `cat mcf.procid` -j 26 | 27 | 4. On target: restore the disk checkpoint onto memory (re-run step 0 if pre-reqs are not met) 28 | Note: the contents of the files must remain the same from the time of dumping (step 3). So, backup files that could be overwritten 29 | cp inp.out inp.out.bak 30 | cp inp.err inp.err.bak 31 | sudo criu restore -vvvv -o mcf.rstor.log -j -d -s -S 32 | 33 | Sanity test: the original process must now be restored: 34 | $ ls /proc/`cat mcf.procid` 35 | shoul show valid output. 36 | 37 | 5. On target: use the icount run controller to resume application execution 38 | Execute for the desired instructions (200 million) and measure performance stats (IPC): 39 | perf stat -a -I 100 -o mcf.perf.out -e instructions,cycles -- sleep 10 & 40 | $PROCHOME/pstree-icount `cat mcf.procid` 1000 200000006 > mcf.run.out 2> mcf.run.err 41 | 42 | Cleanup: 43 | kill -9 `sudo grep Unseiz mcf.chkpt.log | awk '{ print $3 }'` 44 | Now restore backups and we are done: 45 | mv inp.out inp.out.new 46 | mv inp.err inp.err.new 47 | mv inp.out.bak inp.out 48 | mv inp.err.bak inp.err 49 | 50 | 51 | Sanity tests: 52 | $ sudo tail mcf.chkpt.log 53 | (00.260558) cg: `- Dumping rdma of / 54 | (00.260576) cg: Writing CG image 55 | (00.260609) unix: Dumping external sockets 56 | (00.260628) tty: Unpaired slave 3 57 | (00.260632) Writing image inventory (version 1) 58 | (00.260694) Running post-dump scripts 59 | (00.260697) Unfreezing tasks into 2 60 | (00.260699) Unseizing 1890664 into 2 61 | (00.272421) Writing stats 62 | 63 | $ sudo tail mcf.rstor.log 64 | (00.173905) 1890664 was stopped 65 | (00.173928) 1890664 was trapped 66 | (00.173932) 1890664 (native) is going to execute the syscall 11, required is 11 67 | (00.173951) 1890664 was stopped 68 | (00.173960) Run late stage hook from criu master for external devices 69 | (00.173963) restore late stage hook for external plugin failed 70 | (00.173965) Running pre-resume scripts 71 | (00.173970) Restore finished successfully. Tasks resumed. 72 | (00.173972) Writing stats 73 | (00.174035) Running post-resume scripts 74 | 75 | 76 | $ more mcf.ctrl.out 77 | pstree size: 1 78 | printing per-thread icounts:(PID/TID: icount) 79 | 1890664/1890664: 70012110303 80 | total: 70012110303 instructions 81 | 82 | 83 | $ more mcf.run.out 84 | pstree size: 1 85 | printing per-thread icounts:(PID/TID: icount) 86 | 1890664/1890664: 200574614 87 | total: 200574614 instructions 88 | 89 | -------------------------------------------------------------------------------- /pintools/ProcessControl/Makefile: -------------------------------------------------------------------------------- 1 | VERBOSE?=0 2 | CC=gcc 3 | CFLAGS=-g -O2 -DVERBOSE=$(VERBOSE) 4 | LDFLAGS= 5 | DEPS=pstree.h 6 | EXE=pstree-icount pstree-timedrun pstree-pccount pstree-threadperf 7 | 8 | all: $(EXE) 9 | 10 | pstree-icount: pstree-icount.o pstree.o 11 | $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ 12 | 13 | pstree-timedrun: pstree-timedrun.o pstree.o 14 | $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ 15 | 16 | pstree-pccount: pstree-pccount.o pstree.o 17 | $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ 18 | 19 | pstree-threadperf: pstree-threadperf.o pstree.o 20 | $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@ 21 | 22 | %.o: %.c $(DEPS) 23 | $(CC) $(CFLAGS) -c -o $@ $< 24 | 25 | .PHONY: clean 26 | 27 | clean: 28 | rm -f *.o $(EXE) 29 | -------------------------------------------------------------------------------- /pintools/ProcessControl/README: -------------------------------------------------------------------------------- 1 | Tools to control process execution. 2 | ================================== 3 | Author: Karthik Sankaranarayanan (Intel labs). 4 | ========================================================================== 5 | startpaused.sh : 6 | usage: setsid ./startpaused.sh -- 7 | starts application paused and writes PID to 8 | 9 | 1) pstree-icount and pstree-timedrun are both “polling-based and global” 10 | (i.e., they wake up every so many microseconds of polling and pause the 11 | application once it hits a given global icount or time respectively) 12 | 2) pstree-threadperf and pstree-pccount are both 13 | “interrupt-based and local” (i.e., they pause the application after 14 | an interrupt occurs at the specified local thread of the application. 15 | The interrupt is generated by the occurrence of the specified icount 16 | or pc/count respectively) 17 | 18 | pstree-icount: 19 | usage: ./pstree-icount 20 | stop a process tree after a given number of total instructions on core 0 21 | : pid of the root of a SIGSTOPPED pstree 22 | : polling time period in microseconds 23 | : instruction count beyond which to stop (0 for run to completion) 24 | 25 | pstree-pccount: 26 | usage: ./pstree-pccount 27 | stop a process tree at a given thread after occurrences of an instruction at 28 | : pid of the root of a SIGSTOPPED pstree 29 | : tid of the target thread 30 | : instruction address of the target instruction 31 | : no. of occurrences of after which to stop 32 | 33 | 34 | pstree-timedrun 35 | usage: ./pstree-timedrun 36 | stop a process tree after executing for a given number of micro-seconds 37 | : pid of the root of a SIGSTOPPED pstree 38 | : polling time period in microseconds 39 | : no. of seconds after which to stop (0 for run to completion) 40 | 41 | pstree-threadperf 42 | usage: ./pstree-threadperf 43 | stop a process tree at a given thread after userspace instructions and measure performance 44 | : pid of the root of a SIGSTOPPED pstree 45 | : tid of the target thread 46 | : no. of userspace instructions after which to stop (0 for run to completion) 47 | 48 | ---- 49 | See HOWTO.criu for an example use of these tools for CRIU checkpoint generation. 50 | -------------------------------------------------------------------------------- /pintools/ProcessControl/pstree-pccount.c: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2022 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #include "pstree.h" 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | pid_t pid, tid, child; 21 | pid_t pout[MAXPROCS], tout[MAXPROCS]; 22 | unsigned long tdone[MAXPROCS]={0}, donecount = 0; 23 | unsigned long count, i; 24 | int wstatus, pfd; 25 | unsigned long long limit, pc; 26 | 27 | if (argc != 5) { 28 | fprintf(stderr, "usage: %s \n", argv[0]); 29 | fprintf(stderr, "stop a process tree at a given thread after occurrences of an instruction at \n"); 30 | fprintf(stderr, " : pid of the root of a SIGSTOPPED pstree\n"); 31 | fprintf(stderr, " : tid of the target thread\n"); 32 | fprintf(stderr, " : instruction address of the target instruction\n"); 33 | fprintf(stderr, " : no. of occurrences of after which to stop (0 for completion)\n"); 34 | return EXIT_FAILURE; 35 | } 36 | 37 | errno = 0; 38 | pid = parse_long(argv[1], "parse_long: Invalid PID"); 39 | tid = parse_long(argv[2], "parse_long: Invalid TID"); 40 | pc = parse_ull(argv[3], "parse_ull: Invalid instruction address"); 41 | limit = parse_ull(argv[4], "parse_ull: Invalid count"); 42 | 43 | count = get_pstree(pid, pout, tout); 44 | fprintf (stdout, "pstree size: %lu\n", count); 45 | #if VERBOSE > 0 46 | fprintf (stdout, "printing PID/TID:\n"); 47 | for (i=0; i < count; i++) { 48 | fprintf(stdout, "%d/%d\n", pout[i], tout[i]); 49 | } 50 | #endif 51 | 52 | /* make all tids tracees */ 53 | for (i=0; i < count; i++) 54 | seize_tid(tout[i]); 55 | 56 | /* setup pc/count for the target thread */ 57 | for (i=0; i < count; i++) 58 | if (tout[i] == tid) 59 | break; 60 | if (i < count) { 61 | pfd = setup_pccount(tout[i], (void *)pc, limit); 62 | } else { 63 | fprintf(stderr, "unable to find TID: %d in pstree at %d\n", pid, tid); 64 | return EXIT_FAILURE; 65 | } 66 | 67 | /* restart tracees */ 68 | for (i=0; i < count; i++) 69 | continue_tid(tout[i], pout[i]); 70 | 71 | /* main ptrace loop */ 72 | while (1) { 73 | /* blocking wait */ 74 | child = waitpid(-1, &wstatus, 0); 75 | /* SIGIO from the desired thread */ 76 | if (child == tid && WIFSTOPPED(wstatus) && WSTOPSIG(wstatus) == SIGIO) { 77 | #if VERBOSE > 1 78 | fprintf(stdout, "SIGIO stop at TID %d with status 0x%x\n", child, wstatus); 79 | #endif 80 | /* desired point reached: stop the tracees */ 81 | for (i=0; i < count; i++) { 82 | if (!tdone[i]) 83 | interrupt_tid(tout[i]); 84 | } 85 | /* output stats */ 86 | fprintf (stdout, "paused pstree (root PID: %d) at TID: %d , IP: 0x%llx, after %llu occurrences\n", \ 87 | pid, tid, pc, limit); 88 | break; 89 | /* valid stopped child: process stop event */ 90 | } else if (child > 0 && WIFSTOPPED(wstatus)) { 91 | if (handle_stop(pout, tout, NULL, tdone, NULL, &count, \ 92 | child, wstatus, &donecount)) 93 | break; 94 | /* child exited or terminated */ 95 | } else if (child > 0 && (WIFEXITED(wstatus) || WIFSIGNALED(wstatus))) { 96 | if (handle_exit(pout, tout, NULL, tdone, NULL, count, \ 97 | child, wstatus, &donecount)) 98 | break; 99 | /* error */ 100 | } else { 101 | perror("main:waitpid"); 102 | fprintf(stderr, "error: waitpid returned error\n"); 103 | return EXIT_FAILURE; 104 | } 105 | } 106 | 107 | /* detach from undetached tracees */ 108 | for (i=0; i < count; i++) { 109 | if (!tdone[i]) 110 | detach_tid(tout[i], pout[i]); 111 | } 112 | 113 | return EXIT_SUCCESS; 114 | } 115 | 116 | -------------------------------------------------------------------------------- /pintools/ProcessControl/pstree.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2022 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | 17 | #ifndef PSTREE_H 18 | #define PSTREE_H 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #define _GNU_SOURCE 33 | #include 34 | #include 35 | #include 36 | 37 | #define MAXSTR 1024 38 | #define MAXPROCS 4096 39 | 40 | void set_procfs_task_dir(pid_t pid, char *dir); 41 | void set_procfs_children_file(pid_t pid, pid_t tid, char *file); 42 | unsigned long get_all_tasks(pid_t pid, pid_t *tasks); 43 | unsigned long get_all_children(pid_t pid, pid_t tid, pid_t *children); 44 | 45 | /* 46 | * get the full process tree rooted at 47 | * is the output array of pids 48 | * is the output array of tids 49 | * return value: no. of items output successfully 50 | * (zero on error) 51 | */ 52 | unsigned long get_pstree(pid_t pid, pid_t *pout, pid_t *tout); 53 | 54 | /* given end > begin, compute the interval elapsed in nanoseconds */ 55 | unsigned long long elapsed_nsec(struct timespec begin, struct timespec end); 56 | 57 | /* given begin/end timestamps and a time period in us, 58 | * sleep for intvl = period - (end-begin) 59 | */ 60 | void sleep_remaining(struct timespec begin, struct timespec end, unsigned long period_us); 61 | 62 | /* given a pid, setup a userspace icounter for polling */ 63 | int setup_icount_poll(pid_t pid); 64 | /* given a pid, setup a group of hardware perfcounters for interrupting. 65 | * leader is the first counter and is expected to be a userspace 66 | * counter (e.g., userspace icount). returns file descriptors 67 | * in 'pfds' for configs specified in 'cfgs'. 'size' is the length 68 | * of both these arrays 69 | */ 70 | void setup_perfcounters_group(pid_t pid, unsigned long long leader_count, int *pfds, unsigned long long *cfgs, unsigned long size); 71 | /* setup a hardware breakpoint in 'pid' 72 | * at 'addr' to fire after 'count' 73 | * occurrences. 74 | */ 75 | int setup_pccount(pid_t pid, void *addr, unsigned long long count); 76 | long parse_long(char *arg, const char *err); 77 | unsigned long long parse_ull(char *arg, const char *err); 78 | double parse_double(char *arg, const char *err); 79 | void copy_ull(unsigned long long *dst, unsigned long long *src, \ 80 | unsigned long count); 81 | void ptrace_cmd(enum __ptrace_request cmd, pid_t pid, void *addr, void *data, \ 82 | const int strict, const char *msg); 83 | void get_monotonic(struct timespec *tp, const char *msg); 84 | 85 | /* append new thread created by clone if not already present */ 86 | int append_thread(pid_t *pout, pid_t *tout, int *pfds, unsigned long *count, \ 87 | pid_t pid, pid_t tid); 88 | pid_t find_pid(pid_t *pout, pid_t *tout, unsigned long count, pid_t tid); 89 | void seize_tid(pid_t tid); 90 | void continue_tid(pid_t tid, pid_t pid); 91 | void interrupt_tid(pid_t tid); 92 | void detach_tid(pid_t tid, pid_t pid); 93 | unsigned long long read_single_icount(int pfd); 94 | unsigned long long read_all_icounts(int *pfds, unsigned long *tdone, \ 95 | unsigned long long *icounts, unsigned long long *prevcounts, \ 96 | unsigned long count); 97 | /* read perf counter values from the group setup by setup_perfcounters_group */ 98 | void read_perfcounters_group(int *pfds, unsigned long long *vals, unsigned long count); 99 | int handle_exit(pid_t *pout, pid_t *tout, int *pfds, unsigned long *tdone, \ 100 | unsigned long long *icounts, unsigned long count, \ 101 | pid_t child, int wstatus, \ 102 | unsigned long *donecount); 103 | 104 | /* handle ptrace stop events */ 105 | int handle_stop(pid_t *pout, pid_t *tout, int *pfds, unsigned long *tdone, \ 106 | unsigned long long *icounts, unsigned long *count, \ 107 | pid_t child, int wstatus, unsigned long *donecount); 108 | #endif 109 | -------------------------------------------------------------------------------- /pintools/ProcessControl/startpaused.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ "$#" -lt 1 ]; then echo "usage: setsid $0 -- "; echo "starts application paused and writes PID to "; exit 1; fi; 3 | #if [ -f $1 ]; then echo "warning: overwriting $1"; fi 4 | echo $$ > $1 5 | shift 6 | kill -SIGSTOP $$ 7 | exec "$@" 8 | 9 | -------------------------------------------------------------------------------- /pintools/README.sde.mbuild: -------------------------------------------------------------------------------- 1 | To build with Intel Software Development Emulator (SDE) version 9.* 2 | 3 | Get SDE: https://www.intel.com/content/www/us/en/developer/articles/tool/software-development-emulator.html 4 | Version 9.0 or higher 5 | 6 | Unpack and set SDE_BUILD_KIT to the root of the SDE kit. 7 | 8 | Download mubild:python-based build system from https://github.com/intelxed/mbuild 9 | 10 | You need to set two environment variables for this to work: 11 | ----------------------------------------------------------- 12 | 1) SDE_BUILD_KIT pointing to the root of the build kit. 13 | 14 | 2) PYTHONPATH pointing to the directory containing build_kit.py and 15 | the directory containing the mbuild/mbuild directory. 16 | 17 | Run mfile.py using python 3.7 or later. 18 | 19 | For example, using a tcsh/csh like shell on non-windows: 20 | 21 | % setenv SDE_BUILD_KIT 22 | 23 | % setenv PYTHONPATH :/pintools/ 24 | 25 | % ./mfile.py --host-cpu ia32 26 | 27 | -------------------------------------------------------------------------------- /pintools/ROIProbe/README.ROIperf: -------------------------------------------------------------------------------- 1 | A Pin-probe/Linux tool, ROIperf.so, to find performance metrics (RDTSC output, hardware performance counters). 2 | See README.probe_control for the types of events supported. 3 | NOTE: not all combination of events are currently supported by ROIperf. 4 | Namely, with PC+count, only the following combinations are supported: 5 | PCstart:PCstop 6 | PCstart:PCdeltastop 7 | PCstart:ideltastop 8 | 9 | To build: 10 | %setenv PIN_ROOT 11 | %make clean; make 12 | 13 | Example: 14 | % echo "RTNstop:exit:1" > probe.in 15 | % cat probe.in 16 | RTNstop:exit:1 17 | 18 | % $PIN_ROOT/pin -t obj-intel64/ROIperf.so -probecontrol:in probe.in -- /bin/ls 19 | ... 20 | exec_count 1 21 | RTNstop event triggered @exit:1 22 | MyHandler called: RTNstop: Exiting on performance counter stop event by design 23 | 24 | % cat perf.txt 25 | RTN ROI end: TSC 10279648900350570 26 | 27 | %setenv ROIPERF_PERFLIST "0:0,0:1" 28 | 29 | % $PIN_ROOT/pin -t obj-intel64/ROIperf.so -probecontrol:in probe.in -- /bin/ls 30 | ... 31 | stop event triggered @exit:1 32 | MyHandler called: RTNstop: Exiting on performance counter stop event by design 33 | 34 | 35 | % cat perf.txt 36 | RTN ROI end: TSC 75189684037029940 37 | hw_cpu_cycles:53501457 hw_instructions:99621299 38 | 39 | -------------------------------------------------------------------------------- /pintools/ROIProbe/README.probe_control: -------------------------------------------------------------------------------- 1 | A generic region-of-interest monitoring utility based on Pin-probes 2 | It allows client tools to register callbacks on region-of-interests. 3 | 4 | Three types of regions are supported: 5 | 6 | 1. SW-based: RTN + count: 7 | Thread-0: give a callback after 'count' executions of PC. 8 | Implemented using Pin-probes 9 | RTNstart:RTN-name:count, RTNstart:hex-PC:count 10 | RTNstop:RTN:-namecount, RTNstop:hex-PC:count 11 | 12 | 2. HW instruction count: 13 | Thread-0: give a callback after 'count' instructions are executed 14 | Implemented using the Linux system call perf_event_open() 15 | with HW counter 'PERF_COUNT_HW_CPU_INSTRUCTIONS' set for an overflow 16 | callback after 'count' instructions 17 | istart:count 18 | istop:count 19 | ideltastop:count ==> enabled only after a "START" event 20 | 21 | 3. HW PC counts: 22 | Thread-0: give a callback after 'pc' is executed'count' times 23 | Implemented using the Linux system call perf_event_open() 24 | with HW counter 'PERF_TYPE_BREAKPOINT' set for an overflow 25 | callback after 'count' executions of a given 'PC-address==value" 26 | pcstart:value:count 27 | pcstop:value:count 28 | pcdeltastop:value:count ==> enabled only after a "START" event 29 | Assumption: PC values are invariant across execution. Make sure Address 30 | Space Layout Randomization (ASLR) is *disabled*. 31 | (echo 0 | sudo tee /proc/sys/kernel/randomize_va_space) 32 | 33 | A client tool can register a callback using RegisterHandler() -- the callback 34 | NOTE: Not all event combinations are supported with ROIperf. 35 | 36 | is only supported for RTNstart/RTNstop events currently. 37 | See ROI_perf.cpp as an example client tool that uses probe_control. 38 | 39 | To build the default tool probe_control.so: 40 | %setenv PIN_ROOT 41 | %make clean; make 42 | 43 | Example: 44 | % echo "stop:exit:1" > probe.in 45 | % cat probe.in 46 | stop:exit:1 47 | 48 | % $PIN_ROOT/pin -t obj-intel64/probe_control.so -probecontrol:in probe.in -- /bin/ls 49 | ... 50 | exec_count 1 51 | stop event triggered @exit:1 52 | MyHandler called: stop 53 | -------------------------------------------------------------------------------- /pintools/ROIProbe/makefile: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | # 3 | # DO NOT EDIT THIS FILE! 4 | # 5 | ############################################################## 6 | 7 | # If the tool is built out of the kit, PIN_ROOT must be specified in the make invocation and point to the kit root. 8 | PIN_ROOT?=$(shell pwd | sed '/extras.*/s///g') 9 | ifdef PIN_ROOT 10 | CONFIG_ROOT := $(PIN_ROOT)/source/tools/Config 11 | else 12 | CONFIG_ROOT := ../Config 13 | endif 14 | include $(CONFIG_ROOT)/makefile.config 15 | include $(TOOLS_ROOT)/Config/makefile.default.rules 16 | include makefile.rules 17 | 18 | ############################################################## 19 | # 20 | # DO NOT EDIT THIS FILE! 21 | # 22 | ############################################################## 23 | -------------------------------------------------------------------------------- /pintools/ROIProbe/makefile.rules: -------------------------------------------------------------------------------- 1 | ############################################################## 2 | # 3 | # This file includes all the test targets as well as all the 4 | # non-default build rules and test recipes. 5 | # 6 | ############################################################## 7 | 8 | 9 | ############################################################## 10 | # 11 | # Test targets 12 | # 13 | ############################################################## 14 | 15 | ###### Place all generic definitions here ###### 16 | 17 | PIN_ROOT?=$(shell pwd | sed '/extras.*/s///g') 18 | 19 | OPT?=-O2 20 | OBJEXT = o 21 | 22 | LTE_LIB_HOME=../../src/lib 23 | 24 | MYLIBS=-lcle -lperfle 25 | 26 | 27 | CXXFLAGS = -DPINCRT -D_FILE_OFFSET_BITS=64 -I$(PIN_ROOT)/source/tools/InstLib -I$(LTE_LIB_HOME) -I/usr/include/x86_64-linux-gnu/bits/types/ 28 | 29 | CXXFLAGS += ${WARNINGS} $(DBG) $(OPT) ${DEPENDENCYFLAG} 30 | 31 | TOOLNAMES=ROIperf probe_control 32 | 33 | TOOLS=${TOOLNAMES:%=$(OBJDIR)$(PINTOOL_PREFIX)%$(PINTOOL_SUFFIX)} 34 | 35 | 36 | # This defines tests which run tools of the same name. This is simply for convenience to avoid 37 | # defining the test name twice (once in TOOL_ROOTS and again in TEST_ROOTS). 38 | # Tests defined here should not be defined in TOOL_ROOTS and TEST_ROOTS. 39 | TEST_TOOL_ROOTS := ${TOOL_NAMES} 40 | 41 | # This defines the tests to be run that were not already defined in TEST_TOOL_ROOTS. 42 | TEST_ROOTS := 43 | 44 | # This defines a list of tests that should run in the "short" sanity. Tests in this list must also 45 | # appear either in the TEST_TOOL_ROOTS or the TEST_ROOTS list. 46 | # If the entire directory should be tested in sanity, assign TEST_TOOL_ROOTS and TEST_ROOTS to the 47 | # SANITY_SUBSET variable in the tests section below (see example in makefile.rules.tmpl). 48 | SANITY_SUBSET := 49 | 50 | # This defines the tools which will be run during the the tests, and were not already defined in 51 | # TEST_TOOL_ROOTS. 52 | TOOL_ROOTS := 53 | 54 | # This defines the static analysis tools which will be run during the the tests. They should not 55 | # be defined in TEST_TOOL_ROOTS. If a test with the same name exists, it should be defined in 56 | # TEST_ROOTS. 57 | # Note: Static analysis tools are in fact executables linked with the Pin Static Analysis Library. 58 | # This library provides a subset of the Pin APIs which allows the tool to perform static analysis 59 | # of an application or dll. Pin itself is not used when this tool runs. 60 | 61 | # This defines all the applications that will be run during the tests. 62 | APP_ROOTS := 63 | 64 | # This defines any additional object files that need to be compiled. 65 | OBJECT_ROOTS := 66 | 67 | # This defines any additional dlls (shared objects), other than the pintools, that need to be compiled. 68 | DLL_ROOTS := 69 | 70 | # This defines any static libraries (archives), that need to be built. 71 | LIB_ROOTS := 72 | 73 | 74 | ############################################################## 75 | # 76 | # Test recipes 77 | # 78 | ############################################################## 79 | 80 | # This section contains recipes for tests other than the default. 81 | # See makefile.default.rules for the default test rules. 82 | # All tests in this section should adhere to the naming convention: .test 83 | 84 | 85 | ############################################################## 86 | # 87 | # Build rules 88 | # 89 | ############################################################## 90 | 91 | # This section contains the build rules for all binaries that have special build rules. 92 | all: myinstall 93 | 94 | myinstall: 95 | $(MAKE) -C $(LTE_LIB_HOME) clean 96 | $(MAKE) -C $(LTE_LIB_HOME) PINCRT=1 97 | $(MAKE) tools 98 | rm -f *.o 99 | 100 | tools: $(TOOLS) 101 | ## build rules 102 | 103 | $(OBJDIR)%.${OBJEXT}: %.cpp 104 | $(CXX) ${MYDEFINES} ${COPT} $(CXXFLAGS) -Wno-unused-variable $(TOOL_CXXFLAGS) $(PIN_CXXFLAGS) ${COMP_OBJ}$@ $< 105 | 106 | $(OBJDIR)ROIperf$(PINTOOL_SUFFIX): $(OBJDIR)ROIperf.${OBJEXT} $(CONTROLLERLIB) 107 | $(LINKER) $(TOOL_LDFLAGS) $(LINK_EXE)$@ $^ $(TOOL_LPATHS) $(TOOL_LIBS) -L$(LTE_LIB_HOME) $(MYLIBS) $(PIN_LIBS) $(DBG) 108 | @echo "" 109 | @echo "*********************************" 110 | @echo "" 111 | 112 | $(OBJDIR)probe_control$(PINTOOL_SUFFIX): $(OBJDIR)probe_control.${OBJEXT} $(CONTROLLERLIB) 113 | $(LINKER) $(TOOL_LDFLAGS) $(LINK_EXE)$@ $^ $(TOOL_LPATHS) $(TOOL_LIBS) -L$(LTE_LIB_HOME) $(MYLIBS) $(PIN_LIBS) $(DBG) 114 | @echo "" 115 | @echo "*********************************" 116 | @echo "" 117 | 118 | ## cleaning 119 | localclean: 120 | -rm -r -f *.${OBJEXT} pin.log obj-* 121 | 122 | # See makefile.default.rules for the default build rules. 123 | -------------------------------------------------------------------------------- /pintools/ROIProbe/probe_control.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2022 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #include "pin.H" 17 | #include "probe_control.H" 18 | 19 | static PROBE_CONTROL::PROBECONTROL pbcontrol; 20 | using namespace std; 21 | 22 | INT32 Usage() 23 | { 24 | cerr << KNOB_BASE::StringKnobSummary() << endl; 25 | 26 | return -1; 27 | } 28 | 29 | VOID MyProbeHandler(PROBE_CONTROL::PROBE_EVENT_TYPE pe) 30 | { 31 | cerr << "MyHandler called: "; 32 | switch(pe) 33 | { 34 | case PROBE_CONTROL::PROBE_EVENT_RSTART: 35 | { 36 | cerr << "RTNstart"; 37 | break; 38 | } 39 | case PROBE_CONTROL::PROBE_EVENT_RSTOP: 40 | { 41 | cerr << "RTNstop"; 42 | break; 43 | } 44 | default: 45 | { 46 | cerr << "INVALID"; 47 | } 48 | } 49 | cerr << endl << flush; 50 | return; 51 | } 52 | 53 | // argc, argv are the entire command line, including pin -t -- ... 54 | int main(int argc, char * argv[]) 55 | { 56 | if( PIN_Init(argc,argv) ) 57 | { 58 | return Usage(); 59 | } 60 | PIN_InitSymbols(); 61 | 62 | if (!pbcontrol.Activate()) 63 | { 64 | cerr << "WARNING: Probe control not activated." << endl; 65 | } 66 | pbcontrol.RegisterHandler(MyProbeHandler); 67 | // Start the program, never returns 68 | PIN_StartProgramProbed(); 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /pintools/ROIProbe/testls.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | start=`nm -D /bin/ls | grep __libc_start_main` 3 | if [ -z "$start" ] 4 | then 5 | echo "Could not find '__libc_start_main' in 'nm -D /bin/ls' output" 6 | exit 1; 7 | fi 8 | stop=`nm -D /bin/ls | grep exit` 9 | if [ -z "$stop" ] 10 | then 11 | echo "Could not find 'exit' in 'nm -D /bin/ls' output" 12 | exit 1; 13 | fi 14 | echo "RTNstart:__libc_start_main:1" > probe.in 15 | #echo "RTNstop:exit:1" >> probe.in 16 | echo "ideltastop:10000" >> probe.in 17 | export ROIPERF_VERBOSE=1 18 | export ROIPERF_PERFLIST="0:0,0:1,1:0" 19 | set -x 20 | $PIN_ROOT/pin -t obj-intel64/ROIperf.so -probecontrol:in probe.in -probecontrol:verbose -verbose -- /bin/ls 21 | cat perf.txt 22 | -------------------------------------------------------------------------------- /scripts/pinball.entry-addr.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Usage: pinball.entry-addr.sh pinball_basename 3 | # Output: Application THREAD-0 entry PC 4 | # ./pinball.entry-addr.sh ../examples/MT/pinball.mt/log_0 5 | #0x2aaac07dbf88 6 | ERROR() 7 | { 8 | echo " Usage: pinball.entry-addr.sh pinball_basename " 9 | exit 10 | } 11 | 12 | endian() 13 | { 14 | v=$1 15 | i=${#v} 16 | while [ $i -gt 0 ] 17 | do 18 | i=$[$i-2] 19 | echo -n ${v:$i:2} 20 | done 21 | echo 22 | } 23 | #set -x 24 | if [ $# -lt 1 ]; then 25 | ERROR 26 | fi 27 | 28 | PINBALL=$1 29 | TNO=0 30 | if [ $# -eq 2 ]; then 31 | TNO=$2 32 | fi 33 | 34 | RIPNO=`grep -i RIP $PINBALL.global.log | awk '{print $2}'` 35 | if [ -e $PINBALL.$TNO.reg ]; 36 | then 37 | RIPValue=`cat $PINBALL.$TNO.reg | grep -e "^$RIPNO" | head -1 | awk '{print $2}'` 38 | fi 39 | if [ -e $PINBALL.$TNO.reg.bz2 ]; 40 | then 41 | RIPValue=`bzcat $PINBALL.$TNO.reg.bz2 | grep -e "^$RIPNO" | head -1 | awk '{print $2}'` 42 | fi 43 | 44 | if [ -z $RIPValue ]; 45 | then 46 | echo "Thread $TNO not valid" 47 | ERROR 48 | fi 49 | echo -n "Thread: $TNO Entry Address: 0x" 50 | endian $RIPValue 51 | -------------------------------------------------------------------------------- /src/.cproject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | lit2elf 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 10 | clean,full,incremental, 11 | 12 | 13 | 14 | 15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 16 | full,incremental, 17 | 18 | 19 | 20 | 21 | 22 | org.eclipse.cdt.core.cnature 23 | org.eclipse.cdt.core.ccnature 24 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/lib/Makefile: -------------------------------------------------------------------------------- 1 | AS=as 2 | ASFLAGS=--64 3 | ifneq ($(DEBUG),) 4 | ASFLAG += -g 5 | endif 6 | 7 | AR=ar 8 | ARFLAGS=cr 9 | 10 | CC=gcc 11 | ifeq ($(DEBUG),) 12 | #CFLAGS=-fPIC -O3 -fno-tree-loop-distribute-patterns 13 | CFLAGS=-fPIC -O1 -fno-tree-loop-distribute-patterns -fno-stack-protector 14 | else 15 | CFLAGS=-fPIC -O0 -g -fno-stack-protector 16 | endif 17 | CFLAGS+=-I. -mcmodel=large -static -fno-zero-initialized-in-bss -fno-stack-protector 18 | ifneq ($(PINCRT),) 19 | #CFLAGS += -DPINCRT -I/usr/include/x86_64-linux-gnu/bits/types/ 20 | CFLAGS += -DPINCRT 21 | endif 22 | 23 | 24 | LIBCLE=libcle.a 25 | LIBPERFLE=libperfle.a 26 | 27 | LIBCLE_OBJECTS=libcle.o libcle_c.o 28 | LIBPERFLE_OBJECTS=libperfle.o 29 | 30 | OBJECTS=$(LIBCLE_OBJECTS) $(LIBPERFLE_OBJECTS) 31 | 32 | all: $(LIBPERFLE) $(LIBCLE) 33 | 34 | libcle: $(LIBCLE) 35 | 36 | libperfle: $(LIBPERFLE) 37 | 38 | $(LIBCLE): $(LIBCLE_OBJECTS) 39 | $(AR) $(ARFLAGS) $@ $^ 40 | 41 | $(LIBPERFLE): $(LIBPERFLE_OBJECTS) $(LIBCLE_OBJECTS) 42 | $(AR) $(ARFLAGS) $@ $^ 43 | 44 | %.o : %.s 45 | $(AS) $(ASFLAGS) -o $@ $< 46 | 47 | clean: 48 | rm -f $(OBJECTS) $(LIBCLE) $(LIBPERFLE) 49 | -------------------------------------------------------------------------------- /src/lib/lte_perf.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_PERF_H 17 | #define LTE_PERF_H 18 | 19 | #ifndef _GNU_SOURCE 20 | # define _GNU_SOURCE 1 21 | #endif 22 | 23 | #include 24 | #include "lte_lc.h" 25 | 26 | #define __lte_data __attribute__ ((section (".data"))) 27 | #define __lte_static static __lte_data 28 | 29 | #define INVALID_TNUM (~(uint64_t)0) 30 | 31 | // We use the hard limits of the kernel to signal 'performance counter overflow' 32 | // as don't want to link with libc (SIGRTMIN/MAX are function calls in libc). 33 | // Don't use __SIGRTMIN..__SIGRTMIN+3 they can be used by threading libraries. 34 | #define SIGPEOVFL_MIN __SIGRTMIN 35 | #define SIGPEOVFL_MAX __SIGRTMAX 36 | #define SIGPEOVFL SIGPEOVFL_MAX 37 | 38 | typedef void* lte_td_t; 39 | typedef void (*lte_pe_cbk_t)(lte_td_t, int, siginfo_t*, void*); 40 | 41 | #ifdef __cplusplus 42 | extern "C" { 43 | #endif 44 | 45 | uint64_t lte_pe_get_num_threads(); 46 | lte_td_t lte_pe_get_thread_desc(uint64_t tnum); 47 | 48 | uint64_t lte_pe_get_thread_num(lte_td_t td); 49 | pid_t lte_pe_get_thread_tid(lte_td_t td); 50 | int lte_pe_get_thread_fd(lte_td_t td); 51 | 52 | uint64_t lte_pe_get_thread_samples(lte_td_t td); 53 | uint64_t lte_pe_get_thread_icount(lte_td_t td); 54 | uint64_t lte_pe_get_thread_icount_max(lte_td_t td); 55 | uint64_t lte_pe_get_thread_icount_period(lte_td_t td); 56 | uint64_t lte_pe_read_thread_icount(lte_td_t td); 57 | 58 | // initializes the library; returns 0 on success, and performs SYS_exit error 59 | // if sigovfl is from [SIGPEOVFL_MIN, SIGPEOVFL_MAX], than sigovfl will be sent 60 | // on performance counter overflow, otherwise SIGIO 61 | int lte_pe_init(uint64_t num_threads, int sigovfl, const void* sigset); 62 | // initiazile sampling for the thread specified by tnum; on error returns 0 63 | lte_td_t lte_pe_init_thread_sampling_idelta(uint64_t tnum, uint64_t icount_period, uint64_t icount_max, lte_pe_cbk_t callback); 64 | 65 | lte_td_t lte_pe_init_thread_sampling_pcdelta(uint64_t tnum, uint64_t bp_addr, uint64_t bpcount_period, uint64_t bpcount_max, lte_pe_cbk_t callback); 66 | 67 | lte_td_t lte_pe_init_thread_sampling_icount(uint64_t tnum, uint64_t icount_period, uint64_t icount_max, lte_pe_cbk_t callback, uint64_t wicount_period, uint64_t wicount_max, lte_pe_cbk_t wcallback); 68 | 69 | // initiazile bp sampling for the thread specified by tnum; on error returns 0 70 | void lte_pe_init_thread_sampling_bp(uint64_t tnum, uint64_t bp_addr, uint64_t bp_period, uint64_t bpcount_max, lte_pe_cbk_t callback, uint64_t wbp_addr, uint64_t wbp_period, uint64_t wbpcount_max, lte_pe_cbk_t wcallback); 71 | 72 | // sets icount for the thread specified by tnum; on error returns 0 73 | lte_td_t lte_pe_set_thread_end(uint64_t tnum, uint64_t icount); 74 | // returns perf counter file descriptor for non-zero td. "-1" if td is 0. 75 | int lte_pe_get_perf_fd(lte_td_t td); 76 | 77 | // opens file descriptor for performance monitoring using event descriptor attached to td as a group leader; -1 on error 78 | int lte_pe_open_thread_perf_event(lte_td_t td, uint32_t pe_type, uint64_t pe_config, uint8_t isglobal); 79 | uint64_t lte_pe_read(int fd); 80 | uint64_t lte_pe_get_thread_num_by_tid(pid_t tid); 81 | 82 | void lte_pe_disable(int fd); 83 | void lte_pe_enable(int fd); 84 | void lte_pe_reset(int fd); 85 | void lte_pe_close(int fd); 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | #endif //LTE_PERF_H 92 | -------------------------------------------------------------------------------- /src/lte_arch_state.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef _LTE_ARCH_STATE_H_ 17 | #define _LTE_ARCH_STATE_H_ 18 | 19 | #include "lte_types.h" 20 | #include "lte_utils.h" 21 | #include "lte_portability.h" 22 | #include "lte_syself.h" 23 | #include "lte_strtab.h" 24 | #include "lte_x86_state.h" 25 | #include "lte_entry_point.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | 36 | #ifdef USE_SAME_INDEXES 37 | #define FIRST_LDT_ENTRY_NUM 0 38 | #else 39 | #define FIRST_LDT_ENTRY_NUM ((LDT_ENTRIES)/2) 40 | #endif 41 | 42 | class config_t; 43 | 44 | class lte_x86_arch_state_t { 45 | protected: 46 | lte_thread_state_t* thread_state; 47 | lte_size_t threads_num; 48 | lte_size_t threads_num_max; 49 | lte_bool_t text_compressed; 50 | unsigned char arch; 51 | 52 | void clear(); 53 | 54 | public: 55 | lte_x86_arch_state_t(int entry_num = FIRST_LDT_ENTRY_NUM); 56 | ~lte_x86_arch_state_t(); 57 | 58 | bool load(config_t& cfg); 59 | 60 | void print(void); 61 | 62 | unsigned char get_arch() const 63 | { 64 | return arch; 65 | } 66 | 67 | lte_size_t get_threads_num() const 68 | { 69 | return threads_num; 70 | } 71 | 72 | lte_bool_t get_text_compressed() const 73 | { 74 | return text_compressed; 75 | } 76 | 77 | lte_size_t get_threads_num_max() const 78 | { 79 | return threads_num; 80 | } 81 | lte_thread_state_t& get_thread_state(lte_size_t tid) 82 | { 83 | return thread_state[tid]; 84 | } 85 | }; 86 | 87 | #endif /* _LTE_ARCH_STATE_H_ */ 88 | -------------------------------------------------------------------------------- /src/lte_defs.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef _LTE_DEFS_H_ 17 | #define _LTE_DEFS_H_ 18 | 19 | #include 20 | 21 | 22 | #ifdef __cplusplus 23 | #define LTE_RCAST(type, v) reinterpret_cast(v) 24 | #define LTE_SCAST(type, v) static_cast(v) 25 | #define LTE_CCAST(type, v) const_cast(v) 26 | #else 27 | #define LTE_RCAST(type, v) ((type)(v)) 28 | #define LTE_SCAST(type, v) ((type)(v)) 29 | #define LTE_CCAST(type, v) ((type)(v)) 30 | #endif /* __cplusplus */ 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #if (defined(__LP64__) || defined(__LP64) || \ 37 | defined(_M_X64) || defined(_WIN64)) 38 | #define __LTE_LP64__ 39 | #else 40 | #define __LTE_LP32__ 41 | #endif 42 | 43 | #if defined(__linux__) 44 | #define __LTE_LINUX__ 45 | #if defined(__LTE_LP64__) 46 | #define __LTE_LINUX64__ 47 | #else 48 | #define __LTE_LINUX32__ 49 | #endif 50 | #else 51 | #error "Unsupported platform" 52 | #endif 53 | 54 | #if defined(_MSC_VER) 55 | #define __LTE_MSVC__ 56 | #elif defined(__GNUC__) 57 | #define __LTE_GNUC__ 58 | #endif 59 | 60 | #if defined(__LTE_LINUX__) 61 | #define __LTE_DECL 62 | #define __LTE_INLINE __inline 63 | #define __LTE_ATTR_PACKED __attribute__((packed)) 64 | #define __LTE_ATTR_ALIGNED(n) __attribute__((aligned(n))) 65 | #define __lte_packed __LTE_ATTR_PACKED 66 | #define __lte_aligned(n) __LTE_ATTR_ALIGNED(n) 67 | #else 68 | #error "Unsupported platform" 69 | #endif 70 | 71 | #if defined(__LTE_BIGENDIAN__) 72 | #define HIBYTE(v) ((lte_uint8_t)(lte_uint16_t)(v)) 73 | #define LOBYTE(v) ((lte_uint8_t)(((lte_uint16_t)(v))>>8)) 74 | #define HIWORD(v) ((lte_uint16_t)(lte_uint32_t)(v)) 75 | #define LOWORD(v) ((lte_uint16_t)(((lte_uint32_t)(v))>>16)) 76 | #define HIDWORD(qw) ((lte_uint32_t)(lte_uint64_t)(qw)) 77 | #define LODWORD(qw) ((lte_uint32_t)(((lte_uint64_t)(qw))>>32)) 78 | #define MKQWORD(hi, lo) ((((lte_uint64_t)(lo))<<32)|((lte_uint32_t)(hi))) 79 | #define QWSETLODW(qw, v) MKQWORD(HIDWORD(qw), v) 80 | #define QWSETHIDW(qw, v) MKQWORD(v, LODWORD(qw)) 81 | #else 82 | #define HIBYTE(v) ((lte_uint8_t)(((lte_uint16_t)(v))>>8)) 83 | #define LOBYTE(v) ((lte_uint8_t)(lte_uint16_t)(v)) 84 | #define HIWORD(v) ((lte_uint16_t)(((lte_uint32_t)(v))>>16)) 85 | #define LOWORD(v) ((lte_uint16_t)(lte_uint32_t)(v)) 86 | #define HIDWORD(qw) ((lte_uint32_t)(((lte_uint64_t)(qw))>>32)) 87 | #define LODWORD(qw) ((lte_uint32_t)(lte_uint64_t)(qw)) 88 | #define MKQWORD(hi, lo) ((((lte_uint64_t)(hi))<<32)|((lte_uint32_t)(lo))) 89 | #define QWSETLODW(qw, v) MKQWORD(HIDWORD(qw), v) 90 | #define QWSETHIDW(qw, v) MKQWORD(v, LODWORD(qw)) 91 | #endif 92 | 93 | #define LTE_PTR2OFFS(p) (LTE_RCAST(char*,p)-LTE_RCAST(char*,0)) 94 | #define LTE_OFFS2PTR(o) (LTE_RCAST(char*,0)+(o)) 95 | #define LTE_PTRDIFF(p1, p2) (LTE_RCAST(char*,p1)-LTE_RCAST(char*,p2)) 96 | 97 | #define LTE_FIELDOFFS(type, item) LTE_PTR2OFFS(&((type*)0)->item) 98 | 99 | /* number of elements in static array */ 100 | #define LTE_ARRAY_SIZE(v) (sizeof(v)/sizeof(*(v))) 101 | /* pointer to element after last element of static array */ 102 | #define LTE_ARRAY_END(v) ((v)+LTE_ARRAY_SIZE(v)) 103 | /* pointer to last element of static array */ 104 | #define LTE_ARRAY_LAST(v) (LTE_ARRAY_END(v)-1) 105 | 106 | /* a must be power of 2 */ 107 | #define LTE_ALIGN(v,a) ((v)&~((a)-1)) 108 | #define LTE_ALIGN_UP(v,a) LTE_ALIGN((v)+(((a)-1)),a) 109 | #define LTE_PTRALIGN(p,a) LTE_OFFS2PTR(LTE_ALIGN(LTE_PTR2OFFS(p,a))) 110 | #define LTE_PTRALIGN_UP(p,a) LTE_OFFS2PTR(LTE_ALIGN_UP(LTE_PTR2OFFS(p,a))) 111 | #define LTE_OFFS(v, a) ((v)&((a)-1)) 112 | 113 | #ifdef __cplusplus 114 | } 115 | #endif 116 | 117 | #endif /*_LTE_DEFS_H_*/ 118 | -------------------------------------------------------------------------------- /src/lte_memimg.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_MEMIMG_H 17 | #define LTE_MEMIMG_H 18 | 19 | #include "lte_types.h" 20 | #include "lte_syself.h" 21 | #include "lte_elf.h" 22 | #include 23 | 24 | const lte_size_t LTE_PAGE_SIZE = 4096; 25 | 26 | enum lte_memsec_flags_enum_t { 27 | SHF_TEXT = (SHF_ALLOC|SHF_EXECINSTR), 28 | SHF_DATA = (SHF_ALLOC|SHF_WRITE), 29 | SHF_TYPEMASK = (SHF_TEXT|SHF_DATA), 30 | SHF_STACK = (1 << 29), // reusing 31 | SHF_DYNALLOC = (1 << 30), // reusing 32 | SHF_ENTRYPOINT = (1 << 31), // reusing 33 | }; 34 | 35 | class lte_mempage_t : public elf_mempage_t { 36 | public: 37 | lte_mempage_t* region_next; 38 | lte_uint64_t region_size; 39 | lte_addr_t va; 40 | lte_addr_t pa; 41 | lte_uint32_t offs_start; 42 | lte_uint32_t offs_end; 43 | 44 | lte_mempage_t(); 45 | lte_uint64_t get(lte_uint32_t offs) { return *(lte_uint64_t*)(data + offs); } 46 | lte_uint32_t set(lte_uint32_t offs, const lte_uint8_t* p, lte_uint32_t size); 47 | }; 48 | 49 | typedef lte_mempage_t lte_memsec_t; 50 | 51 | class lte_memimg_t { 52 | public: 53 | static const lte_uint32_t page_size = 4096; 54 | 55 | protected: 56 | std::map m_mem; 57 | 58 | public: 59 | typedef std::map::iterator iterator; 60 | 61 | public: 62 | lte_memimg_t() {} 63 | 64 | virtual bool load(const char* fname, lte_addr_t addr_max, lte_bool_t text_compressed) = 0; 65 | 66 | lte_addr_t find_free_block(lte_uint64_t size, lte_uint32_t shflags); 67 | lte_mempage_t* get_first_page() { return m_mem.size() ? &m_mem.begin()->second : NULL; } 68 | lte_mempage_t* get_page(lte_addr_t addr); 69 | lte_mempage_t* get_last_page() { return m_mem.size() ? &m_mem.rbegin()->second : NULL; } 70 | lte_uint64_t get_regions_number(lte_uint64_t flags); 71 | void add_missing_page(lte_addr_t missing_page_addr, lte_uint8_t *page_content); 72 | lte_uint64_t compact(lte_uint64_t regions_max = 0); 73 | lte_uint64_t memcopy(lte_addr_t addr, const lte_uint8_t* p, lte_uint64_t size); 74 | lte_addr_t insert(const lte_uint8_t* p, lte_uint64_t size, lte_uint32_t shflags); 75 | iterator begin() { return m_mem.begin(); } 76 | iterator end() { return m_mem.end(); } 77 | void mark(lte_addr_t vastart, lte_addr_t vaend, lte_uint32_t shflags); 78 | void print(); 79 | }; 80 | 81 | class lte_mem_layout_t { 82 | public: 83 | struct region_t { 84 | lte_addr_t vastart; 85 | lte_addr_t vaend; 86 | }; 87 | 88 | protected: 89 | std::map m_regions; 90 | lte_size_t m_block_size; 91 | 92 | public: 93 | typedef std::map::iterator iterator; 94 | 95 | lte_addr_t get_aligned(lte_addr_t va) { return __lte_align(va, m_block_size); } 96 | 97 | public: 98 | lte_mem_layout_t(lte_size_t block_size = LTE_PAGE_SIZE) : m_block_size(block_size) {} 99 | 100 | lte_addr_t insert(lte_addr_t va, lte_uint64_t size); 101 | lte_addr_t insert(lte_uint64_t size); 102 | lte_addr_t find_free_block(lte_addr_t va, lte_uint64_t size); 103 | lte_addr_t find_free_block(lte_uint64_t size); 104 | 105 | iterator begin() { return m_regions.begin(); } 106 | iterator end() { return m_regions.end(); } 107 | 108 | void print(); 109 | }; 110 | 111 | #endif //LTE_MEMIMAGE_H 112 | -------------------------------------------------------------------------------- /src/lte_reg_enum.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #include "lte_reg_enum.h" 17 | #include 18 | 19 | struct str2lte_reg_t { 20 | lte_reg_enum_t id; 21 | const char* name; 22 | }; 23 | 24 | #define DEFINE_STR2LTE_REG_ENUM(NAME) \ 25 | {LTE_REG_ID(NAME), #NAME}, 26 | 27 | #define LTE_STR2LTE_REG_ENUM_MAPPING \ 28 | LTE_REGISTERS_LIST(DEFINE_STR2LTE_REG_ENUM) \ 29 | {LTE_REG_LAST, NULL} 30 | 31 | static str2lte_reg_t map[] = { 32 | LTE_STR2LTE_REG_ENUM_MAPPING 33 | }; 34 | 35 | lte_reg_enum_t str2lte_reg_enum_t(const char* s) 36 | { 37 | if(!strcmp(s, "FS-BASE")) 38 | return LTE_REG_FSBASE; 39 | else if(!strcmp(s, "GS-BASE")) 40 | return LTE_REG_GSBASE; 41 | 42 | for(const str2lte_reg_t* p = map; p->name; ++p) 43 | if(!strcmp(p->name, s)) 44 | return p->id; 45 | return LTE_REG_INVALID; 46 | } 47 | 48 | const char* lte_reg_enum_t2str(const lte_reg_enum_t v) 49 | { 50 | return (v < LTE_REG_LAST) ? map[v].name : NULL; 51 | } 52 | -------------------------------------------------------------------------------- /src/lte_string.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_STRING_H 17 | #define LTE_STRING_H 18 | 19 | #include "lte_types.h" 20 | #include 21 | #include 22 | 23 | class lte_strlist_t { 24 | protected: 25 | std::vector m_index; 26 | std::vector m_str; 27 | lte_size_t m_length; 28 | lte_size_t m_count; 29 | 30 | void push_str_index(lte_size_t idx) { m_index.push_back(idx); ++m_count; } 31 | void push_end_index(lte_size_t idx) { m_index.push_back(idx); } 32 | lte_size_t expand(lte_size_t delta) { lte_size_t sz = m_str.size(); m_str.resize(sz + delta); return sz; } 33 | 34 | public: 35 | lte_strlist_t() : m_length(0), m_count(0) {} 36 | 37 | char* getline(FILE* f, char wt = 0); 38 | 39 | char* c_str() { return &m_str[0]; } 40 | lte_size_t length() const { return m_length; } 41 | 42 | char* c_str(lte_size_t idx) { return &m_str[m_index[idx]]; } 43 | lte_size_t length(lte_size_t idx) const { return m_index[idx+1] - m_index[idx] - 1; } 44 | char* operator[] (lte_size_t idx) { return &m_str[m_index[idx]]; } 45 | 46 | lte_size_t str_count() const { return m_count; } 47 | 48 | char* find(char c); 49 | char* to_upper(lte_size_t idx); 50 | void set_delimiter(char delim); 51 | }; 52 | 53 | char* lte_strrvrs(char* str, lte_size_t len, char* buffer, lte_size_t size); 54 | 55 | char* lte_strrvrshex(char* str, lte_size_t len, char* buffer, lte_size_t size); 56 | 57 | bool lte_strtovec(const char* str, lte_uint64_t* vec, lte_size_t size); 58 | 59 | #endif //LTE_DTRING_H 60 | -------------------------------------------------------------------------------- /src/lte_strtab.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #include "lte_strtab.h" 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | lte_int32_t elf_table_t::find(lte_size_t offset) const 23 | { 24 | return (offset < table.size()) ? (std::distance(index.begin(), std::upper_bound(index.begin(), index.end(), offset)) - 1) : -1; 25 | } 26 | 27 | lte_size_t elf_table_t::pad(lte_size_t size) 28 | { 29 | lte_size_t offs = table.size(); 30 | 31 | if(size) 32 | { 33 | table.resize(offs + size); 34 | index.push_back(offs); 35 | } 36 | 37 | return offs; 38 | } 39 | 40 | lte_size_t elf_table_t::push_back(const void* p, lte_size_t size, int c) 41 | { 42 | lte_size_t offs = table.size(); 43 | 44 | if(size) 45 | { 46 | table.resize(offs + size); 47 | index.push_back(offs); 48 | if(p) 49 | memcpy(ptr() + offs, p, size); 50 | else 51 | memset(ptr() + offs, c, size); 52 | } 53 | 54 | return offs; 55 | } 56 | 57 | void elf_table_t::pop_back(lte_size_t n) 58 | { 59 | if(n < 1) 60 | return; 61 | 62 | lte_size_t size = count(); 63 | if(n < size) 64 | { 65 | size -= n; 66 | table.resize(index[size]); 67 | index.resize(size); 68 | } 69 | else 70 | { 71 | clear(); 72 | } 73 | } 74 | 75 | void elf_strtab_t::push_back_strtab(const char* strtable, lte_size_t size) 76 | { 77 | if(size) 78 | { 79 | lte_size_t offs = table.size(); 80 | lte_size_t tz = (strtable[size - 1] ? 1 : 0); 81 | table.resize(offs + size + tz, 0x72); 82 | 83 | char* pdst = ptr() + offs; 84 | for(const char *psrc = strtable, *pend = strtable + size; psrc != pend;) 85 | { 86 | index.push_back(pdst - ptr()); 87 | while((psrc != pend) && (*pdst++ = *psrc++)); 88 | } 89 | pdst[tz - 1] = 0; 90 | } 91 | } 92 | 93 | lte_size_t elf_strtab_t::push_back_fmt(const char* fmt, ...) 94 | { 95 | va_list args; 96 | int len; 97 | lte_size_t offs = table.size(); 98 | 99 | va_start(args, fmt); 100 | len = lte_vsnprintf(ptr()+offs, 0, fmt, args); 101 | va_end(args); 102 | 103 | if(!len) 104 | return 0; 105 | 106 | table.resize(table.size() + ++len); 107 | index.push_back(offs); 108 | 109 | va_start(args, fmt); 110 | len = lte_vsnprintf(ptr()+offs, len, fmt, args); 111 | va_end(args); 112 | 113 | return offs; 114 | } 115 | 116 | lte_ssize_t elf_strtab_t::set(lte_uint32_t ind, const char* src) 117 | { 118 | if(ind >= count()) 119 | return 0; 120 | 121 | lte_size_t dst_size = size(ind); 122 | lte_size_t src_size = lte_strlen(src) + 1; 123 | lte_size_t table_size = table.size(); 124 | lte_size_t offs = offset(ind); 125 | 126 | if(src_size != dst_size) 127 | { 128 | if(src_size < dst_size) 129 | { 130 | memcpy(&table[offs + src_size], &table[offs + dst_size], table_size - (offs + dst_size)); 131 | table.resize(table_size - (dst_size - src_size)); 132 | } 133 | else 134 | { 135 | table.resize(table_size + (src_size - dst_size)); 136 | memmove(&table[offs + src_size], &table[offs + dst_size], table_size - (offs + dst_size)); 137 | } 138 | for(lte_uint32_t i = ind + 1; i < index.size(); ++i) 139 | index[i] += (src_size - dst_size); 140 | } 141 | memcpy(&table[offs], src, src_size); 142 | 143 | return (src_size - dst_size); 144 | } 145 | -------------------------------------------------------------------------------- /src/lte_strtab.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #pragma once 17 | #ifndef _LTE_STRTAB_H_ 18 | #define _LTE_STRTAB_H_ 19 | 20 | #include "lte_types.h" 21 | #include "lte_utils.h" 22 | #include "lte_portability.h" 23 | #include 24 | 25 | class elf_table_t { 26 | protected: 27 | std::vector table; 28 | std::vector index; 29 | 30 | protected: 31 | const char* ptr() const { return table.size() ? &(table[0]) : nullptr; } 32 | char* ptr() { return table.size() ? &(table[0]) : nullptr; } 33 | lte_size_t push_back(const void* p, lte_size_t size, int c); 34 | 35 | public: 36 | elf_table_t(){} 37 | ~elf_table_t(){} 38 | 39 | public: 40 | lte_size_t push_back(const void* p, lte_size_t size) { return push_back(p, size, 0); } 41 | lte_size_t push_back(int c, lte_size_t size) { return push_back(nullptr, size, c); } 42 | void pop_back(lte_size_t n = 1); 43 | 44 | template T& get(lte_size_t offs) 45 | { 46 | LTE_ASSERT((offs + sizeof(T)) < table_size()); 47 | return *(T*)&table[offs]; 48 | } 49 | template void set(lte_size_t offs, const T& v) 50 | { 51 | get(offs) = v; 52 | } 53 | 54 | lte_uint8_t& byte(lte_size_t offs) { return get(offs); } 55 | lte_uint16_t& word(lte_size_t offs) { return get(offs); } 56 | lte_uint32_t& dword(lte_size_t offs) { return get(offs); } 57 | lte_uint64_t& qword(lte_size_t offs) { return get(offs); } 58 | 59 | const char* table_ptr() const 60 | { 61 | return ptr(); 62 | } 63 | 64 | char* table_ptr() 65 | { 66 | return ptr(); 67 | } 68 | 69 | lte_size_t table_size() const 70 | { 71 | return table.size(); 72 | } 73 | 74 | lte_size_t offset(lte_uint32_t i) const 75 | { 76 | LTE_ASSERT(i < count()); 77 | return index[i]; 78 | } 79 | 80 | lte_int32_t find(lte_size_t offset) const; 81 | 82 | lte_size_t size(lte_uint32_t i) const 83 | { 84 | lte_uint32_t inext = i + 1; 85 | return ((inext == count()) ? table.size() : offset(inext)) - offset(i); 86 | } 87 | 88 | lte_size_t count() const 89 | { 90 | return index.size(); 91 | } 92 | 93 | void clear() 94 | { 95 | table.clear(); 96 | index.clear(); 97 | } 98 | 99 | lte_size_t pad(lte_size_t size); 100 | 101 | const char* operator [] (lte_uint32_t i) const 102 | { 103 | return ptr() + offset(i); 104 | } 105 | }; 106 | 107 | 108 | class elf_strtab_t : public elf_table_t { 109 | public: 110 | elf_strtab_t(){} 111 | ~elf_strtab_t(){} 112 | 113 | public: 114 | void push_back_strtab(const char* strtable, lte_size_t size); 115 | lte_size_t push_back_fmt(const char* fmt, ...); 116 | lte_size_t push_back(const char* str) 117 | { 118 | return elf_table_t::push_back(str, str ? (lte_strlen(str) + 1) : 0); 119 | } 120 | elf_strtab_t& operator << (const char* str) 121 | { 122 | push_back(str); 123 | return *this; 124 | } 125 | lte_ssize_t set(lte_uint32_t i, const char* p); 126 | }; 127 | 128 | 129 | template 130 | inline elf_table_t& operator << (elf_table_t& t, const T& v) 131 | { 132 | t.push_back(&v, sizeof(*&v)); 133 | return t; 134 | } 135 | 136 | #endif /*_LTE_STRTAB_H_*/ 137 | -------------------------------------------------------------------------------- /src/lte_syself.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef _LTE_SYSELF_H_ 17 | #define _LTE_SYSELF_H_ 18 | 19 | #include "lte_defs.h" 20 | #include "lte_types.h" 21 | 22 | #include 23 | 24 | #ifdef __LTE_BIGENDIAN__ 25 | #define ELFSIGNATURE \ 26 | (((lte_uint32_t)ELFMAG3)|(((lte_uint32_t)ELFMAG2)<<8)|(((lte_uint32_t)ELFMAG1)<<16)|(((lte_uint32_t)ELFMAG0)<<24)) 27 | #else 28 | #define ELFSIGNATURE \ 29 | (((lte_uint32_t)ELFMAG0)|(((lte_uint32_t)ELFMAG1)<<8)|(((lte_uint32_t)ELFMAG2)<<16)|(((lte_uint32_t)ELFMAG3)<<24)) 30 | #endif 31 | 32 | typedef Elf64_Rela Elf_Rela_t; 33 | 34 | inline Elf32_Word ELF_R_SYM(Elf64_Xword i) { return (Elf32_Word)(i >> 32); } 35 | inline Elf32_Word ELF_R_TYPE(Elf64_Xword i) { return (Elf32_Word)(i); } 36 | inline Elf64_Xword ELF_R_INFO(Elf32_Word sym, Elf32_Word type) { return (((Elf64_Xword)sym) << 32) | type; } 37 | 38 | typedef struct { 39 | const char* name; 40 | Elf64_Addr offs; 41 | Elf64_Xword size; 42 | unsigned char info; 43 | Elf_Rela_t* rela; 44 | } Elf_SymInfo_t; 45 | 46 | typedef lte_uint8_t Elf_Byte_t; 47 | typedef lte_size_t Elf_Size_t; 48 | typedef unsigned char Elf_Class_t; 49 | 50 | #endif /*_LTE_SYSELF_H_*/ 51 | -------------------------------------------------------------------------------- /src/lte_types.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef _LTE_TYPES_H_ 17 | #define _LTE_TYPES_H_ 18 | 19 | #include "lte_defs.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | typedef char lte_char_t; 26 | typedef unsigned char lte_uchar_t; 27 | typedef short lte_short_t; 28 | typedef unsigned short lte_ushort_t; 29 | typedef int lte_int_t; 30 | typedef unsigned int lte_uint_t; 31 | typedef long lte_long_t; 32 | typedef unsigned long lte_ulong_t; 33 | typedef long long lte_llong_t; 34 | typedef unsigned long long lte_ullong_t; 35 | 36 | typedef bool lte_bool_t; 37 | #define LTE_TRUE true 38 | #define LTE_FALSE false 39 | 40 | #if ((defined(__STDC_VERSION__)) && (__STDC_VERSION__ >= 199901L)) || \ 41 | (defined(__LTE_GNUC__)) 42 | 43 | #include 44 | 45 | #elif (defined(__LTE_MSVC__) && defined(__LTE_WIN32__)) 46 | 47 | typedef __int8 int8_t; 48 | typedef unsigned __int8 uint8_t; 49 | typedef __int16 int16_t; 50 | typedef unsigned __int16 uint16_t; 51 | typedef __int32 int32_t; 52 | typedef unsigned __int32 uint32_t; 53 | typedef __int64 int64_t; 54 | typedef unsigned __int64 uint64_t; 55 | 56 | #else 57 | 58 | typedef lte_char_t int8_t; 59 | typedef lte_uchar_t uint8_t; 60 | typedef lte_short_t int16_t; 61 | typedef lte_ushort_t uint16_t; 62 | typedef lte_int_t int32_t; 63 | typedef lte_uint_t uint32_t; 64 | typedef lte_llong_t int64_t; 65 | typedef lte_ullong_t uint64_t; 66 | 67 | #endif 68 | 69 | #include 70 | 71 | typedef int8_t lte_int8_t; 72 | typedef uint8_t lte_uint8_t; 73 | typedef int16_t lte_int16_t; 74 | typedef uint16_t lte_uint16_t; 75 | typedef int32_t lte_int32_t; 76 | typedef uint32_t lte_uint32_t; 77 | typedef int64_t lte_int64_t; 78 | typedef uint64_t lte_uint64_t; 79 | 80 | typedef lte_uint32_t lte_addr32_t; 81 | typedef lte_uint64_t lte_addr64_t; 82 | 83 | typedef lte_uint32_t lte_size32_t; 84 | typedef lte_uint64_t lte_size64_t; 85 | typedef size_t lte_size_t; 86 | #if defined(__LTE_LINUX) 87 | typedef ssize_t lte_ssize_t; 88 | #elif defined(__LTE_WIN64) 89 | typedef lte_int64_t lte_ssize_t; 90 | #else 91 | typedef lte_int_t lte_ssize_t; 92 | #endif 93 | 94 | typedef lte_addr64_t lte_addr_t; 95 | 96 | #define LTE_ALLONES(type) (((type)0)-((type)1)) 97 | 98 | #define LTE_MAX_SIZE32 LTE_ALLONES(lte_size32_t) 99 | #define LTE_MAX_SIZE64 LTE_ALLONES(lte_size64_t) 100 | #define LTE_MAX_SIZE LTE_ALLONES(lte_size_t) 101 | #define LTE_MAX_ADDR LTE_ALLONES(lte_addr_t) 102 | #define LTE_MAX_ADDR32 LTE_ALLONES(lte_addr32_t) 103 | #define LTE_MAX_ADDR64 LTE_ALLONES(lte_addr64_t) 104 | #define LTE_UINT_MAX LTE_ALLONES(lte_uint_t) 105 | 106 | #define LTE_MAXVAL(type) LTE_ALLONES(type) 107 | 108 | #define LTE_MAXTHREADS 10000 // Max 10 thousand threads supported 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif /*_LTE_TYPES_H_*/ 115 | -------------------------------------------------------------------------------- /src/lte_utils.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #include "lte_utils.h" 17 | #include 18 | #include 19 | #include 20 | 21 | static char error_title[] = "ERROR: "; 22 | static char assert_title[] = "ASSERT: "; 23 | static char warning_title[] = "WARNING: "; 24 | 25 | static void lte_vprint_errmsg(const char* title, const char* fmt, va_list va) 26 | { 27 | if(title != NULL) 28 | fprintf(stderr, "%s", title); 29 | vfprintf(stderr, fmt, va); 30 | fprintf(stderr, "\n"); 31 | } 32 | 33 | extern "C" void lte_verr_msg(const char* fmt, va_list va) 34 | { 35 | lte_vprint_errmsg(error_title, fmt, va); 36 | } 37 | 38 | extern "C" void lte_err_msg(const char* fmt, ...) 39 | { 40 | va_list va; 41 | va_start(va, fmt); 42 | lte_vprint_errmsg(error_title, fmt, va); 43 | va_end(va); 44 | } 45 | 46 | extern "C" void lte_vwarn_msg(const char* fmt, va_list va) 47 | { 48 | lte_vprint_errmsg(warning_title, fmt, va); 49 | } 50 | 51 | extern "C" void lte_warn_msg(const char* fmt, ...) 52 | { 53 | va_list va; 54 | va_start(va, fmt); 55 | lte_vprint_errmsg(warning_title, fmt, va); 56 | va_end(va); 57 | } 58 | 59 | extern "C" void lte_assert_title(const char* fmt, ...) 60 | { 61 | va_list va; 62 | va_start(va, fmt); 63 | lte_vprint_errmsg(assert_title, fmt, va); 64 | va_end(va); 65 | } 66 | 67 | extern "C" void lte_assert(const char* expr, const char* msg, const char* file, int line) 68 | { 69 | lte_assert_title(expr); 70 | if(msg != NULL) 71 | fprintf(stderr, "%s\n", msg); 72 | fprintf(stderr," at %s:%d\n", file, line); 73 | exit(1); 74 | } 75 | 76 | extern "C" void lte_errx(int err, const char* fmt, ...) 77 | { 78 | va_list va; 79 | va_start(va, fmt); 80 | if(fmt) 81 | lte_vprint_errmsg(error_title, fmt, va); 82 | va_end(va); 83 | exit(err); 84 | } 85 | 86 | extern "C" void lte_trace(const char* file, int line, const char* fmt, ...) 87 | { 88 | va_list va; 89 | if(fmt != NULL) 90 | { 91 | fprintf(stderr,"%s, %d:", file, line); 92 | } 93 | va_start(va, fmt); 94 | vfprintf(stderr, fmt, va); 95 | va_end(va); 96 | } 97 | -------------------------------------------------------------------------------- /src/lte_x86.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_X86_H 17 | #define LTE_X86_H 18 | 19 | #include "lte_x86_gpr.h" 20 | #include "lte_x86_fpu.h" 21 | #include "lte_x86_cr.h" 22 | #include "lte_x86_sr.h" 23 | 24 | #endif //LTE_X86_H 25 | -------------------------------------------------------------------------------- /src/lte_x86_cr.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_X86_CR_H 17 | #define LTE_X86_CR_H 18 | 19 | #include "lte_types.h" 20 | 21 | typedef union { 22 | struct { 23 | lte_uint64_t pe :1; 24 | lte_uint64_t mp :1; 25 | lte_uint64_t em :1; 26 | lte_uint64_t ts :1; 27 | lte_uint64_t et :1; 28 | lte_uint64_t ne :1; 29 | lte_uint64_t rsvd0 :10; 30 | lte_uint64_t wp :1; 31 | lte_uint64_t rsvd1 :1; 32 | lte_uint64_t am :1; 33 | lte_uint64_t rsvd2 :10; 34 | lte_uint64_t nw :1; 35 | lte_uint64_t cd :1; 36 | lte_uint64_t pg :1; 37 | lte_uint64_t rsvd3 :32; 38 | } bits; 39 | lte_uint64_t flat; 40 | } lte_cr0_t; 41 | 42 | typedef union { 43 | lte_uint64_t flat; 44 | } lte_cr2_t; 45 | 46 | typedef union { 47 | struct { 48 | lte_uint64_t rsvd0 :3; 49 | lte_uint64_t pwt :1; 50 | lte_uint64_t pcd :1; 51 | lte_uint64_t rsvd1 :7; 52 | lte_uint64_t page_directory_base :20; 53 | } no_pae; // 32b nonPAE 54 | struct { 55 | lte_uint64_t rsvd0 :3; 56 | lte_uint64_t pwt :1; 57 | lte_uint64_t pcd :1; 58 | lte_uint64_t page_directory_pointer_base :27; 59 | } pae; // 32b PAE 60 | struct { 61 | lte_uint64_t rsvd0 :3; 62 | lte_uint64_t pwt :1; 63 | lte_uint64_t pcd :1; 64 | lte_uint64_t rsvd1 :7; 65 | lte_uint64_t page_map4_base :40; 66 | lte_uint64_t rsvd2 :12; 67 | } long_mode; // 64b mode 68 | lte_uint64_t flat; 69 | } lte_cr3_t; 70 | 71 | typedef union { 72 | struct { 73 | lte_uint64_t vme :1; 74 | lte_uint64_t pvi :1; 75 | lte_uint64_t tsd :1; 76 | lte_uint64_t de :1; 77 | 78 | lte_uint64_t pse :1; 79 | lte_uint64_t pae :1; 80 | lte_uint64_t mce :1; 81 | lte_uint64_t pge :1; 82 | 83 | lte_uint64_t pce :1; 84 | lte_uint64_t osfxsr :1; 85 | lte_uint64_t osxmmexcpt :1; 86 | 87 | lte_uint64_t must_be_zero :2; 88 | lte_uint64_t vmxe :1; 89 | lte_uint64_t smxe :1; 90 | lte_uint64_t rsdv0 :2; 91 | lte_uint64_t pcide :1; 92 | lte_uint64_t osxsave :1; 93 | lte_uint64_t rsvd1 :1; 94 | lte_uint64_t smep :1; 95 | lte_uint64_t rsvd2 :43; 96 | } bits; 97 | lte_uint64_t flat; 98 | } lte_cr4_t; 99 | 100 | typedef union { 101 | struct 102 | { 103 | lte_uint64_t sce :1; ///< syscall enable 104 | lte_uint64_t rsvd0 :7; 105 | lte_uint64_t lme :1; ///< long mode enable 106 | lte_uint64_t rsvd1 :1; 107 | lte_uint64_t lma :1; ///< long mode active 108 | lte_uint64_t nxe :1; ///< execute disable bit enable 109 | lte_uint64_t rsvd2 :52; 110 | } bits; 111 | lte_uint64_t flat; 112 | } lte_msr_efer_t; 113 | 114 | #endif /*LTE_X86_CR_H*/ 115 | -------------------------------------------------------------------------------- /src/lte_x86_fpu.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_X86_FPU_H 17 | #define LTE_X86_FPU_H 18 | 19 | #include "lte_types.h" 20 | 21 | typedef union { 22 | lte_uint64_t qw[1]; 23 | lte_uint32_t dw[2]; 24 | } __lte_packed lte_mm_reg_t; 25 | 26 | typedef union { 27 | struct { 28 | lte_uint64_t sgnf; 29 | lte_uint16_t sexp; 30 | }; 31 | lte_mm_reg_t mm; 32 | lte_uint64_t qw[2]; 33 | } __lte_packed lte_x87_st_reg_t; 34 | 35 | typedef union { 36 | lte_uint64_t qw[2]; 37 | lte_uint32_t dw[4]; 38 | } __lte_packed lte_xmm_reg_t; 39 | 40 | typedef union { 41 | lte_xmm_reg_t xmm[2]; 42 | lte_uint64_t qw[4]; 43 | lte_uint32_t dw[8]; 44 | } __lte_packed lte_ymm_reg_t; 45 | 46 | typedef union { 47 | lte_ymm_reg_t ymm[2]; 48 | lte_xmm_reg_t xmm[4]; 49 | lte_uint64_t qw[8]; 50 | lte_uint32_t dw[16]; 51 | } __lte_packed lte_zmm_reg_t; 52 | 53 | typedef lte_uint64_t lte_opmask_reg_t; 54 | 55 | #endif /*LTE_X86_FPU_H*/ 56 | -------------------------------------------------------------------------------- /src/lte_x86_gpr.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #include "lte_x86_gpr.h" 17 | #include "lte_utils.h" 18 | #include 19 | 20 | typedef enum { 21 | LTE_IND_RFLAGS = 0, 22 | LTE_IND_RDI = 1, 23 | LTE_IND_RSI = 2, 24 | LTE_IND_RBP = 3, 25 | LTE_IND_RSP = 4, 26 | LTE_IND_RBX = 5, 27 | LTE_IND_RDX = 6, 28 | LTE_IND_RCX = 7, 29 | LTE_IND_RAX = 8, 30 | LTE_IND_R8 = 9, 31 | LTE_IND_R9 = 10, 32 | LTE_IND_R10 = 11, 33 | LTE_IND_R11 = 12, 34 | LTE_IND_R12 = 13, 35 | LTE_IND_R13 = 14, 36 | LTE_IND_R14 = 15, 37 | LTE_IND_R15 = 16, 38 | LTE_IND_RIP = 17, 39 | 40 | LTE_IND_EFLAGS = LTE_IND_RFLAGS, 41 | LTE_IND_EDI = LTE_IND_RDI, 42 | LTE_IND_ESI = LTE_IND_RSI, 43 | LTE_IND_EBP = LTE_IND_RBP, 44 | LTE_IND_ESP = LTE_IND_RSP, 45 | LTE_IND_EBX = LTE_IND_RBX, 46 | LTE_IND_EDX = LTE_IND_RDX, 47 | LTE_IND_ECX = LTE_IND_RCX, 48 | LTE_IND_EAX = LTE_IND_RAX, 49 | LTE_IND_EIP = LTE_IND_RIP, 50 | } lte_gpr_index_enum_t; 51 | 52 | 53 | static lte_gpr_index_enum_t gr_indices[] = 54 | { 55 | LTE_IND_RAX, LTE_IND_RCX, LTE_IND_RDX, LTE_IND_RBX, LTE_IND_RSP, LTE_IND_RBP, LTE_IND_RSI, LTE_IND_RDI, 56 | LTE_IND_R8, LTE_IND_R9, LTE_IND_R10, LTE_IND_R11, LTE_IND_R12, LTE_IND_R13, LTE_IND_R14, LTE_IND_R15, 57 | }; 58 | 59 | #define REG(regtype, regarray, regid, reghalf) (((regtype*)(((lte_uint64_t*)(regarray)) + gr_indices[regid]))[reghalf]) 60 | #define R64(regarray, regid) REG(lte_gpr64_t, regarray, (regid-LTE_REG_GPR64_FIRST), 0) 61 | #define R32(regarray, regid) REG(lte_gpr32_t, regarray, (regid-LTE_REG_GPR32_FIRST), 0) 62 | #define R16(regarray, regid) REG(lte_gpr16_t, regarray, (regid-LTE_REG_GPR16_FIRST), 0) 63 | #define R8L(regarray, regid) REG(lte_gpr8_t, regarray, (regid-LTE_REG_GPR8_FIRST), 0) 64 | #define R8H(regarray, regid) REG(lte_gpr8_t, regarray, (regid-LTE_REG_GPR8H_FIRST), 1) 65 | 66 | void lte_gpr_state_set_reg(lte_gpr_state_t* state, const lte_reg_enum_t reg, lte_gpr64_t v) 67 | { 68 | if(LTE_REG_GPR64_FIRST <= reg && reg <= LTE_REG_GPR64_LAST) 69 | { 70 | R64(state->r, reg) = v; 71 | } 72 | else if (LTE_REG_GPR32_FIRST <= reg && reg <= LTE_REG_GPR32_LAST) 73 | { 74 | R32(state->r, reg) = (lte_gpr32_t)v; 75 | } 76 | else if (LTE_REG_GPR16_FIRST <= reg && reg <= LTE_REG_GPR16_LAST) 77 | { 78 | R16(state->r, reg) = (lte_gpr16_t)v; 79 | } 80 | else if (LTE_REG_GPR8_FIRST <= reg && reg <= LTE_REG_GPR8_LAST) 81 | { 82 | R8L(state->r, reg) = (lte_gpr8_t)v; 83 | } 84 | else if (LTE_REG_GPR8H_FIRST <= reg && reg <= LTE_REG_GPR8H_LAST) 85 | { 86 | R8H(state->r, reg) = (lte_gpr8_t)v; 87 | } 88 | else if(LTE_REG_FLAGS_FIRST <= reg && reg <= LTE_REG_FLAGS_LAST) 89 | { 90 | state->r[LTE_IND_RFLAGS] = v; 91 | } 92 | else 93 | { 94 | LTE_ASSERT(false); 95 | } 96 | } 97 | 98 | void lte_gpr_state_init(lte_gpr_state_t* state) 99 | { 100 | memset(state->r, 0, sizeof(state->r)); 101 | } 102 | -------------------------------------------------------------------------------- /src/lte_x86_gpr.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_X86_GPR_H 17 | #define LTE_X86_GPR_H 18 | 19 | #include "lte_types.h" 20 | #include "lte_reg_enum.h" 21 | 22 | // GPRs 23 | typedef lte_uint8_t lte_gpr8_t; 24 | typedef lte_uint16_t lte_gpr16_t; 25 | typedef lte_uint32_t lte_gpr32_t; 26 | typedef lte_uint64_t lte_gpr64_t; 27 | 28 | // GPR state 29 | typedef union { 30 | struct { 31 | union { 32 | lte_gpr64_t rflags; 33 | lte_gpr32_t eflags; 34 | }; 35 | union { 36 | lte_gpr64_t rdi; 37 | lte_gpr32_t edi; 38 | }; 39 | union { 40 | lte_gpr64_t rsi; 41 | lte_gpr32_t esi; 42 | }; 43 | union { 44 | lte_gpr64_t rbp; 45 | lte_gpr32_t ebp; 46 | }; 47 | union { 48 | lte_gpr64_t rsp; 49 | lte_gpr32_t esp; 50 | }; 51 | union { 52 | lte_gpr64_t rbx; 53 | lte_gpr32_t ebx; 54 | }; 55 | union { 56 | lte_gpr64_t rdx; 57 | lte_gpr32_t edx; 58 | }; 59 | union { 60 | lte_gpr64_t rcx; 61 | lte_gpr32_t ecx; 62 | }; 63 | union { 64 | lte_gpr64_t rax; 65 | lte_gpr32_t eax; 66 | }; 67 | union { 68 | lte_gpr64_t r8; 69 | lte_gpr32_t r8d; 70 | }; 71 | union { 72 | lte_gpr64_t r9; 73 | lte_gpr32_t r9d; 74 | }; 75 | union { 76 | lte_gpr64_t r10; 77 | lte_gpr32_t r10d; 78 | }; 79 | union { 80 | lte_gpr64_t r11; 81 | lte_gpr32_t r11d; 82 | }; 83 | union { 84 | lte_gpr64_t r12; 85 | lte_gpr32_t r12d; 86 | }; 87 | union { 88 | lte_gpr64_t r13; 89 | lte_gpr32_t r13d; 90 | }; 91 | union { 92 | lte_gpr64_t r14; 93 | lte_gpr32_t r14d; 94 | }; 95 | union { 96 | lte_gpr64_t r15; 97 | lte_gpr32_t r15d; 98 | }; 99 | }; 100 | lte_gpr64_t r[17]; 101 | } __lte_packed lte_gpr_state_t; 102 | 103 | 104 | void lte_gpr_state_init(lte_gpr_state_t* state); 105 | 106 | void lte_gpr_state_set_reg(lte_gpr_state_t* state, const lte_reg_enum_t reg, lte_gpr64_t v); 107 | 108 | #endif /*LTE_X86_GPR_H*/ 109 | -------------------------------------------------------------------------------- /src/lte_x86_ldt.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_X86_LDT_H 17 | #define LTE_X86_LDT_H 18 | 19 | #include "lte_types.h" 20 | #include "lte_reg_enum.h" 21 | 22 | #include 23 | #include 24 | 25 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 26 | typedef struct user_desc lte_ldt_entry_t; 27 | #else 28 | typedef struct modify_ldt_ldt_s lte_ldt_entry_t; 29 | #endif 30 | 31 | #define LDT_FIRST_ENTRY ((LDT_ENTRIES)/2) 32 | #define LDT_ENTRY(sr) (LDT_FIRST_ENTRY+((sr)-LTE_REG_SR_FIRST)) 33 | 34 | #endif /*LTE_X86_LDT_H*/ 35 | -------------------------------------------------------------------------------- /src/lte_x86_state.cpp: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #include "lte_x86_state.h" 17 | #include "lte_reg_enum.h" 18 | 19 | static void lte_x86_state_init_seg_sel_4G(lte_ldt_entry_t* d, lte_uint32_t num, lte_uint32_t rx_only, lte_uint32_t type) 20 | { 21 | memset(d, 0, sizeof(*d)); 22 | 23 | d->entry_number = num; 24 | d->limit = 0xfffff; 25 | d->seg_32bit = 1; 26 | d->contents = type & 3; 27 | d->read_exec_only = rx_only & 1; 28 | d->limit_in_pages = 1; 29 | d->useable = 1; 30 | } 31 | 32 | void lte_x86_state_init_state(lte_x86_state_t* p) 33 | { 34 | lte_x86_state_zero_state(p); 35 | 36 | p->xstate.fx.fcw = 0x037f; 37 | p->xstate.fx.ftw = 0x0000; // abridged tag 38 | p->xstate.fx.mxcsr = 0x1f80; 39 | p->xstate.fx.mxcsr_mask = 0xffff; 40 | 41 | // set to be NULL selectors 42 | p->srstate.gs.sel.v = MAKE_SEG_SEL(0, 0, 3); 43 | p->srstate.fs.sel.v = MAKE_SEG_SEL(0, 0, 3); 44 | p->srstate.es.sel.v = MAKE_SEG_SEL(0, 0, 3); 45 | p->srstate.ds.sel.v = MAKE_SEG_SEL(0, 0, 3); 46 | p->srstate.cs.sel.v = MAKE_SEG_SEL(0, 0, 3); 47 | p->srstate.ss.sel.v = MAKE_SEG_SEL(0, 0, 3); 48 | 49 | lte_x86_state_init_seg_sel_4G(&p->segdesc[LTE_REG_GS-LTE_REG_SR_FIRST], LDT_ENTRY(LTE_REG_GS), 0, SD_CONTENT_DATA); 50 | lte_x86_state_init_seg_sel_4G(&p->segdesc[LTE_REG_FS-LTE_REG_SR_FIRST], LDT_ENTRY(LTE_REG_FS), 0, SD_CONTENT_DATA); 51 | lte_x86_state_init_seg_sel_4G(&p->segdesc[LTE_REG_ES-LTE_REG_SR_FIRST], LDT_ENTRY(LTE_REG_ES), 0, SD_CONTENT_DATA); 52 | lte_x86_state_init_seg_sel_4G(&p->segdesc[LTE_REG_DS-LTE_REG_SR_FIRST], LDT_ENTRY(LTE_REG_DS), 0, SD_CONTENT_DATA); 53 | lte_x86_state_init_seg_sel_4G(&p->segdesc[LTE_REG_CS-LTE_REG_SR_FIRST], LDT_ENTRY(LTE_REG_CS), 1, SD_CONTENT_CODE); 54 | lte_x86_state_init_seg_sel_4G(&p->segdesc[LTE_REG_SS-LTE_REG_SR_FIRST], LDT_ENTRY(LTE_REG_SS), 0, SD_CONTENT_STACK); 55 | } 56 | 57 | lte_uint16_t lte_fxstate_get_abridged_ftw(lte_uint16_t ftw_hw) 58 | { 59 | lte_uint16_t ftw_fx = 0x00ff; 60 | 61 | for(lte_uint16_t mask_hw = 3, mask_fx = 1; mask_hw; mask_hw <<= 2, mask_fx <<= 1) 62 | { 63 | if((ftw_hw & mask_hw) == mask_hw) 64 | { 65 | ftw_fx ^= mask_fx; 66 | } 67 | } 68 | 69 | return ftw_fx; 70 | } 71 | -------------------------------------------------------------------------------- /src/lte_x86_state.h: -------------------------------------------------------------------------------- 1 | /*BEGIN_LEGAL 2 | BSD License 3 | 4 | Copyright (c)2019 Intel Corporation. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | 12 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | END_LEGAL */ 16 | #ifndef LTE_X86_STATE_H 17 | #define LTE_X86_STATE_H 18 | 19 | #include "lte_x86_xstate.h" 20 | #include "lte_reg_enum.h" 21 | 22 | typedef struct { 23 | lte_xstate_t xstate; 24 | lte_sr_state_t srstate; 25 | lte_gpr_state_t gprstate; 26 | lte_ldt_entry_t segdesc[6]; 27 | union { 28 | lte_gpr64_t rip; 29 | lte_gpr32_t eip; 30 | }; 31 | lte_gpr64_t xcr0; 32 | } __lte_packed __lte_aligned(64) lte_x86_state_t; 33 | 34 | static __LTE_INLINE void lte_x86_state_zero_state(lte_x86_state_t* p) 35 | { 36 | memset(p, 0, sizeof(*p)); 37 | } 38 | 39 | void lte_x86_state_init_state(lte_x86_state_t* p); 40 | 41 | #endif /*LTE_XSAVE_H*/ 42 | -------------------------------------------------------------------------------- /src/startup/Makefile: -------------------------------------------------------------------------------- 1 | ARCH?=64 2 | ASFLAGS=--64 3 | LDFLAGS=-m elf_x86_64 4 | 5 | 6 | ifeq ($(ARCH),64) 7 | # x86_64, st 8 | else 9 | ifeq ($(ARCH),64mt) 10 | # x86_64, mt 11 | else 12 | ifeq ($(ARCH),32) 13 | # i386, st 14 | LDFLAGS=-m elf_i386 15 | ASFLAGS=--32 16 | else 17 | ifeq ($(ARCH),32mt) 18 | # i386, mt 19 | LDFLAGS=-m elf_i386 20 | ASFLAGS=--32 21 | else 22 | $(error Wrong ARCH value) 23 | endif 24 | endif 25 | endif 26 | endif 27 | 28 | TARGET=litstart$(ARCH) 29 | 30 | all: $(TARGET) 31 | 32 | OBJECTS=$(TARGET).o $(TARGET)_state.o $(TARGET)_lit.o 33 | 34 | $(TARGET): $(OBJECTS) 35 | ld $(LDFLAGS) -o $@ $^ 36 | @[ -r $@ ] && objdump -d $@ >$@.dis 37 | @[ -r $@ ] && objdump -t $@ >$@.sym 38 | @[ -r $@ ] && readelf -a $@ >$@.elf 39 | @[ -r $@.dis ] && ./dumpstart.pl $@.dis >$@.c 40 | 41 | %.o : %.s 42 | $(AS) $(ASFLAGS) -o $@ $< 43 | 44 | clean: 45 | rm $(OBJECTS) $(TARGET) $(TARGET).dis $(TARGET).sym $(TARGET).elf -------------------------------------------------------------------------------- /src/startup/dumpstart.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | BEGIN { 4 | use File::Basename; 5 | push(@INC,dirname($0)); 6 | } 7 | 8 | use Getopt::Long; 9 | use File::Spec::Functions qw(catdir catfile); 10 | use File::Basename qw(fileparse basename dirname); 11 | use Data::Dumper; 12 | use Cwd qw(cwd abs_path); 13 | use integer; 14 | use Fcntl; 15 | 16 | sub cvtfile 17 | { 18 | my $fname = shift; 19 | my $start_addr; 20 | my $end_addr; 21 | my $instr_len_max = 0; 22 | 23 | open(FH,"< $fname") or die "Couldn't open $fname: $!\n"; 24 | while(my $s = ) 25 | { 26 | # 4000bc: 49 bc 53 04 40 00 00 movabs $0x400453,%r12 27 | if($s =~ /^\s+([a-fA-F\d]+)\:(.*)/) 28 | { 29 | my $instr_addr = $1; 30 | my $instr_len = 0; 31 | my @opcodes = split(' ', $2); 32 | 33 | if(!defined $start_addr) 34 | { 35 | $start_addr = $instr_addr; 36 | } 37 | $end_addr = $instr_addr; 38 | 39 | for my $o (@opcodes) 40 | { 41 | if($o =~ /^[a-fA-F\d][a-fA-F\d]$/) 42 | { 43 | $instr_len++; 44 | } 45 | else 46 | { 47 | last; 48 | } 49 | } 50 | $instr_len_max = $instr_len if($instr_len > $instr_len_max); 51 | } 52 | } 53 | 54 | seek(FH, 0, SEEK_SET); 55 | 56 | my $fmt = sprintf("%%%dx", length(sprintf("%x", hex($end_addr)-hex($start_addr)))); 57 | 58 | while(my $s = ) 59 | { 60 | if($s =~ /^\s+([a-fA-F\d]+)\:(.*)/) 61 | { 62 | my $instr_addr = $1; 63 | my @v = split(' ', $2); 64 | 65 | $instr_addr = sprintf($fmt, hex($instr_addr)-hex($start_addr)); 66 | print " /*$instr_addr*/"; 67 | 68 | my $item; 69 | my $i = 0; 70 | while (defined($item = shift @v)) 71 | { 72 | if($item =~ /^[a-fA-F\d][a-fA-F\d]$/) 73 | { 74 | print " 0x$item,"; 75 | $i++; 76 | } 77 | else 78 | { 79 | for(; $i < $instr_len_max; $i++) 80 | { 81 | print " "; 82 | } 83 | 84 | my $s = join(' ', @v); 85 | print " //$item $s"; 86 | last; 87 | } 88 | } 89 | print "\n"; 90 | } 91 | else 92 | { 93 | last if($s =~ /^\s*[a-fA-F\d]+\s+\\:/); 94 | print "//$1\n" if($s =~ /^\s*[a-fA-F\d]+\s+(\<.*\>\:)/); 95 | } 96 | } 97 | close(FH); 98 | } 99 | 100 | cvtfile(@ARGV) if((0+@ARGV) > 0); 101 | 1; 102 | -------------------------------------------------------------------------------- /src/startup/litstart32.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .include "litstart32_defs.s" 17 | 18 | .text 19 | .globl _start 20 | _start: 21 | mov $cpu_state,%esp 22 | fxrstor (%esp) 23 | add $state.fs_desc_offs,%esp 24 | mov $0x7b,%eax 25 | mov $0x1,%ebx 26 | mov %esp,%ecx 27 | mov $state.desc_size,%edx 28 | int $0x80 29 | test %eax,%eax 30 | jne _exit 31 | mov state.fs_offs-state.fs_desc_offs(%esp),%fs 32 | mov $0x7b,%eax 33 | mov $0x1,%ebx 34 | lea state.gs_desc_offs-state.fs_desc_offs(%esp),%ecx 35 | mov $state.desc_size,%edx 36 | int $0x80 37 | test %eax,%eax 38 | jne _exit 39 | mov state.gs_offs-state.fs_desc_offs(%esp),%gs 40 | add $state.gpr_state_offs-state.fs_desc_offs,%esp 41 | popf 42 | popa 43 | mov -0x14(%esp),%esp 44 | jmp _lit_start 45 | _exit: 46 | mov $0x0,%ebx 47 | mov $0x1,%eax 48 | int $0x80 49 | -------------------------------------------------------------------------------- /src/startup/litstart32_defs.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .set state.desc_size,16 17 | .set state.fs_desc_offs,2800 18 | .set state.fs_offs,2816 19 | .set state.gs_desc_offs,2820 20 | .set state.gs_offs,2836 21 | .set state.gpr_state_offs,2840 22 | .set state_size,2944 23 | 24 | -------------------------------------------------------------------------------- /src/startup/litstart32_lit.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .text 17 | .globl _lit_start 18 | _lit_start: 19 | mov $0x0,%ebx 20 | mov $0x1,%eax 21 | int $0x80 22 | -------------------------------------------------------------------------------- /src/startup/litstart32mt.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .include "litstart32mt_defs.s" 17 | 18 | .set CLONE_VM,0x100 19 | .set CLONE_FS,0x200 20 | .set CLONE_FILES,0x400 21 | .set CLONE_SIGHAND,0x800 22 | .set CLONE_PARENT,0x8000 23 | .set CLONE_THREAD,0x10000 24 | .set CLONE_IO,0x80000000 25 | .set CLONE_FLAGS,CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_PARENT|CLONE_THREAD|CLONE_IO 26 | .set SYS_exit,0x01 27 | .set SYS_clone,0x78 28 | .set SYS_modify_ldt,0x7b 29 | 30 | .text 31 | .globl _start 32 | _start: 33 | mov $1,%ebp 34 | mov $cpu_state,%esp 35 | .create_thread: 36 | dec %ebp 37 | jz .thread_start 38 | mov $CLONE_FLAGS,%ebx 39 | mov %esp,%ecx 40 | mov $SYS_clone,%eax 41 | int $0x80 42 | test %eax,%eax 43 | jz .thread_start 44 | add $state_size,%esp 45 | jmp .create_thread 46 | .exit: 47 | mov $0x0,%ebx 48 | mov $SYS_exit,%eax 49 | int $0x80 50 | .thread_start: 51 | fxrstor (%esp) 52 | add $state.fs_desc_offs,%esp 53 | mov $SYS_modify_ldt,%eax 54 | mov $0x1,%ebx 55 | mov %esp,%ecx 56 | mov $state.desc_size,%edx 57 | int $0x80 58 | test %eax,%eax 59 | jne .exit 60 | mov state.fs_offs-state.fs_desc_offs(%esp),%fs 61 | mov $SYS_modify_ldt,%eax 62 | mov $0x1,%ebx 63 | lea state.gs_desc_offs-state.fs_desc_offs(%esp),%ecx 64 | mov $state.desc_size,%edx 65 | int $0x80 66 | test %eax,%eax 67 | jne .exit 68 | mov state.gs_offs-state.fs_desc_offs(%esp),%gs 69 | add $state.gpr_state_offs-state.fs_desc_offs,%esp 70 | popa 71 | popf 72 | ret 73 | .tst.t0: 74 | pop %esp 75 | jmp .t0.start 76 | .tst.t1: 77 | pop %esp 78 | jmp .t1.start 79 | .tst.end: 80 | -------------------------------------------------------------------------------- /src/startup/litstart32mt_defs.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .set state.desc_size,16 17 | .set state.fs_desc_offs,2800 18 | .set state.fs_offs,2816 19 | .set state.gs_desc_offs,2820 20 | .set state.gs_offs,2836 21 | .set state.gpr_state_offs,2840 22 | .set state_size,2944 23 | 24 | -------------------------------------------------------------------------------- /src/startup/litstart32mt_lit.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .text 17 | .globl .t0.start 18 | .t0.start: 19 | mov $0x0,%ebx 20 | mov $0x1,%eax 21 | int $0x80 22 | .globl .t1.start 23 | .t1.start: 24 | mov $0x0,%ebx 25 | mov $0x1,%eax 26 | int $0x80 27 | -------------------------------------------------------------------------------- /src/startup/litstart32mt_state.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .globl cpu_state 17 | .data 18 | .align 64 19 | .type cpu_state, @object 20 | .size cpu_state, 2944 21 | cpu_state: 22 | t0.fcw: 23 | .word 0x37f 24 | t0.fsw: 25 | .zero 2 26 | t0.ftw: 27 | .zero 2 28 | t0.fop: 29 | .zero 2 30 | t0.fpuip: 31 | .zero 8 32 | t0.fpudp: 33 | .zero 8 34 | t0.mxcsr: 35 | .long 0x1f80 36 | t0.mxcsr_mask: 37 | .long 0xffff 38 | t0.st: 39 | .zero 128 40 | t0.xmm: 41 | .zero 256 42 | .zero 96 43 | t0.xhdr: 44 | .quad 0x1 45 | .zero 56 46 | t0.ext_area2: 47 | .zero 384 48 | t0.ext_area3: 49 | .zero 64 50 | t0.ext_area4: 51 | .zero 64 52 | t0.ext_area5: 53 | .zero 64 54 | t0.ext_area6: 55 | .zero 512 56 | t0.ext_area7: 57 | .zero 1024 58 | t0.ext_area8: 59 | .zero 104 60 | t0.ext_area9: 61 | .zero 8 62 | .quad 0x1002 63 | .quad 0x51000fffff 64 | t0.fs.sel.v: 65 | .long 0x801f 66 | .quad 0x1005 67 | .quad 0x51000fffff 68 | t0.gs.sel.v: 69 | .long 0x802f 70 | t0.eflags: 71 | .zero 4 72 | t0.edi: 73 | .zero 4 74 | t0.esi: 75 | .zero 4 76 | t0.ebp: 77 | .zero 4 78 | .zero 4 79 | t0.ebx: 80 | .zero 4 81 | t0.edx: 82 | .zero 4 83 | t0.ecx: 84 | .zero 4 85 | t0.eax: 86 | .zero 4 87 | t0.tst.eip: 88 | .long 0x7b 89 | t0.esp: 90 | .zero 4 91 | .zero 56 92 | .zero 4 93 | -------------------------------------------------------------------------------- /src/startup/litstart64.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .include "litstart64_defs.s" 17 | 18 | .text 19 | .globl _start 20 | _start: 21 | movabs $cpu_state,%rsp 22 | mov $0x03,%eax # xfeatures_lo_dword mask 23 | mov $0x00,%edx # xfeatures_hi_dword mask 24 | xrstor (%rsp) 25 | add $state.fs_desc_offs,%rsp 26 | mov $0x9a,%rax 27 | mov $0x1,%rdi 28 | mov %rsp,%rsi 29 | mov $state.desc_size,%rdx 30 | syscall 31 | test %rax,%rax 32 | jnz pbs.exit 33 | mov state.fs_offs-state.fs_desc_offs(%rsp),%fs 34 | mov $0x9e,%rax 35 | mov $0x1002,%rdi 36 | mov state.fs_base_offs-state.fs_desc_offs(%rsp),%rsi 37 | syscall 38 | test %rax,%rax 39 | jnz pbs.exit 40 | mov $0x9a,%rax 41 | mov $0x1,%rdi 42 | lea state.gs_desc_offs-state.fs_desc_offs(%rsp),%rsi 43 | mov $state.desc_size,%rdx 44 | syscall 45 | test %rax,%rax 46 | jnz pbs.exit 47 | mov state.gs_offs-state.fs_desc_offs(%rsp),%gs 48 | mov $0x9e,%rax 49 | mov $0x1001,%rdi 50 | mov state.gs_base_offs-state.fs_desc_offs(%rsp),%rsi 51 | syscall 52 | test %rax,%rax 53 | jnz pbs.exit 54 | add $state.gpr_state_offs-state.fs_desc_offs,%rsp 55 | popfq 56 | pop %rdi 57 | pop %rsi 58 | pop %rbp 59 | pop %rbx 60 | pop %rdx 61 | pop %rcx 62 | pop %rax 63 | pop %r8 64 | pop %r9 65 | pop %r10 66 | pop %r11 67 | pop %r12 68 | pop %r13 69 | pop %r14 70 | pop %r15 71 | pop %rsp 72 | jmpq *pbs.trace.start(%rip) 73 | .text 74 | .globl pbs.trace.start 75 | pbs.trace.start: 76 | .quad trace.start 77 | .text 78 | .globl pbs.exit 79 | pbs.exit: 80 | mov $0x0,%rdi 81 | mov $0x3c,%rax 82 | syscall 83 | -------------------------------------------------------------------------------- /src/startup/litstart64_defs.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .set state.desc_size, 16 17 | .set state.fs_desc_offs, 0xaf0 18 | .set state.fs_offs, 0xb00 19 | .set state.fs_base_offs, 0xb04 20 | .set state.gs_desc_offs, 0xb0c 21 | .set state.gs_offs, 0xb1c 22 | .set state.gs_base_offs, 0xb20 23 | .set state.gpr_state_offs, 0xb28 24 | -------------------------------------------------------------------------------- /src/startup/litstart64_lit.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .data 17 | str: 18 | .string "Hello, World!\n" 19 | 20 | .text 21 | .globl trace.start 22 | trace.start: 23 | mov $1, %rax 24 | mov $1, %rdi 25 | lea str, %rsi 26 | mov $14, %rdx 27 | syscall 28 | 29 | mov $0x0,%rdi 30 | mov $0x3c,%rax 31 | syscall 32 | -------------------------------------------------------------------------------- /src/startup/litstart64mt_defs.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .set state.desc_size, 16 17 | .set state.fs_desc_offs, 0xaf0 18 | .set state.fs_offs, 0xb00 19 | .set state.fs_base_offs, 0xb04 20 | .set state.gs_desc_offs, 0xb0c 21 | .set state.gs_offs, 0xb1c 22 | .set state.gs_base_offs, 0xb20 23 | .set state.gpr_state_offs, 0xb28 24 | .set state_size, 0xbc0 25 | -------------------------------------------------------------------------------- /src/startup/litstart64mt_lit.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .data 17 | str: 18 | .string "CBK: Hello, World!\n" 19 | 20 | .text 21 | .globl trace.start 22 | trace.start: 23 | mov $1, %rax 24 | mov $1, %rdi 25 | lea str, %rsi 26 | mov $20, %rdx 27 | syscall 28 | 29 | mov $0x0,%rdi 30 | mov $0x3c,%rax 31 | syscall 32 | .text 33 | .globl elfie_on_thread_start 34 | elfie_on_thread_start: 35 | ret 36 | .globl elfie_on_start 37 | elfie_on_start: 38 | ret 39 | .globl elfie_on_exit 40 | elfie_on_exit: 41 | ret 42 | -------------------------------------------------------------------------------- /src/startup/litstart64mt_state.s: -------------------------------------------------------------------------------- 1 | #BEGIN_LEGAL 2 | #BSD License 3 | # 4 | #Copyright (c)2019 Intel Corporation. All rights reserved. 5 | # 6 | #Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | # 8 | #1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | # 10 | #2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 11 | # 12 | #3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 13 | # 14 | #THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 15 | #END_LEGAL 16 | .globl cpu_state 17 | .data 18 | .align 64 19 | .type cpu_state, @object 20 | .size cpu_state, 3072 21 | cpu_state: 22 | .ifdef CALLBACKS 23 | .zero 64 24 | .endif 25 | t0.fcw: 26 | .word 0x37f 27 | t0.fsw: 28 | .zero 2 29 | t0.ftw: 30 | .zero 2 31 | t0.fop: 32 | .zero 2 33 | t0.fpuip: 34 | .zero 8 35 | t0.fpudp: 36 | .zero 8 37 | t0.mxcsr: 38 | .long 0x1f80 39 | t0.mxcsr_mask: 40 | .long 0xffff 41 | t0.st: 42 | .zero 128 43 | t0.xmm: 44 | .zero 256 45 | .zero 96 46 | t0.xhdr: 47 | .quad 0x1 48 | .zero 56 49 | t0.ext_area2: 50 | .zero 384 51 | t0.ext_area3: 52 | .zero 64 53 | t0.ext_area4: 54 | .zero 64 55 | t0.ext_area5: 56 | .zero 64 57 | t0.ext_area6: 58 | .zero 512 59 | t0.ext_area7: 60 | .zero 1024 61 | t0.ext_area8: 62 | .zero 104 63 | t0.ext_area9: 64 | .zero 8 65 | .quad 0x1002 66 | .quad 0x51000fffff 67 | t0.fs.sel.v: 68 | .long 0x801f 69 | t0.fs_base: 70 | .zero 8 71 | .quad 0x1005 72 | .quad 0x51000fffff 73 | t0.gs.sel.v: 74 | .long 0x802f 75 | t0.gs_base: 76 | .zero 8 77 | t0.rflags: 78 | .zero 8 79 | t0.rdi: 80 | .zero 8 81 | t0.rsi: 82 | .zero 8 83 | t0.rbp: 84 | .zero 8 85 | t0.rbx: 86 | .zero 8 87 | t0.rdx: 88 | .zero 8 89 | t0.rcx: 90 | .zero 8 91 | t0.rax: 92 | .zero 8 93 | t0.r8: 94 | .zero 8 95 | t0.r9: 96 | .zero 8 97 | t0.r10: 98 | .zero 8 99 | t0.r11: 100 | .zero 8 101 | t0.r12: 102 | .zero 8 103 | t0.r13: 104 | .zero 8 105 | t0.r14: 106 | .zero 8 107 | t0.r15: 108 | .zero 8 109 | t0.tst.rip: 110 | .quad 0xd7 111 | t0.rsp: 112 | .zero 8 113 | .zero 8 114 | --------------------------------------------------------------------------------