当前位置:网站首页>读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] question
- 統計php程序運行時間及設置PHP最長運行時間
- Cartoon: how to multiply large integers? (next)
- Rider 设置选中单词侧边高亮,去除警告建议高亮
- Machine learning 01: Introduction
- First day of learning C language
- 排错-关于clion not found visual studio 的问题
- 漫画:有趣的【海盗】问题
- 华为云云原生容器综合竞争力,中国第一!
- C # realizes crystal report binding data and printing 3-qr code barcode
猜你喜欢
随机推荐
mysql中取出json字段的小技巧
Tips for extracting JSON fields from MySQL
Understand the usage of functions and methods in go language
Force deduction solution summary 729- my schedule I
MYSQL group by 有哪些注意事项
Example tutorial of SQL deduplication
解读:如何应对物联网目前面临的安全问题?
中国银河证券开户安全吗 开户后多久能买股票
云主机oracle异常恢复----惜分飞
Cmake tutorial step6 (add custom commands and generate files)
提高應用程序性能的7個DevOps實踐
Kafaka技术第一课
Oracle缩表空间的完整解决实例
Short the command line via jar manifest or via a classpath file and rerun
Is it safe and reliable to open futures accounts on koufu.com? How to distinguish whether the platform is safe?
Redis+caffeine two-level cache enables smooth access speed
[7.7 live broadcast preview] the lecturer of "typical architecture of SaaS cloud native applications" teaches you to easily build cloud native SaaS applications. Once the problem is solved, Huawei's s
漫画:寻找无序数组的第k大元素(修订版)
Seven Devops practices to improve application performance
Complete solution instance of Oracle shrink table space