xref: /titanic_52/usr/src/uts/intel/dtrace/dtrace_asm.s (revision f63f7506be0210195779706f51c58646e568cc40)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License").  You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22/*
23 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident	"%Z%%M%	%I%	%E% SMI"
28
29#include <sys/asm_linkage.h>
30#include <sys/regset.h>
31
32#if defined(lint)
33#include <sys/dtrace_impl.h>
34#endif
35
36#if defined(lint) || defined(__lint)
37
38greg_t
39dtrace_getfp(void)
40{ return (0); }
41
42#else	/* lint */
43
44#if defined(__amd64)
45
46	ENTRY_NP(dtrace_getfp)
47	movq	%rbp, %rax
48	ret
49	SET_SIZE(dtrace_getfp)
50
51#elif defined(__i386)
52
53	ENTRY_NP(dtrace_getfp)
54	movl	%ebp, %eax
55	ret
56	SET_SIZE(dtrace_getfp)
57
58#endif	/* __i386 */
59#endif	/* lint */
60
61
62#if defined(lint) || defined(__lint)
63
64uint32_t
65dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
66{
67	uint32_t old;
68
69	if ((old = *target) == cmp)
70		*target = new;
71	return (old);
72}
73
74void *
75dtrace_casptr(void *target, void *cmp, void *new)
76{
77	void *old;
78
79	if ((old = *(void **)target) == cmp)
80		*(void **)target = new;
81	return (old);
82}
83
84#else	/* lint */
85
86#if defined(__amd64)
87
88	ENTRY(dtrace_cas32)
89	movl	%esi, %eax
90	lock
91	cmpxchgl %edx, (%rdi)
92	ret
93	SET_SIZE(dtrace_cas32)
94
95	ENTRY(dtrace_casptr)
96	movq	%rsi, %rax
97	lock
98	cmpxchgq %rdx, (%rdi)
99	ret
100	SET_SIZE(dtrace_casptr)
101
102#elif defined(__i386)
103
104	ENTRY(dtrace_cas32)
105	ALTENTRY(dtrace_casptr)
106	movl	4(%esp), %edx
107	movl	8(%esp), %eax
108	movl	12(%esp), %ecx
109	lock
110	cmpxchgl %ecx, (%edx)
111	ret
112	SET_SIZE(dtrace_casptr)
113	SET_SIZE(dtrace_cas32)
114
115#endif	/* __i386 */
116#endif	/* lint */
117
118#if defined(lint)
119
120/*ARGSUSED*/
121uintptr_t
122dtrace_caller(int aframes)
123{
124	return (0);
125}
126
127#else	/* lint */
128
129#if defined(__amd64)
130	ENTRY(dtrace_caller)
131	movq	$-1, %rax
132	ret
133	SET_SIZE(dtrace_caller)
134
135#elif defined(__i386)
136
137	ENTRY(dtrace_caller)
138	movl	$-1, %eax
139	ret
140	SET_SIZE(dtrace_caller)
141
142#endif	/* __i386 */
143#endif	/* lint */
144
145#if defined(lint)
146
147/*ARGSUSED*/
148void
149dtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
150{}
151
152#else
153
154#if defined(__amd64)
155
156	ENTRY(dtrace_copy)
157	pushq	%rbp
158	movq	%rsp, %rbp
159
160	xchgq	%rdi, %rsi		/* make %rsi source, %rdi dest */
161	movq	%rdx, %rcx		/* load count */
162	repz				/* repeat for count ... */
163	smovb				/*   move from %ds:rsi to %ed:rdi */
164	leave
165	ret
166	SET_SIZE(dtrace_copy)
167
168#elif defined(__i386)
169
170	ENTRY(dtrace_copy)
171	pushl	%ebp
172	movl	%esp, %ebp
173	pushl	%esi
174	pushl	%edi
175
176	movl	8(%ebp), %esi		/ Load source address
177	movl	12(%ebp), %edi		/ Load destination address
178	movl	16(%ebp), %ecx		/ Load count
179	repz				/ Repeat for count...
180	smovb				/   move from %ds:si to %es:di
181
182	popl	%edi
183	popl	%esi
184	movl	%ebp, %esp
185	popl	%ebp
186	ret
187	SET_SIZE(dtrace_copy)
188
189#endif	/* __i386 */
190#endif
191
192#if defined(lint)
193
194/*ARGSUSED*/
195void
196dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size)
197{}
198
199#else
200
201#if defined(__amd64)
202
203	ENTRY(dtrace_copystr)
204	pushq	%rbp
205	movq	%rsp, %rbp
206
2070:
208	movb	(%rdi), %al		/* load from source */
209	movb	%al, (%rsi)		/* store to destination */
210	addq	$1, %rdi		/* increment source pointer */
211	addq	$1, %rsi		/* increment destination pointer */
212	subq	$1, %rdx		/* decrement remaining count */
213	cmpb	$0, %al
214	je	1f
215	cmpq	$0, %rdx
216	jne	0b
2171:
218	leave
219	ret
220
221	SET_SIZE(dtrace_copystr)
222
223#elif defined(__i386)
224
225	ENTRY(dtrace_copystr)
226
227	pushl	%ebp			/ Setup stack frame
228	movl	%esp, %ebp
229	pushl	%ebx			/ Save registers
230
231	movl	8(%ebp), %ebx		/ Load source address
232	movl	12(%ebp), %edx		/ Load destination address
233	movl	16(%ebp), %ecx		/ Load count
234
2350:
236	movb	(%ebx), %al		/ Load from source
237	movb	%al, (%edx)		/ Store to destination
238	incl	%ebx			/ Increment source pointer
239	incl	%edx			/ Increment destination pointer
240	decl	%ecx			/ Decrement remaining count
241	cmpb	$0, %al
242	je	1f
243	cmpl	$0, %ecx
244	jne	0b
245
2461:
247	popl	%ebx
248	movl	%ebp, %esp
249	popl	%ebp
250	ret
251
252	SET_SIZE(dtrace_copystr)
253
254#endif	/* __i386 */
255#endif
256
257#if defined(lint)
258
259/*ARGSUSED*/
260uintptr_t
261dtrace_fulword(void *addr)
262{ return (0); }
263
264#else
265#if defined(__amd64)
266
267	ENTRY(dtrace_fulword)
268	movq	(%rdi), %rax
269	ret
270	SET_SIZE(dtrace_fulword)
271
272#elif defined(__i386)
273
274	ENTRY(dtrace_fulword)
275	movl	4(%esp), %ecx
276	xorl	%eax, %eax
277	movl	(%ecx), %eax
278	ret
279	SET_SIZE(dtrace_fulword)
280
281#endif	/* __i386 */
282#endif
283
284#if defined(lint)
285
286/*ARGSUSED*/
287uint8_t
288dtrace_fuword8_nocheck(void *addr)
289{ return (0); }
290
291#else
292#if defined(__amd64)
293
294	ENTRY(dtrace_fuword8_nocheck)
295	xorq	%rax, %rax
296	movb	(%rdi), %al
297	ret
298	SET_SIZE(dtrace_fuword8_nocheck)
299
300#elif defined(__i386)
301
302	ENTRY(dtrace_fuword8_nocheck)
303	movl	4(%esp), %ecx
304	xorl	%eax, %eax
305	movzbl	(%ecx), %eax
306	ret
307	SET_SIZE(dtrace_fuword8_nocheck)
308
309#endif	/* __i386 */
310#endif
311
312#if defined(lint)
313
314/*ARGSUSED*/
315uint16_t
316dtrace_fuword16_nocheck(void *addr)
317{ return (0); }
318
319#else
320#if defined(__amd64)
321
322	ENTRY(dtrace_fuword16_nocheck)
323	xorq	%rax, %rax
324	movw	(%rdi), %ax
325	ret
326	SET_SIZE(dtrace_fuword16_nocheck)
327
328#elif defined(__i386)
329
330	ENTRY(dtrace_fuword16_nocheck)
331	movl	4(%esp), %ecx
332	xorl	%eax, %eax
333	movzwl	(%ecx), %eax
334	ret
335	SET_SIZE(dtrace_fuword16_nocheck)
336
337#endif	/* __i386 */
338#endif
339
340#if defined(lint)
341
342/*ARGSUSED*/
343uint32_t
344dtrace_fuword32_nocheck(void *addr)
345{ return (0); }
346
347#else
348#if defined(__amd64)
349
350	ENTRY(dtrace_fuword32_nocheck)
351	xorq	%rax, %rax
352	movl	(%rdi), %eax
353	ret
354	SET_SIZE(dtrace_fuword32_nocheck)
355
356#elif defined(__i386)
357
358	ENTRY(dtrace_fuword32_nocheck)
359	movl	4(%esp), %ecx
360	xorl	%eax, %eax
361	movl	(%ecx), %eax
362	ret
363	SET_SIZE(dtrace_fuword32_nocheck)
364
365#endif	/* __i386 */
366#endif
367
368#if defined(lint)
369
370/*ARGSUSED*/
371uint64_t
372dtrace_fuword64_nocheck(void *addr)
373{ return (0); }
374
375#else
376#if defined(__amd64)
377
378	ENTRY(dtrace_fuword64_nocheck)
379	movq	(%rdi), %rax
380	ret
381	SET_SIZE(dtrace_fuword64_nocheck)
382
383#elif defined(__i386)
384
385	ENTRY(dtrace_fuword64_nocheck)
386	movl	4(%esp), %ecx
387	xorl	%eax, %eax
388	xorl	%edx, %edx
389	movl	(%ecx), %eax
390	movl	4(%ecx), %edx
391	ret
392	SET_SIZE(dtrace_fuword64_nocheck)
393
394#endif	/* __i386 */
395#endif
396
397#if defined(lint) || defined(__lint)
398
399/*ARGSUSED*/
400void
401dtrace_probe_error(dtrace_state_t *state, dtrace_epid_t epid, int which,
402    int fault, int fltoffs, uintptr_t illval)
403{}
404
405#else	/* lint */
406#if defined(__amd64)
407
408	ENTRY(dtrace_probe_error)
409	pushq	%rbp
410	movq	%rsp, %rbp
411	subq	$0x8, %rsp
412	movq	%r9, (%rsp)
413	movq	%r8, %r9
414	movq	%rcx, %r8
415	movq	%rdx, %rcx
416	movq	%rsi, %rdx
417	movq	%rdi, %rsi
418	movl	dtrace_probeid_error(%rip), %edi
419	call	dtrace_probe
420	addq	$0x8, %rsp
421	leave
422	ret
423	SET_SIZE(dtrace_probe_error)
424
425#elif defined(__i386)
426
427	ENTRY(dtrace_probe_error)
428	pushl	%ebp
429	movl	%esp, %ebp
430	pushl	0x1c(%ebp)
431	pushl	0x18(%ebp)
432	pushl	0x14(%ebp)
433	pushl	0x10(%ebp)
434	pushl	0xc(%ebp)
435	pushl	0x8(%ebp)
436	pushl	dtrace_probeid_error
437	call	dtrace_probe
438	movl	%ebp, %esp
439	popl	%ebp
440	ret
441	SET_SIZE(dtrace_probe_error)
442
443#endif	/* __i386 */
444#endif
445