1 /* asm.h -- macros for m68k asm
2  *
3  * Copyright (c) 1995, 1996 Cygnus Support
4  *
5  * The authors hereby grant permission to use, copy, modify, distribute,
6  * and license this software and its documentation for any purpose, provided
7  * that existing copyright notices are retained in all copies and that this
8  * notice is included verbatim in any distributions. No written agreement,
9  * license, or royalty fee is required for any of the authorized uses.
10  * Modifications to this software may be copyrighted by their authors
11  * and need not follow the licensing terms described here, provided that
12  * the new terms are clearly indicated on the first page of each file where
13  * they apply.
14  */
15 
16 #if 0
17 /*
18  * XXX __USER_LABEL_PREFIX__ and __REGISTER_PREFIX__ do not work on gcc 2.7.0-3
19  * XXX The following ifdef magic fixes the problem but results in a warning
20  * XXX when compiling assembly code.
21  */
22 #ifndef __USER_LABEL_PREFIX__
23 /* #define __USER_LABEL_PREFIX__ ""	/* no underscore for coff */
24 #define __USER_LABEL_PREFIX__ _		/* leading underscore for aout */
25 #endif
26 
27 #ifndef __REGISTER_PREFIX__
28 #define __REGISTER_PREFIX__ 		/* never has anything prefixed */
29 #endif
30 #endif
31 
32 /*
33  * some assemblers choke on '#' as an immediate value. As gcc can also
34  * use '&', use that in those cases.
35  */
36 #ifndef __IMMEDIATE_PREFIX__
37 #define __IMMEDIATE_PREFIX__ #
38 #endif
39 
40 /* ANSI concatenation macros.  */
41 #define CONCAT1(a, b) CONCAT2(a, b)
42 #define CONCAT2(a, b) a ## b
43 
44 /* use the right prefix for global labels.  */
45 #define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__,x)
46 
47 /* use the right prefix for registers.  */
48 #define REG(x) CONCAT1 (__REGISTER_PREFIX__,x)
49 
50 /* use the right prefix for immediate values.  */
51 #define IMM(x) CONCAT1 (__IMMEDIATE_PREFIX__,x)
52 
53 /* use the right prefix for register names */
54 #define d0 REG (d0)
55 #define d1 REG (d1)
56 #define d2 REG (d2)
57 #define d3 REG (d3)
58 #define d4 REG (d4)
59 #define d5 REG (d5)
60 #define d6 REG (d6)
61 #define d7 REG (d7)
62 #define a0 REG (a0)
63 #define a1 REG (a1)
64 #define a2 REG (a2)
65 #define a3 REG (a3)
66 #define a4 REG (a4)
67 #define a5 REG (a5)
68 #define a6 REG (a6)
69 #define a7 REG (a7)
70 #define fp REG (fp)
71 #define fp0 REG (fp0)
72 #define fp1 REG (fp1)
73 #define fp2 REG (fp2)
74 #define fp3 REG (fp3)
75 #define fp4 REG (fp4)
76 #define fp5 REG (fp5)
77 #define fp6 REG (fp6)
78 #define fp7 REG (fp7)
79 #define sp REG (sp)
80 #define usp REG (usp)
81 #define vbr REG (vbr)
82 #define sr REG (sr)
83 #define fpcr REG (fpcr)
84 #define fpsr REG (fpsr)
85 #define fpi REG (fpi)
86 
87 /* Provide a few macros to allow for PIC code support.
88  * With PIC, data is stored A5 relative so we've got to take a bit of special
89  * care to ensure that all loads of global data is via A5.  PIC also requires
90  * jumps and subroutine calls to be PC relative rather than absolute.  We cheat
91  * a little on this and in the PIC case, we use short offset branches and
92  * hope that the final object code is within range (which it should be).
93  */
94 #ifndef __PIC__
95 
96 	/* Non PIC (absolute/relocatable) versions */
97 
98 	.macro PICCALL addr
99 	jbsr	\addr
100 	.endm
101 
102 	.macro PICJUMP addr
103 	jmp	\addr
104 	.endm
105 
106 	.macro PICLEA sym, reg
107 	lea	\sym, \reg
108 	.endm
109 
110 	.macro PICPEA sym, areg
111 	pea	\sym
112 	.endm
113 
114 #else /* __PIC__ */
115 
116 	/* Common for -mid-shared-libary and -msep-data */
117 
118 	.macro PICCALL addr
119 	bsr	\addr
120 	.endm
121 
122 	.macro PICJUMP addr
123 	bra	\addr
124 	.endm
125 
126 # if defined(__ID_SHARED_LIBRARY__)
127 
128 	/* -mid-shared-library versions  */
129 
130 	.macro PICLEA sym, reg
131 	movel	a5@(_current_shared_library_a5_offset_), \reg
132 	movel	\sym@GOT(\reg), \reg
133 	.endm
134 
135 	.macro PICPEA sym, areg
136 	movel	a5@(_current_shared_library_a5_offset_), \areg
137 	movel	\sym@GOT(\areg), sp@-
138 	.endm
139 
140 # else /* !__ID_SHARED_LIBRARY__ */
141 
142 	/* Versions for -msep-data */
143 
144 	.macro PICLEA sym, reg
145 	movel	\sym@GOT(a5), \reg
146 	.endm
147 
148 	.macro PICPEA sym, areg
149 	movel	\sym@GOT(a5), sp@-
150 	.endm
151 
152 # endif /* !__ID_SHARED_LIBRARY__ */
153 #endif /* __PIC__ */
154 
155