1/*
2 * Copyright (C) 2006 CodeSourcery Inc
3 *
4 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5 *
6 * This file defines some m68k assembly macros for handling the differences
7 * between PIC and non-PIC.
8 */
9#include <features.h>
10
11	/* When assembling code for shared flat libraries, this is nonzero
12	 * if %a5 points the current library's GOT.  */
13	.equ	have_current_got, 0
14
15	/* Perform the equivalent of "<op> <target>", where <target> is
16	 * a text address.  <tmp> is available as a temporary address
17	 * register.  */
18	.macro	DO_TEXT op,target,tmp
19#if defined __UCLIBC_FORMAT_SHARED_FLAT__
20	.ifne	have_current_got
21	move.l \target@GOT(%a5),\tmp
22	.else
23	move.l _current_shared_library_a5_offset_(%a5),\tmp
24	move.l \target@GOT(\tmp),\tmp
25	.endif
26	\op (\tmp)
27#elif defined __PIC__
28	lea \target-.-8,\tmp
29	\op (%pc,\tmp)
30#else
31	\op \target
32#endif
33	.endm
34
35	/* Do "pea <target>" when <target> is a text address.
36	 * <tmp> is available as a temporary register.  */
37	.macro PEA_TEXT target,tmp
38	DO_TEXT pea,\target,\tmp
39	.endm
40
41	/* Likewise jsr.  */
42	.macro CALL target,tmp
43	DO_TEXT jsr,\target,\tmp
44	.endm
45
46	/* Likewise jmp.  */
47	.macro JUMP target,tmp
48	DO_TEXT jmp,\target,\tmp
49	.endm
50
51	/* Initialize the global pointer, if functions need to do that.  */
52	.macro INIT_GP
53#if defined __UCLIBC_FORMAT_SHARED_FLAT__
54	move.l	%a5,-(%sp)
55	move.l _current_shared_library_a5_offset_(%a5),%a5
56#endif
57	.endm
58
59	/* Undo the effects of INIT_GP.  */
60	.macro FINI_GP
61#if defined __UCLIBC_FORMAT_SHARED_FLAT__
62	move.l	(%sp)+,%a5
63#endif
64	.endm
65