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/10.2/sys/cddl/dev/dtrace/mips/dtrace_asm.S 283676 2015-05-29 04:01:39Z markj $
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#define LOCORE
32233409Sgonzo
33233409Sgonzo#include <sys/cpuvar_defs.h>
34233409Sgonzo#include <sys/dtrace.h>
35233409Sgonzo
36233409Sgonzo#include <machine/asm.h>
37233409Sgonzo#include <machine/cpu.h>
38233409Sgonzo#include <machine/cpuregs.h>
39233409Sgonzo#include <machine/regnum.h>
40233409Sgonzo
41233409Sgonzo#include "assym.s"
42233409Sgonzo
43233409Sgonzo        .set    noreorder               # Noreorder is default style!
44233409Sgonzo
45233409Sgonzo/*
46233409Sgonzo * Primitives
47233409Sgonzo */
48233409Sgonzo
49233409Sgonzo        .text
50233409Sgonzo
51233409Sgonzo/*
52233409Sgonzovoid dtrace_membar_producer(void)
53233409Sgonzo*/
54233409SgonzoLEAF(dtrace_membar_producer)
55233409Sgonzo	j	ra
56233409Sgonzo	nop
57233409SgonzoEND(dtrace_membar_producer)
58233409Sgonzo
59233409Sgonzo/*
60233409Sgonzovoid dtrace_membar_consumer(void)
61233409Sgonzo*/
62233409SgonzoLEAF(dtrace_membar_consumer)
63233409Sgonzo	j	ra
64233409Sgonzo	nop
65233409SgonzoEND(dtrace_membar_consumer)
66233409Sgonzo
67233409Sgonzo/*
68233409Sgonzodtrace_icookie_t dtrace_interrupt_disable(void)
69233409Sgonzo*/
70233409SgonzoLEAF(dtrace_interrupt_disable)
71233409Sgonzo	mfc0	t0, MIPS_COP_0_STATUS
72233409Sgonzo	move	v0, t0
73233409Sgonzo	and	v0, v0, MIPS_SR_INT_IE
74233409Sgonzo	and	t0, t0, ~MIPS_SR_INT_IE
75233409Sgonzo	mtc0	t0, MIPS_COP_0_STATUS
76233409Sgonzo	j	ra
77233409Sgonzo	nop
78233409SgonzoEND(dtrace_interrupt_disable)
79233409Sgonzo
80233409Sgonzo/*
81233409Sgonzovoid dtrace_interrupt_enable(dtrace_icookie_t cookie)
82233409Sgonzo*/
83233409SgonzoLEAF(dtrace_interrupt_enable)
84233409Sgonzo	mfc0	t0, MIPS_COP_0_STATUS
85233409Sgonzo	beqz	a0, not_enabled
86233409Sgonzo	or	t0, t0, MIPS_SR_INT_IE
87233409Sgonzo	mtc0	t0, MIPS_COP_0_STATUS
88233409Sgonzonot_enabled:
89233409Sgonzo	j	ra
90233409Sgonzo	nop
91233409SgonzoEND(dtrace_interrupt_enable)
92233409Sgonzo
93233409Sgonzo/*
94233409Sgonzouint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
95233409Sgonzo*/
96233409SgonzoLEAF(dtrace_cas32)
97233409Sgonzo1:
98233409Sgonzo	move	t1, a2
99233409Sgonzo	ll	t0, 0(a0)
100233409Sgonzo	bne	t0, a1, 2f
101233409Sgonzo	nop
102233409Sgonzo	sc	t1, 0(a0)
103233409Sgonzo	beqz	t1, 1b
104233409Sgonzo	nop
105233409Sgonzo2:	move	v0, t0
106233409Sgonzo	j	ra
107233409Sgonzo	nop
108233409SgonzoEND(dtrace_cas32)
109233409Sgonzo
110233409Sgonzo/*
111233409Sgonzovoid *
112233409Sgonzodtrace_casptr(void *target, void *cmp, void *new)
113233409Sgonzo*/
114233409SgonzoLEAF(dtrace_casptr)
115233409Sgonzo1:
116233409Sgonzo	move	t1, a2
117233409Sgonzo	PTR_LL	t0, 0(a0)
118233409Sgonzo	bne	t0, a1, 2f
119233409Sgonzo	nop
120233409Sgonzo	PTR_SC	t1, 0(a0)
121233409Sgonzo	beqz	t1, 1b
122233409Sgonzo	nop
123233409Sgonzo2:	move	v0, t0
124233409Sgonzo	j	ra
125233409Sgonzo	nop
126233409SgonzoEND(dtrace_casptr)
127233409Sgonzo
128233409Sgonzo
129233409Sgonzo/*
130233409Sgonzouintptr_t
131233409Sgonzodtrace_fulword(void *addr)
132233409Sgonzo*/
133233409SgonzoLEAF(dtrace_fulword)
134233409SgonzoEND(dtrace_fulword)
135233409Sgonzo
136233409Sgonzo/*
137233409Sgonzouint8_t
138233409Sgonzodtrace_fuword8_nocheck(void *addr)
139233409Sgonzo*/
140233409SgonzoLEAF(dtrace_fuword8_nocheck)
141233409Sgonzo	lbu	v0, 0(a0)
142233409Sgonzo	j	ra
143233409Sgonzo	nop
144233409SgonzoEND(dtrace_fuword8_nocheck)
145233409Sgonzo
146233409Sgonzo/*
147233409Sgonzouint16_t
148233409Sgonzodtrace_fuword16_nocheck(void *addr)
149233409Sgonzo*/
150233409SgonzoLEAF(dtrace_fuword16_nocheck)
151233409Sgonzo	lhu	v0, 0(a0)
152233409Sgonzo	j	ra
153233409Sgonzo	nop
154233409SgonzoEND(dtrace_fuword16_nocheck)
155233409Sgonzo
156233409Sgonzo/*
157233409Sgonzouint32_t
158233409Sgonzodtrace_fuword32_nocheck(void *addr)
159233409Sgonzo*/
160233409SgonzoLEAF(dtrace_fuword32_nocheck)
161233484Sgonzo	lw	v0, 0(a0)
162233409Sgonzo	j	ra
163233409Sgonzo	nop
164233409SgonzoEND(dtrace_fuword32_nocheck)
165233409Sgonzo
166233409Sgonzo/*
167233409Sgonzouint64_t
168233409Sgonzodtrace_fuword64_nocheck(void *addr)
169233409Sgonzo*/
170233409SgonzoLEAF(dtrace_fuword64_nocheck)
171233409Sgonzo#if defined(__mips_n64) || defined(__mips_n32)
172233409Sgonzo	ld	v0, 0(a0)
173233409Sgonzo#else
174233409Sgonzo	lw	v1,4(a0)
175233409Sgonzo	lw	v0,0(a0)
176233409Sgonzo#endif
177233409Sgonzo	j	ra
178233409Sgonzo	nop
179233409SgonzoEND(dtrace_fuword64_nocheck)
180233409Sgonzo
181233409Sgonzo/*
182233409SgonzoXXX: unoptimized
183233409Sgonzovoid
184233409Sgonzodtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
185233409Sgonzo*/
186233409SgonzoLEAF(dtrace_copy)
187233409Sgonzo1:
188233409Sgonzo	beqz	a2, 2f
189233409Sgonzo	nop
190233409Sgonzo	lbu	t0, 0(a0)
191233409Sgonzo	sb	t0, 0(a1)
192233484Sgonzo	PTR_ADDU	a0, a0, 1
193233484Sgonzo	PTR_ADDU	a1, a1, 1
194233484Sgonzo	INT_SUBU	a2, a2, 1
195233409Sgonzo	j	1b
196233409Sgonzo	nop
197233409Sgonzo2:
198233409Sgonzo	j	ra
199233409Sgonzo	nop
200233409SgonzoEND(dtrace_copy)
201233409Sgonzo
202233409Sgonzo/*
203233409SgonzoXXX: Unoptimized. Check for flags on page boundaries only(?)
204233409Sgonzovoid
205233409Sgonzodtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
206233409Sgonzo    volatile uint16_t *flags)
207233409Sgonzo*/
208233409SgonzoLEAF(dtrace_copystr)
209233409Sgonzo1:
210233409Sgonzo	lbu	t0, 0(a0)
211233409Sgonzo	sb	t0, 0(a1)
212233484Sgonzo	PTR_ADDU	a0, a0, 1
213233484Sgonzo	PTR_ADDU	a1, a1, 1
214233484Sgonzo	INT_SUBU	a2, a2, 1
215233409Sgonzo	beqz	t0, 2f
216233409Sgonzo	nop
217233409Sgonzo	lhu	t1, (a3)
218233409Sgonzo	and	t1, t1, CPU_DTRACE_BADADDR
219233409Sgonzo	bnez	t1, 2f
220233409Sgonzo	nop
221233409Sgonzo
222233409Sgonzo	bnez	a2, 1b
223233409Sgonzo	nop
224233409Sgonzo2:
225233409Sgonzo	j	ra
226233409Sgonzo	nop
227233409SgonzoEND(dtrace_copystr)
228233409Sgonzo
229233409Sgonzo/*
230233409Sgonzovoid dtrace_invop_init(void)
231233409Sgonzo*/
232233409SgonzoLEAF(dtrace_invop_init)
233233409Sgonzo	/* XXX: impement it properly */
234233484Sgonzo	PTR_LA	t0, dtrace_invop_jump_addr
235233409Sgonzo	/* dla	t1, dtrace_invop_start */
236233484Sgonzo	PTR_S	zero, 0(t0)
237233409Sgonzo	j	ra
238233409Sgonzo	nop
239233409SgonzoEND(dtrace_invop_init)
240233409Sgonzo
241233409Sgonzo/*
242233409Sgonzovoid dtrace_invop_uninit(void)
243233409Sgonzo*/
244233409SgonzoLEAF(dtrace_invop_uninit)
245233484Sgonzo	PTR_LA	t0, dtrace_invop_jump_addr
246233484Sgonzo	PTR_S	zero, 0(t0)
247233409Sgonzo	j	ra
248233409Sgonzo	nop
249233409SgonzoEND(dtrace_invop_uninit)
250233409Sgonzo
251233409Sgonzo/*
252233409Sgonzouintptr_t
253233409Sgonzodtrace_caller(int aframes)
254233409Sgonzo*/
255233409SgonzoLEAF(dtrace_caller)
256233409Sgonzo	li	v0, -1
257233409Sgonzo	j	ra
258233409Sgonzo	nop
259233409SgonzoEND(dtrace_caller)
260