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 * $FreeBSD$
23 */
24/*
25 * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
26 * Use is subject to license terms.
27 */
28
29#define _ASM
30#define _LOCORE
31
32#include <sys/cpuvar_defs.h>
33#include <sys/dtrace.h>
34
35#include <machine/asm.h>
36#include <mips/cpuregs.h>
37#include <machine/regnum.h>
38
39        .set    noreorder               # Noreorder is default style!
40
41/*
42 * Primitives
43 */
44
45        .text
46
47/*
48void dtrace_membar_producer(void)
49*/
50LEAF(dtrace_membar_producer)
51	j	ra
52	nop
53END(dtrace_membar_producer)
54
55/*
56void dtrace_membar_consumer(void)
57*/
58LEAF(dtrace_membar_consumer)
59	j	ra
60	nop
61END(dtrace_membar_consumer)
62
63/*
64dtrace_icookie_t dtrace_interrupt_disable(void)
65*/
66LEAF(dtrace_interrupt_disable)
67	mfc0	t0, MIPS_COP_0_STATUS
68	move	v0, t0
69	and	v0, v0, MIPS_SR_INT_IE
70	and	t0, t0, ~MIPS_SR_INT_IE
71	mtc0	t0, MIPS_COP_0_STATUS
72	j	ra
73	nop
74END(dtrace_interrupt_disable)
75
76/*
77void dtrace_interrupt_enable(dtrace_icookie_t cookie)
78*/
79LEAF(dtrace_interrupt_enable)
80	mfc0	t0, MIPS_COP_0_STATUS
81	beqz	a0, not_enabled
82	or	t0, t0, MIPS_SR_INT_IE
83	mtc0	t0, MIPS_COP_0_STATUS
84not_enabled:
85	j	ra
86	nop
87END(dtrace_interrupt_enable)
88
89/*
90uint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
91*/
92LEAF(dtrace_cas32)
931:
94	move	t1, a2
95	ll	t0, 0(a0)
96	bne	t0, a1, 2f
97	nop
98	sc	t1, 0(a0)
99	beqz	t1, 1b
100	nop
1012:	move	v0, t0
102	j	ra
103	nop
104END(dtrace_cas32)
105
106/*
107void *
108dtrace_casptr(void *target, void *cmp, void *new)
109*/
110LEAF(dtrace_casptr)
1111:
112	move	t1, a2
113	PTR_LL	t0, 0(a0)
114	bne	t0, a1, 2f
115	nop
116	PTR_SC	t1, 0(a0)
117	beqz	t1, 1b
118	nop
1192:	move	v0, t0
120	j	ra
121	nop
122END(dtrace_casptr)
123
124
125/*
126uintptr_t
127dtrace_fulword(void *addr)
128*/
129LEAF(dtrace_fulword)
130END(dtrace_fulword)
131
132/*
133uint8_t
134dtrace_fuword8_nocheck(void *addr)
135*/
136LEAF(dtrace_fuword8_nocheck)
137	lbu	v0, 0(a0)
138	j	ra
139	nop
140END(dtrace_fuword8_nocheck)
141
142/*
143uint16_t
144dtrace_fuword16_nocheck(void *addr)
145*/
146LEAF(dtrace_fuword16_nocheck)
147	lhu	v0, 0(a0)
148	j	ra
149	nop
150END(dtrace_fuword16_nocheck)
151
152/*
153uint32_t
154dtrace_fuword32_nocheck(void *addr)
155*/
156LEAF(dtrace_fuword32_nocheck)
157	lw	v0, 0(a0)
158	j	ra
159	nop
160END(dtrace_fuword32_nocheck)
161
162/*
163uint64_t
164dtrace_fuword64_nocheck(void *addr)
165*/
166LEAF(dtrace_fuword64_nocheck)
167#if defined(__mips_n64) || defined(__mips_n32)
168	ld	v0, 0(a0)
169#else
170	lw	v1,4(a0)
171	lw	v0,0(a0)
172#endif
173	j	ra
174	nop
175END(dtrace_fuword64_nocheck)
176
177/*
178XXX: unoptimized
179void
180dtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
181*/
182LEAF(dtrace_copy)
1831:
184	beqz	a2, 2f
185	nop
186	lbu	t0, 0(a0)
187	sb	t0, 0(a1)
188	PTR_ADDU	a0, a0, 1
189	PTR_ADDU	a1, a1, 1
190	INT_SUBU	a2, a2, 1
191	j	1b
192	nop
1932:
194	j	ra
195	nop
196END(dtrace_copy)
197
198/*
199XXX: Unoptimized. Check for flags on page boundaries only(?)
200void
201dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
202    volatile uint16_t *flags)
203*/
204LEAF(dtrace_copystr)
2051:
206	lbu	t0, 0(a0)
207	sb	t0, 0(a1)
208	PTR_ADDU	a0, a0, 1
209	PTR_ADDU	a1, a1, 1
210	INT_SUBU	a2, a2, 1
211	beqz	t0, 2f
212	nop
213	lhu	t1, (a3)
214	and	t1, t1, CPU_DTRACE_BADADDR
215	bnez	t1, 2f
216	nop
217
218	bnez	a2, 1b
219	nop
2202:
221	j	ra
222	nop
223END(dtrace_copystr)
224
225/*
226uintptr_t
227dtrace_caller(int aframes)
228*/
229LEAF(dtrace_caller)
230	li	v0, -1
231	j	ra
232	nop
233END(dtrace_caller)
234