1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2018 The FreeBSD Foundation 5 * All rights reserved. 6 * 7 * This software was developed by Konstantin Belousov <[email protected]> 8 * under sponsorship from the FreeBSD Foundation. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * SUCH DAMAGE. 30 * 31 * $FreeBSD$ 32 */ 33 34#include <machine/asmacros.h> 35#include <machine/cputypes.h> 36#include <machine/pmap.h> 37#include <machine/specialreg.h> 38 39#include "assym.inc" 40 41 .text 42 43ENTRY(copyout_fast) 44 pushl %ebp 45 movl %esp, %ebp 46 pushl %esi 47 pushl %edi 48 pushl %ebx 49 50 movl $copyout_fault,%edx 51 movl 20(%ebp),%ebx /* KCR3 */ 52 53 movl PCPU(CURPCB),%eax 54 movl PCB_CR3(%eax),%edi 55 56 cli 57 movl PCPU(TRAMPSTK),%esi 58 movl PCPU(COPYOUT_BUF),%eax 59 subl $4,%esi 60 movl %eax,(%esi) 61 movl 12(%ebp),%eax /* udaddr */ 62 subl $4,%esi 63 movl %eax,(%esi) 64 movl 16(%ebp),%eax /* len */ 65 subl $4,%esi 66 movl %eax,(%esi) 67 68 subl $4, %esi 69 movl %edi, (%esi) 70 71 movl 8(%ebp),%eax /* kaddr */ 72 subl $4,%esi 73 movl %eax,(%esi) 74 movl PCPU(COPYOUT_BUF),%eax 75 subl $4,%esi 76 movl %eax,(%esi) 77 movl 16(%ebp),%eax /* len */ 78 subl $4,%esi 79 movl %eax,(%esi) 80 81 movl %esp,%eax 82 movl %esi,%esp 83 84 /* bcopy(%esi = kaddr, %edi = PCPU(copyout_buf), %ecx = len) */ 85 popl %ecx 86 popl %edi 87 popl %esi 88 rep; movsb 89 90 popl %edi 91 movl %edi,%cr3 92 93 /* bcopy(%esi = PCPU(copyout_buf), %edi = udaddr, %ecx = len) */ 94 popl %ecx 95 popl %edi 96 popl %esi 97 rep; movsb 98 99 movl %ebx,%cr3 100 movl %eax,%esp 101 sti 102 103 xorl %eax,%eax 104 popl %ebx 105 popl %edi 106 popl %esi 107 leave 108 ret 109END(copyout_fast) 110 111ENTRY(copyin_fast) 112 pushl %ebp 113 movl %esp, %ebp 114 pushl %esi 115 pushl %edi 116 pushl %ebx 117 118 movl $copyout_fault,%edx 119 movl 20(%ebp),%ebx /* KCR3 */ 120 121 movl PCPU(CURPCB),%eax 122 movl PCB_CR3(%eax),%edi 123 124 cli 125 movl PCPU(TRAMPSTK),%esi 126 movl PCPU(COPYOUT_BUF),%eax 127 subl $4,%esi 128 movl %eax,(%esi) 129 movl 12(%ebp),%eax /* kaddr */ 130 subl $4,%esi 131 movl %eax,(%esi) 132 movl 16(%ebp),%eax /* len */ 133 subl $4,%esi 134 movl %eax,(%esi) 135 136 movl 8(%ebp),%eax /* udaddr */ 137 subl $4,%esi 138 movl %eax,(%esi) 139 movl PCPU(COPYOUT_BUF),%eax 140 subl $4,%esi 141 movl %eax,(%esi) 142 movl 16(%ebp),%eax /* len */ 143 subl $4,%esi 144 movl %eax,(%esi) 145 146 movl %esp,%eax 147 movl %esi,%esp 148 movl %edi,%cr3 149 150 /* bcopy(%esi = udaddr, %edi = PCPU(copyout_buf), %ecx = len) */ 151 popl %ecx 152 popl %edi 153 popl %esi 154 rep; movsb 155 156 movl %ebx,%cr3 157 158 /* bcopy(%esi = PCPU(copyout_buf), %edi = kaddr, %ecx = len) */ 159 popl %ecx 160 popl %edi 161 popl %esi 162 rep; movsb 163 164 movl %eax,%esp 165 sti 166 167 xorl %eax,%eax 168 popl %ebx 169 popl %edi 170 popl %esi 171 leave 172 ret 173END(copyin_fast) 174 175 ALIGN_TEXT 176copyout_fault: 177 movl %eax,%esp 178 sti 179 movl $EFAULT,%eax 180 popl %ebx 181 popl %edi 182 popl %esi 183 leave 184 ret 185 186ENTRY(fueword_fast) 187 pushl %ebp 188 movl %esp,%ebp 189 pushl %ebx 190 pushl %esi 191 pushl %edi 192 movl 8(%ebp),%ecx /* from */ 193 movl PCPU(CURPCB),%eax 194 movl PCB_CR3(%eax),%eax 195 movl $fusufault,%edx 196 movl 16(%ebp),%ebx 197 movl %esp,%esi 198 cli 199 movl PCPU(TRAMPSTK),%esp 200 movl %eax,%cr3 201 movl (%ecx),%eax 202 movl %ebx,%cr3 203 movl %esi,%esp 204 sti 205 movl 12(%ebp),%edx 206 movl %eax,(%edx) 207 xorl %eax,%eax 208 popl %edi 209 popl %esi 210 popl %ebx 211 leave 212 ret 213END(fueword_fast) 214 215ENTRY(fuword16_fast) 216 pushl %ebp 217 movl %esp,%ebp 218 pushl %ebx 219 pushl %esi 220 pushl %edi 221 movl 8(%ebp),%ecx /* from */ 222 movl PCPU(CURPCB),%eax 223 movl PCB_CR3(%eax),%eax 224 movl $fusufault,%edx 225 movl 12(%ebp),%ebx 226 movl %esp,%esi 227 cli 228 movl PCPU(TRAMPSTK),%esp 229 movl %eax,%cr3 230 movzwl (%ecx),%eax 231 movl %ebx,%cr3 232 movl %esi,%esp 233 sti 234 popl %edi 235 popl %esi 236 popl %ebx 237 leave 238 ret 239END(fuword16_fast) 240 241ENTRY(fubyte_fast) 242 pushl %ebp 243 movl %esp,%ebp 244 pushl %ebx 245 pushl %esi 246 pushl %edi 247 movl 8(%ebp),%ecx /* from */ 248 movl PCPU(CURPCB),%eax 249 movl PCB_CR3(%eax),%eax 250 movl $fusufault,%edx 251 movl 12(%ebp),%ebx 252 movl %esp,%esi 253 cli 254 movl PCPU(TRAMPSTK),%esp 255 movl %eax,%cr3 256 movzbl (%ecx),%eax 257 movl %ebx,%cr3 258 movl %esi,%esp 259 sti 260 popl %edi 261 popl %esi 262 popl %ebx 263 leave 264 ret 265END(fubyte_fast) 266 267 ALIGN_TEXT 268fusufault: 269 movl %esi,%esp 270 sti 271 xorl %eax,%eax 272 decl %eax 273 popl %edi 274 popl %esi 275 popl %ebx 276 leave 277 ret 278 279ENTRY(suword_fast) 280 pushl %ebp 281 movl %esp,%ebp 282 pushl %ebx 283 pushl %esi 284 pushl %edi 285 movl PCPU(CURPCB),%eax 286 movl PCB_CR3(%eax),%eax 287 movl $fusufault,%edx 288 movl 8(%ebp),%ecx /* to */ 289 movl 12(%ebp),%edi /* val */ 290 movl 16(%ebp),%ebx 291 movl %esp,%esi 292 cli 293 movl PCPU(TRAMPSTK),%esp 294 movl %eax,%cr3 295 movl %edi,(%ecx) 296 movl %ebx,%cr3 297 movl %esi,%esp 298 sti 299 xorl %eax,%eax 300 popl %edi 301 popl %esi 302 popl %ebx 303 leave 304 ret 305END(suword_fast) 306 307ENTRY(suword16_fast) 308 pushl %ebp 309 movl %esp,%ebp 310 pushl %ebx 311 pushl %esi 312 pushl %edi 313 movl PCPU(CURPCB),%eax 314 movl PCB_CR3(%eax),%eax 315 movl $fusufault,%edx 316 movl 8(%ebp),%ecx /* to */ 317 movl 12(%ebp),%edi /* val */ 318 movl 16(%ebp),%ebx 319 movl %esp,%esi 320 cli 321 movl PCPU(TRAMPSTK),%esp 322 movl %eax,%cr3 323 movw %di,(%ecx) 324 movl %ebx,%cr3 325 movl %esi,%esp 326 sti 327 xorl %eax,%eax 328 popl %edi 329 popl %esi 330 popl %ebx 331 leave 332 ret 333END(suword16_fast) 334 335ENTRY(subyte_fast) 336 pushl %ebp 337 movl %esp,%ebp 338 pushl %ebx 339 pushl %esi 340 pushl %edi 341 movl PCPU(CURPCB),%eax 342 movl PCB_CR3(%eax),%eax 343 movl $fusufault,%edx 344 movl 8(%ebp),%ecx /* to */ 345 movl 12(%ebp),%edi /* val */ 346 movl 16(%ebp),%ebx 347 movl %esp,%esi 348 cli 349 movl PCPU(TRAMPSTK),%esp 350 movl %eax,%cr3 351 movl %edi,%eax 352 movb %al,(%ecx) 353 movl %ebx,%cr3 354 movl %esi,%esp 355 sti 356 xorl %eax,%eax 357 popl %edi 358 popl %esi 359 popl %ebx 360 leave 361 ret 362END(subyte_fast) 363