1 /* Support for AMDHSA ELF.
3 Copyright (C) 2019 Free Software Foundation, Inc.
4 Copyright (C) 2019 Advanced Micro Devices, Inc. All rights reserved.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 #include "elf/amdgcn.h"
31 bfd_amdgcn_get_mach_from_notes (bfd
*abfd
)
33 asection
* note_section
;
34 bfd_size_type buffer_size
;
35 bfd_byte
* ptr
, * end
, * buffer
= NULL
;
36 unsigned int mach
= 0;
38 note_section
= bfd_get_section_by_name (abfd
, ".note");
39 if (note_section
== NULL
)
42 buffer_size
= note_section
->size
;
46 if (!bfd_malloc_and_get_section (abfd
, note_section
, &buffer
))
50 end
= &buffer
[buffer_size
];
51 while (mach
== 0 && buffer
< end
)
57 if ((ptr
+ 12) >= end
)
60 namesz
= bfd_get_32 (abfd
, ptr
);
61 descsz
= bfd_get_32 (abfd
, ptr
+ 4);
62 type
= bfd_get_32 (abfd
, ptr
+ 8);
64 if (namesz
== 4 && (ptr
+ 16) <= end
65 && (!strcmp((char*) ptr
+ 12, "AMDGPU")
66 || !strcmp((char*) ptr
+ 12, "AMD"))
67 && type
== NT_AMDGPU_HSA_ISA
)
69 unsigned int major
, minor
, patch
;
71 major
= bfd_get_32 (abfd
, ptr
+ 20);
72 minor
= bfd_get_32 (abfd
, ptr
+ 24);
73 patch
= bfd_get_32 (abfd
, ptr
+ 28);
75 switch (major
* 100 + minor
* 10 + patch
)
77 case 801: mach
= bfd_mach_amdgcn_gfx801
; break;
78 case 802: mach
= bfd_mach_amdgcn_gfx802
; break;
79 case 803: mach
= bfd_mach_amdgcn_gfx803
; break;
80 case 810: mach
= bfd_mach_amdgcn_gfx810
; break;
81 case 900: mach
= bfd_mach_amdgcn_gfx900
; break;
82 case 902: mach
= bfd_mach_amdgcn_gfx902
; break;
83 case 904: mach
= bfd_mach_amdgcn_gfx904
; break;
84 case 906: mach
= bfd_mach_amdgcn_gfx906
; break;
85 case 908: mach
= bfd_mach_amdgcn_gfx908
; break;
86 case 909: mach
= bfd_mach_amdgcn_gfx909
; break;
87 default: mach
= bfd_mach_amdgcn_unknown
; break;
91 ptr
+= 12 + ((namesz
+ 3) & ~3) + ((descsz
+ 3) & ~3);
102 elf64_amdgcn_object_p (bfd
*abfd
)
106 if (elf_elfheader (abfd
)->e_ident
[EI_OSABI
] != ELFOSABI_AMDGPU_HSA
)
109 if (elf_elfheader (abfd
)->e_ident
[EI_ABIVERSION
] < 1)
110 mach
= bfd_amdgcn_get_mach_from_notes (abfd
);
112 mach
= elf_elfheader (abfd
)->e_flags
& EF_AMDGPU_MACH
;
114 bfd_default_set_arch_mach (abfd
, bfd_arch_amdgcn
, mach
);
119 #define TARGET_LITTLE_SYM amdgcn_elf64_le_vec
120 #define TARGET_LITTLE_NAME "elf64-amdgcn"
121 #define ELF_ARCH bfd_arch_amdgcn
122 #define ELF_TARGET_ID AMDGCN_ELF_DATA
123 #define ELF_MACHINE_CODE EM_AMDGPU
124 #define ELF_OSABI ELFOSABI_AMDGPU_HSA
125 #define ELF_MAXPAGESIZE 0x10000 /* 64KB */
126 #define ELF_COMMONPAGESIZE 0x1000 /* 4KB */
128 #define bfd_elf64_bfd_reloc_type_lookup \
129 bfd_default_reloc_type_lookup
130 #define bfd_elf64_bfd_reloc_name_lookup \
131 _bfd_norelocs_bfd_reloc_name_lookup
133 #define elf_backend_object_p \
134 elf64_amdgcn_object_p
136 #include "elf64-target.h"