【MIPS CPU 体系结构概述2】连载12:

/*判断当前运行态,设置栈顶sp
保存寄存器--参数a0-a3:4-7,返回值v0-v1:2-3,25,28,31以及一些控制寄存器,
*/

#define SAVE_SOME \
.set push; \
.set reorder; \
mfc0 k0, CP0_STATUS; \
sll k0, 3; /* extract cu0 bit */ \
.set noreorder; \
bltz k0, 8f; \
move k1, sp; \
.set reorder; \
/* Called from user mode, new stack. */ \
GET_SAVED_SP \
8: \
move k0, sp; \
subu sp, k1, PT_SIZE; \
sw k0, PT_R29(sp); \
sw $3, PT_R3(sp); \
sw $0, PT_R0(sp); \
mfc0 v1, CP0_STATUS; \
sw $2, PT_R2(sp); \
sw v1, PT_STATUS(sp); \
sw $4, PT_R4(sp); \
mfc0 v1, CP0_CAUSE; \
sw $5, PT_R5(sp); \
sw v1, PT_CAUSE(sp); \
sw $6, PT_R6(sp); \
mfc0 v1, CP0_EPC; \
sw $7, PT_R7(sp); \
sw v1, PT_EPC(sp); \
sw $25, PT_R25(sp); \
sw $28, PT_R28(sp); \
sw $31, PT_R31(sp); \

ori $28, sp, 0x1fff; \
xori $28, 0x1fff; \
.set pop

#define SAVE_ALL \
SAVE_SOME; \
SAVE_AT; \
SAVE_TEMP; \
SAVE_STATIC

#define RESTORE_AT \
.set push; \
.set noat; \
lw $1, PT_R1(sp); \
.set pop;

#define RESTORE_TEMP \
lw $24, PT_LO(sp); \
lw $8, PT_R8(sp); \
lw $9, PT_R9(sp); \
mtlo $24; \
lw $24, PT_HI(sp); \
lw $10,PT_R10(sp); \
lw $11, PT_R11(sp); \
mthi $24; \
lw $12, PT_R12(sp); \
lw $13, PT_R13(sp); \
lw $14, PT_R14(sp); \
lw $15, PT_R15(sp); \
lw $24, PT_R24(sp)

#define RESTORE_STATIC \
lw $16, PT_R16(sp); \
lw $17, PT_R17(sp); \
lw $18, PT_R18(sp); \
lw $19, PT_R19(sp); \

lw $20, PT_R20(sp); \
lw $21, PT_R21(sp); \
lw $22, PT_R22(sp); \
lw $23, PT_R23(sp); \
lw $30, PT_R30(sp)

#if defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_TX39XX)

#define RESTORE_SOME \
.set push; \
.set reorder; \
mfc0 t0, CP0_STATUS; \
.set pop; \
ori t0, 0x1f; \
xori t0, 0x1f; \
mtc0 t0, CP0_STATUS; \
li v1, 0xff00; \
and t0, v1; \
lw v0, PT_STATUS(sp); \
nor v1, $0, v1; \
and v0, v1; \
or v0, t0; \
mtc0 v0, CP0_STATUS; \
lw $31, PT_R31(sp); \
lw $28, PT_R28(sp); \
lw $25, PT_R25(sp); \
lw $7, PT_R7(sp); \
lw $6, PT_R6(sp); \
lw $5, PT_R5(sp); \
lw $4, PT_R4(sp); \
lw $3, PT_R3(sp); \
lw $2, PT_R2(sp)

#define RESTORE_SP_AND_RET \
.set push; \
.set noreorder; \

lw k0, PT_EPC(sp); \
lw sp, PT_R29(sp); \
jr k0; \
rfe; \

--电子创新网--
粤ICP备12070055号