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
37/*
38void dtrace_membar_producer(void)
39*/
40ENTRY(dtrace_membar_producer)
41	RET
42END(dtrace_membar_producer)
43
44/*
45void dtrace_membar_consumer(void)
46*/
47ENTRY(dtrace_membar_consumer)
48	RET
49END(dtrace_membar_consumer)
50
51/*
52dtrace_icookie_t dtrace_interrupt_disable(void)
53*/
54ENTRY(dtrace_interrupt_disable)
55	mrs	x0, daif
56	msr	daifset, #2
57	RET
58END(dtrace_interrupt_disable)
59
60/*
61void dtrace_interrupt_enable(dtrace_icookie_t cookie)
62*/
63ENTRY(dtrace_interrupt_enable)
64	msr	daif, x0
65	RET
66END(dtrace_interrupt_enable)
67/*
68uint8_t
69dtrace_fuword8_nocheck(void *addr)
70*/
71ENTRY(dtrace_fuword8_nocheck)
72	ldrb	w0, [x0]
73	RET
74END(dtrace_fuword8_nocheck)
75
76/*
77uint16_t
78dtrace_fuword16_nocheck(void *addr)
79*/
80ENTRY(dtrace_fuword16_nocheck)
81	ldrh	w0, [x0]
82	RET
83END(dtrace_fuword16_nocheck)
84
85/*
86uint32_t
87dtrace_fuword32_nocheck(void *addr)
88*/
89ENTRY(dtrace_fuword32_nocheck)
90	ldr	w0, [x0]
91	RET
92END(dtrace_fuword32_nocheck)
93
94/*
95uint64_t
96dtrace_fuword64_nocheck(void *addr)
97*/
98ENTRY(dtrace_fuword64_nocheck)
99	ldr	x0, [x0]
100	RET
101END(dtrace_fuword64_nocheck)
102
103/*
104void
105dtrace_copy(uintptr_t uaddr, uintptr_t kaddr, size_t size)
106*/
107ENTRY(dtrace_copy)
108	cbz	x2, 2f		/* If len == 0 then skip loop */
1091:
110	ldrb	w4, [x0], #1	/* Load from uaddr */
111	strb	w4, [x1], #1	/* Store in kaddr */
112	sub	x2, x2, #1	/* len-- */
113	cbnz	x2, 1b
1142:
115	RET
116END(dtrace_copy)
117
118/*
119void
120dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size,
121    volatile uint16_t *flags)
122XXX: Check for flags?
123*/
124ENTRY(dtrace_copystr)
125	cbz     x2, 2f          /* If len == 0 then skip loop */
126
1271:	ldrb    w4, [x0], #1    /* Load from uaddr */
128	strb    w4, [x1], #1    /* Store in kaddr */
129	cbz     w4, 2f          /* If == 0 then break */
130	sub     x2, x2, #1      /* len-- */
131	cbnz    x2, 1b
1322:
133	RET
134END(dtrace_copystr)
135
136/*
137uintptr_t
138dtrace_caller(int aframes)
139*/
140ENTRY(dtrace_caller)
141	mov	x0, #-1
142	RET
143END(dtrace_caller)
144
145/*
146uint32_t
147dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new)
148*/
149ENTRY(dtrace_cas32)
1501:	ldxr	w3, [x0]	/* Load target */
151	cmp	w3, w1		/* Check if *target == cmp */
152	bne	2f		/* No, return */
153	stxr	w12, w2, [x0]	/* Store new to target */
154	cbnz	w12, 1b		/* Try again if store not succeed */
1552:	mov	w0, w3		/* Return the value loaded from target */
156	RET
157END(dtrace_cas32)
158
159/*
160void *
161dtrace_casptr(volatile void *target, volatile void *cmp, volatile void *new)
162*/
163ENTRY(dtrace_casptr)
1641:	ldxr	x3, [x0]	/* Load target */
165	cmp	x3, x1		/* Check if *target == cmp */
166	bne	2f		/* No, return */
167	stxr	w12, x2, [x0]	/* Store new to target */
168	cbnz	w12, 1b		/* Try again if store not succeed */
1692:	mov	x0, x3		/* Return the value loaded from target */
170	RET
171END(dtrace_casptr)
172