mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-23 02:05:57 +01:00
x86 asm: move RDTSC from x86-assembly-cheat, create RDTSCP
This commit is contained in:
@@ -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;
|
||||
}
|
||||
15
userland/arch/x86_64/intrinsics/rdtscp.c
Normal file
15
userland/arch/x86_64/intrinsics/rdtscp.c
Normal 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;
|
||||
}
|
||||
12
userland/arch/x86_64/rdtsc.S
Normal file
12
userland/arch/x86_64/rdtsc.S
Normal 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
|
||||
20
userland/arch/x86_64/rdtscp.S
Normal file
20
userland/arch/x86_64/rdtscp.S
Normal 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
|
||||
Reference in New Issue
Block a user