RegsInfo.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (C) 2018 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _LIBUNWINDSTACK_REGS_INFO_H
  17. #define _LIBUNWINDSTACK_REGS_INFO_H
  18. #include <stdint.h>
  19. #include <unwindstack/Regs.h>
  20. namespace unwindstack {
  21. template <typename AddressType>
  22. struct RegsInfo {
  23. static constexpr size_t MAX_REGISTERS = 64;
  24. RegsInfo(RegsImpl<AddressType>* regs) : regs(regs) {}
  25. RegsImpl<AddressType>* regs = nullptr;
  26. uint64_t saved_reg_map = 0;
  27. AddressType saved_regs[MAX_REGISTERS];
  28. inline AddressType Get(uint32_t reg) {
  29. if (IsSaved(reg)) {
  30. return saved_regs[reg];
  31. }
  32. return (*regs)[reg];
  33. }
  34. inline AddressType* Save(uint32_t reg) {
  35. if (reg >= MAX_REGISTERS) {
  36. // This should never happen since all currently supported
  37. // architectures have < 64 total registers.
  38. abort();
  39. }
  40. saved_reg_map |= 1ULL << reg;
  41. saved_regs[reg] = (*regs)[reg];
  42. return &(*regs)[reg];
  43. }
  44. inline bool IsSaved(uint32_t reg) {
  45. if (reg > MAX_REGISTERS) {
  46. // This should never happen since all currently supported
  47. // architectures have < 64 total registers.
  48. abort();
  49. }
  50. return saved_reg_map & (1ULL << reg);
  51. }
  52. inline uint16_t Total() { return regs->total_regs(); }
  53. };
  54. } // namespace unwindstack
  55. #endif // _LIBUNWINDSTACK_REGS_INFO_H