1/* Testsuite macros for OpenRISC.
2
3   Copyright (C) 2017-2024 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#ifndef OR1K_ASM_TEST_ENV_H
19#define OR1K_ASM_TEST_ENV_H
20
21#include "or1k-asm.h"
22#include "or1k-asm-test.h"
23
24	.macro STANDARD_TEST_HEADER
25	/* Without the "a" (allocatable) flag, this section gets some
26	   default flags and is discarded by objcopy when flattening to
27	   the binary file.  */
28	.section .exception_vectors, "ax"
29	.org    0x100
30	.global _start
31_start:
32	/* Clear R0 on start-up. There is no guarantee that R0 is hardwired
33	   to zero and indeed it is not when simulating.  */
34	CLEAR_REG r0
35	OR1K_DELAYED_NOP(l.j test_startup)
36	.section .text
37test_startup:
38	.endm
39
40	.macro STANDARD_TEST_BODY
41	LOAD_IMMEDIATE STACK_POINTER_R1, stack_begin
42	CLEAR_BSS r3, r4
43	CALL r3, start_tests
44	EXIT_SIMULATION_WITH_IMMEDIATE_EXIT_CODE SEC_SUCCESS
45	.section .stack
46	.space 4096 /* We need more than EXCEPTION_STACK_SKIP_SIZE bytes.  */
47stack_begin:
48	.endm
49
50	.macro STANDARD_TEST_ENVIRONMENT
51	/* One of the test cases needs to do some tests before setting up
52	   the stack and so on.  That's the reason this macro is split into
53	   2 parts allowing the caller to inject code between the 2
54	   initialisation phases.  */
55	STANDARD_TEST_HEADER
56	STANDARD_TEST_BODY
57	.endm
58
59#endif /* OR1K_ASM_TEST_ENV_H */
60