xref: /freebsd/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S (revision faf25f48d601ae39f5752602f3020e2e92605625)
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 * Portions Copyright 2012,2013 Justin Hibbits <jhibbits@freebsd.org>
23 *
24 * $FreeBSD$
25 */
26/*
27 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28 * Use is subject to license terms.
29 */
30
31#include "assym.inc"
32
33#define _ASM
34
35#include <sys/cpuvar_defs.h>
36#include <sys/dtrace.h>
37
38#include <machine/asm.h>
39/*
40#include <machine/cpu.h>
41*/
42
43/*
44 * Primitives
45 */
46
47        .text
48
49/*
50void dtrace_membar_producer(void)
51*/
52ASENTRY_NOPROF(dtrace_membar_producer)
53	sync
54	blr
55END(dtrace_membar_producer)
56
57/*
58void dtrace_membar_consumer(void)
59*/
60ASENTRY_NOPROF(dtrace_membar_consumer)
61	isync
62	blr
63END(dtrace_membar_consumer)
64
65/*
66dtrace_icookie_t dtrace_interrupt_disable(void)
67*/
68ASENTRY_NOPROF(dtrace_interrupt_disable)
69	mfmsr	%r3
70#ifdef __powerpc64__
71	/* Two-instruction sequence to clear EE flag */
72	rldicl	%r0,%r3,48,1
73	rotldi	%r0,%r0,16
74#else
75	rlwinm	%r0,%r3,0,17,15 /* Clear EE flag */
76#endif
77	mtmsr	%r0
78	blr
79END(dtrace_interrupt_disable)
80
81/*
82void dtrace_interrupt_enable(dtrace_icookie_t cookie)
83*/
84ASENTRY_NOPROF(dtrace_interrupt_enable)
85	mtmsr	%r3
86	blr
87END(dtrace_interrupt_enable)
88
89/*
90uint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
91*/
92ASENTRY_NOPROF(dtrace_cas32)
931:
94	lwarx	%r0,0,%r3
95	cmpw	%r4,%r0
96	bne	2f
97	stwcx.	%r5,0,%r3
98	bne	1b
992:	mr	%r3,%r0
100	blr
101END(dtrace_cas32)
102
103/*
104void *
105dtrace_casptr(void *target, void *cmp, void *new)
106*/
107ASENTRY_NOPROF(dtrace_casptr)
108#ifdef __powerpc64__
1091:
110	ldarx	%r0,0,%r3
111	cmpd	%r4,%r0
112	bne	2f
113	stdcx.	%r5,0,%r3
114	bne	1b
115#else
1161:
117	lwarx	%r0,0,%r3
118	cmpw	%r4,%r0
119	bne	2f
120	stwcx.	%r5,0,%r3
121	bne	1b
122#endif
1232:	mr	%r3,%r0
124	blr
125END(dtrace_casptr)
126
127
128/*
129XXX: unoptimized
130void
131dtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
132*/
133ASENTRY_NOPROF(dtrace_copy)
134	subi	%r7,%r3,1
135	subi	%r8,%r4,1
136	mtctr	%r5
1371:
138	lbzu	%r3,1(%r7)
139	stbu	%r3,1(%r8)
140	bdnz	1b
1412:
142	blr
143END(dtrace_copy)
144
145/*
146void
147dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
148    volatile uint16_t *flags)
149*/
150ASENTRY_NOPROF(dtrace_copystr)
151	subi	%r7,%r3,1
152	subi	%r8,%r4,1
1531:
154	lbzu	%r3,1(%r7)
155	stbu	%r3,1(%r8)
156	subi	%r5,%r5,1
157#ifdef __powerpc64__
158	cmpldi	%r5,0
159#else
160	cmplwi	%r5,0
161#endif
162	beq	2f
163	cmplwi	%r3,0
164	beq	2f
165	andi.	%r0,%r5,0x0fff
166	beq	2f
167	lwz	%r0,0(%r6)
168	andi.	%r0,%r0,CPU_DTRACE_BADADDR
169	beq	1b
1702:
171	blr
172END(dtrace_copystr)
173
174/*
175uintptr_t
176dtrace_caller(int aframes)
177*/
178ASENTRY_NOPROF(dtrace_caller)
179	li	%r3, -1
180	blr
181END(dtrace_caller)
182
183/*
184greg_t
185dtrace_getfp(void)
186*/
187ASENTRY_NOPROF(dtrace_getfp)
188	mr	%r3,%r31
189	blr
190END(dtrace_getfp)
191
192