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_endpgm");
36 __builtin_unreachable ();
37 }
38
39 static inline void __attribute__((noreturn))
exit_with_status_and_signal(int val,int signal)40 exit_with_status_and_signal (int val, int signal)
41 {
42 if (signal == 0)
43 val = val & 0xff;
44 else
45 {
46 val = (128 + signal) & 0xff;
47 signal = signal & 0xff;
48 }
49
50 exit_with_int ((0xffff << 16) | (signal << 8) | val);
51 }
52
53 #endif
54