xref: /f-stack/freebsd/amd64/linux/linux_support.s (revision 22ce4aff)
1a9643ea8Slogwang/*-
2*22ce4affSfengbojiang * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*22ce4affSfengbojiang *
4a9643ea8Slogwang * Copyright (c) 2007 Konstantin Belousov
5a9643ea8Slogwang * All rights reserved.
6a9643ea8Slogwang *
7a9643ea8Slogwang * Redistribution and use in source and binary forms, with or without
8a9643ea8Slogwang * modification, are permitted provided that the following conditions
9a9643ea8Slogwang * are met:
10a9643ea8Slogwang * 1. Redistributions of source code must retain the above copyright
11a9643ea8Slogwang *    notice, this list of conditions and the following disclaimer.
12a9643ea8Slogwang * 2. Redistributions in binary form must reproduce the above copyright
13a9643ea8Slogwang *    notice, this list of conditions and the following disclaimer in the
14a9643ea8Slogwang *    documentation and/or other materials provided with the distribution.
15a9643ea8Slogwang *
16*22ce4affSfengbojiang * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17a9643ea8Slogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18a9643ea8Slogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*22ce4affSfengbojiang * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20a9643ea8Slogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21a9643ea8Slogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22a9643ea8Slogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23a9643ea8Slogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24a9643ea8Slogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25a9643ea8Slogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26a9643ea8Slogwang * SUCH DAMAGE.
27a9643ea8Slogwang *
28a9643ea8Slogwang * $FreeBSD$
29a9643ea8Slogwang */
30a9643ea8Slogwang
31a9643ea8Slogwang#include "linux_assym.h"		/* system definitions */
32a9643ea8Slogwang#include <machine/asmacros.h>		/* miscellaneous asm macros */
33*22ce4affSfengbojiang#include <machine/specialreg.h>
34a9643ea8Slogwang
35*22ce4affSfengbojiang#include "assym.inc"
36a9643ea8Slogwang
37a9643ea8Slogwangfutex_fault:
38*22ce4affSfengbojiang	testl	$CPUID_STDEXT_SMAP,cpu_stdext_feature(%rip)
39*22ce4affSfengbojiang	je	1f
40*22ce4affSfengbojiang	clac
41*22ce4affSfengbojiang1:	movq	$0,PCB_ONFAULT(%r8)
42a9643ea8Slogwang	movl	$-EFAULT,%eax
43a9643ea8Slogwang	ret
44a9643ea8Slogwang
45*22ce4affSfengbojiangENTRY(futex_xchgl_nosmap)
46a9643ea8Slogwang	movq	PCPU(CURPCB),%r8
47a9643ea8Slogwang	movq	$futex_fault,PCB_ONFAULT(%r8)
48a9643ea8Slogwang	movq	$VM_MAXUSER_ADDRESS-4,%rax
49a9643ea8Slogwang	cmpq	%rax,%rsi
50a9643ea8Slogwang	ja	futex_fault
51a9643ea8Slogwang	xchgl	%edi,(%rsi)
52a9643ea8Slogwang	movl	%edi,(%rdx)
53a9643ea8Slogwang	xorl	%eax,%eax
54a9643ea8Slogwang	movq	%rax,PCB_ONFAULT(%r8)
55a9643ea8Slogwang	ret
56*22ce4affSfengbojiangEND(futex_xchgl_nosmap)
57a9643ea8Slogwang
58*22ce4affSfengbojiangENTRY(futex_xchgl_smap)
59*22ce4affSfengbojiang	movq	PCPU(CURPCB),%r8
60*22ce4affSfengbojiang	movq	$futex_fault,PCB_ONFAULT(%r8)
61*22ce4affSfengbojiang	movq	$VM_MAXUSER_ADDRESS-4,%rax
62*22ce4affSfengbojiang	cmpq	%rax,%rsi
63*22ce4affSfengbojiang	ja	futex_fault
64*22ce4affSfengbojiang	stac
65*22ce4affSfengbojiang	xchgl	%edi,(%rsi)
66*22ce4affSfengbojiang	clac
67*22ce4affSfengbojiang	movl	%edi,(%rdx)
68*22ce4affSfengbojiang	xorl	%eax,%eax
69*22ce4affSfengbojiang	movq	%rax,PCB_ONFAULT(%r8)
70*22ce4affSfengbojiang	ret
71*22ce4affSfengbojiangEND(futex_xchgl_smap)
72*22ce4affSfengbojiang
73*22ce4affSfengbojiangENTRY(futex_addl_nosmap)
74a9643ea8Slogwang	movq	PCPU(CURPCB),%r8
75a9643ea8Slogwang	movq	$futex_fault,PCB_ONFAULT(%r8)
76a9643ea8Slogwang	movq	$VM_MAXUSER_ADDRESS-4,%rax
77a9643ea8Slogwang	cmpq	%rax,%rsi
78a9643ea8Slogwang	ja	futex_fault
79a9643ea8Slogwang#ifdef SMP
80a9643ea8Slogwang	lock
81a9643ea8Slogwang#endif
82a9643ea8Slogwang	xaddl	%edi,(%rsi)
83a9643ea8Slogwang	movl	%edi,(%rdx)
84a9643ea8Slogwang	xorl	%eax,%eax
85a9643ea8Slogwang	movq	%rax,PCB_ONFAULT(%r8)
86a9643ea8Slogwang	ret
87*22ce4affSfengbojiangEND(futex_addl_nosmap)
88a9643ea8Slogwang
89*22ce4affSfengbojiangENTRY(futex_addl_smap)
90*22ce4affSfengbojiang	movq	PCPU(CURPCB),%r8
91*22ce4affSfengbojiang	movq	$futex_fault,PCB_ONFAULT(%r8)
92*22ce4affSfengbojiang	movq	$VM_MAXUSER_ADDRESS-4,%rax
93*22ce4affSfengbojiang	cmpq	%rax,%rsi
94*22ce4affSfengbojiang	ja	futex_fault
95*22ce4affSfengbojiang	stac
96*22ce4affSfengbojiang#ifdef SMP
97*22ce4affSfengbojiang	lock
98*22ce4affSfengbojiang#endif
99*22ce4affSfengbojiang	xaddl	%edi,(%rsi)
100*22ce4affSfengbojiang	clac
101*22ce4affSfengbojiang	movl	%edi,(%rdx)
102*22ce4affSfengbojiang	xorl	%eax,%eax
103*22ce4affSfengbojiang	movq	%rax,PCB_ONFAULT(%r8)
104*22ce4affSfengbojiang	ret
105*22ce4affSfengbojiangEND(futex_addl_smap)
106*22ce4affSfengbojiang
107*22ce4affSfengbojiangENTRY(futex_orl_nosmap)
108a9643ea8Slogwang	movq	PCPU(CURPCB),%r8
109a9643ea8Slogwang	movq	$futex_fault,PCB_ONFAULT(%r8)
110a9643ea8Slogwang	movq	$VM_MAXUSER_ADDRESS-4,%rax
111a9643ea8Slogwang	cmpq	%rax,%rsi
112a9643ea8Slogwang	ja	futex_fault
113a9643ea8Slogwang	movl	(%rsi),%eax
114a9643ea8Slogwang1:	movl	%eax,%ecx
115a9643ea8Slogwang	orl	%edi,%ecx
116a9643ea8Slogwang#ifdef SMP
117a9643ea8Slogwang	lock
118a9643ea8Slogwang#endif
119a9643ea8Slogwang	cmpxchgl %ecx,(%rsi)
120a9643ea8Slogwang	jnz	1b
121a9643ea8Slogwang	movl	%eax,(%rdx)
122a9643ea8Slogwang	xorl	%eax,%eax
123a9643ea8Slogwang	movq	%rax,PCB_ONFAULT(%r8)
124a9643ea8Slogwang	ret
125*22ce4affSfengbojiangEND(futex_orl_nosmap)
126a9643ea8Slogwang
127*22ce4affSfengbojiangENTRY(futex_orl_smap)
128*22ce4affSfengbojiang	movq	PCPU(CURPCB),%r8
129*22ce4affSfengbojiang	movq	$futex_fault,PCB_ONFAULT(%r8)
130*22ce4affSfengbojiang	movq	$VM_MAXUSER_ADDRESS-4,%rax
131*22ce4affSfengbojiang	cmpq	%rax,%rsi
132*22ce4affSfengbojiang	ja	futex_fault
133*22ce4affSfengbojiang	movl	(%rsi),%eax
134*22ce4affSfengbojiang1:	movl	%eax,%ecx
135*22ce4affSfengbojiang	orl	%edi,%ecx
136*22ce4affSfengbojiang	stac
137*22ce4affSfengbojiang#ifdef SMP
138*22ce4affSfengbojiang	lock
139*22ce4affSfengbojiang#endif
140*22ce4affSfengbojiang	cmpxchgl %ecx,(%rsi)
141*22ce4affSfengbojiang	clac
142*22ce4affSfengbojiang	jnz	1b
143*22ce4affSfengbojiang	movl	%eax,(%rdx)
144*22ce4affSfengbojiang	xorl	%eax,%eax
145*22ce4affSfengbojiang	movq	%rax,PCB_ONFAULT(%r8)
146*22ce4affSfengbojiang	ret
147*22ce4affSfengbojiangEND(futex_orl_smap)
148*22ce4affSfengbojiang
149*22ce4affSfengbojiangENTRY(futex_andl_nosmap)
150a9643ea8Slogwang	movq	PCPU(CURPCB),%r8
151a9643ea8Slogwang	movq	$futex_fault,PCB_ONFAULT(%r8)
152a9643ea8Slogwang	movq	$VM_MAXUSER_ADDRESS-4,%rax
153a9643ea8Slogwang	cmpq	%rax,%rsi
154a9643ea8Slogwang	ja	futex_fault
155a9643ea8Slogwang	movl	(%rsi),%eax
156a9643ea8Slogwang1:	movl	%eax,%ecx
157a9643ea8Slogwang	andl	%edi,%ecx
158a9643ea8Slogwang#ifdef SMP
159a9643ea8Slogwang	lock
160a9643ea8Slogwang#endif
161a9643ea8Slogwang	cmpxchgl %ecx,(%rsi)
162a9643ea8Slogwang	jnz	1b
163a9643ea8Slogwang	movl	%eax,(%rdx)
164a9643ea8Slogwang	xorl	%eax,%eax
165a9643ea8Slogwang	movq	%rax,PCB_ONFAULT(%r8)
166a9643ea8Slogwang	ret
167*22ce4affSfengbojiangEND(futex_andl_nosmap)
168a9643ea8Slogwang
169*22ce4affSfengbojiangENTRY(futex_andl_smap)
170*22ce4affSfengbojiang	movq	PCPU(CURPCB),%r8
171*22ce4affSfengbojiang	movq	$futex_fault,PCB_ONFAULT(%r8)
172*22ce4affSfengbojiang	movq	$VM_MAXUSER_ADDRESS-4,%rax
173*22ce4affSfengbojiang	cmpq	%rax,%rsi
174*22ce4affSfengbojiang	ja	futex_fault
175*22ce4affSfengbojiang	movl	(%rsi),%eax
176*22ce4affSfengbojiang1:	movl	%eax,%ecx
177*22ce4affSfengbojiang	andl	%edi,%ecx
178*22ce4affSfengbojiang	stac
179*22ce4affSfengbojiang#ifdef SMP
180*22ce4affSfengbojiang	lock
181*22ce4affSfengbojiang#endif
182*22ce4affSfengbojiang	cmpxchgl %ecx,(%rsi)
183*22ce4affSfengbojiang	clac
184*22ce4affSfengbojiang	jnz	1b
185*22ce4affSfengbojiang	movl	%eax,(%rdx)
186*22ce4affSfengbojiang	xorl	%eax,%eax
187*22ce4affSfengbojiang	movq	%rax,PCB_ONFAULT(%r8)
188*22ce4affSfengbojiang	ret
189*22ce4affSfengbojiangEND(futex_andl_smap)
190*22ce4affSfengbojiang
191*22ce4affSfengbojiangENTRY(futex_xorl_nosmap)
192a9643ea8Slogwang	movq	PCPU(CURPCB),%r8
193a9643ea8Slogwang	movq	$futex_fault,PCB_ONFAULT(%r8)
194a9643ea8Slogwang	movq	$VM_MAXUSER_ADDRESS-4,%rax
195a9643ea8Slogwang	cmpq	%rax,%rsi
196a9643ea8Slogwang	ja	futex_fault
197a9643ea8Slogwang	movl	(%rsi),%eax
198a9643ea8Slogwang1:	movl	%eax,%ecx
199a9643ea8Slogwang	xorl	%edi,%ecx
200a9643ea8Slogwang#ifdef SMP
201a9643ea8Slogwang	lock
202a9643ea8Slogwang#endif
203a9643ea8Slogwang	cmpxchgl %ecx,(%rsi)
204a9643ea8Slogwang	jnz	1b
205a9643ea8Slogwang	movl	%eax,(%rdx)
206a9643ea8Slogwang	xorl	%eax,%eax
207a9643ea8Slogwang	movq	%rax,PCB_ONFAULT(%r8)
208a9643ea8Slogwang	ret
209*22ce4affSfengbojiangEND(futex_xorl_nosmap)
210*22ce4affSfengbojiang
211*22ce4affSfengbojiangENTRY(futex_xorl_smap)
212*22ce4affSfengbojiang	movq	PCPU(CURPCB),%r8
213*22ce4affSfengbojiang	movq	$futex_fault,PCB_ONFAULT(%r8)
214*22ce4affSfengbojiang	movq	$VM_MAXUSER_ADDRESS-4,%rax
215*22ce4affSfengbojiang	cmpq	%rax,%rsi
216*22ce4affSfengbojiang	ja	futex_fault
217*22ce4affSfengbojiang	movl	(%rsi),%eax
218*22ce4affSfengbojiang1:	movl	%eax,%ecx
219*22ce4affSfengbojiang	xorl	%edi,%ecx
220*22ce4affSfengbojiang	stac
221*22ce4affSfengbojiang#ifdef SMP
222*22ce4affSfengbojiang	lock
223*22ce4affSfengbojiang#endif
224*22ce4affSfengbojiang	cmpxchgl %ecx,(%rsi)
225*22ce4affSfengbojiang	clac
226*22ce4affSfengbojiang	jnz	1b
227*22ce4affSfengbojiang	movl	%eax,(%rdx)
228*22ce4affSfengbojiang	xorl	%eax,%eax
229*22ce4affSfengbojiang	movq	%rax,PCB_ONFAULT(%r8)
230*22ce4affSfengbojiang	ret
231*22ce4affSfengbojiangEND(futex_xorl_smap)
232