|
| 1 | +/* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | +/* |
| 3 | + * Dynamic Tracing for Linux - x86 specific assembly |
| 4 | + * |
| 5 | + * Copyright (c) 2010, 2017, Oracle and/or its affiliates. All rights reserved. |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + */ |
| 17 | + |
| 18 | +#include <linux/linkage.h> |
| 19 | +#include <asm/smap.h> |
| 20 | + |
| 21 | +#define CPU_DTRACE_BADADDR 0x0004 /* DTrace fault: bad address */ |
| 22 | + |
| 23 | +#if defined(__x86_64__) |
| 24 | + ENTRY(dtrace_caller) |
| 25 | + movq $-1, %rax |
| 26 | + ret |
| 27 | + ENDPROC(dtrace_caller) |
| 28 | + |
| 29 | +#elif defined(__i386__) |
| 30 | + |
| 31 | + ENTRY(dtrace_caller) |
| 32 | + movl $-1, %eax |
| 33 | + ret |
| 34 | + ENDPROC(dtrace_caller) |
| 35 | + |
| 36 | +#endif /* __i386__ */ |
| 37 | + |
| 38 | +#if defined(__x86_64__) |
| 39 | + |
| 40 | + ENTRY(dtrace_copy) |
| 41 | + pushq %rbp |
| 42 | + movq %rsp, %rbp |
| 43 | + |
| 44 | + ASM_STAC |
| 45 | + xchgq %rdi, %rsi # make %rsi source, %rdi dest |
| 46 | + movq %rdx, %rcx # load count |
| 47 | + repz # repeat for count ... |
| 48 | + smovb # move from %ds:rsi to %ed:rdi |
| 49 | + ASM_CLAC |
| 50 | + leave |
| 51 | + ret |
| 52 | + ENDPROC(dtrace_copy) |
| 53 | + |
| 54 | +#elif defined(__i386__) |
| 55 | + |
| 56 | + ENTRY(dtrace_copy) |
| 57 | + pushl %ebp |
| 58 | + movl %esp, %ebp |
| 59 | + pushl %esi |
| 60 | + pushl %edi |
| 61 | + |
| 62 | + movl 8(%ebp), %esi # Load source address |
| 63 | + movl 12(%ebp), %edi # Load destination address |
| 64 | + movl 16(%ebp), %ecx # Load count |
| 65 | + repz # Repeat for count... |
| 66 | + smovb # move from %ds:si to %es:di |
| 67 | + |
| 68 | + popl %edi |
| 69 | + popl %esi |
| 70 | + movl %ebp, %esp |
| 71 | + popl %ebp |
| 72 | + ret |
| 73 | + ENDPROC(dtrace_copy) |
| 74 | + |
| 75 | +#endif /* __i386__ */ |
| 76 | + |
| 77 | +#if defined(__x86_64__) |
| 78 | + |
| 79 | + ENTRY(dtrace_copystr) |
| 80 | + pushq %rbp |
| 81 | + movq %rsp, %rbp |
| 82 | + |
| 83 | + ASM_STAC |
| 84 | +0: |
| 85 | + movb (%rdi), %al # load from source |
| 86 | + movb %al, (%rsi) # store to destination |
| 87 | + addq $1, %rdi # increment source pointer |
| 88 | + addq $1, %rsi # increment destination pointer |
| 89 | + subq $1, %rdx # decrement remaining count |
| 90 | + cmpb $0, %al |
| 91 | + je 2f |
| 92 | + testq $0xfff, %rdx # test if count is 4k-aligned |
| 93 | + jnz 1f # if not, continue with copying |
| 94 | + testq $CPU_DTRACE_BADADDR, (%rcx) # load and test dtrace flags |
| 95 | + jnz 2f |
| 96 | +1: |
| 97 | + cmpq $0, %rdx |
| 98 | + jne 0b |
| 99 | +2: |
| 100 | + ASM_CLAC |
| 101 | + leave |
| 102 | + ret |
| 103 | + |
| 104 | + ENDPROC(dtrace_copystr) |
| 105 | + |
| 106 | +#elif defined(__i386__) |
| 107 | + |
| 108 | + ENTRY(dtrace_copystr) |
| 109 | + |
| 110 | + pushl %ebp # Setup stack frame |
| 111 | + movl %esp, %ebp |
| 112 | + pushl %ebx # Save registers |
| 113 | + |
| 114 | + movl 8(%ebp), %ebx # Load source address |
| 115 | + movl 12(%ebp), %edx # Load destination address |
| 116 | + movl 16(%ebp), %ecx # Load count |
| 117 | + |
| 118 | +0: |
| 119 | + movb (%ebx), %al # Load from source |
| 120 | + movb %al, (%edx) # Store to destination |
| 121 | + incl %ebx # Increment source pointer |
| 122 | + incl %edx # Increment destination pointer |
| 123 | + decl %ecx # Decrement remaining count |
| 124 | + cmpb $0, %al |
| 125 | + je 2f |
| 126 | + testl $0xfff, %ecx # Check if count is 4k-aligned |
| 127 | + jnz 1f |
| 128 | + movl 20(%ebp), %eax # load flags pointer |
| 129 | + testl $CPU_DTRACE_BADADDR, (%eax) # load and test dtrace flags |
| 130 | + jnz 2f |
| 131 | +1: |
| 132 | + cmpl $0, %ecx |
| 133 | + jne 0b |
| 134 | + |
| 135 | +2: |
| 136 | + popl %ebx |
| 137 | + movl %ebp, %esp |
| 138 | + popl %ebp |
| 139 | + ret |
| 140 | + |
| 141 | + ENDPROC(dtrace_copystr) |
| 142 | + |
| 143 | +#endif /* __i386__ */ |
| 144 | + |
| 145 | +#if defined(__x86_64__) |
| 146 | + |
| 147 | + ENTRY(dtrace_fuword8_nocheck) |
| 148 | + xorq %rax, %rax |
| 149 | + ASM_STAC |
| 150 | + movb (%rdi), %al |
| 151 | + ASM_CLAC |
| 152 | + ret |
| 153 | + ENDPROC(dtrace_fuword8_nocheck) |
| 154 | + |
| 155 | +#elif defined(__i386__) |
| 156 | + |
| 157 | + ENTRY(dtrace_fuword8_nocheck) |
| 158 | + movl 4(%esp), %ecx |
| 159 | + xorl %eax, %eax |
| 160 | + movzbl (%ecx), %eax |
| 161 | + ret |
| 162 | + ENDPROC(dtrace_fuword8_nocheck) |
| 163 | + |
| 164 | +#endif /* __i386__ */ |
| 165 | + |
| 166 | +#if defined(__x86_64__) |
| 167 | + |
| 168 | + ENTRY(dtrace_fuword16_nocheck) |
| 169 | + xorq %rax, %rax |
| 170 | + ASM_STAC |
| 171 | + movw (%rdi), %ax |
| 172 | + ASM_CLAC |
| 173 | + ret |
| 174 | + ENDPROC(dtrace_fuword16_nocheck) |
| 175 | + |
| 176 | +#elif defined(__i386__) |
| 177 | + |
| 178 | + ENTRY(dtrace_fuword16_nocheck) |
| 179 | + movl 4(%esp), %ecx |
| 180 | + xorl %eax, %eax |
| 181 | + movzwl (%ecx), %eax |
| 182 | + ret |
| 183 | + ENDPROC(dtrace_fuword16_nocheck) |
| 184 | + |
| 185 | +#endif /* __i386__ */ |
| 186 | + |
| 187 | +#if defined(__x86_64__) |
| 188 | + |
| 189 | + ENTRY(dtrace_fuword32_nocheck) |
| 190 | + xorq %rax, %rax |
| 191 | + ASM_STAC |
| 192 | + movl (%rdi), %eax |
| 193 | + ASM_CLAC |
| 194 | + ret |
| 195 | + ENDPROC(dtrace_fuword32_nocheck) |
| 196 | + |
| 197 | +#elif defined(__i386__) |
| 198 | + |
| 199 | + ENTRY(dtrace_fuword32_nocheck) |
| 200 | + movl 4(%esp), %ecx |
| 201 | + xorl %eax, %eax |
| 202 | + movl (%ecx), %eax |
| 203 | + ret |
| 204 | + ENDPROC(dtrace_fuword32_nocheck) |
| 205 | + |
| 206 | +#endif /* __i386__ */ |
| 207 | + |
| 208 | +#if defined(__x86_64__) |
| 209 | + |
| 210 | + ENTRY(dtrace_fuword64_nocheck) |
| 211 | + ASM_STAC |
| 212 | + movq (%rdi), %rax |
| 213 | + ASM_CLAC |
| 214 | + ret |
| 215 | + ENDPROC(dtrace_fuword64_nocheck) |
| 216 | + |
| 217 | +#elif defined(__i386__) |
| 218 | + |
| 219 | + ENTRY(dtrace_fuword64_nocheck) |
| 220 | + movl 4(%esp), %ecx |
| 221 | + xorl %eax, %eax |
| 222 | + xorl %edx, %edx |
| 223 | + movl (%ecx), %eax |
| 224 | + movl 4(%ecx), %edx |
| 225 | + ret |
| 226 | + ENDPROC(dtrace_fuword64_nocheck) |
| 227 | + |
| 228 | +#endif /* __i386__ */ |
0 commit comments