1233409Sgonzo/*
2233409Sgonzo * CDDL HEADER START
3233409Sgonzo *
4233409Sgonzo * The contents of this file are subject to the terms of the
5233409Sgonzo * Common Development and Distribution License, Version 1.0 only
6233409Sgonzo * (the "License").  You may not use this file except in compliance
7233409Sgonzo * with the License.
8233409Sgonzo *
9233409Sgonzo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10233409Sgonzo * or http://www.opensolaris.org/os/licensing.
11233409Sgonzo * See the License for the specific language governing permissions
12233409Sgonzo * and limitations under the License.
13233409Sgonzo *
14233409Sgonzo * When distributing Covered Code, include this CDDL HEADER in each
15233409Sgonzo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16233409Sgonzo * If applicable, add the following below this CDDL HEADER, with the
17233409Sgonzo * fields enclosed by brackets "[]" replaced with your own identifying
18233409Sgonzo * information: Portions Copyright [yyyy] [name of copyright owner]
19233409Sgonzo *
20233409Sgonzo * CDDL HEADER END
21233409Sgonzo *
22233409Sgonzo * $FreeBSD: releng/11.0/sys/cddl/dev/dtrace/mips/dtrace_asm.S 299118 2016-05-05 13:54:50Z br $
23233409Sgonzo */
24233409Sgonzo/*
25233409Sgonzo * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26233409Sgonzo * Use is subject to license terms.
27233409Sgonzo */
28233409Sgonzo
29233409Sgonzo#define _ASM
30233409Sgonzo#define _LOCORE
31233409Sgonzo
32233409Sgonzo#include <sys/cpuvar_defs.h>
33233409Sgonzo#include <sys/dtrace.h>
34233409Sgonzo
35233409Sgonzo#include <machine/asm.h>
36233409Sgonzo#include <machine/cpu.h>
37233409Sgonzo#include <machine/cpuregs.h>
38233409Sgonzo#include <machine/regnum.h>
39233409Sgonzo
40233409Sgonzo#include "assym.s"
41233409Sgonzo
42233409Sgonzo        .set    noreorder               # Noreorder is default style!
43233409Sgonzo
44233409Sgonzo/*
45233409Sgonzo * Primitives
46233409Sgonzo */
47233409Sgonzo
48233409Sgonzo        .text
49233409Sgonzo
50233409Sgonzo/*
51233409Sgonzovoid dtrace_membar_producer(void)
52233409Sgonzo*/
53233409SgonzoLEAF(dtrace_membar_producer)
54233409Sgonzo	j	ra
55233409Sgonzo	nop
56233409SgonzoEND(dtrace_membar_producer)
57233409Sgonzo
58233409Sgonzo/*
59233409Sgonzovoid dtrace_membar_consumer(void)
60233409Sgonzo*/
61233409SgonzoLEAF(dtrace_membar_consumer)
62233409Sgonzo	j	ra
63233409Sgonzo	nop
64233409SgonzoEND(dtrace_membar_consumer)
65233409Sgonzo
66233409Sgonzo/*
67233409Sgonzodtrace_icookie_t dtrace_interrupt_disable(void)
68233409Sgonzo*/
69233409SgonzoLEAF(dtrace_interrupt_disable)
70233409Sgonzo	mfc0	t0, MIPS_COP_0_STATUS
71233409Sgonzo	move	v0, t0
72233409Sgonzo	and	v0, v0, MIPS_SR_INT_IE
73233409Sgonzo	and	t0, t0, ~MIPS_SR_INT_IE
74233409Sgonzo	mtc0	t0, MIPS_COP_0_STATUS
75233409Sgonzo	j	ra
76233409Sgonzo	nop
77233409SgonzoEND(dtrace_interrupt_disable)
78233409Sgonzo
79233409Sgonzo/*
80233409Sgonzovoid dtrace_interrupt_enable(dtrace_icookie_t cookie)
81233409Sgonzo*/
82233409SgonzoLEAF(dtrace_interrupt_enable)
83233409Sgonzo	mfc0	t0, MIPS_COP_0_STATUS
84233409Sgonzo	beqz	a0, not_enabled
85233409Sgonzo	or	t0, t0, MIPS_SR_INT_IE
86233409Sgonzo	mtc0	t0, MIPS_COP_0_STATUS
87233409Sgonzonot_enabled:
88233409Sgonzo	j	ra
89233409Sgonzo	nop
90233409SgonzoEND(dtrace_interrupt_enable)
91233409Sgonzo
92233409Sgonzo/*
93233409Sgonzouint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
94233409Sgonzo*/
95233409SgonzoLEAF(dtrace_cas32)
96233409Sgonzo1:
97233409Sgonzo	move	t1, a2
98233409Sgonzo	ll	t0, 0(a0)
99233409Sgonzo	bne	t0, a1, 2f
100233409Sgonzo	nop
101233409Sgonzo	sc	t1, 0(a0)
102233409Sgonzo	beqz	t1, 1b
103233409Sgonzo	nop
104233409Sgonzo2:	move	v0, t0
105233409Sgonzo	j	ra
106233409Sgonzo	nop
107233409SgonzoEND(dtrace_cas32)
108233409Sgonzo
109233409Sgonzo/*
110233409Sgonzovoid *
111233409Sgonzodtrace_casptr(void *target, void *cmp, void *new)
112233409Sgonzo*/
113233409SgonzoLEAF(dtrace_casptr)
114233409Sgonzo1:
115233409Sgonzo	move	t1, a2
116233409Sgonzo	PTR_LL	t0, 0(a0)
117233409Sgonzo	bne	t0, a1, 2f
118233409Sgonzo	nop
119233409Sgonzo	PTR_SC	t1, 0(a0)
120233409Sgonzo	beqz	t1, 1b
121233409Sgonzo	nop
122233409Sgonzo2:	move	v0, t0
123233409Sgonzo	j	ra
124233409Sgonzo	nop
125233409SgonzoEND(dtrace_casptr)
126233409Sgonzo
127233409Sgonzo
128233409Sgonzo/*
129233409Sgonzouintptr_t
130233409Sgonzodtrace_fulword(void *addr)
131233409Sgonzo*/
132233409SgonzoLEAF(dtrace_fulword)
133233409SgonzoEND(dtrace_fulword)
134233409Sgonzo
135233409Sgonzo/*
136233409Sgonzouint8_t
137233409Sgonzodtrace_fuword8_nocheck(void *addr)
138233409Sgonzo*/
139233409SgonzoLEAF(dtrace_fuword8_nocheck)
140233409Sgonzo	lbu	v0, 0(a0)
141233409Sgonzo	j	ra
142233409Sgonzo	nop
143233409SgonzoEND(dtrace_fuword8_nocheck)
144233409Sgonzo
145233409Sgonzo/*
146233409Sgonzouint16_t
147233409Sgonzodtrace_fuword16_nocheck(void *addr)
148233409Sgonzo*/
149233409SgonzoLEAF(dtrace_fuword16_nocheck)
150233409Sgonzo	lhu	v0, 0(a0)
151233409Sgonzo	j	ra
152233409Sgonzo	nop
153233409SgonzoEND(dtrace_fuword16_nocheck)
154233409Sgonzo
155233409Sgonzo/*
156233409Sgonzouint32_t
157233409Sgonzodtrace_fuword32_nocheck(void *addr)
158233409Sgonzo*/
159233409SgonzoLEAF(dtrace_fuword32_nocheck)
160233484Sgonzo	lw	v0, 0(a0)
161233409Sgonzo	j	ra
162233409Sgonzo	nop
163233409SgonzoEND(dtrace_fuword32_nocheck)
164233409Sgonzo
165233409Sgonzo/*
166233409Sgonzouint64_t
167233409Sgonzodtrace_fuword64_nocheck(void *addr)
168233409Sgonzo*/
169233409SgonzoLEAF(dtrace_fuword64_nocheck)
170233409Sgonzo#if defined(__mips_n64) || defined(__mips_n32)
171233409Sgonzo	ld	v0, 0(a0)
172233409Sgonzo#else
173233409Sgonzo	lw	v1,4(a0)
174233409Sgonzo	lw	v0,0(a0)
175233409Sgonzo#endif
176233409Sgonzo	j	ra
177233409Sgonzo	nop
178233409SgonzoEND(dtrace_fuword64_nocheck)
179233409Sgonzo
180233409Sgonzo/*
181233409SgonzoXXX: unoptimized
182233409Sgonzovoid
183233409Sgonzodtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
184233409Sgonzo*/
185233409SgonzoLEAF(dtrace_copy)
186233409Sgonzo1:
187233409Sgonzo	beqz	a2, 2f
188233409Sgonzo	nop
189233409Sgonzo	lbu	t0, 0(a0)
190233409Sgonzo	sb	t0, 0(a1)
191233484Sgonzo	PTR_ADDU	a0, a0, 1
192233484Sgonzo	PTR_ADDU	a1, a1, 1
193233484Sgonzo	INT_SUBU	a2, a2, 1
194233409Sgonzo	j	1b
195233409Sgonzo	nop
196233409Sgonzo2:
197233409Sgonzo	j	ra
198233409Sgonzo	nop
199233409SgonzoEND(dtrace_copy)
200233409Sgonzo
201233409Sgonzo/*
202233409SgonzoXXX: Unoptimized. Check for flags on page boundaries only(?)
203233409Sgonzovoid
204233409Sgonzodtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
205233409Sgonzo    volatile uint16_t *flags)
206233409Sgonzo*/
207233409SgonzoLEAF(dtrace_copystr)
208233409Sgonzo1:
209233409Sgonzo	lbu	t0, 0(a0)
210233409Sgonzo	sb	t0, 0(a1)
211233484Sgonzo	PTR_ADDU	a0, a0, 1
212233484Sgonzo	PTR_ADDU	a1, a1, 1
213233484Sgonzo	INT_SUBU	a2, a2, 1
214233409Sgonzo	beqz	t0, 2f
215233409Sgonzo	nop
216233409Sgonzo	lhu	t1, (a3)
217233409Sgonzo	and	t1, t1, CPU_DTRACE_BADADDR
218233409Sgonzo	bnez	t1, 2f
219233409Sgonzo	nop
220233409Sgonzo
221233409Sgonzo	bnez	a2, 1b
222233409Sgonzo	nop
223233409Sgonzo2:
224233409Sgonzo	j	ra
225233409Sgonzo	nop
226233409SgonzoEND(dtrace_copystr)
227233409Sgonzo
228233409Sgonzo/*
229233409Sgonzouintptr_t
230233409Sgonzodtrace_caller(int aframes)
231233409Sgonzo*/
232233409SgonzoLEAF(dtrace_caller)
233233409Sgonzo	li	v0, -1
234233409Sgonzo	j	ra
235233409Sgonzo	nop
236233409SgonzoEND(dtrace_caller)
237