xref: /freebsd/sys/cddl/dev/dtrace/powerpc/dtrace_asm.S (revision d69b94bab0e2a72c62747c188e9df7170824c034)
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>
237e7a9efdSJustin Hibbits *
24c7570492SJustin Hibbits * $FreeBSD$
25c7570492SJustin Hibbits */
26c7570492SJustin Hibbits/*
27c7570492SJustin Hibbits * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28c7570492SJustin Hibbits * Use is subject to license terms.
29c7570492SJustin Hibbits */
30c7570492SJustin Hibbits
31fc2a8776SEd Maste#include "assym.inc"
32c7570492SJustin Hibbits
33c7570492SJustin Hibbits#define _ASM
34c7570492SJustin Hibbits
35c7570492SJustin Hibbits#include <sys/cpuvar_defs.h>
36c7570492SJustin Hibbits#include <sys/dtrace.h>
37c7570492SJustin Hibbits
38c7570492SJustin Hibbits#include <machine/asm.h>
39c7570492SJustin Hibbits/*
40c7570492SJustin Hibbits#include <machine/cpu.h>
41c7570492SJustin Hibbits*/
42c7570492SJustin Hibbits
43c7570492SJustin Hibbits/*
44c7570492SJustin Hibbits * Primitives
45c7570492SJustin Hibbits */
46c7570492SJustin Hibbits
47c7570492SJustin Hibbits        .text
48c7570492SJustin Hibbits
49c7570492SJustin Hibbits/*
50c7570492SJustin Hibbitsvoid dtrace_membar_producer(void)
51c7570492SJustin Hibbits*/
52c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_membar_producer)
53cc117e27SJustin Hibbits	sync
54c7570492SJustin Hibbits	blr
55c7570492SJustin HibbitsEND(dtrace_membar_producer)
56c7570492SJustin Hibbits
57c7570492SJustin Hibbits/*
58c7570492SJustin Hibbitsvoid dtrace_membar_consumer(void)
59c7570492SJustin Hibbits*/
60c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_membar_consumer)
61cc117e27SJustin Hibbits	isync
62c7570492SJustin Hibbits	blr
63c7570492SJustin HibbitsEND(dtrace_membar_consumer)
64c7570492SJustin Hibbits
65c7570492SJustin Hibbits/*
66c7570492SJustin Hibbitsdtrace_icookie_t dtrace_interrupt_disable(void)
67c7570492SJustin Hibbits*/
68c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_interrupt_disable)
69c7570492SJustin Hibbits	mfmsr	%r3
70161c4151SJustin Hibbits#ifdef __powerpc64__
71161c4151SJustin Hibbits	/* Two-instruction sequence to clear EE flag */
72161c4151SJustin Hibbits	rldicl	%r0,%r3,48,1
73161c4151SJustin Hibbits	rotldi	%r0,%r0,16
74161c4151SJustin Hibbits#else
7597a9d3b5SJustin Hibbits	rlwinm	%r0,%r3,0,17,15 /* Clear EE flag */
76161c4151SJustin Hibbits#endif
77c7570492SJustin Hibbits	mtmsr	%r0
78c7570492SJustin Hibbits	blr
79c7570492SJustin HibbitsEND(dtrace_interrupt_disable)
80c7570492SJustin Hibbits
81c7570492SJustin Hibbits/*
82c7570492SJustin Hibbitsvoid dtrace_interrupt_enable(dtrace_icookie_t cookie)
83c7570492SJustin Hibbits*/
84c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_interrupt_enable)
85c7570492SJustin Hibbits	mtmsr	%r3
86c7570492SJustin Hibbits	blr
87c7570492SJustin HibbitsEND(dtrace_interrupt_enable)
88c7570492SJustin Hibbits
89c7570492SJustin Hibbits/*
90c7570492SJustin Hibbitsuint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
91c7570492SJustin Hibbits*/
92c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_cas32)
93c7570492SJustin Hibbits1:
94c7570492SJustin Hibbits	lwarx	%r0,0,%r3
95c7570492SJustin Hibbits	cmpw	%r4,%r0
96c7570492SJustin Hibbits	bne	2f
97c7570492SJustin Hibbits	stwcx.	%r5,0,%r3
98c7570492SJustin Hibbits	bne	1b
99c7570492SJustin Hibbits2:	mr	%r3,%r0
100c7570492SJustin Hibbits	blr
101c7570492SJustin HibbitsEND(dtrace_cas32)
102c7570492SJustin Hibbits
103c7570492SJustin Hibbits/*
104c7570492SJustin Hibbitsvoid *
105c7570492SJustin Hibbitsdtrace_casptr(void *target, void *cmp, void *new)
106c7570492SJustin Hibbits*/
107c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_casptr)
108cc117e27SJustin Hibbits#ifdef __powerpc64__
109cc117e27SJustin Hibbits1:
110cc117e27SJustin Hibbits	ldarx	%r0,0,%r3
111cc117e27SJustin Hibbits	cmpd	%r4,%r0
112cc117e27SJustin Hibbits	bne	2f
113cc117e27SJustin Hibbits	stdcx.	%r5,0,%r3
114cc117e27SJustin Hibbits	bne	1b
115cc117e27SJustin Hibbits#else
116c7570492SJustin Hibbits1:
117c7570492SJustin Hibbits	lwarx	%r0,0,%r3
118c7570492SJustin Hibbits	cmpw	%r4,%r0
119c7570492SJustin Hibbits	bne	2f
120c7570492SJustin Hibbits	stwcx.	%r5,0,%r3
121c7570492SJustin Hibbits	bne	1b
122cc117e27SJustin Hibbits#endif
123c7570492SJustin Hibbits2:	mr	%r3,%r0
124c7570492SJustin Hibbits	blr
125c7570492SJustin HibbitsEND(dtrace_casptr)
126c7570492SJustin Hibbits
127c7570492SJustin Hibbits
128c7570492SJustin Hibbits/*
129c7570492SJustin HibbitsXXX: unoptimized
130c7570492SJustin Hibbitsvoid
131c7570492SJustin Hibbitsdtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
132c7570492SJustin Hibbits*/
133c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_copy)
1347ccb72b3SJustin Hibbits	subi	%r7,%r3,1
1357ccb72b3SJustin Hibbits	subi	%r8,%r4,1
1367ccb72b3SJustin Hibbits	mtctr	%r5
137c7570492SJustin Hibbits1:
138c7570492SJustin Hibbits	lbzu	%r3,1(%r7)
139c7570492SJustin Hibbits	stbu	%r3,1(%r8)
1407ccb72b3SJustin Hibbits	bdnz	1b
141c7570492SJustin Hibbits2:
142c7570492SJustin Hibbits	blr
143c7570492SJustin HibbitsEND(dtrace_copy)
144c7570492SJustin Hibbits
145c7570492SJustin Hibbits/*
146c7570492SJustin Hibbitsvoid
147c7570492SJustin Hibbitsdtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
148c7570492SJustin Hibbits    volatile uint16_t *flags)
149c7570492SJustin Hibbits*/
150c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_copystr)
151e9aae349SJustin Hibbits	subi	%r7,%r3,1
152e9aae349SJustin Hibbits	subi	%r8,%r4,1
153c7570492SJustin Hibbits1:
154c7570492SJustin Hibbits	lbzu	%r3,1(%r7)
155c7570492SJustin Hibbits	stbu	%r3,1(%r8)
156e9aae349SJustin Hibbits	subi	%r5,%r5,1
157e9aae349SJustin Hibbits#ifdef __powerpc64__
158e9aae349SJustin Hibbits	cmpldi	%r5,0
159e9aae349SJustin Hibbits#else
160e9aae349SJustin Hibbits	cmplwi	%r5,0
161e9aae349SJustin Hibbits#endif
162c7570492SJustin Hibbits	beq	2f
163e9aae349SJustin Hibbits	cmplwi	%r3,0
164c7570492SJustin Hibbits	beq	2f
165c7570492SJustin Hibbits	andi.	%r0,%r5,0x0fff
166c7570492SJustin Hibbits	beq	2f
167c7570492SJustin Hibbits	lwz	%r0,0(%r6)
168c7570492SJustin Hibbits	andi.	%r0,%r0,CPU_DTRACE_BADADDR
169c7570492SJustin Hibbits	beq	1b
170c7570492SJustin Hibbits2:
171c7570492SJustin Hibbits	blr
172c7570492SJustin HibbitsEND(dtrace_copystr)
173c7570492SJustin Hibbits
174c7570492SJustin Hibbits/*
175c7570492SJustin Hibbitsuintptr_t
176c7570492SJustin Hibbitsdtrace_caller(int aframes)
177c7570492SJustin Hibbits*/
178c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_caller)
179c7570492SJustin Hibbits	li	%r3, -1
180c7570492SJustin Hibbits	blr
181c7570492SJustin HibbitsEND(dtrace_caller)
182*d69b94baSJustin Hibbits
183*d69b94baSJustin Hibbits/*
184*d69b94baSJustin Hibbitsgreg_t
185*d69b94baSJustin Hibbitsdtrace_getfp(void)
186*d69b94baSJustin Hibbits*/
187*d69b94baSJustin HibbitsASENTRY_NOPROF(dtrace_getfp)
188*d69b94baSJustin Hibbits	mr	%r3,%r31
189*d69b94baSJustin Hibbits	blr
190*d69b94baSJustin HibbitsEND(dtrace_getfp)
191*d69b94baSJustin Hibbits
192