summaryrefslogtreecommitdiffstats
path: root/meta-microblaze/recipes-devtools/gdb
diff options
context:
space:
mode:
authorMark Hatle <mark.hatle@kernel.crashing.org>2020-07-21 10:53:19 -0500
committerMark Hatle <mark.hatle@kernel.crashing.org>2020-08-14 11:56:33 -0500
commit8138cf33a5d2900bbd44259af9776b78f23763a7 (patch)
tree04792e71c54f4052e51c7939d16750bd2317abd3 /meta-microblaze/recipes-devtools/gdb
parent557ab11ff5be82548b5fd97e9c75b3e9b7524414 (diff)
downloadmeta-xilinx-8138cf33a5d2900bbd44259af9776b78f23763a7.tar.gz
meta-microblaze: Rename recipes-microblaze to match oe-core
Signed-off-by: Mark Hatle <mark.hatle@kernel.crashing.org>
Diffstat (limited to 'meta-microblaze/recipes-devtools/gdb')
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb-cross-canadian_%.bbappend4
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb-cross_%.bbappend4
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb-microblaze.inc47
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0001-Add-wdc.ext.clear-and-wdc.ext.flush-insns.patch65
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0003-Disable-the-warning-message-for-eh_frame_hdr.patch31
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0004-Fix-relaxation-of-assembler-resolved-references.patch61
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0005-LOCAL-Fixup-debug_loc-sections-after-linker-relaxati.patch207
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0006-upstream-change-to-garbage-collection-sweep-causes-m.patch39
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0007-Fix-bug-in-TLSTPREL-Relocation.patch33
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0008-Added-Address-extension-instructions.patch98
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0009-fixing-the-MAX_OPCODES-to-correct-value.patch25
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0010-Add-new-bit-field-instructions.patch139
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0011-fixing-the-imm-bug.patch27
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch4186
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0016-MB-X-initial-commit.patch355
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0017-Patch-Microblaze-negl-instruction-is-overriding-rsub.patch36
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0018-Added-relocations-for-MB-X.patch113
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0019-Fixed-MB-x-relocation-issues.patch115
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0020-Fixing-the-branch-related-issues.patch25
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0021-Fixed-address-computation-issues-with-64bit-address.patch97
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0022-Adding-new-relocation-to-support-64bit-rodata.patch69
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0023-fixing-the-.bss-relocation-issue.patch76
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0024-Fixed-the-bug-in-the-R_MICROBLAZE_64_NONE-relocation.patch44
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0025-Patch-MicroBlaze-fixed-Build-issue-which-are-due-to-.patch51
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0026-Patch-Microblaze-changes-of-PR22458-failure-to-choos.patch31
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0028-Patch-Microblaze-Binutils-security-check-is-causing-.patch33
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0029-fixing-the-long-long-long-mingw-toolchain-issue.patch27
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0030-Added-support-to-new-arithmetic-single-register-inst.patch166
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0031-Patch-MicroBlaze-double-imml-generation-for-64-bit-v.patch28
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0032-Add-initial-port-of-linux-gdbserver.patch435
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0033-Initial-port-of-core-reading-support.patch388
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0034-Fix-debug-message-when-register-is-unavailable.patch40
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0035-revert-master-rebase-changes-to-gdbserver.patch31
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0036-revert-master-rebase-changes-to-gdbserver-previous-c.patch33
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0037-microblaze-Add-build_gdbserver-yes-to-top-level-conf.patch32
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0038-Initial-support-for-native-gdb.patch511
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0039-Fixing-the-issues-related-to-GDB-7.12.patch309
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0040-Patch-microblaze-Adding-64-bit-MB-support.patch1110
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0041-patch-MicroBlaze-porting-GDB-for-linux.patch155
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0042-Correcting-the-register-names-from-slr-shr-to-rslr-r.patch146
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0043-Removing-the-header-gdb_assert.h-from-MB-target-file.patch24
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb/0044-gdb-microblaze-linux-nat.c-Fix-target-compilation-of.patch363
-rw-r--r--meta-microblaze/recipes-devtools/gdb/gdb_%.bbappend4
43 files changed, 9813 insertions, 0 deletions
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb-cross-canadian_%.bbappend b/meta-microblaze/recipes-devtools/gdb/gdb-cross-canadian_%.bbappend
new file mode 100644
index 00000000..ceb7b02b
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb-cross-canadian_%.bbappend
@@ -0,0 +1,4 @@
1MICROBLAZEPATCHES = ""
2MICROBLAZEPATCHES_microblaze = "gdb-microblaze.inc"
3
4require ${MICROBLAZEPATCHES}
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb-cross_%.bbappend b/meta-microblaze/recipes-devtools/gdb/gdb-cross_%.bbappend
new file mode 100644
index 00000000..ceb7b02b
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb-cross_%.bbappend
@@ -0,0 +1,4 @@
1MICROBLAZEPATCHES = ""
2MICROBLAZEPATCHES_microblaze = "gdb-microblaze.inc"
3
4require ${MICROBLAZEPATCHES}
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb-microblaze.inc b/meta-microblaze/recipes-devtools/gdb/gdb-microblaze.inc
new file mode 100644
index 00000000..4db9957c
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb-microblaze.inc
@@ -0,0 +1,47 @@
1# MicroBlaze does not support LTTng UST
2LTTNGUST_microblaze = ""
3
4# Add MicroBlaze patches
5FILESEXTRAPATHS_append := ":${THISDIR}/gdb"
6
7SRC_URI_append_microblaze = " \
8 file://0001-Add-wdc.ext.clear-and-wdc.ext.flush-insns.patch \
9 file://0003-Disable-the-warning-message-for-eh_frame_hdr.patch \
10 file://0004-Fix-relaxation-of-assembler-resolved-references.patch \
11 file://0005-LOCAL-Fixup-debug_loc-sections-after-linker-relaxati.patch \
12 file://0006-upstream-change-to-garbage-collection-sweep-causes-m.patch \
13 file://0007-Fix-bug-in-TLSTPREL-Relocation.patch \
14 file://0008-Added-Address-extension-instructions.patch \
15 file://0009-fixing-the-MAX_OPCODES-to-correct-value.patch \
16 file://0010-Add-new-bit-field-instructions.patch \
17 file://0011-fixing-the-imm-bug.patch \
18 file://0015-intial-commit-of-MB-64-bit.patch \
19 file://0016-MB-X-initial-commit.patch \
20 file://0017-Patch-Microblaze-negl-instruction-is-overriding-rsub.patch \
21 file://0018-Added-relocations-for-MB-X.patch \
22 file://0019-Fixed-MB-x-relocation-issues.patch \
23 file://0020-Fixing-the-branch-related-issues.patch \
24 file://0021-Fixed-address-computation-issues-with-64bit-address.patch \
25 file://0022-Adding-new-relocation-to-support-64bit-rodata.patch \
26 file://0023-fixing-the-.bss-relocation-issue.patch \
27 file://0024-Fixed-the-bug-in-the-R_MICROBLAZE_64_NONE-relocation.patch \
28 file://0025-Patch-MicroBlaze-fixed-Build-issue-which-are-due-to-.patch \
29 file://0026-Patch-Microblaze-changes-of-PR22458-failure-to-choos.patch \
30 file://0028-Patch-Microblaze-Binutils-security-check-is-causing-.patch \
31 file://0029-fixing-the-long-long-long-mingw-toolchain-issue.patch \
32 file://0030-Added-support-to-new-arithmetic-single-register-inst.patch \
33 file://0031-Patch-MicroBlaze-double-imml-generation-for-64-bit-v.patch \
34 file://0032-Add-initial-port-of-linux-gdbserver.patch \
35 file://0033-Initial-port-of-core-reading-support.patch \
36 file://0034-Fix-debug-message-when-register-is-unavailable.patch \
37 file://0035-revert-master-rebase-changes-to-gdbserver.patch \
38 file://0036-revert-master-rebase-changes-to-gdbserver-previous-c.patch \
39 file://0037-microblaze-Add-build_gdbserver-yes-to-top-level-conf.patch \
40 file://0038-Initial-support-for-native-gdb.patch \
41 file://0039-Fixing-the-issues-related-to-GDB-7.12.patch \
42 file://0040-Patch-microblaze-Adding-64-bit-MB-support.patch \
43 file://0041-patch-MicroBlaze-porting-GDB-for-linux.patch \
44 file://0042-Correcting-the-register-names-from-slr-shr-to-rslr-r.patch \
45 file://0043-Removing-the-header-gdb_assert.h-from-MB-target-file.patch \
46 file://0044-gdb-microblaze-linux-nat.c-Fix-target-compilation-of.patch \
47 "
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0001-Add-wdc.ext.clear-and-wdc.ext.flush-insns.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0001-Add-wdc.ext.clear-and-wdc.ext.flush-insns.patch
new file mode 100644
index 00000000..4b85d7c9
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0001-Add-wdc.ext.clear-and-wdc.ext.flush-insns.patch
@@ -0,0 +1,65 @@
1From f1cb2126c751d6c2526ea969918d5b51dd5b851f Mon Sep 17 00:00:00 2001
2From: David Holsgrove <david.holsgrove@xilinx.com>
3Date: Wed, 8 May 2013 11:03:36 +1000
4Subject: [PATCH 01/43] Add wdc.ext.clear and wdc.ext.flush insns
5
6Added two new instructions, wdc.ext.clear and wdc.ext.flush,
7to enable MicroBlaze to flush an external cache, which is
8used with the new coherency support for multiprocessing.
9
10Signed-off-by:nagaraju <nmekala@xilix.com>
11Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
12---
13 opcodes/microblaze-opc.h | 5 ++++-
14 opcodes/microblaze-opcm.h | 4 ++--
15 2 files changed, 6 insertions(+), 3 deletions(-)
16
17diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
18index 62ee3c9a4d..865151f95b 100644
19--- a/opcodes/microblaze-opc.h
20+++ b/opcodes/microblaze-opc.h
21@@ -91,6 +91,7 @@
22 #define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
23 #define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
24 #define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
25+#define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
26 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
27
28 /* New Mask for msrset, msrclr insns. */
29@@ -101,7 +102,7 @@
30 #define DELAY_SLOT 1
31 #define NO_DELAY_SLOT 0
32
33-#define MAX_OPCODES 289
34+#define MAX_OPCODES 291
35
36 struct op_code_struct
37 {
38@@ -174,7 +175,9 @@ struct op_code_struct
39 {"wic", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000068, OPCODE_MASK_H34B, wic, special_inst },
40 {"wdc", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000064, OPCODE_MASK_H34B, wdc, special_inst },
41 {"wdc.clear", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000066, OPCODE_MASK_H34B, wdcclear, special_inst },
42+ {"wdc.ext.clear", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000466, OPCODE_MASK_H35B, wdcextclear, special_inst },
43 {"wdc.flush", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000074, OPCODE_MASK_H34B, wdcflush, special_inst },
44+ {"wdc.ext.flush", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000476, OPCODE_MASK_H35B, wdcextflush, special_inst },
45 {"mts", INST_TYPE_SPECIAL_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_MTS, 0x9400C000, OPCODE_MASK_H13S, mts, special_inst },
46 {"mfs", INST_TYPE_RD_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_MFS, 0x94008000, OPCODE_MASK_H23S, mfs, special_inst },
47 {"br", INST_TYPE_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98000000, OPCODE_MASK_H124, br, branch_inst },
48diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
49index 5a2d3b0c8b..42f3dd3be5 100644
50--- a/opcodes/microblaze-opcm.h
51+++ b/opcodes/microblaze-opcm.h
52@@ -33,8 +33,8 @@ enum microblaze_instr
53 /* 'or/and/xor' are C++ keywords. */
54 microblaze_or, microblaze_and, microblaze_xor,
55 andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
56- wic, wdc, wdcclear, wdcflush, mts, mfs, mbar, br, brd,
57- brld, bra, brad, brald, microblaze_brk, beq, beqd, bne, bned, blt,
58+ wic, wdc, wdcclear, wdcextclear, wdcflush, wdcextflush, mts, mfs, mbar, br,
59+ brd, brld, bra, brad, brald, microblaze_brk, beq, beqd, bne, bned, blt,
60 bltd, ble, bled, bgt, bgtd, bge, bged, ori, andi, xori, andni,
61 imm, rtsd, rtid, rtbd, rted, bri, brid, brlid, brai, braid, bralid,
62 brki, beqi, beqid, bnei, bneid, blti, bltid, blei, bleid, bgti,
63--
642.17.1
65
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0003-Disable-the-warning-message-for-eh_frame_hdr.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0003-Disable-the-warning-message-for-eh_frame_hdr.patch
new file mode 100644
index 00000000..53415370
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0003-Disable-the-warning-message-for-eh_frame_hdr.patch
@@ -0,0 +1,31 @@
1From 68fe2e975f229cce08029b3a5afb06132f1cb31c Mon Sep 17 00:00:00 2001
2From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
3Date: Fri, 22 Jun 2012 01:20:20 +0200
4Subject: [PATCH 03/43] Disable the warning message for eh_frame_hdr
5
6Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
7---
8 bfd/elf-eh-frame.c | 3 +++
9 1 file changed, 3 insertions(+)
10
11diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
12index a13e81ebb8..1824ba6e5b 100644
13--- a/bfd/elf-eh-frame.c
14+++ b/bfd/elf-eh-frame.c
15@@ -1044,10 +1044,13 @@ _bfd_elf_parse_eh_frame (bfd *abfd, struct bfd_link_info *info,
16 goto success;
17
18 free_no_table:
19+/* FIXME: Remove the microblaze specifics when relaxing gets fixed. */
20+if (bfd_get_arch(abfd) != bfd_arch_microblaze) {
21 _bfd_error_handler
22 /* xgettext:c-format */
23 (_("error in %pB(%pA); no .eh_frame_hdr table will be created"),
24 abfd, sec);
25+}
26 hdr_info->u.dwarf.table = FALSE;
27 if (sec_info)
28 free (sec_info);
29--
302.17.1
31
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0004-Fix-relaxation-of-assembler-resolved-references.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0004-Fix-relaxation-of-assembler-resolved-references.patch
new file mode 100644
index 00000000..7ba07a0c
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0004-Fix-relaxation-of-assembler-resolved-references.patch
@@ -0,0 +1,61 @@
1From 1ea25f31c38e606603bf406efebfb6cfc26aec38 Mon Sep 17 00:00:00 2001
2From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
3Date: Tue, 14 Feb 2012 01:00:22 +0100
4Subject: [PATCH 04/43] Fix relaxation of assembler resolved references
5
6---
7 bfd/elf32-microblaze.c | 38 ++++++++++++++++++++++++++++++++++++++
8 2 files changed, 39 insertions(+)
9
10diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
11index e3c8027248..359484dd5e 100644
12--- a/bfd/elf32-microblaze.c
13+++ b/bfd/elf32-microblaze.c
14@@ -1973,6 +1973,44 @@ microblaze_elf_relax_section (bfd *abfd,
15 irelscanend = irelocs + o->reloc_count;
16 for (irelscan = irelocs; irelscan < irelscanend; irelscan++)
17 {
18+ if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_NONE)
19+ {
20+ unsigned int val;
21+
22+ isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
23+
24+ /* This was a PC-relative instruction that was completely resolved. */
25+ if (ocontents == NULL)
26+ {
27+ if (elf_section_data (o)->this_hdr.contents != NULL)
28+ ocontents = elf_section_data (o)->this_hdr.contents;
29+ else
30+ {
31+ /* We always cache the section contents.
32+ Perhaps, if info->keep_memory is FALSE, we
33+ should free them, if we are permitted to. */
34+
35+ if (o->rawsize == 0)
36+ o->rawsize = o->size;
37+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
38+ if (ocontents == NULL)
39+ goto error_return;
40+ if (!bfd_get_section_contents (abfd, o, ocontents,
41+ (file_ptr) 0,
42+ o->rawsize))
43+ goto error_return;
44+ elf_section_data (o)->this_hdr.contents = ocontents;
45+ }
46+ }
47+ irelscan->r_addend -= calc_fixup (irelscan->r_addend
48+ + isym->st_value, sec);
49+ val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
50+ microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
51+ irelscan->r_addend);
52+ }
53+ if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_NONE) {
54+ fprintf(stderr, "Unhandled NONE 64\n");
55+ }
56 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
57 {
58 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
59--
602.17.1
61
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0005-LOCAL-Fixup-debug_loc-sections-after-linker-relaxati.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0005-LOCAL-Fixup-debug_loc-sections-after-linker-relaxati.patch
new file mode 100644
index 00000000..18646195
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0005-LOCAL-Fixup-debug_loc-sections-after-linker-relaxati.patch
@@ -0,0 +1,207 @@
1From 62859c17077c559ad5e5db1cfbb496d5e8c3da68 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Mon, 6 Feb 2017 15:53:08 +0530
4Subject: [PATCH 05/43] [LOCAL]: Fixup debug_loc sections after linker
5 relaxation Adds a new reloctype R_MICROBLAZE_32_NONE, used for passing reloc
6 info from the assembler to the linker when the linker manages to fully
7 resolve a local symbol reference.
8
9This is a workaround for design flaws in the assembler to
10linker interface with regards to linker relaxation.
11
12Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
13Signed-off-by: Nagaraju Mekala <nmekala@xilinx.com>
14---
15 bfd/bfd-in2.h | 9 +++++--
16 bfd/elf32-microblaze.c | 53 ++++++++++++++++++++++++++++----------
17 bfd/libbfd.h | 1 +
18 bfd/reloc.c | 6 +++++
19 include/elf/microblaze.h | 2 ++
20 7 files changed, 64 insertions(+), 16 deletions(-)
21
22diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
23index e25da50aaf..721531886a 100644
24--- a/bfd/bfd-in2.h
25+++ b/bfd/bfd-in2.h
26@@ -5866,10 +5866,15 @@ value relative to the read-write small data area anchor */
27 expressions of the form "Symbol Op Symbol" */
28 BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM,
29
30-/* This is a 64 bit reloc that stores the 32 bit pc relative
31+/* This is a 32 bit reloc that stores the 32 bit pc relative
32 value in two words (with an imm instruction). No relocation is
33 done here - only used for relaxing */
34- BFD_RELOC_MICROBLAZE_64_NONE,
35+ BFD_RELOC_MICROBLAZE_32_NONE,
36+
37+/* This is a 64 bit reloc that stores the 32 bit pc relative
38+ * +value in two words (with an imm instruction). No relocation is
39+ * +done here - only used for relaxing */
40+ BFD_RELOC_MICROBLAZE_64_NONE,
41
42 /* This is a 64 bit reloc that stores the 32 bit pc relative
43 value in two words (with an imm instruction). The relocation is
44diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
45index 359484dd5e..1c69c269c7 100644
46--- a/bfd/elf32-microblaze.c
47+++ b/bfd/elf32-microblaze.c
48@@ -176,7 +176,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
49 0x0000ffff, /* Dest Mask. */
50 FALSE), /* PC relative offset? */
51
52- /* This reloc does nothing. Used for relaxation. */
53+ HOWTO (R_MICROBLAZE_32_NONE, /* Type. */
54+ 0, /* Rightshift. */
55+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
56+ 32, /* Bitsize. */
57+ TRUE, /* PC_relative. */
58+ 0, /* Bitpos. */
59+ complain_overflow_bitfield, /* Complain on overflow. */
60+ NULL, /* Special Function. */
61+ "R_MICROBLAZE_32_NONE",/* Name. */
62+ FALSE, /* Partial Inplace. */
63+ 0, /* Source Mask. */
64+ 0, /* Dest Mask. */
65+ FALSE), /* PC relative offset? */
66+
67+ /* This reloc does nothing. Used for relaxation. */
68 HOWTO (R_MICROBLAZE_64_NONE, /* Type. */
69 0, /* Rightshift. */
70 3, /* Size (0 = byte, 1 = short, 2 = long). */
71@@ -562,6 +576,9 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
72 case BFD_RELOC_NONE:
73 microblaze_reloc = R_MICROBLAZE_NONE;
74 break;
75+ case BFD_RELOC_MICROBLAZE_32_NONE:
76+ microblaze_reloc = R_MICROBLAZE_32_NONE;
77+ break;
78 case BFD_RELOC_MICROBLAZE_64_NONE:
79 microblaze_reloc = R_MICROBLAZE_64_NONE;
80 break;
81@@ -1918,6 +1935,7 @@ microblaze_elf_relax_section (bfd *abfd,
82 }
83 break;
84 case R_MICROBLAZE_NONE:
85+ case R_MICROBLAZE_32_NONE:
86 {
87 /* This was a PC-relative instruction that was
88 completely resolved. */
89@@ -1926,12 +1944,18 @@ microblaze_elf_relax_section (bfd *abfd,
90 target_address = irel->r_addend + irel->r_offset;
91 sfix = calc_fixup (irel->r_offset, 0, sec);
92 efix = calc_fixup (target_address, 0, sec);
93+
94+ /* Validate the in-band val. */
95+ val = bfd_get_32 (abfd, contents + irel->r_offset);
96+ if (val != irel->r_addend && ELF32_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
97+ fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
98+ }
99 irel->r_addend -= (efix - sfix);
100 /* Should use HOWTO. */
101 microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
102 irel->r_addend);
103- }
104- break;
105+ }
106+ break;
107 case R_MICROBLAZE_64_NONE:
108 {
109 /* This was a PC-relative 64-bit instruction that was
110@@ -1973,12 +1997,16 @@ microblaze_elf_relax_section (bfd *abfd,
111 irelscanend = irelocs + o->reloc_count;
112 for (irelscan = irelocs; irelscan < irelscanend; irelscan++)
113 {
114- if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_NONE)
115+ if (1 && ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_NONE)
116 {
117 unsigned int val;
118
119 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
120
121+ /* hax: We only do the following fixup for debug location lists. */
122+ if (strcmp(".debug_loc", o->name))
123+ continue;
124+
125 /* This was a PC-relative instruction that was completely resolved. */
126 if (ocontents == NULL)
127 {
128@@ -1999,18 +2027,17 @@ microblaze_elf_relax_section (bfd *abfd,
129 (file_ptr) 0,
130 o->rawsize))
131 goto error_return;
132- elf_section_data (o)->this_hdr.contents = ocontents;
133- }
134- }
135- irelscan->r_addend -= calc_fixup (irelscan->r_addend
136- + isym->st_value, sec);
137+ elf_section_data (o)->this_hdr.contents = ocontents;
138+ }
139+ }
140 val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
141+ if (val != irelscan->r_addend) {
142+ fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend);
143+ }
144+ irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
145 microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
146 irelscan->r_addend);
147 }
148- if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_NONE) {
149- fprintf(stderr, "Unhandled NONE 64\n");
150- }
151 if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
152 {
153 isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
154@@ -2070,7 +2097,7 @@ microblaze_elf_relax_section (bfd *abfd,
155 elf_section_data (o)->this_hdr.contents = ocontents;
156 }
157 }
158- irelscan->r_addend -= calc_fixup (irel->r_addend
159+ irelscan->r_addend -= calc_fixup (irelscan->r_addend
160 + isym->st_value,
161 0,
162 sec);
163diff --git a/bfd/libbfd.h b/bfd/libbfd.h
164index 36284d71a9..feb9fada1e 100644
165--- a/bfd/libbfd.h
166+++ b/bfd/libbfd.h
167@@ -2901,6 +2901,7 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
168 "BFD_RELOC_MICROBLAZE_32_ROSDA",
169 "BFD_RELOC_MICROBLAZE_32_RWSDA",
170 "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM",
171+ "BFD_RELOC_MICROBLAZE_32_NONE",
172 "BFD_RELOC_MICROBLAZE_64_NONE",
173 "BFD_RELOC_MICROBLAZE_64_GOTPC",
174 "BFD_RELOC_MICROBLAZE_64_GOT",
175diff --git a/bfd/reloc.c b/bfd/reloc.c
176index e6446a7809..87753ae4f0 100644
177--- a/bfd/reloc.c
178+++ b/bfd/reloc.c
179@@ -6795,6 +6795,12 @@ ENUM
180 ENUMDOC
181 This is a 32 bit reloc for the microblaze to handle
182 expressions of the form "Symbol Op Symbol"
183+ENUM
184+ BFD_RELOC_MICROBLAZE_32_NONE
185+ENUMDOC
186+ This is a 32 bit reloc that stores the 32 bit pc relative
187+ value in two words (with an imm instruction). No relocation is
188+ done here - only used for relaxing
189 ENUM
190 BFD_RELOC_MICROBLAZE_64_NONE
191 ENUMDOC
192diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h
193index 830b5ad446..6ee0966444 100644
194--- a/include/elf/microblaze.h
195+++ b/include/elf/microblaze.h
196@@ -61,6 +61,8 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type)
197 RELOC_NUMBER (R_MICROBLAZE_TEXTPCREL_64, 30) /* PC-relative TEXT offset. */
198 RELOC_NUMBER (R_MICROBLAZE_TEXTREL_64, 31) /* TEXT Entry offset 64-bit. */
199 RELOC_NUMBER (R_MICROBLAZE_TEXTREL_32_LO, 32) /* TEXT Entry offset 32-bit. */
200+ RELOC_NUMBER (R_MICROBLAZE_32_NONE, 33)
201+
202 END_RELOC_NUMBERS (R_MICROBLAZE_max)
203
204 /* Global base address names. */
205--
2062.17.1
207
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0006-upstream-change-to-garbage-collection-sweep-causes-m.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0006-upstream-change-to-garbage-collection-sweep-causes-m.patch
new file mode 100644
index 00000000..35d44be4
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0006-upstream-change-to-garbage-collection-sweep-causes-m.patch
@@ -0,0 +1,39 @@
1From 72fe91edf03a0270ecd9df795f1a1eaded3b7d15 Mon Sep 17 00:00:00 2001
2From: David Holsgrove <david.holsgrove@xilinx.com>
3Date: Wed, 27 Feb 2013 13:56:11 +1000
4Subject: [PATCH 06/43] upstream change to garbage collection sweep causes mb
5 regression
6
7Upstream change for PR13177 now clears the def_regular during gc_sweep of a
8section. (All other archs in binutils/bfd/elf32-*.c received an update
9to a warning about unresolvable relocations - this warning is not present
10in binutils/bfd/elf32-microblaze.c, but this warning check would not
11prevent the error being seen)
12
13The visible issue with this change is when running a c++ application
14in Petalinux which links libstdc++.so for exception handling it segfaults
15on execution.
16
17This does not occur if static linking libstdc++.a, so its during the
18relocations for a shared lib with garbage collection this occurs
19
20Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
21---
22 bfd/elflink.c | 1 -
23 1 file changed, 1 deletion(-)
24
25diff --git a/bfd/elflink.c b/bfd/elflink.c
26index e50c0e4b38..09d43e3ca5 100644
27--- a/bfd/elflink.c
28+++ b/bfd/elflink.c
29@@ -6187,7 +6187,6 @@ elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *data)
30
31 inf = (struct elf_gc_sweep_symbol_info *) data;
32 (*inf->hide_symbol) (inf->info, h, TRUE);
33- h->def_regular = 0;
34 h->ref_regular = 0;
35 h->ref_regular_nonweak = 0;
36 }
37--
382.17.1
39
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0007-Fix-bug-in-TLSTPREL-Relocation.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0007-Fix-bug-in-TLSTPREL-Relocation.patch
new file mode 100644
index 00000000..a5cc8114
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0007-Fix-bug-in-TLSTPREL-Relocation.patch
@@ -0,0 +1,33 @@
1From 2ea146401a9aed9e3b6cc07e1b6c0f81e5a0527c Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Mon, 15 Jun 2015 16:50:30 +0530
4Subject: [PATCH 07/43] Fix bug in TLSTPREL Relocation
5
6Fixed the problem related to the fixup/relocations TLSTPREL.
7When the fixup is applied the addend is not added at the correct offset
8of the instruction. The offset is hard coded considering its big endian
9and it fails for Little endian. This patch allows support for both
10big & little-endian compilers
11---
12 bfd/elf32-microblaze.c | 4 ++--
13 1 file changed, 2 insertions(+), 2 deletions(-)
14
15diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
16index 1c69c269c7..d19a6dca84 100644
17--- a/bfd/elf32-microblaze.c
18+++ b/bfd/elf32-microblaze.c
19@@ -1451,9 +1451,9 @@ microblaze_elf_relocate_section (bfd *output_bfd,
20 relocation += addend;
21 relocation -= dtprel_base(info);
22 bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
23- contents + offset + 2);
24+ contents + offset + endian);
25 bfd_put_16 (input_bfd, relocation & 0xffff,
26- contents + offset + 2 + INST_WORD_SIZE);
27+ contents + offset + endian + INST_WORD_SIZE);
28 break;
29 case (int) R_MICROBLAZE_TEXTREL_64:
30 case (int) R_MICROBLAZE_TEXTREL_32_LO:
31--
322.17.1
33
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0008-Added-Address-extension-instructions.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0008-Added-Address-extension-instructions.patch
new file mode 100644
index 00000000..933e51e1
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0008-Added-Address-extension-instructions.patch
@@ -0,0 +1,98 @@
1From a4b50cb6f4b8d2f4e7d3b28bbc2f8110277e441d Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Mon, 18 Jan 2016 12:28:21 +0530
4Subject: [PATCH 08/43] Added Address extension instructions
5
6This patch adds the support of new instructions which are required
7for supporting Address extension feature.
8
9Signed-off-by :Nagaraju Mekala <nmekala@xilix.com>
10
11ChangeLog:
12 2016-01-18 Nagaraju Mekala <nmekala@xilix.com>
13
14 *microblaze-opc.h (op_code_struct): Update
15 Added new instructions
16 *microblaze-opcm.h (microblaze_instr): Update
17 Added new instructions
18---
19 opcodes/microblaze-opc.h | 11 +++++++++++
20 opcodes/microblaze-opcm.h | 10 +++++-----
21 2 files changed, 16 insertions(+), 5 deletions(-)
22
23diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
24index 865151f95b..330f1040e7 100644
25--- a/opcodes/microblaze-opc.h
26+++ b/opcodes/microblaze-opc.h
27@@ -178,8 +178,11 @@ struct op_code_struct
28 {"wdc.ext.clear", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000466, OPCODE_MASK_H35B, wdcextclear, special_inst },
29 {"wdc.flush", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000074, OPCODE_MASK_H34B, wdcflush, special_inst },
30 {"wdc.ext.flush", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000476, OPCODE_MASK_H35B, wdcextflush, special_inst },
31+ {"wdc.clear.ea", INST_TYPE_R1_R2_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900000E6, OPCODE_MASK_H34B, wdcclearea, special_inst },
32 {"mts", INST_TYPE_SPECIAL_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_MTS, 0x9400C000, OPCODE_MASK_H13S, mts, special_inst },
33+ {"mtse", INST_TYPE_SPECIAL_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_MTS, 0x9500C000, OPCODE_MASK_H13S, mtse,special_inst },
34 {"mfs", INST_TYPE_RD_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_MFS, 0x94008000, OPCODE_MASK_H23S, mfs, special_inst },
35+ {"mfse", INST_TYPE_RD_SPECIAL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_MFS, 0x94088000, OPCODE_MASK_H23S, mfse, special_inst },
36 {"br", INST_TYPE_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98000000, OPCODE_MASK_H124, br, branch_inst },
37 {"brd", INST_TYPE_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98100000, OPCODE_MASK_H124, brd, branch_inst },
38 {"brld", INST_TYPE_RD_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98140000, OPCODE_MASK_H24, brld, branch_inst },
39@@ -229,18 +232,24 @@ struct op_code_struct
40 {"bgeid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBEA00000, OPCODE_MASK_H1, bgeid, branch_inst },
41 {"lbu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC0000000, OPCODE_MASK_H4, lbu, memory_load_inst },
42 {"lbur", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC0000200, OPCODE_MASK_H4, lbur, memory_load_inst },
43+ {"lbuea", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC0000080, OPCODE_MASK_H4, lbuea, memory_load_inst },
44 {"lhu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC4000000, OPCODE_MASK_H4, lhu, memory_load_inst },
45 {"lhur", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC4000200, OPCODE_MASK_H4, lhur, memory_load_inst },
46+ {"lhuea", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC4000080, OPCODE_MASK_H4, lhuea, memory_load_inst },
47 {"lw", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000000, OPCODE_MASK_H4, lw, memory_load_inst },
48 {"lwr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000200, OPCODE_MASK_H4, lwr, memory_load_inst },
49 {"lwx", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000400, OPCODE_MASK_H4, lwx, memory_load_inst },
50+ {"lwea", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000080, OPCODE_MASK_H4, lwea, memory_load_inst },
51 {"sb", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD0000000, OPCODE_MASK_H4, sb, memory_store_inst },
52 {"sbr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD0000200, OPCODE_MASK_H4, sbr, memory_store_inst },
53+ {"sbea", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD0000080, OPCODE_MASK_H4, sbea, memory_store_inst },
54 {"sh", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD4000000, OPCODE_MASK_H4, sh, memory_store_inst },
55 {"shr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD4000200, OPCODE_MASK_H4, shr, memory_store_inst },
56+ {"shea", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD4000080, OPCODE_MASK_H4, shea, memory_store_inst },
57 {"sw", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000000, OPCODE_MASK_H4, sw, memory_store_inst },
58 {"swr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000200, OPCODE_MASK_H4, swr, memory_store_inst },
59 {"swx", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000400, OPCODE_MASK_H4, swx, memory_store_inst },
60+ {"swea", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000080, OPCODE_MASK_H4, swea, memory_store_inst },
61 {"lbui", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE0000000, OPCODE_MASK_H, lbui, memory_load_inst },
62 {"lhui", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE4000000, OPCODE_MASK_H, lhui, memory_load_inst },
63 {"lwi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, lwi, memory_load_inst },
64@@ -405,6 +414,8 @@ struct op_code_struct
65 {"clz", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900000E0, OPCODE_MASK_H34, clz, special_inst },
66 {"mbar", INST_TYPE_IMM5, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8020004, OPCODE_MASK_HN, mbar, special_inst },
67 {"sleep", INST_TYPE_NONE, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBA020004, OPCODE_MASK_HN, invalid_inst, special_inst }, /* translates to mbar 16. */
68+ {"hibernate", INST_TYPE_NONE, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB9020004, OPCODE_MASK_HN, invalid_inst, special_inst }, /* translates to mbar 8. */
69+ {"suspend", INST_TYPE_NONE, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBB020004, OPCODE_MASK_HN, invalid_inst, special_inst }, /* translates to mbar 24. */
70 {"swapb", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E0, OPCODE_MASK_H4, swapb, arithmetic_inst },
71 {"swaph", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E2, OPCODE_MASK_H4, swaph, arithmetic_inst },
72 {"", 0, 0, 0, 0, 0, 0, 0, 0},
73diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
74index 42f3dd3be5..1c39dbf50b 100644
75--- a/opcodes/microblaze-opcm.h
76+++ b/opcodes/microblaze-opcm.h
77@@ -33,13 +33,13 @@ enum microblaze_instr
78 /* 'or/and/xor' are C++ keywords. */
79 microblaze_or, microblaze_and, microblaze_xor,
80 andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
81- wic, wdc, wdcclear, wdcextclear, wdcflush, wdcextflush, mts, mfs, mbar, br,
82- brd, brld, bra, brad, brald, microblaze_brk, beq, beqd, bne, bned, blt,
83- bltd, ble, bled, bgt, bgtd, bge, bged, ori, andi, xori, andni,
84+ wic, wdc, wdcclear, wdcextclear, wdcflush, wdcextflush, wdcclearea, mts, mtse,
85+ mfs, mfse, mbar, br, brd, brld, bra, brad, brald, microblaze_brk, beq, beqd,
86+ bne, bned, blt, bltd, ble, bled, bgt, bgtd, bge, bged, ori, andi, xori, andni,
87 imm, rtsd, rtid, rtbd, rted, bri, brid, brlid, brai, braid, bralid,
88 brki, beqi, beqid, bnei, bneid, blti, bltid, blei, bleid, bgti,
89- bgtid, bgei, bgeid, lbu, lbur, lhu, lhur, lw, lwr, lwx, sb, sbr, sh,
90- shr, sw, swr, swx, lbui, lhui, lwi,
91+ bgtid, bgei, bgeid, lbu, lbuea, lbur, lhu, lhuea, lhur, lw, lwea, lwr, lwx,
92+ sb, sbea, sbr, sh, shea, shr, sw, swea, swr, swx, lbui, lhui, lwi,
93 sbi, shi, swi, msrset, msrclr, tuqula, fadd, frsub, fmul, fdiv,
94 fcmp_lt, fcmp_eq, fcmp_le, fcmp_gt, fcmp_ne, fcmp_ge, fcmp_un, flt,
95 fint, fsqrt,
96--
972.17.1
98
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0009-fixing-the-MAX_OPCODES-to-correct-value.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0009-fixing-the-MAX_OPCODES-to-correct-value.patch
new file mode 100644
index 00000000..8b51a7a7
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0009-fixing-the-MAX_OPCODES-to-correct-value.patch
@@ -0,0 +1,25 @@
1From 9c7c893866ab6b63942b86be6134c34b96272306 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Thu, 28 Jan 2016 14:07:34 +0530
4Subject: [PATCH 09/43] fixing the MAX_OPCODES to correct value
5
6---
7 opcodes/microblaze-opc.h | 2 +-
8 1 file changed, 1 insertion(+), 1 deletion(-)
9
10diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
11index 330f1040e7..2a6b841232 100644
12--- a/opcodes/microblaze-opc.h
13+++ b/opcodes/microblaze-opc.h
14@@ -102,7 +102,7 @@
15 #define DELAY_SLOT 1
16 #define NO_DELAY_SLOT 0
17
18-#define MAX_OPCODES 291
19+#define MAX_OPCODES 299
20
21 struct op_code_struct
22 {
23--
242.17.1
25
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0010-Add-new-bit-field-instructions.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0010-Add-new-bit-field-instructions.patch
new file mode 100644
index 00000000..11d45a23
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0010-Add-new-bit-field-instructions.patch
@@ -0,0 +1,139 @@
1From 55acba095458b872b500e978af946733a9f33021 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Mon, 18 Jul 2016 12:24:28 +0530
4Subject: [PATCH 10/43] Add new bit-field instructions
5
6This patches adds new bsefi and bsifi instructions.
7BSEFI- The instruction shall extract a bit field from a
8register and place it right-adjusted in the destination register.
9The other bits in the destination register shall be set to zero
10BSIFI- The instruction shall insert a right-adjusted bit field
11from a register at another position in the destination register.
12The rest of the bits in the destination register shall be unchanged
13
14Signed-off-by :Nagaraju Mekala <nmekala@xilix.com>
15---
16 opcodes/microblaze-dis.c | 16 +++++++++
17 opcodes/microblaze-opc.h | 12 ++++++-
18 opcodes/microblaze-opcm.h | 6 +++-
19 4 files changed, 102 insertions(+), 3 deletions(-)
20
21diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
22index f691740dfd..f8aaf27873 100644
23--- a/opcodes/microblaze-dis.c
24+++ b/opcodes/microblaze-dis.c
25@@ -73,6 +73,18 @@ get_field_imm5_mbar (long instr)
26 return(strdup(tmpstr));
27 }
28
29+static char *
30+get_field_imm5width (long instr)
31+{
32+ char tmpstr[25];
33+
34+ if (instr & 0x00004000)
35+ sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
36+ else
37+ sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >> IMM_LOW) + 1)); /* bsifi */
38+ return (strdup (tmpstr));
39+}
40+
41 static char *
42 get_field_rfsl (long instr)
43 {
44@@ -396,6 +408,10 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
45 /* For mbar 16 or sleep insn. */
46 case INST_TYPE_NONE:
47 break;
48+ /* For bit field insns. */
49+ case INST_TYPE_RD_R1_IMM5_IMM5:
50+ print_func (stream, "\t%s, %s, %s, %s", get_field_rd (inst),get_field_r1(inst),get_field_imm5width (inst), get_field_imm5 (inst));
51+ break;
52 /* For tuqula instruction */
53 case INST_TYPE_RD:
54 print_func (stream, "\t%s", get_field_rd (inst));
55diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
56index 2a6b841232..ce8ac351b5 100644
57--- a/opcodes/microblaze-opc.h
58+++ b/opcodes/microblaze-opc.h
59@@ -59,6 +59,9 @@
60 /* For mbar. */
61 #define INST_TYPE_IMM5 20
62
63+/* For bsefi and bsifi */
64+#define INST_TYPE_RD_R1_IMM5_IMM5 21
65+
66 #define INST_TYPE_NONE 25
67
68
69@@ -89,7 +92,9 @@
70 #define OPCODE_MASK_H124 0xFFFF07FF /* High 16, and low 11 bits. */
71 #define OPCODE_MASK_H1234 0xFFFFFFFF /* All 32 bits. */
72 #define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
73+#define OPCODE_MASK_H3B 0xFC00C600 /* High 6 bits and bits 16, 17, 21, 22. */
74 #define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
75+#define OPCODE_MASK_H32B 0xFC00C000 /* High 6 bits and bit 16, 17. */
76 #define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
77 #define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
78 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
79@@ -102,7 +107,7 @@
80 #define DELAY_SLOT 1
81 #define NO_DELAY_SLOT 0
82
83-#define MAX_OPCODES 299
84+#define MAX_OPCODES 301
85
86 struct op_code_struct
87 {
88@@ -159,6 +164,8 @@ struct op_code_struct
89 {"bslli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3, bslli, barrel_shift_inst },
90 {"bsrai", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3, bsrai, barrel_shift_inst },
91 {"bsrli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3, bsrli, barrel_shift_inst },
92+ {"bsefi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64004000, OPCODE_MASK_H32B, bsefi, barrel_shift_inst },
93+ {"bsifi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64008000, OPCODE_MASK_H32B, bsifi, barrel_shift_inst },
94 {"or", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H4, microblaze_or, logical_inst },
95 {"and", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000000, OPCODE_MASK_H4, microblaze_and, logical_inst },
96 {"xor", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000000, OPCODE_MASK_H4, microblaze_xor, logical_inst },
97@@ -438,5 +445,8 @@ char pvr_register_prefix[] = "rpvr";
98 #define MIN_IMM5 ((int) 0x00000000)
99 #define MAX_IMM5 ((int) 0x0000001f)
100
101+#define MIN_IMM_WIDTH ((int) 0x00000001)
102+#define MAX_IMM_WIDTH ((int) 0x00000020)
103+
104 #endif /* MICROBLAZE_OPC */
105
106diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
107index 1c39dbf50b..28662694cd 100644
108--- a/opcodes/microblaze-opcm.h
109+++ b/opcodes/microblaze-opcm.h
110@@ -29,7 +29,7 @@ enum microblaze_instr
111 addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
112 mulh, mulhu, mulhsu,swapb,swaph,
113 idiv, idivu, bsll, bsra, bsrl, get, put, nget, nput, cget, cput,
114- ncget, ncput, muli, bslli, bsrai, bsrli, mului,
115+ ncget, ncput, muli, bslli, bsrai, bsrli, bsefi, bsifi, mului,
116 /* 'or/and/xor' are C++ keywords. */
117 microblaze_or, microblaze_and, microblaze_xor,
118 andn, pcmpbf, pcmpbc, pcmpeq, pcmpne, sra, src, srl, sext8, sext16,
119@@ -129,6 +129,7 @@ enum microblaze_instr_type
120 #define RB_LOW 11 /* Low bit for RB. */
121 #define IMM_LOW 0 /* Low bit for immediate. */
122 #define IMM_MBAR 21 /* low bit for mbar instruction. */
123+#define IMM_WIDTH_LOW 6 /* Low bit for immediate width */
124
125 #define RD_MASK 0x03E00000
126 #define RA_MASK 0x001F0000
127@@ -141,6 +142,9 @@ enum microblaze_instr_type
128 /* Imm mask for mbar. */
129 #define IMM5_MBAR_MASK 0x03E00000
130
131+/* Imm mask for extract/insert width. */
132+#define IMM5_WIDTH_MASK 0x000007C0
133+
134 /* FSL imm mask for get, put instructions. */
135 #define RFSL_MASK 0x000000F
136
137--
1382.17.1
139
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0011-fixing-the-imm-bug.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0011-fixing-the-imm-bug.patch
new file mode 100644
index 00000000..b6f2920a
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0011-fixing-the-imm-bug.patch
@@ -0,0 +1,27 @@
1From f42a99be023e3f933c0a228ac8e08d59c59ec8d7 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Mon, 10 Jul 2017 16:07:28 +0530
4Subject: [PATCH 11/43] fixing the imm bug. with relax option imm -1 is also
5 getting removed this is corrected now.
6
7---
8 bfd/elf32-microblaze.c | 3 +--
9 1 file changed, 1 insertion(+), 2 deletions(-)
10
11diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
12index d19a6dca84..d001437b3f 100644
13--- a/bfd/elf32-microblaze.c
14+++ b/bfd/elf32-microblaze.c
15@@ -1869,8 +1869,7 @@ microblaze_elf_relax_section (bfd *abfd,
16 else
17 symval += irel->r_addend;
18
19- if ((symval & 0xffff8000) == 0
20- || (symval & 0xffff8000) == 0xffff8000)
21+ if ((symval & 0xffff8000) == 0)
22 {
23 /* We can delete this instruction. */
24 sec->relax[sec->relax_count].addr = irel->r_offset;
25--
262.17.1
27
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch
new file mode 100644
index 00000000..96cab28a
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0015-intial-commit-of-MB-64-bit.patch
@@ -0,0 +1,4186 @@
1From b42fae987795bb210476dcaa5e086f42602208f8 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Sun, 30 Sep 2018 16:28:28 +0530
4Subject: [PATCH 15/43] intial commit of MB 64-bit
5
6---
7 bfd/Makefile.am | 2 +
8 bfd/Makefile.in | 3 +
9 bfd/config.bfd | 4 +
10 bfd/configure | 2 +
11 bfd/configure.ac | 2 +
12 bfd/cpu-microblaze.c | 52 +-
13 bfd/elf64-microblaze.c | 3584 ++++++++++++++++++++++++++++
14 bfd/targets.c | 6 +
15 include/elf/common.h | 1 +
16 opcodes/microblaze-dis.c | 39 +-
17 opcodes/microblaze-opc.h | 162 +-
18 opcodes/microblaze-opcm.h | 20 +-
19 19 files changed, 4181 insertions(+), 41 deletions(-)
20 create mode 100644 bfd/elf64-microblaze.c
21
22diff --git a/bfd/Makefile.am b/bfd/Makefile.am
23index a9191555ad..c5fd250812 100644
24--- a/bfd/Makefile.am
25+++ b/bfd/Makefile.am
26@@ -570,6 +570,7 @@ BFD64_BACKENDS = \
27 elf64-riscv.lo \
28 elfxx-riscv.lo \
29 elf64-s390.lo \
30+ elf64-microblaze.lo \
31 elf64-sparc.lo \
32 elf64-tilegx.lo \
33 elf64-x86-64.lo \
34@@ -603,6 +604,7 @@ BFD64_BACKENDS_CFILES = \
35 elf64-nfp.c \
36 elf64-ppc.c \
37 elf64-s390.c \
38+ elf64-microblaze.c \
39 elf64-sparc.c \
40 elf64-tilegx.c \
41 elf64-x86-64.c \
42diff --git a/bfd/Makefile.in b/bfd/Makefile.in
43index 896df52042..fd457cba1e 100644
44--- a/bfd/Makefile.in
45+++ b/bfd/Makefile.in
46@@ -995,6 +995,7 @@ BFD64_BACKENDS = \
47 elf64-riscv.lo \
48 elfxx-riscv.lo \
49 elf64-s390.lo \
50+ elf64-microblaze.lo \
51 elf64-sparc.lo \
52 elf64-tilegx.lo \
53 elf64-x86-64.lo \
54@@ -1028,6 +1029,7 @@ BFD64_BACKENDS_CFILES = \
55 elf64-nfp.c \
56 elf64-ppc.c \
57 elf64-s390.c \
58+ elf64-microblaze.c \
59 elf64-sparc.c \
60 elf64-tilegx.c \
61 elf64-x86-64.c \
62@@ -1494,6 +1496,7 @@ distclean-compile:
63 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-ppc.Plo@am__quote@
64 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-riscv.Plo@am__quote@
65 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-s390.Plo@am__quote@
66+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-microblaze.Plo@am__quote@
67 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-sparc.Plo@am__quote@
68 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-tilegx.Plo@am__quote@
69 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/elf64-x86-64.Plo@am__quote@
70diff --git a/bfd/config.bfd b/bfd/config.bfd
71index f13812b7c7..a98c220db5 100644
72--- a/bfd/config.bfd
73+++ b/bfd/config.bfd
74@@ -850,11 +850,15 @@ case "${targ}" in
75 microblazeel*-*)
76 targ_defvec=microblaze_elf32_le_vec
77 targ_selvecs=microblaze_elf32_vec
78+ targ64_selvecs=microblaze_elf64_vec
79+ targ64_selvecs=microblaze_elf64_le_vec
80 ;;
81
82 microblaze*-*)
83 targ_defvec=microblaze_elf32_vec
84 targ_selvecs=microblaze_elf32_le_vec
85+ targ64_selvecs=microblaze_elf64_vec
86+ targ64_selvecs=microblaze_elf64_le_vec
87 ;;
88
89 #ifdef BFD64
90diff --git a/bfd/configure b/bfd/configure
91index 8d6c94aef2..3defb1f784 100755
92--- a/bfd/configure
93+++ b/bfd/configure
94@@ -14847,6 +14847,8 @@ do
95 rx_elf32_linux_le_vec) tb="$tb elf32-rx.lo elf32.lo $elf" ;;
96 s390_elf32_vec) tb="$tb elf32-s390.lo elf32.lo $elf" ;;
97 s390_elf64_vec) tb="$tb elf64-s390.lo elf64.lo $elf"; target_size=64 ;;
98+ microblaze_elf64_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
99+ microblaze_elf64_le_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
100 score_elf32_be_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
101 score_elf32_le_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
102 sh_coff_vec) tb="$tb coff-sh.lo $coff" ;;
103diff --git a/bfd/configure.ac b/bfd/configure.ac
104index 5f02c41520..d3010b47dc 100644
105--- a/bfd/configure.ac
106+++ b/bfd/configure.ac
107@@ -615,6 +615,8 @@ do
108 rx_elf32_linux_le_vec) tb="$tb elf32-rx.lo elf32.lo $elf" ;;
109 s390_elf32_vec) tb="$tb elf32-s390.lo elf32.lo $elf" ;;
110 s390_elf64_vec) tb="$tb elf64-s390.lo elf64.lo $elf"; target_size=64 ;;
111+ microblaze_elf64_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
112+ microblaze_elf64_le_vec) tb="$tb elf64-microblaze.lo elf64.lo $elf"; target_size=64 ;;
113 score_elf32_be_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
114 score_elf32_le_vec) tb="$tb elf32-score.lo elf32-score7.lo elf32.lo $elf"; want64=true; target_size=64 ;;
115 sh_coff_vec) tb="$tb coff-sh.lo $coff" ;;
116diff --git a/bfd/cpu-microblaze.c b/bfd/cpu-microblaze.c
117index 9bc2eb3de9..c91ba46f75 100644
118--- a/bfd/cpu-microblaze.c
119+++ b/bfd/cpu-microblaze.c
120@@ -23,7 +23,24 @@
121 #include "bfd.h"
122 #include "libbfd.h"
123
124-const bfd_arch_info_type bfd_microblaze_arch =
125+const bfd_arch_info_type bfd_microblaze_arch[] =
126+{
127+#if BFD_DEFAULT_TARGET_SIZE == 64
128+{
129+ 64, /* 32 bits in a word. */
130+ 64, /* 32 bits in an address. */
131+ 8, /* 8 bits in a byte. */
132+ bfd_arch_microblaze, /* Architecture. */
133+ 0, /* Machine number - 0 for now. */
134+ "microblaze", /* Architecture name. */
135+ "MicroBlaze", /* Printable name. */
136+ 3, /* Section align power. */
137+ FALSE, /* Is this the default architecture ? */
138+ bfd_default_compatible, /* Architecture comparison function. */
139+ bfd_default_scan, /* String to architecture conversion. */
140+ bfd_arch_default_fill, /* Default fill. */
141+ &bfd_microblaze_arch[1] /* Next in list. */
142+},
143 {
144 32, /* 32 bits in a word. */
145 32, /* 32 bits in an address. */
146@@ -38,4 +55,37 @@ const bfd_arch_info_type bfd_microblaze_arch =
147 bfd_default_scan, /* String to architecture conversion. */
148 bfd_arch_default_fill, /* Default fill. */
149 NULL /* Next in list. */
150+}
151+#else
152+{
153+ 32, /* 32 bits in a word. */
154+ 32, /* 32 bits in an address. */
155+ 8, /* 8 bits in a byte. */
156+ bfd_arch_microblaze, /* Architecture. */
157+ 0, /* Machine number - 0 for now. */
158+ "microblaze", /* Architecture name. */
159+ "MicroBlaze", /* Printable name. */
160+ 3, /* Section align power. */
161+ TRUE, /* Is this the default architecture ? */
162+ bfd_default_compatible, /* Architecture comparison function. */
163+ bfd_default_scan, /* String to architecture conversion. */
164+ bfd_arch_default_fill, /* Default fill. */
165+ &bfd_microblaze_arch[1] /* Next in list. */
166+},
167+{
168+ 64, /* 32 bits in a word. */
169+ 64, /* 32 bits in an address. */
170+ 8, /* 8 bits in a byte. */
171+ bfd_arch_microblaze, /* Architecture. */
172+ 0, /* Machine number - 0 for now. */
173+ "microblaze", /* Architecture name. */
174+ "MicroBlaze", /* Printable name. */
175+ 3, /* Section align power. */
176+ FALSE, /* Is this the default architecture ? */
177+ bfd_default_compatible, /* Architecture comparison function. */
178+ bfd_default_scan, /* String to architecture conversion. */
179+ bfd_arch_default_fill, /* Default fill. */
180+ NULL /* Next in list. */
181+}
182+#endif
183 };
184diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
185new file mode 100644
186index 0000000000..0f43ae6ea8
187--- /dev/null
188+++ b/bfd/elf64-microblaze.c
189@@ -0,0 +1,3584 @@
190+/* Xilinx MicroBlaze-specific support for 32-bit ELF
191+
192+ Copyright (C) 2009-2016 Free Software Foundation, Inc.
193+
194+ This file is part of BFD, the Binary File Descriptor library.
195+
196+ This program is free software; you can redistribute it and/or modify
197+ it under the terms of the GNU General Public License as published by
198+ the Free Software Foundation; either version 3 of the License, or
199+ (at your option) any later version.
200+
201+ This program is distributed in the hope that it will be useful,
202+ but WITHOUT ANY WARRANTY; without even the implied warranty of
203+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204+ GNU General Public License for more details.
205+
206+ You should have received a copy of the GNU General Public License
207+ along with this program; if not, write to the
208+ Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
209+ Boston, MA 02110-1301, USA. */
210+
211+
212+int dbg1 = 0;
213+
214+#include "sysdep.h"
215+#include "bfd.h"
216+#include "bfdlink.h"
217+#include "libbfd.h"
218+#include "elf-bfd.h"
219+#include "elf/microblaze.h"
220+#include <assert.h>
221+
222+#define USE_RELA /* Only USE_REL is actually significant, but this is
223+ here are a reminder... */
224+#define INST_WORD_SIZE 4
225+
226+static int ro_small_data_pointer = 0;
227+static int rw_small_data_pointer = 0;
228+
229+static reloc_howto_type * microblaze_elf_howto_table [(int) R_MICROBLAZE_max];
230+
231+static reloc_howto_type microblaze_elf_howto_raw[] =
232+{
233+ /* This reloc does nothing. */
234+ HOWTO (R_MICROBLAZE_NONE, /* Type. */
235+ 0, /* Rightshift. */
236+ 3, /* Size (0 = byte, 1 = short, 2 = long). */
237+ 0, /* Bitsize. */
238+ FALSE, /* PC_relative. */
239+ 0, /* Bitpos. */
240+ complain_overflow_dont, /* Complain on overflow. */
241+ NULL, /* Special Function. */
242+ "R_MICROBLAZE_NONE", /* Name. */
243+ FALSE, /* Partial Inplace. */
244+ 0, /* Source Mask. */
245+ 0, /* Dest Mask. */
246+ FALSE), /* PC relative offset? */
247+
248+ /* A standard 32 bit relocation. */
249+ HOWTO (R_MICROBLAZE_32, /* Type. */
250+ 0, /* Rightshift. */
251+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
252+ 32, /* Bitsize. */
253+ FALSE, /* PC_relative. */
254+ 0, /* Bitpos. */
255+ complain_overflow_bitfield, /* Complain on overflow. */
256+ bfd_elf_generic_reloc,/* Special Function. */
257+ "R_MICROBLAZE_32", /* Name. */
258+ FALSE, /* Partial Inplace. */
259+ 0, /* Source Mask. */
260+ 0xffffffff, /* Dest Mask. */
261+ FALSE), /* PC relative offset? */
262+
263+ /* A standard PCREL 32 bit relocation. */
264+ HOWTO (R_MICROBLAZE_32_PCREL,/* Type. */
265+ 0, /* Rightshift. */
266+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
267+ 32, /* Bitsize. */
268+ TRUE, /* PC_relative. */
269+ 0, /* Bitpos. */
270+ complain_overflow_bitfield, /* Complain on overflow. */
271+ bfd_elf_generic_reloc,/* Special Function. */
272+ "R_MICROBLAZE_32_PCREL", /* Name. */
273+ TRUE, /* Partial Inplace. */
274+ 0, /* Source Mask. */
275+ 0xffffffff, /* Dest Mask. */
276+ TRUE), /* PC relative offset? */
277+
278+ /* A 64 bit PCREL relocation. Table-entry not really used. */
279+ HOWTO (R_MICROBLAZE_64_PCREL,/* Type. */
280+ 0, /* Rightshift. */
281+ 4, /* Size (0 = byte, 1 = short, 2 = long). */
282+ 64, /* Bitsize. */
283+ TRUE, /* PC_relative. */
284+ 0, /* Bitpos. */
285+ complain_overflow_dont, /* Complain on overflow. */
286+ bfd_elf_generic_reloc,/* Special Function. */
287+ "R_MICROBLAZE_64_PCREL", /* Name. */
288+ FALSE, /* Partial Inplace. */
289+ 0, /* Source Mask. */
290+ 0x0000ffff, /* Dest Mask. */
291+ TRUE), /* PC relative offset? */
292+
293+ /* The low half of a PCREL 32 bit relocation. */
294+ HOWTO (R_MICROBLAZE_32_PCREL_LO, /* Type. */
295+ 0, /* Rightshift. */
296+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
297+ 16, /* Bitsize. */
298+ TRUE, /* PC_relative. */
299+ 0, /* Bitpos. */
300+ complain_overflow_signed, /* Complain on overflow. */
301+ bfd_elf_generic_reloc, /* Special Function. */
302+ "R_MICROBLAZE_32_PCREL_LO", /* Name. */
303+ FALSE, /* Partial Inplace. */
304+ 0, /* Source Mask. */
305+ 0x0000ffff, /* Dest Mask. */
306+ TRUE), /* PC relative offset? */
307+
308+ /* A 64 bit relocation. Table entry not really used. */
309+ HOWTO (R_MICROBLAZE_64, /* Type. */
310+ 0, /* Rightshift. */
311+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
312+ 16, /* Bitsize. */
313+ FALSE, /* PC_relative. */
314+ 0, /* Bitpos. */
315+ complain_overflow_dont, /* Complain on overflow. */
316+ bfd_elf_generic_reloc,/* Special Function. */
317+ "R_MICROBLAZE_64", /* Name. */
318+ FALSE, /* Partial Inplace. */
319+ 0, /* Source Mask. */
320+ 0x0000ffff, /* Dest Mask. */
321+ FALSE), /* PC relative offset? */
322+
323+ /* The low half of a 32 bit relocation. */
324+ HOWTO (R_MICROBLAZE_32_LO, /* Type. */
325+ 0, /* Rightshift. */
326+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
327+ 16, /* Bitsize. */
328+ FALSE, /* PC_relative. */
329+ 0, /* Bitpos. */
330+ complain_overflow_signed, /* Complain on overflow. */
331+ bfd_elf_generic_reloc,/* Special Function. */
332+ "R_MICROBLAZE_32_LO", /* Name. */
333+ FALSE, /* Partial Inplace. */
334+ 0, /* Source Mask. */
335+ 0x0000ffff, /* Dest Mask. */
336+ FALSE), /* PC relative offset? */
337+
338+ /* Read-only small data section relocation. */
339+ HOWTO (R_MICROBLAZE_SRO32, /* Type. */
340+ 0, /* Rightshift. */
341+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
342+ 16, /* Bitsize. */
343+ FALSE, /* PC_relative. */
344+ 0, /* Bitpos. */
345+ complain_overflow_bitfield, /* Complain on overflow. */
346+ bfd_elf_generic_reloc,/* Special Function. */
347+ "R_MICROBLAZE_SRO32", /* Name. */
348+ FALSE, /* Partial Inplace. */
349+ 0, /* Source Mask. */
350+ 0x0000ffff, /* Dest Mask. */
351+ FALSE), /* PC relative offset? */
352+
353+ /* Read-write small data area relocation. */
354+ HOWTO (R_MICROBLAZE_SRW32, /* Type. */
355+ 0, /* Rightshift. */
356+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
357+ 16, /* Bitsize. */
358+ FALSE, /* PC_relative. */
359+ 0, /* Bitpos. */
360+ complain_overflow_bitfield, /* Complain on overflow. */
361+ bfd_elf_generic_reloc,/* Special Function. */
362+ "R_MICROBLAZE_SRW32", /* Name. */
363+ FALSE, /* Partial Inplace. */
364+ 0, /* Source Mask. */
365+ 0x0000ffff, /* Dest Mask. */
366+ FALSE), /* PC relative offset? */
367+
368+ HOWTO (R_MICROBLAZE_32_NONE, /* Type. */
369+ 0, /* Rightshift. */
370+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
371+ 32, /* Bitsize. */
372+ TRUE, /* PC_relative. */
373+ 0, /* Bitpos. */
374+ complain_overflow_bitfield, /* Complain on overflow. */
375+ NULL, /* Special Function. */
376+ "R_MICROBLAZE_32_NONE",/* Name. */
377+ FALSE, /* Partial Inplace. */
378+ 0, /* Source Mask. */
379+ 0, /* Dest Mask. */
380+ FALSE), /* PC relative offset? */
381+
382+ /* This reloc does nothing. Used for relaxation. */
383+ HOWTO (R_MICROBLAZE_64_NONE, /* Type. */
384+ 0, /* Rightshift. */
385+ 3, /* Size (0 = byte, 1 = short, 2 = long). */
386+ 0, /* Bitsize. */
387+ TRUE, /* PC_relative. */
388+ 0, /* Bitpos. */
389+ complain_overflow_dont, /* Complain on overflow. */
390+ NULL, /* Special Function. */
391+ "R_MICROBLAZE_64_NONE",/* Name. */
392+ FALSE, /* Partial Inplace. */
393+ 0, /* Source Mask. */
394+ 0, /* Dest Mask. */
395+ FALSE), /* PC relative offset? */
396+
397+ /* Symbol Op Symbol relocation. */
398+ HOWTO (R_MICROBLAZE_32_SYM_OP_SYM, /* Type. */
399+ 0, /* Rightshift. */
400+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
401+ 32, /* Bitsize. */
402+ FALSE, /* PC_relative. */
403+ 0, /* Bitpos. */
404+ complain_overflow_bitfield, /* Complain on overflow. */
405+ bfd_elf_generic_reloc,/* Special Function. */
406+ "R_MICROBLAZE_32_SYM_OP_SYM", /* Name. */
407+ FALSE, /* Partial Inplace. */
408+ 0, /* Source Mask. */
409+ 0xffffffff, /* Dest Mask. */
410+ FALSE), /* PC relative offset? */
411+
412+ /* GNU extension to record C++ vtable hierarchy. */
413+ HOWTO (R_MICROBLAZE_GNU_VTINHERIT, /* Type. */
414+ 0, /* Rightshift. */
415+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
416+ 0, /* Bitsize. */
417+ FALSE, /* PC_relative. */
418+ 0, /* Bitpos. */
419+ complain_overflow_dont,/* Complain on overflow. */
420+ NULL, /* Special Function. */
421+ "R_MICROBLAZE_GNU_VTINHERIT", /* Name. */
422+ FALSE, /* Partial Inplace. */
423+ 0, /* Source Mask. */
424+ 0, /* Dest Mask. */
425+ FALSE), /* PC relative offset? */
426+
427+ /* GNU extension to record C++ vtable member usage. */
428+ HOWTO (R_MICROBLAZE_GNU_VTENTRY, /* Type. */
429+ 0, /* Rightshift. */
430+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
431+ 0, /* Bitsize. */
432+ FALSE, /* PC_relative. */
433+ 0, /* Bitpos. */
434+ complain_overflow_dont,/* Complain on overflow. */
435+ _bfd_elf_rel_vtable_reloc_fn, /* Special Function. */
436+ "R_MICROBLAZE_GNU_VTENTRY", /* Name. */
437+ FALSE, /* Partial Inplace. */
438+ 0, /* Source Mask. */
439+ 0, /* Dest Mask. */
440+ FALSE), /* PC relative offset? */
441+
442+ /* A 64 bit GOTPC relocation. Table-entry not really used. */
443+ HOWTO (R_MICROBLAZE_GOTPC_64, /* Type. */
444+ 0, /* Rightshift. */
445+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
446+ 16, /* Bitsize. */
447+ TRUE, /* PC_relative. */
448+ 0, /* Bitpos. */
449+ complain_overflow_dont, /* Complain on overflow. */
450+ bfd_elf_generic_reloc, /* Special Function. */
451+ "R_MICROBLAZE_GOTPC_64", /* Name. */
452+ FALSE, /* Partial Inplace. */
453+ 0, /* Source Mask. */
454+ 0x0000ffff, /* Dest Mask. */
455+ TRUE), /* PC relative offset? */
456+
457+ /* A 64 bit GOT relocation. Table-entry not really used. */
458+ HOWTO (R_MICROBLAZE_GOT_64, /* Type. */
459+ 0, /* Rightshift. */
460+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
461+ 16, /* Bitsize. */
462+ FALSE, /* PC_relative. */
463+ 0, /* Bitpos. */
464+ complain_overflow_dont, /* Complain on overflow. */
465+ bfd_elf_generic_reloc,/* Special Function. */
466+ "R_MICROBLAZE_GOT_64",/* Name. */
467+ FALSE, /* Partial Inplace. */
468+ 0, /* Source Mask. */
469+ 0x0000ffff, /* Dest Mask. */
470+ FALSE), /* PC relative offset? */
471+
472+ /* A 64 bit PLT relocation. Table-entry not really used. */
473+ HOWTO (R_MICROBLAZE_PLT_64, /* Type. */
474+ 0, /* Rightshift. */
475+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
476+ 16, /* Bitsize. */
477+ TRUE, /* PC_relative. */
478+ 0, /* Bitpos. */
479+ complain_overflow_dont, /* Complain on overflow. */
480+ bfd_elf_generic_reloc,/* Special Function. */
481+ "R_MICROBLAZE_PLT_64",/* Name. */
482+ FALSE, /* Partial Inplace. */
483+ 0, /* Source Mask. */
484+ 0x0000ffff, /* Dest Mask. */
485+ TRUE), /* PC relative offset? */
486+
487+ /* Table-entry not really used. */
488+ HOWTO (R_MICROBLAZE_REL, /* Type. */
489+ 0, /* Rightshift. */
490+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
491+ 16, /* Bitsize. */
492+ TRUE, /* PC_relative. */
493+ 0, /* Bitpos. */
494+ complain_overflow_dont, /* Complain on overflow. */
495+ bfd_elf_generic_reloc,/* Special Function. */
496+ "R_MICROBLAZE_REL", /* Name. */
497+ FALSE, /* Partial Inplace. */
498+ 0, /* Source Mask. */
499+ 0x0000ffff, /* Dest Mask. */
500+ TRUE), /* PC relative offset? */
501+
502+ /* Table-entry not really used. */
503+ HOWTO (R_MICROBLAZE_JUMP_SLOT,/* Type. */
504+ 0, /* Rightshift. */
505+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
506+ 16, /* Bitsize. */
507+ TRUE, /* PC_relative. */
508+ 0, /* Bitpos. */
509+ complain_overflow_dont, /* Complain on overflow. */
510+ bfd_elf_generic_reloc,/* Special Function. */
511+ "R_MICROBLAZE_JUMP_SLOT", /* Name. */
512+ FALSE, /* Partial Inplace. */
513+ 0, /* Source Mask. */
514+ 0x0000ffff, /* Dest Mask. */
515+ TRUE), /* PC relative offset? */
516+
517+ /* Table-entry not really used. */
518+ HOWTO (R_MICROBLAZE_GLOB_DAT,/* Type. */
519+ 0, /* Rightshift. */
520+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
521+ 16, /* Bitsize. */
522+ TRUE, /* PC_relative. */
523+ 0, /* Bitpos. */
524+ complain_overflow_dont, /* Complain on overflow. */
525+ bfd_elf_generic_reloc,/* Special Function. */
526+ "R_MICROBLAZE_GLOB_DAT", /* Name. */
527+ FALSE, /* Partial Inplace. */
528+ 0, /* Source Mask. */
529+ 0x0000ffff, /* Dest Mask. */
530+ TRUE), /* PC relative offset? */
531+
532+ /* A 64 bit GOT relative relocation. Table-entry not really used. */
533+ HOWTO (R_MICROBLAZE_GOTOFF_64, /* Type. */
534+ 0, /* Rightshift. */
535+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
536+ 16, /* Bitsize. */
537+ FALSE, /* PC_relative. */
538+ 0, /* Bitpos. */
539+ complain_overflow_dont, /* Complain on overflow. */
540+ bfd_elf_generic_reloc,/* Special Function. */
541+ "R_MICROBLAZE_GOTOFF_64", /* Name. */
542+ FALSE, /* Partial Inplace. */
543+ 0, /* Source Mask. */
544+ 0x0000ffff, /* Dest Mask. */
545+ FALSE), /* PC relative offset? */
546+
547+ /* A 32 bit GOT relative relocation. Table-entry not really used. */
548+ HOWTO (R_MICROBLAZE_GOTOFF_32, /* Type. */
549+ 0, /* Rightshift. */
550+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
551+ 16, /* Bitsize. */
552+ FALSE, /* PC_relative. */
553+ 0, /* Bitpos. */
554+ complain_overflow_dont, /* Complain on overflow. */
555+ bfd_elf_generic_reloc, /* Special Function. */
556+ "R_MICROBLAZE_GOTOFF_32", /* Name. */
557+ FALSE, /* Partial Inplace. */
558+ 0, /* Source Mask. */
559+ 0x0000ffff, /* Dest Mask. */
560+ FALSE), /* PC relative offset? */
561+
562+ /* COPY relocation. Table-entry not really used. */
563+ HOWTO (R_MICROBLAZE_COPY, /* Type. */
564+ 0, /* Rightshift. */
565+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
566+ 16, /* Bitsize. */
567+ FALSE, /* PC_relative. */
568+ 0, /* Bitpos. */
569+ complain_overflow_dont, /* Complain on overflow. */
570+ bfd_elf_generic_reloc,/* Special Function. */
571+ "R_MICROBLAZE_COPY", /* Name. */
572+ FALSE, /* Partial Inplace. */
573+ 0, /* Source Mask. */
574+ 0x0000ffff, /* Dest Mask. */
575+ FALSE), /* PC relative offset? */
576+
577+ /* Marker relocs for TLS. */
578+ HOWTO (R_MICROBLAZE_TLS,
579+ 0, /* rightshift */
580+ 2, /* size (0 = byte, 1 = short, 2 = long) */
581+ 32, /* bitsize */
582+ FALSE, /* pc_relative */
583+ 0, /* bitpos */
584+ complain_overflow_dont, /* complain_on_overflow */
585+ bfd_elf_generic_reloc, /* special_function */
586+ "R_MICROBLAZE_TLS", /* name */
587+ FALSE, /* partial_inplace */
588+ 0, /* src_mask */
589+ 0x0000ffff, /* dst_mask */
590+ FALSE), /* pcrel_offset */
591+
592+ HOWTO (R_MICROBLAZE_TLSGD,
593+ 0, /* rightshift */
594+ 2, /* size (0 = byte, 1 = short, 2 = long) */
595+ 32, /* bitsize */
596+ FALSE, /* pc_relative */
597+ 0, /* bitpos */
598+ complain_overflow_dont, /* complain_on_overflow */
599+ bfd_elf_generic_reloc, /* special_function */
600+ "R_MICROBLAZE_TLSGD", /* name */
601+ FALSE, /* partial_inplace */
602+ 0, /* src_mask */
603+ 0x0000ffff, /* dst_mask */
604+ FALSE), /* pcrel_offset */
605+
606+ HOWTO (R_MICROBLAZE_TLSLD,
607+ 0, /* rightshift */
608+ 2, /* size (0 = byte, 1 = short, 2 = long) */
609+ 32, /* bitsize */
610+ FALSE, /* pc_relative */
611+ 0, /* bitpos */
612+ complain_overflow_dont, /* complain_on_overflow */
613+ bfd_elf_generic_reloc, /* special_function */
614+ "R_MICROBLAZE_TLSLD", /* name */
615+ FALSE, /* partial_inplace */
616+ 0, /* src_mask */
617+ 0x0000ffff, /* dst_mask */
618+ FALSE), /* pcrel_offset */
619+
620+ /* Computes the load module index of the load module that contains the
621+ definition of its TLS sym. */
622+ HOWTO (R_MICROBLAZE_TLSDTPMOD32,
623+ 0, /* rightshift */
624+ 2, /* size (0 = byte, 1 = short, 2 = long) */
625+ 32, /* bitsize */
626+ FALSE, /* pc_relative */
627+ 0, /* bitpos */
628+ complain_overflow_dont, /* complain_on_overflow */
629+ bfd_elf_generic_reloc, /* special_function */
630+ "R_MICROBLAZE_TLSDTPMOD32", /* name */
631+ FALSE, /* partial_inplace */
632+ 0, /* src_mask */
633+ 0x0000ffff, /* dst_mask */
634+ FALSE), /* pcrel_offset */
635+
636+ /* Computes a dtv-relative displacement, the difference between the value
637+ of sym+add and the base address of the thread-local storage block that
638+ contains the definition of sym, minus 0x8000. Used for initializing GOT */
639+ HOWTO (R_MICROBLAZE_TLSDTPREL32,
640+ 0, /* rightshift */
641+ 2, /* size (0 = byte, 1 = short, 2 = long) */
642+ 32, /* bitsize */
643+ FALSE, /* pc_relative */
644+ 0, /* bitpos */
645+ complain_overflow_dont, /* complain_on_overflow */
646+ bfd_elf_generic_reloc, /* special_function */
647+ "R_MICROBLAZE_TLSDTPREL32", /* name */
648+ FALSE, /* partial_inplace */
649+ 0, /* src_mask */
650+ 0x0000ffff, /* dst_mask */
651+ FALSE), /* pcrel_offset */
652+
653+ /* Computes a dtv-relative displacement, the difference between the value
654+ of sym+add and the base address of the thread-local storage block that
655+ contains the definition of sym, minus 0x8000. */
656+ HOWTO (R_MICROBLAZE_TLSDTPREL64,
657+ 0, /* rightshift */
658+ 2, /* size (0 = byte, 1 = short, 2 = long) */
659+ 32, /* bitsize */
660+ FALSE, /* pc_relative */
661+ 0, /* bitpos */
662+ complain_overflow_dont, /* complain_on_overflow */
663+ bfd_elf_generic_reloc, /* special_function */
664+ "R_MICROBLAZE_TLSDTPREL64", /* name */
665+ FALSE, /* partial_inplace */
666+ 0, /* src_mask */
667+ 0x0000ffff, /* dst_mask */
668+ FALSE), /* pcrel_offset */
669+
670+ /* Computes a tp-relative displacement, the difference between the value of
671+ sym+add and the value of the thread pointer (r13). */
672+ HOWTO (R_MICROBLAZE_TLSGOTTPREL32,
673+ 0, /* rightshift */
674+ 2, /* size (0 = byte, 1 = short, 2 = long) */
675+ 32, /* bitsize */
676+ FALSE, /* pc_relative */
677+ 0, /* bitpos */
678+ complain_overflow_dont, /* complain_on_overflow */
679+ bfd_elf_generic_reloc, /* special_function */
680+ "R_MICROBLAZE_TLSGOTTPREL32", /* name */
681+ FALSE, /* partial_inplace */
682+ 0, /* src_mask */
683+ 0x0000ffff, /* dst_mask */
684+ FALSE), /* pcrel_offset */
685+
686+ /* Computes a tp-relative displacement, the difference between the value of
687+ sym+add and the value of the thread pointer (r13). */
688+ HOWTO (R_MICROBLAZE_TLSTPREL32,
689+ 0, /* rightshift */
690+ 2, /* size (0 = byte, 1 = short, 2 = long) */
691+ 32, /* bitsize */
692+ FALSE, /* pc_relative */
693+ 0, /* bitpos */
694+ complain_overflow_dont, /* complain_on_overflow */
695+ bfd_elf_generic_reloc, /* special_function */
696+ "R_MICROBLAZE_TLSTPREL32", /* name */
697+ FALSE, /* partial_inplace */
698+ 0, /* src_mask */
699+ 0x0000ffff, /* dst_mask */
700+ FALSE), /* pcrel_offset */
701+
702+};
703+
704+#ifndef NUM_ELEM
705+#define NUM_ELEM(a) (sizeof (a) / sizeof (a)[0])
706+#endif
707+
708+/* Initialize the microblaze_elf_howto_table, so that linear accesses can be done. */
709+
710+static void
711+microblaze_elf_howto_init (void)
712+{
713+ unsigned int i;
714+
715+ for (i = NUM_ELEM (microblaze_elf_howto_raw); i--;)
716+ {
717+ unsigned int type;
718+
719+ type = microblaze_elf_howto_raw[i].type;
720+
721+ BFD_ASSERT (type < NUM_ELEM (microblaze_elf_howto_table));
722+
723+ microblaze_elf_howto_table [type] = & microblaze_elf_howto_raw [i];
724+ }
725+}
726+
727+static reloc_howto_type *
728+microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
729+ bfd_reloc_code_real_type code)
730+{
731+ enum elf_microblaze_reloc_type microblaze_reloc = R_MICROBLAZE_NONE;
732+
733+ switch (code)
734+ {
735+ case BFD_RELOC_NONE:
736+ microblaze_reloc = R_MICROBLAZE_NONE;
737+ break;
738+ case BFD_RELOC_MICROBLAZE_32_NONE:
739+ microblaze_reloc = R_MICROBLAZE_32_NONE;
740+ break;
741+ case BFD_RELOC_MICROBLAZE_64_NONE:
742+ microblaze_reloc = R_MICROBLAZE_64_NONE;
743+ break;
744+ case BFD_RELOC_32:
745+ microblaze_reloc = R_MICROBLAZE_32;
746+ break;
747+ /* RVA is treated the same as 32 */
748+ case BFD_RELOC_RVA:
749+ microblaze_reloc = R_MICROBLAZE_32;
750+ break;
751+ case BFD_RELOC_32_PCREL:
752+ microblaze_reloc = R_MICROBLAZE_32_PCREL;
753+ break;
754+ case BFD_RELOC_64_PCREL:
755+ microblaze_reloc = R_MICROBLAZE_64_PCREL;
756+ break;
757+ case BFD_RELOC_MICROBLAZE_32_LO_PCREL:
758+ microblaze_reloc = R_MICROBLAZE_32_PCREL_LO;
759+ break;
760+ case BFD_RELOC_64:
761+ microblaze_reloc = R_MICROBLAZE_64;
762+ break;
763+ case BFD_RELOC_MICROBLAZE_32_LO:
764+ microblaze_reloc = R_MICROBLAZE_32_LO;
765+ break;
766+ case BFD_RELOC_MICROBLAZE_32_ROSDA:
767+ microblaze_reloc = R_MICROBLAZE_SRO32;
768+ break;
769+ case BFD_RELOC_MICROBLAZE_32_RWSDA:
770+ microblaze_reloc = R_MICROBLAZE_SRW32;
771+ break;
772+ case BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM:
773+ microblaze_reloc = R_MICROBLAZE_32_SYM_OP_SYM;
774+ break;
775+ case BFD_RELOC_VTABLE_INHERIT:
776+ microblaze_reloc = R_MICROBLAZE_GNU_VTINHERIT;
777+ break;
778+ case BFD_RELOC_VTABLE_ENTRY:
779+ microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
780+ break;
781+ case BFD_RELOC_MICROBLAZE_64_GOTPC:
782+ microblaze_reloc = R_MICROBLAZE_GOTPC_64;
783+ break;
784+ case BFD_RELOC_MICROBLAZE_64_GOT:
785+ microblaze_reloc = R_MICROBLAZE_GOT_64;
786+ break;
787+ case BFD_RELOC_MICROBLAZE_64_PLT:
788+ microblaze_reloc = R_MICROBLAZE_PLT_64;
789+ break;
790+ case BFD_RELOC_MICROBLAZE_64_GOTOFF:
791+ microblaze_reloc = R_MICROBLAZE_GOTOFF_64;
792+ break;
793+ case BFD_RELOC_MICROBLAZE_32_GOTOFF:
794+ microblaze_reloc = R_MICROBLAZE_GOTOFF_32;
795+ break;
796+ case BFD_RELOC_MICROBLAZE_64_TLSGD:
797+ microblaze_reloc = R_MICROBLAZE_TLSGD;
798+ break;
799+ case BFD_RELOC_MICROBLAZE_64_TLSLD:
800+ microblaze_reloc = R_MICROBLAZE_TLSLD;
801+ break;
802+ case BFD_RELOC_MICROBLAZE_32_TLSDTPREL:
803+ microblaze_reloc = R_MICROBLAZE_TLSDTPREL32;
804+ break;
805+ case BFD_RELOC_MICROBLAZE_64_TLSDTPREL:
806+ microblaze_reloc = R_MICROBLAZE_TLSDTPREL64;
807+ break;
808+ case BFD_RELOC_MICROBLAZE_32_TLSDTPMOD:
809+ microblaze_reloc = R_MICROBLAZE_TLSDTPMOD32;
810+ break;
811+ case BFD_RELOC_MICROBLAZE_64_TLSGOTTPREL:
812+ microblaze_reloc = R_MICROBLAZE_TLSGOTTPREL32;
813+ break;
814+ case BFD_RELOC_MICROBLAZE_64_TLSTPREL:
815+ microblaze_reloc = R_MICROBLAZE_TLSTPREL32;
816+ break;
817+ case BFD_RELOC_MICROBLAZE_COPY:
818+ microblaze_reloc = R_MICROBLAZE_COPY;
819+ break;
820+ default:
821+ return (reloc_howto_type *) NULL;
822+ }
823+
824+ if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
825+ /* Initialize howto table if needed. */
826+ microblaze_elf_howto_init ();
827+
828+ return microblaze_elf_howto_table [(int) microblaze_reloc];
829+};
830+
831+static reloc_howto_type *
832+microblaze_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
833+ const char *r_name)
834+{
835+ unsigned int i;
836+
837+ for (i = 0; i < NUM_ELEM (microblaze_elf_howto_raw); i++)
838+ if (microblaze_elf_howto_raw[i].name != NULL
839+ && strcasecmp (microblaze_elf_howto_raw[i].name, r_name) == 0)
840+ return &microblaze_elf_howto_raw[i];
841+
842+ return NULL;
843+}
844+
845+/* Set the howto pointer for a RCE ELF reloc. */
846+
847+static void
848+microblaze_elf_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
849+ arelent * cache_ptr,
850+ Elf_Internal_Rela * dst)
851+{
852+ unsigned int r_type;
853+
854+ if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
855+ /* Initialize howto table if needed. */
856+ microblaze_elf_howto_init ();
857+
858+ r_type = ELF64_R_TYPE (dst->r_info);
859+ if (r_type >= R_MICROBLAZE_max)
860+ {
861+ (*_bfd_error_handler) (_("%B: unrecognised MicroBlaze reloc number: %d"),
862+ abfd, r_type);
863+ bfd_set_error (bfd_error_bad_value);
864+ r_type = R_MICROBLAZE_NONE;
865+ }
866+
867+ cache_ptr->howto = microblaze_elf_howto_table [r_type];
868+}
869+
870+/* Microblaze ELF local labels start with 'L.' or '$L', not '.L'. */
871+
872+static bfd_boolean
873+microblaze_elf_is_local_label_name (bfd *abfd, const char *name)
874+{
875+ if (name[0] == 'L' && name[1] == '.')
876+ return TRUE;
877+
878+ if (name[0] == '$' && name[1] == 'L')
879+ return TRUE;
880+
881+ /* With gcc, the labels go back to starting with '.', so we accept
882+ the generic ELF local label syntax as well. */
883+ return _bfd_elf_is_local_label_name (abfd, name);
884+}
885+
886+/* The microblaze linker (like many others) needs to keep track of
887+ the number of relocs that it decides to copy as dynamic relocs in
888+ check_relocs for each symbol. This is so that it can later discard
889+ them if they are found to be unnecessary. We store the information
890+ in a field extending the regular ELF linker hash table. */
891+
892+struct elf64_mb_dyn_relocs
893+{
894+ struct elf64_mb_dyn_relocs *next;
895+
896+ /* The input section of the reloc. */
897+ asection *sec;
898+
899+ /* Total number of relocs copied for the input section. */
900+ bfd_size_type count;
901+
902+ /* Number of pc-relative relocs copied for the input section. */
903+ bfd_size_type pc_count;
904+};
905+
906+/* ELF linker hash entry. */
907+
908+struct elf64_mb_link_hash_entry
909+{
910+ struct elf_link_hash_entry elf;
911+
912+ /* Track dynamic relocs copied for this symbol. */
913+ struct elf64_mb_dyn_relocs *dyn_relocs;
914+
915+ /* TLS Reference Types for the symbol; Updated by check_relocs */
916+#define TLS_GD 1 /* GD reloc. */
917+#define TLS_LD 2 /* LD reloc. */
918+#define TLS_TPREL 4 /* TPREL reloc, => IE. */
919+#define TLS_DTPREL 8 /* DTPREL reloc, => LD. */
920+#define TLS_TLS 16 /* Any TLS reloc. */
921+ unsigned char tls_mask;
922+
923+};
924+
925+#define IS_TLS_GD(x) (x == (TLS_TLS | TLS_GD))
926+#define IS_TLS_LD(x) (x == (TLS_TLS | TLS_LD))
927+#define IS_TLS_DTPREL(x) (x == (TLS_TLS | TLS_DTPREL))
928+#define IS_TLS_NONE(x) (x == 0)
929+
930+#define elf64_mb_hash_entry(ent) ((struct elf64_mb_link_hash_entry *)(ent))
931+
932+/* ELF linker hash table. */
933+
934+struct elf64_mb_link_hash_table
935+{
936+ struct elf_link_hash_table elf;
937+
938+ /* Short-cuts to get to dynamic linker sections. */
939+ asection *sgot;
940+ asection *sgotplt;
941+ asection *srelgot;
942+ asection *splt;
943+ asection *srelplt;
944+ asection *sdynbss;
945+ asection *srelbss;
946+
947+ /* Small local sym to section mapping cache. */
948+ struct sym_cache sym_sec;
949+
950+ /* TLS Local Dynamic GOT Entry */
951+ union {
952+ bfd_signed_vma refcount;
953+ bfd_vma offset;
954+ } tlsld_got;
955+};
956+
957+/* Nonzero if this section has TLS related relocations. */
958+#define has_tls_reloc sec_flg0
959+
960+/* Get the ELF linker hash table from a link_info structure. */
961+
962+#define elf64_mb_hash_table(p) \
963+ (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
964+ == MICROBLAZE_ELF_DATA ? ((struct elf64_mb_link_hash_table *) ((p)->hash)) : NULL)
965+
966+/* Create an entry in a microblaze ELF linker hash table. */
967+
968+static struct bfd_hash_entry *
969+link_hash_newfunc (struct bfd_hash_entry *entry,
970+ struct bfd_hash_table *table,
971+ const char *string)
972+{
973+ /* Allocate the structure if it has not already been allocated by a
974+ subclass. */
975+ if (entry == NULL)
976+ {
977+ entry = bfd_hash_allocate (table,
978+ sizeof (struct elf64_mb_link_hash_entry));
979+ if (entry == NULL)
980+ return entry;
981+ }
982+
983+ /* Call the allocation method of the superclass. */
984+ entry = _bfd_elf_link_hash_newfunc (entry, table, string);
985+ if (entry != NULL)
986+ {
987+ struct elf64_mb_link_hash_entry *eh;
988+
989+ eh = (struct elf64_mb_link_hash_entry *) entry;
990+ eh->dyn_relocs = NULL;
991+ eh->tls_mask = 0;
992+ }
993+
994+ return entry;
995+}
996+
997+/* Create a mb ELF linker hash table. */
998+
999+static struct bfd_link_hash_table *
1000+microblaze_elf_link_hash_table_create (bfd *abfd)
1001+{
1002+ struct elf64_mb_link_hash_table *ret;
1003+ bfd_size_type amt = sizeof (struct elf64_mb_link_hash_table);
1004+
1005+ ret = (struct elf64_mb_link_hash_table *) bfd_zmalloc (amt);
1006+ if (ret == NULL)
1007+ return NULL;
1008+
1009+ if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
1010+ sizeof (struct elf64_mb_link_hash_entry),
1011+ MICROBLAZE_ELF_DATA))
1012+ {
1013+ free (ret);
1014+ return NULL;
1015+ }
1016+
1017+ return &ret->elf.root;
1018+}
1019+
1020+/* Set the values of the small data pointers. */
1021+
1022+static void
1023+microblaze_elf_final_sdp (struct bfd_link_info *info)
1024+{
1025+ struct bfd_link_hash_entry *h;
1026+
1027+ h = bfd_link_hash_lookup (info->hash, RO_SDA_ANCHOR_NAME, FALSE, FALSE, TRUE);
1028+ if (h != (struct bfd_link_hash_entry *) NULL
1029+ && h->type == bfd_link_hash_defined)
1030+ ro_small_data_pointer = (h->u.def.value
1031+ + h->u.def.section->output_section->vma
1032+ + h->u.def.section->output_offset);
1033+
1034+ h = bfd_link_hash_lookup (info->hash, RW_SDA_ANCHOR_NAME, FALSE, FALSE, TRUE);
1035+ if (h != (struct bfd_link_hash_entry *) NULL
1036+ && h->type == bfd_link_hash_defined)
1037+ rw_small_data_pointer = (h->u.def.value
1038+ + h->u.def.section->output_section->vma
1039+ + h->u.def.section->output_offset);
1040+}
1041+
1042+static bfd_vma
1043+dtprel_base (struct bfd_link_info *info)
1044+{
1045+ /* If tls_sec is NULL, we should have signalled an error already. */
1046+ if (elf_hash_table (info)->tls_sec == NULL)
1047+ return 0;
1048+ return elf_hash_table (info)->tls_sec->vma;
1049+}
1050+
1051+/* The size of the thread control block. */
1052+#define TCB_SIZE 8
1053+
1054+/* Output a simple dynamic relocation into SRELOC. */
1055+
1056+static void
1057+microblaze_elf_output_dynamic_relocation (bfd *output_bfd,
1058+ asection *sreloc,
1059+ unsigned long reloc_index,
1060+ unsigned long indx,
1061+ int r_type,
1062+ bfd_vma offset,
1063+ bfd_vma addend)
1064+{
1065+
1066+ Elf_Internal_Rela rel;
1067+
1068+ rel.r_info = ELF64_R_INFO (indx, r_type);
1069+ rel.r_offset = offset;
1070+ rel.r_addend = addend;
1071+
1072+ bfd_elf64_swap_reloca_out (output_bfd, &rel,
1073+ (sreloc->contents + reloc_index * sizeof (Elf64_External_Rela)));
1074+}
1075+
1076+/* This code is taken from elf64-m32r.c
1077+ There is some attempt to make this function usable for many architectures,
1078+ both USE_REL and USE_RELA ['twould be nice if such a critter existed],
1079+ if only to serve as a learning tool.
1080+
1081+ The RELOCATE_SECTION function is called by the new ELF backend linker
1082+ to handle the relocations for a section.
1083+
1084+ The relocs are always passed as Rela structures; if the section
1085+ actually uses Rel structures, the r_addend field will always be
1086+ zero.
1087+
1088+ This function is responsible for adjust the section contents as
1089+ necessary, and (if using Rela relocs and generating a
1090+ relocatable output file) adjusting the reloc addend as
1091+ necessary.
1092+
1093+ This function does not have to worry about setting the reloc
1094+ address or the reloc symbol index.
1095+
1096+ LOCAL_SYMS is a pointer to the swapped in local symbols.
1097+
1098+ LOCAL_SECTIONS is an array giving the section in the input file
1099+ corresponding to the st_shndx field of each local symbol.
1100+
1101+ The global hash table entry for the global symbols can be found
1102+ via elf_sym_hashes (input_bfd).
1103+
1104+ When generating relocatable output, this function must handle
1105+ STB_LOCAL/STT_SECTION symbols specially. The output symbol is
1106+ going to be the section symbol corresponding to the output
1107+ section, which means that the addend must be adjusted
1108+ accordingly. */
1109+
1110+static bfd_boolean
1111+microblaze_elf_relocate_section (bfd *output_bfd,
1112+ struct bfd_link_info *info,
1113+ bfd *input_bfd,
1114+ asection *input_section,
1115+ bfd_byte *contents,
1116+ Elf_Internal_Rela *relocs,
1117+ Elf_Internal_Sym *local_syms,
1118+ asection **local_sections)
1119+{
1120+ struct elf64_mb_link_hash_table *htab;
1121+ Elf_Internal_Shdr *symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1122+ struct elf_link_hash_entry **sym_hashes = elf_sym_hashes (input_bfd);
1123+ Elf_Internal_Rela *rel, *relend;
1124+ int endian = (bfd_little_endian (output_bfd)) ? 0 : 2;
1125+ /* Assume success. */
1126+ bfd_boolean ret = TRUE;
1127+ asection *sreloc;
1128+ bfd_vma *local_got_offsets;
1129+ unsigned int tls_type;
1130+
1131+ if (!microblaze_elf_howto_table[R_MICROBLAZE_max-1])
1132+ microblaze_elf_howto_init ();
1133+
1134+ htab = elf64_mb_hash_table (info);
1135+ if (htab == NULL)
1136+ return FALSE;
1137+
1138+ local_got_offsets = elf_local_got_offsets (input_bfd);
1139+
1140+ sreloc = elf_section_data (input_section)->sreloc;
1141+
1142+ rel = relocs;
1143+ relend = relocs + input_section->reloc_count;
1144+ for (; rel < relend; rel++)
1145+ {
1146+ int r_type;
1147+ reloc_howto_type *howto;
1148+ unsigned long r_symndx;
1149+ bfd_vma addend = rel->r_addend;
1150+ bfd_vma offset = rel->r_offset;
1151+ struct elf_link_hash_entry *h;
1152+ Elf_Internal_Sym *sym;
1153+ asection *sec;
1154+ const char *sym_name;
1155+ bfd_reloc_status_type r = bfd_reloc_ok;
1156+ const char *errmsg = NULL;
1157+ bfd_boolean unresolved_reloc = FALSE;
1158+
1159+ h = NULL;
1160+ r_type = ELF64_R_TYPE (rel->r_info);
1161+ tls_type = 0;
1162+
1163+ if (r_type < 0 || r_type >= (int) R_MICROBLAZE_max)
1164+ {
1165+ (*_bfd_error_handler) (_("%s: unknown relocation type %d"),
1166+ bfd_get_filename (input_bfd), (int) r_type);
1167+ bfd_set_error (bfd_error_bad_value);
1168+ ret = FALSE;
1169+ continue;
1170+ }
1171+
1172+ howto = microblaze_elf_howto_table[r_type];
1173+ r_symndx = ELF64_R_SYM (rel->r_info);
1174+
1175+ if (bfd_link_relocatable (info))
1176+ {
1177+ /* This is a relocatable link. We don't have to change
1178+ anything, unless the reloc is against a section symbol,
1179+ in which case we have to adjust according to where the
1180+ section symbol winds up in the output section. */
1181+ sec = NULL;
1182+ if (r_symndx >= symtab_hdr->sh_info)
1183+ /* External symbol. */
1184+ continue;
1185+
1186+ /* Local symbol. */
1187+ sym = local_syms + r_symndx;
1188+ sym_name = "<local symbol>";
1189+ /* STT_SECTION: symbol is associated with a section. */
1190+ if (ELF_ST_TYPE (sym->st_info) != STT_SECTION)
1191+ /* Symbol isn't associated with a section. Nothing to do. */
1192+ continue;
1193+
1194+ sec = local_sections[r_symndx];
1195+ addend += sec->output_offset + sym->st_value;
1196+#ifndef USE_REL
1197+ /* This can't be done for USE_REL because it doesn't mean anything
1198+ and elf_link_input_bfd asserts this stays zero. */
1199+ /* rel->r_addend = addend; */
1200+#endif
1201+
1202+#ifndef USE_REL
1203+ /* Addends are stored with relocs. We're done. */
1204+ continue;
1205+#else /* USE_REL */
1206+ /* If partial_inplace, we need to store any additional addend
1207+ back in the section. */
1208+ if (!howto->partial_inplace)
1209+ continue;
1210+ /* ??? Here is a nice place to call a special_function like handler. */
1211+ r = _bfd_relocate_contents (howto, input_bfd, addend,
1212+ contents + offset);
1213+#endif /* USE_REL */
1214+ }
1215+ else
1216+ {
1217+ bfd_vma relocation;
1218+
1219+ /* This is a final link. */
1220+ sym = NULL;
1221+ sec = NULL;
1222+ unresolved_reloc = FALSE;
1223+
1224+ if (r_symndx < symtab_hdr->sh_info)
1225+ {
1226+ /* Local symbol. */
1227+ sym = local_syms + r_symndx;
1228+ sec = local_sections[r_symndx];
1229+ if (sec == 0)
1230+ continue;
1231+ sym_name = "<local symbol>";
1232+ relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
1233+ /* r_addend may have changed if the reference section was
1234+ a merge section. */
1235+ addend = rel->r_addend;
1236+ }
1237+ else
1238+ {
1239+ /* External symbol. */
1240+ bfd_boolean warned ATTRIBUTE_UNUSED;
1241+ bfd_boolean ignored ATTRIBUTE_UNUSED;
1242+
1243+ RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
1244+ r_symndx, symtab_hdr, sym_hashes,
1245+ h, sec, relocation,
1246+ unresolved_reloc, warned, ignored);
1247+ sym_name = h->root.root.string;
1248+ }
1249+
1250+ /* Sanity check the address. */
1251+ if (offset > bfd_get_section_limit (input_bfd, input_section))
1252+ {
1253+ r = bfd_reloc_outofrange;
1254+ goto check_reloc;
1255+ }
1256+
1257+ switch ((int) r_type)
1258+ {
1259+ case (int) R_MICROBLAZE_SRO32 :
1260+ {
1261+ const char *name;
1262+
1263+ /* Only relocate if the symbol is defined. */
1264+ if (sec)
1265+ {
1266+ name = bfd_get_section_name (sec->owner, sec);
1267+
1268+ if (strcmp (name, ".sdata2") == 0
1269+ || strcmp (name, ".sbss2") == 0)
1270+ {
1271+ if (ro_small_data_pointer == 0)
1272+ microblaze_elf_final_sdp (info);
1273+ if (ro_small_data_pointer == 0)
1274+ {
1275+ ret = FALSE;
1276+ r = bfd_reloc_undefined;
1277+ goto check_reloc;
1278+ }
1279+
1280+ /* At this point `relocation' contains the object's
1281+ address. */
1282+ relocation -= ro_small_data_pointer;
1283+ /* Now it contains the offset from _SDA2_BASE_. */
1284+ r = _bfd_final_link_relocate (howto, input_bfd,
1285+ input_section,
1286+ contents, offset,
1287+ relocation, addend);
1288+ }
1289+ else
1290+ {
1291+ (*_bfd_error_handler) (_("%s: The target (%s) of an %s relocation is in the wrong section (%s)"),
1292+ bfd_get_filename (input_bfd),
1293+ sym_name,
1294+ microblaze_elf_howto_table[(int) r_type]->name,
1295+ bfd_get_section_name (sec->owner, sec));
1296+ /*bfd_set_error (bfd_error_bad_value); ??? why? */
1297+ ret = FALSE;
1298+ continue;
1299+ }
1300+ }
1301+ }
1302+ break;
1303+
1304+ case (int) R_MICROBLAZE_SRW32 :
1305+ {
1306+ const char *name;
1307+
1308+ /* Only relocate if the symbol is defined. */
1309+ if (sec)
1310+ {
1311+ name = bfd_get_section_name (sec->owner, sec);
1312+
1313+ if (strcmp (name, ".sdata") == 0
1314+ || strcmp (name, ".sbss") == 0)
1315+ {
1316+ if (rw_small_data_pointer == 0)
1317+ microblaze_elf_final_sdp (info);
1318+ if (rw_small_data_pointer == 0)
1319+ {
1320+ ret = FALSE;
1321+ r = bfd_reloc_undefined;
1322+ goto check_reloc;
1323+ }
1324+
1325+ /* At this point `relocation' contains the object's
1326+ address. */
1327+ relocation -= rw_small_data_pointer;
1328+ /* Now it contains the offset from _SDA_BASE_. */
1329+ r = _bfd_final_link_relocate (howto, input_bfd,
1330+ input_section,
1331+ contents, offset,
1332+ relocation, addend);
1333+ }
1334+ else
1335+ {
1336+ (*_bfd_error_handler) (_("%s: The target (%s) of an %s relocation is in the wrong section (%s)"),
1337+ bfd_get_filename (input_bfd),
1338+ sym_name,
1339+ microblaze_elf_howto_table[(int) r_type]->name,
1340+ bfd_get_section_name (sec->owner, sec));
1341+ /*bfd_set_error (bfd_error_bad_value); ??? why? */
1342+ ret = FALSE;
1343+ continue;
1344+ }
1345+ }
1346+ }
1347+ break;
1348+
1349+ case (int) R_MICROBLAZE_32_SYM_OP_SYM:
1350+ break; /* Do nothing. */
1351+
1352+ case (int) R_MICROBLAZE_GOTPC_64:
1353+ relocation = htab->sgotplt->output_section->vma
1354+ + htab->sgotplt->output_offset;
1355+ relocation -= (input_section->output_section->vma
1356+ + input_section->output_offset
1357+ + offset + INST_WORD_SIZE);
1358+ relocation += addend;
1359+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1360+ contents + offset + endian);
1361+ bfd_put_16 (input_bfd, relocation & 0xffff,
1362+ contents + offset + endian + INST_WORD_SIZE);
1363+ break;
1364+
1365+ case (int) R_MICROBLAZE_PLT_64:
1366+ {
1367+ bfd_vma immediate;
1368+ if (htab->splt != NULL && h != NULL
1369+ && h->plt.offset != (bfd_vma) -1)
1370+ {
1371+ relocation = (htab->splt->output_section->vma
1372+ + htab->splt->output_offset
1373+ + h->plt.offset);
1374+ unresolved_reloc = FALSE;
1375+ immediate = relocation - (input_section->output_section->vma
1376+ + input_section->output_offset
1377+ + offset + INST_WORD_SIZE);
1378+ bfd_put_16 (input_bfd, (immediate >> 16) & 0xffff,
1379+ contents + offset + endian);
1380+ bfd_put_16 (input_bfd, immediate & 0xffff,
1381+ contents + offset + endian + INST_WORD_SIZE);
1382+ }
1383+ else
1384+ {
1385+ relocation -= (input_section->output_section->vma
1386+ + input_section->output_offset
1387+ + offset + INST_WORD_SIZE);
1388+ immediate = relocation;
1389+ bfd_put_16 (input_bfd, (immediate >> 16) & 0xffff,
1390+ contents + offset + endian);
1391+ bfd_put_16 (input_bfd, immediate & 0xffff,
1392+ contents + offset + endian + INST_WORD_SIZE);
1393+ }
1394+ break;
1395+ }
1396+
1397+ case (int) R_MICROBLAZE_TLSGD:
1398+ tls_type = (TLS_TLS | TLS_GD);
1399+ goto dogot;
1400+ case (int) R_MICROBLAZE_TLSLD:
1401+ tls_type = (TLS_TLS | TLS_LD);
1402+ dogot:
1403+ case (int) R_MICROBLAZE_GOT_64:
1404+ {
1405+ bfd_vma *offp;
1406+ bfd_vma off, off2;
1407+ unsigned long indx;
1408+ bfd_vma static_value;
1409+
1410+ bfd_boolean need_relocs = FALSE;
1411+ if (htab->sgot == NULL)
1412+ abort ();
1413+
1414+ indx = 0;
1415+ offp = NULL;
1416+
1417+ /* 1. Identify GOT Offset;
1418+ 2. Compute Static Values
1419+ 3. Process Module Id, Process Offset
1420+ 4. Fixup Relocation with GOT offset value. */
1421+
1422+ /* 1. Determine GOT Offset to use : TLS_LD, global, local */
1423+ if (IS_TLS_LD (tls_type))
1424+ offp = &htab->tlsld_got.offset;
1425+ else if (h != NULL)
1426+ {
1427+ if (htab->sgotplt != NULL && h->got.offset != (bfd_vma) -1)
1428+ offp = &h->got.offset;
1429+ else
1430+ abort ();
1431+ }
1432+ else
1433+ {
1434+ if (local_got_offsets == NULL)
1435+ abort ();
1436+ offp = &local_got_offsets[r_symndx];
1437+ }
1438+
1439+ if (!offp)
1440+ abort ();
1441+
1442+ off = (*offp) & ~1;
1443+ off2 = off;
1444+
1445+ if (IS_TLS_LD(tls_type) || IS_TLS_GD(tls_type))
1446+ off2 = off + 4;
1447+
1448+ /* Symbol index to use for relocs */
1449+ if (h != NULL)
1450+ {
1451+ bfd_boolean dyn =
1452+ elf_hash_table (info)->dynamic_sections_created;
1453+
1454+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
1455+ bfd_link_pic (info),
1456+ h)
1457+ && (!bfd_link_pic (info)
1458+ || !SYMBOL_REFERENCES_LOCAL (info, h)))
1459+ indx = h->dynindx;
1460+ }
1461+
1462+ /* Need to generate relocs ? */
1463+ if ((bfd_link_pic (info) || indx != 0)
1464+ && (h == NULL
1465+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1466+ || h->root.type != bfd_link_hash_undefweak))
1467+ need_relocs = TRUE;
1468+
1469+ /* 2. Compute/Emit Static value of r-expression */
1470+ static_value = relocation + addend;
1471+
1472+ /* 3. Process module-id and offset */
1473+ if (! ((*offp) & 1) )
1474+ {
1475+ bfd_vma got_offset;
1476+
1477+ got_offset = (htab->sgot->output_section->vma
1478+ + htab->sgot->output_offset
1479+ + off);
1480+
1481+ /* Process module-id */
1482+ if (IS_TLS_LD(tls_type))
1483+ {
1484+ if (! bfd_link_pic (info))
1485+ {
1486+ bfd_put_32 (output_bfd, 1, htab->sgot->contents + off);
1487+ }
1488+ else
1489+ {
1490+ microblaze_elf_output_dynamic_relocation (output_bfd,
1491+ htab->srelgot, htab->srelgot->reloc_count++,
1492+ /* symindex= */ 0, R_MICROBLAZE_TLSDTPMOD32,
1493+ got_offset, 0);
1494+ }
1495+ }
1496+ else if (IS_TLS_GD(tls_type))
1497+ {
1498+ if (! need_relocs)
1499+ {
1500+ bfd_put_32 (output_bfd, 1, htab->sgot->contents + off);
1501+ }
1502+ else
1503+ {
1504+ microblaze_elf_output_dynamic_relocation (output_bfd,
1505+ htab->srelgot,
1506+ htab->srelgot->reloc_count++,
1507+ /* symindex= */ indx, R_MICROBLAZE_TLSDTPMOD32,
1508+ got_offset, indx ? 0 : static_value);
1509+ }
1510+ }
1511+
1512+ /* Process Offset */
1513+ if (htab->srelgot == NULL)
1514+ abort ();
1515+
1516+ got_offset = (htab->sgot->output_section->vma
1517+ + htab->sgot->output_offset
1518+ + off2);
1519+ if (IS_TLS_LD(tls_type))
1520+ {
1521+ /* For LD, offset should be 0 */
1522+ *offp |= 1;
1523+ bfd_put_32 (output_bfd, 0, htab->sgot->contents + off2);
1524+ }
1525+ else if (IS_TLS_GD(tls_type))
1526+ {
1527+ *offp |= 1;
1528+ static_value -= dtprel_base(info);
1529+ if (need_relocs)
1530+ {
1531+ microblaze_elf_output_dynamic_relocation (output_bfd,
1532+ htab->srelgot, htab->srelgot->reloc_count++,
1533+ /* symindex= */ indx, R_MICROBLAZE_TLSDTPREL32,
1534+ got_offset, indx ? 0 : static_value);
1535+ }
1536+ else
1537+ {
1538+ bfd_put_32 (output_bfd, static_value,
1539+ htab->sgot->contents + off2);
1540+ }
1541+ }
1542+ else
1543+ {
1544+ bfd_put_32 (output_bfd, static_value,
1545+ htab->sgot->contents + off2);
1546+
1547+ /* Relocs for dyn symbols generated by
1548+ finish_dynamic_symbols */
1549+ if (bfd_link_pic (info) && h == NULL)
1550+ {
1551+ *offp |= 1;
1552+ microblaze_elf_output_dynamic_relocation (output_bfd,
1553+ htab->srelgot, htab->srelgot->reloc_count++,
1554+ /* symindex= */ indx, R_MICROBLAZE_REL,
1555+ got_offset, static_value);
1556+ }
1557+ }
1558+ }
1559+
1560+ /* 4. Fixup Relocation with GOT offset value
1561+ Compute relative address of GOT entry for applying
1562+ the current relocation */
1563+ relocation = htab->sgot->output_section->vma
1564+ + htab->sgot->output_offset
1565+ + off
1566+ - htab->sgotplt->output_section->vma
1567+ - htab->sgotplt->output_offset;
1568+
1569+ /* Apply Current Relocation */
1570+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1571+ contents + offset + endian);
1572+ bfd_put_16 (input_bfd, relocation & 0xffff,
1573+ contents + offset + endian + INST_WORD_SIZE);
1574+
1575+ unresolved_reloc = FALSE;
1576+ break;
1577+ }
1578+
1579+ case (int) R_MICROBLAZE_GOTOFF_64:
1580+ {
1581+ bfd_vma immediate;
1582+ unsigned short lo, high;
1583+ relocation += addend;
1584+ relocation -= htab->sgotplt->output_section->vma
1585+ + htab->sgotplt->output_offset;
1586+ /* Write this value into correct location. */
1587+ immediate = relocation;
1588+ lo = immediate & 0x0000ffff;
1589+ high = (immediate >> 16) & 0x0000ffff;
1590+ bfd_put_16 (input_bfd, high, contents + offset + endian);
1591+ bfd_put_16 (input_bfd, lo, contents + offset + INST_WORD_SIZE + endian);
1592+ break;
1593+ }
1594+
1595+ case (int) R_MICROBLAZE_GOTOFF_32:
1596+ {
1597+ relocation += addend;
1598+ relocation -= htab->sgotplt->output_section->vma
1599+ + htab->sgotplt->output_offset;
1600+ /* Write this value into correct location. */
1601+ bfd_put_32 (input_bfd, relocation, contents + offset);
1602+ break;
1603+ }
1604+
1605+ case (int) R_MICROBLAZE_TLSDTPREL64:
1606+ relocation += addend;
1607+ relocation -= dtprel_base(info);
1608+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1609+ contents + offset + endian);
1610+ bfd_put_16 (input_bfd, relocation & 0xffff,
1611+ contents + offset + endian + INST_WORD_SIZE);
1612+ break;
1613+ case (int) R_MICROBLAZE_64_PCREL :
1614+ case (int) R_MICROBLAZE_64:
1615+ case (int) R_MICROBLAZE_32:
1616+ {
1617+ /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
1618+ from removed linkonce sections, or sections discarded by
1619+ a linker script. */
1620+ if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
1621+ {
1622+ relocation += addend;
1623+ if (r_type == R_MICROBLAZE_32)
1624+ bfd_put_32 (input_bfd, relocation, contents + offset);
1625+ else
1626+ {
1627+ if (r_type == R_MICROBLAZE_64_PCREL)
1628+ relocation -= (input_section->output_section->vma
1629+ + input_section->output_offset
1630+ + offset + INST_WORD_SIZE);
1631+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1632+ contents + offset + endian);
1633+ bfd_put_16 (input_bfd, relocation & 0xffff,
1634+ contents + offset + endian + INST_WORD_SIZE);
1635+ }
1636+ break;
1637+ }
1638+
1639+ if ((bfd_link_pic (info)
1640+ && (h == NULL
1641+ || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
1642+ || h->root.type != bfd_link_hash_undefweak)
1643+ && (!howto->pc_relative
1644+ || (h != NULL
1645+ && h->dynindx != -1
1646+ && (!info->symbolic
1647+ || !h->def_regular))))
1648+ || (!bfd_link_pic (info)
1649+ && h != NULL
1650+ && h->dynindx != -1
1651+ && !h->non_got_ref
1652+ && ((h->def_dynamic
1653+ && !h->def_regular)
1654+ || h->root.type == bfd_link_hash_undefweak
1655+ || h->root.type == bfd_link_hash_undefined)))
1656+ {
1657+ Elf_Internal_Rela outrel;
1658+ bfd_byte *loc;
1659+ bfd_boolean skip;
1660+
1661+ /* When generating a shared object, these relocations
1662+ are copied into the output file to be resolved at run
1663+ time. */
1664+
1665+ BFD_ASSERT (sreloc != NULL);
1666+
1667+ skip = FALSE;
1668+
1669+ outrel.r_offset =
1670+ _bfd_elf_section_offset (output_bfd, info, input_section,
1671+ rel->r_offset);
1672+ if (outrel.r_offset == (bfd_vma) -1)
1673+ skip = TRUE;
1674+ else if (outrel.r_offset == (bfd_vma) -2)
1675+ skip = TRUE;
1676+ outrel.r_offset += (input_section->output_section->vma
1677+ + input_section->output_offset);
1678+
1679+ if (skip)
1680+ memset (&outrel, 0, sizeof outrel);
1681+ /* h->dynindx may be -1 if the symbol was marked to
1682+ become local. */
1683+ else if (h != NULL
1684+ && ((! info->symbolic && h->dynindx != -1)
1685+ || !h->def_regular))
1686+ {
1687+ BFD_ASSERT (h->dynindx != -1);
1688+ outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
1689+ outrel.r_addend = addend;
1690+ }
1691+ else
1692+ {
1693+ if (r_type == R_MICROBLAZE_32)
1694+ {
1695+ outrel.r_info = ELF64_R_INFO (0, R_MICROBLAZE_REL);
1696+ outrel.r_addend = relocation + addend;
1697+ }
1698+ else
1699+ {
1700+ BFD_FAIL ();
1701+ (*_bfd_error_handler)
1702+ (_("%B: probably compiled without -fPIC?"),
1703+ input_bfd);
1704+ bfd_set_error (bfd_error_bad_value);
1705+ return FALSE;
1706+ }
1707+ }
1708+
1709+ loc = sreloc->contents;
1710+ loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
1711+ bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
1712+ break;
1713+ }
1714+ else
1715+ {
1716+ relocation += addend;
1717+ if (r_type == R_MICROBLAZE_32)
1718+ bfd_put_32 (input_bfd, relocation, contents + offset);
1719+ else
1720+ {
1721+ if (r_type == R_MICROBLAZE_64_PCREL)
1722+ relocation -= (input_section->output_section->vma
1723+ + input_section->output_offset
1724+ + offset + INST_WORD_SIZE);
1725+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
1726+ contents + offset + endian);
1727+ bfd_put_16 (input_bfd, relocation & 0xffff,
1728+ contents + offset + endian + INST_WORD_SIZE);
1729+ }
1730+ break;
1731+ }
1732+ }
1733+
1734+ default :
1735+ r = _bfd_final_link_relocate (howto, input_bfd, input_section,
1736+ contents, offset,
1737+ relocation, addend);
1738+ break;
1739+ }
1740+ }
1741+
1742+ check_reloc:
1743+
1744+ if (r != bfd_reloc_ok)
1745+ {
1746+ /* FIXME: This should be generic enough to go in a utility. */
1747+ const char *name;
1748+
1749+ if (h != NULL)
1750+ name = h->root.root.string;
1751+ else
1752+ {
1753+ name = (bfd_elf_string_from_elf_section
1754+ (input_bfd, symtab_hdr->sh_link, sym->st_name));
1755+ if (name == NULL || *name == '\0')
1756+ name = bfd_section_name (input_bfd, sec);
1757+ }
1758+
1759+ if (errmsg != NULL)
1760+ goto common_error;
1761+
1762+ switch (r)
1763+ {
1764+ case bfd_reloc_overflow:
1765+ (*info->callbacks->reloc_overflow)
1766+ (info, (h ? &h->root : NULL), name, howto->name,
1767+ (bfd_vma) 0, input_bfd, input_section, offset);
1768+ break;
1769+
1770+ case bfd_reloc_undefined:
1771+ (*info->callbacks->undefined_symbol)
1772+ (info, name, input_bfd, input_section, offset, TRUE);
1773+ break;
1774+
1775+ case bfd_reloc_outofrange:
1776+ errmsg = _("internal error: out of range error");
1777+ goto common_error;
1778+
1779+ case bfd_reloc_notsupported:
1780+ errmsg = _("internal error: unsupported relocation error");
1781+ goto common_error;
1782+
1783+ case bfd_reloc_dangerous:
1784+ errmsg = _("internal error: dangerous error");
1785+ goto common_error;
1786+
1787+ default:
1788+ errmsg = _("internal error: unknown error");
1789+ /* Fall through. */
1790+ common_error:
1791+ (*info->callbacks->warning) (info, errmsg, name, input_bfd,
1792+ input_section, offset);
1793+ break;
1794+ }
1795+ }
1796+ }
1797+
1798+ return ret;
1799+}
1800+
1801+/* Merge backend specific data from an object file to the output
1802+ object file when linking.
1803+
1804+ Note: We only use this hook to catch endian mismatches. */
1805+static bfd_boolean
1806+microblaze_elf_merge_private_bfd_data (bfd * ibfd, bfd * obfd)
1807+{
1808+ /* Check if we have the same endianess. */
1809+ if (! _bfd_generic_verify_endian_match (ibfd, obfd))
1810+ return FALSE;
1811+
1812+ return TRUE;
1813+}
1814+
1815+
1816+/* Calculate fixup value for reference. */
1817+
1818+static int
1819+calc_fixup (bfd_vma start, bfd_vma size, asection *sec)
1820+{
1821+ bfd_vma end = start + size;
1822+ int i, fixup = 0;
1823+
1824+ if (sec == NULL || sec->relax == NULL)
1825+ return 0;
1826+
1827+ /* Look for addr in relax table, total fixup value. */
1828+ for (i = 0; i < sec->relax_count; i++)
1829+ {
1830+ if (end <= sec->relax[i].addr)
1831+ break;
1832+ if ((end != start) && (start > sec->relax[i].addr))
1833+ continue;
1834+ fixup += sec->relax[i].size;
1835+ }
1836+ return fixup;
1837+}
1838+
1839+/* Read-modify-write into the bfd, an immediate value into appropriate fields of
1840+ a 32-bit instruction. */
1841+static void
1842+microblaze_bfd_write_imm_value_32 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
1843+{
1844+ unsigned long instr = bfd_get_32 (abfd, bfd_addr);
1845+ instr &= ~0x0000ffff;
1846+ instr |= (val & 0x0000ffff);
1847+ bfd_put_32 (abfd, instr, bfd_addr);
1848+}
1849+
1850+/* Read-modify-write into the bfd, an immediate value into appropriate fields of
1851+ two consecutive 32-bit instructions. */
1852+static void
1853+microblaze_bfd_write_imm_value_64 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
1854+{
1855+ unsigned long instr_hi;
1856+ unsigned long instr_lo;
1857+
1858+ instr_hi = bfd_get_32 (abfd, bfd_addr);
1859+ instr_hi &= ~0x0000ffff;
1860+ instr_hi |= ((val >> 16) & 0x0000ffff);
1861+ bfd_put_32 (abfd, instr_hi, bfd_addr);
1862+
1863+ instr_lo = bfd_get_32 (abfd, bfd_addr + INST_WORD_SIZE);
1864+ instr_lo &= ~0x0000ffff;
1865+ instr_lo |= (val & 0x0000ffff);
1866+ bfd_put_32 (abfd, instr_lo, bfd_addr + INST_WORD_SIZE);
1867+}
1868+
1869+static bfd_boolean
1870+microblaze_elf_relax_section (bfd *abfd,
1871+ asection *sec,
1872+ struct bfd_link_info *link_info,
1873+ bfd_boolean *again)
1874+{
1875+ Elf_Internal_Shdr *symtab_hdr;
1876+ Elf_Internal_Rela *internal_relocs;
1877+ Elf_Internal_Rela *free_relocs = NULL;
1878+ Elf_Internal_Rela *irel, *irelend;
1879+ bfd_byte *contents = NULL;
1880+ bfd_byte *free_contents = NULL;
1881+ int rel_count;
1882+ unsigned int shndx;
1883+ int i, sym_index;
1884+ asection *o;
1885+ struct elf_link_hash_entry *sym_hash;
1886+ Elf_Internal_Sym *isymbuf, *isymend;
1887+ Elf_Internal_Sym *isym;
1888+ int symcount;
1889+ int offset;
1890+ bfd_vma src, dest;
1891+
1892+ /* We only do this once per section. We may be able to delete some code
1893+ by running multiple passes, but it is not worth it. */
1894+ *again = FALSE;
1895+
1896+ /* Only do this for a text section. */
1897+ if (bfd_link_relocatable (link_info)
1898+ || (sec->flags & SEC_RELOC) == 0
1899+ || (sec->reloc_count == 0)
1900+ || (sec->flags & SEC_CODE) == 0)
1901+ return TRUE;
1902+
1903+ BFD_ASSERT ((sec->size > 0) || (sec->rawsize > 0));
1904+
1905+ /* If this is the first time we have been called for this section,
1906+ initialize the cooked size. */
1907+ if (sec->size == 0)
1908+ sec->size = sec->rawsize;
1909+
1910+ /* Get symbols for this section. */
1911+ symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1912+ isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
1913+ symcount = symtab_hdr->sh_size / sizeof (Elf64_External_Sym);
1914+ if (isymbuf == NULL)
1915+ isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, symcount,
1916+ 0, NULL, NULL, NULL);
1917+ BFD_ASSERT (isymbuf != NULL);
1918+
1919+ internal_relocs = _bfd_elf_link_read_relocs (abfd, sec, NULL, NULL, link_info->keep_memory);
1920+ if (internal_relocs == NULL)
1921+ goto error_return;
1922+ if (! link_info->keep_memory)
1923+ free_relocs = internal_relocs;
1924+
1925+ sec->relax = (struct relax_table *) bfd_malloc ((sec->reloc_count + 1)
1926+ * sizeof (struct relax_table));
1927+ if (sec->relax == NULL)
1928+ goto error_return;
1929+ sec->relax_count = 0;
1930+
1931+ irelend = internal_relocs + sec->reloc_count;
1932+ rel_count = 0;
1933+ for (irel = internal_relocs; irel < irelend; irel++, rel_count++)
1934+ {
1935+ bfd_vma symval;
1936+ if ((ELF64_R_TYPE (irel->r_info) != (int) R_MICROBLAZE_64_PCREL)
1937+ && (ELF64_R_TYPE (irel->r_info) != (int) R_MICROBLAZE_64 ))
1938+ continue; /* Can't delete this reloc. */
1939+
1940+ /* Get the section contents. */
1941+ if (contents == NULL)
1942+ {
1943+ if (elf_section_data (sec)->this_hdr.contents != NULL)
1944+ contents = elf_section_data (sec)->this_hdr.contents;
1945+ else
1946+ {
1947+ contents = (bfd_byte *) bfd_malloc (sec->size);
1948+ if (contents == NULL)
1949+ goto error_return;
1950+ free_contents = contents;
1951+
1952+ if (!bfd_get_section_contents (abfd, sec, contents,
1953+ (file_ptr) 0, sec->size))
1954+ goto error_return;
1955+ elf_section_data (sec)->this_hdr.contents = contents;
1956+ }
1957+ }
1958+
1959+ /* Get the value of the symbol referred to by the reloc. */
1960+ if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
1961+ {
1962+ /* A local symbol. */
1963+ asection *sym_sec;
1964+
1965+ isym = isymbuf + ELF64_R_SYM (irel->r_info);
1966+ if (isym->st_shndx == SHN_UNDEF)
1967+ sym_sec = bfd_und_section_ptr;
1968+ else if (isym->st_shndx == SHN_ABS)
1969+ sym_sec = bfd_abs_section_ptr;
1970+ else if (isym->st_shndx == SHN_COMMON)
1971+ sym_sec = bfd_com_section_ptr;
1972+ else
1973+ sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
1974+
1975+ symval = _bfd_elf_rela_local_sym (abfd, isym, &sym_sec, irel);
1976+ }
1977+ else
1978+ {
1979+ unsigned long indx;
1980+ struct elf_link_hash_entry *h;
1981+
1982+ indx = ELF64_R_SYM (irel->r_info) - symtab_hdr->sh_info;
1983+ h = elf_sym_hashes (abfd)[indx];
1984+ BFD_ASSERT (h != NULL);
1985+
1986+ if (h->root.type != bfd_link_hash_defined
1987+ && h->root.type != bfd_link_hash_defweak)
1988+ /* This appears to be a reference to an undefined
1989+ symbol. Just ignore it--it will be caught by the
1990+ regular reloc processing. */
1991+ continue;
1992+
1993+ symval = (h->root.u.def.value
1994+ + h->root.u.def.section->output_section->vma
1995+ + h->root.u.def.section->output_offset);
1996+ }
1997+
1998+ /* If this is a PC-relative reloc, subtract the instr offset from
1999+ the symbol value. */
2000+ if (ELF64_R_TYPE (irel->r_info) == (int) R_MICROBLAZE_64_PCREL)
2001+ {
2002+ symval = symval + irel->r_addend
2003+ - (irel->r_offset
2004+ + sec->output_section->vma
2005+ + sec->output_offset);
2006+ }
2007+ else
2008+ symval += irel->r_addend;
2009+
2010+ if ((symval & 0xffff8000) == 0)
2011+ {
2012+ /* We can delete this instruction. */
2013+ sec->relax[sec->relax_count].addr = irel->r_offset;
2014+ sec->relax[sec->relax_count].size = INST_WORD_SIZE;
2015+ sec->relax_count++;
2016+
2017+ /* Rewrite relocation type. */
2018+ switch ((enum elf_microblaze_reloc_type) ELF64_R_TYPE (irel->r_info))
2019+ {
2020+ case R_MICROBLAZE_64_PCREL:
2021+ irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
2022+ (int) R_MICROBLAZE_32_PCREL_LO);
2023+ break;
2024+ case R_MICROBLAZE_64:
2025+ irel->r_info = ELF64_R_INFO (ELF64_R_SYM (irel->r_info),
2026+ (int) R_MICROBLAZE_32_LO);
2027+ break;
2028+ default:
2029+ /* Cannot happen. */
2030+ BFD_ASSERT (FALSE);
2031+ }
2032+ }
2033+ } /* Loop through all relocations. */
2034+
2035+ /* Loop through the relocs again, and see if anything needs to change. */
2036+ if (sec->relax_count > 0)
2037+ {
2038+ shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
2039+ rel_count = 0;
2040+ sec->relax[sec->relax_count].addr = sec->size;
2041+
2042+ for (irel = internal_relocs; irel < irelend; irel++, rel_count++)
2043+ {
2044+ bfd_vma nraddr;
2045+
2046+ /* Get the new reloc address. */
2047+ nraddr = irel->r_offset - calc_fixup (irel->r_offset, 0, sec);
2048+ switch ((enum elf_microblaze_reloc_type) ELF64_R_TYPE (irel->r_info))
2049+ {
2050+ default:
2051+ break;
2052+ case R_MICROBLAZE_64_PCREL:
2053+ break;
2054+ case R_MICROBLAZE_64:
2055+ case R_MICROBLAZE_32_LO:
2056+ /* If this reloc is against a symbol defined in this
2057+ section, we must check the addend to see it will put the value in
2058+ range to be adjusted, and hence must be changed. */
2059+ if (ELF64_R_SYM (irel->r_info) < symtab_hdr->sh_info)
2060+ {
2061+ isym = isymbuf + ELF64_R_SYM (irel->r_info);
2062+ /* Only handle relocs against .text. */
2063+ if (isym->st_shndx == shndx
2064+ && ELF64_ST_TYPE (isym->st_info) == STT_SECTION)
2065+ irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
2066+ }
2067+ break;
2068+ case R_MICROBLAZE_NONE:
2069+ case R_MICROBLAZE_32_NONE:
2070+ {
2071+ /* This was a PC-relative instruction that was
2072+ completely resolved. */
2073+ int sfix, efix;
2074+ unsigned int val;
2075+ bfd_vma target_address;
2076+ target_address = irel->r_addend + irel->r_offset;
2077+ sfix = calc_fixup (irel->r_offset, 0, sec);
2078+ efix = calc_fixup (target_address, 0, sec);
2079+
2080+ /* Validate the in-band val. */
2081+ val = bfd_get_32 (abfd, contents + irel->r_offset);
2082+ if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
2083+ fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
2084+ }
2085+ irel->r_addend -= (efix - sfix);
2086+ /* Should use HOWTO. */
2087+ microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset,
2088+ irel->r_addend);
2089+ }
2090+ break;
2091+ case R_MICROBLAZE_64_NONE:
2092+ {
2093+ /* This was a PC-relative 64-bit instruction that was
2094+ completely resolved. */
2095+ int sfix, efix;
2096+ bfd_vma target_address;
2097+ target_address = irel->r_addend + irel->r_offset + INST_WORD_SIZE;
2098+ sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, 0, sec);
2099+ efix = calc_fixup (target_address, 0, sec);
2100+ irel->r_addend -= (efix - sfix);
2101+ microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset
2102+ + INST_WORD_SIZE, irel->r_addend);
2103+ }
2104+ break;
2105+ }
2106+ irel->r_offset = nraddr;
2107+ } /* Change all relocs in this section. */
2108+
2109+ /* Look through all other sections. */
2110+ for (o = abfd->sections; o != NULL; o = o->next)
2111+ {
2112+ Elf_Internal_Rela *irelocs;
2113+ Elf_Internal_Rela *irelscan, *irelscanend;
2114+ bfd_byte *ocontents;
2115+
2116+ if (o == sec
2117+ || (o->flags & SEC_RELOC) == 0
2118+ || o->reloc_count == 0)
2119+ continue;
2120+
2121+ /* We always cache the relocs. Perhaps, if info->keep_memory is
2122+ FALSE, we should free them, if we are permitted to. */
2123+
2124+ irelocs = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL, TRUE);
2125+ if (irelocs == NULL)
2126+ goto error_return;
2127+
2128+ ocontents = NULL;
2129+ irelscanend = irelocs + o->reloc_count;
2130+ for (irelscan = irelocs; irelscan < irelscanend; irelscan++)
2131+ {
2132+ if (1 && ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_NONE)
2133+ {
2134+ unsigned int val;
2135+
2136+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2137+
2138+ /* hax: We only do the following fixup for debug location lists. */
2139+ if (strcmp(".debug_loc", o->name))
2140+ continue;
2141+
2142+ /* This was a PC-relative instruction that was completely resolved. */
2143+ if (ocontents == NULL)
2144+ {
2145+ if (elf_section_data (o)->this_hdr.contents != NULL)
2146+ ocontents = elf_section_data (o)->this_hdr.contents;
2147+ else
2148+ {
2149+ /* We always cache the section contents.
2150+ Perhaps, if info->keep_memory is FALSE, we
2151+ should free them, if we are permitted to. */
2152+
2153+ if (o->rawsize == 0)
2154+ o->rawsize = o->size;
2155+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2156+ if (ocontents == NULL)
2157+ goto error_return;
2158+ if (!bfd_get_section_contents (abfd, o, ocontents,
2159+ (file_ptr) 0,
2160+ o->rawsize))
2161+ goto error_return;
2162+ elf_section_data (o)->this_hdr.contents = ocontents;
2163+ }
2164+ }
2165+
2166+ val = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2167+ if (val != irelscan->r_addend) {
2168+ fprintf(stderr, "%d: CORRUPT relax reloc! %x %lx\n", __LINE__, val, irelscan->r_addend);
2169+ }
2170+ irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
2171+ microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
2172+ irelscan->r_addend);
2173+ }
2174+ if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
2175+ {
2176+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2177+
2178+ /* Look at the reloc only if the value has been resolved. */
2179+ if (isym->st_shndx == shndx
2180+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2181+ {
2182+ if (ocontents == NULL)
2183+ {
2184+ if (elf_section_data (o)->this_hdr.contents != NULL)
2185+ ocontents = elf_section_data (o)->this_hdr.contents;
2186+ else
2187+ {
2188+ /* We always cache the section contents.
2189+ Perhaps, if info->keep_memory is FALSE, we
2190+ should free them, if we are permitted to. */
2191+ if (o->rawsize == 0)
2192+ o->rawsize = o->size;
2193+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2194+ if (ocontents == NULL)
2195+ goto error_return;
2196+ if (!bfd_get_section_contents (abfd, o, ocontents,
2197+ (file_ptr) 0,
2198+ o->rawsize))
2199+ goto error_return;
2200+ elf_section_data (o)->this_hdr.contents = ocontents;
2201+ }
2202+
2203+ }
2204+ irelscan->r_addend -= calc_fixup (irelscan->r_addend, 0, sec);
2205+ }
2206+ else if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_SYM_OP_SYM)
2207+ {
2208+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2209+
2210+ /* Look at the reloc only if the value has been resolved. */
2211+ if (ocontents == NULL)
2212+ {
2213+ if (elf_section_data (o)->this_hdr.contents != NULL)
2214+ ocontents = elf_section_data (o)->this_hdr.contents;
2215+ else
2216+ {
2217+ /* We always cache the section contents.
2218+ Perhaps, if info->keep_memory is FALSE, we
2219+ should free them, if we are permitted to. */
2220+
2221+ if (o->rawsize == 0)
2222+ o->rawsize = o->size;
2223+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2224+ if (ocontents == NULL)
2225+ goto error_return;
2226+ if (!bfd_get_section_contents (abfd, o, ocontents,
2227+ (file_ptr) 0,
2228+ o->rawsize))
2229+ goto error_return;
2230+ elf_section_data (o)->this_hdr.contents = ocontents;
2231+ }
2232+ }
2233+ irelscan->r_addend -= calc_fixup (irelscan->r_addend
2234+ + isym->st_value,
2235+ 0,
2236+ sec);
2237+ }
2238+ }
2239+ else if ((ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_PCREL_LO)
2240+ || (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32_LO))
2241+ {
2242+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2243+
2244+ /* Look at the reloc only if the value has been resolved. */
2245+ if (isym->st_shndx == shndx
2246+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2247+ {
2248+ bfd_vma immediate;
2249+ bfd_vma target_address;
2250+
2251+ if (ocontents == NULL)
2252+ {
2253+ if (elf_section_data (o)->this_hdr.contents != NULL)
2254+ ocontents = elf_section_data (o)->this_hdr.contents;
2255+ else
2256+ {
2257+ /* We always cache the section contents.
2258+ Perhaps, if info->keep_memory is FALSE, we
2259+ should free them, if we are permitted to. */
2260+ if (o->rawsize == 0)
2261+ o->rawsize = o->size;
2262+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2263+ if (ocontents == NULL)
2264+ goto error_return;
2265+ if (!bfd_get_section_contents (abfd, o, ocontents,
2266+ (file_ptr) 0,
2267+ o->rawsize))
2268+ goto error_return;
2269+ elf_section_data (o)->this_hdr.contents = ocontents;
2270+ }
2271+ }
2272+
2273+ unsigned long instr = bfd_get_32 (abfd, ocontents + irelscan->r_offset);
2274+ immediate = instr & 0x0000ffff;
2275+ target_address = immediate;
2276+ offset = calc_fixup (target_address, 0, sec);
2277+ immediate -= offset;
2278+ irelscan->r_addend -= offset;
2279+ microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
2280+ irelscan->r_addend);
2281+ }
2282+ }
2283+
2284+ if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64)
2285+ {
2286+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2287+
2288+ /* Look at the reloc only if the value has been resolved. */
2289+ if (isym->st_shndx == shndx
2290+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2291+ {
2292+ bfd_vma immediate;
2293+
2294+ if (ocontents == NULL)
2295+ {
2296+ if (elf_section_data (o)->this_hdr.contents != NULL)
2297+ ocontents = elf_section_data (o)->this_hdr.contents;
2298+ else
2299+ {
2300+ /* We always cache the section contents.
2301+ Perhaps, if info->keep_memory is FALSE, we
2302+ should free them, if we are permitted to. */
2303+
2304+ if (o->rawsize == 0)
2305+ o->rawsize = o->size;
2306+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2307+ if (ocontents == NULL)
2308+ goto error_return;
2309+ if (!bfd_get_section_contents (abfd, o, ocontents,
2310+ (file_ptr) 0,
2311+ o->rawsize))
2312+ goto error_return;
2313+ elf_section_data (o)->this_hdr.contents = ocontents;
2314+ }
2315+ }
2316+ unsigned long instr_hi = bfd_get_32 (abfd, ocontents
2317+ + irelscan->r_offset);
2318+ unsigned long instr_lo = bfd_get_32 (abfd, ocontents
2319+ + irelscan->r_offset
2320+ + INST_WORD_SIZE);
2321+ immediate = (instr_hi & 0x0000ffff) << 16;
2322+ immediate |= (instr_lo & 0x0000ffff);
2323+ offset = calc_fixup (irelscan->r_addend, 0, sec);
2324+ immediate -= offset;
2325+ irelscan->r_addend -= offset;
2326+ }
2327+ }
2328+ else if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_64_PCREL)
2329+ {
2330+ isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
2331+
2332+ /* Look at the reloc only if the value has been resolved. */
2333+ if (isym->st_shndx == shndx
2334+ && (ELF64_ST_TYPE (isym->st_info) == STT_SECTION))
2335+ {
2336+ bfd_vma immediate;
2337+ bfd_vma target_address;
2338+
2339+ if (ocontents == NULL)
2340+ {
2341+ if (elf_section_data (o)->this_hdr.contents != NULL)
2342+ ocontents = elf_section_data (o)->this_hdr.contents;
2343+ else
2344+ {
2345+ /* We always cache the section contents.
2346+ Perhaps, if info->keep_memory is FALSE, we
2347+ should free them, if we are permitted to. */
2348+ if (o->rawsize == 0)
2349+ o->rawsize = o->size;
2350+ ocontents = (bfd_byte *) bfd_malloc (o->rawsize);
2351+ if (ocontents == NULL)
2352+ goto error_return;
2353+ if (!bfd_get_section_contents (abfd, o, ocontents,
2354+ (file_ptr) 0,
2355+ o->rawsize))
2356+ goto error_return;
2357+ elf_section_data (o)->this_hdr.contents = ocontents;
2358+ }
2359+ }
2360+ unsigned long instr_hi = bfd_get_32 (abfd, ocontents
2361+ + irelscan->r_offset);
2362+ unsigned long instr_lo = bfd_get_32 (abfd, ocontents
2363+ + irelscan->r_offset
2364+ + INST_WORD_SIZE);
2365+ immediate = (instr_hi & 0x0000ffff) << 16;
2366+ immediate |= (instr_lo & 0x0000ffff);
2367+ target_address = immediate;
2368+ offset = calc_fixup (target_address, 0, sec);
2369+ immediate -= offset;
2370+ irelscan->r_addend -= offset;
2371+ microblaze_bfd_write_imm_value_64 (abfd, ocontents
2372+ + irelscan->r_offset, immediate);
2373+ }
2374+ }
2375+ }
2376+ }
2377+
2378+ /* Adjust the local symbols defined in this section. */
2379+ isymend = isymbuf + symtab_hdr->sh_info;
2380+ for (isym = isymbuf; isym < isymend; isym++)
2381+ {
2382+ if (isym->st_shndx == shndx)
2383+ {
2384+ isym->st_value -= calc_fixup (isym->st_value, 0, sec);
2385+ if (isym->st_size)
2386+ isym->st_size -= calc_fixup (isym->st_value, isym->st_size, sec);
2387+ }
2388+ }
2389+
2390+ /* Now adjust the global symbols defined in this section. */
2391+ isym = isymbuf + symtab_hdr->sh_info;
2392+ symcount = (symtab_hdr->sh_size / sizeof (Elf64_External_Sym)) - symtab_hdr->sh_info;
2393+ for (sym_index = 0; sym_index < symcount; sym_index++)
2394+ {
2395+ sym_hash = elf_sym_hashes (abfd)[sym_index];
2396+ if ((sym_hash->root.type == bfd_link_hash_defined
2397+ || sym_hash->root.type == bfd_link_hash_defweak)
2398+ && sym_hash->root.u.def.section == sec)
2399+ {
2400+ sym_hash->root.u.def.value -= calc_fixup (sym_hash->root.u.def.value,
2401+ 0, sec);
2402+ if (sym_hash->size)
2403+ sym_hash->size -= calc_fixup (sym_hash->root.u.def.value,
2404+ sym_hash->size, sec);
2405+ }
2406+ }
2407+
2408+ /* Physically move the code and change the cooked size. */
2409+ dest = sec->relax[0].addr;
2410+ for (i = 0; i < sec->relax_count; i++)
2411+ {
2412+ int len;
2413+ src = sec->relax[i].addr + sec->relax[i].size;
2414+ len = sec->relax[i+1].addr - sec->relax[i].addr - sec->relax[i].size;
2415+
2416+ memmove (contents + dest, contents + src, len);
2417+ sec->size -= sec->relax[i].size;
2418+ dest += len;
2419+ }
2420+
2421+ elf_section_data (sec)->relocs = internal_relocs;
2422+ free_relocs = NULL;
2423+
2424+ elf_section_data (sec)->this_hdr.contents = contents;
2425+ free_contents = NULL;
2426+
2427+ symtab_hdr->contents = (bfd_byte *) isymbuf;
2428+ }
2429+
2430+ if (free_relocs != NULL)
2431+ {
2432+ free (free_relocs);
2433+ free_relocs = NULL;
2434+ }
2435+
2436+ if (free_contents != NULL)
2437+ {
2438+ if (!link_info->keep_memory)
2439+ free (free_contents);
2440+ else
2441+ /* Cache the section contents for elf_link_input_bfd. */
2442+ elf_section_data (sec)->this_hdr.contents = contents;
2443+ free_contents = NULL;
2444+ }
2445+
2446+ if (sec->relax_count == 0)
2447+ {
2448+ *again = FALSE;
2449+ free (sec->relax);
2450+ sec->relax = NULL;
2451+ }
2452+ else
2453+ *again = TRUE;
2454+ return TRUE;
2455+
2456+ error_return:
2457+ if (free_relocs != NULL)
2458+ free (free_relocs);
2459+ if (free_contents != NULL)
2460+ free (free_contents);
2461+ if (sec->relax != NULL)
2462+ {
2463+ free (sec->relax);
2464+ sec->relax = NULL;
2465+ sec->relax_count = 0;
2466+ }
2467+ return FALSE;
2468+}
2469+
2470+/* Return the section that should be marked against GC for a given
2471+ relocation. */
2472+
2473+static asection *
2474+microblaze_elf_gc_mark_hook (asection *sec,
2475+ struct bfd_link_info * info,
2476+ Elf_Internal_Rela * rel,
2477+ struct elf_link_hash_entry * h,
2478+ Elf_Internal_Sym * sym)
2479+{
2480+ if (h != NULL)
2481+ switch (ELF64_R_TYPE (rel->r_info))
2482+ {
2483+ case R_MICROBLAZE_GNU_VTINHERIT:
2484+ case R_MICROBLAZE_GNU_VTENTRY:
2485+ return NULL;
2486+ }
2487+
2488+ return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2489+}
2490+
2491+/* Update the got entry reference counts for the section being removed. */
2492+
2493+static bfd_boolean
2494+microblaze_elf_gc_sweep_hook (bfd * abfd ATTRIBUTE_UNUSED,
2495+ struct bfd_link_info * info ATTRIBUTE_UNUSED,
2496+ asection * sec ATTRIBUTE_UNUSED,
2497+ const Elf_Internal_Rela * relocs ATTRIBUTE_UNUSED)
2498+{
2499+ return TRUE;
2500+}
2501+
2502+/* PIC support. */
2503+
2504+#define PLT_ENTRY_SIZE 16
2505+
2506+#define PLT_ENTRY_WORD_0 0xb0000000 /* "imm 0". */
2507+#define PLT_ENTRY_WORD_1 0xe9940000 /* "lwi r12,r20,0" - relocated to lwi r12,r20,func@GOT. */
2508+#define PLT_ENTRY_WORD_1_NOPIC 0xe9800000 /* "lwi r12,r0,0" - non-PIC object. */
2509+#define PLT_ENTRY_WORD_2 0x98186000 /* "brad r12". */
2510+#define PLT_ENTRY_WORD_3 0x80000000 /* "nop". */
2511+
2512+/* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up
2513+ shortcuts to them in our hash table. */
2514+
2515+static bfd_boolean
2516+create_got_section (bfd *dynobj, struct bfd_link_info *info)
2517+{
2518+ struct elf64_mb_link_hash_table *htab;
2519+
2520+ if (! _bfd_elf_create_got_section (dynobj, info))
2521+ return FALSE;
2522+ htab = elf64_mb_hash_table (info);
2523+ if (htab == NULL)
2524+ return FALSE;
2525+
2526+ htab->sgot = bfd_get_linker_section (dynobj, ".got");
2527+ htab->sgotplt = bfd_get_linker_section (dynobj, ".got.plt");
2528+ if (!htab->sgot || !htab->sgotplt)
2529+ return FALSE;
2530+
2531+ if ((htab->srelgot = bfd_get_linker_section (dynobj, ".rela.got")) == NULL)
2532+ htab->srelgot = bfd_make_section_anyway (dynobj, ".rela.got");
2533+ if (htab->srelgot == NULL
2534+ || ! bfd_set_section_flags (dynobj, htab->srelgot, SEC_ALLOC
2535+ | SEC_LOAD
2536+ | SEC_HAS_CONTENTS
2537+ | SEC_IN_MEMORY
2538+ | SEC_LINKER_CREATED
2539+ | SEC_READONLY)
2540+ || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2))
2541+ return FALSE;
2542+ return TRUE;
2543+}
2544+
2545+static bfd_boolean
2546+update_local_sym_info (bfd *abfd,
2547+ Elf_Internal_Shdr *symtab_hdr,
2548+ unsigned long r_symndx,
2549+ unsigned int tls_type)
2550+{
2551+ bfd_signed_vma *local_got_refcounts = elf_local_got_refcounts (abfd);
2552+ unsigned char *local_got_tls_masks;
2553+
2554+ if (local_got_refcounts == NULL)
2555+ {
2556+ bfd_size_type size = symtab_hdr->sh_info;
2557+
2558+ size *= (sizeof (*local_got_refcounts) + sizeof (*local_got_tls_masks));
2559+ local_got_refcounts = bfd_zalloc (abfd, size);
2560+ if (local_got_refcounts == NULL)
2561+ return FALSE;
2562+ elf_local_got_refcounts (abfd) = local_got_refcounts;
2563+ }
2564+
2565+ local_got_tls_masks =
2566+ (unsigned char *) (local_got_refcounts + symtab_hdr->sh_info);
2567+ local_got_tls_masks[r_symndx] |= tls_type;
2568+ local_got_refcounts[r_symndx] += 1;
2569+
2570+ return TRUE;
2571+}
2572+/* Look through the relocs for a section during the first phase. */
2573+
2574+static bfd_boolean
2575+microblaze_elf_check_relocs (bfd * abfd,
2576+ struct bfd_link_info * info,
2577+ asection * sec,
2578+ const Elf_Internal_Rela * relocs)
2579+{
2580+ Elf_Internal_Shdr * symtab_hdr;
2581+ struct elf_link_hash_entry ** sym_hashes;
2582+ struct elf_link_hash_entry ** sym_hashes_end;
2583+ const Elf_Internal_Rela * rel;
2584+ const Elf_Internal_Rela * rel_end;
2585+ struct elf64_mb_link_hash_table *htab;
2586+ asection *sreloc = NULL;
2587+
2588+ if (bfd_link_relocatable (info))
2589+ return TRUE;
2590+
2591+ htab = elf64_mb_hash_table (info);
2592+ if (htab == NULL)
2593+ return FALSE;
2594+
2595+ symtab_hdr = & elf_tdata (abfd)->symtab_hdr;
2596+ sym_hashes = elf_sym_hashes (abfd);
2597+ sym_hashes_end = sym_hashes + symtab_hdr->sh_size / sizeof (Elf64_External_Sym);
2598+ if (!elf_bad_symtab (abfd))
2599+ sym_hashes_end -= symtab_hdr->sh_info;
2600+
2601+ rel_end = relocs + sec->reloc_count;
2602+
2603+ for (rel = relocs; rel < rel_end; rel++)
2604+ {
2605+ unsigned int r_type;
2606+ struct elf_link_hash_entry * h;
2607+ unsigned long r_symndx;
2608+ unsigned char tls_type = 0;
2609+
2610+ r_symndx = ELF64_R_SYM (rel->r_info);
2611+ r_type = ELF64_R_TYPE (rel->r_info);
2612+
2613+ if (r_symndx < symtab_hdr->sh_info)
2614+ h = NULL;
2615+ else
2616+ {
2617+ h = sym_hashes [r_symndx - symtab_hdr->sh_info];
2618+
2619+ /* PR15323, ref flags aren't set for references in the same
2620+ object. */
2621+ h->root.non_ir_ref = 1;
2622+ }
2623+
2624+ switch (r_type)
2625+ {
2626+ /* This relocation describes the C++ object vtable hierarchy.
2627+ Reconstruct it for later use during GC. */
2628+ case R_MICROBLAZE_GNU_VTINHERIT:
2629+ if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2630+ return FALSE;
2631+ break;
2632+
2633+ /* This relocation describes which C++ vtable entries are actually
2634+ used. Record for later use during GC. */
2635+ case R_MICROBLAZE_GNU_VTENTRY:
2636+ if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2637+ return FALSE;
2638+ break;
2639+
2640+ /* This relocation requires .plt entry. */
2641+ case R_MICROBLAZE_PLT_64:
2642+ if (h != NULL)
2643+ {
2644+ h->needs_plt = 1;
2645+ h->plt.refcount += 1;
2646+ }
2647+ break;
2648+
2649+ /* This relocation requires .got entry. */
2650+ case R_MICROBLAZE_TLSGD:
2651+ tls_type |= (TLS_TLS | TLS_GD);
2652+ goto dogottls;
2653+ case R_MICROBLAZE_TLSLD:
2654+ tls_type |= (TLS_TLS | TLS_LD);
2655+ dogottls:
2656+ sec->has_tls_reloc = 1;
2657+ case R_MICROBLAZE_GOT_64:
2658+ if (htab->sgot == NULL)
2659+ {
2660+ if (htab->elf.dynobj == NULL)
2661+ htab->elf.dynobj = abfd;
2662+ if (!create_got_section (htab->elf.dynobj, info))
2663+ return FALSE;
2664+ }
2665+ if (h != NULL)
2666+ {
2667+ h->got.refcount += 1;
2668+ elf64_mb_hash_entry (h)->tls_mask |= tls_type;
2669+ }
2670+ else
2671+ {
2672+ if (! update_local_sym_info(abfd, symtab_hdr, r_symndx, tls_type) )
2673+ return FALSE;
2674+ }
2675+ break;
2676+
2677+ case R_MICROBLAZE_64:
2678+ case R_MICROBLAZE_64_PCREL:
2679+ case R_MICROBLAZE_32:
2680+ {
2681+ if (h != NULL && !bfd_link_pic (info))
2682+ {
2683+ /* we may need a copy reloc. */
2684+ h->non_got_ref = 1;
2685+
2686+ /* we may also need a .plt entry. */
2687+ h->plt.refcount += 1;
2688+ if (ELF64_R_TYPE (rel->r_info) != R_MICROBLAZE_64_PCREL)
2689+ h->pointer_equality_needed = 1;
2690+ }
2691+
2692+
2693+ /* If we are creating a shared library, and this is a reloc
2694+ against a global symbol, or a non PC relative reloc
2695+ against a local symbol, then we need to copy the reloc
2696+ into the shared library. However, if we are linking with
2697+ -Bsymbolic, we do not need to copy a reloc against a
2698+ global symbol which is defined in an object we are
2699+ including in the link (i.e., DEF_REGULAR is set). At
2700+ this point we have not seen all the input files, so it is
2701+ possible that DEF_REGULAR is not set now but will be set
2702+ later (it is never cleared). In case of a weak definition,
2703+ DEF_REGULAR may be cleared later by a strong definition in
2704+ a shared library. We account for that possibility below by
2705+ storing information in the relocs_copied field of the hash
2706+ table entry. A similar situation occurs when creating
2707+ shared libraries and symbol visibility changes render the
2708+ symbol local.
2709+
2710+ If on the other hand, we are creating an executable, we
2711+ may need to keep relocations for symbols satisfied by a
2712+ dynamic library if we manage to avoid copy relocs for the
2713+ symbol. */
2714+
2715+ if ((bfd_link_pic (info)
2716+ && (sec->flags & SEC_ALLOC) != 0
2717+ && (r_type != R_MICROBLAZE_64_PCREL
2718+ || (h != NULL
2719+ && (! info->symbolic
2720+ || h->root.type == bfd_link_hash_defweak
2721+ || !h->def_regular))))
2722+ || (!bfd_link_pic (info)
2723+ && (sec->flags & SEC_ALLOC) != 0
2724+ && h != NULL
2725+ && (h->root.type == bfd_link_hash_defweak
2726+ || !h->def_regular)))
2727+ {
2728+ struct elf64_mb_dyn_relocs *p;
2729+ struct elf64_mb_dyn_relocs **head;
2730+
2731+ /* When creating a shared object, we must copy these
2732+ relocs into the output file. We create a reloc
2733+ section in dynobj and make room for the reloc. */
2734+
2735+ if (sreloc == NULL)
2736+ {
2737+ bfd *dynobj;
2738+
2739+ if (htab->elf.dynobj == NULL)
2740+ htab->elf.dynobj = abfd;
2741+ dynobj = htab->elf.dynobj;
2742+
2743+ sreloc = _bfd_elf_make_dynamic_reloc_section (sec, dynobj,
2744+ 2, abfd, 1);
2745+ if (sreloc == NULL)
2746+ return FALSE;
2747+ }
2748+
2749+ /* If this is a global symbol, we count the number of
2750+ relocations we need for this symbol. */
2751+ if (h != NULL)
2752+ head = &((struct elf64_mb_link_hash_entry *) h)->dyn_relocs;
2753+ else
2754+ {
2755+ /* Track dynamic relocs needed for local syms too.
2756+ We really need local syms available to do this
2757+ easily. Oh well. */
2758+
2759+ asection *s;
2760+ Elf_Internal_Sym *isym;
2761+ void *vpp;
2762+
2763+ isym = bfd_sym_from_r_symndx (&htab->sym_sec,
2764+ abfd, r_symndx);
2765+ if (isym == NULL)
2766+ return FALSE;
2767+
2768+ s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2769+ if (s == NULL)
2770+ return FALSE;
2771+
2772+ vpp = &elf_section_data (s)->local_dynrel;
2773+ head = (struct elf64_mb_dyn_relocs **) vpp;
2774+ }
2775+
2776+ p = *head;
2777+ if (p == NULL || p->sec != sec)
2778+ {
2779+ bfd_size_type amt = sizeof *p;
2780+ p = ((struct elf64_mb_dyn_relocs *)
2781+ bfd_alloc (htab->elf.dynobj, amt));
2782+ if (p == NULL)
2783+ return FALSE;
2784+ p->next = *head;
2785+ *head = p;
2786+ p->sec = sec;
2787+ p->count = 0;
2788+ p->pc_count = 0;
2789+ }
2790+
2791+ p->count += 1;
2792+ if (r_type == R_MICROBLAZE_64_PCREL)
2793+ p->pc_count += 1;
2794+ }
2795+ }
2796+ break;
2797+ }
2798+ }
2799+
2800+ return TRUE;
2801+}
2802+
2803+static bfd_boolean
2804+microblaze_elf_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
2805+{
2806+ struct elf64_mb_link_hash_table *htab;
2807+
2808+ htab = elf64_mb_hash_table (info);
2809+ if (htab == NULL)
2810+ return FALSE;
2811+
2812+ if (!htab->sgot && !create_got_section (dynobj, info))
2813+ return FALSE;
2814+
2815+ if (!_bfd_elf_create_dynamic_sections (dynobj, info))
2816+ return FALSE;
2817+
2818+ htab->splt = bfd_get_linker_section (dynobj, ".plt");
2819+ htab->srelplt = bfd_get_linker_section (dynobj, ".rela.plt");
2820+ htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss");
2821+ if (!bfd_link_pic (info))
2822+ htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss");
2823+
2824+ if (!htab->splt || !htab->srelplt || !htab->sdynbss
2825+ || (!bfd_link_pic (info) && !htab->srelbss))
2826+ abort ();
2827+
2828+ return TRUE;
2829+}
2830+
2831+/* Copy the extra info we tack onto an elf_link_hash_entry. */
2832+
2833+static void
2834+microblaze_elf_copy_indirect_symbol (struct bfd_link_info *info,
2835+ struct elf_link_hash_entry *dir,
2836+ struct elf_link_hash_entry *ind)
2837+{
2838+ struct elf64_mb_link_hash_entry *edir, *eind;
2839+
2840+ edir = (struct elf64_mb_link_hash_entry *) dir;
2841+ eind = (struct elf64_mb_link_hash_entry *) ind;
2842+
2843+ if (eind->dyn_relocs != NULL)
2844+ {
2845+ if (edir->dyn_relocs != NULL)
2846+ {
2847+ struct elf64_mb_dyn_relocs **pp;
2848+ struct elf64_mb_dyn_relocs *p;
2849+
2850+ if (ind->root.type == bfd_link_hash_indirect)
2851+ abort ();
2852+
2853+ /* Add reloc counts against the weak sym to the strong sym
2854+ list. Merge any entries against the same section. */
2855+ for (pp = &eind->dyn_relocs; (p = *pp) != NULL; )
2856+ {
2857+ struct elf64_mb_dyn_relocs *q;
2858+
2859+ for (q = edir->dyn_relocs; q != NULL; q = q->next)
2860+ if (q->sec == p->sec)
2861+ {
2862+ q->pc_count += p->pc_count;
2863+ q->count += p->count;
2864+ *pp = p->next;
2865+ break;
2866+ }
2867+ if (q == NULL)
2868+ pp = &p->next;
2869+ }
2870+ *pp = edir->dyn_relocs;
2871+ }
2872+
2873+ edir->dyn_relocs = eind->dyn_relocs;
2874+ eind->dyn_relocs = NULL;
2875+ }
2876+
2877+ edir->tls_mask |= eind->tls_mask;
2878+
2879+ _bfd_elf_link_hash_copy_indirect (info, dir, ind);
2880+}
2881+
2882+static bfd_boolean
2883+microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
2884+ struct elf_link_hash_entry *h)
2885+{
2886+ struct elf64_mb_link_hash_table *htab;
2887+ struct elf64_mb_link_hash_entry * eh;
2888+ struct elf64_mb_dyn_relocs *p;
2889+ asection *sdynbss, *s;
2890+ unsigned int power_of_two;
2891+ bfd *dynobj;
2892+
2893+ htab = elf64_mb_hash_table (info);
2894+ if (htab == NULL)
2895+ return FALSE;
2896+
2897+ /* If this is a function, put it in the procedure linkage table. We
2898+ will fill in the contents of the procedure linkage table later,
2899+ when we know the address of the .got section. */
2900+ if (h->type == STT_FUNC
2901+ || h->needs_plt)
2902+ {
2903+ if (h->plt.refcount <= 0
2904+ || SYMBOL_CALLS_LOCAL (info, h)
2905+ || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2906+ && h->root.type == bfd_link_hash_undefweak))
2907+ {
2908+ /* This case can occur if we saw a PLT reloc in an input
2909+ file, but the symbol was never referred to by a dynamic
2910+ object, or if all references were garbage collected. In
2911+ such a case, we don't actually need to build a procedure
2912+ linkage table, and we can just do a PC32 reloc instead. */
2913+ h->plt.offset = (bfd_vma) -1;
2914+ h->needs_plt = 0;
2915+ }
2916+
2917+ return TRUE;
2918+ }
2919+ else
2920+ /* It's possible that we incorrectly decided a .plt reloc was
2921+ needed for an R_MICROBLAZE_64_PCREL reloc to a non-function sym in
2922+ check_relocs. We can't decide accurately between function and
2923+ non-function syms in check-relocs; Objects loaded later in
2924+ the link may change h->type. So fix it now. */
2925+ h->plt.offset = (bfd_vma) -1;
2926+
2927+ /* If this is a weak symbol, and there is a real definition, the
2928+ processor independent code will have arranged for us to see the
2929+ real definition first, and we can just use the same value. */
2930+ if (h->u.weakdef != NULL)
2931+ {
2932+ BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
2933+ || h->u.weakdef->root.type == bfd_link_hash_defweak);
2934+ h->root.u.def.section = h->u.weakdef->root.u.def.section;
2935+ h->root.u.def.value = h->u.weakdef->root.u.def.value;
2936+ return TRUE;
2937+ }
2938+
2939+ /* This is a reference to a symbol defined by a dynamic object which
2940+ is not a function. */
2941+
2942+ /* If we are creating a shared library, we must presume that the
2943+ only references to the symbol are via the global offset table.
2944+ For such cases we need not do anything here; the relocations will
2945+ be handled correctly by relocate_section. */
2946+ if (bfd_link_pic (info))
2947+ return TRUE;
2948+
2949+ /* If there are no references to this symbol that do not use the
2950+ GOT, we don't need to generate a copy reloc. */
2951+ if (!h->non_got_ref)
2952+ return TRUE;
2953+
2954+ /* If -z nocopyreloc was given, we won't generate them either. */
2955+ if (info->nocopyreloc)
2956+ {
2957+ h->non_got_ref = 0;
2958+ return TRUE;
2959+ }
2960+
2961+ eh = (struct elf64_mb_link_hash_entry *) h;
2962+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
2963+ {
2964+ s = p->sec->output_section;
2965+ if (s != NULL && (s->flags & SEC_READONLY) != 0)
2966+ break;
2967+ }
2968+
2969+ /* If we didn't find any dynamic relocs in read-only sections, then
2970+ we'll be keeping the dynamic relocs and avoiding the copy reloc. */
2971+ if (p == NULL)
2972+ {
2973+ h->non_got_ref = 0;
2974+ return TRUE;
2975+ }
2976+
2977+ /* We must allocate the symbol in our .dynbss section, which will
2978+ become part of the .bss section of the executable. There will be
2979+ an entry for this symbol in the .dynsym section. The dynamic
2980+ object will contain position independent code, so all references
2981+ from the dynamic object to this symbol will go through the global
2982+ offset table. The dynamic linker will use the .dynsym entry to
2983+ determine the address it must put in the global offset table, so
2984+ both the dynamic object and the regular object will refer to the
2985+ same memory location for the variable. */
2986+
2987+ /* We must generate a R_MICROBLAZE_COPY reloc to tell the dynamic linker
2988+ to copy the initial value out of the dynamic object and into the
2989+ runtime process image. */
2990+ dynobj = elf_hash_table (info)->dynobj;
2991+ BFD_ASSERT (dynobj != NULL);
2992+ if ((h->root.u.def.section->flags & SEC_ALLOC) != 0)
2993+ {
2994+ htab->srelbss->size += sizeof (Elf64_External_Rela);
2995+ h->needs_copy = 1;
2996+ }
2997+
2998+ /* We need to figure out the alignment required for this symbol. I
2999+ have no idea how ELF linkers handle this. */
3000+ power_of_two = bfd_log2 (h->size);
3001+ if (power_of_two > 3)
3002+ power_of_two = 3;
3003+
3004+ sdynbss = htab->sdynbss;
3005+ /* Apply the required alignment. */
3006+ sdynbss->size = BFD_ALIGN (sdynbss->size, (bfd_size_type) (1 << power_of_two));
3007+ if (power_of_two > bfd_get_section_alignment (dynobj, sdynbss))
3008+ {
3009+ if (! bfd_set_section_alignment (dynobj, sdynbss, power_of_two))
3010+ return FALSE;
3011+ }
3012+
3013+ /* Define the symbol as being at this point in the section. */
3014+ h->root.u.def.section = sdynbss;
3015+ h->root.u.def.value = sdynbss->size;
3016+
3017+ /* Increment the section size to make room for the symbol. */
3018+ sdynbss->size += h->size;
3019+ return TRUE;
3020+}
3021+
3022+/* Allocate space in .plt, .got and associated reloc sections for
3023+ dynamic relocs. */
3024+
3025+static bfd_boolean
3026+allocate_dynrelocs (struct elf_link_hash_entry *h, void * dat)
3027+{
3028+ struct bfd_link_info *info;
3029+ struct elf64_mb_link_hash_table *htab;
3030+ struct elf64_mb_link_hash_entry *eh;
3031+ struct elf64_mb_dyn_relocs *p;
3032+
3033+ if (h->root.type == bfd_link_hash_indirect)
3034+ return TRUE;
3035+
3036+ info = (struct bfd_link_info *) dat;
3037+ htab = elf64_mb_hash_table (info);
3038+ if (htab == NULL)
3039+ return FALSE;
3040+
3041+ if (htab->elf.dynamic_sections_created
3042+ && h->plt.refcount > 0)
3043+ {
3044+ /* Make sure this symbol is output as a dynamic symbol.
3045+ Undefined weak syms won't yet be marked as dynamic. */
3046+ if (h->dynindx == -1
3047+ && !h->forced_local)
3048+ {
3049+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
3050+ return FALSE;
3051+ }
3052+
3053+ if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, bfd_link_pic (info), h))
3054+ {
3055+ asection *s = htab->splt;
3056+
3057+ /* The first entry in .plt is reserved. */
3058+ if (s->size == 0)
3059+ s->size = PLT_ENTRY_SIZE;
3060+
3061+ h->plt.offset = s->size;
3062+
3063+ /* If this symbol is not defined in a regular file, and we are
3064+ not generating a shared library, then set the symbol to this
3065+ location in the .plt. This is required to make function
3066+ pointers compare as equal between the normal executable and
3067+ the shared library. */
3068+ if (! bfd_link_pic (info)
3069+ && !h->def_regular)
3070+ {
3071+ h->root.u.def.section = s;
3072+ h->root.u.def.value = h->plt.offset;
3073+ }
3074+
3075+ /* Make room for this entry. */
3076+ s->size += PLT_ENTRY_SIZE;
3077+
3078+ /* We also need to make an entry in the .got.plt section, which
3079+ will be placed in the .got section by the linker script. */
3080+ htab->sgotplt->size += 4;
3081+
3082+ /* We also need to make an entry in the .rel.plt section. */
3083+ htab->srelplt->size += sizeof (Elf64_External_Rela);
3084+ }
3085+ else
3086+ {
3087+ h->plt.offset = (bfd_vma) -1;
3088+ h->needs_plt = 0;
3089+ }
3090+ }
3091+ else
3092+ {
3093+ h->plt.offset = (bfd_vma) -1;
3094+ h->needs_plt = 0;
3095+ }
3096+
3097+ eh = (struct elf64_mb_link_hash_entry *) h;
3098+ if (h->got.refcount > 0)
3099+ {
3100+ unsigned int need;
3101+ asection *s;
3102+
3103+ /* Make sure this symbol is output as a dynamic symbol.
3104+ Undefined weak syms won't yet be marked as dynamic. */
3105+ if (h->dynindx == -1
3106+ && !h->forced_local)
3107+ {
3108+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
3109+ return FALSE;
3110+ }
3111+
3112+ need = 0;
3113+ if ((eh->tls_mask & TLS_TLS) != 0)
3114+ {
3115+ /* Handle TLS Symbol */
3116+ if ((eh->tls_mask & TLS_LD) != 0)
3117+ {
3118+ if (!eh->elf.def_dynamic)
3119+ /* We'll just use htab->tlsld_got.offset. This should
3120+ always be the case. It's a little odd if we have
3121+ a local dynamic reloc against a non-local symbol. */
3122+ htab->tlsld_got.refcount += 1;
3123+ else
3124+ need += 8;
3125+ }
3126+ if ((eh->tls_mask & TLS_GD) != 0)
3127+ need += 8;
3128+ }
3129+ else
3130+ {
3131+ /* Regular (non-TLS) symbol */
3132+ need += 4;
3133+ }
3134+ if (need == 0)
3135+ {
3136+ h->got.offset = (bfd_vma) -1;
3137+ }
3138+ else
3139+ {
3140+ s = htab->sgot;
3141+ h->got.offset = s->size;
3142+ s->size += need;
3143+ htab->srelgot->size += need * (sizeof (Elf64_External_Rela) / 4);
3144+ }
3145+ }
3146+ else
3147+ h->got.offset = (bfd_vma) -1;
3148+
3149+ if (eh->dyn_relocs == NULL)
3150+ return TRUE;
3151+
3152+ /* In the shared -Bsymbolic case, discard space allocated for
3153+ dynamic pc-relative relocs against symbols which turn out to be
3154+ defined in regular objects. For the normal shared case, discard
3155+ space for pc-relative relocs that have become local due to symbol
3156+ visibility changes. */
3157+
3158+ if (bfd_link_pic (info))
3159+ {
3160+ if (h->def_regular
3161+ && (h->forced_local
3162+ || info->symbolic))
3163+ {
3164+ struct elf64_mb_dyn_relocs **pp;
3165+
3166+ for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
3167+ {
3168+ p->count -= p->pc_count;
3169+ p->pc_count = 0;
3170+ if (p->count == 0)
3171+ *pp = p->next;
3172+ else
3173+ pp = &p->next;
3174+ }
3175+ }
3176+ }
3177+ else
3178+ {
3179+ /* For the non-shared case, discard space for relocs against
3180+ symbols which turn out to need copy relocs or are not
3181+ dynamic. */
3182+
3183+ if (!h->non_got_ref
3184+ && ((h->def_dynamic
3185+ && !h->def_regular)
3186+ || (htab->elf.dynamic_sections_created
3187+ && (h->root.type == bfd_link_hash_undefweak
3188+ || h->root.type == bfd_link_hash_undefined))))
3189+ {
3190+ /* Make sure this symbol is output as a dynamic symbol.
3191+ Undefined weak syms won't yet be marked as dynamic. */
3192+ if (h->dynindx == -1
3193+ && !h->forced_local)
3194+ {
3195+ if (! bfd_elf_link_record_dynamic_symbol (info, h))
3196+ return FALSE;
3197+ }
3198+
3199+ /* If that succeeded, we know we'll be keeping all the
3200+ relocs. */
3201+ if (h->dynindx != -1)
3202+ goto keep;
3203+ }
3204+
3205+ eh->dyn_relocs = NULL;
3206+
3207+ keep: ;
3208+ }
3209+
3210+ /* Finally, allocate space. */
3211+ for (p = eh->dyn_relocs; p != NULL; p = p->next)
3212+ {
3213+ asection *sreloc = elf_section_data (p->sec)->sreloc;
3214+ sreloc->size += p->count * sizeof (Elf64_External_Rela);
3215+ }
3216+
3217+ return TRUE;
3218+}
3219+
3220+/* Set the sizes of the dynamic sections. */
3221+
3222+static bfd_boolean
3223+microblaze_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3224+ struct bfd_link_info *info)
3225+{
3226+ struct elf64_mb_link_hash_table *htab;
3227+ bfd *dynobj;
3228+ asection *s;
3229+ bfd *ibfd;
3230+
3231+ htab = elf64_mb_hash_table (info);
3232+ if (htab == NULL)
3233+ return FALSE;
3234+
3235+ dynobj = htab->elf.dynobj;
3236+ BFD_ASSERT (dynobj != NULL);
3237+
3238+ /* Set up .got offsets for local syms, and space for local dynamic
3239+ relocs. */
3240+ for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3241+ {
3242+ bfd_signed_vma *local_got;
3243+ bfd_signed_vma *end_local_got;
3244+ bfd_size_type locsymcount;
3245+ Elf_Internal_Shdr *symtab_hdr;
3246+ unsigned char *lgot_masks;
3247+ asection *srel;
3248+
3249+ if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
3250+ continue;
3251+
3252+ for (s = ibfd->sections; s != NULL; s = s->next)
3253+ {
3254+ struct elf64_mb_dyn_relocs *p;
3255+
3256+ for (p = ((struct elf64_mb_dyn_relocs *)
3257+ elf_section_data (s)->local_dynrel);
3258+ p != NULL;
3259+ p = p->next)
3260+ {
3261+ if (!bfd_is_abs_section (p->sec)
3262+ && bfd_is_abs_section (p->sec->output_section))
3263+ {
3264+ /* Input section has been discarded, either because
3265+ it is a copy of a linkonce section or due to
3266+ linker script /DISCARD/, so we'll be discarding
3267+ the relocs too. */
3268+ }
3269+ else if (p->count != 0)
3270+ {
3271+ srel = elf_section_data (p->sec)->sreloc;
3272+ srel->size += p->count * sizeof (Elf64_External_Rela);
3273+ if ((p->sec->output_section->flags & SEC_READONLY) != 0)
3274+ info->flags |= DF_TEXTREL;
3275+ }
3276+ }
3277+ }
3278+
3279+ local_got = elf_local_got_refcounts (ibfd);
3280+ if (!local_got)
3281+ continue;
3282+
3283+ symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
3284+ locsymcount = symtab_hdr->sh_info;
3285+ end_local_got = local_got + locsymcount;
3286+ lgot_masks = (unsigned char *) end_local_got;
3287+ s = htab->sgot;
3288+ srel = htab->srelgot;
3289+
3290+ for (; local_got < end_local_got; ++local_got, ++lgot_masks)
3291+ {
3292+ if (*local_got > 0)
3293+ {
3294+ unsigned int need = 0;
3295+ if ((*lgot_masks & TLS_TLS) != 0)
3296+ {
3297+ if ((*lgot_masks & TLS_GD) != 0)
3298+ need += 8;
3299+ if ((*lgot_masks & TLS_LD) != 0)
3300+ htab->tlsld_got.refcount += 1;
3301+ }
3302+ else
3303+ need += 4;
3304+
3305+ if (need == 0)
3306+ {
3307+ *local_got = (bfd_vma) -1;
3308+ }
3309+ else
3310+ {
3311+ *local_got = s->size;
3312+ s->size += need;
3313+ if (bfd_link_pic (info))
3314+ srel->size += need * (sizeof (Elf64_External_Rela) / 4);
3315+ }
3316+ }
3317+ else
3318+ *local_got = (bfd_vma) -1;
3319+ }
3320+ }
3321+
3322+ /* Allocate global sym .plt and .got entries, and space for global
3323+ sym dynamic relocs. */
3324+ elf_link_hash_traverse (elf_hash_table (info), allocate_dynrelocs, info);
3325+
3326+ if (htab->tlsld_got.refcount > 0)
3327+ {
3328+ htab->tlsld_got.offset = htab->sgot->size;
3329+ htab->sgot->size += 8;
3330+ if (bfd_link_pic (info))
3331+ htab->srelgot->size += sizeof (Elf64_External_Rela);
3332+ }
3333+ else
3334+ htab->tlsld_got.offset = (bfd_vma) -1;
3335+
3336+ if (elf_hash_table (info)->dynamic_sections_created)
3337+ {
3338+ /* Make space for the trailing nop in .plt. */
3339+ if (htab->splt->size > 0)
3340+ htab->splt->size += 4;
3341+ }
3342+
3343+ /* The check_relocs and adjust_dynamic_symbol entry points have
3344+ determined the sizes of the various dynamic sections. Allocate
3345+ memory for them. */
3346+ for (s = dynobj->sections; s != NULL; s = s->next)
3347+ {
3348+ const char *name;
3349+ bfd_boolean strip = FALSE;
3350+
3351+ if ((s->flags & SEC_LINKER_CREATED) == 0)
3352+ continue;
3353+
3354+ /* It's OK to base decisions on the section name, because none
3355+ of the dynobj section names depend upon the input files. */
3356+ name = bfd_get_section_name (dynobj, s);
3357+
3358+ if (strncmp (name, ".rela", 5) == 0)
3359+ {
3360+ if (s->size == 0)
3361+ {
3362+ /* If we don't need this section, strip it from the
3363+ output file. This is to handle .rela.bss and
3364+ .rela.plt. We must create it in
3365+ create_dynamic_sections, because it must be created
3366+ before the linker maps input sections to output
3367+ sections. The linker does that before
3368+ adjust_dynamic_symbol is called, and it is that
3369+ function which decides whether anything needs to go
3370+ into these sections. */
3371+ strip = TRUE;
3372+ }
3373+ else
3374+ {
3375+ /* We use the reloc_count field as a counter if we need
3376+ to copy relocs into the output file. */
3377+ s->reloc_count = 0;
3378+ }
3379+ }
3380+ else if (s != htab->splt && s != htab->sgot && s != htab->sgotplt)
3381+ {
3382+ /* It's not one of our sections, so don't allocate space. */
3383+ continue;
3384+ }
3385+
3386+ if (strip)
3387+ {
3388+ s->flags |= SEC_EXCLUDE;
3389+ continue;
3390+ }
3391+
3392+ /* Allocate memory for the section contents. */
3393+ /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3394+ Unused entries should be reclaimed before the section's contents
3395+ are written out, but at the moment this does not happen. Thus in
3396+ order to prevent writing out garbage, we initialise the section's
3397+ contents to zero. */
3398+ s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3399+ if (s->contents == NULL && s->size != 0)
3400+ return FALSE;
3401+ }
3402+
3403+ if (elf_hash_table (info)->dynamic_sections_created)
3404+ {
3405+ /* Add some entries to the .dynamic section. We fill in the
3406+ values later, in microblaze_elf_finish_dynamic_sections, but we
3407+ must add the entries now so that we get the correct size for
3408+ the .dynamic section. The DT_DEBUG entry is filled in by the
3409+ dynamic linker and used by the debugger. */
3410+#define add_dynamic_entry(TAG, VAL) \
3411+ _bfd_elf_add_dynamic_entry (info, TAG, VAL)
3412+
3413+ if (bfd_link_executable (info))
3414+ {
3415+ if (!add_dynamic_entry (DT_DEBUG, 0))
3416+ return FALSE;
3417+ }
3418+
3419+ if (!add_dynamic_entry (DT_RELA, 0)
3420+ || !add_dynamic_entry (DT_RELASZ, 0)
3421+ || !add_dynamic_entry (DT_RELAENT, sizeof (Elf64_External_Rela)))
3422+ return FALSE;
3423+
3424+ if (htab->splt->size != 0)
3425+ {
3426+ if (!add_dynamic_entry (DT_PLTGOT, 0)
3427+ || !add_dynamic_entry (DT_PLTRELSZ, 0)
3428+ || !add_dynamic_entry (DT_PLTREL, DT_RELA)
3429+ || !add_dynamic_entry (DT_JMPREL, 0)
3430+ || !add_dynamic_entry (DT_BIND_NOW, 1))
3431+ return FALSE;
3432+ }
3433+
3434+ if (info->flags & DF_TEXTREL)
3435+ {
3436+ if (!add_dynamic_entry (DT_TEXTREL, 0))
3437+ return FALSE;
3438+ }
3439+ }
3440+#undef add_dynamic_entry
3441+ return TRUE;
3442+}
3443+
3444+/* Finish up dynamic symbol handling. We set the contents of various
3445+ dynamic sections here. */
3446+
3447+static bfd_boolean
3448+microblaze_elf_finish_dynamic_symbol (bfd *output_bfd,
3449+ struct bfd_link_info *info,
3450+ struct elf_link_hash_entry *h,
3451+ Elf_Internal_Sym *sym)
3452+{
3453+ struct elf64_mb_link_hash_table *htab;
3454+ struct elf64_mb_link_hash_entry *eh = elf64_mb_hash_entry(h);
3455+
3456+ htab = elf64_mb_hash_table (info);
3457+ if (htab == NULL)
3458+ return FALSE;
3459+
3460+ if (h->plt.offset != (bfd_vma) -1)
3461+ {
3462+ asection *splt;
3463+ asection *srela;
3464+ asection *sgotplt;
3465+ Elf_Internal_Rela rela;
3466+ bfd_byte *loc;
3467+ bfd_vma plt_index;
3468+ bfd_vma got_offset;
3469+ bfd_vma got_addr;
3470+
3471+ /* This symbol has an entry in the procedure linkage table. Set
3472+ it up. */
3473+ BFD_ASSERT (h->dynindx != -1);
3474+
3475+ splt = htab->splt;
3476+ srela = htab->srelplt;
3477+ sgotplt = htab->sgotplt;
3478+ BFD_ASSERT (splt != NULL && srela != NULL && sgotplt != NULL);
3479+
3480+ plt_index = h->plt.offset / PLT_ENTRY_SIZE - 1; /* first entry reserved. */
3481+ got_offset = (plt_index + 3) * 4; /* 3 reserved ??? */
3482+ got_addr = got_offset;
3483+
3484+ /* For non-PIC objects we need absolute address of the GOT entry. */
3485+ if (!bfd_link_pic (info))
3486+ got_addr += htab->sgotplt->output_section->vma + sgotplt->output_offset;
3487+
3488+ /* Fill in the entry in the procedure linkage table. */
3489+ bfd_put_32 (output_bfd, PLT_ENTRY_WORD_0 + ((got_addr >> 16) & 0xffff),
3490+ splt->contents + h->plt.offset);
3491+ if (bfd_link_pic (info))
3492+ bfd_put_32 (output_bfd, PLT_ENTRY_WORD_1 + (got_addr & 0xffff),
3493+ splt->contents + h->plt.offset + 4);
3494+ else
3495+ bfd_put_32 (output_bfd, PLT_ENTRY_WORD_1_NOPIC + (got_addr & 0xffff),
3496+ splt->contents + h->plt.offset + 4);
3497+ bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD_2,
3498+ splt->contents + h->plt.offset + 8);
3499+ bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD_3,
3500+ splt->contents + h->plt.offset + 12);
3501+
3502+ /* Any additions to the .got section??? */
3503+ /* bfd_put_32 (output_bfd,
3504+ splt->output_section->vma + splt->output_offset + h->plt.offset + 4,
3505+ sgotplt->contents + got_offset); */
3506+
3507+ /* Fill in the entry in the .rela.plt section. */
3508+ rela.r_offset = (sgotplt->output_section->vma
3509+ + sgotplt->output_offset
3510+ + got_offset);
3511+ rela.r_info = ELF64_R_INFO (h->dynindx, R_MICROBLAZE_JUMP_SLOT);
3512+ rela.r_addend = 0;
3513+ loc = srela->contents;
3514+ loc += plt_index * sizeof (Elf64_External_Rela);
3515+ bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3516+
3517+ if (!h->def_regular)
3518+ {
3519+ /* Mark the symbol as undefined, rather than as defined in
3520+ the .plt section. Zero the value. */
3521+ sym->st_shndx = SHN_UNDEF;
3522+ sym->st_value = 0;
3523+ }
3524+ }
3525+
3526+ /* h->got.refcount to be checked ? */
3527+ if (h->got.offset != (bfd_vma) -1 &&
3528+ ! ((h->got.offset & 1) ||
3529+ IS_TLS_LD(eh->tls_mask) || IS_TLS_GD(eh->tls_mask)))
3530+ {
3531+ asection *sgot;
3532+ asection *srela;
3533+ bfd_vma offset;
3534+
3535+ /* This symbol has an entry in the global offset table. Set it
3536+ up. */
3537+
3538+ sgot = htab->sgot;
3539+ srela = htab->srelgot;
3540+ BFD_ASSERT (sgot != NULL && srela != NULL);
3541+
3542+ offset = (sgot->output_section->vma + sgot->output_offset
3543+ + (h->got.offset &~ (bfd_vma) 1));
3544+
3545+ /* If this is a -Bsymbolic link, and the symbol is defined
3546+ locally, we just want to emit a RELATIVE reloc. Likewise if
3547+ the symbol was forced to be local because of a version file.
3548+ The entry in the global offset table will already have been
3549+ initialized in the relocate_section function. */
3550+ if (bfd_link_pic (info)
3551+ && ((info->symbolic && h->def_regular)
3552+ || h->dynindx == -1))
3553+ {
3554+ asection *sec = h->root.u.def.section;
3555+ microblaze_elf_output_dynamic_relocation (output_bfd,
3556+ srela, srela->reloc_count++,
3557+ /* symindex= */ 0,
3558+ R_MICROBLAZE_REL, offset,
3559+ h->root.u.def.value
3560+ + sec->output_section->vma
3561+ + sec->output_offset);
3562+ }
3563+ else
3564+ {
3565+ microblaze_elf_output_dynamic_relocation (output_bfd,
3566+ srela, srela->reloc_count++,
3567+ h->dynindx,
3568+ R_MICROBLAZE_GLOB_DAT,
3569+ offset, 0);
3570+ }
3571+
3572+ bfd_put_32 (output_bfd, (bfd_vma) 0,
3573+ sgot->contents + (h->got.offset &~ (bfd_vma) 1));
3574+ }
3575+
3576+ if (h->needs_copy)
3577+ {
3578+ asection *s;
3579+ Elf_Internal_Rela rela;
3580+ bfd_byte *loc;
3581+
3582+ /* This symbols needs a copy reloc. Set it up. */
3583+
3584+ BFD_ASSERT (h->dynindx != -1);
3585+
3586+ s = bfd_get_linker_section (htab->elf.dynobj, ".rela.bss");
3587+ BFD_ASSERT (s != NULL);
3588+
3589+ rela.r_offset = (h->root.u.def.value
3590+ + h->root.u.def.section->output_section->vma
3591+ + h->root.u.def.section->output_offset);
3592+ rela.r_info = ELF64_R_INFO (h->dynindx, R_MICROBLAZE_COPY);
3593+ rela.r_addend = 0;
3594+ loc = s->contents + s->reloc_count++ * sizeof (Elf64_External_Rela);
3595+ bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3596+ }
3597+
3598+ /* Mark some specially defined symbols as absolute. */
3599+ if (h == htab->elf.hdynamic
3600+ || h == htab->elf.hgot
3601+ || h == htab->elf.hplt)
3602+ sym->st_shndx = SHN_ABS;
3603+
3604+ return TRUE;
3605+}
3606+
3607+
3608+/* Finish up the dynamic sections. */
3609+
3610+static bfd_boolean
3611+microblaze_elf_finish_dynamic_sections (bfd *output_bfd,
3612+ struct bfd_link_info *info)
3613+{
3614+ bfd *dynobj;
3615+ asection *sdyn, *sgot;
3616+ struct elf64_mb_link_hash_table *htab;
3617+
3618+ htab = elf64_mb_hash_table (info);
3619+ if (htab == NULL)
3620+ return FALSE;
3621+
3622+ dynobj = htab->elf.dynobj;
3623+
3624+ sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3625+
3626+ if (htab->elf.dynamic_sections_created)
3627+ {
3628+ asection *splt;
3629+ Elf64_External_Dyn *dyncon, *dynconend;
3630+
3631+ splt = bfd_get_linker_section (dynobj, ".plt");
3632+ BFD_ASSERT (splt != NULL && sdyn != NULL);
3633+
3634+ dyncon = (Elf64_External_Dyn *) sdyn->contents;
3635+ dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3636+ for (; dyncon < dynconend; dyncon++)
3637+ {
3638+ Elf_Internal_Dyn dyn;
3639+ const char *name;
3640+ bfd_boolean size;
3641+
3642+ bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3643+
3644+ switch (dyn.d_tag)
3645+ {
3646+ case DT_PLTGOT: name = ".got.plt"; size = FALSE; break;
3647+ case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break;
3648+ case DT_JMPREL: name = ".rela.plt"; size = FALSE; break;
3649+ case DT_RELA: name = ".rela.dyn"; size = FALSE; break;
3650+ case DT_RELASZ: name = ".rela.dyn"; size = TRUE; break;
3651+ default: name = NULL; size = FALSE; break;
3652+ }
3653+
3654+ if (name != NULL)
3655+ {
3656+ asection *s;
3657+
3658+ s = bfd_get_section_by_name (output_bfd, name);
3659+ if (s == NULL)
3660+ dyn.d_un.d_val = 0;
3661+ else
3662+ {
3663+ if (! size)
3664+ dyn.d_un.d_ptr = s->vma;
3665+ else
3666+ dyn.d_un.d_val = s->size;
3667+ }
3668+ bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3669+ }
3670+ }
3671+
3672+ /* Clear the first entry in the procedure linkage table,
3673+ and put a nop in the last four bytes. */
3674+ if (splt->size > 0)
3675+ {
3676+ memset (splt->contents, 0, PLT_ENTRY_SIZE);
3677+ bfd_put_32 (output_bfd, (bfd_vma) 0x80000000 /* nop. */,
3678+ splt->contents + splt->size - 4);
3679+ }
3680+
3681+ elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
3682+ }
3683+
3684+ /* Set the first entry in the global offset table to the address of
3685+ the dynamic section. */
3686+ sgot = bfd_get_linker_section (dynobj, ".got.plt");
3687+ if (sgot && sgot->size > 0)
3688+ {
3689+ if (sdyn == NULL)
3690+ bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
3691+ else
3692+ bfd_put_32 (output_bfd,
3693+ sdyn->output_section->vma + sdyn->output_offset,
3694+ sgot->contents);
3695+ elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
3696+ }
3697+
3698+ if (htab->sgot && htab->sgot->size > 0)
3699+ elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 4;
3700+
3701+ return TRUE;
3702+}
3703+
3704+/* Hook called by the linker routine which adds symbols from an object
3705+ file. We use it to put .comm items in .sbss, and not .bss. */
3706+
3707+static bfd_boolean
3708+microblaze_elf_add_symbol_hook (bfd *abfd,
3709+ struct bfd_link_info *info,
3710+ Elf_Internal_Sym *sym,
3711+ const char **namep ATTRIBUTE_UNUSED,
3712+ flagword *flagsp ATTRIBUTE_UNUSED,
3713+ asection **secp,
3714+ bfd_vma *valp)
3715+{
3716+ if (sym->st_shndx == SHN_COMMON
3717+ && !bfd_link_relocatable (info)
3718+ && sym->st_size <= elf_gp_size (abfd))
3719+ {
3720+ /* Common symbols less than or equal to -G nn bytes are automatically
3721+ put into .sbss. */
3722+ *secp = bfd_make_section_old_way (abfd, ".sbss");
3723+ if (*secp == NULL
3724+ || ! bfd_set_section_flags (abfd, *secp, SEC_IS_COMMON))
3725+ return FALSE;
3726+
3727+ *valp = sym->st_size;
3728+ }
3729+
3730+ return TRUE;
3731+}
3732+
3733+#define TARGET_LITTLE_SYM microblaze_elf64_le_vec
3734+#define TARGET_LITTLE_NAME "elf64-microblazeel"
3735+
3736+#define TARGET_BIG_SYM microblaze_elf64_vec
3737+#define TARGET_BIG_NAME "elf64-microblaze"
3738+
3739+#define ELF_ARCH bfd_arch_microblaze
3740+#define ELF_TARGET_ID MICROBLAZE_ELF_DATA
3741+#define ELF_MACHINE_CODE EM_MICROBLAZE
3742+#define ELF_MACHINE_ALT1 EM_MICROBLAZE_OLD
3743+#define ELF_MAXPAGESIZE 0x1000
3744+#define elf_info_to_howto microblaze_elf_info_to_howto
3745+#define elf_info_to_howto_rel NULL
3746+
3747+#define bfd_elf64_bfd_reloc_type_lookup microblaze_elf_reloc_type_lookup
3748+#define bfd_elf64_bfd_is_local_label_name microblaze_elf_is_local_label_name
3749+#define elf_backend_relocate_section microblaze_elf_relocate_section
3750+#define bfd_elf64_bfd_relax_section microblaze_elf_relax_section
3751+#define bfd_elf64_bfd_merge_private_bfd_data microblaze_elf_merge_private_bfd_data
3752+#define bfd_elf64_bfd_reloc_name_lookup microblaze_elf_reloc_name_lookup
3753+
3754+#define elf_backend_gc_mark_hook microblaze_elf_gc_mark_hook
3755+#define elf_backend_gc_sweep_hook microblaze_elf_gc_sweep_hook
3756+#define elf_backend_check_relocs microblaze_elf_check_relocs
3757+#define elf_backend_copy_indirect_symbol microblaze_elf_copy_indirect_symbol
3758+#define bfd_elf64_bfd_link_hash_table_create microblaze_elf_link_hash_table_create
3759+#define elf_backend_can_gc_sections 1
3760+#define elf_backend_can_refcount 1
3761+#define elf_backend_want_got_plt 1
3762+#define elf_backend_plt_readonly 1
3763+#define elf_backend_got_header_size 12
3764+#define elf_backend_rela_normal 1
3765+
3766+#define elf_backend_adjust_dynamic_symbol microblaze_elf_adjust_dynamic_symbol
3767+#define elf_backend_create_dynamic_sections microblaze_elf_create_dynamic_sections
3768+#define elf_backend_finish_dynamic_sections microblaze_elf_finish_dynamic_sections
3769+#define elf_backend_finish_dynamic_symbol microblaze_elf_finish_dynamic_symbol
3770+#define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
3771+#define elf_backend_add_symbol_hook microblaze_elf_add_symbol_hook
3772+
3773+#include "elf64-target.h"
3774diff --git a/bfd/targets.c b/bfd/targets.c
3775index 158168cb3b..ef567a30c8 100644
3776--- a/bfd/targets.c
3777+++ b/bfd/targets.c
3778@@ -706,6 +706,8 @@ extern const bfd_target mep_elf32_le_vec;
3779 extern const bfd_target metag_elf32_vec;
3780 extern const bfd_target microblaze_elf32_vec;
3781 extern const bfd_target microblaze_elf32_le_vec;
3782+extern const bfd_target microblaze_elf64_vec;
3783+extern const bfd_target microblaze_elf64_le_vec;
3784 extern const bfd_target mips_ecoff_be_vec;
3785 extern const bfd_target mips_ecoff_le_vec;
3786 extern const bfd_target mips_ecoff_bele_vec;
3787@@ -1073,6 +1075,10 @@ static const bfd_target * const _bfd_target_vector[] =
3788
3789 &metag_elf32_vec,
3790
3791+#ifdef BFD64
3792+ &microblaze_elf64_vec,
3793+ &microblaze_elf64_le_vec,
3794+#endif
3795 &microblaze_elf32_vec,
3796
3797 &mips_ecoff_be_vec,
3798diff --git a/include/elf/common.h b/include/elf/common.h
3799index e8faf67be3..ca89da1631 100644
3800--- a/include/elf/common.h
3801+++ b/include/elf/common.h
3802@@ -339,6 +339,7 @@
3803 #define EM_RISCV 243 /* RISC-V */
3804 #define EM_LANAI 244 /* Lanai 32-bit processor. */
3805 #define EM_BPF 247 /* Linux BPF – in-kernel virtual machine. */
3806+#define EM_MB_64 248 /* Xilinx MicroBlaze 32-bit RISC soft processor core */
3807 #define EM_NFP 250 /* Netronome Flow Processor. */
3808 #define EM_CSKY 252 /* C-SKY processor family. */
3809
3810diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
3811index f8aaf27873..20ea6a885a 100644
3812--- a/opcodes/microblaze-dis.c
3813+++ b/opcodes/microblaze-dis.c
3814@@ -33,6 +33,7 @@
3815 #define get_field_r1(instr) get_field (instr, RA_MASK, RA_LOW)
3816 #define get_field_r2(instr) get_field (instr, RB_MASK, RB_LOW)
3817 #define get_int_field_imm(instr) ((instr & IMM_MASK) >> IMM_LOW)
3818+#define get_int_field_imml(instr) ((instr & IMML_MASK) >> IMM_LOW)
3819 #define get_int_field_r1(instr) ((instr & RA_MASK) >> RA_LOW)
3820
3821
3822@@ -56,11 +57,20 @@ get_field_imm (long instr)
3823 }
3824
3825 static char *
3826-get_field_imm5 (long instr)
3827+get_field_imml (long instr)
3828 {
3829 char tmpstr[25];
3830
3831- sprintf (tmpstr, "%d", (short)((instr & IMM5_MASK) >> IMM_LOW));
3832+ sprintf (tmpstr, "%d", (short)((instr & IMML_MASK) >> IMM_LOW));
3833+ return (strdup (tmpstr));
3834+}
3835+
3836+static char *
3837+get_field_imms (long instr)
3838+{
3839+ char tmpstr[25];
3840+
3841+ sprintf (tmpstr, "%d", (short)((instr & IMM6_MASK) >> IMM_LOW));
3842 return (strdup (tmpstr));
3843 }
3844
3845@@ -74,14 +84,14 @@ get_field_imm5_mbar (long instr)
3846 }
3847
3848 static char *
3849-get_field_imm5width (long instr)
3850+get_field_immw (long instr)
3851 {
3852 char tmpstr[25];
3853
3854 if (instr & 0x00004000)
3855- sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
3856+ sprintf (tmpstr, "%d", (short)(((instr & IMM6_WIDTH_MASK) >> IMM_WIDTH_LOW))); /* bsefi */
3857 else
3858- sprintf (tmpstr, "%d", (short)(((instr & IMM5_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM5_MASK) >> IMM_LOW) + 1)); /* bsifi */
3859+ sprintf (tmpstr, "%d", (short)(((instr & IMM6_WIDTH_MASK) >> IMM_WIDTH_LOW) - ((instr & IMM6_MASK) >> IMM_LOW) + 1)); /* bsifi */
3860 return (strdup (tmpstr));
3861 }
3862
3863@@ -286,9 +296,13 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
3864 }
3865 }
3866 break;
3867- case INST_TYPE_RD_R1_IMM5:
3868+ case INST_TYPE_RD_R1_IMML:
3869+ print_func (stream, "\t%s, %s, %s", get_field_rd (inst),
3870+ get_field_r1(inst), get_field_imm (inst));
3871+ /* TODO: Also print symbol */
3872+ case INST_TYPE_RD_R1_IMMS:
3873 print_func (stream, "\t%s, %s, %s", get_field_rd (inst),
3874- get_field_r1(inst), get_field_imm5 (inst));
3875+ get_field_r1(inst), get_field_imms (inst));
3876 break;
3877 case INST_TYPE_RD_RFSL:
3878 print_func (stream, "\t%s, %s", get_field_rd (inst), get_field_rfsl (inst));
3879@@ -386,6 +400,10 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
3880 }
3881 }
3882 break;
3883+ case INST_TYPE_IMML:
3884+ print_func (stream, "\t%s", get_field_imml (inst));
3885+ /* TODO: Also print symbol */
3886+ break;
3887 case INST_TYPE_RD_R2:
3888 print_func (stream, "\t%s, %s", get_field_rd (inst), get_field_r2 (inst));
3889 break;
3890@@ -409,9 +427,10 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
3891 case INST_TYPE_NONE:
3892 break;
3893 /* For bit field insns. */
3894- case INST_TYPE_RD_R1_IMM5_IMM5:
3895- print_func (stream, "\t%s, %s, %s, %s", get_field_rd (inst),get_field_r1(inst),get_field_imm5width (inst), get_field_imm5 (inst));
3896- break;
3897+ case INST_TYPE_RD_R1_IMMW_IMMS:
3898+ print_func (stream, "\t%s, %s, %s, %s", get_field_rd (inst), get_field_r1(inst),
3899+ get_field_immw (inst), get_field_imms (inst));
3900+ break;
3901 /* For tuqula instruction */
3902 case INST_TYPE_RD:
3903 print_func (stream, "\t%s", get_field_rd (inst));
3904diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
3905index ce8ac351b5..985834b8df 100644
3906--- a/opcodes/microblaze-opc.h
3907+++ b/opcodes/microblaze-opc.h
3908@@ -40,7 +40,7 @@
3909 #define INST_TYPE_RD_SPECIAL 11
3910 #define INST_TYPE_R1 12
3911 /* New instn type for barrel shift imms. */
3912-#define INST_TYPE_RD_R1_IMM5 13
3913+#define INST_TYPE_RD_R1_IMMS 13
3914 #define INST_TYPE_RD_RFSL 14
3915 #define INST_TYPE_R1_RFSL 15
3916
3917@@ -60,7 +60,13 @@
3918 #define INST_TYPE_IMM5 20
3919
3920 /* For bsefi and bsifi */
3921-#define INST_TYPE_RD_R1_IMM5_IMM5 21
3922+#define INST_TYPE_RD_R1_IMMW_IMMS 21
3923+
3924+/* For 64-bit instructions */
3925+#define INST_TYPE_IMML 22
3926+#define INST_TYPE_RD_R1_IMML 23
3927+#define INST_TYPE_R1_IMML 24
3928+#define INST_TYPE_RD_R1_IMMW_IMMS 21
3929
3930 #define INST_TYPE_NONE 25
3931
3932@@ -91,13 +97,14 @@
3933 #define OPCODE_MASK_H24 0xFC1F07FF /* High 6, bits 20-16 and low 11 bits. */
3934 #define OPCODE_MASK_H124 0xFFFF07FF /* High 16, and low 11 bits. */
3935 #define OPCODE_MASK_H1234 0xFFFFFFFF /* All 32 bits. */
3936-#define OPCODE_MASK_H3 0xFC000600 /* High 6 bits and bits 21, 22. */
3937-#define OPCODE_MASK_H3B 0xFC00C600 /* High 6 bits and bits 16, 17, 21, 22. */
3938+#define OPCODE_MASK_H3 0xFC000700 /* High 6 bits and bits 21, 22, 23. */
3939+#define OPCODE_MASK_H3B 0xFC00E600 /* High 6 bits and bits 16, 17, 18, 21, 22. */
3940 #define OPCODE_MASK_H32 0xFC00FC00 /* High 6 bits and bit 16-21. */
3941-#define OPCODE_MASK_H32B 0xFC00C000 /* High 6 bits and bit 16, 17. */
3942+#define OPCODE_MASK_H32B 0xFC00E000 /* High 6 bits and bit 16, 17, 18. */
3943 #define OPCODE_MASK_H34B 0xFC0000FF /* High 6 bits and low 8 bits. */
3944 #define OPCODE_MASK_H35B 0xFC0004FF /* High 6 bits and low 9 bits. */
3945 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
3946+#define OPCODE_MASK_H8 0xFF000000 /* High 8 bits only. */
3947
3948 /* New Mask for msrset, msrclr insns. */
3949 #define OPCODE_MASK_H23N 0xFC1F8000 /* High 6 and bits 11 - 16. */
3950@@ -107,7 +114,7 @@
3951 #define DELAY_SLOT 1
3952 #define NO_DELAY_SLOT 0
3953
3954-#define MAX_OPCODES 301
3955+#define MAX_OPCODES 412
3956
3957 struct op_code_struct
3958 {
3959@@ -125,6 +132,7 @@ struct op_code_struct
3960 /* More info about output format here. */
3961 } opcodes[MAX_OPCODES] =
3962 {
3963+ /* 32-bit instructions */
3964 {"add", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x00000000, OPCODE_MASK_H4, add, arithmetic_inst },
3965 {"rsub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000000, OPCODE_MASK_H4, rsub, arithmetic_inst },
3966 {"addc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x08000000, OPCODE_MASK_H4, addc, arithmetic_inst },
3967@@ -161,11 +169,11 @@ struct op_code_struct
3968 {"ncget", INST_TYPE_RD_RFSL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x6C006000, OPCODE_MASK_H32, ncget, anyware_inst },
3969 {"ncput", INST_TYPE_R1_RFSL, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x6C00E000, OPCODE_MASK_H32, ncput, anyware_inst },
3970 {"muli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x60000000, OPCODE_MASK_H, muli, mult_inst },
3971- {"bslli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3, bslli, barrel_shift_inst },
3972- {"bsrai", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3, bsrai, barrel_shift_inst },
3973- {"bsrli", INST_TYPE_RD_R1_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3, bsrli, barrel_shift_inst },
3974- {"bsefi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64004000, OPCODE_MASK_H32B, bsefi, barrel_shift_inst },
3975- {"bsifi", INST_TYPE_RD_R1_IMM5_IMM5, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64008000, OPCODE_MASK_H32B, bsifi, barrel_shift_inst },
3976+ {"bslli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000400, OPCODE_MASK_H3B, bslli, barrel_shift_inst },
3977+ {"bsrai", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000200, OPCODE_MASK_H3B, bsrai, barrel_shift_inst },
3978+ {"bsrli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64000000, OPCODE_MASK_H3B, bsrli, barrel_shift_inst },
3979+ {"bsefi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64004000, OPCODE_MASK_H32B, bsefi, barrel_shift_inst },
3980+ {"bsifi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64008000, OPCODE_MASK_H32B, bsifi, barrel_shift_inst },
3981 {"or", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000000, OPCODE_MASK_H4, microblaze_or, logical_inst },
3982 {"and", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000000, OPCODE_MASK_H4, microblaze_and, logical_inst },
3983 {"xor", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000000, OPCODE_MASK_H4, microblaze_xor, logical_inst },
3984@@ -425,6 +433,129 @@ struct op_code_struct
3985 {"suspend", INST_TYPE_NONE, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBB020004, OPCODE_MASK_HN, invalid_inst, special_inst }, /* translates to mbar 24. */
3986 {"swapb", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E0, OPCODE_MASK_H4, swapb, arithmetic_inst },
3987 {"swaph", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x900001E2, OPCODE_MASK_H4, swaph, arithmetic_inst },
3988+
3989+ /* 64-bit instructions */
3990+ {"addl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x00000100, OPCODE_MASK_H4, addl, arithmetic_inst },
3991+ {"rsubl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000100, OPCODE_MASK_H4, rsubl, arithmetic_inst },
3992+ {"addlc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x08000100, OPCODE_MASK_H4, addlc, arithmetic_inst },
3993+ {"rsublc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x0C000100, OPCODE_MASK_H4, rsublc, arithmetic_inst },
3994+ {"addlk", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x10000100, OPCODE_MASK_H4, addlk, arithmetic_inst },
3995+ {"rsublk", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000100, OPCODE_MASK_H4, rsublk, arithmetic_inst },
3996+ {"addlkc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x18000100, OPCODE_MASK_H4, addlkc, arithmetic_inst },
3997+ {"rsublkc", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x1C000100, OPCODE_MASK_H4, rsublkc, arithmetic_inst },
3998+ {"cmpl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000101, OPCODE_MASK_H4, cmpl, arithmetic_inst },
3999+ {"cmplu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000103, OPCODE_MASK_H4, cmplu, arithmetic_inst },
4000+ {"addli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x20000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4001+ {"rsubli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x24000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4002+ {"addlic", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x28000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4003+ {"rsublic", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x2C000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4004+ {"addlik", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4005+ {"rsublik", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x34000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4006+ {"addlikc", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x38000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4007+ {"rsublikc",INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x3C000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
4008+ {"mull", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x40000100, OPCODE_MASK_H4, mull, mult_inst },
4009+ {"bslll", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000500, OPCODE_MASK_H3, bslll, barrel_shift_inst },
4010+ {"bslra", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000300, OPCODE_MASK_H3, bslra, barrel_shift_inst },
4011+ {"bslrl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000100, OPCODE_MASK_H3, bslrl, barrel_shift_inst },
4012+ {"bsllli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64002400, OPCODE_MASK_H3B, bsllli, barrel_shift_inst },
4013+ {"bslrai", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64002200, OPCODE_MASK_H3B, bslrai, barrel_shift_inst },
4014+ {"bslrli", INST_TYPE_RD_R1_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64002000, OPCODE_MASK_H3B, bslrli, barrel_shift_inst },
4015+ {"bslefi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x64006000, OPCODE_MASK_H32B, bslefi, barrel_shift_inst },
4016+ {"bslifi", INST_TYPE_RD_R1_IMMW_IMMS, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x6400a000, OPCODE_MASK_H32B, bslifi, barrel_shift_inst },
4017+ {"orl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000100, OPCODE_MASK_H4, orl, logical_inst },
4018+ {"andl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x84000100, OPCODE_MASK_H4, andl, logical_inst },
4019+ {"xorl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000100, OPCODE_MASK_H4, xorl, logical_inst },
4020+ {"andnl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x8C000100, OPCODE_MASK_H4, andnl, logical_inst },
4021+ {"pcmplbf", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x80000500, OPCODE_MASK_H4, pcmplbf, logical_inst },
4022+ {"pcmpleq", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x88000500, OPCODE_MASK_H4, pcmpleq, logical_inst },
4023+ {"pcmplne", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x8C000500, OPCODE_MASK_H4, pcmplne, logical_inst },
4024+ {"srla", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000101, OPCODE_MASK_H34, srla, logical_inst },
4025+ {"srlc", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000121, OPCODE_MASK_H34, srlc, logical_inst },
4026+ {"srll", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000141, OPCODE_MASK_H34, srll, logical_inst },
4027+ {"sextl8", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000160, OPCODE_MASK_H34, sextl8, logical_inst },
4028+ {"sextl16", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000161, OPCODE_MASK_H34, sextl16, logical_inst },
4029+ {"sextl32", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x90000162, OPCODE_MASK_H34, sextl32, logical_inst },
4030+ {"brea", INST_TYPE_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98010000, OPCODE_MASK_H124, brea, branch_inst },
4031+ {"bread", INST_TYPE_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98110000, OPCODE_MASK_H124, bread, branch_inst },
4032+ {"breald", INST_TYPE_RD_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x98150000, OPCODE_MASK_H24, breald, branch_inst },
4033+ {"beaeq", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D000000, OPCODE_MASK_H14, beaeq, branch_inst },
4034+ {"bealeq", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D000100, OPCODE_MASK_H14, bealeq, branch_inst },
4035+ {"beaeqd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F000000, OPCODE_MASK_H14, beaeqd, branch_inst },
4036+ {"bealeqd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F000100, OPCODE_MASK_H14, bealeqd, branch_inst },
4037+ {"beane", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D200000, OPCODE_MASK_H14, beane, branch_inst },
4038+ {"bealne", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D200100, OPCODE_MASK_H14, bealne, branch_inst },
4039+ {"beaned", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F200000, OPCODE_MASK_H14, beaned, branch_inst },
4040+ {"bealned", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F200100, OPCODE_MASK_H14, bealned, branch_inst },
4041+ {"bealt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D400000, OPCODE_MASK_H14, bealt, branch_inst },
4042+ {"beallt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D400100, OPCODE_MASK_H14, beallt, branch_inst },
4043+ {"bealtd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F400000, OPCODE_MASK_H14, bealtd, branch_inst },
4044+ {"bealltd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F400100, OPCODE_MASK_H14, bealltd, branch_inst },
4045+ {"beale", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D600000, OPCODE_MASK_H14, beale, branch_inst },
4046+ {"bealle", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D600100, OPCODE_MASK_H14, bealle, branch_inst },
4047+ {"bealed", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F600000, OPCODE_MASK_H14, bealed, branch_inst },
4048+ {"bealled", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F600100, OPCODE_MASK_H14, bealled, branch_inst },
4049+ {"beagt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D800000, OPCODE_MASK_H14, beagt, branch_inst },
4050+ {"bealgt", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9D800100, OPCODE_MASK_H14, bealgt, branch_inst },
4051+ {"beagtd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F800000, OPCODE_MASK_H14, beagtd, branch_inst },
4052+ {"bealgtd", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9F800100, OPCODE_MASK_H14, bealgtd, branch_inst },
4053+ {"beage", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9DA00000, OPCODE_MASK_H14, beage, branch_inst },
4054+ {"bealge", INST_TYPE_R1_R2, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9DA00100, OPCODE_MASK_H14, bealge, branch_inst },
4055+ {"beaged", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9FA00000, OPCODE_MASK_H14, beaged, branch_inst },
4056+ {"bealged", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9FA00100, OPCODE_MASK_H14, bealged, branch_inst },
4057+ {"orli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA0000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4058+ {"andli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA4000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4059+ {"xorli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA8000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4060+ {"andnli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xAC000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
4061+ {"imml", INST_TYPE_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB2000000, OPCODE_MASK_H8, imml, immediate_inst },
4062+ {"breai", INST_TYPE_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8010000, OPCODE_MASK_H12, breai, branch_inst },
4063+ {"breaid", INST_TYPE_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8110000, OPCODE_MASK_H12, breaid, branch_inst },
4064+ {"brealid", INST_TYPE_RD_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8150000, OPCODE_MASK_H2, brealid, branch_inst },
4065+ {"beaeqi", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD000000, OPCODE_MASK_H1, beaeqi, branch_inst },
4066+ {"bealeqi", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD000000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beaeqi */
4067+ {"beaeqid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF000000, OPCODE_MASK_H1, beaeqid, branch_inst },
4068+ {"bealeqid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF000000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beaeqid */
4069+ {"beanei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD200000, OPCODE_MASK_H1, beanei, branch_inst },
4070+ {"bealnei", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD200000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beanei */
4071+ {"beaneid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF200000, OPCODE_MASK_H1, beaneid, branch_inst },
4072+ {"bealneid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF200000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beaneid */
4073+ {"bealti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD400000, OPCODE_MASK_H1, bealti, branch_inst },
4074+ {"beallti", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD400000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealti */
4075+ {"bealtid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF400000, OPCODE_MASK_H1, bealtid, branch_inst },
4076+ {"bealltid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF400000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealtid */
4077+ {"bealei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD600000, OPCODE_MASK_H1, bealei, branch_inst },
4078+ {"beallei", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD600000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealei */
4079+ {"bealeid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF600000, OPCODE_MASK_H1, bealeid, branch_inst },
4080+ {"bealleid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF600000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to bealeid */
4081+ {"beagti", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD800000, OPCODE_MASK_H1, beagti, branch_inst },
4082+ {"bealgti", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBD800000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beagti */
4083+ {"beagtid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF800000, OPCODE_MASK_H1, beagtid, branch_inst },
4084+ {"bealgtid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBF800000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beagtid */
4085+ {"beagei", INST_TYPE_R1_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBDA00000, OPCODE_MASK_H1, beagei, branch_inst },
4086+ {"bealgei", INST_TYPE_R1_IMML, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBDA00000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beagei */
4087+ {"beageid", INST_TYPE_R1_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBFA00000, OPCODE_MASK_H1, beageid, branch_inst },
4088+ {"bealgeid",INST_TYPE_R1_IMML, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xBFA00000, OPCODE_MASK_H1, invalid_inst, branch_inst }, /* Identical to beageid */
4089+ {"ll", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000100, OPCODE_MASK_H4, ll, memory_load_inst },
4090+ {"llr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000300, OPCODE_MASK_H4, llr, memory_load_inst },
4091+ {"sl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000100, OPCODE_MASK_H4, sl, memory_store_inst },
4092+ {"slr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000300, OPCODE_MASK_H4, slr, memory_store_inst },
4093+ {"lli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */
4094+ {"sli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */
4095+ {"lla", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* lla translates to addlik */
4096+ {"dadd", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000400, OPCODE_MASK_H4, dadd, arithmetic_inst },
4097+ {"drsub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000480, OPCODE_MASK_H4, drsub, arithmetic_inst },
4098+ {"dmul", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000500, OPCODE_MASK_H4, dmul, arithmetic_inst },
4099+ {"ddiv", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000580, OPCODE_MASK_H4, ddiv, arithmetic_inst },
4100+ {"dcmp.lt", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000610, OPCODE_MASK_H4, dcmp_lt, arithmetic_inst },
4101+ {"dcmp.eq", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000620, OPCODE_MASK_H4, dcmp_eq, arithmetic_inst },
4102+ {"dcmp.le", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000630, OPCODE_MASK_H4, dcmp_le, arithmetic_inst },
4103+ {"dcmp.gt", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000640, OPCODE_MASK_H4, dcmp_gt, arithmetic_inst },
4104+ {"dcmp.ne", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000650, OPCODE_MASK_H4, dcmp_ne, arithmetic_inst },
4105+ {"dcmp.ge", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000660, OPCODE_MASK_H4, dcmp_ge, arithmetic_inst },
4106+ {"dcmp.un", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000600, OPCODE_MASK_H4, dcmp_un, arithmetic_inst },
4107+ {"dbl", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000680, OPCODE_MASK_H4, dbl, arithmetic_inst },
4108+ {"dlong", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000700, OPCODE_MASK_H4, dlong, arithmetic_inst },
4109+ {"dsqrt", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000780, OPCODE_MASK_H4, dsqrt, arithmetic_inst },
4110+
4111 {"", 0, 0, 0, 0, 0, 0, 0, 0},
4112 };
4113
4114@@ -445,8 +576,17 @@ char pvr_register_prefix[] = "rpvr";
4115 #define MIN_IMM5 ((int) 0x00000000)
4116 #define MAX_IMM5 ((int) 0x0000001f)
4117
4118+#define MIN_IMM6 ((int) 0x00000000)
4119+#define MAX_IMM6 ((int) 0x0000003f)
4120+
4121 #define MIN_IMM_WIDTH ((int) 0x00000001)
4122 #define MAX_IMM_WIDTH ((int) 0x00000020)
4123
4124+#define MIN_IMM6_WIDTH ((int) 0x00000001)
4125+#define MAX_IMM6_WIDTH ((int) 0x00000040)
4126+
4127+#define MIN_IMML ((long) 0xffffff8000000000L)
4128+#define MAX_IMML ((long) 0x0000007fffffffffL)
4129+
4130 #endif /* MICROBLAZE_OPC */
4131
4132diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
4133index 28662694cd..076dbcd0b3 100644
4134--- a/opcodes/microblaze-opcm.h
4135+++ b/opcodes/microblaze-opcm.h
4136@@ -25,6 +25,7 @@
4137
4138 enum microblaze_instr
4139 {
4140+ /* 32-bit instructions */
4141 add, rsub, addc, rsubc, addk, rsubk, addkc, rsubkc, clz, cmp, cmpu,
4142 addi, rsubi, addic, rsubic, addik, rsubik, addikc, rsubikc, mul,
4143 mulh, mulhu, mulhsu,swapb,swaph,
4144@@ -58,6 +59,18 @@ enum microblaze_instr
4145 aputd, taputd, caputd, tcaputd, naputd, tnaputd, ncaputd, tncaputd,
4146 eagetd, teagetd, ecagetd, tecagetd, neagetd, tneagetd, necagetd, tnecagetd,
4147 eaputd, teaputd, ecaputd, tecaputd, neaputd, tneaputd, necaputd, tnecaputd,
4148+
4149+ /* 64-bit instructions */
4150+ addl, rsubl, addlc, rsublc, addlk, rsublk, addlkc, rsublkc, cmpl, cmplu, mull,
4151+ bslll, bslra, bslrl, bsllli, bslrai, bslrli, bslefi, bslifi, orl, andl, xorl,
4152+ andnl, pcmplbf, pcmpleq, pcmplne, srla, srlc, srll, sextl8, sextl16, sextl32,
4153+ brea, bread, breald, beaeq, bealeq, beaeqd, bealeqd, beane, bealne, beaned,
4154+ bealned, bealt, beallt, bealtd, bealltd, beale, bealle, bealed, bealled, beagt,
4155+ bealgt, beagtd, bealgtd, beage, bealge, beaged, bealged, breai, breaid, brealid,
4156+ beaeqi, beaeqid, beanei, beaneid, bealti, bealtid, bealei, bealeid, beagti,
4157+ beagtid, beagei, beageid, imml, ll, llr, sl, slr,
4158+ dadd, drsub, dmul, ddiv, dcmp_lt, dcmp_eq, dcmp_le, dcmp_gt, dcmp_ne, dcmp_ge,
4159+ dcmp_un, dbl, dlong, dsqrt,
4160 invalid_inst
4161 };
4162
4163@@ -135,15 +148,18 @@ enum microblaze_instr_type
4164 #define RA_MASK 0x001F0000
4165 #define RB_MASK 0x0000F800
4166 #define IMM_MASK 0x0000FFFF
4167+#define IMML_MASK 0x00FFFFFF
4168
4169-/* Imm mask for barrel shifts. */
4170+/* Imm masks for barrel shifts. */
4171 #define IMM5_MASK 0x0000001F
4172+#define IMM6_MASK 0x0000003F
4173
4174 /* Imm mask for mbar. */
4175 #define IMM5_MBAR_MASK 0x03E00000
4176
4177-/* Imm mask for extract/insert width. */
4178+/* Imm masks for extract/insert width. */
4179 #define IMM5_WIDTH_MASK 0x000007C0
4180+#define IMM6_WIDTH_MASK 0x00000FC0
4181
4182 /* FSL imm mask for get, put instructions. */
4183 #define RFSL_MASK 0x000000F
4184--
41852.17.1
4186
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0016-MB-X-initial-commit.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0016-MB-X-initial-commit.patch
new file mode 100644
index 00000000..d4441443
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0016-MB-X-initial-commit.patch
@@ -0,0 +1,355 @@
1From 92419bfa472c29b96ff85a9769b9301539867364 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Sun, 30 Sep 2018 16:31:26 +0530
4Subject: [PATCH 16/43] MB-X initial commit code cleanup is needed.
5
6---
7 bfd/bfd-in2.h | 10 +++
8 bfd/elf32-microblaze.c | 65 +++++++++++++++-
9 bfd/elf64-microblaze.c | 61 ++++++++++++++-
10 bfd/libbfd.h | 2 +
11 bfd/reloc.c | 12 +++
12 include/elf/microblaze.h | 2 +
13 opcodes/microblaze-opc.h | 4 +-
14 opcodes/microblaze-opcm.h | 4 +-
15 9 files changed, 277 insertions(+), 35 deletions(-)
16
17diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
18index 721531886a..4f777059d8 100644
19--- a/bfd/bfd-in2.h
20+++ b/bfd/bfd-in2.h
21@@ -5876,11 +5876,21 @@ done here - only used for relaxing */
22 * +done here - only used for relaxing */
23 BFD_RELOC_MICROBLAZE_64_NONE,
24
25+/* This is a 64 bit reloc that stores the 32 bit pc relative
26+ * +value in two words (with an imml instruction). No relocation is
27+ * +done here - only used for relaxing */
28+ BFD_RELOC_MICROBLAZE_64,
29+
30 /* This is a 64 bit reloc that stores the 32 bit pc relative
31 value in two words (with an imm instruction). The relocation is
32 PC-relative GOT offset */
33 BFD_RELOC_MICROBLAZE_64_GOTPC,
34
35+/* This is a 64 bit reloc that stores the 32 bit pc relative
36+value in two words (with an imml instruction). The relocation is
37+PC-relative GOT offset */
38+ BFD_RELOC_MICROBLAZE_64_GPC,
39+
40 /* This is a 64 bit reloc that stores the 32 bit pc relative
41 value in two words (with an imm instruction). The relocation is
42 GOT offset */
43diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
44index d001437b3f..035e71f311 100644
45--- a/bfd/elf32-microblaze.c
46+++ b/bfd/elf32-microblaze.c
47@@ -116,6 +116,20 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
48 0x0000ffff, /* Dest Mask. */
49 TRUE), /* PC relative offset? */
50
51+ HOWTO (R_MICROBLAZE_IMML_64, /* Type. */
52+ 0, /* Rightshift. */
53+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
54+ 16, /* Bitsize. */
55+ TRUE, /* PC_relative. */
56+ 0, /* Bitpos. */
57+ complain_overflow_dont, /* Complain on overflow. */
58+ bfd_elf_generic_reloc,/* Special Function. */
59+ "R_MICROBLAZE_IMML_64", /* Name. */
60+ FALSE, /* Partial Inplace. */
61+ 0, /* Source Mask. */
62+ 0x0000ffff, /* Dest Mask. */
63+ FALSE), /* PC relative offset? */
64+
65 /* A 64 bit relocation. Table entry not really used. */
66 HOWTO (R_MICROBLAZE_64, /* Type. */
67 0, /* Rightshift. */
68@@ -280,6 +294,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
69 0x0000ffff, /* Dest Mask. */
70 TRUE), /* PC relative offset? */
71
72+ /* A 64 bit GOTPC relocation. Table-entry not really used. */
73+ HOWTO (R_MICROBLAZE_GPC_64, /* Type. */
74+ 0, /* Rightshift. */
75+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
76+ 16, /* Bitsize. */
77+ TRUE, /* PC_relative. */
78+ 0, /* Bitpos. */
79+ complain_overflow_dont, /* Complain on overflow. */
80+ bfd_elf_generic_reloc, /* Special Function. */
81+ "R_MICROBLAZE_GPC_64", /* Name. */
82+ FALSE, /* Partial Inplace. */
83+ 0, /* Source Mask. */
84+ 0x0000ffff, /* Dest Mask. */
85+ TRUE), /* PC relative offset? */
86+
87 /* A 64 bit GOT relocation. Table-entry not really used. */
88 HOWTO (R_MICROBLAZE_GOT_64, /* Type. */
89 0, /* Rightshift. */
90@@ -619,9 +648,15 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
91 case BFD_RELOC_VTABLE_ENTRY:
92 microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
93 break;
94+ case BFD_RELOC_MICROBLAZE_64:
95+ microblaze_reloc = R_MICROBLAZE_IMML_64;
96+ break;
97 case BFD_RELOC_MICROBLAZE_64_GOTPC:
98 microblaze_reloc = R_MICROBLAZE_GOTPC_64;
99 break;
100+ case BFD_RELOC_MICROBLAZE_64_GPC:
101+ microblaze_reloc = R_MICROBLAZE_GPC_64;
102+ break;
103 case BFD_RELOC_MICROBLAZE_64_GOT:
104 microblaze_reloc = R_MICROBLAZE_GOT_64;
105 break;
106@@ -1467,7 +1502,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
107 if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
108 {
109 relocation += addend;
110- if (r_type == R_MICROBLAZE_32)
111+ if (r_type == R_MICROBLAZE_32)// || r_type == R_MICROBLAZE_IMML_64)
112 bfd_put_32 (input_bfd, relocation, contents + offset);
113 else
114 {
115@@ -1933,6 +1968,28 @@ microblaze_elf_relax_section (bfd *abfd,
116 irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
117 }
118 break;
119+ case R_MICROBLAZE_IMML_64:
120+ {
121+ /* This was a PC-relative instruction that was
122+ completely resolved. */
123+ int sfix, efix;
124+ unsigned int val;
125+ bfd_vma target_address;
126+ target_address = irel->r_addend + irel->r_offset;
127+ sfix = calc_fixup (irel->r_offset, 0, sec);
128+ efix = calc_fixup (target_address, 0, sec);
129+
130+ /* Validate the in-band val. */
131+ val = bfd_get_32 (abfd, contents + irel->r_offset);
132+ if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
133+ fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
134+ }
135+ irel->r_addend -= (efix - sfix);
136+ /* Should use HOWTO. */
137+ microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset,
138+ irel->r_addend);
139+ }
140+ break;
141 case R_MICROBLAZE_NONE:
142 case R_MICROBLAZE_32_NONE:
143 {
144@@ -2037,9 +2094,9 @@ microblaze_elf_relax_section (bfd *abfd,
145 microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
146 irelscan->r_addend);
147 }
148- if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
149- {
150- isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
151+ if (ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)// || ELF32_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_IMML_64)
152+ {
153+ isym = isymbuf + ELF32_R_SYM (irelscan->r_info);
154
155 /* Look at the reloc only if the value has been resolved. */
156 if (isym->st_shndx == shndx
157diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
158index 0f43ae6ea8..56a45f2a05 100644
159--- a/bfd/elf64-microblaze.c
160+++ b/bfd/elf64-microblaze.c
161@@ -116,6 +116,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
162 0x0000ffff, /* Dest Mask. */
163 TRUE), /* PC relative offset? */
164
165+ /* A 64 bit relocation. Table entry not really used. */
166+ HOWTO (R_MICROBLAZE_IMML_64, /* Type. */
167+ 0, /* Rightshift. */
168+ 4, /* Size (0 = byte, 1 = short, 2 = long). */
169+ 64, /* Bitsize. */
170+ TRUE, /* PC_relative. */
171+ 0, /* Bitpos. */
172+ complain_overflow_dont, /* Complain on overflow. */
173+ bfd_elf_generic_reloc,/* Special Function. */
174+ "R_MICROBLAZE_IMML_64", /* Name. */
175+ FALSE, /* Partial Inplace. */
176+ 0, /* Source Mask. */
177+ 0x0000ffff, /* Dest Mask. */
178+ TRUE), /* PC relative offset? */
179+
180 /* A 64 bit relocation. Table entry not really used. */
181 HOWTO (R_MICROBLAZE_64, /* Type. */
182 0, /* Rightshift. */
183@@ -265,6 +280,21 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
184 0x0000ffff, /* Dest Mask. */
185 TRUE), /* PC relative offset? */
186
187+ /* A 64 bit GOTPC relocation. Table-entry not really used. */
188+ HOWTO (R_MICROBLAZE_GPC_64, /* Type. */
189+ 0, /* Rightshift. */
190+ 2, /* Size (0 = byte, 1 = short, 2 = long). */
191+ 16, /* Bitsize. */
192+ TRUE, /* PC_relative. */
193+ 0, /* Bitpos. */
194+ complain_overflow_dont, /* Complain on overflow. */
195+ bfd_elf_generic_reloc, /* Special Function. */
196+ "R_MICROBLAZE_GPC_64", /* Name. */
197+ FALSE, /* Partial Inplace. */
198+ 0, /* Source Mask. */
199+ 0x0000ffff, /* Dest Mask. */
200+ TRUE), /* PC relative offset? */
201+
202 /* A 64 bit GOT relocation. Table-entry not really used. */
203 HOWTO (R_MICROBLAZE_GOT_64, /* Type. */
204 0, /* Rightshift. */
205@@ -589,9 +619,15 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
206 case BFD_RELOC_VTABLE_ENTRY:
207 microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
208 break;
209+ case BFD_RELOC_MICROBLAZE_64:
210+ microblaze_reloc = R_MICROBLAZE_IMML_64;
211+ break;
212 case BFD_RELOC_MICROBLAZE_64_GOTPC:
213 microblaze_reloc = R_MICROBLAZE_GOTPC_64;
214 break;
215+ case BFD_RELOC_MICROBLAZE_64_GPC:
216+ microblaze_reloc = R_MICROBLAZE_GPC_64;
217+ break;
218 case BFD_RELOC_MICROBLAZE_64_GOT:
219 microblaze_reloc = R_MICROBLAZE_GOT_64;
220 break;
221@@ -1161,6 +1197,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
222 break; /* Do nothing. */
223
224 case (int) R_MICROBLAZE_GOTPC_64:
225+ case (int) R_MICROBLAZE_GPC_64:
226 relocation = htab->sgotplt->output_section->vma
227 + htab->sgotplt->output_offset;
228 relocation -= (input_section->output_section->vma
229@@ -1431,7 +1468,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
230 if (r_symndx == STN_UNDEF || (input_section->flags & SEC_ALLOC) == 0)
231 {
232 relocation += addend;
233- if (r_type == R_MICROBLAZE_32)
234+ if (r_type == R_MICROBLAZE_32)// || r_type == R_MICROBLAZE_IMML_64)
235 bfd_put_32 (input_bfd, relocation, contents + offset);
236 else
237 {
238@@ -1876,6 +1913,28 @@ microblaze_elf_relax_section (bfd *abfd,
239 irel->r_addend -= calc_fixup (irel->r_addend, 0, sec);
240 }
241 break;
242+ case R_MICROBLAZE_IMML_64:
243+ {
244+ /* This was a PC-relative instruction that was
245+ completely resolved. */
246+ int sfix, efix;
247+ unsigned int val;
248+ bfd_vma target_address;
249+ target_address = irel->r_addend + irel->r_offset;
250+ sfix = calc_fixup (irel->r_offset, 0, sec);
251+ efix = calc_fixup (target_address, 0, sec);
252+
253+ /* Validate the in-band val. */
254+ val = bfd_get_32 (abfd, contents + irel->r_offset);
255+ if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
256+ fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
257+ }
258+ irel->r_addend -= (efix - sfix);
259+ /* Should use HOWTO. */
260+ microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset,
261+ irel->r_addend);
262+ }
263+ break;
264 case R_MICROBLAZE_NONE:
265 case R_MICROBLAZE_32_NONE:
266 {
267diff --git a/bfd/libbfd.h b/bfd/libbfd.h
268index feb9fada1e..450653f2d8 100644
269--- a/bfd/libbfd.h
270+++ b/bfd/libbfd.h
271@@ -2903,7 +2903,9 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
272 "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM",
273 "BFD_RELOC_MICROBLAZE_32_NONE",
274 "BFD_RELOC_MICROBLAZE_64_NONE",
275+ "BFD_RELOC_MICROBLAZE_64",
276 "BFD_RELOC_MICROBLAZE_64_GOTPC",
277+ "BFD_RELOC_MICROBLAZE_64_GPC",
278 "BFD_RELOC_MICROBLAZE_64_GOT",
279 "BFD_RELOC_MICROBLAZE_64_PLT",
280 "BFD_RELOC_MICROBLAZE_64_GOTOFF",
281diff --git a/bfd/reloc.c b/bfd/reloc.c
282index 87753ae4f0..ccf29f54cf 100644
283--- a/bfd/reloc.c
284+++ b/bfd/reloc.c
285@@ -6803,12 +6803,24 @@ ENUMDOC
286 done here - only used for relaxing
287 ENUM
288 BFD_RELOC_MICROBLAZE_64_NONE
289+ENUMDOC
290+ This is a 32 bit reloc that stores the 32 bit pc relative
291+ value in two words (with an imml instruction). No relocation is
292+ done here - only used for relaxing
293+ENUM
294+ BFD_RELOC_MICROBLAZE_64
295 ENUMDOC
296 This is a 64 bit reloc that stores the 32 bit pc relative
297 value in two words (with an imm instruction). No relocation is
298 done here - only used for relaxing
299 ENUM
300 BFD_RELOC_MICROBLAZE_64_GOTPC
301+ENUMDOC
302+ This is a 64 bit reloc that stores the 32 bit pc relative
303+ value in two words (with an imml instruction). No relocation is
304+ done here - only used for relaxing
305+ENUM
306+ BFD_RELOC_MICROBLAZE_64_GPC
307 ENUMDOC
308 This is a 64 bit reloc that stores the 32 bit pc relative
309 value in two words (with an imm instruction). The relocation is
310diff --git a/include/elf/microblaze.h b/include/elf/microblaze.h
311index 6ee0966444..16b2736577 100644
312--- a/include/elf/microblaze.h
313+++ b/include/elf/microblaze.h
314@@ -62,6 +62,8 @@ START_RELOC_NUMBERS (elf_microblaze_reloc_type)
315 RELOC_NUMBER (R_MICROBLAZE_TEXTREL_64, 31) /* TEXT Entry offset 64-bit. */
316 RELOC_NUMBER (R_MICROBLAZE_TEXTREL_32_LO, 32) /* TEXT Entry offset 32-bit. */
317 RELOC_NUMBER (R_MICROBLAZE_32_NONE, 33)
318+ RELOC_NUMBER (R_MICROBLAZE_IMML_64, 34)
319+ RELOC_NUMBER (R_MICROBLAZE_GPC_64, 35) /* GOT entry offset. */
320
321 END_RELOC_NUMBERS (R_MICROBLAZE_max)
322
323diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
324index 985834b8df..9b6264b61c 100644
325--- a/opcodes/microblaze-opc.h
326+++ b/opcodes/microblaze-opc.h
327@@ -538,8 +538,8 @@ struct op_code_struct
328 {"llr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xC8000300, OPCODE_MASK_H4, llr, memory_load_inst },
329 {"sl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000100, OPCODE_MASK_H4, sl, memory_store_inst },
330 {"slr", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xD8000300, OPCODE_MASK_H4, slr, memory_store_inst },
331- {"lli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */
332- {"sli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */
333+ {"lli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xEC000000, OPCODE_MASK_H, invalid_inst, memory_load_inst }, /* Identical to 32-bit */
334+ {"sli", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xFC000000, OPCODE_MASK_H, invalid_inst, memory_store_inst }, /* Identical to 32-bit */
335 {"lla", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* lla translates to addlik */
336 {"dadd", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000400, OPCODE_MASK_H4, dadd, arithmetic_inst },
337 {"drsub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000480, OPCODE_MASK_H4, drsub, arithmetic_inst },
338diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
339index 076dbcd0b3..5f2e190d23 100644
340--- a/opcodes/microblaze-opcm.h
341+++ b/opcodes/microblaze-opcm.h
342@@ -40,8 +40,8 @@ enum microblaze_instr
343 imm, rtsd, rtid, rtbd, rted, bri, brid, brlid, brai, braid, bralid,
344 brki, beqi, beqid, bnei, bneid, blti, bltid, blei, bleid, bgti,
345 bgtid, bgei, bgeid, lbu, lbuea, lbur, lhu, lhuea, lhur, lw, lwea, lwr, lwx,
346- sb, sbea, sbr, sh, shea, shr, sw, swea, swr, swx, lbui, lhui, lwi,
347- sbi, shi, swi, msrset, msrclr, tuqula, fadd, frsub, fmul, fdiv,
348+ sb, sbea, sbr, sh, shea, shr, sw, swea, swr, swx, lbui, lhui, lwi, lli,
349+ sbi, shi, sli, swi, msrset, msrclr, tuqula, fadd, frsub, fmul, fdiv,
350 fcmp_lt, fcmp_eq, fcmp_le, fcmp_gt, fcmp_ne, fcmp_ge, fcmp_un, flt,
351 fint, fsqrt,
352 tget, tcget, tnget, tncget, tput, tcput, tnput, tncput,
353--
3542.17.1
355
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0017-Patch-Microblaze-negl-instruction-is-overriding-rsub.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0017-Patch-Microblaze-negl-instruction-is-overriding-rsub.patch
new file mode 100644
index 00000000..26938396
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0017-Patch-Microblaze-negl-instruction-is-overriding-rsub.patch
@@ -0,0 +1,36 @@
1From 4010e83aa48f0415e4478d70871aa87cb204d350 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Tue, 11 Sep 2018 13:48:33 +0530
4Subject: [PATCH 17/43] [Patch,Microblaze] : negl instruction is overriding
5 rsubl,fixed it by changing the instruction order...
6
7---
8 opcodes/microblaze-opc.h | 4 ++--
9 1 file changed, 2 insertions(+), 2 deletions(-)
10
11diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
12index 9b6264b61c..824afc0ab0 100644
13--- a/opcodes/microblaze-opc.h
14+++ b/opcodes/microblaze-opc.h
15@@ -275,9 +275,7 @@ struct op_code_struct
16 {"la", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* la translates to addik. */
17 {"tuqula",INST_TYPE_RD, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x3000002A, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* tuqula rd translates to addik rd, r0, 42. */
18 {"not", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA800FFFF, OPCODE_MASK_H34, invalid_inst, logical_inst }, /* not translates to xori rd,ra,-1. */
19- {"neg", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* neg translates to rsub rd, ra, r0. */
20 {"rtb", INST_TYPE_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB6000004, OPCODE_MASK_H1, invalid_inst, return_inst }, /* rtb translates to rts rd, 4. */
21- {"sub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* sub translates to rsub rd, rb, ra. */
22 {"lmi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xE8000000, OPCODE_MASK_H, invalid_inst, memory_load_inst },
23 {"smi", INST_TYPE_RD_R1_IMM, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xF8000000, OPCODE_MASK_H, invalid_inst, memory_store_inst },
24 {"msrset",INST_TYPE_RD_IMM15, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x94100000, OPCODE_MASK_H23N, msrset, special_inst },
25@@ -555,6 +553,8 @@ struct op_code_struct
26 {"dbl", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000680, OPCODE_MASK_H4, dbl, arithmetic_inst },
27 {"dlong", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000700, OPCODE_MASK_H4, dlong, arithmetic_inst },
28 {"dsqrt", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x58000780, OPCODE_MASK_H4, dsqrt, arithmetic_inst },
29+ {"neg", INST_TYPE_RD_R1, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* neg translates to rsub rd, ra, r0. */
30+ {"sub", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x04000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* sub translates to rsub rd, rb, ra. */
31
32 {"", 0, 0, 0, 0, 0, 0, 0, 0},
33 };
34--
352.17.1
36
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0018-Added-relocations-for-MB-X.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0018-Added-relocations-for-MB-X.patch
new file mode 100644
index 00000000..93ec10fd
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0018-Added-relocations-for-MB-X.patch
@@ -0,0 +1,113 @@
1From b625d19f8b86dd81c32f21793cc3e038ca275e57 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Tue, 11 Sep 2018 17:30:17 +0530
4Subject: [PATCH 18/43] Added relocations for MB-X
5
6---
7 bfd/bfd-in2.h | 11 +++--
8 bfd/libbfd.h | 4 +-
9 bfd/reloc.c | 26 ++++++-----
10 4 files changed, 62 insertions(+), 69 deletions(-)
11
12diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
13index 4f777059d8..de46e78902 100644
14--- a/bfd/bfd-in2.h
15+++ b/bfd/bfd-in2.h
16@@ -5872,15 +5872,20 @@ done here - only used for relaxing */
17 BFD_RELOC_MICROBLAZE_32_NONE,
18
19 /* This is a 64 bit reloc that stores the 32 bit pc relative
20- * +value in two words (with an imm instruction). No relocation is
21+ * +value in two words (with an imml instruction). No relocation is
22 * +done here - only used for relaxing */
23- BFD_RELOC_MICROBLAZE_64_NONE,
24+ BFD_RELOC_MICROBLAZE_64_PCREL,
25
26-/* This is a 64 bit reloc that stores the 32 bit pc relative
27+/* This is a 64 bit reloc that stores the 32 bit relative
28 * +value in two words (with an imml instruction). No relocation is
29 * +done here - only used for relaxing */
30 BFD_RELOC_MICROBLAZE_64,
31
32+/* This is a 64 bit reloc that stores the 32 bit pc relative
33+ * +value in two words (with an imm instruction). No relocation is
34+ * +done here - only used for relaxing */
35+ BFD_RELOC_MICROBLAZE_64_NONE,
36+
37 /* This is a 64 bit reloc that stores the 32 bit pc relative
38 value in two words (with an imm instruction). The relocation is
39 PC-relative GOT offset */
40diff --git a/bfd/libbfd.h b/bfd/libbfd.h
41index 450653f2d8..d87a183d5e 100644
42--- a/bfd/libbfd.h
43+++ b/bfd/libbfd.h
44@@ -2903,14 +2903,14 @@ static const char *const bfd_reloc_code_real_names[] = { "@@uninitialized@@",
45 "BFD_RELOC_MICROBLAZE_32_SYM_OP_SYM",
46 "BFD_RELOC_MICROBLAZE_32_NONE",
47 "BFD_RELOC_MICROBLAZE_64_NONE",
48- "BFD_RELOC_MICROBLAZE_64",
49 "BFD_RELOC_MICROBLAZE_64_GOTPC",
50- "BFD_RELOC_MICROBLAZE_64_GPC",
51 "BFD_RELOC_MICROBLAZE_64_GOT",
52 "BFD_RELOC_MICROBLAZE_64_PLT",
53 "BFD_RELOC_MICROBLAZE_64_GOTOFF",
54 "BFD_RELOC_MICROBLAZE_32_GOTOFF",
55 "BFD_RELOC_MICROBLAZE_COPY",
56+ "BFD_RELOC_MICROBLAZE_64",
57+ "BFD_RELOC_MICROBLAZE_64_PCREL",
58 "BFD_RELOC_MICROBLAZE_64_TLS",
59 "BFD_RELOC_MICROBLAZE_64_TLSGD",
60 "BFD_RELOC_MICROBLAZE_64_TLSLD",
61diff --git a/bfd/reloc.c b/bfd/reloc.c
62index ccf29f54cf..861f2d48c0 100644
63--- a/bfd/reloc.c
64+++ b/bfd/reloc.c
65@@ -6803,24 +6803,12 @@ ENUMDOC
66 done here - only used for relaxing
67 ENUM
68 BFD_RELOC_MICROBLAZE_64_NONE
69-ENUMDOC
70- This is a 32 bit reloc that stores the 32 bit pc relative
71- value in two words (with an imml instruction). No relocation is
72- done here - only used for relaxing
73-ENUM
74- BFD_RELOC_MICROBLAZE_64
75 ENUMDOC
76 This is a 64 bit reloc that stores the 32 bit pc relative
77 value in two words (with an imm instruction). No relocation is
78 done here - only used for relaxing
79 ENUM
80 BFD_RELOC_MICROBLAZE_64_GOTPC
81-ENUMDOC
82- This is a 64 bit reloc that stores the 32 bit pc relative
83- value in two words (with an imml instruction). No relocation is
84- done here - only used for relaxing
85-ENUM
86- BFD_RELOC_MICROBLAZE_64_GPC
87 ENUMDOC
88 This is a 64 bit reloc that stores the 32 bit pc relative
89 value in two words (with an imm instruction). The relocation is
90@@ -6906,6 +6894,20 @@ ENUMDOC
91 value in two words (with an imm instruction). The relocation is
92 relative offset from start of TEXT.
93
94+ This is a 64 bit reloc that stores 64-bit thread pointer relative offset
95+ to two words (uses imml instruction).
96+ENUM
97+BFD_RELOC_MICROBLAZE_64,
98+ENUMDOC
99+ This is a 64 bit reloc that stores the 64 bit pc relative
100+ value in two words (with an imml instruction). No relocation is
101+ done here - only used for relaxing
102+ENUM
103+BFD_RELOC_MICROBLAZE_64_PCREL,
104+ENUMDOC
105+ This is a 32 bit reloc that stores the 32 bit pc relative
106+ value in two words (with an imml instruction). No relocation is
107+ done here - only used for relaxing
108 ENUM
109 BFD_RELOC_AARCH64_RELOC_START
110 ENUMDOC
111--
1122.17.1
113
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0019-Fixed-MB-x-relocation-issues.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0019-Fixed-MB-x-relocation-issues.patch
new file mode 100644
index 00000000..4a35a597
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0019-Fixed-MB-x-relocation-issues.patch
@@ -0,0 +1,115 @@
1From f190b9380c325b48697755328f4193791a758e55 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Fri, 28 Sep 2018 12:04:55 +0530
4Subject: [PATCH 19/43] -Fixed MB-x relocation issues -Added imml for required
5 MB-x instructions
6
7---
8 bfd/elf64-microblaze.c | 68 ++++++++++++++---
9 3 files changed, 167 insertions(+), 55 deletions(-)
10
11diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
12index 56a45f2a05..54a2461037 100644
13--- a/bfd/elf64-microblaze.c
14+++ b/bfd/elf64-microblaze.c
15@@ -1476,8 +1476,17 @@ microblaze_elf_relocate_section (bfd *output_bfd,
16 relocation -= (input_section->output_section->vma
17 + input_section->output_offset
18 + offset + INST_WORD_SIZE);
19- bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
20+ unsigned long insn = bfd_get_32 (input_bfd, contents + offset +endian);
21+ if (insn == 0xb2000000 || insn == 0xb2ffffff)
22+ {
23+ insn &= ~0x00ffffff;
24+ insn |= (relocation >> 16) & 0xffffff;
25+ bfd_put_32 (input_bfd, insn,
26 contents + offset + endian);
27+ }
28+ else
29+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
30+ contents + offset + endian);
31 bfd_put_16 (input_bfd, relocation & 0xffff,
32 contents + offset + endian + INST_WORD_SIZE);
33 }
34@@ -1567,11 +1576,28 @@ microblaze_elf_relocate_section (bfd *output_bfd,
35 else
36 {
37 if (r_type == R_MICROBLAZE_64_PCREL)
38- relocation -= (input_section->output_section->vma
39- + input_section->output_offset
40- + offset + INST_WORD_SIZE);
41- bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
42+ {
43+ if (!input_section->output_section->vma &&
44+ !input_section->output_offset && !offset)
45+ relocation -= (input_section->output_section->vma
46+ + input_section->output_offset
47+ + offset);
48+ else
49+ relocation -= (input_section->output_section->vma
50+ + input_section->output_offset
51+ + offset + INST_WORD_SIZE);
52+ }
53+ unsigned long insn = bfd_get_32 (input_bfd, contents + offset +endian);
54+ if (insn == 0xb2000000 || insn == 0xb2ffffff)
55+ {
56+ insn &= ~0x00ffffff;
57+ insn |= (relocation >> 16) & 0xffffff;
58+ bfd_put_32 (input_bfd, insn,
59 contents + offset + endian);
60+ }
61+ else
62+ bfd_put_16 (input_bfd, (relocation >> 16) & 0xffff,
63+ contents + offset + endian);
64 bfd_put_16 (input_bfd, relocation & 0xffff,
65 contents + offset + endian + INST_WORD_SIZE);
66 }
67@@ -1690,9 +1716,19 @@ static void
68 microblaze_bfd_write_imm_value_32 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
69 {
70 unsigned long instr = bfd_get_32 (abfd, bfd_addr);
71- instr &= ~0x0000ffff;
72- instr |= (val & 0x0000ffff);
73- bfd_put_32 (abfd, instr, bfd_addr);
74+
75+ if (instr == 0xb2000000 || instr == 0xb2ffffff)
76+ {
77+ instr &= ~0x00ffffff;
78+ instr |= (val & 0xffffff);
79+ bfd_put_32 (abfd, instr, bfd_addr);
80+ }
81+ else
82+ {
83+ instr &= ~0x0000ffff;
84+ instr |= (val & 0x0000ffff);
85+ bfd_put_32 (abfd, instr, bfd_addr);
86+ }
87 }
88
89 /* Read-modify-write into the bfd, an immediate value into appropriate fields of
90@@ -1704,10 +1740,18 @@ microblaze_bfd_write_imm_value_64 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
91 unsigned long instr_lo;
92
93 instr_hi = bfd_get_32 (abfd, bfd_addr);
94- instr_hi &= ~0x0000ffff;
95- instr_hi |= ((val >> 16) & 0x0000ffff);
96- bfd_put_32 (abfd, instr_hi, bfd_addr);
97-
98+ if (instr_hi == 0xb2000000 || instr_hi == 0xb2ffffff)
99+ {
100+ instr_hi &= ~0x00ffffff;
101+ instr_hi |= (val >> 16) & 0xffffff;
102+ bfd_put_32 (abfd, instr_hi,bfd_addr);
103+ }
104+ else
105+ {
106+ instr_hi &= ~0x0000ffff;
107+ instr_hi |= ((val >> 16) & 0x0000ffff);
108+ bfd_put_32 (abfd, instr_hi, bfd_addr);
109+ }
110 instr_lo = bfd_get_32 (abfd, bfd_addr + INST_WORD_SIZE);
111 instr_lo &= ~0x0000ffff;
112 instr_lo |= (val & 0x0000ffff);
113--
1142.17.1
115
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0020-Fixing-the-branch-related-issues.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0020-Fixing-the-branch-related-issues.patch
new file mode 100644
index 00000000..2e790dc1
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0020-Fixing-the-branch-related-issues.patch
@@ -0,0 +1,25 @@
1From 534688ca48be148ade9bb1daf77c41c4b221ac0e Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Sun, 30 Sep 2018 17:06:58 +0530
4Subject: [PATCH 20/43] Fixing the branch related issues
5
6---
7 bfd/elf64-microblaze.c | 2 +-
8 1 file changed, 1 insertion(+), 1 deletion(-)
9
10diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
11index 54a2461037..e9b3cf3a86 100644
12--- a/bfd/elf64-microblaze.c
13+++ b/bfd/elf64-microblaze.c
14@@ -2532,7 +2532,7 @@ microblaze_elf_check_relocs (bfd * abfd,
15
16 /* PR15323, ref flags aren't set for references in the same
17 object. */
18- h->root.non_ir_ref = 1;
19+ h->root.non_ir_ref_regular = 1;
20 }
21
22 switch (r_type)
23--
242.17.1
25
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0021-Fixed-address-computation-issues-with-64bit-address.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0021-Fixed-address-computation-issues-with-64bit-address.patch
new file mode 100644
index 00000000..dffdbd3a
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0021-Fixed-address-computation-issues-with-64bit-address.patch
@@ -0,0 +1,97 @@
1From a19471b62a23803a062693a61c783efc05e2cd33 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Tue, 9 Oct 2018 10:14:22 +0530
4Subject: [PATCH 21/43] - Fixed address computation issues with 64bit address -
5 Fixed imml dissassamble issue
6
7---
8 bfd/bfd-in2.h | 5 +++
9 bfd/elf64-microblaze.c | 14 ++++----
10 opcodes/microblaze-dis.c | 2 +-
11 4 files changed, 79 insertions(+), 16 deletions(-)
12
13diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
14index de46e78902..33c9cb62d9 100644
15--- a/bfd/bfd-in2.h
16+++ b/bfd/bfd-in2.h
17@@ -5881,6 +5881,11 @@ done here - only used for relaxing */
18 * +done here - only used for relaxing */
19 BFD_RELOC_MICROBLAZE_64,
20
21+/* This is a 64 bit reloc that stores the 32 bit relative
22+ * +value in two words (with an imml instruction). No relocation is
23+ * +done here - only used for relaxing */
24+ BFD_RELOC_MICROBLAZE_EA64,
25+
26 /* This is a 64 bit reloc that stores the 32 bit pc relative
27 * +value in two words (with an imm instruction). No relocation is
28 * +done here - only used for relaxing */
29diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
30index e9b3cf3a86..40f10aac6d 100644
31--- a/bfd/elf64-microblaze.c
32+++ b/bfd/elf64-microblaze.c
33@@ -121,15 +121,15 @@ static reloc_howto_type microblaze_elf_howto_raw[] =
34 0, /* Rightshift. */
35 4, /* Size (0 = byte, 1 = short, 2 = long). */
36 64, /* Bitsize. */
37- TRUE, /* PC_relative. */
38+ FALSE, /* PC_relative. */
39 0, /* Bitpos. */
40 complain_overflow_dont, /* Complain on overflow. */
41 bfd_elf_generic_reloc,/* Special Function. */
42 "R_MICROBLAZE_IMML_64", /* Name. */
43 FALSE, /* Partial Inplace. */
44 0, /* Source Mask. */
45- 0x0000ffff, /* Dest Mask. */
46- TRUE), /* PC relative offset? */
47+ 0xffffffffffffff, /* Dest Mask. */
48+ FALSE), /* PC relative offset? */
49
50 /* A 64 bit relocation. Table entry not really used. */
51 HOWTO (R_MICROBLAZE_64, /* Type. */
52@@ -585,9 +585,9 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
53 case BFD_RELOC_32:
54 microblaze_reloc = R_MICROBLAZE_32;
55 break;
56- /* RVA is treated the same as 32 */
57+ /* RVA is treated the same as 64 */
58 case BFD_RELOC_RVA:
59- microblaze_reloc = R_MICROBLAZE_32;
60+ microblaze_reloc = R_MICROBLAZE_IMML_64;
61 break;
62 case BFD_RELOC_32_PCREL:
63 microblaze_reloc = R_MICROBLAZE_32_PCREL;
64@@ -619,7 +619,7 @@ microblaze_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
65 case BFD_RELOC_VTABLE_ENTRY:
66 microblaze_reloc = R_MICROBLAZE_GNU_VTENTRY;
67 break;
68- case BFD_RELOC_MICROBLAZE_64:
69+ case BFD_RELOC_MICROBLAZE_EA64:
70 microblaze_reloc = R_MICROBLAZE_IMML_64;
71 break;
72 case BFD_RELOC_MICROBLAZE_64_GOTPC:
73@@ -1969,7 +1969,7 @@ microblaze_elf_relax_section (bfd *abfd,
74 efix = calc_fixup (target_address, 0, sec);
75
76 /* Validate the in-band val. */
77- val = bfd_get_32 (abfd, contents + irel->r_offset);
78+ val = bfd_get_64 (abfd, contents + irel->r_offset);
79 if (val != irel->r_addend && ELF64_R_TYPE (irel->r_info) == R_MICROBLAZE_32_NONE) {
80 fprintf(stderr, "%d: CORRUPT relax reloc %x %lx\n", __LINE__, val, irel->r_addend);
81 }
82diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
83index 20ea6a885a..f679a43606 100644
84--- a/opcodes/microblaze-dis.c
85+++ b/opcodes/microblaze-dis.c
86@@ -61,7 +61,7 @@ get_field_imml (long instr)
87 {
88 char tmpstr[25];
89
90- sprintf (tmpstr, "%d", (short)((instr & IMML_MASK) >> IMM_LOW));
91+ sprintf (tmpstr, "%d", (int)((instr & IMML_MASK) >> IMM_LOW));
92 return (strdup (tmpstr));
93 }
94
95--
962.17.1
97
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0022-Adding-new-relocation-to-support-64bit-rodata.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0022-Adding-new-relocation-to-support-64bit-rodata.patch
new file mode 100644
index 00000000..e79b6626
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0022-Adding-new-relocation-to-support-64bit-rodata.patch
@@ -0,0 +1,69 @@
1From 2aa455f838644cd804ec93aeea0d30bb265e91df Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Sat, 13 Oct 2018 21:17:01 +0530
4Subject: [PATCH 22/43] Adding new relocation to support 64bit rodata
5
6---
7 bfd/elf64-microblaze.c | 11 +++++++--
8 2 files changed, 54 insertions(+), 6 deletions(-)
9
10diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
11index 40f10aac6d..4d9b90647f 100644
12--- a/bfd/elf64-microblaze.c
13+++ b/bfd/elf64-microblaze.c
14@@ -1461,6 +1461,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
15 case (int) R_MICROBLAZE_64_PCREL :
16 case (int) R_MICROBLAZE_64:
17 case (int) R_MICROBLAZE_32:
18+ case (int) R_MICROBLAZE_IMML_64:
19 {
20 /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
21 from removed linkonce sections, or sections discarded by
22@@ -1470,6 +1471,8 @@ microblaze_elf_relocate_section (bfd *output_bfd,
23 relocation += addend;
24 if (r_type == R_MICROBLAZE_32)// || r_type == R_MICROBLAZE_IMML_64)
25 bfd_put_32 (input_bfd, relocation, contents + offset);
26+ else if (r_type == R_MICROBLAZE_IMML_64)
27+ bfd_put_64 (input_bfd, relocation, contents + offset);
28 else
29 {
30 if (r_type == R_MICROBLAZE_64_PCREL)
31@@ -1547,7 +1550,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
32 }
33 else
34 {
35- if (r_type == R_MICROBLAZE_32)
36+ if (r_type == R_MICROBLAZE_32 || r_type == R_MICROBLAZE_IMML_64)
37 {
38 outrel.r_info = ELF64_R_INFO (0, R_MICROBLAZE_REL);
39 outrel.r_addend = relocation + addend;
40@@ -1573,6 +1576,8 @@ microblaze_elf_relocate_section (bfd *output_bfd,
41 relocation += addend;
42 if (r_type == R_MICROBLAZE_32)
43 bfd_put_32 (input_bfd, relocation, contents + offset);
44+ else if (r_type == R_MICROBLAZE_IMML_64)
45+ bfd_put_64 (input_bfd, relocation, contents + offset + endian);
46 else
47 {
48 if (r_type == R_MICROBLAZE_64_PCREL)
49@@ -2085,7 +2090,8 @@ microblaze_elf_relax_section (bfd *abfd,
50 microblaze_bfd_write_imm_value_32 (abfd, ocontents + irelscan->r_offset,
51 irelscan->r_addend);
52 }
53- if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32)
54+ if (ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_32
55+ || ELF64_R_TYPE (irelscan->r_info) == (int) R_MICROBLAZE_IMML_64)
56 {
57 isym = isymbuf + ELF64_R_SYM (irelscan->r_info);
58
59@@ -2591,6 +2597,7 @@ microblaze_elf_check_relocs (bfd * abfd,
60 case R_MICROBLAZE_64:
61 case R_MICROBLAZE_64_PCREL:
62 case R_MICROBLAZE_32:
63+ case R_MICROBLAZE_IMML_64:
64 {
65 if (h != NULL && !bfd_link_pic (info))
66 {
67--
682.17.1
69
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0023-fixing-the-.bss-relocation-issue.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0023-fixing-the-.bss-relocation-issue.patch
new file mode 100644
index 00000000..2458df6c
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0023-fixing-the-.bss-relocation-issue.patch
@@ -0,0 +1,76 @@
1From 3240839197b1c42b3cd6e77c5b3b47aa7a1378a4 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Wed, 24 Oct 2018 12:34:37 +0530
4Subject: [PATCH 23/43] fixing the .bss relocation issue
5
6---
7 bfd/elf64-microblaze.c | 18 ++++++++++++------
8 1 file changed, 12 insertions(+), 6 deletions(-)
9
10diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
11index 4d9b90647f..184b7d560d 100644
12--- a/bfd/elf64-microblaze.c
13+++ b/bfd/elf64-microblaze.c
14@@ -1480,7 +1480,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
15 + input_section->output_offset
16 + offset + INST_WORD_SIZE);
17 unsigned long insn = bfd_get_32 (input_bfd, contents + offset +endian);
18- if (insn == 0xb2000000 || insn == 0xb2ffffff)
19+ if ((insn & 0xff000000) == 0xb2000000)
20 {
21 insn &= ~0x00ffffff;
22 insn |= (relocation >> 16) & 0xffffff;
23@@ -1593,7 +1593,7 @@ microblaze_elf_relocate_section (bfd *output_bfd,
24 + offset + INST_WORD_SIZE);
25 }
26 unsigned long insn = bfd_get_32 (input_bfd, contents + offset +endian);
27- if (insn == 0xb2000000 || insn == 0xb2ffffff)
28+ if ((insn & 0xff000000) == 0xb2000000)
29 {
30 insn &= ~0x00ffffff;
31 insn |= (relocation >> 16) & 0xffffff;
32@@ -1722,7 +1722,7 @@ microblaze_bfd_write_imm_value_32 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
33 {
34 unsigned long instr = bfd_get_32 (abfd, bfd_addr);
35
36- if (instr == 0xb2000000 || instr == 0xb2ffffff)
37+ if ((instr & 0xff000000) == 0xb2000000)
38 {
39 instr &= ~0x00ffffff;
40 instr |= (val & 0xffffff);
41@@ -1745,7 +1745,7 @@ microblaze_bfd_write_imm_value_64 (bfd *abfd, bfd_byte *bfd_addr, bfd_vma val)
42 unsigned long instr_lo;
43
44 instr_hi = bfd_get_32 (abfd, bfd_addr);
45- if (instr_hi == 0xb2000000 || instr_hi == 0xb2ffffff)
46+ if ((instr_hi & 0xff000000) == 0xb2000000)
47 {
48 instr_hi &= ~0x00ffffff;
49 instr_hi |= (val >> 16) & 0xffffff;
50@@ -2238,7 +2238,10 @@ microblaze_elf_relax_section (bfd *abfd,
51 unsigned long instr_lo = bfd_get_32 (abfd, ocontents
52 + irelscan->r_offset
53 + INST_WORD_SIZE);
54- immediate = (instr_hi & 0x0000ffff) << 16;
55+ if ((instr_hi & 0xff000000) == 0xb2000000)
56+ immediate = (instr_hi & 0x00ffffff) << 24;
57+ else
58+ immediate = (instr_hi & 0x0000ffff) << 16;
59 immediate |= (instr_lo & 0x0000ffff);
60 offset = calc_fixup (irelscan->r_addend, 0, sec);
61 immediate -= offset;
62@@ -2282,7 +2285,10 @@ microblaze_elf_relax_section (bfd *abfd,
63 unsigned long instr_lo = bfd_get_32 (abfd, ocontents
64 + irelscan->r_offset
65 + INST_WORD_SIZE);
66- immediate = (instr_hi & 0x0000ffff) << 16;
67+ if ((instr_hi & 0xff000000) == 0xb2000000)
68+ immediate = (instr_hi & 0x00ffffff) << 24;
69+ else
70+ immediate = (instr_hi & 0x0000ffff) << 16;
71 immediate |= (instr_lo & 0x0000ffff);
72 target_address = immediate;
73 offset = calc_fixup (target_address, 0, sec);
74--
752.17.1
76
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0024-Fixed-the-bug-in-the-R_MICROBLAZE_64_NONE-relocation.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0024-Fixed-the-bug-in-the-R_MICROBLAZE_64_NONE-relocation.patch
new file mode 100644
index 00000000..d0ca677c
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0024-Fixed-the-bug-in-the-R_MICROBLAZE_64_NONE-relocation.patch
@@ -0,0 +1,44 @@
1From 50bd636604305329b302b9fbbb692795d26f5fa5 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Wed, 28 Nov 2018 14:00:29 +0530
4Subject: [PATCH 24/43] Fixed the bug in the R_MICROBLAZE_64_NONE relocation.
5 It was adjusting only lower 16bits.
6
7---
8 bfd/elf32-microblaze.c | 4 ++--
9 bfd/elf64-microblaze.c | 4 ++--
10 2 files changed, 4 insertions(+), 4 deletions(-)
11
12diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
13index 035e71f311..2d8c062a42 100644
14--- a/bfd/elf32-microblaze.c
15+++ b/bfd/elf32-microblaze.c
16@@ -2022,8 +2022,8 @@ microblaze_elf_relax_section (bfd *abfd,
17 sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, 0, sec);
18 efix = calc_fixup (target_address, 0, sec);
19 irel->r_addend -= (efix - sfix);
20- microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset
21- + INST_WORD_SIZE, irel->r_addend);
22+ microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset,
23+ irel->r_addend);
24 }
25 break;
26 }
27diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
28index 184b7d560d..ef6a87062b 100644
29--- a/bfd/elf64-microblaze.c
30+++ b/bfd/elf64-microblaze.c
31@@ -2017,8 +2017,8 @@ microblaze_elf_relax_section (bfd *abfd,
32 sfix = calc_fixup (irel->r_offset + INST_WORD_SIZE, 0, sec);
33 efix = calc_fixup (target_address, 0, sec);
34 irel->r_addend -= (efix - sfix);
35- microblaze_bfd_write_imm_value_32 (abfd, contents + irel->r_offset
36- + INST_WORD_SIZE, irel->r_addend);
37+ microblaze_bfd_write_imm_value_64 (abfd, contents + irel->r_offset,
38+ irel->r_addend);
39 }
40 break;
41 }
42--
432.17.1
44
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0025-Patch-MicroBlaze-fixed-Build-issue-which-are-due-to-.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0025-Patch-MicroBlaze-fixed-Build-issue-which-are-due-to-.patch
new file mode 100644
index 00000000..fba32c08
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0025-Patch-MicroBlaze-fixed-Build-issue-which-are-due-to-.patch
@@ -0,0 +1,51 @@
1From b8c4b1fa22137d18d4ada7e350948035705f402f Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Sun, 2 Dec 2018 14:49:14 +0530
4Subject: [PATCH 25/43] [Patch,MicroBlaze]: fixed Build issue which are due to
5 conflicts in patches.
6
7---
8 bfd/elf32-microblaze.c | 1 +
9 bfd/elf64-microblaze.c | 12 ++++++------
10 3 files changed, 9 insertions(+), 8 deletions(-)
11
12diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
13index 2d8c062a42..6a795c5069 100644
14--- a/bfd/elf32-microblaze.c
15+++ b/bfd/elf32-microblaze.c
16@@ -1996,6 +1996,7 @@ microblaze_elf_relax_section (bfd *abfd,
17 /* This was a PC-relative instruction that was
18 completely resolved. */
19 int sfix, efix;
20+ unsigned int val;
21 bfd_vma target_address;
22 target_address = irel->r_addend + irel->r_offset;
23 sfix = calc_fixup (irel->r_offset, 0, sec);
24diff --git a/bfd/elf64-microblaze.c b/bfd/elf64-microblaze.c
25index ef6a87062b..bed534e7dd 100644
26--- a/bfd/elf64-microblaze.c
27+++ b/bfd/elf64-microblaze.c
28@@ -2854,14 +2854,14 @@ microblaze_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
29 /* If this is a weak symbol, and there is a real definition, the
30 processor independent code will have arranged for us to see the
31 real definition first, and we can just use the same value. */
32- if (h->u.weakdef != NULL)
33+ if (h->is_weakalias)
34 {
35- BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined
36- || h->u.weakdef->root.type == bfd_link_hash_defweak);
37- h->root.u.def.section = h->u.weakdef->root.u.def.section;
38- h->root.u.def.value = h->u.weakdef->root.u.def.value;
39+ struct elf_link_hash_entry *def = weakdef (h);
40+ BFD_ASSERT (def->root.type == bfd_link_hash_defined);
41+ h->root.u.def.section = def->root.u.def.section;
42+ h->root.u.def.value = def->root.u.def.value;
43 return TRUE;
44- }
45+ }
46
47 /* This is a reference to a symbol defined by a dynamic object which
48 is not a function. */
49--
502.17.1
51
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0026-Patch-Microblaze-changes-of-PR22458-failure-to-choos.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0026-Patch-Microblaze-changes-of-PR22458-failure-to-choos.patch
new file mode 100644
index 00000000..38245cbd
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0026-Patch-Microblaze-changes-of-PR22458-failure-to-choos.patch
@@ -0,0 +1,31 @@
1From 212c40ed034096069f3ab0dac74ccfb79063b84c Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Tue, 26 Feb 2019 17:31:41 +0530
4Subject: [PATCH 26/43] [Patch,Microblaze] : changes of "PR22458, failure to
5 choose a matching ELF target" is causing "Multiple Prevailing definition
6 errors",added check for best_match elf.
7
8---
9 bfd/format.c | 5 +++++
10 1 file changed, 5 insertions(+)
11
12diff --git a/bfd/format.c b/bfd/format.c
13index 97a92291a8..3a74cc49d2 100644
14--- a/bfd/format.c
15+++ b/bfd/format.c
16@@ -292,7 +292,12 @@ bfd_check_format_matches (bfd *abfd, bfd_format format, char ***matching)
17
18 /* Don't check the default target twice. */
19 if (*target == &binary_vec
20+#if !BFD_SUPPORTS_PLUGINS
21 || (!abfd->target_defaulted && *target == save_targ))
22+#else
23+ || (!abfd->target_defaulted && *target == save_targ)
24+ || (*target)->match_priority > best_match)
25+#endif
26 continue;
27
28 /* If we already tried a match, the bfd is modified and may
29--
302.17.1
31
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0028-Patch-Microblaze-Binutils-security-check-is-causing-.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0028-Patch-Microblaze-Binutils-security-check-is-causing-.patch
new file mode 100644
index 00000000..664675b9
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0028-Patch-Microblaze-Binutils-security-check-is-causing-.patch
@@ -0,0 +1,33 @@
1From 7fdfff333f4982d7eb32a564aacfd2d8822c0004 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Mon, 11 Mar 2019 14:23:58 +0530
4Subject: [PATCH 28/43] [Patch,Microblaze] : Binutils security check is causing
5 build error for windows builds.commenting for now.
6
7---
8 bfd/elf-attrs.c | 2 ++
9 1 file changed, 2 insertions(+)
10
11diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
12index bfe135e7fb..feb5cb37f5 100644
13--- a/bfd/elf-attrs.c
14+++ b/bfd/elf-attrs.c
15@@ -440,6 +440,7 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
16 /* PR 17512: file: 2844a11d. */
17 if (hdr->sh_size == 0)
18 return;
19+ #if 0
20 if (hdr->sh_size > bfd_get_file_size (abfd))
21 {
22 /* xgettext:c-format */
23@@ -448,6 +449,7 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
24 bfd_set_error (bfd_error_invalid_operation);
25 return;
26 }
27+ #endif
28
29 contents = (bfd_byte *) bfd_malloc (hdr->sh_size + 1);
30 if (!contents)
31--
322.17.1
33
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0029-fixing-the-long-long-long-mingw-toolchain-issue.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0029-fixing-the-long-long-long-mingw-toolchain-issue.patch
new file mode 100644
index 00000000..0da9e7b4
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0029-fixing-the-long-long-long-mingw-toolchain-issue.patch
@@ -0,0 +1,27 @@
1From fcb9c923a78a6a6141626f4c2a82579cfc4e43d6 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Thu, 29 Nov 2018 17:59:25 +0530
4Subject: [PATCH 29/43] fixing the long & long long mingw toolchain issue
5
6---
7 opcodes/microblaze-opc.h | 4 ++--
8 2 files changed, 7 insertions(+), 7 deletions(-)
9
10diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
11index 824afc0ab0..d59ee0a95f 100644
12--- a/opcodes/microblaze-opc.h
13+++ b/opcodes/microblaze-opc.h
14@@ -585,8 +585,8 @@ char pvr_register_prefix[] = "rpvr";
15 #define MIN_IMM6_WIDTH ((int) 0x00000001)
16 #define MAX_IMM6_WIDTH ((int) 0x00000040)
17
18-#define MIN_IMML ((long) 0xffffff8000000000L)
19-#define MAX_IMML ((long) 0x0000007fffffffffL)
20+#define MIN_IMML ((long long) 0xffffff8000000000L)
21+#define MAX_IMML ((long long) 0x0000007fffffffffL)
22
23 #endif /* MICROBLAZE_OPC */
24
25--
262.17.1
27
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0030-Added-support-to-new-arithmetic-single-register-inst.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0030-Added-support-to-new-arithmetic-single-register-inst.patch
new file mode 100644
index 00000000..79d7f4fe
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0030-Added-support-to-new-arithmetic-single-register-inst.patch
@@ -0,0 +1,166 @@
1From f36d3bdd09f5c9987199f08ea3dd98bf45a9e18e Mon Sep 17 00:00:00 2001
2From: Nagaraju <nmekala@xilinx.com>
3Date: Fri, 23 Aug 2019 16:18:43 +0530
4Subject: [PATCH 30/43] Added support to new arithmetic single register
5 instructions
6
7---
8 opcodes/microblaze-dis.c | 12 +++
9 opcodes/microblaze-opc.h | 43 ++++++++++-
10 opcodes/microblaze-opcm.h | 5 +-
11 4 files changed, 201 insertions(+), 6 deletions(-)
12
13diff --git a/opcodes/microblaze-dis.c b/opcodes/microblaze-dis.c
14index f679a43606..e5e880cb1c 100644
15--- a/opcodes/microblaze-dis.c
16+++ b/opcodes/microblaze-dis.c
17@@ -114,6 +114,15 @@ get_field_imm15 (long instr)
18 return (strdup (tmpstr));
19 }
20
21+static char *
22+get_field_imm16 (long instr)
23+{
24+ char tmpstr[25];
25+
26+ sprintf (tmpstr, "%d", (short)((instr & IMM16_MASK) >> IMM_LOW));
27+ return (strdup (tmpstr));
28+}
29+
30 static char *
31 get_field_special (long instr, struct op_code_struct * op)
32 {
33@@ -419,6 +428,9 @@ print_insn_microblaze (bfd_vma memaddr, struct disassemble_info * info)
34 case INST_TYPE_RD_IMM15:
35 print_func (stream, "\t%s, %s", get_field_rd (inst), get_field_imm15 (inst));
36 break;
37+ case INST_TYPE_RD_IMML:
38+ print_func (stream, "\t%s, %s", get_field_rd (inst), get_field_imm16 (inst));
39+ break;
40 /* For mbar insn. */
41 case INST_TYPE_IMM5:
42 print_func (stream, "\t%s", get_field_imm5_mbar (inst));
43diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
44index d59ee0a95f..0774f70e08 100644
45--- a/opcodes/microblaze-opc.h
46+++ b/opcodes/microblaze-opc.h
47@@ -69,6 +69,7 @@
48 #define INST_TYPE_RD_R1_IMMW_IMMS 21
49
50 #define INST_TYPE_NONE 25
51+#define INST_TYPE_RD_IMML 26
52
53
54
55@@ -84,6 +85,7 @@
56 #define IMMVAL_MASK_MFS 0x0000
57
58 #define OPCODE_MASK_H 0xFC000000 /* High 6 bits only. */
59+#define OPCODE_MASK_LIMM 0xFC1F0000 /* High 6 bits and 12-16 bits */
60 #define OPCODE_MASK_H1 0xFFE00000 /* High 11 bits. */
61 #define OPCODE_MASK_H2 0xFC1F0000 /* High 6 and bits 20-16. */
62 #define OPCODE_MASK_H12 0xFFFF0000 /* High 16. */
63@@ -106,6 +108,33 @@
64 #define OPCODE_MASK_H34C 0xFC0007E0 /* High 6 bits and bits 21-26. */
65 #define OPCODE_MASK_H8 0xFF000000 /* High 8 bits only. */
66
67+/*Defines to identify 64-bit single reg instructions */
68+#define ADDLI_ONE_REG_MASK 0x68000000
69+#define ADDLIC_ONE_REG_MASK 0x68020000
70+#define ADDLIK_ONE_REG_MASK 0x68040000
71+#define ADDLIKC_ONE_REG_MASK 0x68060000
72+#define RSUBLI_ONE_REG_MASK 0x68010000
73+#define RSUBLIC_ONE_REG_MASK 0x68030000
74+#define RSUBLIK_ONE_REG_MASK 0x68050000
75+#define RSUBLIKC_ONE_REG_MASK 0x68070000
76+#define ORLI_ONE_REG_MASK 0x68100000
77+#define ANDLI_ONE_REG_MASK 0x68110000
78+#define XORLI_ONE_REG_MASK 0x68120000
79+#define ANDLNI_ONE_REG_MASK 0x68130000
80+#define ADDLI_MASK 0x20000000
81+#define ADDLIC_MASK 0x28000000
82+#define ADDLIK_MASK 0x30000000
83+#define ADDLIKC_MASK 0x38000000
84+#define RSUBLI_MASK 0x24000000
85+#define RSUBLIC_MASK 0x2C000000
86+#define RSUBLIK_MASK 0x34000000
87+#define RSUBLIKC_MASK 0x3C000000
88+#define ANDLI_MASK 0xA4000000
89+#define ANDLNI_MASK 0xAC000000
90+#define ORLI_MASK 0xA0000000
91+#define XORLI_MASK 0xA8000000
92+
93+
94 /* New Mask for msrset, msrclr insns. */
95 #define OPCODE_MASK_H23N 0xFC1F8000 /* High 6 and bits 11 - 16. */
96 /* Mask for mbar insn. */
97@@ -114,7 +143,7 @@
98 #define DELAY_SLOT 1
99 #define NO_DELAY_SLOT 0
100
101-#define MAX_OPCODES 412
102+#define MAX_OPCODES 424
103
104 struct op_code_struct
105 {
106@@ -444,13 +473,21 @@ struct op_code_struct
107 {"cmpl", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000101, OPCODE_MASK_H4, cmpl, arithmetic_inst },
108 {"cmplu", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x14000103, OPCODE_MASK_H4, cmplu, arithmetic_inst },
109 {"addli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x20000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
110+ {"addli", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68000000, OPCODE_MASK_LIMM, addli, arithmetic_inst },
111 {"rsubli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x24000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
112+ {"rsubli", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68010000, OPCODE_MASK_LIMM, rsubli, arithmetic_inst },
113 {"addlic", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x28000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
114+ {"addlic", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68020000, OPCODE_MASK_LIMM, addlic, arithmetic_inst },
115 {"rsublic", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x2C000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
116+ {"rsublic", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68030000, OPCODE_MASK_LIMM, rsublic, arithmetic_inst },
117 {"addlik", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x30000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
118+ {"addlik", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68040000, OPCODE_MASK_LIMM, addlik, arithmetic_inst },
119 {"rsublik", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x34000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
120+ {"rsublik", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68050000, OPCODE_MASK_LIMM, rsublik, arithmetic_inst },
121 {"addlikc", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x38000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
122+ {"addlikc", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68060000, OPCODE_MASK_LIMM, addlikc, arithmetic_inst },
123 {"rsublikc",INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x3C000000, OPCODE_MASK_H, invalid_inst, arithmetic_inst }, /* Identical to 32-bit */
124+ {"rsublikc", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68070000, OPCODE_MASK_LIMM, rsublikc, arithmetic_inst },
125 {"mull", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x40000100, OPCODE_MASK_H4, mull, mult_inst },
126 {"bslll", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000500, OPCODE_MASK_H3, bslll, barrel_shift_inst },
127 {"bslra", INST_TYPE_RD_R1_R2, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x44000300, OPCODE_MASK_H3, bslra, barrel_shift_inst },
128@@ -501,9 +538,13 @@ struct op_code_struct
129 {"beaged", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9FA00000, OPCODE_MASK_H14, beaged, branch_inst },
130 {"bealged", INST_TYPE_R1_R2, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0x9FA00100, OPCODE_MASK_H14, bealged, branch_inst },
131 {"orli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA0000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
132+ {"orli", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68100000, OPCODE_MASK_LIMM, orli, arithmetic_inst },
133 {"andli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA4000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
134+ {"andli", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68110000, OPCODE_MASK_LIMM, andli, arithmetic_inst },
135 {"xorli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xA8000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
136+ {"xorli", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68120000, OPCODE_MASK_LIMM, xorli, arithmetic_inst },
137 {"andnli", INST_TYPE_RD_R1_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xAC000000, OPCODE_MASK_H, invalid_inst, logical_inst }, /* Identical to 32-bit */
138+ {"andnli", INST_TYPE_RD_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL,0x68130000, OPCODE_MASK_LIMM, andnli, arithmetic_inst },
139 {"imml", INST_TYPE_IMML, INST_NO_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB2000000, OPCODE_MASK_H8, imml, immediate_inst },
140 {"breai", INST_TYPE_IMM, INST_PC_OFFSET, NO_DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8010000, OPCODE_MASK_H12, breai, branch_inst },
141 {"breaid", INST_TYPE_IMM, INST_PC_OFFSET, DELAY_SLOT, IMMVAL_MASK_NON_SPECIAL, 0xB8110000, OPCODE_MASK_H12, breaid, branch_inst },
142diff --git a/opcodes/microblaze-opcm.h b/opcodes/microblaze-opcm.h
143index 5f2e190d23..4d2ee2dd0d 100644
144--- a/opcodes/microblaze-opcm.h
145+++ b/opcodes/microblaze-opcm.h
146@@ -61,7 +61,9 @@ enum microblaze_instr
147 eaputd, teaputd, ecaputd, tecaputd, neaputd, tneaputd, necaputd, tnecaputd,
148
149 /* 64-bit instructions */
150- addl, rsubl, addlc, rsublc, addlk, rsublk, addlkc, rsublkc, cmpl, cmplu, mull,
151+ addl, addli, addlic, addlik, addlikc, rsubl, rsubli, rsublic, rsublik, rsublikc,
152+ addlc, rsublc, addlk, rsublk, addlkc, rsublkc, cmpl, cmplu, mull,
153+ andli, andnli, orli, xorli,
154 bslll, bslra, bslrl, bsllli, bslrai, bslrli, bslefi, bslifi, orl, andl, xorl,
155 andnl, pcmplbf, pcmpleq, pcmplne, srla, srlc, srll, sextl8, sextl16, sextl32,
156 brea, bread, breald, beaeq, bealeq, beaeqd, bealeqd, beane, bealne, beaned,
157@@ -166,5 +168,6 @@ enum microblaze_instr_type
158
159 /* Imm mask for msrset, msrclr instructions. */
160 #define IMM15_MASK 0x00007FFF
161+#define IMM16_MASK 0x0000FFFF
162
163 #endif /* MICROBLAZE-OPCM */
164--
1652.17.1
166
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0031-Patch-MicroBlaze-double-imml-generation-for-64-bit-v.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0031-Patch-MicroBlaze-double-imml-generation-for-64-bit-v.patch
new file mode 100644
index 00000000..0be07120
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0031-Patch-MicroBlaze-double-imml-generation-for-64-bit-v.patch
@@ -0,0 +1,28 @@
1From a15e73a33b3f395f2096e252b655775ed8424c14 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Mon, 26 Aug 2019 15:29:42 +0530
4Subject: [PATCH 31/43] [Patch,MicroBlaze] : double imml generation for 64 bit
5 values.
6
7---
8 opcodes/microblaze-opc.h | 4 +-
9 2 files changed, 263 insertions(+), 63 deletions(-)
10
11diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
12index 0774f70e08..bd9d91cd57 100644
13--- a/opcodes/microblaze-opc.h
14+++ b/opcodes/microblaze-opc.h
15@@ -626,8 +626,8 @@ char pvr_register_prefix[] = "rpvr";
16 #define MIN_IMM6_WIDTH ((int) 0x00000001)
17 #define MAX_IMM6_WIDTH ((int) 0x00000040)
18
19-#define MIN_IMML ((long long) 0xffffff8000000000L)
20-#define MAX_IMML ((long long) 0x0000007fffffffffL)
21+#define MIN_IMML ((long long) -9223372036854775808)
22+#define MAX_IMML ((long long) 9223372036854775807)
23
24 #endif /* MICROBLAZE_OPC */
25
26--
272.17.1
28
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0032-Add-initial-port-of-linux-gdbserver.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0032-Add-initial-port-of-linux-gdbserver.patch
new file mode 100644
index 00000000..88c137f5
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0032-Add-initial-port-of-linux-gdbserver.patch
@@ -0,0 +1,435 @@
1From 5c7fa77256c704cc493a6bd42425fcec814710e8 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Mon, 23 Jan 2017 19:07:44 +0530
4Subject: [PATCH 32/43] Add initial port of linux gdbserver add
5 gdb_proc_service_h to gdbserver microblaze-linux
6
7gdbserver needs to initialise the microblaze registers
8
9other archs use this step to run a *_arch_setup() to carry out all
10architecture specific setup - may need to add in future
11
12 * add linux-ptrace.o to gdbserver configure
13 * Update breakpoint opcode
14 * fix segfault on connecting gdbserver
15 * add microblaze_linux_memory_remove_breakpoint
16 * add set_solib_svr4_fetch_link_map_offsets
17 * add set_gdbarch_fetch_tls_load_module_address
18 * Force reading of r0 as 0, prevent stores
19
20Signed-off-by: David Holsgrove <david.holsgrove@petalogix.com>
21Signed-off-by: Nathan Rossi <nathan.rossi@petalogix.com>
22---
23 gdb/configure.host | 3 +
24 gdb/gdbserver/linux-microblaze-low.c | 189 +++++++++++++++++++++++++++
25 gdb/microblaze-linux-tdep.c | 29 +++-
26 gdb/microblaze-tdep.c | 35 ++++-
27 gdb/microblaze-tdep.h | 4 +-
28 gdb/regformats/reg-microblaze.dat | 41 ++++++
29 6 files changed, 298 insertions(+), 3 deletions(-)
30 create mode 100644 gdb/gdbserver/linux-microblaze-low.c
31 create mode 100644 gdb/regformats/reg-microblaze.dat
32
33diff --git a/gdb/configure.host b/gdb/configure.host
34index c87f997abc..de8d6b00f3 100644
35--- a/gdb/configure.host
36+++ b/gdb/configure.host
37@@ -65,6 +65,7 @@ hppa*) gdb_host_cpu=pa ;;
38 i[34567]86*) gdb_host_cpu=i386 ;;
39 m68*) gdb_host_cpu=m68k ;;
40 mips*) gdb_host_cpu=mips ;;
41+microblaze*) gdb_host_cpu=microblaze ;;
42 powerpc* | rs6000) gdb_host_cpu=powerpc ;;
43 sparcv9 | sparc64) gdb_host_cpu=sparc ;;
44 s390*) gdb_host_cpu=s390 ;;
45@@ -133,6 +134,8 @@ mips*-*-netbsd* | mips*-*-knetbsd*-gnu)
46 mips*-*-freebsd*) gdb_host=fbsd ;;
47 mips64*-*-openbsd*) gdb_host=obsd64 ;;
48
49+microblaze*-*linux*) gdb_host=linux ;;
50+
51 powerpc-*-aix* | rs6000-*-* | powerpc64-*-aix*)
52 gdb_host=aix ;;
53 powerpc*-*-freebsd*) gdb_host=fbsd ;;
54diff --git a/gdb/gdbserver/linux-microblaze-low.c b/gdb/gdbserver/linux-microblaze-low.c
55new file mode 100644
56index 0000000000..cba5d6fc58
57--- /dev/null
58+++ b/gdb/gdbserver/linux-microblaze-low.c
59@@ -0,0 +1,189 @@
60+/* GNU/Linux/Microblaze specific low level interface, for the remote server for
61+ GDB.
62+ Copyright (C) 1995-2013 Free Software Foundation, Inc.
63+
64+ This file is part of GDB.
65+
66+ This program is free software; you can redistribute it and/or modify
67+ it under the terms of the GNU General Public License as published by
68+ the Free Software Foundation; either version 3 of the License, or
69+ (at your option) any later version.
70+
71+ This program is distributed in the hope that it will be useful,
72+ but WITHOUT ANY WARRANTY; without even the implied warranty of
73+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74+ GNU General Public License for more details.
75+
76+ You should have received a copy of the GNU General Public License
77+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
78+
79+#include "server.h"
80+#include "linux-low.h"
81+
82+#include <asm/ptrace.h>
83+#include <sys/procfs.h>
84+#include <sys/ptrace.h>
85+
86+#include "gdb_proc_service.h"
87+
88+static int microblaze_regmap[] =
89+ {PT_GPR(0), PT_GPR(1), PT_GPR(2), PT_GPR(3),
90+ PT_GPR(4), PT_GPR(5), PT_GPR(6), PT_GPR(7),
91+ PT_GPR(8), PT_GPR(9), PT_GPR(10), PT_GPR(11),
92+ PT_GPR(12), PT_GPR(13), PT_GPR(14), PT_GPR(15),
93+ PT_GPR(16), PT_GPR(17), PT_GPR(18), PT_GPR(19),
94+ PT_GPR(20), PT_GPR(21), PT_GPR(22), PT_GPR(23),
95+ PT_GPR(24), PT_GPR(25), PT_GPR(26), PT_GPR(27),
96+ PT_GPR(28), PT_GPR(29), PT_GPR(30), PT_GPR(31),
97+ PT_PC, PT_MSR, PT_EAR, PT_ESR,
98+ PT_FSR
99+ };
100+
101+#define microblaze_num_regs (sizeof microblaze_regmap / sizeof microblaze_regmap[0])
102+
103+/* Defined in auto-generated file microblaze-linux.c. */
104+void init_registers_microblaze (void);
105+
106+static int
107+microblaze_cannot_store_register (int regno)
108+{
109+ if (microblaze_regmap[regno] == -1 || regno == 0)
110+ return 1;
111+
112+ return 0;
113+}
114+
115+static int
116+microblaze_cannot_fetch_register (int regno)
117+{
118+ return 0;
119+}
120+
121+static CORE_ADDR
122+microblaze_get_pc (struct regcache *regcache)
123+{
124+ unsigned long pc;
125+
126+ collect_register_by_name (regcache, "pc", &pc);
127+ return (CORE_ADDR) pc;
128+}
129+
130+static void
131+microblaze_set_pc (struct regcache *regcache, CORE_ADDR pc)
132+{
133+ unsigned long newpc = pc;
134+
135+ supply_register_by_name (regcache, "pc", &newpc);
136+}
137+
138+/* dbtrap insn */
139+/* brki r16, 0x18; */
140+static const unsigned long microblaze_breakpoint = 0xba0c0018;
141+#define microblaze_breakpoint_len 4
142+
143+static int
144+microblaze_breakpoint_at (CORE_ADDR where)
145+{
146+ unsigned long insn;
147+
148+ (*the_target->read_memory) (where, (unsigned char *) &insn, 4);
149+ if (insn == microblaze_breakpoint)
150+ return 1;
151+ /* If necessary, recognize more trap instructions here. GDB only uses the
152+ one. */
153+ return 0;
154+}
155+
156+static CORE_ADDR
157+microblaze_reinsert_addr (struct regcache *regcache)
158+{
159+ unsigned long pc;
160+ collect_register_by_name (regcache, "r15", &pc);
161+ return pc;
162+}
163+
164+#ifdef HAVE_PTRACE_GETREGS
165+
166+static void
167+microblaze_collect_ptrace_register (struct regcache *regcache, int regno, char *buf)
168+{
169+ int size = register_size (regno);
170+
171+ memset (buf, 0, sizeof (long));
172+
173+ if (size < sizeof (long))
174+ collect_register (regcache, regno, buf + sizeof (long) - size);
175+ else
176+ collect_register (regcache, regno, buf);
177+}
178+
179+static void
180+microblaze_supply_ptrace_register (struct regcache *regcache,
181+ int regno, const char *buf)
182+{
183+ int size = register_size (regno);
184+
185+ if (regno == 0) {
186+ unsigned long regbuf_0 = 0;
187+ /* clobbering r0 so that it is always 0 as enforced by hardware */
188+ supply_register (regcache, regno, (const char*)&regbuf_0);
189+ } else {
190+ if (size < sizeof (long))
191+ supply_register (regcache, regno, buf + sizeof (long) - size);
192+ else
193+ supply_register (regcache, regno, buf);
194+ }
195+}
196+
197+/* Provide only a fill function for the general register set. ps_lgetregs
198+ will use this for NPTL support. */
199+
200+static void microblaze_fill_gregset (struct regcache *regcache, void *buf)
201+{
202+ int i;
203+
204+ for (i = 0; i < 32; i++)
205+ microblaze_collect_ptrace_register (regcache, i, (char *) buf + microblaze_regmap[i]);
206+}
207+
208+static void
209+microblaze_store_gregset (struct regcache *regcache, const void *buf)
210+{
211+ int i;
212+
213+ for (i = 0; i < 32; i++)
214+ supply_register (regcache, i, (char *) buf + microblaze_regmap[i]);
215+}
216+
217+#endif /* HAVE_PTRACE_GETREGS */
218+
219+struct regset_info target_regsets[] = {
220+#ifdef HAVE_PTRACE_GETREGS
221+ { PTRACE_GETREGS, PTRACE_SETREGS, 0, sizeof (elf_gregset_t), GENERAL_REGS, microblaze_fill_gregset, microblaze_store_gregset },
222+ { 0, 0, 0, -1, -1, NULL, NULL },
223+#endif /* HAVE_PTRACE_GETREGS */
224+ { 0, 0, 0, -1, -1, NULL, NULL }
225+};
226+
227+struct linux_target_ops the_low_target = {
228+ init_registers_microblaze,
229+ microblaze_num_regs,
230+ microblaze_regmap,
231+ NULL,
232+ microblaze_cannot_fetch_register,
233+ microblaze_cannot_store_register,
234+ NULL, /* fetch_register */
235+ microblaze_get_pc,
236+ microblaze_set_pc,
237+ (const unsigned char *) &microblaze_breakpoint,
238+ microblaze_breakpoint_len,
239+ microblaze_reinsert_addr,
240+ 0,
241+ microblaze_breakpoint_at,
242+ NULL,
243+ NULL,
244+ NULL,
245+ NULL,
246+ microblaze_collect_ptrace_register,
247+ microblaze_supply_ptrace_register,
248+};
249diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
250index 4e5f60cd4e..7ab650a1cc 100644
251--- a/gdb/microblaze-linux-tdep.c
252+++ b/gdb/microblaze-linux-tdep.c
253@@ -37,6 +37,22 @@
254 #include "tramp-frame.h"
255 #include "linux-tdep.h"
256
257+static int microblaze_debug_flag = 0;
258+
259+static void
260+microblaze_debug (const char *fmt, ...)
261+{
262+ if (microblaze_debug_flag)
263+ {
264+ va_list args;
265+
266+ va_start (args, fmt);
267+ printf_unfiltered ("MICROBLAZE LINUX: ");
268+ vprintf_unfiltered (fmt, args);
269+ va_end (args);
270+ }
271+}
272+
273 static int
274 microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
275 struct bp_target_info *bp_tgt)
276@@ -46,18 +62,25 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
277 int val;
278 int bplen;
279 gdb_byte old_contents[BREAKPOINT_MAX];
280+ struct cleanup *cleanup;
281
282 /* Determine appropriate breakpoint contents and size for this address. */
283 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
284
285+ /* Make sure we see the memory breakpoints. */
286+ cleanup = make_show_memory_breakpoints_cleanup (1);
287 val = target_read_memory (addr, old_contents, bplen);
288
289 /* If our breakpoint is no longer at the address, this means that the
290 program modified the code on us, so it is wrong to put back the
291 old value. */
292 if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
293- val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
294+ {
295+ val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
296+ microblaze_debug ("microblaze_linux_memory_remove_breakpoint writing back to memory at addr 0x%lx\n", addr);
297+ }
298
299+ do_cleanups (cleanup);
300 return val;
301 }
302
303@@ -129,6 +152,10 @@ microblaze_linux_init_abi (struct gdbarch_info info,
304 /* Trampolines. */
305 tramp_frame_prepend_unwinder (gdbarch,
306 &microblaze_linux_sighandler_tramp_frame);
307+
308+ /* Enable TLS support. */
309+ set_gdbarch_fetch_tls_load_module_address (gdbarch,
310+ svr4_fetch_objfile_link_map);
311 }
312
313 void
314diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
315index 1248acbdc9..730a2b281f 100644
316--- a/gdb/microblaze-tdep.c
317+++ b/gdb/microblaze-tdep.c
318@@ -137,7 +137,38 @@ microblaze_fetch_instruction (CORE_ADDR pc)
319 constexpr gdb_byte microblaze_break_insn[] = MICROBLAZE_BREAKPOINT;
320
321 typedef BP_MANIPULATION (microblaze_break_insn) microblaze_breakpoint;
322-
323+static int
324+microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
325+ struct bp_target_info *bp_tgt)
326+{
327+ CORE_ADDR addr = bp_tgt->placed_address;
328+ const unsigned char *bp;
329+ int val;
330+ int bplen;
331+ gdb_byte old_contents[BREAKPOINT_MAX];
332+ struct cleanup *cleanup;
333+
334+ /* Determine appropriate breakpoint contents and size for this address. */
335+ bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
336+ if (bp == NULL)
337+ error (_("Software breakpoints not implemented for this target."));
338+
339+ /* Make sure we see the memory breakpoints. */
340+ cleanup = make_show_memory_breakpoints_cleanup (1);
341+ val = target_read_memory (addr, old_contents, bplen);
342+
343+ /* If our breakpoint is no longer at the address, this means that the
344+ program modified the code on us, so it is wrong to put back the
345+ old value. */
346+ if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
347+ {
348+ val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
349+ microblaze_debug ("microblaze_linux_memory_remove_breakpoint writing back to memory at addr 0x%lx\n", addr);
350+ }
351+
352+ do_cleanups (cleanup);
353+ return val;
354+}
355
356 /* Allocate and initialize a frame cache. */
357
358@@ -731,6 +762,7 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
359 microblaze_breakpoint::kind_from_pc);
360 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
361 microblaze_breakpoint::bp_from_kind);
362+ set_gdbarch_memory_remove_breakpoint (gdbarch, microblaze_linux_memory_remove_breakpoint);
363
364 set_gdbarch_frame_args_skip (gdbarch, 8);
365
366@@ -770,4 +802,5 @@ When non-zero, microblaze specific debugging is enabled."),
367 NULL,
368 &setdebuglist, &showdebuglist);
369
370+
371 }
372diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
373index a0048148e4..63aab84ef6 100644
374--- a/gdb/microblaze-tdep.h
375+++ b/gdb/microblaze-tdep.h
376@@ -117,6 +117,8 @@ struct microblaze_frame_cache
377
378 /* MICROBLAZE_BREAKPOINT defines the breakpoint that should be used.
379 Only used for native debugging. */
380-#define MICROBLAZE_BREAKPOINT {0xb9, 0xcc, 0x00, 0x60}
381+#define MICROBLAZE_BREAKPOINT {0xba, 0x0c, 0x00, 0x18}
382+#define MICROBLAZE_BREAKPOINT_LE {0x18, 0x00, 0x0c, 0xba}
383+
384
385 #endif /* microblaze-tdep.h */
386diff --git a/gdb/regformats/reg-microblaze.dat b/gdb/regformats/reg-microblaze.dat
387new file mode 100644
388index 0000000000..bd8a438442
389--- /dev/null
390+++ b/gdb/regformats/reg-microblaze.dat
391@@ -0,0 +1,41 @@
392+name:microblaze
393+expedite:r1,pc
394+32:r0
395+32:r1
396+32:r2
397+32:r3
398+32:r4
399+32:r5
400+32:r6
401+32:r7
402+32:r8
403+32:r9
404+32:r10
405+32:r11
406+32:r12
407+32:r13
408+32:r14
409+32:r15
410+32:r16
411+32:r17
412+32:r18
413+32:r19
414+32:r20
415+32:r21
416+32:r22
417+32:r23
418+32:r24
419+32:r25
420+32:r26
421+32:r27
422+32:r28
423+32:r29
424+32:r30
425+32:r31
426+32:pc
427+32:msr
428+32:ear
429+32:esr
430+32:fsr
431+32:slr
432+32:shr
433--
4342.17.1
435
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0033-Initial-port-of-core-reading-support.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0033-Initial-port-of-core-reading-support.patch
new file mode 100644
index 00000000..e60893ef
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0033-Initial-port-of-core-reading-support.patch
@@ -0,0 +1,388 @@
1From a9d58bc9edc348ed15d62598f2a0d0862aaf4e61 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Tue, 24 Jan 2017 14:55:56 +0530
4Subject: [PATCH 33/43] Initial port of core reading support Added support for
5 reading notes in linux core dumps Support for reading of PRSTATUS and PSINFO
6 information for rebuilding ".reg" sections of core dumps at run time.
7
8Signed-off-by: David Holsgrove <david.holsgrove@petalogix.com>
9Signed-off-by: Nathan Rossi <nathan.rossi@petalogix.com>
10---
11 bfd/elf32-microblaze.c | 84 ++++++++++++++++++++++++++++++++++
12 gdb/configure.tgt | 2 +-
13 gdb/microblaze-linux-tdep.c | 57 +++++++++++++++++++++++
14 gdb/microblaze-tdep.c | 90 +++++++++++++++++++++++++++++++++++++
15 gdb/microblaze-tdep.h | 27 +++++++++++
16 5 files changed, 259 insertions(+), 1 deletion(-)
17
18diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
19index 6a795c5069..c280431df6 100644
20--- a/bfd/elf32-microblaze.c
21+++ b/bfd/elf32-microblaze.c
22@@ -767,6 +767,87 @@ microblaze_elf_is_local_label_name (bfd *abfd, const char *name)
23 return _bfd_elf_is_local_label_name (abfd, name);
24 }
25
26+/* Support for core dump NOTE sections. */
27+static bfd_boolean
28+microblaze_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
29+{
30+ int offset;
31+ unsigned int size;
32+
33+ switch (note->descsz)
34+ {
35+ default:
36+ return FALSE;
37+
38+ case 228: /* Linux/MicroBlaze */
39+ /* pr_cursig */
40+ elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
41+
42+ /* pr_pid */
43+ elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
44+
45+ /* pr_reg */
46+ offset = 72;
47+ size = 50 * 4;
48+
49+ break;
50+ }
51+
52+ /* Make a ".reg/999" section. */
53+ return _bfd_elfcore_make_pseudosection (abfd, ".reg",
54+ size, note->descpos + offset);
55+}
56+
57+static bfd_boolean
58+microblaze_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
59+{
60+ switch (note->descsz)
61+ {
62+ default:
63+ return FALSE;
64+
65+ case 128: /* Linux/MicroBlaze elf_prpsinfo */
66+ elf_tdata (abfd)->core->program
67+ = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
68+ elf_tdata (abfd)->core->command
69+ = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
70+ }
71+
72+ /* Note that for some reason, a spurious space is tacked
73+ onto the end of the args in some (at least one anyway)
74+ implementations, so strip it off if it exists. */
75+
76+ {
77+ char *command = elf_tdata (abfd)->core->command;
78+ int n = strlen (command);
79+
80+ if (0 < n && command[n - 1] == ' ')
81+ command[n - 1] = '\0';
82+ }
83+
84+ return TRUE;
85+}
86+
87+/* The microblaze linker (like many others) needs to keep track of
88+ the number of relocs that it decides to copy as dynamic relocs in
89+ check_relocs for each symbol. This is so that it can later discard
90+ them if they are found to be unnecessary. We store the information
91+ in a field extending the regular ELF linker hash table. */
92+
93+struct elf32_mb_dyn_relocs
94+{
95+ struct elf32_mb_dyn_relocs *next;
96+
97+ /* The input section of the reloc. */
98+ asection *sec;
99+
100+ /* Total number of relocs copied for the input section. */
101+ bfd_size_type count;
102+
103+ /* Number of pc-relative relocs copied for the input section. */
104+ bfd_size_type pc_count;
105+};
106+
107 /* ELF linker hash entry. */
108
109 struct elf32_mb_link_hash_entry
110@@ -3672,4 +3753,7 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
111 #define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
112 #define elf_backend_add_symbol_hook microblaze_elf_add_symbol_hook
113
114+#define elf_backend_grok_prstatus microblaze_elf_grok_prstatus
115+#define elf_backend_grok_psinfo microblaze_elf_grok_psinfo
116+
117 #include "elf32-target.h"
118diff --git a/gdb/configure.tgt b/gdb/configure.tgt
119index 27f122ad04..622bd486b3 100644
120--- a/gdb/configure.tgt
121+++ b/gdb/configure.tgt
122@@ -397,7 +397,7 @@ mep-*-*)
123
124 microblaze*-linux-*|microblaze*-*-linux*)
125 # Target: Xilinx MicroBlaze running Linux
126- gdb_target_obs="microblaze-tdep.o microblaze-linux-tdep.o solib-svr4.o \
127+ gdb_target_obs="microblaze-tdep.o microblaze-linux-tdep.o solib-svr4.o glibc-tdep.o \
128 symfile-mem.o linux-tdep.o"
129 gdb_sim=../sim/microblaze/libsim.a
130 ;;
131diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
132index 7ab650a1cc..e2225d778a 100644
133--- a/gdb/microblaze-linux-tdep.c
134+++ b/gdb/microblaze-linux-tdep.c
135@@ -135,11 +135,54 @@ static struct tramp_frame microblaze_linux_sighandler_tramp_frame =
136 microblaze_linux_sighandler_cache_init
137 };
138
139+const struct microblaze_gregset microblaze_linux_core_gregset;
140+
141+static void
142+microblaze_linux_supply_core_gregset (const struct regset *regset,
143+ struct regcache *regcache,
144+ int regnum, const void *gregs, size_t len)
145+{
146+ microblaze_supply_gregset (&microblaze_linux_core_gregset, regcache,
147+ regnum, gregs);
148+}
149+
150+static void
151+microblaze_linux_collect_core_gregset (const struct regset *regset,
152+ const struct regcache *regcache,
153+ int regnum, void *gregs, size_t len)
154+{
155+ microblaze_collect_gregset (&microblaze_linux_core_gregset, regcache,
156+ regnum, gregs);
157+}
158+
159+static void
160+microblaze_linux_supply_core_fpregset (const struct regset *regset,
161+ struct regcache *regcache,
162+ int regnum, const void *fpregs, size_t len)
163+{
164+ /* FIXME. */
165+ microblaze_supply_fpregset (regcache, regnum, fpregs);
166+}
167+
168+static void
169+microblaze_linux_collect_core_fpregset (const struct regset *regset,
170+ const struct regcache *regcache,
171+ int regnum, void *fpregs, size_t len)
172+{
173+ /* FIXME. */
174+ microblaze_collect_fpregset (regcache, regnum, fpregs);
175+}
176
177 static void
178 microblaze_linux_init_abi (struct gdbarch_info info,
179 struct gdbarch *gdbarch)
180 {
181+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
182+
183+ tdep->gregset = regset_alloc (gdbarch, microblaze_linux_supply_core_gregset,
184+ microblaze_linux_collect_core_gregset);
185+ tdep->sizeof_gregset = 200;
186+
187 linux_init_abi (info, gdbarch);
188
189 set_gdbarch_memory_remove_breakpoint (gdbarch,
190@@ -153,6 +196,20 @@ microblaze_linux_init_abi (struct gdbarch_info info,
191 tramp_frame_prepend_unwinder (gdbarch,
192 &microblaze_linux_sighandler_tramp_frame);
193
194+ /* BFD target for core files. */
195+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
196+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblaze");
197+ else
198+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblazeel");
199+
200+
201+ /* Shared library handling. */
202+ set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
203+ set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
204+
205+ set_gdbarch_regset_from_core_section (gdbarch,
206+ microblaze_regset_from_core_section);
207+
208 /* Enable TLS support. */
209 set_gdbarch_fetch_tls_load_module_address (gdbarch,
210 svr4_fetch_objfile_link_map);
211diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
212index 730a2b281f..49713ea9b1 100644
213--- a/gdb/microblaze-tdep.c
214+++ b/gdb/microblaze-tdep.c
215@@ -137,6 +137,14 @@ microblaze_fetch_instruction (CORE_ADDR pc)
216 constexpr gdb_byte microblaze_break_insn[] = MICROBLAZE_BREAKPOINT;
217
218 typedef BP_MANIPULATION (microblaze_break_insn) microblaze_breakpoint;
219+static CORE_ADDR
220+microblaze_store_arguments (struct regcache *regcache, int nargs,
221+ struct value **args, CORE_ADDR sp,
222+ int struct_return, CORE_ADDR struct_addr)
223+{
224+ error (_("store_arguments not implemented"));
225+ return sp;
226+}
227 static int
228 microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
229 struct bp_target_info *bp_tgt)
230@@ -541,6 +549,12 @@ microblaze_frame_base_address (struct frame_info *next_frame,
231 return cache->base;
232 }
233
234+static const struct frame_unwind *
235+microblaze_frame_sniffer (struct frame_info *next_frame)
236+{
237+ return &microblaze_frame_unwind;
238+}
239+
240 static const struct frame_base microblaze_frame_base =
241 {
242 &microblaze_frame_unwind,
243@@ -677,6 +691,71 @@ microblaze_register_g_packet_guesses (struct gdbarch *gdbarch)
244 tdesc_microblaze_with_stack_protect);
245 }
246
247+void
248+microblaze_supply_gregset (const struct microblaze_gregset *gregset,
249+ struct regcache *regcache,
250+ int regnum, const void *gregs)
251+{
252+ unsigned int *regs = gregs;
253+ if (regnum >= 0)
254+ regcache_raw_supply (regcache, regnum, regs + regnum);
255+
256+ if (regnum == -1) {
257+ int i;
258+
259+ for (i = 0; i < 50; i++) {
260+ regcache_raw_supply (regcache, i, regs + i);
261+ }
262+ }
263+}
264+
265+
266+void
267+microblaze_collect_gregset (const struct microblaze_gregset *gregset,
268+ const struct regcache *regcache,
269+ int regnum, void *gregs)
270+{
271+ /* FIXME. */
272+}
273+
274+void
275+microblaze_supply_fpregset (struct regcache *regcache,
276+ int regnum, const void *fpregs)
277+{
278+ /* FIXME. */
279+}
280+
281+void
282+microblaze_collect_fpregset (const struct regcache *regcache,
283+ int regnum, void *fpregs)
284+{
285+ /* FIXME. */
286+}
287+
288+
289+/* Return the appropriate register set for the core section identified
290+ by SECT_NAME and SECT_SIZE. */
291+
292+const struct regset *
293+microblaze_regset_from_core_section (struct gdbarch *gdbarch,
294+ const char *sect_name, size_t sect_size)
295+{
296+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
297+
298+ microblaze_debug ("microblaze_regset_from_core_section, sect_name = %s\n", sect_name);
299+
300+ if (strcmp (sect_name, ".reg") == 0 && sect_size >= tdep->sizeof_gregset)
301+ return tdep->gregset;
302+
303+ if (strcmp (sect_name, ".reg2") == 0 && sect_size >= tdep->sizeof_fpregset)
304+ return tdep->fpregset;
305+
306+ microblaze_debug ("microblaze_regset_from_core_section returning null :-( \n");
307+ return NULL;
308+}
309+
310+
311+
312 static struct gdbarch *
313 microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
314 {
315@@ -733,6 +812,10 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
316 tdep = XCNEW (struct gdbarch_tdep);
317 gdbarch = gdbarch_alloc (&info, tdep);
318
319+ tdep->gregset = NULL;
320+ tdep->sizeof_gregset = 0;
321+ tdep->fpregset = NULL;
322+ tdep->sizeof_fpregset = 0;
323 set_gdbarch_long_double_bit (gdbarch, 128);
324
325 set_gdbarch_num_regs (gdbarch, MICROBLAZE_NUM_REGS);
326@@ -781,6 +864,13 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
327 frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
328 if (tdesc_data != NULL)
329 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
330+ //frame_base_append_sniffer (gdbarch, microblaze_frame_sniffer);
331+
332+ /* If we have register sets, enable the generic core file support. */
333+ if (tdep->gregset) {
334+ set_gdbarch_regset_from_core_section (gdbarch,
335+ microblaze_regset_from_core_section);
336+ }
337
338 return gdbarch;
339 }
340diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
341index 63aab84ef6..02650f61d9 100644
342--- a/gdb/microblaze-tdep.h
343+++ b/gdb/microblaze-tdep.h
344@@ -22,8 +22,22 @@
345
346
347 /* Microblaze architecture-specific information. */
348+struct microblaze_gregset
349+{
350+ unsigned int gregs[32];
351+ unsigned int fpregs[32];
352+ unsigned int pregs[16];
353+};
354+
355 struct gdbarch_tdep
356 {
357+ int dummy; // declare something.
358+
359+ /* Register sets. */
360+ struct regset *gregset;
361+ size_t sizeof_gregset;
362+ struct regset *fpregset;
363+ size_t sizeof_fpregset;
364 };
365
366 /* Register numbers. */
367@@ -120,5 +134,18 @@ struct microblaze_frame_cache
368 #define MICROBLAZE_BREAKPOINT {0xba, 0x0c, 0x00, 0x18}
369 #define MICROBLAZE_BREAKPOINT_LE {0x18, 0x00, 0x0c, 0xba}
370
371+extern void microblaze_supply_gregset (const struct microblaze_gregset *gregset,
372+ struct regcache *regcache,
373+ int regnum, const void *gregs);
374+extern void microblaze_collect_gregset (const struct microblaze_gregset *gregset,
375+ const struct regcache *regcache,
376+ int regnum, void *gregs);
377+extern void microblaze_supply_fpregset (struct regcache *regcache,
378+ int regnum, const void *fpregs);
379+extern void microblaze_collect_fpregset (const struct regcache *regcache,
380+ int regnum, void *fpregs);
381+
382+extern const struct regset * microblaze_regset_from_core_section (struct gdbarch *gdbarch,
383+ const char *sect_name, size_t sect_size);
384
385 #endif /* microblaze-tdep.h */
386--
3872.17.1
388
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0034-Fix-debug-message-when-register-is-unavailable.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0034-Fix-debug-message-when-register-is-unavailable.patch
new file mode 100644
index 00000000..f0ec43b1
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0034-Fix-debug-message-when-register-is-unavailable.patch
@@ -0,0 +1,40 @@
1From 9e42c672613131b25da90e58aefd2d39e497c3f6 Mon Sep 17 00:00:00 2001
2From: Nathan Rossi <nathan.rossi@petalogix.com>
3Date: Tue, 8 May 2012 18:11:17 +1000
4Subject: [PATCH 34/43] Fix debug message when register is unavailable
5
6Signed-off-by: Nathan Rossi <nathan.rossi@petalogix.com>
7---
8 gdb/frame.c | 13 ++++++++++---
9 1 file changed, 10 insertions(+), 3 deletions(-)
10
11diff --git a/gdb/frame.c b/gdb/frame.c
12index d8b5f819f1..49706dc97c 100644
13--- a/gdb/frame.c
14+++ b/gdb/frame.c
15@@ -1227,12 +1227,19 @@ frame_unwind_register_value (frame_info *next_frame, int regnum)
16 else
17 {
18 int i;
19- const gdb_byte *buf = value_contents (value);
20+ const gdb_byte *buf = NULL;
21+ if (value_entirely_available(value)) {
22+ buf = value_contents (value);
23+ }
24
25 fprintf_unfiltered (gdb_stdlog, " bytes=");
26 fprintf_unfiltered (gdb_stdlog, "[");
27- for (i = 0; i < register_size (gdbarch, regnum); i++)
28- fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
29+ if (buf != NULL) {
30+ for (i = 0; i < register_size (gdbarch, regnum); i++)
31+ fprintf_unfiltered (gdb_stdlog, "%02x", buf[i]);
32+ } else {
33+ fprintf_unfiltered (gdb_stdlog, "unavailable");
34+ }
35 fprintf_unfiltered (gdb_stdlog, "]");
36 }
37 }
38--
392.17.1
40
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0035-revert-master-rebase-changes-to-gdbserver.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0035-revert-master-rebase-changes-to-gdbserver.patch
new file mode 100644
index 00000000..0fe5c082
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0035-revert-master-rebase-changes-to-gdbserver.patch
@@ -0,0 +1,31 @@
1From 6f2d2fd5a214126e2c81dfb0dada3001ba353419 Mon Sep 17 00:00:00 2001
2From: David Holsgrove <david.holsgrove@xilinx.com>
3Date: Mon, 22 Jul 2013 11:16:05 +1000
4Subject: [PATCH 35/43] revert master-rebase changes to gdbserver
5
6Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
7---
8 gdb/gdbserver/configure.srv | 7 +++++++
9 1 file changed, 7 insertions(+)
10
11diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
12index bec72e2b19..153dcb4c71 100644
13--- a/gdb/gdbserver/configure.srv
14+++ b/gdb/gdbserver/configure.srv
15@@ -210,6 +210,13 @@ case "${target}" in
16 srv_linux_usrregs=yes
17 srv_linux_thread_db=yes
18 ;;
19+ microblaze*-*-linux*) srv_regobj=microblaze-linux.o
20+ srv_tgtobj="linux-low.o linux-osdata.o linux-microblaze-low.o "
21+ srv_tgtobj="${srv_tgtobj} linux-procfs.o linux-ptrace.o"
22+ srv_linux_regsets=yes
23+ srv_linux_usrregs=yes
24+ srv_linux_thread_db=yes
25+ ;;
26 powerpc*-*-linux*) srv_regobj="powerpc-32l.o"
27 srv_regobj="${srv_regobj} powerpc-altivec32l.o"
28 srv_regobj="${srv_regobj} powerpc-cell32l.o"
29--
302.17.1
31
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0036-revert-master-rebase-changes-to-gdbserver-previous-c.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0036-revert-master-rebase-changes-to-gdbserver-previous-c.patch
new file mode 100644
index 00000000..111d8059
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0036-revert-master-rebase-changes-to-gdbserver-previous-c.patch
@@ -0,0 +1,33 @@
1From a21f56098eb41e20ba2e6995e6dc72acdea045a0 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Mon, 30 Apr 2018 17:09:55 +0530
4Subject: [PATCH 36/43] revert master-rebase changes to gdbserver , previous
5 commit typo's
6
7---
8 gdb/gdbserver/Makefile.in | 2 ++
9 1 file changed, 2 insertions(+)
10
11diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
12index f5fc55034e..73ca5fd7c5 100644
13--- a/gdb/gdbserver/Makefile.in
14+++ b/gdb/gdbserver/Makefile.in
15@@ -169,6 +169,7 @@ SFILES = \
16 $(srcdir)/linux-low.c \
17 $(srcdir)/linux-m32r-low.c \
18 $(srcdir)/linux-m68k-low.c \
19+ $(srcdir)/linux-microblaze-low.c \
20 $(srcdir)/linux-mips-low.c \
21 $(srcdir)/linux-nios2-low.c \
22 $(srcdir)/linux-ppc-low.c \
23@@ -226,6 +227,7 @@ SFILES = \
24 $(srcdir)/nat/linux-osdata.c \
25 $(srcdir)/nat/linux-personality.c \
26 $(srcdir)/nat/mips-linux-watch.c \
27+ $(srcdir)/nat/microblaze-linux.c \
28 $(srcdir)/nat/ppc-linux.c \
29 $(srcdir)/nat/fork-inferior.c \
30 $(srcdir)/target/waitstatus.c
31--
322.17.1
33
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0037-microblaze-Add-build_gdbserver-yes-to-top-level-conf.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0037-microblaze-Add-build_gdbserver-yes-to-top-level-conf.patch
new file mode 100644
index 00000000..16b891bd
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0037-microblaze-Add-build_gdbserver-yes-to-top-level-conf.patch
@@ -0,0 +1,32 @@
1From 62bda7ae7bf0880201c4872c54e5b530b2fec27b Mon Sep 17 00:00:00 2001
2From: David Holsgrove <david.holsgrove@xilinx.com>
3Date: Mon, 16 Dec 2013 16:37:32 +1000
4Subject: [PATCH 37/43] microblaze: Add build_gdbserver=yes to top level
5 configure.tgt
6
7For Microblaze linux toolchains, set the build_gdbserver=yes
8to allow driving gdbserver configuration from the upper level
9
10This patch has been absorbed into the original patch to add
11linux gdbserver support for Microblaze.
12
13Signed-off-by: David Holsgrove <david.holsgrove@xilinx.com>
14---
15 gdb/configure.tgt | 1 +
16 1 file changed, 1 insertion(+)
17
18diff --git a/gdb/configure.tgt b/gdb/configure.tgt
19index 622bd486b3..989523735b 100644
20--- a/gdb/configure.tgt
21+++ b/gdb/configure.tgt
22@@ -405,6 +405,7 @@ microblaze*-*-*)
23 # Target: Xilinx MicroBlaze running standalone
24 gdb_target_obs="microblaze-tdep.o"
25 gdb_sim=../sim/microblaze/libsim.a
26+ build_gdbserver=yes
27 ;;
28
29 mips*-*-linux*)
30--
312.17.1
32
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0038-Initial-support-for-native-gdb.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0038-Initial-support-for-native-gdb.patch
new file mode 100644
index 00000000..ca37355c
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0038-Initial-support-for-native-gdb.patch
@@ -0,0 +1,511 @@
1From fef2dfc9c55d19be25262175a4fa4921167a30b7 Mon Sep 17 00:00:00 2001
2From: David Holsgrove <david.holsgrove@petalogix.com>
3Date: Fri, 20 Jul 2012 15:18:35 +1000
4Subject: [PATCH 38/43] Initial support for native gdb
5
6microblaze: Follow PPC method of getting setting registers
7using PTRACE PEEK/POKE
8
9Signed-off-by: David Holsgrove <david.holsgrove@petalogix.com>
10
11Conflicts:
12 gdb/Makefile.in
13---
14 gdb/Makefile.in | 4 +-
15 gdb/config/microblaze/linux.mh | 9 +
16 gdb/microblaze-linux-nat.c | 431 +++++++++++++++++++++++++++++++++
17 3 files changed, 443 insertions(+), 1 deletion(-)
18 create mode 100644 gdb/config/microblaze/linux.mh
19 create mode 100644 gdb/microblaze-linux-nat.c
20
21diff --git a/gdb/Makefile.in b/gdb/Makefile.in
22index 5614cc3386..d620580498 100644
23--- a/gdb/Makefile.in
24+++ b/gdb/Makefile.in
25@@ -1316,6 +1316,7 @@ HFILES_NO_SRCDIR = \
26 memory-map.h \
27 memrange.h \
28 microblaze-tdep.h \
29+ microblaze-linux-tdep.h \
30 mips-linux-tdep.h \
31 mips-nbsd-tdep.h \
32 mips-tdep.h \
33@@ -1349,6 +1350,7 @@ HFILES_NO_SRCDIR = \
34 prologue-value.h \
35 psympriv.h \
36 psymtab.h \
37+ ia64-hpux-tdep.h \
38 ravenscar-thread.h \
39 record.h \
40 record-full.h \
41@@ -2263,6 +2265,7 @@ ALLDEPFILES = \
42 m68k-tdep.c \
43 microblaze-linux-tdep.c \
44 microblaze-tdep.c \
45+ microblaze-linux-nat.c \
46 mingw-hdep.c \
47 mips-fbsd-nat.c \
48 mips-fbsd-tdep.c \
49@@ -2365,7 +2368,6 @@ ALLDEPFILES = \
50 xtensa-linux-tdep.c \
51 xtensa-tdep.c \
52 xtensa-xtregs.c \
53- common/mingw-strerror.c \
54 common/posix-strerror.c
55
56 # Some files need explicit build rules (due to -Werror problems) or due
57diff --git a/gdb/config/microblaze/linux.mh b/gdb/config/microblaze/linux.mh
58new file mode 100644
59index 0000000000..a4eaf540e1
60--- /dev/null
61+++ b/gdb/config/microblaze/linux.mh
62@@ -0,0 +1,9 @@
63+# Host: Microblaze, running Linux
64+
65+NAT_FILE= config/nm-linux.h
66+NATDEPFILES= inf-ptrace.o fork-child.o \
67+ microblaze-linux-nat.o proc-service.o linux-thread-db.o \
68+ linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o
69+NAT_CDEPS = $(srcdir)/proc-service.list
70+
71+LOADLIBES = -ldl $(RDYNAMIC)
72diff --git a/gdb/microblaze-linux-nat.c b/gdb/microblaze-linux-nat.c
73new file mode 100644
74index 0000000000..e9b8c9c522
75--- /dev/null
76+++ b/gdb/microblaze-linux-nat.c
77@@ -0,0 +1,431 @@
78+/* Microblaze GNU/Linux native support.
79+
80+ Copyright (C) 1988-1989, 1991-1992, 1994, 1996, 2000-2012 Free
81+ Software Foundation, Inc.
82+
83+ This file is part of GDB.
84+
85+ This program is free software; you can redistribute it and/or modify
86+ it under the terms of the GNU General Public License as published by
87+ the Free Software Foundation; either version 3 of the License, or
88+ (at your option) any later version.
89+
90+ This program is distributed in the hope that it will be useful,
91+ but WITHOUT ANY WARRANTY; without even the implied warranty of
92+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93+ GNU General Public License for more details.
94+
95+ You should have received a copy of the GNU General Public License
96+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
97+
98+#include "defs.h"
99+#include "arch-utils.h"
100+#include "dis-asm.h"
101+#include "frame.h"
102+#include "trad-frame.h"
103+#include "symtab.h"
104+#include "value.h"
105+#include "gdbcmd.h"
106+#include "breakpoint.h"
107+#include "inferior.h"
108+#include "regcache.h"
109+#include "target.h"
110+#include "frame.h"
111+#include "frame-base.h"
112+#include "frame-unwind.h"
113+#include "dwarf2-frame.h"
114+#include "osabi.h"
115+
116+#include "gdb_assert.h"
117+#include "gdb_string.h"
118+#include "target-descriptions.h"
119+#include "opcodes/microblaze-opcm.h"
120+#include "opcodes/microblaze-dis.h"
121+
122+#include "linux-nat.h"
123+#include "target-descriptions.h"
124+
125+#include <sys/user.h>
126+#include <sys/utsname.h>
127+#include <sys/procfs.h>
128+#include <sys/ptrace.h>
129+
130+/* Prototypes for supply_gregset etc. */
131+#include "gregset.h"
132+
133+#include "microblaze-tdep.h"
134+
135+#include <elf/common.h>
136+#include "auxv.h"
137+
138+/* Defines ps_err_e, struct ps_prochandle. */
139+#include "gdb_proc_service.h"
140+
141+/* On GNU/Linux, threads are implemented as pseudo-processes, in which
142+ case we may be tracing more than one process at a time. In that
143+ case, inferior_ptid will contain the main process ID and the
144+ individual thread (process) ID. get_thread_id () is used to get
145+ the thread id if it's available, and the process id otherwise. */
146+
147+int
148+get_thread_id (ptid_t ptid)
149+{
150+ int tid = TIDGET (ptid);
151+ if (0 == tid)
152+ tid = PIDGET (ptid);
153+ return tid;
154+}
155+
156+#define GET_THREAD_ID(PTID) get_thread_id (PTID)
157+
158+/* Non-zero if our kernel may support the PTRACE_GETREGS and
159+ PTRACE_SETREGS requests, for reading and writing the
160+ general-purpose registers. Zero if we've tried one of
161+ them and gotten an error. */
162+int have_ptrace_getsetregs = 1;
163+
164+static int
165+microblaze_register_u_addr (struct gdbarch *gdbarch, int regno)
166+{
167+ int u_addr = -1;
168+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
169+ /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
170+ interface, and not the wordsize of the program's ABI. */
171+ int wordsize = sizeof (long);
172+
173+ /* General purpose registers occupy 1 slot each in the buffer. */
174+ if (regno >= MICROBLAZE_R0_REGNUM
175+ && regno <= MICROBLAZE_FSR_REGNUM)
176+ u_addr = (regno * wordsize);
177+
178+ return u_addr;
179+}
180+
181+
182+static void
183+fetch_register (struct regcache *regcache, int tid, int regno)
184+{
185+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
186+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
187+ /* This isn't really an address. But ptrace thinks of it as one. */
188+ CORE_ADDR regaddr = microblaze_register_u_addr (gdbarch, regno);
189+ int bytes_transferred;
190+ unsigned int offset; /* Offset of registers within the u area. */
191+ char buf[MAX_REGISTER_SIZE];
192+
193+ if (regaddr == -1)
194+ {
195+ memset (buf, '\0', register_size (gdbarch, regno)); /* Supply zeroes */
196+ regcache_raw_supply (regcache, regno, buf);
197+ return;
198+ }
199+
200+ /* Read the raw register using sizeof(long) sized chunks. On a
201+ 32-bit platform, 64-bit floating-point registers will require two
202+ transfers. */
203+ for (bytes_transferred = 0;
204+ bytes_transferred < register_size (gdbarch, regno);
205+ bytes_transferred += sizeof (long))
206+ {
207+ long l;
208+
209+ errno = 0;
210+ l = ptrace (PTRACE_PEEKUSER, tid, (PTRACE_TYPE_ARG3) regaddr, 0);
211+ regaddr += sizeof (long);
212+ if (errno != 0)
213+ {
214+ char message[128];
215+ sprintf (message, "reading register %s (#%d)",
216+ gdbarch_register_name (gdbarch, regno), regno);
217+ perror_with_name (message);
218+ }
219+ memcpy (&buf[bytes_transferred], &l, sizeof (l));
220+ }
221+
222+ /* Now supply the register. Keep in mind that the regcache's idea
223+ of the register's size may not be a multiple of sizeof
224+ (long). */
225+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
226+ {
227+ /* Little-endian values are always found at the left end of the
228+ bytes transferred. */
229+ regcache_raw_supply (regcache, regno, buf);
230+ }
231+ else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
232+ {
233+ /* Big-endian values are found at the right end of the bytes
234+ transferred. */
235+ size_t padding = (bytes_transferred - register_size (gdbarch, regno));
236+ regcache_raw_supply (regcache, regno, buf + padding);
237+ }
238+ else
239+ internal_error (__FILE__, __LINE__,
240+ _("fetch_register: unexpected byte order: %d"),
241+ gdbarch_byte_order (gdbarch));
242+}
243+
244+/* This function actually issues the request to ptrace, telling
245+ it to get all general-purpose registers and put them into the
246+ specified regset.
247+
248+ If the ptrace request does not exist, this function returns 0
249+ and properly sets the have_ptrace_* flag. If the request fails,
250+ this function calls perror_with_name. Otherwise, if the request
251+ succeeds, then the regcache gets filled and 1 is returned. */
252+static int
253+fetch_all_gp_regs (struct regcache *regcache, int tid)
254+{
255+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
256+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
257+ gdb_gregset_t gregset;
258+
259+ if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0)
260+ {
261+ if (errno == EIO)
262+ {
263+ have_ptrace_getsetregs = 0;
264+ return 0;
265+ }
266+ perror_with_name (_("Couldn't get general-purpose registers."));
267+ }
268+
269+ supply_gregset (regcache, (const gdb_gregset_t *) &gregset);
270+
271+ return 1;
272+}
273+
274+
275+/* This is a wrapper for the fetch_all_gp_regs function. It is
276+ responsible for verifying if this target has the ptrace request
277+ that can be used to fetch all general-purpose registers at one
278+ shot. If it doesn't, then we should fetch them using the
279+ old-fashioned way, which is to iterate over the registers and
280+ request them one by one. */
281+static void
282+fetch_gp_regs (struct regcache *regcache, int tid)
283+{
284+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
285+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
286+ int i;
287+
288+ if (have_ptrace_getsetregs)
289+ if (fetch_all_gp_regs (regcache, tid))
290+ return;
291+
292+ /* If we've hit this point, it doesn't really matter which
293+ architecture we are using. We just need to read the
294+ registers in the "old-fashioned way". */
295+ for (i = MICROBLAZE_R0_REGNUM; i <= MICROBLAZE_FSR_REGNUM; i++)
296+ fetch_register (regcache, tid, i);
297+}
298+
299+
300+static void
301+store_register (const struct regcache *regcache, int tid, int regno)
302+{
303+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
304+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
305+ /* This isn't really an address. But ptrace thinks of it as one. */
306+ CORE_ADDR regaddr = microblaze_register_u_addr (gdbarch, regno);
307+ int i;
308+ size_t bytes_to_transfer;
309+ char buf[MAX_REGISTER_SIZE];
310+
311+ if (regaddr == -1)
312+ return;
313+
314+ /* First collect the register. Keep in mind that the regcache's
315+ idea of the register's size may not be a multiple of sizeof
316+ (long). */
317+ memset (buf, 0, sizeof buf);
318+ bytes_to_transfer = align_up (register_size (gdbarch, regno), sizeof (long));
319+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
320+ {
321+ /* Little-endian values always sit at the left end of the buffer. */
322+ regcache_raw_collect (regcache, regno, buf);
323+ }
324+ else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
325+ {
326+ /* Big-endian values sit at the right end of the buffer. */
327+ size_t padding = (bytes_to_transfer - register_size (gdbarch, regno));
328+ regcache_raw_collect (regcache, regno, buf + padding);
329+ }
330+
331+ for (i = 0; i < bytes_to_transfer; i += sizeof (long))
332+ {
333+ long l;
334+
335+ memcpy (&l, &buf[i], sizeof (l));
336+ errno = 0;
337+ ptrace (PTRACE_POKEUSER, tid, (PTRACE_TYPE_ARG3) regaddr, l);
338+ regaddr += sizeof (long);
339+
340+ if (errno != 0)
341+ {
342+ char message[128];
343+ sprintf (message, "writing register %s (#%d)",
344+ gdbarch_register_name (gdbarch, regno), regno);
345+ perror_with_name (message);
346+ }
347+ }
348+}
349+
350+/* This function actually issues the request to ptrace, telling
351+ it to store all general-purpose registers present in the specified
352+ regset.
353+
354+ If the ptrace request does not exist, this function returns 0
355+ and properly sets the have_ptrace_* flag. If the request fails,
356+ this function calls perror_with_name. Otherwise, if the request
357+ succeeds, then the regcache is stored and 1 is returned. */
358+static int
359+store_all_gp_regs (const struct regcache *regcache, int tid, int regno)
360+{
361+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
362+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
363+ gdb_gregset_t gregset;
364+
365+ if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0)
366+ {
367+ if (errno == EIO)
368+ {
369+ have_ptrace_getsetregs = 0;
370+ return 0;
371+ }
372+ perror_with_name (_("Couldn't get general-purpose registers."));
373+ }
374+
375+ fill_gregset (regcache, &gregset, regno);
376+
377+ if (ptrace (PTRACE_SETREGS, tid, 0, (void *) &gregset) < 0)
378+ {
379+ if (errno == EIO)
380+ {
381+ have_ptrace_getsetregs = 0;
382+ return 0;
383+ }
384+ perror_with_name (_("Couldn't set general-purpose registers."));
385+ }
386+
387+ return 1;
388+}
389+
390+/* This is a wrapper for the store_all_gp_regs function. It is
391+ responsible for verifying if this target has the ptrace request
392+ that can be used to store all general-purpose registers at one
393+ shot. If it doesn't, then we should store them using the
394+ old-fashioned way, which is to iterate over the registers and
395+ store them one by one. */
396+static void
397+store_gp_regs (const struct regcache *regcache, int tid, int regno)
398+{
399+ struct gdbarch *gdbarch = get_regcache_arch (regcache);
400+ struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
401+ int i;
402+
403+ if (have_ptrace_getsetregs)
404+ if (store_all_gp_regs (regcache, tid, regno))
405+ return;
406+
407+ /* If we hit this point, it doesn't really matter which
408+ architecture we are using. We just need to store the
409+ registers in the "old-fashioned way". */
410+ for (i = MICROBLAZE_R0_REGNUM; i <= MICROBLAZE_FSR_REGNUM; i++)
411+ store_register (regcache, tid, i);
412+}
413+
414+
415+/* Fetch registers from the child process. Fetch all registers if
416+ regno == -1, otherwise fetch all general registers or all floating
417+ point registers depending upon the value of regno. */
418+
419+static void
420+microblaze_linux_fetch_inferior_registers (struct target_ops *ops,
421+ struct regcache *regcache, int regno)
422+{
423+ /* Get the thread id for the ptrace call. */
424+ int tid = GET_THREAD_ID (inferior_ptid);
425+
426+ if (regno == -1)
427+ fetch_gp_regs (regcache, tid);
428+ else
429+ fetch_register (regcache, tid, regno);
430+}
431+
432+/* Store registers back into the inferior. Store all registers if
433+ regno == -1, otherwise store all general registers or all floating
434+ point registers depending upon the value of regno. */
435+
436+static void
437+microblaze_linux_store_inferior_registers (struct target_ops *ops,
438+ struct regcache *regcache, int regno)
439+{
440+ /* Get the thread id for the ptrace call. */
441+ int tid = GET_THREAD_ID (inferior_ptid);
442+
443+ if (regno >= 0)
444+ store_register (regcache, tid, regno);
445+ else
446+ store_gp_regs (regcache, tid, -1);
447+}
448+
449+/* Wrapper functions for the standard regset handling, used by
450+ thread debugging. */
451+
452+void
453+fill_gregset (const struct regcache *regcache,
454+ gdb_gregset_t *gregsetp, int regno)
455+{
456+ microblaze_collect_gregset (NULL, regcache, regno, gregsetp);
457+}
458+
459+void
460+supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
461+{
462+ microblaze_supply_gregset (NULL, regcache, -1, gregsetp);
463+}
464+
465+void
466+fill_fpregset (const struct regcache *regcache,
467+ gdb_fpregset_t *fpregsetp, int regno)
468+{
469+ /* FIXME. */
470+}
471+
472+void
473+supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
474+{
475+ /* FIXME. */
476+}
477+
478+static const struct target_desc *
479+microblaze_linux_read_description (struct target_ops *ops)
480+{
481+ CORE_ADDR microblaze_hwcap = 0;
482+
483+ if (target_auxv_search (ops, AT_HWCAP, &microblaze_hwcap) != 1)
484+ return NULL;
485+
486+ return NULL;
487+}
488+
489+
490+void _initialize_microblaze_linux_nat (void);
491+
492+void
493+_initialize_microblaze_linux_nat (void)
494+{
495+ struct target_ops *t;
496+
497+ /* Fill in the generic GNU/Linux methods. */
498+ t = linux_target ();
499+
500+ /* Add our register access methods. */
501+ t->to_fetch_registers = microblaze_linux_fetch_inferior_registers;
502+ t->to_store_registers = microblaze_linux_store_inferior_registers;
503+
504+ t->to_read_description = microblaze_linux_read_description;
505+
506+ /* Register the target. */
507+ linux_nat_add_target (t);
508+}
509--
5102.17.1
511
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0039-Fixing-the-issues-related-to-GDB-7.12.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0039-Fixing-the-issues-related-to-GDB-7.12.patch
new file mode 100644
index 00000000..b8fb68bc
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0039-Fixing-the-issues-related-to-GDB-7.12.patch
@@ -0,0 +1,309 @@
1From e3e7d58035fb75b6cf33689352c6e22309c6dbde Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Fri, 17 Feb 2017 14:09:40 +0530
4Subject: [PATCH 39/43] Fixing the issues related to GDB-7.12 added all the
5 required function which are new in 7.12 and removed few deprecated functions
6 from 7.6
7
8---
9 gdb/config/microblaze/linux.mh | 4 +-
10 gdb/gdbserver/configure.srv | 3 +-
11 gdb/gdbserver/linux-microblaze-low.c | 97 ++++++++++++++++++++++++----
12 gdb/microblaze-linux-tdep.c | 68 +++++++++++++++++--
13 gdb/microblaze-tdep.h | 1 +
14 5 files changed, 153 insertions(+), 20 deletions(-)
15
16diff --git a/gdb/config/microblaze/linux.mh b/gdb/config/microblaze/linux.mh
17index a4eaf540e1..74a53b854a 100644
18--- a/gdb/config/microblaze/linux.mh
19+++ b/gdb/config/microblaze/linux.mh
20@@ -1,9 +1,11 @@
21 # Host: Microblaze, running Linux
22
23+#linux-nat.o linux-waitpid.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o
24 NAT_FILE= config/nm-linux.h
25 NATDEPFILES= inf-ptrace.o fork-child.o \
26 microblaze-linux-nat.o proc-service.o linux-thread-db.o \
27- linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o
28+ linux-nat.o linux-osdata.o linux-fork.o linux-procfs.o linux-ptrace.o \
29+ linux-waitpid.o linux-personality.o linux-namespaces.o
30 NAT_CDEPS = $(srcdir)/proc-service.list
31
32 LOADLIBES = -ldl $(RDYNAMIC)
33diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
34index 153dcb4c71..201b7ae190 100644
35--- a/gdb/gdbserver/configure.srv
36+++ b/gdb/gdbserver/configure.srv
37@@ -211,8 +211,7 @@ case "${target}" in
38 srv_linux_thread_db=yes
39 ;;
40 microblaze*-*-linux*) srv_regobj=microblaze-linux.o
41- srv_tgtobj="linux-low.o linux-osdata.o linux-microblaze-low.o "
42- srv_tgtobj="${srv_tgtobj} linux-procfs.o linux-ptrace.o"
43+ srv_tgtobj="$srv_linux_obj linux-microblaze-low.o "
44 srv_linux_regsets=yes
45 srv_linux_usrregs=yes
46 srv_linux_thread_db=yes
47diff --git a/gdb/gdbserver/linux-microblaze-low.c b/gdb/gdbserver/linux-microblaze-low.c
48index cba5d6fc58..a2733f3c21 100644
49--- a/gdb/gdbserver/linux-microblaze-low.c
50+++ b/gdb/gdbserver/linux-microblaze-low.c
51@@ -39,10 +39,11 @@ static int microblaze_regmap[] =
52 PT_FSR
53 };
54
55-#define microblaze_num_regs (sizeof microblaze_regmap / sizeof microblaze_regmap[0])
56+#define microblaze_num_regs (sizeof (microblaze_regmap) / sizeof (microblaze_regmap[0]))
57
58 /* Defined in auto-generated file microblaze-linux.c. */
59 void init_registers_microblaze (void);
60+extern const struct target_desc *tdesc_microblaze;
61
62 static int
63 microblaze_cannot_store_register (int regno)
64@@ -81,6 +82,15 @@ microblaze_set_pc (struct regcache *regcache, CORE_ADDR pc)
65 static const unsigned long microblaze_breakpoint = 0xba0c0018;
66 #define microblaze_breakpoint_len 4
67
68+/* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
69+
70+static const gdb_byte *
71+microblaze_sw_breakpoint_from_kind (int kind, int *size)
72+{
73+ *size = microblaze_breakpoint_len;
74+ return (const gdb_byte *) &microblaze_breakpoint;
75+}
76+
77 static int
78 microblaze_breakpoint_at (CORE_ADDR where)
79 {
80@@ -107,7 +117,7 @@ microblaze_reinsert_addr (struct regcache *regcache)
81 static void
82 microblaze_collect_ptrace_register (struct regcache *regcache, int regno, char *buf)
83 {
84- int size = register_size (regno);
85+ int size = register_size (regcache->tdesc, regno);
86
87 memset (buf, 0, sizeof (long));
88
89@@ -121,7 +131,7 @@ static void
90 microblaze_supply_ptrace_register (struct regcache *regcache,
91 int regno, const char *buf)
92 {
93- int size = register_size (regno);
94+ int size = register_size (regcache->tdesc, regno);
95
96 if (regno == 0) {
97 unsigned long regbuf_0 = 0;
98@@ -157,33 +167,94 @@ microblaze_store_gregset (struct regcache *regcache, const void *buf)
99
100 #endif /* HAVE_PTRACE_GETREGS */
101
102-struct regset_info target_regsets[] = {
103+static struct regset_info microblaze_regsets[] = {
104 #ifdef HAVE_PTRACE_GETREGS
105 { PTRACE_GETREGS, PTRACE_SETREGS, 0, sizeof (elf_gregset_t), GENERAL_REGS, microblaze_fill_gregset, microblaze_store_gregset },
106- { 0, 0, 0, -1, -1, NULL, NULL },
107+ { 0, 0, 0, -1, GENERAL_REGS, NULL, NULL },
108 #endif /* HAVE_PTRACE_GETREGS */
109- { 0, 0, 0, -1, -1, NULL, NULL }
110+ { 0, 0, 0, -1, GENERAL_REGS, NULL, NULL },
111+ NULL_REGSET
112 };
113
114+static struct usrregs_info microblaze_usrregs_info =
115+ {
116+ microblaze_num_regs,
117+ microblaze_regmap,
118+ };
119+
120+static struct regsets_info microblaze_regsets_info =
121+ {
122+ microblaze_regsets, /* regsets */
123+ 0, /* num_regsets */
124+ NULL, /* disabled_regsets */
125+ };
126+
127+static struct regs_info regs_info =
128+ {
129+ NULL, /* regset_bitmap */
130+ &microblaze_usrregs_info,
131+ &microblaze_regsets_info
132+ };
133+
134+static const struct regs_info *
135+microblaze_regs_info (void)
136+{
137+ return &regs_info;
138+}
139+
140+/* Support for hardware single step. */
141+
142+static int
143+microblaze_supports_hardware_single_step (void)
144+{
145+ return 1;
146+}
147+
148+
149+static void
150+microblaze_arch_setup (void)
151+{
152+ current_process ()->tdesc = tdesc_microblaze;
153+}
154+
155 struct linux_target_ops the_low_target = {
156- init_registers_microblaze,
157- microblaze_num_regs,
158- microblaze_regmap,
159- NULL,
160+ microblaze_arch_setup,
161+ microblaze_regs_info,
162 microblaze_cannot_fetch_register,
163 microblaze_cannot_store_register,
164 NULL, /* fetch_register */
165 microblaze_get_pc,
166 microblaze_set_pc,
167- (const unsigned char *) &microblaze_breakpoint,
168- microblaze_breakpoint_len,
169- microblaze_reinsert_addr,
170+ NULL,
171+ microblaze_sw_breakpoint_from_kind,
172+ NULL,
173 0,
174 microblaze_breakpoint_at,
175 NULL,
176 NULL,
177 NULL,
178 NULL,
179+ NULL,
180 microblaze_collect_ptrace_register,
181 microblaze_supply_ptrace_register,
182+ NULL, /* siginfo_fixup */
183+ NULL, /* new_process */
184+ NULL, /* new_thread */
185+ NULL, /* new_fork */
186+ NULL, /* prepare_to_resume */
187+ NULL, /* process_qsupported */
188+ NULL, /* supports_tracepoints */
189+ NULL, /* get_thread_area */
190+ NULL, /* install_fast_tracepoint_jump_pad */
191+ NULL, /* emit_ops */
192+ NULL, /* get_min_fast_tracepoint_insn_len */
193+ NULL, /* supports_range_stepping */
194+ NULL, /* breakpoint_kind_from_current_state */
195+ microblaze_supports_hardware_single_step,
196 };
197+
198+void
199+initialize_low_arch (void)
200+{
201+ init_registers_microblaze ();
202+}
203diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
204index e2225d778a..011e513941 100644
205--- a/gdb/microblaze-linux-tdep.c
206+++ b/gdb/microblaze-linux-tdep.c
207@@ -29,13 +29,76 @@
208 #include "regcache.h"
209 #include "value.h"
210 #include "osabi.h"
211-#include "regset.h"
212 #include "solib-svr4.h"
213 #include "microblaze-tdep.h"
214 #include "trad-frame.h"
215 #include "frame-unwind.h"
216 #include "tramp-frame.h"
217 #include "linux-tdep.h"
218+#include "glibc-tdep.h"
219+
220+#include "gdb_assert.h"
221+
222+#ifndef REGSET_H
223+#define REGSET_H 1
224+
225+struct gdbarch;
226+struct regcache;
227+
228+/* Data structure for the supported register notes in a core file. */
229+struct core_regset_section
230+{
231+ const char *sect_name;
232+ int size;
233+ const char *human_name;
234+};
235+
236+/* Data structure describing a register set. */
237+
238+typedef void (supply_regset_ftype) (const struct regset *, struct regcache *,
239+ int, const void *, size_t);
240+typedef void (collect_regset_ftype) (const struct regset *,
241+ const struct regcache *,
242+ int, void *, size_t);
243+
244+struct regset
245+{
246+ /* Data pointer for private use by the methods below, presumably
247+ providing some sort of description of the register set. */
248+ const void *descr;
249+
250+ /* Function supplying values in a register set to a register cache. */
251+ supply_regset_ftype *supply_regset;
252+
253+ /* Function collecting values in a register set from a register cache. */
254+ collect_regset_ftype *collect_regset;
255+
256+ /* Architecture associated with the register set. */
257+ struct gdbarch *arch;
258+};
259+
260+#endif
261+
262+/* Allocate a fresh 'struct regset' whose supply_regset function is
263+ SUPPLY_REGSET, and whose collect_regset function is COLLECT_REGSET.
264+ If the regset has no collect_regset function, pass NULL for
265+ COLLECT_REGSET.
266+
267+ The object returned is allocated on ARCH's obstack. */
268+
269+struct regset *
270+regset_alloc (struct gdbarch *arch,
271+ supply_regset_ftype *supply_regset,
272+ collect_regset_ftype *collect_regset)
273+{
274+ struct regset *regset = GDBARCH_OBSTACK_ZALLOC (arch, struct regset);
275+
276+ regset->arch = arch;
277+ regset->supply_regset = supply_regset;
278+ regset->collect_regset = collect_regset;
279+
280+ return regset;
281+}
282
283 static int microblaze_debug_flag = 0;
284
285@@ -207,9 +270,6 @@ microblaze_linux_init_abi (struct gdbarch_info info,
286 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
287 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
288
289- set_gdbarch_regset_from_core_section (gdbarch,
290- microblaze_regset_from_core_section);
291-
292 /* Enable TLS support. */
293 set_gdbarch_fetch_tls_load_module_address (gdbarch,
294 svr4_fetch_objfile_link_map);
295diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
296index 02650f61d9..3777cbb6a8 100644
297--- a/gdb/microblaze-tdep.h
298+++ b/gdb/microblaze-tdep.h
299@@ -24,6 +24,7 @@
300 /* Microblaze architecture-specific information. */
301 struct microblaze_gregset
302 {
303+ microblaze_gregset() {}
304 unsigned int gregs[32];
305 unsigned int fpregs[32];
306 unsigned int pregs[16];
307--
3082.17.1
309
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0040-Patch-microblaze-Adding-64-bit-MB-support.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0040-Patch-microblaze-Adding-64-bit-MB-support.patch
new file mode 100644
index 00000000..e89d4049
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0040-Patch-microblaze-Adding-64-bit-MB-support.patch
@@ -0,0 +1,1110 @@
1From ecaa548038df1ebf653ef3c3429e49c207461b19 Mon Sep 17 00:00:00 2001
2From: Nagaraju Mekala <nmekala@xilix.com>
3Date: Thu, 31 Jan 2019 14:36:00 +0530
4Subject: [PATCH 40/43] [Patch, microblaze]: Adding 64 bit MB support Added new
5 architecture to Microblaze 64-bit support to GDB Signed-off-by :Nagaraju
6 Mekala <nmekala@xilix.com>
7
8Merged on top of binutils work.
9
10Signed-off-by: Mark Hatle <mark.hatle@xilinx.com>
11---
12 bfd/archures.c | 2 +
13 bfd/bfd-in2.h | 2 +
14 bfd/cpu-microblaze.c | 12 +-
15 bfd/elf32-microblaze.c | 93 +-------
16 gdb/Makefile.in | 2 +-
17 gdb/features/Makefile | 3 +
18 gdb/features/microblaze-core.xml | 6 +-
19 gdb/features/microblaze-stack-protect.xml | 4 +-
20 gdb/features/microblaze-with-stack-protect.c | 8 +-
21 gdb/features/microblaze.c | 6 +-
22 gdb/features/microblaze64-core.xml | 69 ++++++
23 gdb/features/microblaze64-stack-protect.xml | 12 +
24 .../microblaze64-with-stack-protect.c | 79 +++++++
25 .../microblaze64-with-stack-protect.xml | 12 +
26 gdb/features/microblaze64.c | 77 +++++++
27 gdb/features/microblaze64.xml | 11 +
28 gdb/microblaze-tdep.c | 207 ++++++++++++++++--
29 gdb/microblaze-tdep.h | 8 +-
30 .../microblaze-with-stack-protect.dat | 4 +-
31 opcodes/microblaze-opc.h | 1 -
32 22 files changed, 504 insertions(+), 134 deletions(-)
33 create mode 100644 gdb/features/microblaze64-core.xml
34 create mode 100644 gdb/features/microblaze64-stack-protect.xml
35 create mode 100644 gdb/features/microblaze64-with-stack-protect.c
36 create mode 100644 gdb/features/microblaze64-with-stack-protect.xml
37 create mode 100644 gdb/features/microblaze64.c
38 create mode 100644 gdb/features/microblaze64.xml
39
40diff --git a/bfd/archures.c b/bfd/archures.c
41index 647cf0d8d4..3fdf7c3c0e 100644
42--- a/bfd/archures.c
43+++ b/bfd/archures.c
44@@ -512,6 +512,8 @@ DESCRIPTION
45 . bfd_arch_lm32, {* Lattice Mico32. *}
46 .#define bfd_mach_lm32 1
47 . bfd_arch_microblaze,{* Xilinx MicroBlaze. *}
48+.#define bfd_mach_microblaze 1
49+.#define bfd_mach_microblaze64 2
50 . bfd_arch_tilepro, {* Tilera TILEPro. *}
51 . bfd_arch_tilegx, {* Tilera TILE-Gx. *}
52 .#define bfd_mach_tilepro 1
53diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
54index 33c9cb62d9..db624c62b9 100644
55--- a/bfd/bfd-in2.h
56+++ b/bfd/bfd-in2.h
57@@ -2411,6 +2411,8 @@ enum bfd_architecture
58 bfd_arch_lm32, /* Lattice Mico32. */
59 #define bfd_mach_lm32 1
60 bfd_arch_microblaze,/* Xilinx MicroBlaze. */
61+#define bfd_mach_microblaze 1
62+#define bfd_mach_microblaze64 2
63 bfd_arch_tilepro, /* Tilera TILEPro. */
64 bfd_arch_tilegx, /* Tilera TILE-Gx. */
65 #define bfd_mach_tilepro 1
66diff --git a/bfd/cpu-microblaze.c b/bfd/cpu-microblaze.c
67index c91ba46f75..8e7bcead28 100644
68--- a/bfd/cpu-microblaze.c
69+++ b/bfd/cpu-microblaze.c
70@@ -30,8 +30,8 @@ const bfd_arch_info_type bfd_microblaze_arch[] =
71 64, /* 32 bits in a word. */
72 64, /* 32 bits in an address. */
73 8, /* 8 bits in a byte. */
74- bfd_arch_microblaze, /* Architecture. */
75- 0, /* Machine number - 0 for now. */
76+ bfd_arch_microblaze, /* Architecture. */
77+ bfd_mach_microblaze64, /* 64 bit Machine */
78 "microblaze", /* Architecture name. */
79 "MicroBlaze", /* Printable name. */
80 3, /* Section align power. */
81@@ -46,7 +46,7 @@ const bfd_arch_info_type bfd_microblaze_arch[] =
82 32, /* 32 bits in an address. */
83 8, /* 8 bits in a byte. */
84 bfd_arch_microblaze, /* Architecture. */
85- 0, /* Machine number - 0 for now. */
86+ bfd_mach_microblaze, /* 32 bit Machine */
87 "microblaze", /* Architecture name. */
88 "MicroBlaze", /* Printable name. */
89 3, /* Section align power. */
90@@ -62,7 +62,7 @@ const bfd_arch_info_type bfd_microblaze_arch[] =
91 32, /* 32 bits in an address. */
92 8, /* 8 bits in a byte. */
93 bfd_arch_microblaze, /* Architecture. */
94- 0, /* Machine number - 0 for now. */
95+ bfd_mach_microblaze, /* 32 bit Machine */
96 "microblaze", /* Architecture name. */
97 "MicroBlaze", /* Printable name. */
98 3, /* Section align power. */
99@@ -76,8 +76,8 @@ const bfd_arch_info_type bfd_microblaze_arch[] =
100 64, /* 32 bits in a word. */
101 64, /* 32 bits in an address. */
102 8, /* 8 bits in a byte. */
103- bfd_arch_microblaze, /* Architecture. */
104- 0, /* Machine number - 0 for now. */
105+ bfd_arch_microblaze, /* Architecture. */
106+ bfd_mach_microblaze64, /* 64 bit Machine */
107 "microblaze", /* Architecture name. */
108 "MicroBlaze", /* Printable name. */
109 3, /* Section align power. */
110diff --git a/bfd/elf32-microblaze.c b/bfd/elf32-microblaze.c
111index c280431df6..f9996eae12 100644
112--- a/bfd/elf32-microblaze.c
113+++ b/bfd/elf32-microblaze.c
114@@ -767,87 +767,6 @@ microblaze_elf_is_local_label_name (bfd *abfd, const char *name)
115 return _bfd_elf_is_local_label_name (abfd, name);
116 }
117
118-/* Support for core dump NOTE sections. */
119-static bfd_boolean
120-microblaze_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
121-{
122- int offset;
123- unsigned int size;
124-
125- switch (note->descsz)
126- {
127- default:
128- return FALSE;
129-
130- case 228: /* Linux/MicroBlaze */
131- /* pr_cursig */
132- elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
133-
134- /* pr_pid */
135- elf_tdata (abfd)->core->pid = bfd_get_32 (abfd, note->descdata + 24);
136-
137- /* pr_reg */
138- offset = 72;
139- size = 50 * 4;
140-
141- break;
142- }
143-
144- /* Make a ".reg/999" section. */
145- return _bfd_elfcore_make_pseudosection (abfd, ".reg",
146- size, note->descpos + offset);
147-}
148-
149-static bfd_boolean
150-microblaze_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
151-{
152- switch (note->descsz)
153- {
154- default:
155- return FALSE;
156-
157- case 128: /* Linux/MicroBlaze elf_prpsinfo */
158- elf_tdata (abfd)->core->program
159- = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16);
160- elf_tdata (abfd)->core->command
161- = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80);
162- }
163-
164- /* Note that for some reason, a spurious space is tacked
165- onto the end of the args in some (at least one anyway)
166- implementations, so strip it off if it exists. */
167-
168- {
169- char *command = elf_tdata (abfd)->core->command;
170- int n = strlen (command);
171-
172- if (0 < n && command[n - 1] == ' ')
173- command[n - 1] = '\0';
174- }
175-
176- return TRUE;
177-}
178-
179-/* The microblaze linker (like many others) needs to keep track of
180- the number of relocs that it decides to copy as dynamic relocs in
181- check_relocs for each symbol. This is so that it can later discard
182- them if they are found to be unnecessary. We store the information
183- in a field extending the regular ELF linker hash table. */
184-
185-struct elf32_mb_dyn_relocs
186-{
187- struct elf32_mb_dyn_relocs *next;
188-
189- /* The input section of the reloc. */
190- asection *sec;
191-
192- /* Total number of relocs copied for the input section. */
193- bfd_size_type count;
194-
195- /* Number of pc-relative relocs copied for the input section. */
196- bfd_size_type pc_count;
197-};
198-
199 /* ELF linker hash entry. */
200
201 struct elf32_mb_link_hash_entry
202@@ -3683,6 +3602,14 @@ microblaze_elf_finish_dynamic_sections (bfd *output_bfd,
203 return TRUE;
204 }
205
206+
207+static bfd_boolean
208+elf_microblaze_object_p (bfd *abfd)
209+{
210+ /* Set the right machine number for an s390 elf32 file. */
211+ return bfd_default_set_arch_mach (abfd, bfd_arch_microblaze, bfd_mach_microblaze);
212+}
213+
214 /* Hook called by the linker routine which adds symbols from an object
215 file. We use it to put .comm items in .sbss, and not .bss. */
216
217@@ -3752,8 +3679,6 @@ microblaze_elf_add_symbol_hook (bfd *abfd,
218 #define elf_backend_finish_dynamic_symbol microblaze_elf_finish_dynamic_symbol
219 #define elf_backend_size_dynamic_sections microblaze_elf_size_dynamic_sections
220 #define elf_backend_add_symbol_hook microblaze_elf_add_symbol_hook
221-
222-#define elf_backend_grok_prstatus microblaze_elf_grok_prstatus
223-#define elf_backend_grok_psinfo microblaze_elf_grok_psinfo
224+#define elf_backend_object_p elf_microblaze_object_p
225
226 #include "elf32-target.h"
227diff --git a/gdb/Makefile.in b/gdb/Makefile.in
228index d620580498..69b003f8cb 100644
229--- a/gdb/Makefile.in
230+++ b/gdb/Makefile.in
231@@ -2265,7 +2265,7 @@ ALLDEPFILES = \
232 m68k-tdep.c \
233 microblaze-linux-tdep.c \
234 microblaze-tdep.c \
235- microblaze-linux-nat.c \
236+ microblaze-linux-nat.c \
237 mingw-hdep.c \
238 mips-fbsd-nat.c \
239 mips-fbsd-tdep.c \
240diff --git a/gdb/features/Makefile b/gdb/features/Makefile
241index 3d84ca09a1..fdeec19753 100644
242--- a/gdb/features/Makefile
243+++ b/gdb/features/Makefile
244@@ -64,6 +64,7 @@ WHICH = aarch64 \
245 i386/x32-avx-avx512-linux \
246 mips-linux mips-dsp-linux \
247 microblaze-with-stack-protect \
248+ microblaze64-with-stack-protect \
249 mips64-linux mips64-dsp-linux \
250 nios2-linux \
251 rs6000/powerpc-32 \
252@@ -135,7 +136,9 @@ XMLTOC = \
253 arm/arm-with-vfpv2.xml \
254 arm/arm-with-vfpv3.xml \
255 microblaze-with-stack-protect.xml \
256+ microblaze64-with-stack-protect.xml \
257 microblaze.xml \
258+ microblaze64.xml \
259 mips-dsp-linux.xml \
260 mips-linux.xml \
261 mips64-dsp-linux.xml \
262diff --git a/gdb/features/microblaze-core.xml b/gdb/features/microblaze-core.xml
263index 88c93e5d66..5bc3e49f84 100644
264--- a/gdb/features/microblaze-core.xml
265+++ b/gdb/features/microblaze-core.xml
266@@ -8,7 +8,7 @@
267 <!DOCTYPE feature SYSTEM "gdb-target.dtd">
268 <feature name="org.gnu.gdb.microblaze.core">
269 <reg name="r0" bitsize="32" regnum="0"/>
270- <reg name="r1" bitsize="32" type="data_ptr"/>
271+ <reg name="r1" bitsize="32"/>
272 <reg name="r2" bitsize="32"/>
273 <reg name="r3" bitsize="32"/>
274 <reg name="r4" bitsize="32"/>
275@@ -39,7 +39,7 @@
276 <reg name="r29" bitsize="32"/>
277 <reg name="r30" bitsize="32"/>
278 <reg name="r31" bitsize="32"/>
279- <reg name="rpc" bitsize="32" type="code_ptr"/>
280+ <reg name="rpc" bitsize="32"/>
281 <reg name="rmsr" bitsize="32"/>
282 <reg name="rear" bitsize="32"/>
283 <reg name="resr" bitsize="32"/>
284@@ -64,4 +64,6 @@
285 <reg name="rtlbsx" bitsize="32"/>
286 <reg name="rtlblo" bitsize="32"/>
287 <reg name="rtlbhi" bitsize="32"/>
288+ <reg name="slr" bitsize="32"/>
289+ <reg name="shr" bitsize="32"/>
290 </feature>
291diff --git a/gdb/features/microblaze-stack-protect.xml b/gdb/features/microblaze-stack-protect.xml
292index 870c148bb0..a7f27b903c 100644
293--- a/gdb/features/microblaze-stack-protect.xml
294+++ b/gdb/features/microblaze-stack-protect.xml
295@@ -7,6 +7,6 @@
296
297 <!DOCTYPE feature SYSTEM "gdb-target.dtd">
298 <feature name="org.gnu.gdb.microblaze.stack-protect">
299- <reg name="rslr" bitsize="32"/>
300- <reg name="rshr" bitsize="32"/>
301+ <reg name="slr" bitsize="32"/>
302+ <reg name="shr" bitsize="32"/>
303 </feature>
304diff --git a/gdb/features/microblaze-with-stack-protect.c b/gdb/features/microblaze-with-stack-protect.c
305index b39aa19887..609934e2b4 100644
306--- a/gdb/features/microblaze-with-stack-protect.c
307+++ b/gdb/features/microblaze-with-stack-protect.c
308@@ -14,7 +14,7 @@ initialize_tdesc_microblaze_with_stack_protect (void)
309
310 feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze.core");
311 tdesc_create_reg (feature, "r0", 0, 1, NULL, 32, "int");
312- tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "data_ptr");
313+ tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "int");
314 tdesc_create_reg (feature, "r2", 2, 1, NULL, 32, "int");
315 tdesc_create_reg (feature, "r3", 3, 1, NULL, 32, "int");
316 tdesc_create_reg (feature, "r4", 4, 1, NULL, 32, "int");
317@@ -45,7 +45,7 @@ initialize_tdesc_microblaze_with_stack_protect (void)
318 tdesc_create_reg (feature, "r29", 29, 1, NULL, 32, "int");
319 tdesc_create_reg (feature, "r30", 30, 1, NULL, 32, "int");
320 tdesc_create_reg (feature, "r31", 31, 1, NULL, 32, "int");
321- tdesc_create_reg (feature, "rpc", 32, 1, NULL, 32, "code_ptr");
322+ tdesc_create_reg (feature, "rpc", 32, 1, NULL, 32, "int");
323 tdesc_create_reg (feature, "rmsr", 33, 1, NULL, 32, "int");
324 tdesc_create_reg (feature, "rear", 34, 1, NULL, 32, "int");
325 tdesc_create_reg (feature, "resr", 35, 1, NULL, 32, "int");
326@@ -72,8 +72,8 @@ initialize_tdesc_microblaze_with_stack_protect (void)
327 tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
328
329 feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze.stack-protect");
330- tdesc_create_reg (feature, "rslr", 57, 1, NULL, 32, "int");
331- tdesc_create_reg (feature, "rshr", 58, 1, NULL, 32, "int");
332+ tdesc_create_reg (feature, "slr", 57, 1, NULL, 32, "int");
333+ tdesc_create_reg (feature, "shr", 58, 1, NULL, 32, "int");
334
335 tdesc_microblaze_with_stack_protect = result;
336 }
337diff --git a/gdb/features/microblaze.c b/gdb/features/microblaze.c
338index 6c86fc0770..ceb98ca8b8 100644
339--- a/gdb/features/microblaze.c
340+++ b/gdb/features/microblaze.c
341@@ -14,7 +14,7 @@ initialize_tdesc_microblaze (void)
342
343 feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze.core");
344 tdesc_create_reg (feature, "r0", 0, 1, NULL, 32, "int");
345- tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "data_ptr");
346+ tdesc_create_reg (feature, "r1", 1, 1, NULL, 32, "int");
347 tdesc_create_reg (feature, "r2", 2, 1, NULL, 32, "int");
348 tdesc_create_reg (feature, "r3", 3, 1, NULL, 32, "int");
349 tdesc_create_reg (feature, "r4", 4, 1, NULL, 32, "int");
350@@ -45,7 +45,7 @@ initialize_tdesc_microblaze (void)
351 tdesc_create_reg (feature, "r29", 29, 1, NULL, 32, "int");
352 tdesc_create_reg (feature, "r30", 30, 1, NULL, 32, "int");
353 tdesc_create_reg (feature, "r31", 31, 1, NULL, 32, "int");
354- tdesc_create_reg (feature, "rpc", 32, 1, NULL, 32, "code_ptr");
355+ tdesc_create_reg (feature, "rpc", 32, 1, NULL, 32, "int");
356 tdesc_create_reg (feature, "rmsr", 33, 1, NULL, 32, "int");
357 tdesc_create_reg (feature, "rear", 34, 1, NULL, 32, "int");
358 tdesc_create_reg (feature, "resr", 35, 1, NULL, 32, "int");
359@@ -70,6 +70,8 @@ initialize_tdesc_microblaze (void)
360 tdesc_create_reg (feature, "rtlbsx", 54, 1, NULL, 32, "int");
361 tdesc_create_reg (feature, "rtlblo", 55, 1, NULL, 32, "int");
362 tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
363+ tdesc_create_reg (feature, "slr", 57, 1, NULL, 64, "uint64");
364+ tdesc_create_reg (feature, "shr", 58, 1, NULL, 64, "uint64");
365
366 tdesc_microblaze = result;
367 }
368diff --git a/gdb/features/microblaze64-core.xml b/gdb/features/microblaze64-core.xml
369new file mode 100644
370index 0000000000..96e99e2fb2
371--- /dev/null
372+++ b/gdb/features/microblaze64-core.xml
373@@ -0,0 +1,69 @@
374+<?xml version="1.0"?>
375+<!-- Copyright (C) 2014-2018 Free Software Foundation, Inc.
376+
377+ Copying and distribution of this file, with or without modification,
378+ are permitted in any medium without royalty provided the copyright
379+ notice and this notice are preserved. -->
380+
381+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
382+<feature name="org.gnu.gdb.microblaze64.core">
383+ <reg name="r0" bitsize="64" regnum="0"/>
384+ <reg name="r1" bitsize="64"/>
385+ <reg name="r2" bitsize="64"/>
386+ <reg name="r3" bitsize="64"/>
387+ <reg name="r4" bitsize="64"/>
388+ <reg name="r5" bitsize="64"/>
389+ <reg name="r6" bitsize="64"/>
390+ <reg name="r7" bitsize="64"/>
391+ <reg name="r8" bitsize="64"/>
392+ <reg name="r9" bitsize="64"/>
393+ <reg name="r10" bitsize="64"/>
394+ <reg name="r11" bitsize="64"/>
395+ <reg name="r12" bitsize="64"/>
396+ <reg name="r13" bitsize="64"/>
397+ <reg name="r14" bitsize="64"/>
398+ <reg name="r15" bitsize="64"/>
399+ <reg name="r16" bitsize="64"/>
400+ <reg name="r17" bitsize="64"/>
401+ <reg name="r18" bitsize="64"/>
402+ <reg name="r19" bitsize="64"/>
403+ <reg name="r20" bitsize="64"/>
404+ <reg name="r21" bitsize="64"/>
405+ <reg name="r22" bitsize="64"/>
406+ <reg name="r23" bitsize="64"/>
407+ <reg name="r24" bitsize="64"/>
408+ <reg name="r25" bitsize="64"/>
409+ <reg name="r26" bitsize="64"/>
410+ <reg name="r27" bitsize="64"/>
411+ <reg name="r28" bitsize="64"/>
412+ <reg name="r29" bitsize="64"/>
413+ <reg name="r30" bitsize="64"/>
414+ <reg name="r31" bitsize="64"/>
415+ <reg name="rpc" bitsize="64"/>
416+ <reg name="rmsr" bitsize="32"/>
417+ <reg name="rear" bitsize="64"/>
418+ <reg name="resr" bitsize="32"/>
419+ <reg name="rfsr" bitsize="32"/>
420+ <reg name="rbtr" bitsize="64"/>
421+ <reg name="rpvr0" bitsize="32"/>
422+ <reg name="rpvr1" bitsize="32"/>
423+ <reg name="rpvr2" bitsize="32"/>
424+ <reg name="rpvr3" bitsize="32"/>
425+ <reg name="rpvr4" bitsize="32"/>
426+ <reg name="rpvr5" bitsize="32"/>
427+ <reg name="rpvr6" bitsize="32"/>
428+ <reg name="rpvr7" bitsize="32"/>
429+ <reg name="rpvr8" bitsize="64"/>
430+ <reg name="rpvr9" bitsize="64"/>
431+ <reg name="rpvr10" bitsize="32"/>
432+ <reg name="rpvr11" bitsize="32"/>
433+ <reg name="redr" bitsize="32"/>
434+ <reg name="rpid" bitsize="32"/>
435+ <reg name="rzpr" bitsize="32"/>
436+ <reg name="rtlbx" bitsize="32"/>
437+ <reg name="rtlbsx" bitsize="32"/>
438+ <reg name="rtlblo" bitsize="32"/>
439+ <reg name="rtlbhi" bitsize="32"/>
440+ <reg name="slr" bitsize="64"/>
441+ <reg name="shr" bitsize="64"/>
442+</feature>
443diff --git a/gdb/features/microblaze64-stack-protect.xml b/gdb/features/microblaze64-stack-protect.xml
444new file mode 100644
445index 0000000000..1bbf5fc3ce
446--- /dev/null
447+++ b/gdb/features/microblaze64-stack-protect.xml
448@@ -0,0 +1,12 @@
449+<?xml version="1.0"?>
450+<!-- Copyright (C) 2014-2018 Free Software Foundation, Inc.
451+
452+ Copying and distribution of this file, with or without modification,
453+ are permitted in any medium without royalty provided the copyright
454+ notice and this notice are preserved. -->
455+
456+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
457+<feature name="org.gnu.gdb.microblaze64.stack-protect">
458+ <reg name="slr" bitsize="64"/>
459+ <reg name="shr" bitsize="64"/>
460+</feature>
461diff --git a/gdb/features/microblaze64-with-stack-protect.c b/gdb/features/microblaze64-with-stack-protect.c
462new file mode 100644
463index 0000000000..f448c9a749
464--- /dev/null
465+++ b/gdb/features/microblaze64-with-stack-protect.c
466@@ -0,0 +1,79 @@
467+/* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro:
468+ Original: microblaze-with-stack-protect.xml */
469+
470+#include "defs.h"
471+#include "osabi.h"
472+#include "target-descriptions.h"
473+
474+struct target_desc *tdesc_microblaze64_with_stack_protect;
475+static void
476+initialize_tdesc_microblaze64_with_stack_protect (void)
477+{
478+ struct target_desc *result = allocate_target_description ();
479+ struct tdesc_feature *feature;
480+
481+ feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze64.core");
482+ tdesc_create_reg (feature, "r0", 0, 1, NULL, 64, "uint64");
483+ tdesc_create_reg (feature, "r1", 1, 1, NULL, 64, "uint64");
484+ tdesc_create_reg (feature, "r2", 2, 1, NULL, 64, "uint64");
485+ tdesc_create_reg (feature, "r3", 3, 1, NULL, 64, "uint64");
486+ tdesc_create_reg (feature, "r4", 4, 1, NULL, 64, "uint64");
487+ tdesc_create_reg (feature, "r5", 5, 1, NULL, 64, "uint64");
488+ tdesc_create_reg (feature, "r6", 6, 1, NULL, 64, "uint64");
489+ tdesc_create_reg (feature, "r7", 7, 1, NULL, 64, "uint64");
490+ tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "uint64");
491+ tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "uint64");
492+ tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "uint64");
493+ tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "uint64");
494+ tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "uint64");
495+ tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "uint64");
496+ tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "uint64");
497+ tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "uint64");
498+ tdesc_create_reg (feature, "r16", 16, 1, NULL, 64, "uint64");
499+ tdesc_create_reg (feature, "r17", 17, 1, NULL, 64, "uint64");
500+ tdesc_create_reg (feature, "r18", 18, 1, NULL, 64, "uint64");
501+ tdesc_create_reg (feature, "r19", 19, 1, NULL, 64, "uint64");
502+ tdesc_create_reg (feature, "r20", 20, 1, NULL, 64, "uint64");
503+ tdesc_create_reg (feature, "r21", 21, 1, NULL, 64, "uint64");
504+ tdesc_create_reg (feature, "r22", 22, 1, NULL, 64, "uint64");
505+ tdesc_create_reg (feature, "r23", 23, 1, NULL, 64, "uint64");
506+ tdesc_create_reg (feature, "r24", 24, 1, NULL, 64, "uint64");
507+ tdesc_create_reg (feature, "r25", 25, 1, NULL, 64, "uint64");
508+ tdesc_create_reg (feature, "r26", 26, 1, NULL, 64, "uint64");
509+ tdesc_create_reg (feature, "r27", 27, 1, NULL, 64, "uint64");
510+ tdesc_create_reg (feature, "r28", 28, 1, NULL, 64, "uint64");
511+ tdesc_create_reg (feature, "r29", 29, 1, NULL, 64, "uint64");
512+ tdesc_create_reg (feature, "r30", 30, 1, NULL, 64, "uint64");
513+ tdesc_create_reg (feature, "r31", 31, 1, NULL, 64, "uint64");
514+ tdesc_create_reg (feature, "rpc", 32, 1, NULL, 64, "uint64");
515+ tdesc_create_reg (feature, "rmsr", 33, 1, NULL, 32, "int");
516+ tdesc_create_reg (feature, "rear", 34, 1, NULL, 64, "int");
517+ tdesc_create_reg (feature, "resr", 35, 1, NULL, 32, "int");
518+ tdesc_create_reg (feature, "rfsr", 36, 1, NULL, 32, "int");
519+ tdesc_create_reg (feature, "rbtr", 37, 1, NULL, 64, "uint64");
520+ tdesc_create_reg (feature, "rpvr0", 38, 1, NULL, 32, "int");
521+ tdesc_create_reg (feature, "rpvr1", 39, 1, NULL, 32, "int");
522+ tdesc_create_reg (feature, "rpvr2", 40, 1, NULL, 32, "int");
523+ tdesc_create_reg (feature, "rpvr3", 41, 1, NULL, 32, "int");
524+ tdesc_create_reg (feature, "rpvr4", 42, 1, NULL, 32, "int");
525+ tdesc_create_reg (feature, "rpvr5", 43, 1, NULL, 32, "int");
526+ tdesc_create_reg (feature, "rpvr6", 44, 1, NULL, 32, "int");
527+ tdesc_create_reg (feature, "rpvr7", 45, 1, NULL, 32, "int");
528+ tdesc_create_reg (feature, "rpvr8", 46, 1, NULL, 64, "uint64");
529+ tdesc_create_reg (feature, "rpvr9", 47, 1, NULL, 64, "uint64");
530+ tdesc_create_reg (feature, "rpvr10", 48, 1, NULL, 32, "int");
531+ tdesc_create_reg (feature, "rpvr11", 49, 1, NULL, 32, "int");
532+ tdesc_create_reg (feature, "redr", 50, 1, NULL, 32, "int");
533+ tdesc_create_reg (feature, "rpid", 51, 1, NULL, 32, "int");
534+ tdesc_create_reg (feature, "rzpr", 52, 1, NULL, 32, "int");
535+ tdesc_create_reg (feature, "rtlbx", 53, 1, NULL, 32, "int");
536+ tdesc_create_reg (feature, "rtlbsx", 54, 1, NULL, 32, "int");
537+ tdesc_create_reg (feature, "rtlblo", 55, 1, NULL, 32, "int");
538+ tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
539+
540+ feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze64.stack-protect");
541+ tdesc_create_reg (feature, "slr", 57, 1, NULL, 64, "uint64");
542+ tdesc_create_reg (feature, "shr", 58, 1, NULL, 64, "uint64");
543+
544+ tdesc_microblaze64_with_stack_protect = result;
545+}
546diff --git a/gdb/features/microblaze64-with-stack-protect.xml b/gdb/features/microblaze64-with-stack-protect.xml
547new file mode 100644
548index 0000000000..0e9f01611f
549--- /dev/null
550+++ b/gdb/features/microblaze64-with-stack-protect.xml
551@@ -0,0 +1,12 @@
552+<?xml version="1.0"?>
553+<!-- Copyright (C) 2014-2018 Free Software Foundation, Inc.
554+
555+ Copying and distribution of this file, with or without modification,
556+ are permitted in any medium without royalty provided the copyright
557+ notice and this notice are preserved. -->
558+
559+<!DOCTYPE target SYSTEM "gdb-target.dtd">
560+<target>
561+ <xi:include href="microblaze64-core.xml"/>
562+ <xi:include href="microblaze64-stack-protect.xml"/>
563+</target>
564diff --git a/gdb/features/microblaze64.c b/gdb/features/microblaze64.c
565new file mode 100644
566index 0000000000..1aa37c4512
567--- /dev/null
568+++ b/gdb/features/microblaze64.c
569@@ -0,0 +1,77 @@
570+/* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro:
571+ Original: microblaze.xml */
572+
573+#include "defs.h"
574+#include "osabi.h"
575+#include "target-descriptions.h"
576+
577+struct target_desc *tdesc_microblaze64;
578+static void
579+initialize_tdesc_microblaze64 (void)
580+{
581+ struct target_desc *result = allocate_target_description ();
582+ struct tdesc_feature *feature;
583+
584+ feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze64.core");
585+ tdesc_create_reg (feature, "r0", 0, 1, NULL, 64, "uint64");
586+ tdesc_create_reg (feature, "r1", 1, 1, NULL, 64, "uint64");
587+ tdesc_create_reg (feature, "r2", 2, 1, NULL, 64, "uint64");
588+ tdesc_create_reg (feature, "r3", 3, 1, NULL, 64, "uint64");
589+ tdesc_create_reg (feature, "r4", 4, 1, NULL, 64, "uint64");
590+ tdesc_create_reg (feature, "r5", 5, 1, NULL, 64, "uint64");
591+ tdesc_create_reg (feature, "r6", 6, 1, NULL, 64, "uint64");
592+ tdesc_create_reg (feature, "r7", 7, 1, NULL, 64, "uint64");
593+ tdesc_create_reg (feature, "r8", 8, 1, NULL, 64, "uint64");
594+ tdesc_create_reg (feature, "r9", 9, 1, NULL, 64, "uint64");
595+ tdesc_create_reg (feature, "r10", 10, 1, NULL, 64, "uint64");
596+ tdesc_create_reg (feature, "r11", 11, 1, NULL, 64, "uint64");
597+ tdesc_create_reg (feature, "r12", 12, 1, NULL, 64, "uint64");
598+ tdesc_create_reg (feature, "r13", 13, 1, NULL, 64, "uint64");
599+ tdesc_create_reg (feature, "r14", 14, 1, NULL, 64, "uint64");
600+ tdesc_create_reg (feature, "r15", 15, 1, NULL, 64, "uint64");
601+ tdesc_create_reg (feature, "r16", 16, 1, NULL, 64, "uint64");
602+ tdesc_create_reg (feature, "r17", 17, 1, NULL, 64, "uint64");
603+ tdesc_create_reg (feature, "r18", 18, 1, NULL, 64, "uint64");
604+ tdesc_create_reg (feature, "r19", 19, 1, NULL, 64, "uint64");
605+ tdesc_create_reg (feature, "r20", 20, 1, NULL, 64, "uint64");
606+ tdesc_create_reg (feature, "r21", 21, 1, NULL, 64, "uint64");
607+ tdesc_create_reg (feature, "r22", 22, 1, NULL, 64, "uint64");
608+ tdesc_create_reg (feature, "r23", 23, 1, NULL, 64, "uint64");
609+ tdesc_create_reg (feature, "r24", 24, 1, NULL, 64, "uint64");
610+ tdesc_create_reg (feature, "r25", 25, 1, NULL, 64, "uint64");
611+ tdesc_create_reg (feature, "r26", 26, 1, NULL, 64, "uint64");
612+ tdesc_create_reg (feature, "r27", 27, 1, NULL, 64, "uint64");
613+ tdesc_create_reg (feature, "r28", 28, 1, NULL, 64, "uint64");
614+ tdesc_create_reg (feature, "r29", 29, 1, NULL, 64, "uint64");
615+ tdesc_create_reg (feature, "r30", 30, 1, NULL, 64, "uint64");
616+ tdesc_create_reg (feature, "r31", 31, 1, NULL, 64, "uint64");
617+ tdesc_create_reg (feature, "rpc", 32, 1, NULL, 64, "uint64");
618+ tdesc_create_reg (feature, "rmsr", 33, 1, NULL, 32, "int");
619+ tdesc_create_reg (feature, "rear", 34, 1, NULL, 64, "uint64");
620+ tdesc_create_reg (feature, "resr", 35, 1, NULL, 32, "int");
621+ tdesc_create_reg (feature, "rfsr", 36, 1, NULL, 32, "int");
622+ tdesc_create_reg (feature, "rbtr", 37, 1, NULL, 64, "uint64");
623+ tdesc_create_reg (feature, "rpvr0", 38, 1, NULL, 32, "int");
624+ tdesc_create_reg (feature, "rpvr1", 39, 1, NULL, 32, "int");
625+ tdesc_create_reg (feature, "rpvr2", 40, 1, NULL, 32, "int");
626+ tdesc_create_reg (feature, "rpvr3", 41, 1, NULL, 32, "int");
627+ tdesc_create_reg (feature, "rpvr4", 42, 1, NULL, 32, "int");
628+ tdesc_create_reg (feature, "rpvr5", 43, 1, NULL, 32, "int");
629+ tdesc_create_reg (feature, "rpvr6", 44, 1, NULL, 32, "int");
630+ tdesc_create_reg (feature, "rpvr7", 45, 1, NULL, 32, "int");
631+ tdesc_create_reg (feature, "rpvr8", 46, 1, NULL, 64, "uint64");
632+ tdesc_create_reg (feature, "rpvr9", 47, 1, NULL, 64, "uint64");
633+ tdesc_create_reg (feature, "rpvr10", 48, 1, NULL, 32, "int");
634+ tdesc_create_reg (feature, "rpvr11", 49, 1, NULL, 32, "int");
635+ tdesc_create_reg (feature, "redr", 50, 1, NULL, 32, "int");
636+ tdesc_create_reg (feature, "rpid", 51, 1, NULL, 32, "int");
637+ tdesc_create_reg (feature, "rzpr", 52, 1, NULL, 32, "int");
638+ tdesc_create_reg (feature, "rtlbx", 53, 1, NULL, 32, "int");
639+ tdesc_create_reg (feature, "rtlbsx", 54, 1, NULL, 32, "int");
640+ tdesc_create_reg (feature, "rtlblo", 55, 1, NULL, 32, "int");
641+ tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
642+ tdesc_create_reg (feature, "slr", 57, 1, NULL, 64, "uint64");
643+ tdesc_create_reg (feature, "shr", 58, 1, NULL, 64, "uint64");
644+
645+ tdesc_microblaze64 = result;
646+}
647diff --git a/gdb/features/microblaze64.xml b/gdb/features/microblaze64.xml
648new file mode 100644
649index 0000000000..515d18e65c
650--- /dev/null
651+++ b/gdb/features/microblaze64.xml
652@@ -0,0 +1,11 @@
653+<?xml version="1.0"?>
654+<!-- Copyright (C) 2014-2018 Free Software Foundation, Inc.
655+
656+ Copying and distribution of this file, with or without modification,
657+ are permitted in any medium without royalty provided the copyright
658+ notice and this notice are preserved. -->
659+
660+<!DOCTYPE target SYSTEM "gdb-target.dtd">
661+<target>
662+ <xi:include href="microblaze64-core.xml"/>
663+</target>
664diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
665index 49713ea9b1..0605283c9e 100644
666--- a/gdb/microblaze-tdep.c
667+++ b/gdb/microblaze-tdep.c
668@@ -40,7 +40,9 @@
669 #include "remote.h"
670
671 #include "features/microblaze-with-stack-protect.c"
672+#include "features/microblaze64-with-stack-protect.c"
673 #include "features/microblaze.c"
674+#include "features/microblaze64.c"
675
676 /* Instruction macros used for analyzing the prologue. */
677 /* This set of instruction macros need to be changed whenever the
678@@ -75,12 +77,13 @@ static const char *microblaze_register_names[] =
679 "rpvr0", "rpvr1", "rpvr2", "rpvr3", "rpvr4", "rpvr5", "rpvr6",
680 "rpvr7", "rpvr8", "rpvr9", "rpvr10", "rpvr11",
681 "redr", "rpid", "rzpr", "rtlbx", "rtlbsx", "rtlblo", "rtlbhi",
682- "rslr", "rshr"
683+ "slr", "shr"
684 };
685
686 #define MICROBLAZE_NUM_REGS ARRAY_SIZE (microblaze_register_names)
687
688 static unsigned int microblaze_debug_flag = 0;
689+int reg_size = 4;
690
691 static void ATTRIBUTE_PRINTF (1, 2)
692 microblaze_debug (const char *fmt, ...)
693@@ -145,6 +148,7 @@ microblaze_store_arguments (struct regcache *regcache, int nargs,
694 error (_("store_arguments not implemented"));
695 return sp;
696 }
697+#if 0
698 static int
699 microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
700 struct bp_target_info *bp_tgt)
701@@ -154,7 +158,7 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
702 int val;
703 int bplen;
704 gdb_byte old_contents[BREAKPOINT_MAX];
705- struct cleanup *cleanup;
706+ //struct cleanup *cleanup;
707
708 /* Determine appropriate breakpoint contents and size for this address. */
709 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
710@@ -162,7 +166,8 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
711 error (_("Software breakpoints not implemented for this target."));
712
713 /* Make sure we see the memory breakpoints. */
714- cleanup = make_show_memory_breakpoints_cleanup (1);
715+ scoped_restore
716+ cleanup = make_scoped_restore_show_memory_breakpoints (1);
717 val = target_read_memory (addr, old_contents, bplen);
718
719 /* If our breakpoint is no longer at the address, this means that the
720@@ -178,6 +183,7 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
721 return val;
722 }
723
724+#endif
725 /* Allocate and initialize a frame cache. */
726
727 static struct microblaze_frame_cache *
728@@ -570,17 +576,16 @@ microblaze_extract_return_value (struct type *type, struct regcache *regcache,
729 gdb_byte *valbuf)
730 {
731 gdb_byte buf[8];
732-
733 /* Copy the return value (starting) in RETVAL_REGNUM to VALBUF. */
734 switch (TYPE_LENGTH (type))
735 {
736 case 1: /* return last byte in the register. */
737 regcache->cooked_read (MICROBLAZE_RETVAL_REGNUM, buf);
738- memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 1, 1);
739+ memcpy(valbuf, buf + reg_size - 1, 1);
740 return;
741 case 2: /* return last 2 bytes in register. */
742 regcache->cooked_read (MICROBLAZE_RETVAL_REGNUM, buf);
743- memcpy(valbuf, buf + MICROBLAZE_REGISTER_SIZE - 2, 2);
744+ memcpy(valbuf, buf + reg_size - 2, 2);
745 return;
746 case 4: /* for sizes 4 or 8, copy the required length. */
747 case 8:
748@@ -647,7 +652,119 @@ microblaze_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type)
749 return (TYPE_LENGTH (type) == 16);
750 }
751
752-
753+#if 0
754+static std::vector<CORE_ADDR>
755+microblaze_software_single_step (struct regcache *regcache)
756+{
757+// struct gdbarch *arch = get_frame_arch(frame);
758+ struct gdbarch *arch = get_regcache_arch (regcache);
759+ struct address_space *aspace = get_regcache_aspace (regcache);
760+// struct address_space *aspace = get_frame_address_space (frame);
761+ struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
762+ static char le_breakp[] = MICROBLAZE_BREAKPOINT_LE;
763+ static char be_breakp[] = MICROBLAZE_BREAKPOINT;
764+ enum bfd_endian byte_order = gdbarch_byte_order (arch);
765+ char *breakp = byte_order == BFD_ENDIAN_BIG ? be_breakp : le_breakp;
766+ std::vector<CORE_ADDR> ret = 0;
767+
768+ /* Save the address and the values of the next_pc and the target */
769+ static struct sstep_breaks
770+ {
771+ CORE_ADDR address;
772+ bfd_boolean valid;
773+ /* Shadow contents. */
774+ char data[INST_WORD_SIZE];
775+ } stepbreaks[2];
776+ int ii;
777+
778+ if (1)
779+ {
780+ CORE_ADDR pc;
781+ std::vector<CORE_ADDR> *next_pcs = NULL;
782+ long insn;
783+ enum microblaze_instr minstr;
784+ bfd_boolean isunsignednum;
785+ enum microblaze_instr_type insn_type;
786+ short delay_slots;
787+ int imm;
788+ bfd_boolean immfound = FALSE;
789+
790+ /* Set a breakpoint at the next instruction */
791+ /* If the current instruction is an imm, set it at the inst after */
792+ /* If the instruction has a delay slot, skip the delay slot */
793+ pc = regcache_read_pc (regcache);
794+ insn = microblaze_fetch_instruction (pc);
795+ minstr = get_insn_microblaze (insn, &isunsignednum, &insn_type, &delay_slots);
796+ if (insn_type == immediate_inst)
797+ {
798+ int rd, ra, rb;
799+ immfound = TRUE;
800+ minstr = microblaze_decode_insn (insn, &rd, &ra, &rb, &imm);
801+ pc = pc + INST_WORD_SIZE;
802+ insn = microblaze_fetch_instruction (pc);
803+ minstr = get_insn_microblaze (insn, &isunsignednum, &insn_type, &delay_slots);
804+ }
805+ stepbreaks[0].address = pc + (delay_slots * INST_WORD_SIZE) + INST_WORD_SIZE;
806+ if (insn_type != return_inst) {
807+ stepbreaks[0].valid = TRUE;
808+ } else {
809+ stepbreaks[0].valid = FALSE;
810+ }
811+
812+ microblaze_debug ("single-step insn_type=%x insn=%x\n", insn_type, insn);
813+ /* Now check for branch or return instructions */
814+ if (insn_type == branch_inst || insn_type == return_inst) {
815+ int limm;
816+ int lrd, lra, lrb;
817+ int ra, rb;
818+ bfd_boolean targetvalid;
819+ bfd_boolean unconditionalbranch;
820+ microblaze_decode_insn(insn, &lrd, &lra, &lrb, &limm);
821+ if (lra >= 0 && lra < MICROBLAZE_NUM_REGS)
822+ ra = regcache_raw_get_unsigned(regcache, lra);
823+ else
824+ ra = 0;
825+ if (lrb >= 0 && lrb < MICROBLAZE_NUM_REGS)
826+ rb = regcache_raw_get_unsigned(regcache, lrb);
827+ else
828+ rb = 0;
829+ stepbreaks[1].address = microblaze_get_target_address (insn, immfound, imm, pc, ra, rb, &targetvalid, &unconditionalbranch);
830+ microblaze_debug ("single-step uncondbr=%d targetvalid=%d target=%x\n", unconditionalbranch, targetvalid, stepbreaks[1].address);
831+ if (unconditionalbranch)
832+ stepbreaks[0].valid = FALSE; /* This is a unconditional branch: will not come to the next address */
833+ if (targetvalid && (stepbreaks[0].valid == FALSE ||
834+ (stepbreaks[0].address != stepbreaks[1].address))
835+ && (stepbreaks[1].address != pc)) {
836+ stepbreaks[1].valid = TRUE;
837+ } else {
838+ stepbreaks[1].valid = FALSE;
839+ }
840+ } else {
841+ stepbreaks[1].valid = FALSE;
842+ }
843+
844+ /* Insert the breakpoints */
845+ for (ii = 0; ii < 2; ++ii)
846+ {
847+
848+ /* ignore invalid breakpoint. */
849+ if (stepbreaks[ii].valid) {
850+ VEC_safe_push (CORE_ADDR, next_pcs, stepbreaks[ii].address);;
851+// insert_single_step_breakpoint (arch, aspace, stepbreaks[ii].address);
852+ ret = next_pcs;
853+ }
854+ }
855+ }
856+ return ret;
857+}
858+#endif
859+
860+static void
861+microblaze_write_pc (struct regcache *regcache, CORE_ADDR pc)
862+{
863+ regcache_cooked_write_unsigned (regcache, MICROBLAZE_PC_REGNUM, pc);
864+}
865+
866 static int dwarf2_to_reg_map[78] =
867 { 0 /* r0 */, 1 /* r1 */, 2 /* r2 */, 3 /* r3 */, /* 0- 3 */
868 4 /* r4 */, 5 /* r5 */, 6 /* r6 */, 7 /* r7 */, /* 4- 7 */
869@@ -682,13 +799,14 @@ microblaze_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg)
870 static void
871 microblaze_register_g_packet_guesses (struct gdbarch *gdbarch)
872 {
873+
874 register_remote_g_packet_guess (gdbarch,
875- 4 * MICROBLAZE_NUM_CORE_REGS,
876- tdesc_microblaze);
877+ 4 * MICROBLAZE_NUM_REGS,
878+ tdesc_microblaze64);
879
880 register_remote_g_packet_guess (gdbarch,
881 4 * MICROBLAZE_NUM_REGS,
882- tdesc_microblaze_with_stack_protect);
883+ tdesc_microblaze64_with_stack_protect);
884 }
885
886 void
887@@ -696,15 +814,15 @@ microblaze_supply_gregset (const struct microblaze_gregset *gregset,
888 struct regcache *regcache,
889 int regnum, const void *gregs)
890 {
891- unsigned int *regs = gregs;
892+ const gdb_byte *regs = (const gdb_byte *) gregs;
893 if (regnum >= 0)
894- regcache_raw_supply (regcache, regnum, regs + regnum);
895+ regcache->raw_supply (regnum, regs + regnum);
896
897 if (regnum == -1) {
898 int i;
899
900 for (i = 0; i < 50; i++) {
901- regcache_raw_supply (regcache, i, regs + i);
902+ regcache->raw_supply (regnum, regs + i);
903 }
904 }
905 }
906@@ -755,6 +873,17 @@ microblaze_regset_from_core_section (struct gdbarch *gdbarch,
907 }
908
909
910+static void
911+make_regs (struct gdbarch *arch)
912+{
913+ struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
914+ int mach = gdbarch_bfd_arch_info (arch)->mach;
915+
916+ if (mach == bfd_mach_microblaze64)
917+ {
918+ set_gdbarch_ptr_bit (arch, 64);
919+ }
920+}
921
922 static struct gdbarch *
923 microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
924@@ -769,8 +898,15 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
925 if (arches != NULL)
926 return arches->gdbarch;
927 if (tdesc == NULL)
928- tdesc = tdesc_microblaze;
929-
930+ {
931+ if (info.bfd_arch_info->mach == bfd_mach_microblaze64)
932+ {
933+ tdesc = tdesc_microblaze64;
934+ reg_size = 8;
935+ }
936+ else
937+ tdesc = tdesc_microblaze;
938+ }
939 /* Check any target description for validity. */
940 if (tdesc_has_registers (tdesc))
941 {
942@@ -778,27 +914,35 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
943 int valid_p;
944 int i;
945
946- feature = tdesc_find_feature (tdesc,
947+ if (info.bfd_arch_info->mach == bfd_mach_microblaze64)
948+ feature = tdesc_find_feature (tdesc,
949+ "org.gnu.gdb.microblaze64.core");
950+ else
951+ feature = tdesc_find_feature (tdesc,
952 "org.gnu.gdb.microblaze.core");
953 if (feature == NULL)
954 return NULL;
955 tdesc_data = tdesc_data_alloc ();
956
957 valid_p = 1;
958- for (i = 0; i < MICROBLAZE_NUM_CORE_REGS; i++)
959+ for (i = 0; i < MICROBLAZE_NUM_REGS; i++)
960 valid_p &= tdesc_numbered_register (feature, tdesc_data, i,
961 microblaze_register_names[i]);
962- feature = tdesc_find_feature (tdesc,
963+ if (info.bfd_arch_info->mach == bfd_mach_microblaze64)
964+ feature = tdesc_find_feature (tdesc,
965+ "org.gnu.gdb.microblaze64.stack-protect");
966+ else
967+ feature = tdesc_find_feature (tdesc,
968 "org.gnu.gdb.microblaze.stack-protect");
969 if (feature != NULL)
970 {
971 valid_p = 1;
972 valid_p &= tdesc_numbered_register (feature, tdesc_data,
973 MICROBLAZE_SLR_REGNUM,
974- "rslr");
975+ "slr");
976 valid_p &= tdesc_numbered_register (feature, tdesc_data,
977 MICROBLAZE_SHR_REGNUM,
978- "rshr");
979+ "shr");
980 }
981
982 if (!valid_p)
983@@ -806,6 +950,7 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
984 tdesc_data_cleanup (tdesc_data);
985 return NULL;
986 }
987+
988 }
989
990 /* Allocate space for the new architecture. */
991@@ -825,7 +970,17 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
992 /* Register numbers of various important registers. */
993 set_gdbarch_sp_regnum (gdbarch, MICROBLAZE_SP_REGNUM);
994 set_gdbarch_pc_regnum (gdbarch, MICROBLAZE_PC_REGNUM);
995+
996+ /* Register set.
997+ make_regs (gdbarch); */
998+ switch (info.bfd_arch_info->mach)
999+ {
1000+ case bfd_mach_microblaze64:
1001+ set_gdbarch_ptr_bit (gdbarch, 64);
1002+ break;
1003+ }
1004
1005+
1006 /* Map Dwarf2 registers to GDB registers. */
1007 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, microblaze_dwarf2_reg_to_regnum);
1008
1009@@ -845,13 +1000,15 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1010 microblaze_breakpoint::kind_from_pc);
1011 set_gdbarch_sw_breakpoint_from_kind (gdbarch,
1012 microblaze_breakpoint::bp_from_kind);
1013- set_gdbarch_memory_remove_breakpoint (gdbarch, microblaze_linux_memory_remove_breakpoint);
1014+// set_gdbarch_memory_remove_breakpoint (gdbarch, microblaze_linux_memory_remove_breakpoint);
1015+
1016+// set_gdbarch_software_single_step (gdbarch, microblaze_software_single_step);
1017
1018 set_gdbarch_frame_args_skip (gdbarch, 8);
1019
1020 set_gdbarch_unwind_pc (gdbarch, microblaze_unwind_pc);
1021
1022- microblaze_register_g_packet_guesses (gdbarch);
1023+ //microblaze_register_g_packet_guesses (gdbarch);
1024
1025 frame_base_set_default (gdbarch, &microblaze_frame_base);
1026
1027@@ -866,11 +1023,11 @@ microblaze_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1028 tdesc_use_registers (gdbarch, tdesc, tdesc_data);
1029 //frame_base_append_sniffer (gdbarch, microblaze_frame_sniffer);
1030
1031- /* If we have register sets, enable the generic core file support. */
1032+ /* If we have register sets, enable the generic core file support.
1033 if (tdep->gregset) {
1034 set_gdbarch_regset_from_core_section (gdbarch,
1035 microblaze_regset_from_core_section);
1036- }
1037+ }*/
1038
1039 return gdbarch;
1040 }
1041@@ -882,6 +1039,8 @@ _initialize_microblaze_tdep (void)
1042
1043 initialize_tdesc_microblaze_with_stack_protect ();
1044 initialize_tdesc_microblaze ();
1045+ initialize_tdesc_microblaze64_with_stack_protect ();
1046+ initialize_tdesc_microblaze64 ();
1047 /* Debug this files internals. */
1048 add_setshow_zuinteger_cmd ("microblaze", class_maintenance,
1049 &microblaze_debug_flag, _("\
1050diff --git a/gdb/microblaze-tdep.h b/gdb/microblaze-tdep.h
1051index 3777cbb6a8..55f5dd1962 100644
1052--- a/gdb/microblaze-tdep.h
1053+++ b/gdb/microblaze-tdep.h
1054@@ -27,7 +27,7 @@ struct microblaze_gregset
1055 microblaze_gregset() {}
1056 unsigned int gregs[32];
1057 unsigned int fpregs[32];
1058- unsigned int pregs[16];
1059+ unsigned int pregs[18];
1060 };
1061
1062 struct gdbarch_tdep
1063@@ -101,9 +101,9 @@ enum microblaze_regnum
1064 MICROBLAZE_RTLBSX_REGNUM,
1065 MICROBLAZE_RTLBLO_REGNUM,
1066 MICROBLAZE_RTLBHI_REGNUM,
1067- MICROBLAZE_SLR_REGNUM, MICROBLAZE_NUM_CORE_REGS = MICROBLAZE_SLR_REGNUM,
1068+ MICROBLAZE_SLR_REGNUM,
1069 MICROBLAZE_SHR_REGNUM,
1070- MICROBLAZE_NUM_REGS
1071+ MICROBLAZE_NUM_REGS, MICROBLAZE_NUM_CORE_REGS = MICROBLAZE_NUM_REGS
1072 };
1073
1074 struct microblaze_frame_cache
1075@@ -128,7 +128,7 @@ struct microblaze_frame_cache
1076 struct trad_frame_saved_reg *saved_regs;
1077 };
1078 /* All registers are 32 bits. */
1079-#define MICROBLAZE_REGISTER_SIZE 4
1080+//#define MICROBLAZE_REGISTER_SIZE 8
1081
1082 /* MICROBLAZE_BREAKPOINT defines the breakpoint that should be used.
1083 Only used for native debugging. */
1084diff --git a/gdb/regformats/microblaze-with-stack-protect.dat b/gdb/regformats/microblaze-with-stack-protect.dat
1085index 8040a7b3fd..450e321d49 100644
1086--- a/gdb/regformats/microblaze-with-stack-protect.dat
1087+++ b/gdb/regformats/microblaze-with-stack-protect.dat
1088@@ -60,5 +60,5 @@ expedite:r1,rpc
1089 32:rtlbsx
1090 32:rtlblo
1091 32:rtlbhi
1092-32:rslr
1093-32:rshr
1094+32:slr
1095+32:shr
1096diff --git a/opcodes/microblaze-opc.h b/opcodes/microblaze-opc.h
1097index bd9d91cd57..12d4456bc2 100644
1098--- a/opcodes/microblaze-opc.h
1099+++ b/opcodes/microblaze-opc.h
1100@@ -134,7 +134,6 @@
1101 #define ORLI_MASK 0xA0000000
1102 #define XORLI_MASK 0xA8000000
1103
1104-
1105 /* New Mask for msrset, msrclr insns. */
1106 #define OPCODE_MASK_H23N 0xFC1F8000 /* High 6 and bits 11 - 16. */
1107 /* Mask for mbar insn. */
1108--
11092.17.1
1110
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0041-patch-MicroBlaze-porting-GDB-for-linux.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0041-patch-MicroBlaze-porting-GDB-for-linux.patch
new file mode 100644
index 00000000..7d63e63e
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0041-patch-MicroBlaze-porting-GDB-for-linux.patch
@@ -0,0 +1,155 @@
1From 3f830717572e074a21840549b48265ec00d67bd1 Mon Sep 17 00:00:00 2001
2From: Mahesh Bodapati <mbodapat@xilinx.com>
3Date: Thu, 12 Dec 2019 14:56:17 +0530
4Subject: [PATCH 41/43] [patch,MicroBlaze] : porting GDB for linux
5
6---
7 gdb/features/microblaze-linux.xml | 12 ++++++++++
8 gdb/gdbserver/Makefile.in | 2 ++
9 gdb/gdbserver/configure.srv | 3 ++-
10 gdb/microblaze-linux-tdep.c | 39 ++++++++++++++++++++++++-------
11 4 files changed, 47 insertions(+), 9 deletions(-)
12 create mode 100644 gdb/features/microblaze-linux.xml
13
14diff --git a/gdb/features/microblaze-linux.xml b/gdb/features/microblaze-linux.xml
15new file mode 100644
16index 0000000000..8983e66eb3
17--- /dev/null
18+++ b/gdb/features/microblaze-linux.xml
19@@ -0,0 +1,12 @@
20+<?xml version="1.0"?>
21+<!-- Copyright (C) 2014-2018 Free Software Foundation, Inc.
22+
23+ Copying and distribution of this file, with or without modification,
24+ are permitted in any medium without royalty provided the copyright
25+ notice and this notice are preserved. -->
26+
27+<!DOCTYPE target SYSTEM "gdb-target.dtd">
28+<target>
29+ <osabi>GNU/Linux</osabi>
30+ <xi:include href="microblaze-core.xml"/>
31+</target>
32diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
33index 73ca5fd7c5..f5d8663ec8 100644
34--- a/gdb/gdbserver/Makefile.in
35+++ b/gdb/gdbserver/Makefile.in
36@@ -639,6 +639,8 @@ common/%.o: ../common/%.c
37
38 %-generated.c: ../regformats/rs6000/%.dat | $(regdat_sh)
39 $(ECHO_REGDAT) $(SHELL) $(regdat_sh) $< $@
40+microblaze-linux.c : $(srcdir)/../regformats/reg-microblaze.dat $(regdat_sh)
41+ $(ECHO_REGDAT) $(SHELL) $(regdat_sh) $(srcdir)/../regformats/reg-microblaze.dat microblaze-linux.c
42
43 #
44 # Dependency tracking.
45diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
46index 201b7ae190..e5ed6498a8 100644
47--- a/gdb/gdbserver/configure.srv
48+++ b/gdb/gdbserver/configure.srv
49@@ -210,8 +210,9 @@ case "${target}" in
50 srv_linux_usrregs=yes
51 srv_linux_thread_db=yes
52 ;;
53- microblaze*-*-linux*) srv_regobj=microblaze-linux.o
54+ microblaze*-*-linux*) srv_regobj="microblaze-linux.o"
55 srv_tgtobj="$srv_linux_obj linux-microblaze-low.o "
56+ srv_xmlfiles="microblaze-linux.xml"
57 srv_linux_regsets=yes
58 srv_linux_usrregs=yes
59 srv_linux_thread_db=yes
60diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
61index 011e513941..e3d2a7508d 100644
62--- a/gdb/microblaze-linux-tdep.c
63+++ b/gdb/microblaze-linux-tdep.c
64@@ -41,7 +41,7 @@
65
66 #ifndef REGSET_H
67 #define REGSET_H 1
68-
69+int MICROBLAZE_REGISTER_SIZE=4;
70 struct gdbarch;
71 struct regcache;
72
73@@ -115,7 +115,7 @@ microblaze_debug (const char *fmt, ...)
74 va_end (args);
75 }
76 }
77-
78+#if 0
79 static int
80 microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
81 struct bp_target_info *bp_tgt)
82@@ -131,7 +131,7 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
83 bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
84
85 /* Make sure we see the memory breakpoints. */
86- cleanup = make_show_memory_breakpoints_cleanup (1);
87+ cleanup = make_scoped_restore_show_memory_breakpoints (1);
88 val = target_read_memory (addr, old_contents, bplen);
89
90 /* If our breakpoint is no longer at the address, this means that the
91@@ -146,6 +146,7 @@ microblaze_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
92 do_cleanups (cleanup);
93 return val;
94 }
95+#endif
96
97 static void
98 microblaze_linux_sigtramp_cache (struct frame_info *next_frame,
99@@ -248,8 +249,8 @@ microblaze_linux_init_abi (struct gdbarch_info info,
100
101 linux_init_abi (info, gdbarch);
102
103- set_gdbarch_memory_remove_breakpoint (gdbarch,
104- microblaze_linux_memory_remove_breakpoint);
105+// set_gdbarch_memory_remove_breakpoint (gdbarch,
106+// microblaze_linux_memory_remove_breakpoint);
107
108 /* Shared library handling. */
109 set_solib_svr4_fetch_link_map_offsets (gdbarch,
110@@ -261,10 +262,30 @@ microblaze_linux_init_abi (struct gdbarch_info info,
111
112 /* BFD target for core files. */
113 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
114- set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblaze");
115+ {
116+ if (info.bfd_arch_info->mach == bfd_mach_microblaze64) {
117+ set_gdbarch_gcore_bfd_target (gdbarch, "elf64-microblaze");
118+ MICROBLAZE_REGISTER_SIZE=8;
119+ }
120+ else
121+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblaze");
122+ }
123 else
124- set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblazeel");
125+ {
126+ if (info.bfd_arch_info->mach == bfd_mach_microblaze64) {
127+ set_gdbarch_gcore_bfd_target (gdbarch, "elf64-microblazeel");
128+ MICROBLAZE_REGISTER_SIZE=8;
129+ }
130+ else
131+ set_gdbarch_gcore_bfd_target (gdbarch, "elf32-microblazeel");
132+ }
133
134+ switch (info.bfd_arch_info->mach)
135+ {
136+ case bfd_mach_microblaze64:
137+ set_gdbarch_ptr_bit (gdbarch, 64);
138+ break;
139+ }
140
141 /* Shared library handling. */
142 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
143@@ -278,6 +299,8 @@ microblaze_linux_init_abi (struct gdbarch_info info,
144 void
145 _initialize_microblaze_linux_tdep (void)
146 {
147- gdbarch_register_osabi (bfd_arch_microblaze, 0, GDB_OSABI_LINUX,
148+ gdbarch_register_osabi (bfd_arch_microblaze, bfd_mach_microblaze, GDB_OSABI_LINUX,
149+ microblaze_linux_init_abi);
150+ gdbarch_register_osabi (bfd_arch_microblaze, bfd_mach_microblaze64, GDB_OSABI_LINUX,
151 microblaze_linux_init_abi);
152 }
153--
1542.17.1
155
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0042-Correcting-the-register-names-from-slr-shr-to-rslr-r.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0042-Correcting-the-register-names-from-slr-shr-to-rslr-r.patch
new file mode 100644
index 00000000..06e63f3c
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0042-Correcting-the-register-names-from-slr-shr-to-rslr-r.patch
@@ -0,0 +1,146 @@
1From 746453e0f35fd669cfacabfe223b8e7007a99797 Mon Sep 17 00:00:00 2001
2From: Nagaraju <nmekala@xilinx.com>
3Date: Thu, 19 Dec 2019 12:22:04 +0530
4Subject: [PATCH 42/43] Correcting the register names from slr & shr to rslr &
5 rshr
6
7---
8 gdb/features/microblaze-core.xml | 4 ++--
9 gdb/features/microblaze-stack-protect.xml | 4 ++--
10 gdb/features/microblaze-with-stack-protect.c | 4 ++--
11 gdb/features/microblaze.c | 4 ++--
12 gdb/features/microblaze64-core.xml | 4 ++--
13 gdb/features/microblaze64-stack-protect.xml | 4 ++--
14 gdb/features/microblaze64-with-stack-protect.c | 4 ++--
15 gdb/features/microblaze64.c | 4 ++--
16 gdb/microblaze-tdep.c | 2 +-
17 9 files changed, 17 insertions(+), 17 deletions(-)
18
19diff --git a/gdb/features/microblaze-core.xml b/gdb/features/microblaze-core.xml
20index 5bc3e49f84..6f73f4eb84 100644
21--- a/gdb/features/microblaze-core.xml
22+++ b/gdb/features/microblaze-core.xml
23@@ -64,6 +64,6 @@
24 <reg name="rtlbsx" bitsize="32"/>
25 <reg name="rtlblo" bitsize="32"/>
26 <reg name="rtlbhi" bitsize="32"/>
27- <reg name="slr" bitsize="32"/>
28- <reg name="shr" bitsize="32"/>
29+ <reg name="rslr" bitsize="32"/>
30+ <reg name="rshr" bitsize="32"/>
31 </feature>
32diff --git a/gdb/features/microblaze-stack-protect.xml b/gdb/features/microblaze-stack-protect.xml
33index a7f27b903c..870c148bb0 100644
34--- a/gdb/features/microblaze-stack-protect.xml
35+++ b/gdb/features/microblaze-stack-protect.xml
36@@ -7,6 +7,6 @@
37
38 <!DOCTYPE feature SYSTEM "gdb-target.dtd">
39 <feature name="org.gnu.gdb.microblaze.stack-protect">
40- <reg name="slr" bitsize="32"/>
41- <reg name="shr" bitsize="32"/>
42+ <reg name="rslr" bitsize="32"/>
43+ <reg name="rshr" bitsize="32"/>
44 </feature>
45diff --git a/gdb/features/microblaze-with-stack-protect.c b/gdb/features/microblaze-with-stack-protect.c
46index 609934e2b4..ab162fd258 100644
47--- a/gdb/features/microblaze-with-stack-protect.c
48+++ b/gdb/features/microblaze-with-stack-protect.c
49@@ -72,8 +72,8 @@ initialize_tdesc_microblaze_with_stack_protect (void)
50 tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
51
52 feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze.stack-protect");
53- tdesc_create_reg (feature, "slr", 57, 1, NULL, 32, "int");
54- tdesc_create_reg (feature, "shr", 58, 1, NULL, 32, "int");
55+ tdesc_create_reg (feature, "rslr", 57, 1, NULL, 32, "int");
56+ tdesc_create_reg (feature, "rshr", 58, 1, NULL, 32, "int");
57
58 tdesc_microblaze_with_stack_protect = result;
59 }
60diff --git a/gdb/features/microblaze.c b/gdb/features/microblaze.c
61index ceb98ca8b8..7919ac96e6 100644
62--- a/gdb/features/microblaze.c
63+++ b/gdb/features/microblaze.c
64@@ -70,8 +70,8 @@ initialize_tdesc_microblaze (void)
65 tdesc_create_reg (feature, "rtlbsx", 54, 1, NULL, 32, "int");
66 tdesc_create_reg (feature, "rtlblo", 55, 1, NULL, 32, "int");
67 tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
68- tdesc_create_reg (feature, "slr", 57, 1, NULL, 64, "uint64");
69- tdesc_create_reg (feature, "shr", 58, 1, NULL, 64, "uint64");
70+ tdesc_create_reg (feature, "rslr", 57, 1, NULL, 64, "uint64");
71+ tdesc_create_reg (feature, "rshr", 58, 1, NULL, 64, "uint64");
72
73 tdesc_microblaze = result;
74 }
75diff --git a/gdb/features/microblaze64-core.xml b/gdb/features/microblaze64-core.xml
76index 96e99e2fb2..b9adadfade 100644
77--- a/gdb/features/microblaze64-core.xml
78+++ b/gdb/features/microblaze64-core.xml
79@@ -64,6 +64,6 @@
80 <reg name="rtlbsx" bitsize="32"/>
81 <reg name="rtlblo" bitsize="32"/>
82 <reg name="rtlbhi" bitsize="32"/>
83- <reg name="slr" bitsize="64"/>
84- <reg name="shr" bitsize="64"/>
85+ <reg name="rslr" bitsize="64"/>
86+ <reg name="rshr" bitsize="64"/>
87 </feature>
88diff --git a/gdb/features/microblaze64-stack-protect.xml b/gdb/features/microblaze64-stack-protect.xml
89index 1bbf5fc3ce..9d7ea8b9fd 100644
90--- a/gdb/features/microblaze64-stack-protect.xml
91+++ b/gdb/features/microblaze64-stack-protect.xml
92@@ -7,6 +7,6 @@
93
94 <!DOCTYPE feature SYSTEM "gdb-target.dtd">
95 <feature name="org.gnu.gdb.microblaze64.stack-protect">
96- <reg name="slr" bitsize="64"/>
97- <reg name="shr" bitsize="64"/>
98+ <reg name="rslr" bitsize="64"/>
99+ <reg name="rshr" bitsize="64"/>
100 </feature>
101diff --git a/gdb/features/microblaze64-with-stack-protect.c b/gdb/features/microblaze64-with-stack-protect.c
102index f448c9a749..249cb534da 100644
103--- a/gdb/features/microblaze64-with-stack-protect.c
104+++ b/gdb/features/microblaze64-with-stack-protect.c
105@@ -72,8 +72,8 @@ initialize_tdesc_microblaze64_with_stack_protect (void)
106 tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
107
108 feature = tdesc_create_feature (result, "org.gnu.gdb.microblaze64.stack-protect");
109- tdesc_create_reg (feature, "slr", 57, 1, NULL, 64, "uint64");
110- tdesc_create_reg (feature, "shr", 58, 1, NULL, 64, "uint64");
111+ tdesc_create_reg (feature, "rslr", 57, 1, NULL, 64, "uint64");
112+ tdesc_create_reg (feature, "rshr", 58, 1, NULL, 64, "uint64");
113
114 tdesc_microblaze64_with_stack_protect = result;
115 }
116diff --git a/gdb/features/microblaze64.c b/gdb/features/microblaze64.c
117index 1aa37c4512..5d3e2c8cd9 100644
118--- a/gdb/features/microblaze64.c
119+++ b/gdb/features/microblaze64.c
120@@ -70,8 +70,8 @@ initialize_tdesc_microblaze64 (void)
121 tdesc_create_reg (feature, "rtlbsx", 54, 1, NULL, 32, "int");
122 tdesc_create_reg (feature, "rtlblo", 55, 1, NULL, 32, "int");
123 tdesc_create_reg (feature, "rtlbhi", 56, 1, NULL, 32, "int");
124- tdesc_create_reg (feature, "slr", 57, 1, NULL, 64, "uint64");
125- tdesc_create_reg (feature, "shr", 58, 1, NULL, 64, "uint64");
126+ tdesc_create_reg (feature, "rslr", 57, 1, NULL, 64, "uint64");
127+ tdesc_create_reg (feature, "rshr", 58, 1, NULL, 64, "uint64");
128
129 tdesc_microblaze64 = result;
130 }
131diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
132index 0605283c9e..7a0c2527f4 100644
133--- a/gdb/microblaze-tdep.c
134+++ b/gdb/microblaze-tdep.c
135@@ -77,7 +77,7 @@ static const char *microblaze_register_names[] =
136 "rpvr0", "rpvr1", "rpvr2", "rpvr3", "rpvr4", "rpvr5", "rpvr6",
137 "rpvr7", "rpvr8", "rpvr9", "rpvr10", "rpvr11",
138 "redr", "rpid", "rzpr", "rtlbx", "rtlbsx", "rtlblo", "rtlbhi",
139- "slr", "shr"
140+ "rslr", "rshr"
141 };
142
143 #define MICROBLAZE_NUM_REGS ARRAY_SIZE (microblaze_register_names)
144--
1452.17.1
146
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0043-Removing-the-header-gdb_assert.h-from-MB-target-file.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0043-Removing-the-header-gdb_assert.h-from-MB-target-file.patch
new file mode 100644
index 00000000..0b6cae62
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0043-Removing-the-header-gdb_assert.h-from-MB-target-file.patch
@@ -0,0 +1,24 @@
1From 8cb6a265c2108ff7117c07e106604b46238c6ae7 Mon Sep 17 00:00:00 2001
2From: Nagaraju <nmekala@xilinx.com>
3Date: Fri, 17 Jan 2020 15:45:48 +0530
4Subject: [PATCH 43/43] Removing the header "gdb_assert.h" from MB target file
5
6---
7 gdb/microblaze-linux-tdep.c | 1 -
8 1 file changed, 1 deletion(-)
9
10diff --git a/gdb/microblaze-linux-tdep.c b/gdb/microblaze-linux-tdep.c
11index e3d2a7508d..5ef937219c 100644
12--- a/gdb/microblaze-linux-tdep.c
13+++ b/gdb/microblaze-linux-tdep.c
14@@ -37,7 +37,6 @@
15 #include "linux-tdep.h"
16 #include "glibc-tdep.h"
17
18-#include "gdb_assert.h"
19
20 #ifndef REGSET_H
21 #define REGSET_H 1
22--
232.17.1
24
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb/0044-gdb-microblaze-linux-nat.c-Fix-target-compilation-of.patch b/meta-microblaze/recipes-devtools/gdb/gdb/0044-gdb-microblaze-linux-nat.c-Fix-target-compilation-of.patch
new file mode 100644
index 00000000..ace6aabd
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb/0044-gdb-microblaze-linux-nat.c-Fix-target-compilation-of.patch
@@ -0,0 +1,363 @@
1From 8d75e232d3513a184180d797ef20bf53d3543fa7 Mon Sep 17 00:00:00 2001
2From: Mark Hatle <mark.hatle@xilinx.com>
3Date: Mon, 20 Jan 2020 12:48:13 -0800
4Subject: [PATCH] gdb/microblaze-linux-nat.c: Fix target compilation of gdb
5
6Add the nat to the configure file
7
8Remove gdb_assert.h and gdb_string.h.
9
10Adjust include for opcodes as well.
11
12Update to match latest style of components, similar to ppc-linux-nat.c
13
14Update:
15 get_regcache_arch(regcache) to regcache->arch()
16 regcache_raw_supply(regcache, ...) to regcache->raw_supply(...)
17 regcache_raw_collect(regcache, ...) to regcache->raw_collect(...)
18
19Signed-off-by: Mark Hatle <mark.hatle@xilinx.com>
20---
21 gdb/configure.nat | 4 +
22 gdb/microblaze-linux-nat.c | 149 +++++++++++++------------------------
23 gdb/microblaze-tdep.c | 3 +-
24 3 files changed, 57 insertions(+), 99 deletions(-)
25
26diff --git a/gdb/configure.nat b/gdb/configure.nat
27index 64ee101d83..f0f6c2f5bc 100644
28--- a/gdb/configure.nat
29+++ b/gdb/configure.nat
30@@ -261,6 +261,10 @@ case ${gdb_host} in
31 # Host: Motorola m68k running GNU/Linux.
32 NATDEPFILES="${NATDEPFILES} m68k-linux-nat.o"
33 ;;
34+ microblaze*)
35+ # Host: Microblaze, running Linux
36+ NATDEPFILES="${NATDEPFILES} microblaze-linux-nat.o"
37+ ;;
38 mips)
39 # Host: Linux/MIPS
40 NATDEPFILES="${NATDEPFILES} linux-nat-trad.o \
41diff --git a/gdb/microblaze-linux-nat.c b/gdb/microblaze-linux-nat.c
42index e9b8c9c522..e09a86bb3f 100644
43--- a/gdb/microblaze-linux-nat.c
44+++ b/gdb/microblaze-linux-nat.c
45@@ -36,11 +36,9 @@
46 #include "dwarf2-frame.h"
47 #include "osabi.h"
48
49-#include "gdb_assert.h"
50-#include "gdb_string.h"
51 #include "target-descriptions.h"
52-#include "opcodes/microblaze-opcm.h"
53-#include "opcodes/microblaze-dis.h"
54+#include "../opcodes/microblaze-opcm.h"
55+#include "../opcodes/microblaze-dis.h"
56
57 #include "linux-nat.h"
58 #include "target-descriptions.h"
59@@ -61,34 +59,27 @@
60 /* Defines ps_err_e, struct ps_prochandle. */
61 #include "gdb_proc_service.h"
62
63-/* On GNU/Linux, threads are implemented as pseudo-processes, in which
64- case we may be tracing more than one process at a time. In that
65- case, inferior_ptid will contain the main process ID and the
66- individual thread (process) ID. get_thread_id () is used to get
67- the thread id if it's available, and the process id otherwise. */
68-
69-int
70-get_thread_id (ptid_t ptid)
71-{
72- int tid = TIDGET (ptid);
73- if (0 == tid)
74- tid = PIDGET (ptid);
75- return tid;
76-}
77-
78-#define GET_THREAD_ID(PTID) get_thread_id (PTID)
79-
80 /* Non-zero if our kernel may support the PTRACE_GETREGS and
81 PTRACE_SETREGS requests, for reading and writing the
82 general-purpose registers. Zero if we've tried one of
83 them and gotten an error. */
84 int have_ptrace_getsetregs = 1;
85
86+struct microblaze_linux_nat_target final : public linux_nat_target
87+{
88+ /* Add our register access methods. */
89+ void fetch_registers (struct regcache *, int) override;
90+ void store_registers (struct regcache *, int) override;
91+
92+ const struct target_desc *read_description () override;
93+};
94+
95+static microblaze_linux_nat_target the_microblaze_linux_nat_target;
96+
97 static int
98 microblaze_register_u_addr (struct gdbarch *gdbarch, int regno)
99 {
100 int u_addr = -1;
101- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
102 /* NOTE: cagney/2003-11-25: This is the word size used by the ptrace
103 interface, and not the wordsize of the program's ABI. */
104 int wordsize = sizeof (long);
105@@ -105,18 +96,16 @@ microblaze_register_u_addr (struct gdbarch *gdbarch, int regno)
106 static void
107 fetch_register (struct regcache *regcache, int tid, int regno)
108 {
109- struct gdbarch *gdbarch = get_regcache_arch (regcache);
110- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
111+ struct gdbarch *gdbarch = regcache->arch();
112 /* This isn't really an address. But ptrace thinks of it as one. */
113 CORE_ADDR regaddr = microblaze_register_u_addr (gdbarch, regno);
114 int bytes_transferred;
115- unsigned int offset; /* Offset of registers within the u area. */
116- char buf[MAX_REGISTER_SIZE];
117+ char buf[sizeof(long)];
118
119 if (regaddr == -1)
120 {
121 memset (buf, '\0', register_size (gdbarch, regno)); /* Supply zeroes */
122- regcache_raw_supply (regcache, regno, buf);
123+ regcache->raw_supply (regno, buf);
124 return;
125 }
126
127@@ -149,14 +138,14 @@ fetch_register (struct regcache *regcache, int tid, int regno)
128 {
129 /* Little-endian values are always found at the left end of the
130 bytes transferred. */
131- regcache_raw_supply (regcache, regno, buf);
132+ regcache->raw_supply (regno, buf);
133 }
134 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
135 {
136 /* Big-endian values are found at the right end of the bytes
137 transferred. */
138 size_t padding = (bytes_transferred - register_size (gdbarch, regno));
139- regcache_raw_supply (regcache, regno, buf + padding);
140+ regcache->raw_supply (regno, buf + padding);
141 }
142 else
143 internal_error (__FILE__, __LINE__,
144@@ -175,8 +164,6 @@ fetch_register (struct regcache *regcache, int tid, int regno)
145 static int
146 fetch_all_gp_regs (struct regcache *regcache, int tid)
147 {
148- struct gdbarch *gdbarch = get_regcache_arch (regcache);
149- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
150 gdb_gregset_t gregset;
151
152 if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0)
153@@ -204,8 +191,6 @@ fetch_all_gp_regs (struct regcache *regcache, int tid)
154 static void
155 fetch_gp_regs (struct regcache *regcache, int tid)
156 {
157- struct gdbarch *gdbarch = get_regcache_arch (regcache);
158- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
159 int i;
160
161 if (have_ptrace_getsetregs)
162@@ -219,17 +204,29 @@ fetch_gp_regs (struct regcache *regcache, int tid)
163 fetch_register (regcache, tid, i);
164 }
165
166+/* Fetch registers from the child process. Fetch all registers if
167+ regno == -1, otherwise fetch all general registers or all floating
168+ point registers depending upon the value of regno. */
169+void
170+microblaze_linux_nat_target::fetch_registers (struct regcache *regcache, int regno)
171+{
172+ pid_t tid = get_ptrace_pid (regcache->ptid ());
173+
174+ if (regno == -1)
175+ fetch_gp_regs (regcache, tid);
176+ else
177+ fetch_register (regcache, tid, regno);
178+}
179
180 static void
181 store_register (const struct regcache *regcache, int tid, int regno)
182 {
183- struct gdbarch *gdbarch = get_regcache_arch (regcache);
184- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
185+ struct gdbarch *gdbarch = regcache->arch();
186 /* This isn't really an address. But ptrace thinks of it as one. */
187 CORE_ADDR regaddr = microblaze_register_u_addr (gdbarch, regno);
188 int i;
189 size_t bytes_to_transfer;
190- char buf[MAX_REGISTER_SIZE];
191+ char buf[sizeof(long)];
192
193 if (regaddr == -1)
194 return;
195@@ -242,13 +239,13 @@ store_register (const struct regcache *regcache, int tid, int regno)
196 if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
197 {
198 /* Little-endian values always sit at the left end of the buffer. */
199- regcache_raw_collect (regcache, regno, buf);
200+ regcache->raw_collect (regno, buf);
201 }
202 else if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
203 {
204 /* Big-endian values sit at the right end of the buffer. */
205 size_t padding = (bytes_to_transfer - register_size (gdbarch, regno));
206- regcache_raw_collect (regcache, regno, buf + padding);
207+ regcache->raw_collect (regno, buf + padding);
208 }
209
210 for (i = 0; i < bytes_to_transfer; i += sizeof (long))
211@@ -281,8 +278,6 @@ store_register (const struct regcache *regcache, int tid, int regno)
212 static int
213 store_all_gp_regs (const struct regcache *regcache, int tid, int regno)
214 {
215- struct gdbarch *gdbarch = get_regcache_arch (regcache);
216- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
217 gdb_gregset_t gregset;
218
219 if (ptrace (PTRACE_GETREGS, tid, 0, (void *) &gregset) < 0)
220@@ -319,8 +314,6 @@ store_all_gp_regs (const struct regcache *regcache, int tid, int regno)
221 static void
222 store_gp_regs (const struct regcache *regcache, int tid, int regno)
223 {
224- struct gdbarch *gdbarch = get_regcache_arch (regcache);
225- struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
226 int i;
227
228 if (have_ptrace_getsetregs)
229@@ -335,33 +328,10 @@ store_gp_regs (const struct regcache *regcache, int tid, int regno)
230 }
231
232
233-/* Fetch registers from the child process. Fetch all registers if
234- regno == -1, otherwise fetch all general registers or all floating
235- point registers depending upon the value of regno. */
236-
237-static void
238-microblaze_linux_fetch_inferior_registers (struct target_ops *ops,
239- struct regcache *regcache, int regno)
240-{
241- /* Get the thread id for the ptrace call. */
242- int tid = GET_THREAD_ID (inferior_ptid);
243-
244- if (regno == -1)
245- fetch_gp_regs (regcache, tid);
246- else
247- fetch_register (regcache, tid, regno);
248-}
249-
250-/* Store registers back into the inferior. Store all registers if
251- regno == -1, otherwise store all general registers or all floating
252- point registers depending upon the value of regno. */
253-
254-static void
255-microblaze_linux_store_inferior_registers (struct target_ops *ops,
256- struct regcache *regcache, int regno)
257+void
258+microblaze_linux_nat_target::store_registers (struct regcache *regcache, int regno)
259 {
260- /* Get the thread id for the ptrace call. */
261- int tid = GET_THREAD_ID (inferior_ptid);
262+ pid_t tid = get_ptrace_pid (regcache->ptid ());
263
264 if (regno >= 0)
265 store_register (regcache, tid, regno);
266@@ -373,59 +343,44 @@ microblaze_linux_store_inferior_registers (struct target_ops *ops,
267 thread debugging. */
268
269 void
270-fill_gregset (const struct regcache *regcache,
271- gdb_gregset_t *gregsetp, int regno)
272+supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
273 {
274- microblaze_collect_gregset (NULL, regcache, regno, gregsetp);
275+ microblaze_supply_gregset (NULL, regcache, -1, gregsetp);
276 }
277
278 void
279-supply_gregset (struct regcache *regcache, const gdb_gregset_t *gregsetp)
280+fill_gregset (const struct regcache *regcache,
281+ gdb_gregset_t *gregsetp, int regno)
282 {
283- microblaze_supply_gregset (NULL, regcache, -1, gregsetp);
284+ microblaze_collect_gregset (NULL, regcache, regno, gregsetp);
285 }
286
287 void
288-fill_fpregset (const struct regcache *regcache,
289- gdb_fpregset_t *fpregsetp, int regno)
290+supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
291 {
292 /* FIXME. */
293+ return;
294 }
295
296 void
297-supply_fpregset (struct regcache *regcache, const gdb_fpregset_t *fpregsetp)
298+fill_fpregset (const struct regcache *regcache,
299+ gdb_fpregset_t *fpregsetp, int regno)
300 {
301 /* FIXME. */
302+ return;
303 }
304
305-static const struct target_desc *
306-microblaze_linux_read_description (struct target_ops *ops)
307+const struct target_desc *
308+microblaze_linux_nat_target::read_description ()
309 {
310- CORE_ADDR microblaze_hwcap = 0;
311-
312- if (target_auxv_search (ops, AT_HWCAP, &microblaze_hwcap) != 1)
313- return NULL;
314-
315 return NULL;
316 }
317
318-
319-void _initialize_microblaze_linux_nat (void);
320-
321 void
322 _initialize_microblaze_linux_nat (void)
323 {
324- struct target_ops *t;
325-
326- /* Fill in the generic GNU/Linux methods. */
327- t = linux_target ();
328-
329- /* Add our register access methods. */
330- t->to_fetch_registers = microblaze_linux_fetch_inferior_registers;
331- t->to_store_registers = microblaze_linux_store_inferior_registers;
332-
333- t->to_read_description = microblaze_linux_read_description;
334+ linux_target = &the_microblaze_linux_nat_target;
335
336 /* Register the target. */
337- linux_nat_add_target (t);
338+ add_inf_child_target (linux_target);
339 }
340diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c
341index 7a0c2527f4..23deb24d26 100644
342--- a/gdb/microblaze-tdep.c
343+++ b/gdb/microblaze-tdep.c
344@@ -657,7 +657,7 @@ static std::vector<CORE_ADDR>
345 microblaze_software_single_step (struct regcache *regcache)
346 {
347 // struct gdbarch *arch = get_frame_arch(frame);
348- struct gdbarch *arch = get_regcache_arch (regcache);
349+ struct gdbarch *arch = regcache->arch();
350 struct address_space *aspace = get_regcache_aspace (regcache);
351 // struct address_space *aspace = get_frame_address_space (frame);
352 struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
353@@ -876,7 +876,6 @@ microblaze_regset_from_core_section (struct gdbarch *gdbarch,
354 static void
355 make_regs (struct gdbarch *arch)
356 {
357- struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
358 int mach = gdbarch_bfd_arch_info (arch)->mach;
359
360 if (mach == bfd_mach_microblaze64)
361--
3622.17.1
363
diff --git a/meta-microblaze/recipes-devtools/gdb/gdb_%.bbappend b/meta-microblaze/recipes-devtools/gdb/gdb_%.bbappend
new file mode 100644
index 00000000..ceb7b02b
--- /dev/null
+++ b/meta-microblaze/recipes-devtools/gdb/gdb_%.bbappend
@@ -0,0 +1,4 @@
1MICROBLAZEPATCHES = ""
2MICROBLAZEPATCHES_microblaze = "gdb-microblaze.inc"
3
4require ${MICROBLAZEPATCHES}