1d4e76214Sopenharmony_ci/* libunwind - a platform-independent unwind library 2d4e76214Sopenharmony_ci Copyright (C) 2002-2005 Hewlett-Packard Co 3d4e76214Sopenharmony_ci Contributed by David Mosberger-Tang <davidm@hpl.hp.com> 4d4e76214Sopenharmony_ci 5d4e76214Sopenharmony_ciThis file is part of libunwind. 6d4e76214Sopenharmony_ci 7d4e76214Sopenharmony_ciPermission is hereby granted, free of charge, to any person obtaining 8d4e76214Sopenharmony_cia copy of this software and associated documentation files (the 9d4e76214Sopenharmony_ci"Software"), to deal in the Software without restriction, including 10d4e76214Sopenharmony_ciwithout limitation the rights to use, copy, modify, merge, publish, 11d4e76214Sopenharmony_cidistribute, sublicense, and/or sell copies of the Software, and to 12d4e76214Sopenharmony_cipermit persons to whom the Software is furnished to do so, subject to 13d4e76214Sopenharmony_cithe following conditions: 14d4e76214Sopenharmony_ci 15d4e76214Sopenharmony_ciThe above copyright notice and this permission notice shall be 16d4e76214Sopenharmony_ciincluded in all copies or substantial portions of the Software. 17d4e76214Sopenharmony_ci 18d4e76214Sopenharmony_ciTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19d4e76214Sopenharmony_ciEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20d4e76214Sopenharmony_ciMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21d4e76214Sopenharmony_ciNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22d4e76214Sopenharmony_ciLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23d4e76214Sopenharmony_ciOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24d4e76214Sopenharmony_ciWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 25d4e76214Sopenharmony_ci 26d4e76214Sopenharmony_ci#include "unwind_i.h" 27d4e76214Sopenharmony_ci 28d4e76214Sopenharmony_ci/* Apply rotation to a general register. REG must be in the range 0-127. */ 29d4e76214Sopenharmony_ci 30d4e76214Sopenharmony_cistatic inline int 31d4e76214Sopenharmony_cirotate_gr (struct cursor *c, int reg) 32d4e76214Sopenharmony_ci{ 33d4e76214Sopenharmony_ci unsigned int rrb_gr, sor; 34d4e76214Sopenharmony_ci int preg; 35d4e76214Sopenharmony_ci 36d4e76214Sopenharmony_ci sor = 8 * ((c->cfm >> 14) & 0xf); 37d4e76214Sopenharmony_ci rrb_gr = (c->cfm >> 18) & 0x7f; 38d4e76214Sopenharmony_ci 39d4e76214Sopenharmony_ci if ((unsigned) (reg - 32) >= sor) 40d4e76214Sopenharmony_ci preg = reg; 41d4e76214Sopenharmony_ci else 42d4e76214Sopenharmony_ci { 43d4e76214Sopenharmony_ci preg = reg + rrb_gr; /* apply rotation */ 44d4e76214Sopenharmony_ci if ((unsigned) (preg - 32) >= sor) 45d4e76214Sopenharmony_ci preg -= sor; /* wrap around */ 46d4e76214Sopenharmony_ci } 47d4e76214Sopenharmony_ci if (sor) 48d4e76214Sopenharmony_ci Debug (15, "sor=%u rrb.gr=%u, r%d -> r%d\n", sor, rrb_gr, reg, preg); 49d4e76214Sopenharmony_ci return preg; 50d4e76214Sopenharmony_ci} 51d4e76214Sopenharmony_ci 52d4e76214Sopenharmony_ci/* Apply rotation to a floating-point register. The number REG must 53d4e76214Sopenharmony_ci be in the range of 0-127. */ 54d4e76214Sopenharmony_ci 55d4e76214Sopenharmony_cistatic inline int 56d4e76214Sopenharmony_cirotate_fr (struct cursor *c, int reg) 57d4e76214Sopenharmony_ci{ 58d4e76214Sopenharmony_ci unsigned int rrb_fr; 59d4e76214Sopenharmony_ci int preg; 60d4e76214Sopenharmony_ci 61d4e76214Sopenharmony_ci rrb_fr = (c->cfm >> 25) & 0x7f; 62d4e76214Sopenharmony_ci if (reg < 32) 63d4e76214Sopenharmony_ci preg = reg; /* register not part of the rotating partition */ 64d4e76214Sopenharmony_ci else 65d4e76214Sopenharmony_ci { 66d4e76214Sopenharmony_ci preg = reg + rrb_fr; /* apply rotation */ 67d4e76214Sopenharmony_ci if (preg > 127) 68d4e76214Sopenharmony_ci preg -= 96; /* wrap around */ 69d4e76214Sopenharmony_ci } 70d4e76214Sopenharmony_ci if (rrb_fr) 71d4e76214Sopenharmony_ci Debug (15, "rrb.fr=%u, f%d -> f%d\n", rrb_fr, reg, preg); 72d4e76214Sopenharmony_ci return preg; 73d4e76214Sopenharmony_ci} 74