[Cbe-oss-dev] [PATCH 23/23]MARS/task: asm reg func self modifying

Yuji Mano yuji.mano at am.sony.com
Tue Mar 17 04:55:26 EST 2009


Resend

Implement registers_save/registers_restore in task module to be self modifying
assembly code. This reduces task module code size by 288 bytes.

Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>
---
 task/src/mpu/module/task_switch.S |  164 ++++++++++++++------------------------
 1 file changed, 64 insertions(+), 100 deletions(-)

--- a/task/src/mpu/module/task_switch.S
+++ b/task/src/mpu/module/task_switch.S
@@ -128,106 +128,70 @@ task_restore:
 .size	task_restore, .-task_restore
 
 
+/*
+ * Registers are saved/restored on task stack.
+ *
+ * Task Stack               High Address
+ * +------------------------+
+ * |  Used Task Stack Area  |
+ * +------------------------+ <--- STACK_PTR
+ * | Non-volatile Registers |          |
+ * |         $127           |          |
+ * |         $126           |          |
+ * |         $125           |       (size)
+ * |         ...            |    NUM_REGS * 16
+ * |         $82            |          |
+ * |         $81            |          |
+ * |         $80            |          |
+ * +------------------------+ <--- REGS_PTR
+ * |    Work Code Block     |
+ * +------------------------+ <--- CODE_PTR + 16
+ * |    Loop Code Block     |
+ * +------------------------+ <--- CODE_PTR
+ *                          Low Address
+ */
+
+#define NUM_REGS	48	/* number of registers to be saved/restored */
+#define STACK_PTR	$73	/* current task stack pointer */
+#define CODE_PTR	$74	/* where code will be loaded into stack */
+#define REGS_PTR	$75	/* where regs will be placed into stack */
+#define REGS_INC	$76	/* register increment value for instruction */
+#define TEMP		$77	/* temporary register */
+#define INST		$78	/* register to store volatile instruction */
+#define INST_MASK	$79	/* mask instruction to store or load */
+
 __registers_save:
-	lqr	$75, __task_stack
-	stqd	$80, -16($75)
-	stqd	$81, -32($75)
-	stqd	$82, -48($75)
-	stqd	$83, -64($75)
-	stqd	$84, -80($75)
-	stqd	$85, -96($75)
-	stqd	$86, -112($75)
-	stqd	$87, -128($75)
-	stqd	$88, -144($75)
-	stqd	$89, -160($75)
-	stqd	$90, -176($75)
-	stqd	$91, -192($75)
-	stqd	$92, -208($75)
-	stqd	$93, -224($75)
-	stqd	$94, -240($75)
-	stqd	$95, -256($75)
-	stqd	$96, -272($75)
-	stqd	$97, -288($75)
-	stqd	$98, -304($75)
-	stqd	$99, -320($75)
-	stqd	$100, -336($75)
-	stqd	$101, -352($75)
-	stqd	$102, -368($75)
-	stqd	$103, -384($75)
-	stqd	$104, -400($75)
-	stqd	$105, -416($75)
-	stqd	$106, -432($75)
-	stqd	$107, -448($75)
-	stqd	$108, -464($75)
-	stqd	$109, -480($75)
-	stqd	$110, -496($75)
-	stqd	$111, -512($75)
-	stqd	$112, -528($75)
-	stqd	$113, -544($75)
-	stqd	$114, -560($75)
-	stqd	$115, -576($75)
-	stqd	$116, -592($75)
-	stqd	$117, -608($75)
-	stqd	$118, -624($75)
-	stqd	$119, -640($75)
-	stqd	$120, -656($75)
-	stqd	$121, -672($75)
-	stqd	$122, -688($75)
-	stqd	$123, -704($75)
-	stqd	$124, -720($75)
-	stqd	$125, -736($75)
-	stqd	$126, -752($75)
-	stqd	$127, -768($75)
-	bi	$LR
+	il	INST_MASK, 0			/* no mask - default is stqd */
+	br	body				/* jump to the body */
 
 __registers_restore:
-	lqr	$75, __task_stack
-	lqd	$80, -16($75)
-	lqd	$81, -32($75)
-	lqd	$82, -48($75)
-	lqd	$83, -64($75)
-	lqd	$84, -80($75)
-	lqd	$85, -96($75)
-	lqd	$86, -112($75)
-	lqd	$87, -128($75)
-	lqd	$88, -144($75)
-	lqd	$89, -160($75)
-	lqd	$90, -176($75)
-	lqd	$91, -192($75)
-	lqd	$92, -208($75)
-	lqd	$93, -224($75)
-	lqd	$94, -240($75)
-	lqd	$95, -256($75)
-	lqd	$96, -272($75)
-	lqd	$97, -288($75)
-	lqd	$98, -304($75)
-	lqd	$99, -320($75)
-	lqd	$100, -336($75)
-	lqd	$101, -352($75)
-	lqd	$102, -368($75)
-	lqd	$103, -384($75)
-	lqd	$104, -400($75)
-	lqd	$105, -416($75)
-	lqd	$106, -432($75)
-	lqd	$107, -448($75)
-	lqd	$108, -464($75)
-	lqd	$109, -480($75)
-	lqd	$110, -496($75)
-	lqd	$111, -512($75)
-	lqd	$112, -528($75)
-	lqd	$113, -544($75)
-	lqd	$114, -560($75)
-	lqd	$115, -576($75)
-	lqd	$116, -592($75)
-	lqd	$117, -608($75)
-	lqd	$118, -624($75)
-	lqd	$119, -640($75)
-	lqd	$120, -656($75)
-	lqd	$121, -672($75)
-	lqd	$122, -688($75)
-	lqd	$123, -704($75)
-	lqd	$124, -720($75)
-	lqd	$125, -736($75)
-	lqd	$126, -752($75)
-	lqd	$127, -768($75)
-	bi	$LR
+	il	INST_MASK, 16			/* set necessary bits */
+	shlqbyi	INST_MASK, INST_MASK, 15	/* shift to correct position */
+
+body:
+	lqr	STACK_PTR, __task_stack		/* load task stack pointer */
+	il	TEMP, -NUM_REGS * 16		/* size of reg save area */
+	a	REGS_PTR, STACK_PTR, TEMP	/* set reg load addr pointer */
+	ai	CODE_PTR, REGS_PTR, -2 * 16	/* set code load addr pointer */
+	lqr	TEMP, loop			/* load loop code to register */
+	stqd	TEMP, 0(CODE_PTR)		/* store loop code to stack */
+	lqr	INST, inst			/* load inst code to register */
+	or	INST, INST, INST_MASK		/* mask instr to stqd or lqd */
+	il	REGS_INC, 1			/* set bit in reg incrementer */
+	shlqbyi	REGS_INC, REGS_INC, 12		/* shift to correct word slot */
+	il	TEMP, NUM_REGS - 1		/* initialize loop counter */
+	sync					/* wait till loop code stored */
+	bi	CODE_PTR			/* jump and never return */
+
+	.balignl	16, 0			/* align self modifying code */
+loop:
+	stqd	INST, 16(CODE_PTR)		/* store inst code to stack */
+	a	INST, INST, REGS_INC		/* increment register number */
+	ai	TEMP, TEMP, -1			/* decrment loop counter */
+	sync					/* wait till inst code stored */
+
+inst:
+	stqd	$80, 0(REGS_PTR)		/* store reg to stack */
+	ai	REGS_PTR, REGS_PTR, 16		/* increment regs pointer */
+	biz	TEMP, $LR			/* if (TEMP == 0) done */
+	br	loop				/* if (TEMP != 0) loop */





More information about the cbe-oss-dev mailing list