/* Define usage of "reserved" registers */
#if defined(__linux__)
#define SYSTEM_CLOBBERS_R2	1	/* Pointer to Thread Local Storage */
#define SYSTEM_CLOBBERS_R13	1	/* Pointer to .sdata section */
#endif

#ifdef __ASSEMBLY__
/* Helper macros */
#ifdef SYSTEM_CLOBBERS_R2
#define RESTORE_SYSTEM_R2	lwz r2,XLM_TOC(0)
#define SAVE_SYSTEM_R2		stw r2,XLM_TOC(0)
#else
#define RESTORE_SYSTEM_R2
#define SAVE_SYSTEM_R2
#endif
#ifdef SYSTEM_CLOBBERS_R13
#define RESTORE_SYSTEM_R13	lwz r13,XLM_R13(0)
#define SAVE_SYSTEM_R13		stw r13,XLM_R13(0)
#else
#define RESTORE_SYSTEM_R13
#define SAVE_SYSTEM_R13
#endif

/* Helper macros */
#define xglue(x, y)		x ## y
#define glue(x, y)		xglue(x, y)

/* Apple assembler perticularities */
#if (defined(__APPLE__) && defined(__MACH__))
#define C_SYMBOL_NAME(NAME)	glue(_, NAME)
#define ASM_TYPE(NAME, TYPE)	/* nothing */
#define ASM_ALIGN_2(EXP)	EXP
#define ASM_HA16(VAR)		ha16(VAR)
#define ASM_LO16(VAR)		lo16(VAR)
#define ASM_MACRO_END		.endmacro
#define ASM_MACRO_ARG_SEP	,
#define ASM_MACRO_ARG0_DEF	/* nothing! */
#define ASM_MACRO_ARG0		$0
#define ASM_MACRO_ARG1_DEF	/* nothing! */
#define ASM_MACRO_ARG1		$1
#define ASM_MACRO_ARG2_DEF	/* nothing! */
#define ASM_MACRO_ARG2		$2
#define ASM_MACRO_ARG3_DEF	/* nothing! */
#define ASM_MACRO_ARG3		$3
#endif

/* Defaults for GNU assembler */
#ifndef ASM_TYPE
#define ASM_TYPE(NAME, TYPE)	.type NAME, TYPE
#endif
#ifndef ASM_ALIGN_2
#define ASM_ALIGN_2(EXP)	(1 << (EXP))
#endif
#ifndef ASM_HA16
#define ASM_HA16(VAR)		VAR@ha
#endif
#ifndef ASM_LO16
#define ASM_LO16(VAR)		VAR@l
#endif
#ifndef ASM_MACRO_START
#define ASM_MACRO_START		.macro
#endif
#ifndef ASM_MACRO_END
#define ASM_MACRO_END		.endm
#endif
#ifndef ASM_MACRO_ARG_SEP
#define ASM_MACRO_ARG_SEP
#endif
#ifndef ASM_MACRO_ARG0_DEF
#define ASM_MACRO_ARG0_DEF	__asm_macro_arg0
#define ASM_MACRO_ARG0		\__asm_macro_arg0
#define ASM_MACRO_ARG1_DEF	, __asm_macro_arg1
#define ASM_MACRO_ARG1		\__asm_macro_arg1
#define ASM_MACRO_ARG2_DEF	, __asm_macro_arg2
#define ASM_MACRO_ARG2		\__asm_macro_arg2
#define ASM_MACRO_ARG3_DEF	, __asm_macro_arg3
#define ASM_MACRO_ARG3		\__asm_macro_arg3
#endif
#ifndef C_SYMBOL_NAME
#define C_SYMBOL_NAME(NAME)	NAME
#endif
#ifndef ASM_GLOBAL_DIRECTIVE
#define ASM_GLOBAL_DIRECTIVE	.globl
#endif

/* Register names */
#if defined(__linux__) || defined(__NetBSD__)
#define	r0	0
#define	r1	1
#define	r2	2
#define	r3	3
#define	r4	4
#define	r5	5
#define	r6	6
#define	r7	7
#define	r8	8
#define	r9	9
#define	r10	10
#define	r11	11
#define	r12	12
#define	r13	13
#define	r14	14
#define	r15	15
#define	r16	16
#define	r17	17
#define	r18	18
#define	r19	19
#define	r20	20
#define	r21	21
#define	r22	22
#define	r23	23
#define	r24	24
#define	r25	25
#define	r26	26
#define	r27	27
#define	r28	28
#define	r29	29
#define	r30	30
#define	r31	31
#endif

#if defined(__linux__) || defined(__NetBSD__)
#define	f0	0
#define	f1	1
#define	f2	2
#define	f3	3
#define	f4	4
#define	f5	5
#define	f6	6
#define	f7	7
#define	f8	8
#define	f9	9
#define	f10	10
#define	f11	11
#define	f12	12
#define	f13	13
#define	f14	14
#define	f15	15
#define	f16	16
#define	f17	17
#define	f18	18
#define	f19	19
#define	f20	20
#define	f21	21
#define	f22	22
#define	f23	23
#define	f24	24
#define	f25	25
#define	f26	26
#define	f27	27
#define	f28	28
#define	f29	29
#define	f30	30
#define	f31	31
#endif
#endif
