1 /*- 2 * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com> 3 * All rights reserved. 4 * 5 * Portions of this software were developed by SRI International and the 6 * University of Cambridge Computer Laboratory under DARPA/AFRL contract 7 * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme. 8 * 9 * Portions of this software were developed by the University of Cambridge 10 * Computer Laboratory as part of the CTSRD Project, with support from the 11 * UK Higher Education Innovation Fund (HEIF). 12 * 13 * Redistribution and use in source and binary forms, with or without 14 * modification, are permitted provided that the following conditions 15 * are met: 16 * 1. Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 2. Redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 */ 34 35 #include <sys/cdefs.h> 36 __FBSDID("$FreeBSD$"); 37 38 #include <sys/types.h> 39 #include <string.h> 40 #include <thread_db.h> 41 42 #include "libpthread_db.h" 43 44 void 45 pt_reg_to_ucontext(const struct reg *r, ucontext_t *uc) 46 { 47 mcontext_t *mc; 48 49 mc = &uc->uc_mcontext; 50 51 memcpy(mc->mc_gpregs.gp_t, r->t, sizeof(mc->mc_gpregs.gp_t)); 52 memcpy(mc->mc_gpregs.gp_s, r->s, sizeof(mc->mc_gpregs.gp_s)); 53 memcpy(mc->mc_gpregs.gp_a, r->a, sizeof(mc->mc_gpregs.gp_a)); 54 mc->mc_gpregs.gp_ra = r->ra; 55 mc->mc_gpregs.gp_sp = r->sp; 56 mc->mc_gpregs.gp_gp = r->gp; 57 mc->mc_gpregs.gp_tp = r->tp; 58 mc->mc_gpregs.gp_sepc = r->sepc; 59 mc->mc_gpregs.gp_sstatus = r->sstatus; 60 } 61 62 void 63 pt_ucontext_to_reg(const ucontext_t *uc, struct reg *r) 64 { 65 const mcontext_t *mc; 66 67 mc = &uc->uc_mcontext; 68 69 memcpy(r->t, mc->mc_gpregs.gp_t, sizeof(mc->mc_gpregs.gp_t)); 70 memcpy(r->s, mc->mc_gpregs.gp_s, sizeof(mc->mc_gpregs.gp_s)); 71 memcpy(r->a, mc->mc_gpregs.gp_a, sizeof(mc->mc_gpregs.gp_a)); 72 r->ra = mc->mc_gpregs.gp_ra; 73 r->sp = mc->mc_gpregs.gp_sp; 74 r->gp = mc->mc_gpregs.gp_gp; 75 r->tp = mc->mc_gpregs.gp_tp; 76 r->sepc = mc->mc_gpregs.gp_sepc; 77 r->sstatus = mc->mc_gpregs.gp_sstatus; 78 } 79 80 void 81 pt_fpreg_to_ucontext(const struct fpreg *r __unused, ucontext_t *uc __unused) 82 { 83 mcontext_t *mc = &uc->uc_mcontext; 84 85 memcpy(&mc->mc_fpregs, r, sizeof(*r)); 86 mc->mc_flags |= _MC_FP_VALID; 87 } 88 89 void 90 pt_ucontext_to_fpreg(const ucontext_t *uc __unused, struct fpreg *r __unused) 91 { 92 const mcontext_t *mc = &uc->uc_mcontext; 93 94 if (mc->mc_flags & _MC_FP_VALID) 95 memcpy(r, &mc->mc_fpregs, sizeof(*r)); 96 else 97 memset(r, 0, sizeof(*r)); 98 } 99 100 void 101 pt_md_init(void) 102 { 103 } 104 105 int 106 pt_reg_sstep(struct reg *reg __unused, int step __unused) 107 { 108 109 return (0); 110 } 111