Fix the execution of the MSP430 simulator testsuite.
[external/binutils.git] / sim / testsuite / sim / msp430 / testutils.inc
1 # MACRO: start
2 # All assembler tests should start with a call to "start"
3         .macro start
4         .text
5
6         # Skip over these inlined funcs.
7         jmp __start;
8
9         .global __pass
10         .type __pass, function
11 __pass:
12         # Note - we cannot just invoke:
13         #
14         #  write 1, _passmsg, 5
15         #
16         # here because _passmsg contains the run-time (VMA) address of
17         # the pass string (probably 0x500) not the load-time (LMA)
18         # address (probably 0x804c).  Normally using the VMA address
19         # would be the correct thing to do - *if* there was some start
20         # up code which copied data from LMA to VMA.  But we have no
21         # start up code, so the data still resides at the LMA
22         # address.  Hence we use __romdatastart instead.
23         #
24         # Note - we are cheating because the address that we pass to
25         # "write" should actually be:
26         #
27         #    __romdatastart + (_passmsg - __datastart)
28         #
29         # but the assembler cannot cope with this expression.  So we
30         # cheat and use the fact that we know that _passmsg is the
31         # first string in the .data section and so (_passmsg -
32         # __datastart) evaluates to zero.
33
34         write 1, __romdatastart, 5
35         exit 0
36
37         .global __fail
38         .type __fail, function
39 __fail:
40         # Note - see above.
41         #
42         #   write 1, _failmsg, 5
43         #
44         # This time we use the fact that _passmsg is aligned to a
45         # 16 byte boundary to work out that (_failmsg - __datastart)
46         # evaluates to 0x10.
47
48         write 1, __romdatastart + 0x10, 5
49         exit 1
50
51         .data
52 _passmsg:
53         .ascii "pass\n"
54         .align 4
55
56 _failmsg:
57         .ascii "fail\n"
58         .align 4
59
60         .text
61         .global __start
62         .type __start, function
63 __start:
64         .endm
65
66 # MACRO: system_call
67 # Make a libgloss/Linux system call
68         .macro system_call nr:req
69         call #(0x180|\nr);
70         .endm
71
72 # MACRO: exit
73 # Quit the current test
74         .macro exit rc:req
75         mov #\rc, r12
76         system_call 1
77         .endm
78
79 # MACRO: pass
80 # Write 'pass' to stdout via syscalls and quit;
81 # meant for non-OS operating environments
82         .macro pass
83         jmp __pass;
84         .endm
85
86 # MACRO: fail
87 # Write 'fail' to stdout via syscalls and quit;
88 # meant for non-OS operating environments
89         .macro fail
90         jmp __fail;
91         .endm
92
93 # MACRO: write
94 # Just like the write() C function; uses system calls
95         .macro write fd:req, buf:req, count:req
96         mov #\fd, r12;
97         mov #\buf, r13;
98         mov #\count, r14;
99         system_call 5
100         .endm