2021-02-08 09:19:00 -08:00
|
|
|
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
|
|
|
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 :vi │
|
2020-06-15 07:18:57 -07:00
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
2021-02-08 09:19:00 -08:00
|
|
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
2020-06-15 07:18:57 -07:00
|
|
|
│ │
|
2020-12-27 17:18:44 -08:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 07:18:57 -07:00
|
|
|
│ │
|
2020-12-27 17:18:44 -08:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 07:18:57 -07:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2021-02-28 23:42:35 -08:00
|
|
|
#include "libc/macros.h"
|
2021-02-08 09:19:00 -08:00
|
|
|
.privileged
|
2020-06-15 07:18:57 -07:00
|
|
|
|
2021-02-08 09:19:00 -08:00
|
|
|
ftrace_hook:
|
2023-05-09 01:56:56 -07:00
|
|
|
#ifdef __x86_64__
|
|
|
|
|
2025-01-02 18:44:07 -08:00
|
|
|
// save argument registers
|
|
|
|
// we save %rax because __gc() takes it as an argument.
|
|
|
|
// we save %r10 because it's used as a syscall argument.
|
2023-07-08 12:04:44 -07:00
|
|
|
|
2023-07-10 04:29:46 -07:00
|
|
|
cmpl $0,__ftrace(%rip)
|
2023-06-06 19:46:56 -07:00
|
|
|
jle 1f
|
|
|
|
push %rbp
|
2021-02-08 09:19:00 -08:00
|
|
|
mov %rsp,%rbp
|
2023-07-08 12:04:44 -07:00
|
|
|
and $-16,%rsp
|
2025-01-02 18:44:07 -08:00
|
|
|
sub $128,%rsp
|
|
|
|
movdqu %xmm0,-0x80(%rbp)
|
|
|
|
movdqu %xmm1,-0x70(%rbp)
|
|
|
|
movdqu %xmm2,-0x60(%rbp)
|
|
|
|
movdqu %xmm3,-0x50(%rbp)
|
|
|
|
movdqu %xmm4,-0x40(%rbp)
|
|
|
|
movdqu %xmm5,-0x30(%rbp)
|
|
|
|
movdqu %xmm6,-0x20(%rbp)
|
|
|
|
movdqu %xmm7,-0x10(%rbp)
|
2021-02-08 09:19:00 -08:00
|
|
|
push %rax
|
2023-07-09 16:52:08 -07:00
|
|
|
push %rcx
|
|
|
|
push %rdx
|
2021-02-08 09:19:00 -08:00
|
|
|
push %rdi
|
|
|
|
push %rsi
|
|
|
|
push %r8
|
|
|
|
push %r9
|
2023-07-08 12:04:44 -07:00
|
|
|
push %r10
|
2021-07-11 23:17:47 -07:00
|
|
|
call ftracer
|
2025-01-02 18:44:07 -08:00
|
|
|
movdqu -0x80(%rbp),%xmm0
|
|
|
|
movdqu -0x70(%rbp),%xmm1
|
|
|
|
movdqu -0x60(%rbp),%xmm2
|
|
|
|
movdqu -0x50(%rbp),%xmm3
|
|
|
|
movdqu -0x40(%rbp),%xmm4
|
|
|
|
movdqu -0x30(%rbp),%xmm5
|
|
|
|
movdqu -0x20(%rbp),%xmm6
|
|
|
|
movdqu -0x10(%rbp),%xmm7
|
2023-07-08 12:04:44 -07:00
|
|
|
pop %r10
|
2021-02-08 09:19:00 -08:00
|
|
|
pop %r9
|
|
|
|
pop %r8
|
|
|
|
pop %rsi
|
|
|
|
pop %rdi
|
2023-07-09 16:52:08 -07:00
|
|
|
pop %rdx
|
|
|
|
pop %rcx
|
2021-02-08 09:19:00 -08:00
|
|
|
pop %rax
|
2023-07-08 12:04:44 -07:00
|
|
|
leave
|
2023-06-06 19:46:56 -07:00
|
|
|
1: ret
|
2023-05-09 01:56:56 -07:00
|
|
|
|
|
|
|
#elif defined(__aarch64__)
|
|
|
|
|
2023-07-09 05:11:25 -07:00
|
|
|
stp x29,x30,[sp,-384]!
|
2023-06-05 23:35:31 -07:00
|
|
|
mov x29,sp
|
|
|
|
stp x0,x1,[sp,16]
|
2023-10-14 20:57:15 -07:00
|
|
|
|
|
|
|
adrp x0,__ftrace
|
|
|
|
ldr w0,[x0,#:lo12:__ftrace]
|
|
|
|
cmp w0,0
|
|
|
|
ble 1f
|
|
|
|
|
2023-06-05 23:35:31 -07:00
|
|
|
stp x2,x3,[sp,32]
|
|
|
|
stp x4,x5,[sp,48]
|
|
|
|
stp x6,x7,[sp,64]
|
2023-07-08 12:04:44 -07:00
|
|
|
stp x8,x9,[sp,80]
|
|
|
|
stp x10,x11,[sp,96]
|
|
|
|
stp x12,x13,[sp,112]
|
|
|
|
stp x14,x15,[sp,128]
|
2023-10-14 20:57:15 -07:00
|
|
|
stp x16,x19,[sp,160]
|
2023-07-08 12:04:44 -07:00
|
|
|
stp x20,x21,[sp,176]
|
|
|
|
stp x22,x23,[sp,192]
|
|
|
|
stp x24,x25,[sp,208]
|
|
|
|
stp x26,x27,[sp,224]
|
2023-10-14 20:57:15 -07:00
|
|
|
stp x17,x28,[sp,240]
|
2023-07-09 05:11:25 -07:00
|
|
|
stp q0,q1,[sp,256]
|
|
|
|
stp q2,q3,[sp,288]
|
|
|
|
stp q4,q5,[sp,320]
|
|
|
|
stp q6,q7,[sp,352]
|
2023-07-08 12:04:44 -07:00
|
|
|
|
2023-05-09 01:56:56 -07:00
|
|
|
bl ftracer
|
2023-07-08 12:04:44 -07:00
|
|
|
|
2023-07-09 05:11:25 -07:00
|
|
|
ldp q6,q7,[sp,352]
|
2023-10-14 20:57:15 -07:00
|
|
|
ldp q4,q5,[sp,320]
|
|
|
|
ldp q2,q3,[sp,288]
|
|
|
|
ldp q0,q1,[sp,256]
|
|
|
|
ldp x17,x28,[sp,240]
|
|
|
|
ldp x26,x27,[sp,224]
|
|
|
|
ldp x24,x25,[sp,208]
|
|
|
|
ldp x22,x23,[sp,192]
|
|
|
|
ldp x20,x21,[sp,176]
|
|
|
|
ldp x16,x19,[sp,160]
|
|
|
|
ldp x14,x15,[sp,128]
|
|
|
|
ldp x12,x13,[sp,112]
|
|
|
|
ldp x10,x11,[sp,96]
|
|
|
|
ldp x8,x9,[sp,80]
|
|
|
|
ldp x6,x7,[sp,64]
|
|
|
|
ldp x4,x5,[sp,48]
|
|
|
|
ldp x2,x3,[sp,32]
|
2023-07-08 12:04:44 -07:00
|
|
|
|
2023-10-14 20:57:15 -07:00
|
|
|
1: ldp x0,x1,[sp,16]
|
2023-07-09 05:11:25 -07:00
|
|
|
ldp x29,x30,[sp],384
|
2023-10-14 20:57:15 -07:00
|
|
|
ret
|
2023-05-09 01:56:56 -07:00
|
|
|
|
|
|
|
#endif /* __x86_64__ */
|
2023-07-23 10:57:18 -07:00
|
|
|
.endfn ftrace_hook,globl,hidden
|