0bf33e679a0ca6747f5b44a2095f9c3c37f63cf1
[dragonfly.git] / sys / emulation / linux / i386 / linux_support.s
1 /*-
2  * Copyright (c) 2006,2007 Konstantin Belousov
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 4. Neither the name of the University nor the names of its contributors
14  *    may be used to endorse or promote products derived from this software
15  *    without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31
32 #include "linux_assym.h"                /* system definitions */
33 #include <machine/asmacros.h>           /* miscellaneous asm macros */
34 #include <machine/cputypes.h>
35 #include <machine/pmap.h>
36 #include <machine/specialreg.h>
37
38 #include "assym.s"
39
40 /*
41  * A stack-based on-fault routine is used for more complex PCB_ONFAULT
42  * situations (such as memcpy/bcopy/bzero).  In this case the on-fault
43  * routine must be pushed on the stack.
44  */
45 stack_onfault:
46         ret
47
48 futex_fault_decx:
49         movl    PCPU(curthread),%ecx
50         movl    TD_PCB(%ecx), %ecx
51 futex_fault:
52         movl    $0,PCB_ONFAULT(%ecx)
53         movl    $EFAULT,%eax
54         ret
55
56 futex_fault_pop:
57         addl    $4,%esp
58         movl    $0,PCB_ONFAULT(%ecx)
59         movl    $EFAULT,%eax
60         ret
61
62 ENTRY(futex_xchgl)
63         movl    PCPU(curthread),%ecx
64         movl    TD_PCB(%ecx),%ecx
65         pushl   $futex_fault
66         movl    $stack_onfault, PCB_ONFAULT(%ecx)
67         movl    8(%esp),%eax
68         movl    12(%esp),%edx
69         cmpl    $VM_MAX_USER_ADDRESS-4,%edx
70         ja      futex_fault_pop
71         xchgl   %eax,(%edx)
72         movl    16(%esp),%edx
73         movl    %eax,(%edx)
74         xorl    %eax,%eax
75         movl    %eax,PCB_ONFAULT(%ecx)
76         ret
77
78 ENTRY(futex_addl)
79         movl    PCPU(curthread),%ecx
80         movl    TD_PCB(%ecx),%ecx
81         pushl   $futex_fault
82         movl    $stack_onfault,PCB_ONFAULT(%ecx)
83         movl    8(%esp),%eax
84         movl    12(%esp),%edx
85         cmpl    $VM_MAX_USER_ADDRESS-4,%edx
86         ja      futex_fault_pop
87 #ifdef SMP
88         lock
89 #endif
90         xaddl   %eax,(%edx)
91         movl    16(%esp),%edx
92         movl    %eax,(%edx)
93         xorl    %eax,%eax
94         movl    %eax,PCB_ONFAULT(%ecx)
95         ret
96
97 ENTRY(futex_orl)
98         movl    PCPU(curthread),%ecx
99         movl    TD_PCB(%ecx),%ecx
100         pushl   $futex_fault_decx
101         movl    $stack_onfault,PCB_ONFAULT(%ecx)
102         movl    12(%esp),%edx
103         cmpl    $VM_MAX_USER_ADDRESS-4,%edx
104         ja      futex_fault_pop
105         movl    (%edx),%eax
106 1:      movl    %eax,%ecx
107         orl     8(%esp),%ecx
108 #ifdef SMP
109         lock
110 #endif
111         cmpxchgl %ecx,(%edx)
112         jnz     1b
113 futex_tail:
114         movl    16(%esp),%edx
115         movl    %eax,(%edx)
116         xorl    %eax,%eax
117         movl    PCPU(curthread),%ecx
118         movl    %eax,PCB_ONFAULT(%ecx)
119         ret
120
121 ENTRY(futex_andl)
122         movl    PCPU(curthread),%ecx
123         movl    TD_PCB(%ecx),%ecx
124         pushl   $futex_fault_decx
125         movl    $stack_onfault,PCB_ONFAULT(%ecx)
126         movl    12(%esp),%edx
127         cmpl    $VM_MAX_USER_ADDRESS-4,%edx
128         ja      futex_fault_pop
129         movl    (%edx),%eax
130 1:      movl    %eax,%ecx
131         andl    8(%esp),%ecx
132 #ifdef SMP
133         lock
134 #endif
135         cmpxchgl %ecx,(%edx)
136         jnz     1b
137         jmp     futex_tail
138
139 ENTRY(futex_xorl)
140         movl    PCPU(curthread),%ecx
141         movl    TD_PCB(%ecx),%ecx
142         pushl   $futex_fault_decx
143         movl    $stack_onfault,PCB_ONFAULT(%ecx)
144         movl    12(%esp),%edx
145         cmpl    $VM_MAX_USER_ADDRESS-4,%edx
146         ja      futex_fault_pop
147         movl    (%edx),%eax
148 1:      movl    %eax,%ecx
149         xorl    8(%esp),%ecx
150 #ifdef SMP
151         lock
152 #endif
153         cmpxchgl %ecx,(%edx)
154         jnz     1b
155         jmp     futex_tail