当前位置:网站首页>读libco保存恢复现场汇编代码
读libco保存恢复现场汇编代码
2022-07-05 17:14:00 【山有木兮啊】
x86 64位下
struct coctx_t
{
void *regs[ 14 ];
size_t ss_size;
char *ss_sp;
};
void coctx_swap(coctx_t*, coctx_t*) asm("coctx_swap");
/** 在进入这块代码之前会有call操作及压栈操作, 对于x86 64bit机器: %rdi, %rsi, %rdx, %rcx, %r8, %r9 :六个寄存器,当参数少于7个时, 参数从左到右放入寄存器: rdi, rsi, rdx, rcx, r8, r9; 当参数为7个以上时,前 6 个与前面一样, 但后面的依次从"右向左"放入栈中,即和32位汇编一样 所以栈应该是 h <- rbp 返回值地址 <- rsp l */
leaq (%rsp),%rax /* rsp存放的是返回值的地址 rax = &ra ra: rerurn address */
movq %rax, 104(%rdi) /* 上一行把rsp寄存器的值放到了rax,所以此时参数1(假设为param1)的regs[13]的存的是rsp寄存器的值 */
movq %rbx, 96(%rdi) /* param1->regs[12] = rbx */
movq %rcx, 88(%rdi) /* param1->regs[11] = rcx */
movq %rdx, 80(%rdi) /* param1->regs[10] = rdx */
movq 0(%rax), %rax /* rax存放的是返回值的地址,mov指令将返回值赋值给rax寄存器 *&ra = ra */
movq %rax, 72(%rdi) /* param1->regs[9] = rax */
movq %rsi, 64(%rdi) /* param1->regs[8] = rsi */
movq %rdi, 56(%rdi) /* param1->regs[7] = rdi */
movq %rbp, 48(%rdi) /* param1->regs[6] = rbp */
movq %r8, 40(%rdi) .
movq %r9, 32(%rdi) .
movq %r12, 24(%rdi) .
movq %r13, 16(%rdi)
movq %r14, 8(%rdi)
movq %r15, (%rdi) /* param1->regs[0] = r15 */
xorq %rax, %rax /* 异或指令 rax = rax ^ rax = 0 , 清空rax值*/
/* 以上用于保存当前的堆栈至第一个参数 */
/* 以下用于从第二个参数恢复现场 */
movq 48(%rsi), %rbp /* 由于恢复和保存相反,所以可参照上面进行分析 */
movq 104(%rsi), %rsp
movq (%rsi), %r15
movq 8(%rsi), %r14
movq 16(%rsi), %r13
movq 24(%rsi), %r12
movq 32(%rsi), %r9
movq 40(%rsi), %r8
movq 56(%rsi), %rdi
movq 80(%rsi), %rdx
movq 88(%rsi), %rcx
movq 96(%rsi), %rbx
leaq 8(%rsp), %rsp
/* rsp先是存放的是从param2->regs[13]取出的值, 此操作后将rsp寄存器里的地址+8字节 赋值给rsp, 此时rsp指向的是将要执行的函数参数一(没参数则等于rbp的值) */
pushq 72(%rsi) /* 将param2->regs[9] (即返回值地址) 压栈 rsp地址 - 8*/
/* 这两句的作用就是更新返回值地址 */
movq 64(%rsi), %rsi
ret
边栏推荐
- Cartoon: interesting pirate problem (full version)
- Rider 设置选中单词侧边高亮,去除警告建议高亮
- 普通程序员看代码,顶级程序员看趋势
- Zhang Ping'an: accélérer l'innovation numérique dans le cloud et construire conjointement un écosystème industriel intelligent
- 激动人心!2022开放原子全球开源峰会报名火热开启!
- 解读:如何应对物联网目前面临的安全问题?
- 漫画:如何实现大整数相乘?(整合版)
- [binary tree] insufficient nodes on the root to leaf path
- Short the command line via jar manifest or via a classpath file and rerun
- 漫画:一道数学题引发的血案
猜你喜欢
一文了解MySQL事务隔离级别

Design of electronic clock based on 51 single chip microcomputer

7 pratiques devops pour améliorer la performance des applications

激动人心!2022开放原子全球开源峰会报名火热开启!
基于Redis实现延时队列的优化方案小结

CMake教程Step1(基本起点)

提高应用程序性能的7个DevOps实践

ICML 2022 | Meta propose une méthode robuste d'optimisation bayésienne Multi - objectifs pour faire face efficacement au bruit d'entrée

WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands

Count the running time of PHP program and set the maximum running time of PHP
随机推荐
漫画:如何实现大整数相乘?(下)
WR | Jufeng group of West Lake University revealed the impact of microplastics pollution on the flora and denitrification function of constructed wetlands
得知女儿被猥亵,35岁男子将对方打至轻伤二级,法院作出不起诉决定
Winedt common shortcut key modify shortcut key latex compile button
激动人心!2022开放原子全球开源峰会报名火热开启!
To solve the problem of "double click PDF file, pop up", please install Evernote program
SQL Server(2)
c#图文混合,以二进制方式写入数据库
ICML 2022 | Meta提出鲁棒的多目标贝叶斯优化方法,有效应对输入噪声
CMake教程Step1(基本起点)
Force deduction solution summary 1200 minimum absolute difference
MySql 查询符合条件的最新数据行
Cartoon: how to multiply large integers? (next)
C # realizes crystal report binding data and printing 3-qr code barcode
SQL删除重复数据的实例教程
Cmake tutorial step6 (add custom commands and generate files)
mysql中取出json字段的小技巧
统计php程序运行时间及设置PHP最长运行时间
The second day of learning C language for Asian people
CVPR 2022最佳学生论文:单张图像估计物体在3D空间中的位姿估计