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: releng/11.0/sys/cddl/dev/dtrace/mips/dtrace_asm.S 299118 2016-05-05 13:54:50Z br $
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 <machine/cpu.h>
37#include <machine/cpuregs.h>
38#include <machine/regnum.h>
39
40#include "assym.s"
41
42        .set    noreorder               # Noreorder is default style!
43
44/*
45 * Primitives
46 */
47
48        .text
49
50/*
51void dtrace_membar_producer(void)
52*/
53LEAF(dtrace_membar_producer)
54	j	ra
55	nop
56END(dtrace_membar_producer)
57
58/*
59void dtrace_membar_consumer(void)
60*/
61LEAF(dtrace_membar_consumer)
62	j	ra
63	nop
64END(dtrace_membar_consumer)
65
66/*
67dtrace_icookie_t dtrace_interrupt_disable(void)
68*/
69LEAF(dtrace_interrupt_disable)
70	mfc0	t0, MIPS_COP_0_STATUS
71	move	v0, t0
72	and	v0, v0, MIPS_SR_INT_IE
73	and	t0, t0, ~MIPS_SR_INT_IE
74	mtc0	t0, MIPS_COP_0_STATUS
75	j	ra
76	nop
77END(dtrace_interrupt_disable)
78
79/*
80void dtrace_interrupt_enable(dtrace_icookie_t cookie)
81*/
82LEAF(dtrace_interrupt_enable)
83	mfc0	t0, MIPS_COP_0_STATUS
84	beqz	a0, not_enabled
85	or	t0, t0, MIPS_SR_INT_IE
86	mtc0	t0, MIPS_COP_0_STATUS
87not_enabled:
88	j	ra
89	nop
90END(dtrace_interrupt_enable)
91
92/*
93uint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
94*/
95LEAF(dtrace_cas32)
961:
97	move	t1, a2
98	ll	t0, 0(a0)
99	bne	t0, a1, 2f
100	nop
101	sc	t1, 0(a0)
102	beqz	t1, 1b
103	nop
1042:	move	v0, t0
105	j	ra
106	nop
107END(dtrace_cas32)
108
109/*
110void *
111dtrace_casptr(void *target, void *cmp, void *new)
112*/
113LEAF(dtrace_casptr)
1141:
115	move	t1, a2
116	PTR_LL	t0, 0(a0)
117	bne	t0, a1, 2f
118	nop
119	PTR_SC	t1, 0(a0)
120	beqz	t1, 1b
121	nop
1222:	move	v0, t0
123	j	ra
124	nop
125END(dtrace_casptr)
126
127
128/*
129uintptr_t
130dtrace_fulword(void *addr)
131*/
132LEAF(dtrace_fulword)
133END(dtrace_fulword)
134
135/*
136uint8_t
137dtrace_fuword8_nocheck(void *addr)
138*/
139LEAF(dtrace_fuword8_nocheck)
140	lbu	v0, 0(a0)
141	j	ra
142	nop
143END(dtrace_fuword8_nocheck)
144
145/*
146uint16_t
147dtrace_fuword16_nocheck(void *addr)
148*/
149LEAF(dtrace_fuword16_nocheck)
150	lhu	v0, 0(a0)
151	j	ra
152	nop
153END(dtrace_fuword16_nocheck)
154
155/*
156uint32_t
157dtrace_fuword32_nocheck(void *addr)
158*/
159LEAF(dtrace_fuword32_nocheck)
160	lw	v0, 0(a0)
161	j	ra
162	nop
163END(dtrace_fuword32_nocheck)
164
165/*
166uint64_t
167dtrace_fuword64_nocheck(void *addr)
168*/
169LEAF(dtrace_fuword64_nocheck)
170#if defined(__mips_n64) || defined(__mips_n32)
171	ld	v0, 0(a0)
172#else
173	lw	v1,4(a0)
174	lw	v0,0(a0)
175#endif
176	j	ra
177	nop
178END(dtrace_fuword64_nocheck)
179
180/*
181XXX: unoptimized
182void
183dtrace_copy(uintptr_t src, uintptr_t dest, size_t size)
184*/
185LEAF(dtrace_copy)
1861:
187	beqz	a2, 2f
188	nop
189	lbu	t0, 0(a0)
190	sb	t0, 0(a1)
191	PTR_ADDU	a0, a0, 1
192	PTR_ADDU	a1, a1, 1
193	INT_SUBU	a2, a2, 1
194	j	1b
195	nop
1962:
197	j	ra
198	nop
199END(dtrace_copy)
200
201/*
202XXX: Unoptimized. Check for flags on page boundaries only(?)
203void
204dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
205    volatile uint16_t *flags)
206*/
207LEAF(dtrace_copystr)
2081:
209	lbu	t0, 0(a0)
210	sb	t0, 0(a1)
211	PTR_ADDU	a0, a0, 1
212	PTR_ADDU	a1, a1, 1
213	INT_SUBU	a2, a2, 1
214	beqz	t0, 2f
215	nop
216	lhu	t1, (a3)
217	and	t1, t1, CPU_DTRACE_BADADDR
218	bnez	t1, 2f
219	nop
220
221	bnez	a2, 1b
222	nop
2232:
224	j	ra
225	nop
226END(dtrace_copystr)
227
228/*
229uintptr_t
230dtrace_caller(int aframes)
231*/
232LEAF(dtrace_caller)
233	li	v0, -1
234	j	ra
235	nop
236END(dtrace_caller)
237