libpthread_md.c revision 132950
162587Sitojun/* 278064Sume * Copyright (c) 2004 David Xu <davidxu@freebsd.org> 362587Sitojun * Copyright (c) 2004 Marcel Moolenaar 4139826Simp * All rights reserved. 553541Sshin * 653541Sshin * Redistribution and use in source and binary forms, with or without 753541Sshin * modification, are permitted provided that the following conditions 853541Sshin * are met: 953541Sshin * 1053541Sshin * 1. Redistributions of source code must retain the above copyright 1153541Sshin * notice, this list of conditions and the following disclaimer. 1253541Sshin * 2. Redistributions in binary form must reproduce the above copyright 1353541Sshin * notice, this list of conditions and the following disclaimer in the 1453541Sshin * documentation and/or other materials provided with the distribution. 1553541Sshin * 1653541Sshin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1753541Sshin * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1853541Sshin * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1953541Sshin * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2053541Sshin * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2153541Sshin * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2253541Sshin * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2353541Sshin * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2453541Sshin * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2553541Sshin * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2653541Sshin */ 2753541Sshin 2853541Sshin#include <sys/cdefs.h> 2953541Sshin__FBSDID("$FreeBSD: head/lib/libthread_db/arch/amd64/libpthread_md.c 132950 2004-08-01 02:08:39Z davidxu $"); 3053541Sshin 3153541Sshin#include <sys/procfs.h> 3253541Sshin#include <ucontext.h> 3362587Sitojun 3462587Sitojunvoid 3562587Sitojunpt_reg_to_ucontext(const struct reg *r, ucontext_t *uc) 3655009Sshin{ 3753541Sshin mcontext_t *mc = &uc->uc_mcontext; 3853541Sshin 3953541Sshin mc->mc_rdi = r->r_rdi; 4078064Sume mc->mc_rsi = r->r_rsi; 4153541Sshin mc->mc_rdx = r->r_rdx; 4253541Sshin mc->mc_rcx = r->r_rcx; 4353541Sshin mc->mc_r8 = r->r_r8; 4453541Sshin mc->mc_r9 = r->r_r9; 4553541Sshin mc->mc_rax = r->r_rax; 4653541Sshin mc->mc_rbx = r->r_rbx; 4778064Sume mc->mc_rbp = r->r_rbp; 4853541Sshin mc->mc_r10 = r->r_r10; 4953541Sshin mc->mc_r11 = r->r_r11; 5053541Sshin mc->mc_r12 = r->r_r12; 5153541Sshin mc->mc_r13 = r->r_r13; 5284994Sdarrenr mc->mc_r14 = r->r_r14; 5353541Sshin mc->mc_r15 = r->r_r15; 5453541Sshin mc->mc_rip = r->r_rip; 5553541Sshin mc->mc_cs = r->r_cs; 5678064Sume mc->mc_rflags = r->r_rflags; 5778064Sume mc->mc_rsp = r->r_rsp; 5862587Sitojun mc->mc_ss = r->r_ss; 5978064Sume} 6062587Sitojun 6153541Sshinvoid 62148385Sumept_ucontext_to_reg(const ucontext_t *uc, struct reg *r) 6362587Sitojun{ 6453541Sshin const mcontext_t *mc = &uc->uc_mcontext; 6553541Sshin 6678064Sume r->r_rdi = mc->mc_rdi; 6778064Sume r->r_rsi = mc->mc_rsi; 6863256Sitojun r->r_rdx = mc->mc_rdx; 6953541Sshin r->r_rcx = mc->mc_rcx; 7078064Sume r->r_r8 = mc->mc_r8; 7162601Sitojun r->r_r9 = mc->mc_r9; 7278064Sume r->r_rax = mc->mc_rax; 7353541Sshin r->r_rbx = mc->mc_rbx; 7463256Sitojun r->r_rbp = mc->mc_rbp; 7553541Sshin r->r_r10 = mc->mc_r10; 76105199Ssam r->r_r11 = mc->mc_r11; 77105199Ssam r->r_r12 = mc->mc_r12; 78105199Ssam r->r_r13 = mc->mc_r13; 79105199Ssam r->r_r14 = mc->mc_r14; 80105199Ssam r->r_r15 = mc->mc_r15; 81105199Ssam r->r_rip = mc->mc_rip; 82105199Ssam r->r_cs = mc->mc_cs; 8353541Sshin r->r_rflags = mc->mc_rflags; 8453541Sshin r->r_rsp = mc->mc_rsp; 8553541Sshin r->r_ss = mc->mc_ss; 8653541Sshin} 8784994Sdarrenr 8884994Sdarrenrvoid 8953541Sshinpt_fpreg_to_ucontext(const struct fpreg* r, ucontext_t *uc) 9053541Sshin{ 9153541Sshin memcpy(&uc->uc_mcontext.mc_fpstate, r, sizeof(r)); 9253541Sshin} 9353541Sshin 9453541Sshinvoid 9553541Sshinpt_ucontext_to_fpreg(const ucontext_t *uc, struct fpreg *r) 9653541Sshin{ 9753541Sshin memcpy(r, &uc->uc_mcontext.mc_fpstate, sizeof(r)); 9853541Sshin} 9953541Sshin 10053541Sshinvoid 10153541Sshinpt_md_init(void) 10253541Sshin{ 10353541Sshin /* Nothing to do */ 10453541Sshin} 10553541Sshin 10653541Sshinint 10753541Sshinpt_reg_sstep(struct reg *reg, int step) 10853541Sshin{ 10953541Sshin register_t old; 110122062Sume 111122062Sume old = reg->r_rflags; 11253541Sshin if (step) 11362587Sitojun reg->r_rflags |= 0x0100; 11462587Sitojun else 115148385Sume reg->r_rflags &= ~0x0100; 116148385Sume return (old != reg->r_rflags); /* changed ? */ 11763256Sitojun} 11853541Sshin