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