1 /*
2 * Support file for amdgcn in newlib.
3 * Copyright (c) 2017 Mentor Graphics.
4 *
5 * The authors hereby grant permission to use, copy, modify, distribute,
6 * and license this software and its documentation for any purpose, provided
7 * that existing copyright notices are retained in all copies and that this
8 * notice is included verbatim in any distributions. No written agreement,
9 * license, or royalty fee is required for any of the authorized uses.
10 * Modifications to this software may be copyrighted by their authors
11 * and need not follow the licensing terms described here, provided that
12 * the new terms are clearly indicated on the first page of each file where
13 * they apply.
14 */
15
16 #ifndef _AMDGCN_EXIT_VALUE_H_
17 #define _AMDGCN_EXIT_VALUE_H_
18
19 static inline void __attribute__((noreturn))
exit_with_int(int val)20 exit_with_int (int val)
21 {
22 /* Write the exit value to the conventional place. */
23 int *return_value;
24 #if defined(__has_builtin) && __has_builtin(__builtin_gcn_kernarg_ptr)
25 __asm__ ("s_load_dwordx2 %0, %1, 16 glc\n\t"
26 "s_waitcnt 0"
27 : "=Sg"(return_value) : "r"(__builtin_gcn_kernarg_ptr()));
28 #else
29 __asm__ ("s_load_dwordx2 %0, s[8:9], 16 glc\n\t"
30 "s_waitcnt 0" : "=Sg"(return_value));
31 #endif
32 *return_value = val;
33
34 /* Terminate the current kernel. */
35 __asm__ ("s_dcache_wb");
36 __asm__ ("s_endpgm");
37 __builtin_unreachable ();
38 }
39
40 static inline void __attribute__((noreturn))
exit_with_status_and_signal(int val,int signal)41 exit_with_status_and_signal (int val, int signal)
42 {
43 if (signal == 0)
44 val = val & 0xff;
45 else
46 {
47 val = (128 + signal) & 0xff;
48 signal = signal & 0xff;
49 }
50
51 exit_with_int ((0xffff << 16) | (signal << 8) | val);
52 }
53
54 #endif
55