Changeset View
Changeset View
Standalone View
Standalone View
head/sys/amd64/amd64/cpu_switch.S
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | |||||
* Save the current thread state, then select the next thread to run | * Save the current thread state, then select the next thread to run | ||||
* and load its state. | * and load its state. | ||||
* %rdi = oldtd | * %rdi = oldtd | ||||
* %rsi = newtd | * %rsi = newtd | ||||
* %rdx = mtx | * %rdx = mtx | ||||
*/ | */ | ||||
ENTRY(cpu_switch) | ENTRY(cpu_switch) | ||||
/* Switch to new thread. First, save context. */ | /* Switch to new thread. First, save context. */ | ||||
movq TD_PCB(%rdi),%r8 | leaq TD_MD_PCB(%rdi),%r8 | ||||
movq (%rsp),%rax /* Hardware registers */ | movq (%rsp),%rax /* Hardware registers */ | ||||
movq %r15,PCB_R15(%r8) | movq %r15,PCB_R15(%r8) | ||||
movq %r14,PCB_R14(%r8) | movq %r14,PCB_R14(%r8) | ||||
movq %r13,PCB_R13(%r8) | movq %r13,PCB_R13(%r8) | ||||
movq %r12,PCB_R12(%r8) | movq %r12,PCB_R12(%r8) | ||||
movq %rbp,PCB_RBP(%r8) | movq %rbp,PCB_RBP(%r8) | ||||
movq %rsp,PCB_RSP(%r8) | movq %rsp,PCB_RSP(%r8) | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | 2: | ||||
/* Save is done. Now fire up new thread. Leave old vmspace. */ | /* Save is done. Now fire up new thread. Leave old vmspace. */ | ||||
movq %rsi,%r12 | movq %rsi,%r12 | ||||
movq %rdi,%r13 | movq %rdi,%r13 | ||||
movq %rdx,%r15 | movq %rdx,%r15 | ||||
movq %rsi,%rdi | movq %rsi,%rdi | ||||
callq pmap_activate_sw | callq pmap_activate_sw | ||||
movq %r15,TD_LOCK(%r13) /* Release the old thread */ | movq %r15,TD_LOCK(%r13) /* Release the old thread */ | ||||
sw1: | sw1: | ||||
movq TD_PCB(%r12),%r8 | leaq TD_MD_PCB(%r12),%r8 | ||||
#if defined(SCHED_ULE) && defined(SMP) | #if defined(SCHED_ULE) && defined(SMP) | ||||
movq $blocked_lock, %rdx | movq $blocked_lock, %rdx | ||||
movq TD_LOCK(%r12),%rcx | movq TD_LOCK(%r12),%rcx | ||||
cmpq %rcx, %rdx | cmpq %rcx, %rdx | ||||
je sw1wait | je sw1wait | ||||
sw1cont: | sw1cont: | ||||
#endif | #endif | ||||
/* | /* | ||||
Show All 36 Lines | do_kthread: | ||||
/* Do we need to reload tss ? */ | /* Do we need to reload tss ? */ | ||||
movq PCPU(TSSP),%rax | movq PCPU(TSSP),%rax | ||||
movq PCB_TSSP(%r8),%rdx | movq PCB_TSSP(%r8),%rdx | ||||
testq %rdx,%rdx | testq %rdx,%rdx | ||||
cmovzq PCPU(COMMONTSSP),%rdx | cmovzq PCPU(COMMONTSSP),%rdx | ||||
cmpq %rax,%rdx | cmpq %rax,%rdx | ||||
jne do_tss | jne do_tss | ||||
done_tss: | done_tss: | ||||
movq %r8,PCPU(RSP0) | movq TD_MD_STACK_BASE(%r12),%r9 | ||||
movq %r9,PCPU(RSP0) | |||||
movq %r8,PCPU(CURPCB) | movq %r8,PCPU(CURPCB) | ||||
movq PCPU(PTI_RSP0),%rax | movq PCPU(PTI_RSP0),%rax | ||||
cmpq $~0,PCPU(UCR3) | cmpq $~0,PCPU(UCR3) | ||||
cmove %r8,%rax | cmove %r9,%rax | ||||
movq %rax,TSS_RSP0(%rdx) | movq %rax,TSS_RSP0(%rdx) | ||||
movq %r12,PCPU(CURTHREAD) /* into next thread */ | movq %r12,PCPU(CURTHREAD) /* into next thread */ | ||||
/* Test if debug registers should be restored. */ | /* Test if debug registers should be restored. */ | ||||
testl $PCB_DBREGS,PCB_FLAGS(%r8) | testl $PCB_DBREGS,PCB_FLAGS(%r8) | ||||
jnz load_dr /* static predict not taken */ | jnz load_dr /* static predict not taken */ | ||||
done_load_dr: | done_load_dr: | ||||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |