免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1112 | 回复: 0
打印 上一主题 下一主题

ARM Linux 进程调度(3) 选择自 FireAngel 的 Blog [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-02 09:55 |只看该作者 |倒序浏览

switch_mm中是进行页表的切换,即将下一个的pgd的开始物理地址放入CP15中的C2寄存器。进程的pgd的虚拟地址存放在task_struct结构中的pgd指针中,通过__virt_to_phys宏可以转变成成物理地址。
static inline voidswitch_mm(struct mm_struct *prev, struct mm_struct *next,         struct task_struct *tsk, unsigned int cpu){       if (prev != next)              cpu_switch_mm(next->pgd, tsk);} #define cpu_switch_mm(pgd,tsk) cpu_set_pgd(__virt_to_phys((unsigned long)(pgd))) #define cpu_get_pgd()      \       ({                                        \              unsigned long pg;                     \              __asm__("mrc p15, 0, %0, c2, c0, 0"      \                      : "=r" (pg));                \              pg &= ~0x3fff;                           \              (pgd_t *)phys_to_virt(pg);         \       })
switch_to()完成进程上下文的切换,通过调用汇编函数__switch_to完成,其实现比较简单,也就是保存prev进程的上下文信息,该上下文信息由context_save_struct结构描述,包括主要的寄存器,然后将next的上下文信息读出,信息保存在task_struct中的thread.save中TSS_SAVE标识了thread.save在task_struct中的位置。
/* * Register switch for ARMv3 and ARMv4 processors * r0 = previous, r1 = next, return previous. * previous and next are guaranteed not to be the same. */ ENTRY(__switch_to)              stmfd      sp!, {r4 - sl, fp, lr}        @ Store most regs on stack              mrs ip, cpsr              str   ip, [sp, #-4]!                 @ Save cpsr_SVC              str   sp, [r0, #TSS_SAVE]         @ Save sp_SVC              ldr   sp, [r1, #TSS_SAVE]         @ Get saved sp_SVC              ldr   r2, [r1, #TSS_DOMAIN]              ldr   ip, [sp], #4              mcr p15, 0, r2, c3, c0        @ Set domain register              msr spsr, ip                 @ Save tasks CPSR into SPSR for this return              ldmfd      sp!, {r4 - sl, fp, pc}^            @ Load all regs saved previously
struct context_save_struct {       unsigned long cpsr;       unsigned long r4;       unsigned long r5;       unsigned long r6;       unsigned long r7;       unsigned long r8;       unsigned long r9;       unsigned long sl;       unsigned long fp;       unsigned long pc;};

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/51591/showart_454715.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP