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 * Portions Copyright 2016 Ruslan Bukin <br@bsdpad.com> 23 * 24 * $FreeBSD$ 25 */ 26/* 27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28 * Use is subject to license terms. 29 */ 30 31#define _ASM 32#define _LOCORE 33 34#include <sys/cpuvar_defs.h> 35#include <sys/dtrace.h> 36 37#include <machine/riscvreg.h> 38#include <machine/asm.h> 39 40#include "assym.s" 41 42/* 43void dtrace_membar_producer(void) 44*/ 45ENTRY(dtrace_membar_producer) 46 RET 47END(dtrace_membar_producer) 48 49/* 50void dtrace_membar_consumer(void) 51*/ 52ENTRY(dtrace_membar_consumer) 53 RET 54END(dtrace_membar_consumer) 55 56/* 57dtrace_icookie_t dtrace_interrupt_disable(void) 58*/ 59ENTRY(dtrace_interrupt_disable) 60 csrci sstatus, 1 61 RET 62END(dtrace_interrupt_disable) 63 64/* 65void dtrace_interrupt_enable(dtrace_icookie_t cookie) 66*/ 67ENTRY(dtrace_interrupt_enable) 68 csrsi sstatus, 1 69 RET 70END(dtrace_interrupt_enable) 71/* 72uint8_t 73dtrace_fuword8_nocheck(void *addr) 74*/ 75ENTRY(dtrace_fuword8_nocheck) 76 lb a0, 0(a0) 77 RET 78END(dtrace_fuword8_nocheck) 79 80/* 81uint16_t 82dtrace_fuword16_nocheck(void *addr) 83*/ 84ENTRY(dtrace_fuword16_nocheck) 85 lh a0, 0(a0) 86 RET 87END(dtrace_fuword16_nocheck) 88 89/* 90uint32_t 91dtrace_fuword32_nocheck(void *addr) 92*/ 93ENTRY(dtrace_fuword32_nocheck) 94 lw a0, 0(a0) 95 RET 96END(dtrace_fuword32_nocheck) 97 98/* 99uint64_t 100dtrace_fuword64_nocheck(void *addr) 101*/ 102ENTRY(dtrace_fuword64_nocheck) 103 ld a0, 0(a0) 104 RET 105END(dtrace_fuword64_nocheck) 106 107/* 108void 109dtrace_copy(uintptr_t uaddr, uintptr_t kaddr, size_t size) 110*/ 111ENTRY(dtrace_copy) 112 beqz a2, 2f /* If len == 0 then skip loop */ 1131: 114 lb a4, 0(a0) /* Load from uaddr */ 115 addi a0, a0, 1 116 sb a4, 0(a1) /* Store in kaddr */ 117 addi a1, a1, 1 118 addi a2, a2, -1 /* len-- */ 119 bnez a2, 1b 1202: 121 RET 122END(dtrace_copy) 123 124/* 125void 126dtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size, 127 volatile uint16_t *flags) 128XXX: Check for flags? 129*/ 130ENTRY(dtrace_copystr) 131 beqz a2, 2f /* If len == 0 then skip loop */ 132 lb a4, 0(a0) /* Load from uaddr */ 133 addi a0, a0, 1 134 sb a4, 0(a1) /* Store in kaddr */ 135 addi a1, a1, 1 136 beqz a4, 2f /* If == 0 then break */ 137 addi a2, a2, -1 /* len-- */ 138 bnez a2, 1b 1392: 140 RET 141END(dtrace_copystr) 142 143/* 144uintptr_t 145dtrace_caller(int aframes) 146*/ 147ENTRY(dtrace_caller) 148 li a0, -1 149 RET 150END(dtrace_caller) 151 152/* 153uint32_t 154dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new) 155*/ 156ENTRY(dtrace_cas32) 1571: lr.w a3, 0(a0) /* Load target */ 158 bne a3, a1, 2f /* *target != cmp ? return */ 159 sc.w a4, a2, 0(a0) /* Store new to target */ 160 bnez a4, 1b /* Try again if store not succeed */ 1612: mv a0, a3 /* Return the value loaded from target */ 162 RET 163END(dtrace_cas32) 164 165/* 166void * 167dtrace_casptr(volatile void *target, volatile void *cmp, volatile void *new) 168*/ 169ENTRY(dtrace_casptr) 1701: lr.d a3, 0(a0) /* Load target */ 171 bne a3, a1, 2f /* *target != cmp ? return */ 172 sc.d a4, a2, 0(a0) /* Store new to target */ 173 bnez a4, 1b /* Try again if store not succeed */ 1742: mv a0, a3 /* Return the value loaded from target */ 175 RET 176END(dtrace_casptr) 177