1 ; This testcase is part of GDB, the GNU debugger.
3 ; Copyright 2017-2019 Free Software Foundation, Inc.
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.
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.
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/>.
43 ; Standard prologue using short instructions.
49 ; ST_S can store only some of the core registers.
57 ; Standard prologue without `sub sp,sp,INTEGER`.
72 ; Standard prologue of leaf function.
85 ; Prologue with `push fp`.
92 ; mov fp,sp is part of prologue, but this test will not verify that.
93 ; It will be checked later in the "arg_regs_fp" test.
101 ; Prologue with frame pointer and store relative to FP.
104 fp_prologue_with_store:
118 ; Verify that store of the non-callee saved registers is not part of prologue.
119 ; Repeat this test for multiple registers, to check boundaries. Also check
120 ; with both ST and PUSH (aka ST.AW). We have to use multiple functions for
121 ; this, because GDB would stop analisys at the first instruction that is not
125 noncallee_saved_regs_r12_st:
134 noncallee_saved_regs_r12_push:
142 noncallee_saved_regs_r2_push:
150 noncallee_saved_regs_gp_push:
157 ; LP_COUNT is treated like a normal register.
160 noncallee_saved_regs_lp_count:
167 ; BLINK is saved, but after an instruction that is not part of prologue.
168 ; Currently arc_analyze_prologue stops analisys at the first intstruction
169 ; that is not a part of prologue. This might be not the best way, but it is
170 ; what it is right now, so this test confirms this.
173 noncallee_saved_regs_blink_out_of_prologue:
181 ; Saving arguments register via FP.
197 ; Like the previous, but with mov_s.
205 ; Not part of the prologue.
212 ; Saving arguments register without FP.
220 ; Normally that would be done before saving args, but it is used as a
221 ; marker that saving arguments relatively to SP is considered part of
224 ; Not part of the prologue.
231 ; ENTER_S that does nothing.
240 ; ENTER_S that stores BLINK.
249 ; ENTER_S that stores FP.
258 ; ENTER_S that stores R13, FP and BLINK.
262 enter_s (32 + 16 + 1)
267 ; ENTER_S that stores R13-R15
276 ; ENTER_S that stores everything it could.
280 enter_s (32 + 16 + 14)
288 nested_prologue_inner:
299 nested_prologue_outer:
304 bl @nested_prologue_inner
312 ; Prologue with maximum length.
313 ; Expressions like (0xFFFFFFFF + 25) force assembler to use long immediate
314 ; even for values that don't need it, thus letting us test maksimum prologue
315 ; length without having huge frames.
319 sub sp,sp,(0xFFFFFFFF + 25) ; 24 bytes
321 ; Allocate space for 13 callee-saved and 8 arg regs.
322 sub sp,sp,(0xFFFFFFFF + 1 + 21 * 4)
346 sub sp,sp,(0xFFFFFFFF + 1 + 16) ; Space for local variables.
348 add sp,sp,24 + 21 * 4 + 16
351 ; Few tests that test that prologue analysis stops at branch. There are four
352 ; types of "branches": conditional and non-conditional, relative branches and
359 ; This store on stack is not a prologue.
367 cond_branch_in_prologue:
370 ; Doesn't matter if branch is taken or not.
372 ; This store on stack is not a prologue.
384 ; This store on stack is not a prologue.
392 cond_jump_in_prologue:
395 ; It doesn't matter if jump is taken or not - prologue analysis has to
396 ; stop before `jeq` in any case.
398 ; This store on stack is not a prologue.
410 ; Use SUB SP,SP,0 because it is otherwise a valid instruction for
411 ; prologue, so it will halt analysis purely because of its predicate.
412 sub.eq sp,sp,0 ; This is not a prologue anymore.
417 ; Loops should halt prologue analysis.
425 push r26 ; Not part of prologue.
434 ; Store of a constant value (not a register).
445 ; Test that store to immediate address halts prologue analysis.
449 st r14,[@some_variable]
454 ; Store with AB writeback mode.
465 ; Store of a word with AS writeback mode.
471 st.as r14,[sp,1] ; ST.AS, hence address is (offset << 2).
476 ; Store of a halfword with AS writeback mode.
482 sth.as r14,[sp,2] ; STH.AS, hence address is (offset << 1).
487 ; Store of a double word with AS writeback mode. Shift is still 2, like ST!
494 std.as r14,[sp,1] ; STD.AS, hence address is (offset << 2).
496 st.as r14,[sp,1] ; STD.AS, hence address is (offset << 2).
497 st.as r15,[sp,2] ; STD.AS, hence address is (offset << 2).
503 ; Store of the halfword. R14 will not be reported as "saved".
514 ; Store of the halfword. R14 will not be reported as "saved".
526 ; Store of the byte. R14 will not be reported as "saved".
537 ; Store of the byte. R14 will not be reported as "saved".
549 ; Store of the byte. R14 will not be reported as "saved".
560 ; Double word store, optionally available for ARC HS.
568 std.aw 0xdeadbeef,[sp,-8]
579 ; Store relative to some register with a known value.
586 ; Check for both mov and mov_s in one testcase.
593 ; Store relative to some register with a known value using sub.
594 ; Like a previous test, but register is assigned via sub, instead of mov.
597 r_relative_sub_store:
598 ; Following is a complicated way to construct frame like this:
611 ; Like r_relative_store, but using st_s c,[b,u7] which has different opcode.
614 r_relative_store_st_s:
623 ; Store relative to some register with a unknown value.
626 r_relative_store_unknown:
629 st r15,[gp,0] ; GP value is not relative to SP.
634 ; Store relative to some register with a unknown value, using st_s r0,[gp,s11].
640 st_s r0,[gp,0] ; GP value is not relative to SP.
645 ; Check prologue that uses `push_s RR` instructions. `push_s b` and `push_s
646 ; blink` use slightly different subopcodes.
658 push_s blink ; Also tested in mini_prologue ().
662 ; Check for SUB_S c,b,u3 presence - it doesn't affect prologue.
672 ; Check for SUB_S b,b,c presence - it doesn't affect prologue.
684 ; Check for SUB_S b,b,u5.
695 ; Check for SUB 0,b,c, which is effectively a noop (but it can set status
696 ; flags). It shouldn't stop prologue analysis.
707 ; Check for SUB a,limm,c.
712 sub r13,0xdeadbeef,r14
717 ; Check for sub_s.ne b,b,b. Has a condition code, hence should halt prologue.
727 ; Check MOV that uses LIMM values.
749 ; Check that MOV_S h,s3 doesn't prevent prologue analysis.
759 ; Check that MOV_S b,u8 doesn't prevent prologue analysis.
769 ; Check that `mov_s.ne b,h` halts prologue analysis.
779 ; Check that register R12 which original value is not stored will not pop-up in
780 ; the "Saved registers" list.
792 ; Two stores at the same adddress. GDB should report only the R14.
802 ; Test for a case where callee has an alloca or anything else that might
803 ; modify stack dynamically in the function body - after the prologue.
804 ; This assumes that FP is set properly, so that GDB can use it - this holds
805 ; true for frames generated by GCC.
813 add r0,r1,r2 ; Not a prologue anymore.
833 # Create small section for GP-relative accesses.
837 bl @standard_prologue
839 bl @no_subsp_prologue
842 bl @fp_prologue_with_store
843 bl @noncallee_saved_regs_r12_st
844 bl @noncallee_saved_regs_r12_push
845 bl @noncallee_saved_regs_r2_push
846 bl @noncallee_saved_regs_gp_push
847 bl @noncallee_saved_regs_lp_count
848 bl @noncallee_saved_regs_blink_out_of_prologue
850 bl @arg_regs_fp_mov_s
858 bl @nested_prologue_outer
859 bl @max_length_prologue
860 bl @branch_in_prologue
861 bl @cond_branch_in_prologue
863 bl @cond_jump_in_prologue
879 bl @r_relative_sub_store
880 bl @r_relative_store_st_s
881 bl @r_relative_store_unknown