博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nachos中switch汇编源码分析
阅读量:4068 次
发布时间:2019-05-25

本文共 646 字,大约阅读时间需要 2 分钟。

昨天有空看了一下nachos里的switch.s中switch 函数,从最底层了解了一下,进程(线程)切换时,是如何把旧进程搬出寄存器,新进程如何搬进寄存器。

具体源码和分析如下:

/* void SWITCH( thread *t1, thread *t2 )
**
** on entry, stack looks like this:
**      8(esp)  ->              thread *t2(new)
**      4(esp)  ->              thread *t1(old)
**       (esp)  ->              return address
**
** we push the current eax on the stack so that we can use it as
** a pointer to t1, this decrements esp by 4, so when we use it
** to reference stuff on the stack, we add 4 to the offset.

*/

 

具体分析如下:

1.  回顾一下EAX等这些寄存器是干嘛的?

     

2.  movl的语法是如何操作的?

     movl  source des 

3. 基于上面的知识和源码,流程图如下:

     总的思路, 就是当前的进程 所有寄存器状态保存到 4(esp )所指向的旧线程的内存中,

    然后再把8(esp)所指向的新线程的内存中的值更新当前的寄存器值,

    然后把该函数的返回地址,指向新的线程

                                 如有不对之处,欢迎指正!

转载地址:http://npoji.baihongyu.com/

你可能感兴趣的文章
Visual Studio 2010:C++0x新特性
查看>>
所谓的进步和提升,就是完成认知升级
查看>>
如何用好碎片化时间,让思维更有效率?
查看>>
No.182 - LeetCode1325 - C指针的魅力
查看>>
Encoding Schemes
查看>>
带WiringPi库的交叉笔译如何处理二之软链接概念
查看>>
Java8 HashMap集合解析
查看>>
自定义 select 下拉框 多选插件
查看>>
gdb 调试core dump
查看>>
gdb debug tips
查看>>
linux和windows内存布局验证
查看>>
本地服务方式搭建etcd集群
查看>>
安装k8s Master高可用集群
查看>>
忽略图片透明区域的事件(Flex)
查看>>
Xpath使用方法
查看>>
移动端自动化测试-Mac-IOS-Appium环境搭建
查看>>
Selenium之前世今生
查看>>
Selenium-WebDriverApi接口详解
查看>>
Selenium-ActionChains Api接口详解
查看>>
Selenium-Switch与SelectApi接口详解
查看>>