1139790Simp/*- 2118933Smarcel * Copyright (c) 2003 Marcel Moolenaar 3118933Smarcel * All rights reserved. 4118933Smarcel * 5118933Smarcel * Redistribution and use in source and binary forms, with or without 6118933Smarcel * modification, are permitted provided that the following conditions 7118933Smarcel * are met: 8118933Smarcel * 9118933Smarcel * 1. Redistributions of source code must retain the above copyright 10118933Smarcel * notice, this list of conditions and the following disclaimer. 11118933Smarcel * 2. Redistributions in binary form must reproduce the above copyright 12118933Smarcel * notice, this list of conditions and the following disclaimer in the 13118933Smarcel * documentation and/or other materials provided with the distribution. 14118933Smarcel * 15118933Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16118933Smarcel * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17118933Smarcel * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18118933Smarcel * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19118933Smarcel * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20118933Smarcel * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21118933Smarcel * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22118933Smarcel * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23118933Smarcel * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24118933Smarcel * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25118933Smarcel */ 26118933Smarcel 27118933Smarcel#include <sys/cdefs.h> 28118933Smarcel__FBSDID("$FreeBSD$"); 29118933Smarcel 30118933Smarcel#include <sys/param.h> 31118933Smarcel#include <sys/systm.h> 32118933Smarcel#include <sys/proc.h> 33118933Smarcel#include <sys/ptrace.h> 34118933Smarcel#include <machine/frame.h> 35118933Smarcel 36118933Smarcelint 37118933Smarcelcpu_ptrace(struct thread *td, int req, void *addr, int data) 38118933Smarcel{ 39118933Smarcel struct trapframe *tf; 40118933Smarcel uint64_t *kstack; 41118933Smarcel int error; 42118933Smarcel 43118981Smarcel error = EINVAL; 44118981Smarcel tf = td->td_frame; 45118981Smarcel 46118933Smarcel switch (req) { 47118933Smarcel case PT_GETKSTACK: 48118981Smarcel if (data >= 0 && data < (tf->tf_special.ndirty >> 3)) { 49121635Smarcel kstack = (uint64_t*)(td->td_kstack + 50121635Smarcel (tf->tf_special.bspstore & 0x1ffUL)); 51118933Smarcel error = copyout(kstack + data, addr, 8); 52118981Smarcel } 53118933Smarcel break; 54118933Smarcel case PT_SETKSTACK: 55118981Smarcel if (data >= 0 && data < (tf->tf_special.ndirty >> 3)) { 56121635Smarcel kstack = (uint64_t*)(td->td_kstack + 57121635Smarcel (tf->tf_special.bspstore & 0x1ffUL)); 58118933Smarcel error = copyin(addr, kstack + data, 8); 59118981Smarcel } 60118933Smarcel break; 61118933Smarcel } 62118933Smarcel 63118933Smarcel return (error); 64118933Smarcel} 65