$NetBSD: patch-ac,v 1.9 2003/06/29 23:06:47 jtb Exp $

--- /dev/null
+++ config/netbsd/powerpc.s
@@ -0,0 +1,46 @@
+#
+#	coswitch for the PowerPC
+#
+
+	.file   "rswitch.s"
+
+	.set	RSIZE, 80		# room for regs 14-31, rounded up mod16
+
+	.data
+errmsg:		.string "new_context() returned in coswitch\n"
+
+	.text
+	.align  2
+	.globl  coswitch
+	.type	coswitch,@function
+
+coswitch:
+	stwu	1, -RSIZE(1)		# allocate stack frame
+
+					# Save Old Context:
+	stw	1, 0(3)			# SP
+	mflr	0
+	stw	0, 4(3)			# LR (return address)
+	stmw	14, -RSIZE(1)		# GPRs 14-31 (save on stack)
+
+	cmpi	0, 5, 0
+	beq	first			# if first time
+
+					# Restore new context:
+	lwz	1, 0(4)			# SP
+	lwz	0, 4(4)			# LR
+	mtlr	0
+	lmw	14, -RSIZE(1)		# GPRs 14-31 (from stack)
+
+	addic	1, 1, RSIZE		# deallocate stack frame
+	blr				# return into new context
+
+first:					# First-time call:
+	lwz	1, 0(4)			# SP as figured by Icon
+	addic	1, 1, -64		# save area for callee
+	addi	3, 0, 0			# arg1
+	addi	4, 0, 0			# arg2
+	bl	new_context		# new_context(0,0)
+	lis	3, errmsg@ha
+	la	3, errmsg@l(3)
+	bl	syserr
