diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-26 12:56:51 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-26 12:56:59 -0300 |
| commit | b7b08a7d29d84de187dd8a55e0c94de66b07a572 (patch) | |
| tree | 7e55661d3eca3cf3b16aada6e87eabee68802fb9 /tests/abi_probe.S | |
| download | asm-b7b08a7d29d84de187dd8a55e0c94de66b07a572.tar.gz | |
Initial importv0.1.0
Diffstat (limited to 'tests/abi_probe.S')
| -rw-r--r-- | tests/abi_probe.S | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/tests/abi_probe.S b/tests/abi_probe.S new file mode 100644 index 0000000..0e07ec4 --- /dev/null +++ b/tests/abi_probe.S @@ -0,0 +1,102 @@ +/* + * cepis_abi_probe(fn, a0, a1, a2, a3) + * + * Calls fn(a0, a1, a2, a3) with every callee-saved register holding a + * distinctive sentinel and returns a bitmask of the ones it came back + * clobbered, plus bits for a moved stack pointer and a left-over direction + * flag. 0 means the callee honoured the System V AMD64 ABI. + * + * Not part of the library: this file is only linked into the test driver. + */ + + .text + .globl cepis_abi_probe + .type cepis_abi_probe, @function + .p2align 4 +cepis_abi_probe: + push %rbp + mov %rsp, %rbp + push %rbx + push %r12 + push %r13 + push %r14 + push %r15 + sub $8, %rsp + mov %rbp, cepis__probe_bp(%rip) + mov %rsp, cepis__probe_sp(%rip) + mov %rdi, %rax + mov %rsi, %rdi + mov %rdx, %rsi + mov %rcx, %rdx + mov %r8, %rcx + movabs $0x1111111111111111, %rbx + movabs $0x2222222222222222, %r12 + movabs $0x3333333333333333, %r13 + movabs $0x4444444444444444, %r14 + movabs $0x5555555555555555, %r15 + movabs $0x6666666666666666, %rbp + call *%rax + xor %r8d, %r8d + movabs $0x1111111111111111, %r9 + cmp %r9, %rbx + je .Lp_r12 + or $1, %r8d +.Lp_r12: + movabs $0x2222222222222222, %r9 + cmp %r9, %r12 + je .Lp_r13 + or $2, %r8d +.Lp_r13: + movabs $0x3333333333333333, %r9 + cmp %r9, %r13 + je .Lp_r14 + or $4, %r8d +.Lp_r14: + movabs $0x4444444444444444, %r9 + cmp %r9, %r14 + je .Lp_r15 + or $8, %r8d +.Lp_r15: + movabs $0x5555555555555555, %r9 + cmp %r9, %r15 + je .Lp_rbp + or $16, %r8d +.Lp_rbp: + movabs $0x6666666666666666, %r9 + cmp %r9, %rbp + je .Lp_sp + or $32, %r8d +.Lp_sp: + mov cepis__probe_sp(%rip), %r9 + cmp %r9, %rsp + je .Lp_df + or $64, %r8d + mov %r9, %rsp +.Lp_df: + pushfq + pop %r9 + test $0x400, %r9d + jz .Lp_done + or $128, %r8d + cld +.Lp_done: + mov cepis__probe_bp(%rip), %rbp + mov %r8d, %eax + lea -40(%rbp), %rsp + pop %r15 + pop %r14 + pop %r13 + pop %r12 + pop %rbx + pop %rbp + ret + .size cepis_abi_probe, . - cepis_abi_probe + + .data + .p2align 3 +cepis__probe_bp: + .quad 0 +cepis__probe_sp: + .quad 0 + + .section .note.GNU-stack,"",@progbits |