1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2002-2005 Hewlett-Packard Co
3 	Contributed by David Mosberger-Tang <davidm@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 /* Apply rotation to a general register.  REG must be in the range 0-127.  */
29 
30 static inline int
rotate_gr(struct cursor * c,int reg)31 rotate_gr (struct cursor *c, int reg)
32 {
33   unsigned int rrb_gr, sor;
34   int preg;
35 
36   sor = 8 * ((c->cfm >> 14) & 0xf);
37   rrb_gr = (c->cfm >> 18) & 0x7f;
38 
39   if ((unsigned) (reg - 32) >= sor)
40     preg = reg;
41   else
42     {
43       preg = reg + rrb_gr;	/* apply rotation */
44       if ((unsigned) (preg - 32) >= sor)
45 	preg -= sor;		/* wrap around */
46     }
47   if (sor)
48     Debug (15, "sor=%u rrb.gr=%u, r%d -> r%d\n", sor, rrb_gr, reg, preg);
49   return preg;
50 }
51 
52 /* Apply rotation to a floating-point register.  The number REG must
53    be in the range of 0-127.  */
54 
55 static inline int
rotate_fr(struct cursor * c,int reg)56 rotate_fr (struct cursor *c, int reg)
57 {
58   unsigned int rrb_fr;
59   int preg;
60 
61   rrb_fr = (c->cfm >> 25) & 0x7f;
62   if (reg < 32)
63     preg = reg;		/* register not part of the rotating partition */
64   else
65     {
66       preg = reg + rrb_fr;	/* apply rotation */
67       if (preg > 127)
68 	preg -= 96;		/* wrap around */
69     }
70   if (rrb_fr)
71     Debug (15, "rrb.fr=%u, f%d -> f%d\n", rrb_fr, reg, preg);
72   return preg;
73 }
74