xref: /freebsd/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1c7570492SJustin Hibbits/*
2c7570492SJustin Hibbits * CDDL HEADER START
3c7570492SJustin Hibbits *
4c7570492SJustin Hibbits * The contents of this file are subject to the terms of the
5c7570492SJustin Hibbits * Common Development and Distribution License, Version 1.0 only
6c7570492SJustin Hibbits * (the "License").  You may not use this file except in compliance
7c7570492SJustin Hibbits * with the License.
8c7570492SJustin Hibbits *
9c7570492SJustin Hibbits * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10c7570492SJustin Hibbits * or http://www.opensolaris.org/os/licensing.
11c7570492SJustin Hibbits * See the License for the specific language governing permissions
12c7570492SJustin Hibbits * and limitations under the License.
13c7570492SJustin Hibbits *
14c7570492SJustin Hibbits * When distributing Covered Code, include this CDDL HEADER in each
15c7570492SJustin Hibbits * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16c7570492SJustin Hibbits * If applicable, add the following below this CDDL HEADER, with the
17c7570492SJustin Hibbits * fields enclosed by brackets "[]" replaced with your own identifying
18c7570492SJustin Hibbits * information: Portions Copyright [yyyy] [name of copyright owner]
19c7570492SJustin Hibbits *
20c7570492SJustin Hibbits * CDDL HEADER END
21c7570492SJustin Hibbits *
227e7a9efdSJustin Hibbits * Portions Copyright 2012,2013 Justin Hibbits <jhibbits@freebsd.org>
23c7570492SJustin Hibbits */
24c7570492SJustin Hibbits/*
25c7570492SJustin Hibbits * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26c7570492SJustin Hibbits * Use is subject to license terms.
27c7570492SJustin Hibbits */
28c7570492SJustin Hibbits
29fc2a8776SEd Maste#include "assym.inc"
30c7570492SJustin Hibbits
31c7570492SJustin Hibbits#define _ASM
32c7570492SJustin Hibbits
33c7570492SJustin Hibbits#include <sys/cpuvar_defs.h>
34c7570492SJustin Hibbits#include <sys/dtrace.h>
35c7570492SJustin Hibbits
36c7570492SJustin Hibbits#include <machine/asm.h>
37c7570492SJustin Hibbits/*
38c7570492SJustin Hibbits#include <machine/cpu.h>
39c7570492SJustin Hibbits*/
40c7570492SJustin Hibbits
41c7570492SJustin Hibbits/*
42c7570492SJustin Hibbits * Primitives
43c7570492SJustin Hibbits */
44c7570492SJustin Hibbits
45c7570492SJustin Hibbits        .text
46c7570492SJustin Hibbits
47c7570492SJustin Hibbits/*
48c7570492SJustin Hibbitsvoid dtrace_membar_producer(void)
49c7570492SJustin Hibbits*/
50c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_membar_producer)
51cc117e27SJustin Hibbits	sync
52c7570492SJustin Hibbits	blr
53c7570492SJustin HibbitsEND(dtrace_membar_producer)
54c7570492SJustin Hibbits
55c7570492SJustin Hibbits/*
56c7570492SJustin Hibbitsvoid dtrace_membar_consumer(void)
57c7570492SJustin Hibbits*/
58c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_membar_consumer)
59cc117e27SJustin Hibbits	isync
60c7570492SJustin Hibbits	blr
61c7570492SJustin HibbitsEND(dtrace_membar_consumer)
62c7570492SJustin Hibbits
63c7570492SJustin Hibbits/*
64c7570492SJustin Hibbitsdtrace_icookie_t dtrace_interrupt_disable(void)
65c7570492SJustin Hibbits*/
66c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_interrupt_disable)
67c7570492SJustin Hibbits	mfmsr	%r3
68161c4151SJustin Hibbits#ifdef __powerpc64__
69161c4151SJustin Hibbits	/* Two-instruction sequence to clear EE flag */
70161c4151SJustin Hibbits	rldicl	%r0,%r3,48,1
71161c4151SJustin Hibbits	rotldi	%r0,%r0,16
72161c4151SJustin Hibbits#else
7397a9d3b5SJustin Hibbits	rlwinm	%r0,%r3,0,17,15 /* Clear EE flag */
74161c4151SJustin Hibbits#endif
75c7570492SJustin Hibbits	mtmsr	%r0
76c7570492SJustin Hibbits	blr
77c7570492SJustin HibbitsEND(dtrace_interrupt_disable)
78c7570492SJustin Hibbits
79c7570492SJustin Hibbits/*
80c7570492SJustin Hibbitsvoid dtrace_interrupt_enable(dtrace_icookie_t cookie)
81c7570492SJustin Hibbits*/
82c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_interrupt_enable)
83c7570492SJustin Hibbits	mtmsr	%r3
84c7570492SJustin Hibbits	blr
85c7570492SJustin HibbitsEND(dtrace_interrupt_enable)
86c7570492SJustin Hibbits
87c7570492SJustin Hibbits/*
88c7570492SJustin Hibbitsuint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
89c7570492SJustin Hibbits*/
90c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_cas32)
91c7570492SJustin Hibbits1:
92c7570492SJustin Hibbits	lwarx	%r0,0,%r3
93c7570492SJustin Hibbits	cmpw	%r4,%r0
94c7570492SJustin Hibbits	bne	2f
95c7570492SJustin Hibbits	stwcx.	%r5,0,%r3
96c7570492SJustin Hibbits	bne	1b
97c7570492SJustin Hibbits2:	mr	%r3,%r0
98c7570492SJustin Hibbits	blr
99c7570492SJustin HibbitsEND(dtrace_cas32)
100c7570492SJustin Hibbits
101c7570492SJustin Hibbits/*
102c7570492SJustin Hibbitsvoid *
103c7570492SJustin Hibbitsdtrace_casptr(void *target, void *cmp, void *new)
104c7570492SJustin Hibbits*/
105c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_casptr)
106cc117e27SJustin Hibbits#ifdef __powerpc64__
107cc117e27SJustin Hibbits1:
108cc117e27SJustin Hibbits	ldarx	%r0,0,%r3
109cc117e27SJustin Hibbits	cmpd	%r4,%r0
110cc117e27SJustin Hibbits	bne	2f
111cc117e27SJustin Hibbits	stdcx.	%r5,0,%r3
112cc117e27SJustin Hibbits	bne	1b
113cc117e27SJustin Hibbits#else
114c7570492SJustin Hibbits1:
115c7570492SJustin Hibbits	lwarx	%r0,0,%r3
116c7570492SJustin Hibbits	cmpw	%r4,%r0
117c7570492SJustin Hibbits	bne	2f
118c7570492SJustin Hibbits	stwcx.	%r5,0,%r3
119c7570492SJustin Hibbits	bne	1b
120cc117e27SJustin Hibbits#endif
121c7570492SJustin Hibbits2:	mr	%r3,%r0
122c7570492SJustin Hibbits	blr
123c7570492SJustin HibbitsEND(dtrace_casptr)
124c7570492SJustin Hibbits
125c7570492SJustin Hibbits
126c7570492SJustin Hibbits/*
127c7570492SJustin HibbitsXXX: unoptimized
128c7570492SJustin Hibbitsvoid
129c7570492SJustin Hibbitsdtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
130c7570492SJustin Hibbits*/
131c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_copy)
1327ccb72b3SJustin Hibbits	subi	%r7,%r3,1
1337ccb72b3SJustin Hibbits	subi	%r8,%r4,1
1347ccb72b3SJustin Hibbits	mtctr	%r5
135c7570492SJustin Hibbits1:
136c7570492SJustin Hibbits	lbzu	%r3,1(%r7)
137c7570492SJustin Hibbits	stbu	%r3,1(%r8)
1387ccb72b3SJustin Hibbits	bdnz	1b
139c7570492SJustin Hibbits2:
140c7570492SJustin Hibbits	blr
141c7570492SJustin HibbitsEND(dtrace_copy)
142c7570492SJustin Hibbits
143c7570492SJustin Hibbits/*
144c7570492SJustin Hibbitsvoid
145c7570492SJustin Hibbitsdtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
146c7570492SJustin Hibbits    volatile uint16_t *flags)
147c7570492SJustin Hibbits*/
148c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_copystr)
149e9aae349SJustin Hibbits	subi	%r7,%r3,1
150e9aae349SJustin Hibbits	subi	%r8,%r4,1
151c7570492SJustin Hibbits1:
152c7570492SJustin Hibbits	lbzu	%r3,1(%r7)
153c7570492SJustin Hibbits	stbu	%r3,1(%r8)
154e9aae349SJustin Hibbits	subi	%r5,%r5,1
155e9aae349SJustin Hibbits#ifdef __powerpc64__
156e9aae349SJustin Hibbits	cmpldi	%r5,0
157e9aae349SJustin Hibbits#else
158e9aae349SJustin Hibbits	cmplwi	%r5,0
159e9aae349SJustin Hibbits#endif
160c7570492SJustin Hibbits	beq	2f
161e9aae349SJustin Hibbits	cmplwi	%r3,0
162c7570492SJustin Hibbits	beq	2f
163c7570492SJustin Hibbits	andi.	%r0,%r5,0x0fff
164c7570492SJustin Hibbits	beq	2f
165c7570492SJustin Hibbits	lwz	%r0,0(%r6)
166c7570492SJustin Hibbits	andi.	%r0,%r0,CPU_DTRACE_BADADDR
167c7570492SJustin Hibbits	beq	1b
168c7570492SJustin Hibbits2:
169c7570492SJustin Hibbits	blr
170c7570492SJustin HibbitsEND(dtrace_copystr)
171c7570492SJustin Hibbits
172c7570492SJustin Hibbits/*
173c7570492SJustin Hibbitsuintptr_t
174c7570492SJustin Hibbitsdtrace_caller(int aframes)
175c7570492SJustin Hibbits*/
176c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_caller)
177c7570492SJustin Hibbits	li	%r3, -1
178c7570492SJustin Hibbits	blr
179c7570492SJustin HibbitsEND(dtrace_caller)
180*d69b94baSJustin Hibbits
181*d69b94baSJustin Hibbits/*
182*d69b94baSJustin Hibbitsgreg_t
183*d69b94baSJustin Hibbitsdtrace_getfp(void)
184*d69b94baSJustin Hibbits*/
185*d69b94baSJustin HibbitsASENTRY_NOPROF(dtrace_getfp)
186*d69b94baSJustin Hibbits	mr	%r3,%r31
187*d69b94baSJustin Hibbits	blr
188*d69b94baSJustin HibbitsEND(dtrace_getfp)
189*d69b94baSJustin Hibbits
190