Chinaunix首页 | 论坛 | 博客
  • 博客访问: 412959
  • 博文数量: 93
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 1052
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-19 11:01
文章分类

全部博文(93)

文章存档

2011年(1)

2009年(26)

2008年(66)

我的朋友

分类: LINUX

2008-04-04 13:50:53

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

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