Jz4740:
* Optimize & cleanup thread handling a bit * Unify exception return and fix a potential bug git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20659 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
87efb79682
commit
c606fd04c8
2 changed files with 50 additions and 101 deletions
|
@ -216,10 +216,10 @@ _init_stack_loop:
|
|||
.section .vectors, "ax", %progbits
|
||||
real_exception_handler:
|
||||
addiu sp, -0x80
|
||||
sw ra, 0(sp)
|
||||
sw fp, 4(sp)
|
||||
sw gp, 8(sp)
|
||||
sw t9, 0xC(sp)
|
||||
sw ra, 0(sp)
|
||||
sw fp, 4(sp)
|
||||
sw gp, 8(sp)
|
||||
sw t9, 0xC(sp)
|
||||
sw t8, 0x10(sp)
|
||||
sw s7, 0x14(sp)
|
||||
sw s6, 0x18(sp)
|
||||
|
@ -274,60 +274,10 @@ real_exception_handler:
|
|||
_int:
|
||||
jal intr_handler
|
||||
nop
|
||||
lw ra, 0(sp)
|
||||
lw fp, 4(sp)
|
||||
sw gp, 8(sp)
|
||||
lw t9, 0xC(sp)
|
||||
lw t8, 0x10(sp)
|
||||
lw s7, 0x14(sp)
|
||||
lw s6, 0x18(sp)
|
||||
lw s5, 0x1C(sp)
|
||||
lw s4, 0x20(sp)
|
||||
lw s3, 0x24(sp)
|
||||
lw s2, 0x28(sp)
|
||||
lw s1, 0x2C(sp)
|
||||
lw s0, 0x30(sp)
|
||||
lw t7, 0x34(sp)
|
||||
lw t6, 0x38(sp)
|
||||
lw t5, 0x3C(sp)
|
||||
lw t4, 0x40(sp)
|
||||
lw t3, 0x44(sp)
|
||||
lw t2, 0x48(sp)
|
||||
lw t1, 0x4C(sp)
|
||||
lw t0, 0x50(sp)
|
||||
lw a3, 0x54(sp)
|
||||
lw a2, 0x58(sp)
|
||||
lw a1, 0x5C(sp)
|
||||
lw a0, 0x60(sp)
|
||||
lw v1, 0x64(sp)
|
||||
lw v0, 0x68(sp)
|
||||
lw $1, 0x6C(sp)
|
||||
lw k0, 0x70(sp)
|
||||
mtlo k0
|
||||
nop
|
||||
lw k0, 0x74(sp)
|
||||
mthi k0
|
||||
nop
|
||||
lw k0, 0x78(sp)
|
||||
nop
|
||||
mtc0 k0, C0_STATUS # Status register
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
lw k0, 0x7C(sp)
|
||||
nop
|
||||
mtc0 k0, C0_EPC # Exception Program Counter
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
addiu sp, 0x80
|
||||
eret # Exception Return
|
||||
nop
|
||||
j _exception_return
|
||||
|
||||
_exception:
|
||||
add a0, sp, $0
|
||||
move a0, sp
|
||||
mfc0 a1, C0_CAUSE # C0_CAUSE of last exception
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
|
@ -340,10 +290,12 @@ _exception:
|
|||
sll zero, 1
|
||||
jal exception_handler
|
||||
nop
|
||||
lw ra, 0(sp)
|
||||
lw fp, 4(sp)
|
||||
sw gp, 8(sp)
|
||||
lw t9, 0xC(sp)
|
||||
|
||||
_exception_return:
|
||||
lw ra, 0(sp)
|
||||
lw fp, 4(sp)
|
||||
lw gp, 8(sp)
|
||||
lw t9, 0xC(sp)
|
||||
lw t8, 0x10(sp)
|
||||
lw s7, 0x14(sp)
|
||||
lw s6, 0x18(sp)
|
||||
|
@ -375,15 +327,15 @@ _exception:
|
|||
mthi k0
|
||||
nop
|
||||
lw k0, 0x78(sp)
|
||||
nop
|
||||
mtc0 k0, C0_STATUS # Status register
|
||||
nop
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
lw k0, 0x7C(sp)
|
||||
nop
|
||||
mtc0 k0, C0_EPC # Exception Program Counter
|
||||
nop
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
sll zero, 1
|
||||
|
|
|
@ -937,23 +937,23 @@ static inline void core_sleep(void)
|
|||
void start_thread(void); /* Provide C access to ASM label */
|
||||
static void __attribute__((used)) _start_thread(void)
|
||||
{
|
||||
/* $t1 = context */
|
||||
/* t1 = context */
|
||||
asm volatile (
|
||||
"start_thread: \n"
|
||||
".set noreorder \n"
|
||||
".set noat \n"
|
||||
"lw $8, 4($9) \n" /* Fetch thread function pointer ($8 = $t0, $9 = $t1) */
|
||||
"lw $8, 4($9) \n" /* Fetch thread function pointer ($8 = t0, $9 = t1) */
|
||||
"lw $29, 40($9) \n" /* Set initial sp(=$29) */
|
||||
"jalr $8 \n" /* Start the thread */
|
||||
"sw $0, 48($9) \n" /* Clear start address */
|
||||
"jr $8 \n" /* Start the thread */
|
||||
"nop \n"
|
||||
".set at \n"
|
||||
".set reorder \n"
|
||||
::: "t0"
|
||||
);
|
||||
thread_exit();
|
||||
}
|
||||
|
||||
/* Place context pointer in $s0 slot, function pointer in $s1 slot, and
|
||||
/* Place context pointer in s0 slot, function pointer in s1 slot, and
|
||||
* start_thread pointer in context_start */
|
||||
#define THREAD_STARTUP_INIT(core, thread, function) \
|
||||
({ (thread)->context.r[0] = (uint32_t)&(thread)->context, \
|
||||
|
@ -969,22 +969,21 @@ static inline void store_context(void* addr)
|
|||
asm volatile (
|
||||
".set noreorder \n"
|
||||
".set noat \n"
|
||||
"move $8, %0 \n"
|
||||
"sw $16, 0($8) \n" /* $s0 */
|
||||
"sw $17, 4($8) \n" /* $s1 */
|
||||
"sw $18, 8($8) \n" /* $s2 */
|
||||
"sw $19, 12($8) \n" /* $s3 */
|
||||
"sw $20, 16($8) \n" /* $s4 */
|
||||
"sw $21, 20($8) \n" /* $s5 */
|
||||
"sw $22, 24($8) \n" /* $s6 */
|
||||
"sw $23, 28($8) \n" /* $s7 */
|
||||
"sw $28, 32($8) \n" /* gp */
|
||||
"sw $30, 36($8) \n" /* fp */
|
||||
"sw $29, 40($8) \n" /* sp */
|
||||
"sw $31, 44($8) \n" /* ra */
|
||||
"sw $16, 0(%0) \n" /* s0 */
|
||||
"sw $17, 4(%0) \n" /* s1 */
|
||||
"sw $18, 8(%0) \n" /* s2 */
|
||||
"sw $19, 12(%0) \n" /* s3 */
|
||||
"sw $20, 16(%0) \n" /* s4 */
|
||||
"sw $21, 20(%0) \n" /* s5 */
|
||||
"sw $22, 24(%0) \n" /* s6 */
|
||||
"sw $23, 28(%0) \n" /* s7 */
|
||||
"sw $28, 32(%0) \n" /* gp */
|
||||
"sw $30, 36(%0) \n" /* fp */
|
||||
"sw $29, 40(%0) \n" /* sp */
|
||||
"sw $31, 44(%0) \n" /* ra */
|
||||
".set at \n"
|
||||
".set reorder \n"
|
||||
: : "r" (addr) : "t0"
|
||||
: : "r" (addr)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -997,29 +996,27 @@ static inline void load_context(const void* addr)
|
|||
asm volatile (
|
||||
".set noat \n"
|
||||
".set noreorder \n"
|
||||
"lw $8, 48(%0) \n" /* Get start address ($8 = $t0) */
|
||||
"lw $8, 48(%0) \n" /* Get start address ($8 = t0) */
|
||||
"beqz $8, running \n" /* NULL -> already running */
|
||||
"nop \n"
|
||||
"move $9, %0 \n" /* $t1 = context */
|
||||
"jr $8 \n"
|
||||
"nop \n"
|
||||
"move $9, %0 \n" /* t1 = context */
|
||||
"running: \n"
|
||||
"move $8, %0 \n"
|
||||
"lw $16, 0($8) \n" /* $s0 */
|
||||
"lw $17, 4($8) \n" /* $s1 */
|
||||
"lw $18, 8($8) \n" /* $s2 */
|
||||
"lw $19, 12($8) \n" /* $s3 */
|
||||
"lw $20, 16($8) \n" /* $s4 */
|
||||
"lw $21, 20($8) \n" /* $s5 */
|
||||
"lw $22, 24($8) \n" /* $s6 */
|
||||
"lw $23, 28($8) \n" /* $s7 */
|
||||
"lw $28, 32($8) \n" /* gp */
|
||||
"lw $30, 36($8) \n" /* fp */
|
||||
"lw $29, 40($8) \n" /* sp */
|
||||
"lw $31, 44($8) \n" /* ra */
|
||||
"lw $16, 0(%0) \n" /* s0 */
|
||||
"lw $17, 4(%0) \n" /* s1 */
|
||||
"lw $18, 8(%0) \n" /* s2 */
|
||||
"lw $19, 12(%0) \n" /* s3 */
|
||||
"lw $20, 16(%0) \n" /* s4 */
|
||||
"lw $21, 20(%0) \n" /* s5 */
|
||||
"lw $22, 24(%0) \n" /* s6 */
|
||||
"lw $23, 28(%0) \n" /* s7 */
|
||||
"lw $28, 32(%0) \n" /* gp */
|
||||
"lw $30, 36(%0) \n" /* fp */
|
||||
"lw $29, 40(%0) \n" /* sp */
|
||||
"lw $31, 44(%0) \n" /* ra */
|
||||
".set at \n"
|
||||
".set reorder \n"
|
||||
: : "r" (addr) : "t0" /* only! */
|
||||
: : "r" (addr) : "t0", "t1"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1033,9 +1030,9 @@ static inline void core_sleep(void)
|
|||
__cpm_idle_mode();
|
||||
#endif
|
||||
asm volatile(".set mips32r2 \n"
|
||||
"mfc0 $8, $12 \n" /* mfc $t0, $12 */
|
||||
"move $9, $8 \n" /* move $t1, $t0 */
|
||||
"la $10, 0x8000000 \n" /* la $t2, 0x8000000 */
|
||||
"mfc0 $8, $12 \n" /* mfc t0, $12 */
|
||||
"move $9, $8 \n" /* move t1, t0 */
|
||||
"la $10, 0x8000000 \n" /* la t2, 0x8000000 */
|
||||
"or $8, $8, $10 \n" /* Enable reduced power mode */
|
||||
"mtc0 $8, $12 \n"
|
||||
"wait \n"
|
||||
|
|
Loading…
Reference in a new issue