tinyrpc/includes/coroutine/coctx.h
2024-12-17 15:47:10 +08:00

38 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
namespace tinyrpc {
namespace reg {
enum { // https://wiki.osdev.org/System_V_ABI
kRBP = 6, // 栈底指针
kRDI = 7, // rdi调用函数时的第一个参数
kRSI = 8, // rsi, 调用函数时的第二个参数 这两个是 根据调用约定确定的
kRETAddr = 9, // 下一个要执行的命令地址,它将被分配给 rip
kRSP = 13, // 堆栈顶部指针
/*
High memory
-----------------
| 调用者的 rbp | <- 被调用函数栈帧的起点
-----------------
| 返回地址 (rip) | <- 存储调用函数后的下一条指令地址
-----------------
| 局部变量 |
-----------------
Low memory
*/
};
}
struct coctx { // Coroutine Context
void* regs[14]{}; // 初始化为 0
};
// 将当前寄存器的状态保存到第一个上下文中,然后从第二个上下文中取出寄存器的状态并将其分配给寄存器。
extern "C" void coctx_swap(coctx *, coctx *) asm("coctx_swap");
}