#! /bin/sh -e
## 114_mips_delay_slots_in_branch.dpatch
##
## DP: Description: Handle delay slots in branch correctly. (#266660)
## DP: Author: Thiemo Seufer <ica2_ts@csv.ica.uni-stuttgart.de>
## DP: Upstream status: Committed to trunk
## DP: Date: 2004-08-18
## DP: URL: http://sources.redhat.com/ml/binutils/2004-08/msg00223.html

if [ $# -lt 1 ]; then
    echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
    exit 1
fi

[ -f debian/patches/00patch-opts ] && . debian/patches/00patch-opts
patch_opts="${patch_opts:--f --no-backup-if-mismatch} ${2:+-d $2}"

case "$1" in
    -patch) patch -p1 ${patch_opts} < $0;;
    -unpatch) patch -R -p1 ${patch_opts} < $0;;
    *)
        echo "`basename $0`: script expects -patch|-unpatch as argument" >&2
        exit 1;;
esac

exit 0

@DPATCH@
diff -urNad /home/james/debian/packages/binutils/binutils-2.15/gas/config/tc-mips.c binutils-2.15/gas/config/tc-mips.c
--- /home/james/debian/packages/binutils/binutils-2.15/gas/config/tc-mips.c	2004-05-17 20:36:10.000000000 +0100
+++ binutils-2.15/gas/config/tc-mips.c	2004-08-31 21:05:27.475711036 +0100
@@ -2708,6 +2708,7 @@
 	  prev_insn_reloc_type[1] = BFD_RELOC_UNUSED;
 	  prev_insn_reloc_type[2] = BFD_RELOC_UNUSED;
 	  prev_insn_extended = 0;
+	  prev_insn_is_delay_slot = 1;
 	}
       else
 	{
diff -urNad /home/james/debian/packages/binutils/binutils-2.15/gas/testsuite/gas/mips/branch-swap.d binutils-2.15/gas/testsuite/gas/mips/branch-swap.d
--- /home/james/debian/packages/binutils/binutils-2.15/gas/testsuite/gas/mips/branch-swap.d	1970-01-01 01:00:00.000000000 +0100
+++ binutils-2.15/gas/testsuite/gas/mips/branch-swap.d	2004-08-31 21:05:27.478710562 +0100
@@ -0,0 +1,20 @@
+#as: -march=mips2
+#objdump: -dr
+#name: MIPS branch-swap
+
+.*:     file format .*mips.*
+
+Disassembly of section \.text:
+
+00000000 <foo-0x10>:
+   0:	5040ffff 	beqzl	v0,0 <foo-0x10>
+   4:	00000000 	nop
+   8:	1000fffd 	b	0 <foo-0x10>
+   c:	00000000 	nop
+
+00000010 <foo>:
+  10:	5040ffff 	beqzl	v0,10 <foo>
+  14:	00000000 	nop
+  18:	1000fffd 	b	10 <foo>
+  1c:	00000000 	nop
+	\.\.\.
diff -urNad /home/james/debian/packages/binutils/binutils-2.15/gas/testsuite/gas/mips/branch-swap.s binutils-2.15/gas/testsuite/gas/mips/branch-swap.s
--- /home/james/debian/packages/binutils/binutils-2.15/gas/testsuite/gas/mips/branch-swap.s	1970-01-01 01:00:00.000000000 +0100
+++ binutils-2.15/gas/testsuite/gas/mips/branch-swap.s	2004-08-31 21:05:27.477710720 +0100
@@ -0,0 +1,9 @@
+	.set push
+	.set mips2
+1:	beqzl	$2, 1b
+	b	1b
+foo:	beqzl	$2, foo
+	b	foo
+
+	.set pop
+	.space 8
diff -urNad /home/james/debian/packages/binutils/binutils-2.15/gas/testsuite/gas/mips/mips.exp binutils-2.15/gas/testsuite/gas/mips/mips.exp
--- /home/james/debian/packages/binutils/binutils-2.15/gas/testsuite/gas/mips/mips.exp	2004-01-23 13:01:07.000000000 +0000
+++ binutils-2.15/gas/testsuite/gas/mips/mips.exp	2004-08-31 21:05:27.477710720 +0100
@@ -429,6 +429,7 @@
     run_dump_test_arches "branch-misc-1" [mips_arch_list_matching mips1]
     run_list_test_arches "branch-misc-2" "-32 -non_shared" [mips_arch_list_matching mips1]
     run_list_test_arches "branch-misc-2pic" "-32 -call_shared" [mips_arch_list_matching mips1]
+    run_dump_test "branch-swap"
 
     if $ilocks {
 	run_dump_test "div-ilocks"
