1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2017 Red Hat
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Authors:
25 * Ben Crocker <[email protected]>
26 */
27
28 #ifdef HAVE_FUNC_ATTRIBUTE_VISIBILITY
29 #define HIDDEN __attribute__((visibility("hidden")))
30 #else
31 #define HIDDEN
32 #endif
33
34 // NOTE: These must be powers of two:
35 #define PPC64LE_ENTRY_SIZE 64
36 #define PPC64LE_PAGE_ALIGN 65536
37 #if ((PPC64LE_ENTRY_SIZE & (PPC64LE_ENTRY_SIZE - 1)) != 0)
38 #error PPC64LE_ENTRY_SIZE must be a power of two!
39 #endif
40 #if ((PPC64LE_PAGE_ALIGN & (PPC64LE_PAGE_ALIGN - 1)) != 0)
41 #error PPC64LE_PAGE_ALIGN must be a power of two!
42 #endif
43
44 __asm__(".text\n"
45 ".balign " U_STRINGIFY(PPC64LE_ENTRY_SIZE) "\n"
46 "ppc64le_entry_start:");
47
48 #define STUB_ASM_ENTRY(func) \
49 ".globl " func "\n" \
50 ".type " func ", @function\n" \
51 ".balign " U_STRINGIFY(PPC64LE_ENTRY_SIZE) "\n" \
52 func ":\n\t" \
53 " addis 2, 12, .TOC.-" func "@ha\n\t" \
54 " addi 2, 2, .TOC.-" func "@l\n\t" \
55 " .localentry " func ", .-" func "\n\t"
56
57 #define STUB_ASM_CODE(slot) \
58 " addis 11, 2, _glapi_tls_Dispatch@got@tprel@ha\n\t" \
59 " ld 11, _glapi_tls_Dispatch@got@tprel@l(11)\n\t" \
60 " add 11, 11,_glapi_tls_Dispatch@tls\n\t" \
61 " ld 11, 0(11)\n\t" \
62 " ld 12, " slot "*8(11)\n\t" \
63 " mtctr 12\n\t" \
64 " bctr\n" \
65
66 #define MAPI_TMP_STUB_ASM_GCC
67 #include "mapi_tmp.h"
68
69 #ifndef MAPI_MODE_BRIDGE
70
71 #include <string.h>
72
73 void
entry_patch_public(void)74 entry_patch_public(void)
75 {
76 }
77
78 extern char
79 ppc64le_entry_start[] HIDDEN;
80
81 mapi_func
entry_get_public(int slot)82 entry_get_public(int slot)
83 {
84 return (mapi_func) (ppc64le_entry_start + slot * PPC64LE_ENTRY_SIZE);
85 }
86
87 #endif /* MAPI_MODE_BRIDGE */
88