mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
LibJS/JIT: Add Assembler::push() and pop() helpers
This commit is contained in:
parent
acece9057e
commit
10dcb4d53a
Notes:
sideshowbarker
2024-07-17 04:10:16 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/10dcb4d53a Pull-request: https://github.com/SerenityOS/serenity/pull/21619 Reviewed-by: https://github.com/Hendiadyoin1
1 changed files with 38 additions and 27 deletions
|
@ -312,24 +312,40 @@ struct Assembler {
|
|||
emit8(0xc3);
|
||||
}
|
||||
|
||||
void push(Operand op)
|
||||
{
|
||||
if (op.type == Operand::Type::Reg) {
|
||||
if (to_underlying(op.reg) >= 8)
|
||||
emit8(0x49);
|
||||
emit8(0x50 | encode_reg(op.reg));
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void pop(Operand op)
|
||||
{
|
||||
if (op.type == Operand::Type::Reg) {
|
||||
if (to_underlying(op.reg) >= 8)
|
||||
emit8(0x49);
|
||||
emit8(0x58 | encode_reg(op.reg));
|
||||
} else {
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
void native_call(void* callee)
|
||||
{
|
||||
// push caller-saved registers on the stack
|
||||
// (callee-saved registers: RBX, RSP, RBP, and R12–R15)
|
||||
|
||||
// push RCX, RDX, RSI, RDI, R8, R9, R10, R11
|
||||
emit8(0x51);
|
||||
emit8(0x52);
|
||||
emit8(0x56);
|
||||
emit8(0x57);
|
||||
emit8(0x41);
|
||||
emit8(0x50);
|
||||
emit8(0x41);
|
||||
emit8(0x51);
|
||||
emit8(0x41);
|
||||
emit8(0x52);
|
||||
emit8(0x41);
|
||||
emit8(0x53);
|
||||
push(Operand::Register(Reg::RCX));
|
||||
push(Operand::Register(Reg::RDX));
|
||||
push(Operand::Register(Reg::RSI));
|
||||
push(Operand::Register(Reg::RDI));
|
||||
push(Operand::Register(Reg::R8));
|
||||
push(Operand::Register(Reg::R9));
|
||||
push(Operand::Register(Reg::R10));
|
||||
push(Operand::Register(Reg::R11));
|
||||
|
||||
// align the stack to 16-byte boundary
|
||||
emit8(0x48);
|
||||
|
@ -351,19 +367,14 @@ struct Assembler {
|
|||
emit8(0x08);
|
||||
|
||||
// restore caller-saved registers from the stack
|
||||
// pop R11, R10, R9, R8, RDI, RSI, RDX, RCX
|
||||
emit8(0x41);
|
||||
emit8(0x5b);
|
||||
emit8(0x41);
|
||||
emit8(0x5a);
|
||||
emit8(0x41);
|
||||
emit8(0x59);
|
||||
emit8(0x41);
|
||||
emit8(0x58);
|
||||
emit8(0x5f);
|
||||
emit8(0x5e);
|
||||
emit8(0x5a);
|
||||
emit8(0x59);
|
||||
pop(Operand::Register(Reg::R11));
|
||||
pop(Operand::Register(Reg::R10));
|
||||
pop(Operand::Register(Reg::R9));
|
||||
pop(Operand::Register(Reg::R8));
|
||||
pop(Operand::Register(Reg::RDI));
|
||||
pop(Operand::Register(Reg::RSI));
|
||||
pop(Operand::Register(Reg::RDX));
|
||||
pop(Operand::Register(Reg::RCX));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue