/ src / google_breakpad / common / minidump_cpu_arm64.h
minidump_cpu_arm64.h
  1  /* Copyright 2013 Google LLC
  2   *
  3   * Redistribution and use in source and binary forms, with or without
  4   * modification, are permitted provided that the following conditions are
  5   * met:
  6   *
  7   *     * Redistributions of source code must retain the above copyright
  8   * notice, this list of conditions and the following disclaimer.
  9   *     * Redistributions in binary form must reproduce the above
 10   * copyright notice, this list of conditions and the following disclaimer
 11   * in the documentation and/or other materials provided with the
 12   * distribution.
 13   *     * Neither the name of Google LLC nor the names of its
 14   * contributors may be used to endorse or promote products derived from
 15   * this software without specific prior written permission.
 16   *
 17   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 21   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 22   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 23   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 24   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 25   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 28  
 29  /* minidump_format.h: A cross-platform reimplementation of minidump-related
 30   * portions of DbgHelp.h from the Windows Platform SDK.
 31   *
 32   * (This is C99 source, please don't corrupt it with C++.)
 33   *
 34   * This file contains the necessary definitions to read minidump files
 35   * produced on ARM.  These files may be read on any platform provided
 36   * that the alignments of these structures on the processing system are
 37   * identical to the alignments of these structures on the producing system.
 38   * For this reason, precise-sized types are used.  The structures defined
 39   * by this file have been laid out to minimize alignment problems by
 40   * ensuring that all members are aligned on their natural boundaries.
 41   * In some cases, tail-padding may be significant when different ABIs specify
 42   * different tail-padding behaviors.  To avoid problems when reading or
 43   * writing affected structures, MD_*_SIZE macros are provided where needed,
 44   * containing the useful size of the structures without padding.
 45   *
 46   * Structures that are defined by Microsoft to contain a zero-length array
 47   * are instead defined here to contain an array with one element, as
 48   * zero-length arrays are forbidden by standard C and C++.  In these cases,
 49   * *_minsize constants are provided to be used in place of sizeof.  For a
 50   * cleaner interface to these sizes when using C++, see minidump_size.h.
 51   *
 52   * These structures are also sufficient to populate minidump files.
 53   *
 54   * Because precise data type sizes are crucial for this implementation to
 55   * function properly and portably, a set of primitive types with known sizes
 56   * are used as the basis of each structure defined by this file.
 57   *
 58   * Author: Colin Blundell
 59   */
 60  
 61  /*
 62   * ARM64 support
 63   */
 64  
 65  #ifndef GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_ARM64_H__
 66  #define GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_ARM64_H__
 67  
 68  #include "google_breakpad/common/breakpad_types.h"
 69  
 70  #define MD_FLOATINGSAVEAREA_ARM64_FPR_COUNT 32
 71  #define MD_CONTEXT_ARM64_GPR_COUNT 33
 72  
 73  typedef struct {
 74    /* 32 128-bit floating point registers, d0 .. d31. */
 75    uint128_struct regs[MD_FLOATINGSAVEAREA_ARM64_FPR_COUNT];
 76  
 77    uint32_t fpcr;       /* FPU control register */
 78    uint32_t fpsr;       /* FPU status register */
 79  } MDFloatingSaveAreaARM64;
 80  
 81  /* For (MDRawContextARM64).context_flags.  These values indicate the type of
 82   * context stored in the structure. */
 83  #define MD_CONTEXT_ARM64 0x00400000
 84  #define MD_CONTEXT_ARM64_CONTROL (MD_CONTEXT_ARM64 | 0x00000001)
 85  #define MD_CONTEXT_ARM64_INTEGER (MD_CONTEXT_ARM64 | 0x00000002)
 86  #define MD_CONTEXT_ARM64_FLOATING_POINT (MD_CONTEXT_ARM64 | 0x00000004)
 87  #define MD_CONTEXT_ARM64_DEBUG (MD_CONTEXT_ARM64 | 0x00000008)
 88  #define MD_CONTEXT_ARM64_FULL (MD_CONTEXT_ARM64_CONTROL | \
 89                                 MD_CONTEXT_ARM64_INTEGER | \
 90                                 MD_CONTEXT_ARM64_FLOATING_POINT)
 91  #define MD_CONTEXT_ARM64_ALL (MD_CONTEXT_ARM64_FULL | MD_CONTEXT_ARM64_DEBUG)
 92  
 93  typedef struct {
 94    /* Determines which fields of this struct are populated */
 95    uint32_t context_flags;
 96  
 97    /* CPSR (flags, basically): 32 bits:
 98          bit 31 - N (negative)
 99          bit 30 - Z (zero)
100          bit 29 - C (carry)
101          bit 28 - V (overflow)
102          bit 27 - Q (saturation flag, sticky)
103       All other fields -- ignore */
104    uint32_t cpsr;
105  
106    /* 33 64-bit integer registers, x0 .. x31 + the PC
107     * Note the following fixed uses:
108     *   x29 is the frame pointer
109     *   x30 is the link register
110     *   x31 is the stack pointer
111     *   The PC is effectively x32.
112     */
113    uint64_t iregs[MD_CONTEXT_ARM64_GPR_COUNT];
114  
115    /* The next field is included with MD_CONTEXT64_ARM_FLOATING_POINT */
116    MDFloatingSaveAreaARM64 float_save;
117  
118    uint32_t bcr[8];
119    uint64_t bvr[8];
120    uint32_t wcr[2];
121    uint64_t wvr[2];
122  } MDRawContextARM64;
123  
124  typedef struct {
125    uint32_t       fpsr;      /* FPU status register */
126    uint32_t       fpcr;      /* FPU control register */
127  
128    /* 32 128-bit floating point registers, d0 .. d31. */
129    uint128_struct regs[MD_FLOATINGSAVEAREA_ARM64_FPR_COUNT];
130  } MDFloatingSaveAreaARM64_Old;
131  
132  /* Use the same 32-bit alignment when accessing this structure from 64-bit code
133   * as is used natively in 32-bit code. */
134  #pragma pack(push, 4)
135  
136  typedef struct {
137    /* The next field determines the layout of the structure, and which parts
138     * of it are populated
139     */
140    uint64_t      context_flags;
141  
142    /* 33 64-bit integer registers, x0 .. x31 + the PC
143     * Note the following fixed uses:
144     *   x29 is the frame pointer
145     *   x30 is the link register
146     *   x31 is the stack pointer
147     *   The PC is effectively x32.
148     */
149    uint64_t     iregs[MD_CONTEXT_ARM64_GPR_COUNT];
150  
151    /* CPSR (flags, basically): 32 bits:
152          bit 31 - N (negative)
153          bit 30 - Z (zero)
154          bit 29 - C (carry)
155          bit 28 - V (overflow)
156          bit 27 - Q (saturation flag, sticky)
157       All other fields -- ignore */
158    uint32_t    cpsr;
159  
160    /* The next field is included with MD_CONTEXT64_ARM_FLOATING_POINT */
161    MDFloatingSaveAreaARM64_Old float_save;
162  
163  } MDRawContextARM64_Old;
164  
165  #pragma pack(pop)
166  
167  /* Indices into iregs for registers with a dedicated or conventional
168   * purpose.
169   */
170  enum MDARM64RegisterNumbers {
171    MD_CONTEXT_ARM64_REG_FP     = 29,
172    MD_CONTEXT_ARM64_REG_LR     = 30,
173    MD_CONTEXT_ARM64_REG_SP     = 31,
174    MD_CONTEXT_ARM64_REG_PC     = 32
175  };
176  
177  /* For (MDRawContextARM64_Old).context_flags.  These values indicate the type of
178   * context stored in the structure. MD_CONTEXT_ARM64_OLD is Breakpad-defined.
179   * This value was chosen to avoid likely conflicts with MD_CONTEXT_*
180   * for other CPUs. */
181  #define MD_CONTEXT_ARM64_OLD                   0x80000000
182  #define MD_CONTEXT_ARM64_INTEGER_OLD           (MD_CONTEXT_ARM64_OLD | 0x00000002)
183  #define MD_CONTEXT_ARM64_FLOATING_POINT_OLD    (MD_CONTEXT_ARM64_OLD | 0x00000004)
184  
185  #define MD_CONTEXT_ARM64_FULL_OLD              (MD_CONTEXT_ARM64_INTEGER_OLD | \
186                                            MD_CONTEXT_ARM64_FLOATING_POINT_OLD)
187  
188  #define MD_CONTEXT_ARM64_ALL_OLD               (MD_CONTEXT_ARM64_INTEGER_OLD | \
189                                            MD_CONTEXT_ARM64_FLOATING_POINT_OLD)
190  
191  #endif  /* GOOGLE_BREAKPAD_COMMON_MINIDUMP_CPU_ARM64_H__ */