1130803Smarcel/* Target-dependent code for FreeBSD/amd64. 2130803Smarcel 3130803Smarcel Copyright 2003, 2004 Free Software Foundation, Inc. 4130803Smarcel 5130803Smarcel This file is part of GDB. 6130803Smarcel 7130803Smarcel This program is free software; you can redistribute it and/or modify 8130803Smarcel it under the terms of the GNU General Public License as published by 9130803Smarcel the Free Software Foundation; either version 2 of the License, or 10130803Smarcel (at your option) any later version. 11130803Smarcel 12130803Smarcel This program is distributed in the hope that it will be useful, 13130803Smarcel but WITHOUT ANY WARRANTY; without even the implied warranty of 14130803Smarcel MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15130803Smarcel GNU General Public License for more details. 16130803Smarcel 17130803Smarcel You should have received a copy of the GNU General Public License 18130803Smarcel along with this program; if not, write to the Free Software 19130803Smarcel Foundation, Inc., 59 Temple Place - Suite 330, 20130803Smarcel Boston, MA 02111-1307, USA. */ 21130803Smarcel 22130803Smarcel#include "defs.h" 23130803Smarcel#include "arch-utils.h" 24130803Smarcel#include "frame.h" 25130803Smarcel#include "gdbcore.h" 26130803Smarcel#include "regcache.h" 27130803Smarcel#include "osabi.h" 28130803Smarcel 29130803Smarcel#include "gdb_string.h" 30130803Smarcel 31130803Smarcel#include "amd64-tdep.h" 32130803Smarcel#include "solib-svr4.h" 33130803Smarcel 34130803Smarcel/* Support for signal handlers. */ 35130803Smarcel 36130803Smarcel/* Assuming NEXT_FRAME is for a frame following a BSD sigtramp 37130803Smarcel routine, return the address of the associated sigcontext structure. */ 38130803Smarcel 39130803Smarcelstatic CORE_ADDR 40130803Smarcelamd64fbsd_sigcontext_addr (struct frame_info *next_frame) 41130803Smarcel{ 42130803Smarcel CORE_ADDR sp; 43130803Smarcel 44130803Smarcel /* The `struct sigcontext' (which really is an `ucontext_t' on 45130803Smarcel FreeBSD/amd64) lives at a fixed offset in the signal frame. See 46130803Smarcel <machine/sigframe.h>. */ 47130803Smarcel sp = frame_unwind_register_unsigned (next_frame, AMD64_RSP_REGNUM); 48130803Smarcel return sp + 16; 49130803Smarcel} 50130803Smarcel 51130803Smarcel/* FreeBSD 5.1-RELEASE or later. */ 52130803Smarcel 53130803Smarcel/* Mapping between the general-purpose registers in `struct reg' 54130803Smarcel format and GDB's register cache layout. 55130803Smarcel 56130803Smarcel Note that some registers are 32-bit, but since we're little-endian 57130803Smarcel we get away with that. */ 58130803Smarcel 59130803Smarcel/* From <machine/reg.h>. */ 60130803Smarcelstatic int amd64fbsd_r_reg_offset[] = 61130803Smarcel{ 62130803Smarcel 14 * 8, /* %rax */ 63130803Smarcel 11 * 8, /* %rbx */ 64130803Smarcel 13 * 8, /* %rcx */ 65130803Smarcel 12 * 8, /* %rdx */ 66130803Smarcel 9 * 8, /* %rsi */ 67130803Smarcel 8 * 8, /* %rdi */ 68130803Smarcel 10 * 8, /* %rbp */ 69130803Smarcel 20 * 8, /* %rsp */ 70130803Smarcel 7 * 8, /* %r8 ... */ 71130803Smarcel 6 * 8, 72130803Smarcel 5 * 8, 73130803Smarcel 4 * 8, 74130803Smarcel 3 * 8, 75130803Smarcel 2 * 8, 76130803Smarcel 1 * 8, 77130803Smarcel 0 * 8, /* ... %r15 */ 78130803Smarcel 17 * 8, /* %rip */ 79130803Smarcel 19 * 8, /* %eflags */ 80130803Smarcel 18 * 8, /* %cs */ 81130803Smarcel 21 * 8, /* %ss */ 82130803Smarcel -1, /* %ds */ 83130803Smarcel -1, /* %es */ 84130803Smarcel -1, /* %fs */ 85130803Smarcel -1 /* %gs */ 86130803Smarcel}; 87130803Smarcel 88130803Smarcel/* Location of the signal trampoline. */ 89130803SmarcelCORE_ADDR amd64fbsd_sigtramp_start_addr = 0x7fffffffffc0; 90130803SmarcelCORE_ADDR amd64fbsd_sigtramp_end_addr = 0x7fffffffffe0; 91130803Smarcel 92130803Smarcel/* From <machine/signal.h>. */ 93130803Smarcelint amd64fbsd_sc_reg_offset[] = 94130803Smarcel{ 95130803Smarcel 24 + 6 * 8, /* %rax */ 96130803Smarcel 24 + 7 * 8, /* %rbx */ 97130803Smarcel 24 + 3 * 8, /* %rcx */ 98130803Smarcel 24 + 2 * 8, /* %rdx */ 99130803Smarcel 24 + 1 * 8, /* %rsi */ 100130803Smarcel 24 + 0 * 8, /* %rdi */ 101130803Smarcel 24 + 8 * 8, /* %rbp */ 102130803Smarcel 24 + 22 * 8, /* %rsp */ 103130803Smarcel 24 + 4 * 8, /* %r8 ... */ 104130803Smarcel 24 + 5 * 8, 105130803Smarcel 24 + 9 * 8, 106130803Smarcel 24 + 10 * 8, 107130803Smarcel 24 + 11 * 8, 108130803Smarcel 24 + 12 * 8, 109130803Smarcel 24 + 13 * 8, 110130803Smarcel 24 + 14 * 8, /* ... %r15 */ 111130803Smarcel 24 + 19 * 8, /* %rip */ 112130803Smarcel 24 + 21 * 8, /* %eflags */ 113130803Smarcel 24 + 20 * 8, /* %cs */ 114130803Smarcel 24 + 23 * 8, /* %ss */ 115130803Smarcel -1, /* %ds */ 116130803Smarcel -1, /* %es */ 117130803Smarcel -1, /* %fs */ 118130803Smarcel -1 /* %gs */ 119130803Smarcel}; 120130803Smarcel 121130803Smarcelvoid 122130803Smarcelamd64fbsd_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) 123130803Smarcel{ 124130803Smarcel struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); 125130803Smarcel 126130803Smarcel /* Obviously FreeBSD is BSD-based. */ 127130803Smarcel i386bsd_init_abi (info, gdbarch); 128130803Smarcel 129130803Smarcel tdep->gregset_reg_offset = amd64fbsd_r_reg_offset; 130130803Smarcel tdep->gregset_num_regs = ARRAY_SIZE (amd64fbsd_r_reg_offset); 131130803Smarcel tdep->sizeof_gregset = 22 * 8; 132130803Smarcel 133130803Smarcel amd64_init_abi (info, gdbarch); 134130803Smarcel 135130803Smarcel tdep->sigtramp_start = amd64fbsd_sigtramp_start_addr; 136130803Smarcel tdep->sigtramp_end = amd64fbsd_sigtramp_end_addr; 137130803Smarcel tdep->sigcontext_addr = amd64fbsd_sigcontext_addr; 138130803Smarcel tdep->sc_reg_offset = amd64fbsd_sc_reg_offset; 139130803Smarcel tdep->sc_num_regs = ARRAY_SIZE (amd64fbsd_sc_reg_offset); 140130803Smarcel 141130803Smarcel /* FreeBSD uses SVR4-style shared libraries. */ 142130803Smarcel set_solib_svr4_fetch_link_map_offsets 143130803Smarcel (gdbarch, svr4_lp64_fetch_link_map_offsets); 144130803Smarcel} 145130803Smarcel 146130803Smarcel 147130803Smarcel/* Provide a prototype to silence -Wmissing-prototypes. */ 148130803Smarcelvoid _initialize_amd64fbsd_tdep (void); 149130803Smarcel 150130803Smarcelvoid 151130803Smarcel_initialize_amd64fbsd_tdep (void) 152130803Smarcel{ 153130803Smarcel gdbarch_register_osabi (bfd_arch_i386, bfd_mach_x86_64, 154130803Smarcel GDB_OSABI_FREEBSD_ELF, amd64fbsd_init_abi); 155130803Smarcel} 156