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