Planeshift

minidump_cpu_amd64.h

Go to the documentation of this file.
00001 /* Copyright (c) 2006, Google Inc.
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are
00006  * met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  * notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above
00011  * copyright notice, this list of conditions and the following disclaimer
00012  * in the documentation and/or other materials provided with the
00013  * distribution.
00014  *     * Neither the name of Google Inc. nor the names of its
00015  * contributors may be used to endorse or promote products derived from
00016  * this software without specific prior written permission.
00017  *
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00022  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00023  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00024  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00025  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00026  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00028  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
00029 
00030 /* minidump_format.h: A cross-platform reimplementation of minidump-related
00031  * portions of DbgHelp.h from the Windows Platform SDK.
00032  *
00033  * (This is C99 source, please don't corrupt it with C++.)
00034  *
00035  * This file contains the necessary definitions to read minidump files
00036  * produced on amd64.  These files may be read on any platform provided
00037  * that the alignments of these structures on the processing system are
00038  * identical to the alignments of these structures on the producing system.
00039  * For this reason, precise-sized types are used.  The structures defined
00040  * by this file have been laid out to minimize alignment problems by ensuring
00041  * ensuring that all members are aligned on their natural boundaries.  In
00042  * In some cases, tail-padding may be significant when different ABIs specify
00043  * different tail-padding behaviors.  To avoid problems when reading or
00044  * writing affected structures, MD_*_SIZE macros are provided where needed,
00045  * containing the useful size of the structures without padding.
00046  *
00047  * Structures that are defined by Microsoft to contain a zero-length array
00048  * are instead defined here to contain an array with one element, as
00049  * zero-length arrays are forbidden by standard C and C++.  In these cases,
00050  * *_minsize constants are provided to be used in place of sizeof.  For a
00051  * cleaner interface to these sizes when using C++, see minidump_size.h.
00052  *
00053  * These structures are also sufficient to populate minidump files.
00054  *
00055  * These definitions may be extended to support handling minidump files
00056  * for other CPUs and other operating systems.
00057  *
00058  * Because precise data type sizes are crucial for this implementation to
00059  * function properly and portably in terms of interoperability with minidumps
00060  * produced by DbgHelp on Windows, a set of primitive types with known sizes
00061  * are used as the basis of each structure defined by this file.  DbgHelp
00062  * on Windows is assumed to be the reference implementation; this file
00063  * seeks to provide a cross-platform compatible implementation.  To avoid
00064  * collisions with the types and values defined and used by DbgHelp in the
00065  * event that this implementation is used on Windows, each type and value
00066  * defined here is given a new name, beginning with "MD".  Names of the
00067  * equivalent types and values in the Windows Platform SDK are given in
00068  * comments.
00069  *
00070  * Author: Mark Mentovai
00071  * Change to split into its own file: Neal Sidhwaney */
00072 
00073 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__
00074 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__
00075 
00076 
00077 /*
00078  * AMD64 support, see WINNT.H
00079  */
00080 
00081 typedef struct {
00082   uint16_t       control_word;
00083   uint16_t       status_word;
00084   uint8_t        tag_word;
00085   uint8_t        reserved1;
00086   uint16_t       error_opcode;
00087   uint32_t       error_offset;
00088   uint16_t       error_selector;
00089   uint16_t       reserved2;
00090   uint32_t       data_offset;
00091   uint16_t       data_selector;
00092   uint16_t       reserved3;
00093   uint32_t       mx_csr;
00094   uint32_t       mx_csr_mask;
00095   uint128_struct float_registers[8];
00096   uint128_struct xmm_registers[16];
00097   uint8_t        reserved4[96];
00098 } MDXmmSaveArea32AMD64;  /* XMM_SAVE_AREA32 */
00099 
00100 #define MD_CONTEXT_AMD64_VR_COUNT 26
00101 
00102 typedef struct {
00103   /*
00104    * Register parameter home addresses.
00105    */
00106   uint64_t  p1_home;
00107   uint64_t  p2_home;
00108   uint64_t  p3_home;
00109   uint64_t  p4_home;
00110   uint64_t  p5_home;
00111   uint64_t  p6_home;
00112 
00113   /* The next field determines the layout of the structure, and which parts
00114    * of it are populated */
00115   uint32_t  context_flags;
00116   uint32_t  mx_csr;
00117 
00118   /* The next register is included with MD_CONTEXT_AMD64_CONTROL */
00119   uint16_t  cs;
00120 
00121   /* The next 4 registers are included with MD_CONTEXT_AMD64_SEGMENTS */
00122   uint16_t  ds;
00123   uint16_t  es;
00124   uint16_t  fs;
00125   uint16_t  gs;
00126 
00127   /* The next 2 registers are included with MD_CONTEXT_AMD64_CONTROL */
00128   uint16_t  ss;
00129   uint32_t  eflags;
00130 
00131   /* The next 6 registers are included with MD_CONTEXT_AMD64_DEBUG_REGISTERS */
00132   uint64_t  dr0;
00133   uint64_t  dr1;
00134   uint64_t  dr2;
00135   uint64_t  dr3;
00136   uint64_t  dr6;
00137   uint64_t  dr7;
00138 
00139   /* The next 4 registers are included with MD_CONTEXT_AMD64_INTEGER */
00140   uint64_t  rax;
00141   uint64_t  rcx;
00142   uint64_t  rdx;
00143   uint64_t  rbx;
00144 
00145   /* The next register is included with MD_CONTEXT_AMD64_CONTROL */
00146   uint64_t  rsp;
00147 
00148   /* The next 11 registers are included with MD_CONTEXT_AMD64_INTEGER */
00149   uint64_t  rbp;
00150   uint64_t  rsi;
00151   uint64_t  rdi;
00152   uint64_t  r8;
00153   uint64_t  r9;
00154   uint64_t  r10;
00155   uint64_t  r11;
00156   uint64_t  r12;
00157   uint64_t  r13;
00158   uint64_t  r14;
00159   uint64_t  r15;
00160 
00161   /* The next register is included with MD_CONTEXT_AMD64_CONTROL */
00162   uint64_t  rip;
00163 
00164   /* The next set of registers are included with
00165    * MD_CONTEXT_AMD64_FLOATING_POINT
00166    */
00167   union {
00168     MDXmmSaveArea32AMD64 flt_save;
00169     struct {
00170       uint128_struct header[2];
00171       uint128_struct legacy[8];
00172       uint128_struct xmm0;
00173       uint128_struct xmm1;
00174       uint128_struct xmm2;
00175       uint128_struct xmm3;
00176       uint128_struct xmm4;
00177       uint128_struct xmm5;
00178       uint128_struct xmm6;
00179       uint128_struct xmm7;
00180       uint128_struct xmm8;
00181       uint128_struct xmm9;
00182       uint128_struct xmm10;
00183       uint128_struct xmm11;
00184       uint128_struct xmm12;
00185       uint128_struct xmm13;
00186       uint128_struct xmm14;
00187       uint128_struct xmm15;
00188     } sse_registers;
00189   };
00190 
00191   uint128_struct vector_register[MD_CONTEXT_AMD64_VR_COUNT];
00192   uint64_t       vector_control;
00193 
00194   /* The next 5 registers are included with MD_CONTEXT_AMD64_DEBUG_REGISTERS */
00195   uint64_t debug_control;
00196   uint64_t last_branch_to_rip;
00197   uint64_t last_branch_from_rip;
00198   uint64_t last_exception_to_rip;
00199   uint64_t last_exception_from_rip;
00200 
00201 } MDRawContextAMD64;  /* CONTEXT */
00202 
00203 /* For (MDRawContextAMD64).context_flags.  These values indicate the type of
00204  * context stored in the structure.  The high 24 bits identify the CPU, the
00205  * low 8 bits identify the type of context saved. */
00206 #define MD_CONTEXT_AMD64 0x00100000  /* CONTEXT_AMD64 */
00207 #define MD_CONTEXT_AMD64_CONTROL         (MD_CONTEXT_AMD64 | 0x00000001)
00208      /* CONTEXT_CONTROL */
00209 #define MD_CONTEXT_AMD64_INTEGER         (MD_CONTEXT_AMD64 | 0x00000002)
00210      /* CONTEXT_INTEGER */
00211 #define MD_CONTEXT_AMD64_SEGMENTS        (MD_CONTEXT_AMD64 | 0x00000004)
00212      /* CONTEXT_SEGMENTS */
00213 #define MD_CONTEXT_AMD64_FLOATING_POINT  (MD_CONTEXT_AMD64 | 0x00000008)
00214      /* CONTEXT_FLOATING_POINT */
00215 #define MD_CONTEXT_AMD64_DEBUG_REGISTERS (MD_CONTEXT_AMD64 | 0x00000010)
00216      /* CONTEXT_DEBUG_REGISTERS */
00217 #define MD_CONTEXT_AMD64_XSTATE          (MD_CONTEXT_AMD64 | 0x00000040)
00218      /* CONTEXT_XSTATE */
00219 
00220 /* WinNT.h refers to CONTEXT_MMX_REGISTERS but doesn't appear to define it
00221  * I think it really means CONTEXT_FLOATING_POINT.
00222  */
00223 
00224 #define MD_CONTEXT_AMD64_FULL            (MD_CONTEXT_AMD64_CONTROL | \
00225                                           MD_CONTEXT_AMD64_INTEGER | \
00226                                           MD_CONTEXT_AMD64_FLOATING_POINT)
00227      /* CONTEXT_FULL */
00228 
00229 #define MD_CONTEXT_AMD64_ALL             (MD_CONTEXT_AMD64_FULL | \
00230                                           MD_CONTEXT_AMD64_SEGMENTS | \
00231                                           MD_CONTEXT_X86_DEBUG_REGISTERS)
00232      /* CONTEXT_ALL */
00233 
00234 
00235 #endif /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_AMD64_H__ */