Chinaunix首页 | 论坛 | 博客
  • 博客访问: 155903
  • 博文数量: 129
  • 博客积分: 125
  • 博客等级: 入伍新兵
  • 技术积分: 670
  • 用 户 组: 普通用户
  • 注册时间: 2012-06-17 16:37
文章分类

全部博文(129)

文章存档

2013年(12)

2012年(117)

我的朋友

分类:

2012-07-19 17:12:02

asm volatile ("asm routine" : output : input : modify);

 

#define switch_to(prev,next,last) do {                    
    asm 
volatile("pushl %%esi "                    
             
"pushl %%edi "                    
             
"pushl %%ebp "                    
             
"movl %%esp,%0 "    /* save ESP */        
             
"movl %3,%%esp "    /* restore ESP */    
             
"movl $1f,%1 "        /* save EIP */        
             
"pushl %4 "        /* restore EIP */    
             
"jmp __switch_to "                
             
"1: "                        
             
"popl %%ebp "                    
             
"popl %%edi "                    
             
"popl %%esi "                    
             :
"=m" (prev->thread.esp),"=m" (prev->thread.eip),    
              
"=b" (last)                    
             :
"m" (next->thread.esp),"m" (next->thread.eip),    
              
"a" (prev), "d" (next),                
              
"b" (prev));                    
while (0)

上面的代码汇编之后大致如下:

#define switch_to(prev,next,last) do {            
    asm 
volatile("pushl %%esi "                
             
"pushl %%edi "                    
             
"pushl %%ebp "                    
             
"movl %%esp,(prev->thread.esp) "/* save ESP */        
             
"movl (next->thread.esp),%%esp "/* restore ESP */    
             
"movl $1f,(prev->thread.eip) "    /* save EIP */        
             
"pushl (next->thread.eip) "        /* restore EIP */    
             
"jmp __switch_to "                
             
"1: "                                
             
"popl %%ebp "                    
             
"popl %%edi "                    
             
"popl %%esi "                    
             :
"=m" (prev->thread.esp),"=m" (prev->thread.eip),    
              
"=b" (last)                    
             :
"m" (next->thread.esp),"m" (next->thread.eip),    
              
"a" (prev), "d" (next),                
              
"b" (prev));                    
while (0)

m = memory

b = ebx

a = eax

d = edx

 f = forward

阅读(236) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~