-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathget_htm_failure_code.c
39 lines (31 loc) · 1010 Bytes
/
get_htm_failure_code.c
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
/*
* How to abort with a user-provided code and get TEXASR
* inspected for the code.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
int main(void)
{
asm(
" tbegin. \n\t"
" beq exit \n\t"
" li 14, 0xAB \n\t" // Arbitrary user-provided code.
" tabort. 14 \n\t"
" tend. \n\t"
"exit: \n\t"
: // no output
: "r"(counter_ptr)
: "r14","r15", "r16", "r17"
);
uint64_t texasr = __builtin_get_texasr();
uint8_t code = texasr >> 56; // Right way to inspect.
printf("HTM failure code: 0x%X\n", code);
}
/*
References:
[1] http://lxr.free-electrons.com/source/tools/testing/selftests/powerpc/tm/tm-resched-dscr.c
[2] https://github.com/torvalds/linux/blob/master/Documentation/powerpc/transactional_memory.txt#L174
*/