shithub: scc

Download patch

ref: 21674aabd645829b4be407b084e399c46f5ccd6f
parent: 413609195feb8bd92c45204536c925a1006cba9e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Sep 21 15:50:40 EDT 2019

[as-powerpc] Add BC instructions

These are conditional branch instructions

--- a/src/cmd/as/target/powerpc/ins.c
+++ b/src/cmd/as/target/powerpc/ins.c
@@ -79,6 +79,7 @@
 			if ((getclass(np) & class) == 0)
 				return 0;
 			break;
+		case AIMM5:
 		case AIMM8:
 		case AIMM16:
 		case AIMM32:
@@ -160,7 +161,31 @@
 void
 b_form(Op *op, Node **args)
 {
-	abort();
+	unsigned long ins, opcd, bo, bi, bd, aa, lk;
+	long long dst;
+	long long max = 1l << 13;
+	long long min = -(1l << 13);
+
+	opcd = op->bytes[0];
+	aa = op->bytes[1];
+	lk = op->bytes[2];
+
+	bo = args[0]->sym->value;
+	bi = args[1]->sym->value;
+
+	dst = args[2]->sym->value;
+	if (dst & 0x3)
+		error("unaligned branch");
+	if (aa)
+		dst -= cursec->curpc - 4;
+
+	if (dst < min || dst > max)
+		error("out of range branch");
+	bd = dst;
+	bd >>= 2;
+
+	ins = opcd<<26 | bo<<21 | bi<<16 | bd<<11 | aa<<1 | lk;
+	emit_packed(ins);
 }
 
 void
--- a/src/cmd/as/target/powerpc/powerpc.dat
+++ b/src/cmd/as/target/powerpc/powerpc.dat
@@ -45,3 +45,12 @@
 BL	imm64	4	18,0,1	i_form	POWERPC64
 BLA	imm32	4	18,1,1	i_form	POWERPC
 BLA	imm64	4	18,1,1	i_form	POWERPC64
+
+BC	imm5,imm5,imm32	4	16,0,0	b_form	POWERPC
+BC	imm5,imm5,imm64	4	16,0,0	b_form	POWERPC64
+BCA	imm5,imm5,imm32	4	16,1,0	b_form	POWERPC
+BCA	imm5,imm5,imm64	4	16,1,0	b_form	POWERPC64
+BCL	imm5,imm5,imm32	4	16,0,1	b_form	POWERPC
+BCL	imm5,imm5,imm64	4	16,0,1	b_form	POWERPC64
+BCLA	imm5,imm5,imm32	4	16,1,1	b_form	POWERPC
+BCLA	imm5,imm5,imm64	4	16,1,1	b_form	POWERPC64
--- a/src/cmd/as/target/powerpc/rules.dat
+++ b/src/cmd/as/target/powerpc/rules.dat
@@ -1,3 +1,4 @@
+imm5	AIMM5
 imm8	AIMM8
 imm16	AIMM16
 imm32	AIMM32
--- a/tests/as/execute/powerpc.s
+++ b/tests/as/execute/powerpc.s
@@ -2,3 +2,8 @@
 	BA	$L1	/ 48 00 00 0E
 	BL	$L1	/ 48 00 00 0D
 L1:	BLA	$L1	/ 48 00 00 07
+
+	BC	$3,$2,$L2	/ 40 62 38 00
+	BCA	$2,$1,$L2	/ 40 41 18 02
+	BCL	$1,$3,$L2	/ 40 23 38 01
+L2:	BCLA	$3,$4,$L2	/ 40 64 08 03