Home | History | Annotate | Download | only in x86
      1 /* libunwind - a platform-independent unwind library
      2    Copyright (C) 2004 Hewlett-Packard Co
      3 	Contributed by David Mosberger-Tang <davidm (at) hpl.hp.com>
      4 
      5 This file is part of libunwind.
      6 
      7 Permission is hereby granted, free of charge, to any person obtaining
      8 a copy of this software and associated documentation files (the
      9 "Software"), to deal in the Software without restriction, including
     10 without limitation the rights to use, copy, modify, merge, publish,
     11 distribute, sublicense, and/or sell copies of the Software, and to
     12 permit persons to whom the Software is furnished to do so, subject to
     13 the following conditions:
     14 
     15 The above copyright notice and this permission notice shall be
     16 included in all copies or substantial portions of the Software.
     17 
     18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
     25 
     26 #include "unwind_i.h"
     27 
     28 PROTECTED int
     29 unw_get_save_loc (unw_cursor_t *cursor, int reg, unw_save_loc_t *sloc)
     30 {
     31   struct cursor *c = (struct cursor *) cursor;
     32   dwarf_loc_t loc;
     33 
     34   loc = DWARF_NULL_LOC;		/* default to "not saved" */
     35 
     36   switch (reg)
     37     {
     38     case UNW_X86_EIP: loc = c->dwarf.loc[EIP]; break;
     39     case UNW_X86_CFA: break;
     40     case UNW_X86_EAX: loc = c->dwarf.loc[EAX]; break;
     41     case UNW_X86_ECX: loc = c->dwarf.loc[ECX]; break;
     42     case UNW_X86_EDX: loc = c->dwarf.loc[EDX]; break;
     43     case UNW_X86_EBX: loc = c->dwarf.loc[EBX]; break;
     44     case UNW_X86_ESP: loc = c->dwarf.loc[ESP]; break;
     45     case UNW_X86_EBP: loc = c->dwarf.loc[EBP]; break;
     46     case UNW_X86_ESI: loc = c->dwarf.loc[ESI]; break;
     47     case UNW_X86_EDI: loc = c->dwarf.loc[EDI]; break;
     48     case UNW_X86_EFLAGS: loc = c->dwarf.loc[EFLAGS]; break;
     49     case UNW_X86_TRAPNO: loc = c->dwarf.loc[TRAPNO]; break;
     50     case UNW_X86_ST0: loc = c->dwarf.loc[ST0]; break;
     51 
     52     case UNW_X86_FCW:
     53     case UNW_X86_FSW:
     54     case UNW_X86_FTW:
     55     case UNW_X86_FOP:
     56     case UNW_X86_FCS:
     57     case UNW_X86_FIP:
     58     case UNW_X86_FEA:
     59     case UNW_X86_FDS:
     60     case UNW_X86_MXCSR:
     61     case UNW_X86_GS:
     62     case UNW_X86_FS:
     63     case UNW_X86_ES:
     64     case UNW_X86_DS:
     65     case UNW_X86_SS:
     66     case UNW_X86_CS:
     67     case UNW_X86_TSS:
     68     case UNW_X86_LDT:
     69       loc = x86_scratch_loc (c, reg);
     70       break;
     71 
     72       /* stacked fp registers */
     73     case UNW_X86_ST1:
     74     case UNW_X86_ST2:
     75     case UNW_X86_ST3:
     76     case UNW_X86_ST4:
     77     case UNW_X86_ST5:
     78     case UNW_X86_ST6:
     79     case UNW_X86_ST7:
     80       /* SSE fp registers */
     81     case UNW_X86_XMM0_lo:
     82     case UNW_X86_XMM0_hi:
     83     case UNW_X86_XMM1_lo:
     84     case UNW_X86_XMM1_hi:
     85     case UNW_X86_XMM2_lo:
     86     case UNW_X86_XMM2_hi:
     87     case UNW_X86_XMM3_lo:
     88     case UNW_X86_XMM3_hi:
     89     case UNW_X86_XMM4_lo:
     90     case UNW_X86_XMM4_hi:
     91     case UNW_X86_XMM5_lo:
     92     case UNW_X86_XMM5_hi:
     93     case UNW_X86_XMM6_lo:
     94     case UNW_X86_XMM6_hi:
     95     case UNW_X86_XMM7_lo:
     96     case UNW_X86_XMM7_hi:
     97     case UNW_X86_XMM0:
     98     case UNW_X86_XMM1:
     99     case UNW_X86_XMM2:
    100     case UNW_X86_XMM3:
    101     case UNW_X86_XMM4:
    102     case UNW_X86_XMM5:
    103     case UNW_X86_XMM6:
    104     case UNW_X86_XMM7:
    105       loc = x86_scratch_loc (c, reg);
    106       break;
    107 
    108     default:
    109       break;
    110     }
    111 
    112   memset (sloc, 0, sizeof (*sloc));
    113 
    114   if (DWARF_IS_NULL_LOC (loc))
    115     {
    116       sloc->type = UNW_SLT_NONE;
    117       return 0;
    118     }
    119 
    120 #if !defined(UNW_LOCAL_ONLY)
    121   if (DWARF_IS_REG_LOC (loc))
    122     {
    123       sloc->type = UNW_SLT_REG;
    124       sloc->u.regnum = DWARF_GET_LOC (loc);
    125     }
    126   else
    127 #endif
    128     {
    129       sloc->type = UNW_SLT_MEMORY;
    130       sloc->u.addr = DWARF_GET_LOC (loc);
    131     }
    132   return 0;
    133 }
    134