QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 977|回复: 4

__switch_to的问题

[复制链接]
发表于 2004-3-30 09:29:39 | 显示全部楼层 |阅读模式
我在看情境分析的时候,在schedule的switch_to里:

#define switch_to(prev,next,last) do {                                        \
        asm volatile("pushl %%esi\n\t"                                        \
                     "pushl %%edi\n\t"                                        \
                     "pushl %%ebp\n\t"                                        \
                     "movl %%esp,%0\n\t"        /* save ESP */                \
                     "movl %3,%%esp\n\t"        /* restore ESP */        \
                     "movl $1f,%1\n\t"                /* save EIP */                \
                     "pushl %4\n\t"                /* restore EIP */        \
                     "jmp __switch_to\n"                                \
                     "1:\t"                                                \
                     "popl %%ebp\n\t"                                        \
                     "popl %%edi\n\t"                                        \
                     "popl %%esi\n\t"                                        \
                     :"=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)

调用了__switch_to,来做TSS关于当前进程的内核空间堆栈指针的设置.但是__switch_to是带有两个形参的:

void __switch_to(struct task_struct *prev_p, struct task_struct *next_p)

但是我仔细看了代码,在跳转到__switch_to之前,系统堆栈中并没有指向prev_p和next_p的指针,那么这个函数的两个实参从哪儿而来呢?
盼指教!
发表于 2004-3-30 14:32:20 | 显示全部楼层
struct task_struct fastcall * __switch_to(struct task_struct *prev_p, struct task_struct *next_p)

fastcall :使用寄存器传递参数,而不是栈

注意一下switch_to中各寄存器的变化
回复

使用道具 举报

 楼主| 发表于 2004-3-30 15:02:23 | 显示全部楼层
哦,谢谢回复!
我对汇编不是很了解,也就是说一个函数被声明为fastcall,就通过寄存器来传递参数,那用于这个目的的是哪几个寄存器阿,它们的顺序是什么,我的问题可能比较幼稚,请包涵!
通过代码,可以知道是eax,edx,...(后面还有哪些??)
回复

使用道具 举报

发表于 2004-3-30 16:56:36 | 显示全部楼层
用于此目的的寄存器有3个,按顺序是eax,edx,ecx.
ebx另有它用,具体的我忘记了

可以手动指定函数使用这几个寄存器,例如:
int f (int a,int b) __attribute__ ((regparm(3)))
回复

使用道具 举报

 楼主| 发表于 2004-3-30 16:58:19 | 显示全部楼层
ok.thx
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-9-29 11:36 , Processed in 0.038495 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表