1c7570492SJustin Hibbits/* 2c7570492SJustin Hibbits * CDDL HEADER START 3c7570492SJustin Hibbits * 4c7570492SJustin Hibbits * The contents of this file are subject to the terms of the 5c7570492SJustin Hibbits * Common Development and Distribution License, Version 1.0 only 6c7570492SJustin Hibbits * (the "License"). You may not use this file except in compliance 7c7570492SJustin Hibbits * with the License. 8c7570492SJustin Hibbits * 9c7570492SJustin Hibbits * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10c7570492SJustin Hibbits * or http://www.opensolaris.org/os/licensing. 11c7570492SJustin Hibbits * See the License for the specific language governing permissions 12c7570492SJustin Hibbits * and limitations under the License. 13c7570492SJustin Hibbits * 14c7570492SJustin Hibbits * When distributing Covered Code, include this CDDL HEADER in each 15c7570492SJustin Hibbits * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16c7570492SJustin Hibbits * If applicable, add the following below this CDDL HEADER, with the 17c7570492SJustin Hibbits * fields enclosed by brackets "[]" replaced with your own identifying 18c7570492SJustin Hibbits * information: Portions Copyright [yyyy] [name of copyright owner] 19c7570492SJustin Hibbits * 20c7570492SJustin Hibbits * CDDL HEADER END 21c7570492SJustin Hibbits * 22*7e7a9efdSJustin Hibbits * Portions Copyright 2012,2013 Justin Hibbits <jhibbits@freebsd.org> 23*7e7a9efdSJustin Hibbits * 24c7570492SJustin Hibbits * $FreeBSD$ 25c7570492SJustin Hibbits */ 26c7570492SJustin Hibbits/* 27c7570492SJustin Hibbits * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 28c7570492SJustin Hibbits * Use is subject to license terms. 29c7570492SJustin Hibbits */ 30c7570492SJustin Hibbits 31c7570492SJustin Hibbits#include "assym.s" 32c7570492SJustin Hibbits 33c7570492SJustin Hibbits#define _ASM 34c7570492SJustin Hibbits 35c7570492SJustin Hibbits#include <sys/cpuvar_defs.h> 36c7570492SJustin Hibbits#include <sys/dtrace.h> 37c7570492SJustin Hibbits 38c7570492SJustin Hibbits#include <machine/asm.h> 39c7570492SJustin Hibbits/* 40c7570492SJustin Hibbits#include <machine/cpu.h> 41c7570492SJustin Hibbits*/ 42c7570492SJustin Hibbits 43c7570492SJustin Hibbits/* 44c7570492SJustin Hibbits * Primitives 45c7570492SJustin Hibbits */ 46c7570492SJustin Hibbits 47c7570492SJustin Hibbits .text 48c7570492SJustin Hibbits 49c7570492SJustin Hibbits/* 50c7570492SJustin Hibbitsvoid dtrace_membar_producer(void) 51c7570492SJustin Hibbits*/ 52c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_membar_producer) 53c7570492SJustin Hibbits blr 54c7570492SJustin HibbitsEND(dtrace_membar_producer) 55c7570492SJustin Hibbits 56c7570492SJustin Hibbits/* 57c7570492SJustin Hibbitsvoid dtrace_membar_consumer(void) 58c7570492SJustin Hibbits*/ 59c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_membar_consumer) 60c7570492SJustin Hibbits blr 61c7570492SJustin HibbitsEND(dtrace_membar_consumer) 62c7570492SJustin Hibbits 63c7570492SJustin Hibbits/* 64c7570492SJustin Hibbitsdtrace_icookie_t dtrace_interrupt_disable(void) 65c7570492SJustin Hibbits*/ 66c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_interrupt_disable) 67c7570492SJustin Hibbits mfmsr %r3 68c7570492SJustin Hibbits andi. %r0,%r3,~PSL_EE@l 69c7570492SJustin Hibbits mtmsr %r0 70c7570492SJustin Hibbits blr 71c7570492SJustin HibbitsEND(dtrace_interrupt_disable) 72c7570492SJustin Hibbits 73c7570492SJustin Hibbits/* 74c7570492SJustin Hibbitsvoid dtrace_interrupt_enable(dtrace_icookie_t cookie) 75c7570492SJustin Hibbits*/ 76c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_interrupt_enable) 77c7570492SJustin Hibbits mtmsr %r3 78c7570492SJustin Hibbits blr 79c7570492SJustin HibbitsEND(dtrace_interrupt_enable) 80c7570492SJustin Hibbits 81c7570492SJustin Hibbits/* 82c7570492SJustin Hibbitsuint32_t dtrace_cas32(uint32_t *target, uint32_t cmp, uint32_t new) 83c7570492SJustin Hibbits*/ 84c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_cas32) 85c7570492SJustin Hibbits1: 86c7570492SJustin Hibbits lwarx %r0,0,%r3 87c7570492SJustin Hibbits cmpw %r4,%r0 88c7570492SJustin Hibbits bne 2f 89c7570492SJustin Hibbits stwcx. %r5,0,%r3 90c7570492SJustin Hibbits bne 1b 91c7570492SJustin Hibbits2: mr %r3,%r0 92c7570492SJustin Hibbits blr 93c7570492SJustin HibbitsEND(dtrace_cas32) 94c7570492SJustin Hibbits 95c7570492SJustin Hibbits/* 96c7570492SJustin Hibbitsvoid * 97c7570492SJustin Hibbitsdtrace_casptr(void *target, void *cmp, void *new) 98c7570492SJustin Hibbits*/ 99c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_casptr) 100c7570492SJustin Hibbits1: 101c7570492SJustin Hibbits lwarx %r0,0,%r3 102c7570492SJustin Hibbits cmpw %r4,%r0 103c7570492SJustin Hibbits bne 2f 104c7570492SJustin Hibbits stwcx. %r5,0,%r3 105c7570492SJustin Hibbits bne 1b 106c7570492SJustin Hibbits2: mr %r3,%r0 107c7570492SJustin Hibbits blr 108c7570492SJustin HibbitsEND(dtrace_casptr) 109c7570492SJustin Hibbits 110c7570492SJustin Hibbits 111c7570492SJustin Hibbits/* 112c7570492SJustin Hibbitsuintptr_t 113c7570492SJustin Hibbitsdtrace_fulword(void *addr) 114c7570492SJustin Hibbits*/ 115c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_fulword) 116c7570492SJustin HibbitsEND(dtrace_fulword) 117c7570492SJustin Hibbits 118c7570492SJustin Hibbits/* 119c7570492SJustin HibbitsXXX: unoptimized 120c7570492SJustin Hibbitsvoid 121c7570492SJustin Hibbitsdtrace_copy(uintptr_t src, uintptr_t dest, size_t size) 122c7570492SJustin Hibbits*/ 123c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_copy) 124c7570492SJustin Hibbits addme %r7,%r3 125c7570492SJustin Hibbits addme %r8,%r4 126c7570492SJustin Hibbits1: 127c7570492SJustin Hibbits lbzu %r3,1(%r7) 128c7570492SJustin Hibbits stbu %r3,1(%r8) 129c7570492SJustin Hibbits addme %r5,%r5 130c7570492SJustin Hibbits beq 2f 131c7570492SJustin Hibbits2: 132c7570492SJustin Hibbits blr 133c7570492SJustin HibbitsEND(dtrace_copy) 134c7570492SJustin Hibbits 135c7570492SJustin Hibbits/* 136c7570492SJustin Hibbitsvoid 137c7570492SJustin Hibbitsdtrace_copystr(uintptr_t uaddr, uintptr_t kaddr, size_t size, 138c7570492SJustin Hibbits volatile uint16_t *flags) 139c7570492SJustin Hibbits*/ 140c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_copystr) 141c7570492SJustin Hibbits addme %r7,%r3 142c7570492SJustin Hibbits addme %r8,%r4 143c7570492SJustin Hibbits1: 144c7570492SJustin Hibbits lbzu %r3,1(%r7) 145c7570492SJustin Hibbits stbu %r3,1(%r8) 146c7570492SJustin Hibbits addme %r5,%r5 147c7570492SJustin Hibbits beq 2f 148c7570492SJustin Hibbits or %r3,%r3,%r3 149c7570492SJustin Hibbits beq 2f 150c7570492SJustin Hibbits andi. %r0,%r5,0x0fff 151c7570492SJustin Hibbits beq 2f 152c7570492SJustin Hibbits lwz %r0,0(%r6) 153c7570492SJustin Hibbits andi. %r0,%r0,CPU_DTRACE_BADADDR 154c7570492SJustin Hibbits beq 1b 155c7570492SJustin Hibbits2: 156c7570492SJustin Hibbits blr 157c7570492SJustin HibbitsEND(dtrace_copystr) 158c7570492SJustin Hibbits 159c7570492SJustin Hibbits/* 160c7570492SJustin Hibbitsvoid dtrace_invop_init(void) 161c7570492SJustin Hibbits*/ 162c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_invop_init) 163c7570492SJustin Hibbits /* XXX: impement it properly -- implement dtrace_invop_start */ 164c7570492SJustin Hibbits li %r0,0 165c7570492SJustin Hibbits li %r3,dtrace_invop_jump_addr@l 166c7570492SJustin Hibbits addis %r3,%r3,dtrace_invop_jump_addr@ha 167c7570492SJustin Hibbits stw %r0,0(%r3) 168c7570492SJustin Hibbits blr 169c7570492SJustin HibbitsEND(dtrace_invop_init) 170c7570492SJustin Hibbits 171c7570492SJustin Hibbits/* 172c7570492SJustin Hibbitsvoid dtrace_invop_uninit(void) 173c7570492SJustin Hibbits*/ 174c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_invop_uninit) 175c7570492SJustin Hibbits li %r0,0 176c7570492SJustin Hibbits li %r3,dtrace_invop_jump_addr@l 177c7570492SJustin Hibbits addis %r3,%r3,dtrace_invop_jump_addr@ha 178c7570492SJustin Hibbits stw %r0,0(%r3) 179c7570492SJustin Hibbits blr 180c7570492SJustin HibbitsEND(dtrace_invop_uninit) 181c7570492SJustin Hibbits 182c7570492SJustin Hibbits/* 183c7570492SJustin Hibbits * The panic() and cmn_err() functions invoke vpanic() as a common entry point 184c7570492SJustin Hibbits * into the panic code implemented in panicsys(). vpanic() is responsible 185c7570492SJustin Hibbits * for passing through the format string and arguments, and constructing a 186c7570492SJustin Hibbits * regs structure on the stack into which it saves the current register 187c7570492SJustin Hibbits * values. If we are not dying due to a fatal trap, these registers will 188c7570492SJustin Hibbits * then be preserved in panicbuf as the current processor state. Before 189c7570492SJustin Hibbits * invoking panicsys(), vpanic() activates the first panic trigger (see 190c7570492SJustin Hibbits * common/os/panic.c) and switches to the panic_stack if successful. Note that 191c7570492SJustin Hibbits * DTrace takes a slightly different panic path if it must panic from probe 192c7570492SJustin Hibbits * context. Instead of calling panic, it calls into dtrace_vpanic(), which 193c7570492SJustin Hibbits * sets up the initial stack as vpanic does, calls dtrace_panic_trigger(), and 194c7570492SJustin Hibbits * branches back into vpanic(). 195c7570492SJustin Hibbits */ 196c7570492SJustin Hibbits 197c7570492SJustin Hibbits/* 198c7570492SJustin Hibbitsvoid 199c7570492SJustin Hibbitsvpanic(const char *format, va_list alist) 200c7570492SJustin Hibbits*/ 201c7570492SJustin HibbitsASENTRY_NOPROF(vpanic) /* Initial stack layout: */ 202c7570492SJustin Hibbits 203c7570492SJustin Hibbitsvpanic_common: 204c7570492SJustin Hibbits blr 205c7570492SJustin HibbitsEND(vpanic) 206c7570492SJustin Hibbits 207c7570492SJustin Hibbits 208c7570492SJustin Hibbits 209c7570492SJustin Hibbits/* 210c7570492SJustin Hibbitsvoid 211c7570492SJustin Hibbitsdtrace_vpanic(const char *format, va_list alist) 212c7570492SJustin Hibbits*/ 213c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_vpanic) /* Initial stack layout: */ 214c7570492SJustin Hibbits 215c7570492SJustin Hibbits#if 0 216c7570492SJustin Hibbits bl dtrace_panic_trigger /* %eax = dtrace_panic_trigger() */ 217c7570492SJustin Hibbits#endif 218c7570492SJustin Hibbits b vpanic_common 219c7570492SJustin HibbitsEND(dtrace_vpanic) 220c7570492SJustin Hibbits 221c7570492SJustin Hibbits/* 222c7570492SJustin Hibbitsuintptr_t 223c7570492SJustin Hibbitsdtrace_caller(int aframes) 224c7570492SJustin Hibbits*/ 225c7570492SJustin HibbitsASENTRY_NOPROF(dtrace_caller) 226c7570492SJustin Hibbits li %r3, -1 227c7570492SJustin Hibbits blr 228c7570492SJustin HibbitsEND(dtrace_caller) 229c7570492SJustin Hibbits 230