x86 asm: move RDTSC from x86-assembly-cheat, create RDTSCP

This commit is contained in:
Ciro Santilli 六四事件 法轮功
2019-06-16 00:00:04 +00:00
parent 658ac53d0f
commit ef4fa33ef7
6 changed files with 133 additions and 40 deletions

View File

@@ -1,5 +1,6 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-rdtsc-instruction */
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -7,8 +8,6 @@
#include <x86intrin.h>
int main(void) {
uintmax_t val;
val = __rdtsc();
printf("%ju\n", val);
printf("0x%016" PRIX64 "\n", (uint64_t)__rdtsc());
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,15 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-rdtscp-instruction */
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <x86intrin.h>
int main(void) {
uint32_t pid;
printf("0x%016" PRIX64 "\n", (uint64_t)__rdtscp(&pid));
printf("0x%08" PRIX32 "\n", pid);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,12 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-rdtsc-instruction */
#include <lkmc.h>
LKMC_PROLOGUE
rdtsc
mov %edx, %edi
shl $32, %rdi
add %rax, %rdi
call lkmc_print_hex_64
call lkmc_print_newline
LKMC_EPILOGUE

View File

@@ -0,0 +1,20 @@
/* https://github.com/cirosantilli/linux-kernel-module-cheat#x86-rdtscp-instruction */
#include <lkmc.h>
LKMC_PROLOGUE
rdtscp
mov %edx, %edi
shl $32, %rdi
add %rax, %rdi
mov %ecx, %r12d
/* Print RDTSC. */
call lkmc_print_hex_64
call lkmc_print_newline
/* Print PID. */
mov %r12d, %edi
call lkmc_print_hex_32
call lkmc_print_newline
LKMC_EPILOGUE