Understanding the linux kernel-ch3-Process Switch

task switch
context switch
hardware context 
switch_to Macro
#define switch_to(prev,next,last) do {/
unsigned long esi,edi;/
asm volatile("pushfl/n/t"/
     "pushl %%ebp/n/t"/
     "movl %%esp,%0/n/t"/* save ESP *//
     "movl %5,%%esp/n/t"/* restore ESP *//
     "movl $1f,%1/n/t"/* save EIP *//
     "pushl %6/n/t"/* restore EIP *//
     "jmp __switch_to/n"/
     "1:/t"/
     "popl %%ebp/n/t"/
     "popfl"/
     :"=m" (prev->thread.esp),"=m" (prev->thread.eip),/
      "=a" (last),"=S" (esi),"=D" (edi)/
     :"m" (next->thread.esp),"m" (next->thread.eip),/
      "2" (prev), "d" (next));/
} while (0)
1. movl prev, %eax
    movl next, %edx
2. pushfl
    pushl %ebp
3,movl %esp,484(%eax)//prev->thread.esp 
4,movl 484(%edx), %esp//next->thread.esp 
5,movl $1f, 480(%eax)//prev->thread.eip
6,pushl 480(%edx)//next->thread.eip 
7,jmp _ _switch_to
8. 1:
        popl %ebp
        popfl
9,movl %eax, last
_ _switch_to ( )
_ _switch_to(struct task_struct *prev_p,
                struct task_struct *next_p)
       _ _attribute_ _(regparm(3));
_ _unlazy_fpu( ) macro,save the contents of the FPU, MMX, and XMM registers of the prev_p process.
 smp_processor_id( ) macro to get the index of the local CPU 
Loads next_p->thread.esp0 in the esp0 field of the TSS relative to the local CPU
Loads in the Global Descriptor Table of the local CPU the Thread-Local Storage (TLS) segments used by the next_p process
Stores the contents of the fs and gs segmentation registers in prev_p->thread.fs and prev_p->thread.gs
load fs or the gs segmentation register 
Loads six of the dr0,..., dr7 debug registers
Updates the I/O bitmap in the TSS
Terminates
FPU:arithmetic floating-point unit 
floating-point registers belongs to hardware contextESCAPE
MMX instructions act on the floating-point registers of the FPU
SIMD:single-instruction multiple-data 
SSE extensions Streaming SIMD ExtensionsPentium III 
XMM registers
SSE2 extensionsPentium 4
TS (Task-Switching) flag in the cr0 register       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值