jump.S 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Tests the jump instructions.
  2. Copyright (C) 2017-2022 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. # mach: or1k
  14. # output: report(0x48000000);\n
  15. # output: report(0x00000005);\n
  16. # output: report(0x00000000);\n
  17. # output: report(0x00000000);\n
  18. # output: report(0x00000000);\n
  19. # output: \n
  20. # output: report(0x48000000);\n
  21. # output: report(0x00000009);\n
  22. # output: report(0x00000000);\n
  23. # output: report(0x00000001);\n
  24. # output: report(0x00000000);\n
  25. # output: \n
  26. # output: report(0x44000000);\n
  27. # output: report(0x00000005);\n
  28. # output: report(0x00000000);\n
  29. # output: report(0x00000000);\n
  30. # output: report(0x00000000);\n
  31. # output: \n
  32. # output: report(0x44000000);\n
  33. # output: report(0x00000009);\n
  34. # output: report(0x00000000);\n
  35. # output: report(0x00000000);\n
  36. # output: report(0x00000000);\n
  37. # output: \n
  38. # output: exit(0)\n
  39. #include "or1k-asm-test-helpers.h"
  40. /* Tests a jump instruction using a register destination.
  41. Checks whether the jump succeeds, or whether an exception is triggered
  42. (but not if the right exception was triggered yet).
  43. We manually construct the opcode, to allow us to force R9 into the
  44. destination field, to test exception handling. Usually the assembler
  45. would prevent this.
  46. Do not specify R31 as the register to use for the jump, as it's used
  47. internally. */
  48. .macro TEST_JUMP opcode_value dest_register_number alignment_offset
  49. REPORT_IMMEDIATE_TO_CONSOLE \opcode_value
  50. REPORT_IMMEDIATE_TO_CONSOLE \dest_register_number
  51. REPORT_IMMEDIATE_TO_CONSOLE \alignment_offset
  52. LOAD_IMMEDIATE r\dest_register_number, 51f + \alignment_offset
  53. /* Generate the jump opcode. */
  54. \@1$: OR1K_DELAYED_NOP \
  55. (.word ( \opcode_value | (\dest_register_number << 11) ))
  56. /* If the jump failed, we land here. */
  57. REPORT_IMMEDIATE_TO_CONSOLE 1
  58. OR1K_DELAYED_NOP (l.j 52f)
  59. /* If the jump succeeds, we land here. */
  60. 51: REPORT_IMMEDIATE_TO_CONSOLE 0
  61. 52: REPORT_EXCEPTION \@1$
  62. PRINT_NEWLINE_TO_CONSOLE
  63. .endm
  64. STANDARD_TEST_ENVIRONMENT
  65. .section .text
  66. start_tests:
  67. PUSH LINK_REGISTER_R9
  68. /* Test l.jalr (jump and link register) */
  69. TEST_JUMP 0x48000000, 5, 0
  70. /* TODO: The sim does not support unaligned memory access yet.
  71. TEST_JUMP 0x48000000, 5, 1
  72. TEST_JUMP 0x48000000, 5, 2
  73. TEST_JUMP 0x48000000, 5, 3
  74. */
  75. /* Test with link register as the destination. This is not
  76. allowed. */
  77. TEST_JUMP 0x48000000, 9, 0
  78. /* Test l.jr (jump register) */
  79. TEST_JUMP 0x44000000, 5, 0
  80. /* TODO: The sim does not support unaligned memory access yet.
  81. TEST_JUMP 0x44000000, 5, 1
  82. TEST_JUMP 0x44000000, 5, 2
  83. TEST_JUMP 0x44000000, 5, 3
  84. */
  85. /* Test with link register as the destination. */
  86. TEST_JUMP 0x44000000, 9, 0
  87. POP LINK_REGISTER_R9
  88. RETURN_TO_LINK_REGISTER_R9