xref: /freebsd/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S (revision 389e4940069316fe667ffa263fa7d6390d0a960f)
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,~PSL_EE /* 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	addme	%r7,%r3
152	addme	%r8,%r4
1531:
154	lbzu	%r3,1(%r7)
155	stbu	%r3,1(%r8)
156	addme	%r5,%r5
157	beq	2f
158	or	%r3,%r3,%r3
159	beq	2f
160	andi.	%r0,%r5,0x0fff
161	beq	2f
162	lwz	%r0,0(%r6)
163	andi.	%r0,%r0,CPU_DTRACE_BADADDR
164	beq	1b
1652:
166	blr
167END(dtrace_copystr)
168
169/*
170uintptr_t
171dtrace_caller(int aframes)
172*/
173ASENTRY_NOPROF(dtrace_caller)
174	li	%r3, -1
175	blr
176END(dtrace_caller)
177