aarch64-mte-linux.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Common Linux target-dependent functionality for AArch64 MTE
  2. Copyright (C) 2021-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "arch/aarch64-mte-linux.h"
  15. /* See arch/aarch64-mte-linux.h */
  16. size_t
  17. aarch64_mte_get_tag_granules (CORE_ADDR addr, size_t len, size_t granule_size)
  18. {
  19. /* An empty range has 0 tag granules. */
  20. if (len == 0)
  21. return 0;
  22. /* Start address */
  23. CORE_ADDR s_addr = align_down (addr, granule_size);
  24. /* End address */
  25. CORE_ADDR e_addr = align_down (addr + len - 1, granule_size);
  26. /* We always have at least 1 granule because len is non-zero at this
  27. point. */
  28. return 1 + (e_addr - s_addr) / granule_size;
  29. }
  30. /* See arch/aarch64-mte-linux.h */
  31. CORE_ADDR
  32. aarch64_mte_make_ltag_bits (CORE_ADDR value)
  33. {
  34. return value & AARCH64_MTE_LOGICAL_MAX_VALUE;
  35. }
  36. /* See arch/aarch64-mte-linux.h */
  37. CORE_ADDR
  38. aarch64_mte_make_ltag (CORE_ADDR value)
  39. {
  40. return (aarch64_mte_make_ltag_bits (value)
  41. << AARCH64_MTE_LOGICAL_TAG_START_BIT);
  42. }
  43. /* See arch/aarch64-mte-linux.h */
  44. CORE_ADDR
  45. aarch64_mte_set_ltag (CORE_ADDR address, CORE_ADDR tag)
  46. {
  47. /* Remove the existing tag. */
  48. address &= ~aarch64_mte_make_ltag (AARCH64_MTE_LOGICAL_MAX_VALUE);
  49. /* Return the new tagged address. */
  50. return address | aarch64_mte_make_ltag (tag);
  51. }
  52. /* See arch/aarch64-mte-linux.h */
  53. CORE_ADDR
  54. aarch64_mte_get_ltag (CORE_ADDR address)
  55. {
  56. CORE_ADDR ltag_addr = address >> AARCH64_MTE_LOGICAL_TAG_START_BIT;
  57. return aarch64_mte_make_ltag_bits (ltag_addr);
  58. }