Home | History | Annotate | Download | only in common
      1 /* Copyright (c) 2013, Google Inc.
      2  * All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
     29 
     30 /* minidump_format.h: A cross-platform reimplementation of minidump-related
     31  * portions of DbgHelp.h from the Windows Platform SDK.
     32  *
     33  * (This is C99 source, please don't corrupt it with C++.)
     34  *
     35  * This file contains the necessary definitions to read minidump files
     36  * produced on MIPS.  These files may be read on any platform provided
     37  * that the alignments of these structures on the processing system are
     38  * identical to the alignments of these structures on the producing system.
     39  * For this reason, precise-sized types are used.  The structures defined
     40  * by this file have been laid out to minimize alignment problems by
     41  * ensuring that all members are aligned on their natural boundaries.
     42  * In some cases, tail-padding may be significant when different ABIs specify
     43  * different tail-padding behaviors.  To avoid problems when reading or
     44  * writing affected structures, MD_*_SIZE macros are provided where needed,
     45  * containing the useful size of the structures without padding.
     46  *
     47  * Structures that are defined by Microsoft to contain a zero-length array
     48  * are instead defined here to contain an array with one element, as
     49  * zero-length arrays are forbidden by standard C and C++.  In these cases,
     50  * *_minsize constants are provided to be used in place of sizeof.  For a
     51  * cleaner interface to these sizes when using C++, see minidump_size.h.
     52  *
     53  * These structures are also sufficient to populate minidump files.
     54  *
     55  * Because precise data type sizes are crucial for this implementation to
     56  * function properly and portably, a set of primitive types with known sizes
     57  * are used as the basis of each structure defined by this file.
     58  *
     59  * Author: Chris Dearman
     60  */
     61 
     62 /*
     63  * MIPS support
     64  */
     65 
     66 #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_MIPS_H__
     67 #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_MIPS_H__
     68 
     69 #if defined(__mips__) && !defined(__ANDROID__)
     70 typedef struct {
     71   uint64_t regs[32];
     72   uint64_t lo;
     73   uint64_t hi;
     74   uint64_t epc;
     75   uint64_t badvaddr;
     76   uint64_t status;
     77   uint64_t cause;
     78 } user_regs_struct;
     79 
     80 typedef struct {
     81   uint64_t regs[32];
     82   uint32_t fpcsr;
     83   uint32_t fir;
     84 } user_fpregs_struct;
     85 #endif
     86 
     87 #define MD_CONTEXT_MIPS_GPR_COUNT 32
     88 #define MD_FLOATINGSAVEAREA_MIPS_FPR_COUNT 32
     89 #define MD_CONTEXT_MIPS_DSP_COUNT 3
     90 
     91 /*
     92  * Note that these structures *do not* map directly to the CONTEXT
     93  * structure defined in WinNT.h in the Windows Mobile SDK. That structure
     94  * does not accomodate VFPv3, and I'm unsure if it was ever used in the
     95  * wild anyway, as Windows CE only seems to produce "cedumps" which
     96  * are not exactly minidumps.
     97  */
     98 typedef struct {
     99   /* 32 64-bit floating point registers, f0..f31 */
    100   uint64_t regs[MD_FLOATINGSAVEAREA_MIPS_FPR_COUNT];
    101 
    102   uint32_t fpcsr; /* FPU status register. */
    103   uint32_t fir; /* FPU implementation register. */
    104 } MDFloatingSaveAreaMIPS;
    105 
    106 typedef struct {
    107   /* The next field determines the layout of the structure, and which parts
    108    * of it are populated.
    109    */
    110   uint32_t context_flags;
    111   uint32_t _pad0;
    112 
    113   /* 32 64-bit integer registers, r0..r31.
    114    * Note the following fixed uses:
    115    *   r30 is the stack pointer.
    116    *   r31 is the return address (link register).
    117    */
    118   uint64_t iregs[MD_CONTEXT_MIPS_GPR_COUNT];
    119 
    120   /* multiply/divide result. */
    121   uint64_t mdhi, mdlo;
    122 
    123   /* DSP accumulators. */
    124   uint32_t hi[MD_CONTEXT_MIPS_DSP_COUNT];
    125   uint32_t lo[MD_CONTEXT_MIPS_DSP_COUNT];
    126   uint32_t dsp_control;
    127   uint32_t _pad1;
    128 
    129   uint64_t epc;
    130   uint64_t badvaddr;
    131   uint32_t status;
    132   uint32_t cause;
    133 
    134   /* The next field is included with MD_CONTEXT_MIPS_FLOATING_POINT. */
    135   MDFloatingSaveAreaMIPS float_save;
    136 
    137 } MDRawContextMIPS;
    138 
    139 /* Indices into iregs for registers with a dedicated or conventional
    140  * purpose.
    141  */
    142 enum MDMIPSRegisterNumbers {
    143   MD_CONTEXT_MIPS_REG_S0     = 16,
    144   MD_CONTEXT_MIPS_REG_S1     = 17,
    145   MD_CONTEXT_MIPS_REG_S2     = 18,
    146   MD_CONTEXT_MIPS_REG_S3     = 19,
    147   MD_CONTEXT_MIPS_REG_S4     = 20,
    148   MD_CONTEXT_MIPS_REG_S5     = 21,
    149   MD_CONTEXT_MIPS_REG_S6     = 22,
    150   MD_CONTEXT_MIPS_REG_S7     = 23,
    151   MD_CONTEXT_MIPS_REG_GP     = 28,
    152   MD_CONTEXT_MIPS_REG_SP     = 29,
    153   MD_CONTEXT_MIPS_REG_FP     = 30,
    154   MD_CONTEXT_MIPS_REG_RA     = 31,
    155 };
    156 
    157 /* For (MDRawContextMIPS).context_flags.  These values indicate the type of
    158  * context stored in the structure. */
    159 /* CONTEXT_MIPS from the Windows CE 5.0 SDK. This value isn't correct
    160  * because this bit can be used for flags. Presumably this value was
    161  * never actually used in minidumps, but only in "CEDumps" which
    162  * are a whole parallel minidump file format for Windows CE.
    163  * Therefore, Breakpad defines its own value for MIPS CPUs.
    164  */
    165 #define MD_CONTEXT_MIPS  0x00040000
    166 #define MD_CONTEXT_MIPS_INTEGER           (MD_CONTEXT_MIPS | 0x00000002)
    167 #define MD_CONTEXT_MIPS_FLOATING_POINT    (MD_CONTEXT_MIPS | 0x00000004)
    168 #define MD_CONTEXT_MIPS_DSP               (MD_CONTEXT_MIPS | 0x00000008)
    169 
    170 #define MD_CONTEXT_MIPS_FULL              (MD_CONTEXT_MIPS_INTEGER | \
    171                                            MD_CONTEXT_MIPS_FLOATING_POINT | \
    172                                            MD_CONTEXT_MIPS_DSP)
    173 
    174 #define MD_CONTEXT_MIPS_ALL               (MD_CONTEXT_MIPS_INTEGER | \
    175                                            MD_CONTEXT_MIPS_FLOATING_POINT \
    176                                            MD_CONTEXT_MIPS_DSP)
    177 
    178 #endif  // GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_MIPS_H__
    179