1*56bb7041Schristos#----------------------------------------------------------------------------
2*56bb7041Schristos# Macros
3*56bb7041Schristos#----------------------------------------------------------------------------
4*56bb7041Schristos
5*56bb7041Schristos	mask = (1 << alignment) - 1
6*56bb7041Schristos
7*56bb7041Schristos	# Output VALUE as an unaligned pointer-sized quantity.
8*56bb7041Schristos	.macro pbyte value
9*56bb7041Schristos	.if alignment == 2
10*56bb7041Schristos	.4byte		\value
11*56bb7041Schristos	.else
12*56bb7041Schristos	.8byte		\value
13*56bb7041Schristos	.endif
14*56bb7041Schristos	.endm
15*56bb7041Schristos
16*56bb7041Schristos
17*56bb7041Schristos	# Start a new CIE, and emit everything up to the augmentation data.
18*56bb7041Schristos	# Use LABEL to mark the start of the entry and AUG as the augmentation
19*56bb7041Schristos	# string.
20*56bb7041Schristos	.macro start_cie label,aug
21*56bb7041Schristos	.section	.eh_frame,"aw",@progbits
22*56bb7041Schristos\label:
23*56bb7041Schristos	.word		2f-1f		# Length
24*56bb7041Schristos1:
25*56bb7041Schristos	.word		0		# Identifier
26*56bb7041Schristos	.byte		1		# Version
27*56bb7041Schristos	.string		"\aug"		# Augmentation
28*56bb7041Schristos	.byte		1		# Code alignment
29*56bb7041Schristos	.byte		4		# Data alignment
30*56bb7041Schristos	.byte		31		# Return address column
31*56bb7041Schristos	.endm
32*56bb7041Schristos
33*56bb7041Schristos
34*56bb7041Schristos	# Create a dummy function of SIZE bytes in SECTION and emit the
35*56bb7041Schristos	# first four entries of an FDE for it.
36*56bb7041Schristos	.macro start_fde cie,section,size
37*56bb7041Schristos	.section	\section,"ax",@progbits
38*56bb7041Schristos3:
39*56bb7041Schristos	.rept		\size / 4
40*56bb7041Schristos	nop
41*56bb7041Schristos	.endr
42*56bb7041Schristos4:
43*56bb7041Schristos	.section	.eh_frame,"aw",@progbits
44*56bb7041Schristos	.word		2f-1f		# Length
45*56bb7041Schristos1:
46*56bb7041Schristos	.word		.-\cie		# CIE offset
47*56bb7041Schristos	pbyte		3b		# Initial PC
48*56bb7041Schristos	pbyte		4b-3b		# Size of code
49*56bb7041Schristos	.endm
50*56bb7041Schristos
51*56bb7041Schristos
52*56bb7041Schristos	# Finish a CIE or FDE entry.
53*56bb7041Schristos	.macro end_entry
54*56bb7041Schristos	.p2align	alignment,fill
55*56bb7041Schristos2:
56*56bb7041Schristos	.endm
57*56bb7041Schristos
58*56bb7041Schristos
59*56bb7041Schristos	# Start the augmentation data for a CIE that has a 'P' entry
60*56bb7041Schristos	# followed by EXTRA bytes.  AUGLEN is the length of augmentation
61*56bb7041Schristos	# string (including zero terminator), ENCODING is the encoding to
62*56bb7041Schristos	# use for the personality routine and VALUE is the value it
63*56bb7041Schristos	# should have.
64*56bb7041Schristos	.macro		persaug auglen,extra,encoding,value
65*56bb7041Schristos	.if (\encoding & 0xf0) == 0x50
66*56bb7041Schristos	.byte		(-(9 + \auglen + 3 + 2) & mask) + 2 + mask + \extra
67*56bb7041Schristos	.byte		\encoding
68*56bb7041Schristos	.fill		-(9 + \auglen + 3 + 2) & mask,1,0
69*56bb7041Schristos	.else
70*56bb7041Schristos	.byte		2 + mask + \extra
71*56bb7041Schristos	.byte		\encoding
72*56bb7041Schristos	.endif
73*56bb7041Schristos	pbyte		\value
74*56bb7041Schristos	.endm
75*56bb7041Schristos
76*56bb7041Schristos
77*56bb7041Schristos	.macro cie_basic label
78*56bb7041Schristos	start_cie	\label,""
79*56bb7041Schristos	end_entry
80*56bb7041Schristos	.endm
81*56bb7041Schristos
82*56bb7041Schristos	.macro fde_basic cie,section,size
83*56bb7041Schristos	start_fde	\cie,\section,\size
84*56bb7041Schristos	end_entry
85*56bb7041Schristos	.endm
86*56bb7041Schristos
87*56bb7041Schristos
88*56bb7041Schristos	.macro cie_zP label,encoding,value
89*56bb7041Schristos	start_cie	 \label,"zP"
90*56bb7041Schristos	persaug		3,0,\encoding,\value
91*56bb7041Schristos	end_entry
92*56bb7041Schristos	.endm
93*56bb7041Schristos
94*56bb7041Schristos	.macro fde_zP cie,section,size
95*56bb7041Schristos	start_fde	 \cie,\section,\size
96*56bb7041Schristos	.byte		 0		# Augmentation length
97*56bb7041Schristos	end_entry
98*56bb7041Schristos	.endm
99*56bb7041Schristos
100*56bb7041Schristos
101*56bb7041Schristos	.macro cie_zPR label,encoding,value
102*56bb7041Schristos	start_cie	 \label,"zPR"
103*56bb7041Schristos	persaug		4,1,\encoding,\value
104*56bb7041Schristos	.byte		0		# FDE enconding
105*56bb7041Schristos	end_entry
106*56bb7041Schristos	.endm
107*56bb7041Schristos
108*56bb7041Schristos	.macro fde_zPR cie,section,size
109*56bb7041Schristos	start_fde	\cie,\section,\size
110*56bb7041Schristos	.byte		0		# Augmentation length
111*56bb7041Schristos	end_entry
112*56bb7041Schristos	.endm
113*56bb7041Schristos
114*56bb7041Schristos#----------------------------------------------------------------------------
115*56bb7041Schristos# Test code
116*56bb7041Schristos#----------------------------------------------------------------------------
117*56bb7041Schristos
118*56bb7041Schristos	cie_basic	basic1
119*56bb7041Schristos	fde_basic	basic1,.text,0x10
120*56bb7041Schristos	fde_basic	basic1,.text,0x20
121*56bb7041Schristos
122*56bb7041Schristos	cie_basic	basic2
123*56bb7041Schristos	fde_basic	basic2,.text,0x30
124*56bb7041Schristos
125*56bb7041Schristos	cie_basic	basic3
126*56bb7041Schristos	fde_basic	basic3,.text,0x40
127*56bb7041Schristos
128*56bb7041Schristos	cie_basic	basic4
129*56bb7041Schristos	fde_basic	basic4,.text,0x50
130*56bb7041Schristos
131*56bb7041Schristos	cie_zP		zP_unalign1,0x00,foo
132*56bb7041Schristos	fde_zP		zP_unalign1,.text,0x10
133*56bb7041Schristos	fde_zP		zP_unalign1,.text,0x20
134*56bb7041Schristos
135*56bb7041Schristos	cie_zP		zP_align1,0x50,foo
136*56bb7041Schristos	fde_zP		zP_align1,.text,0x10
137*56bb7041Schristos	fde_zP		zP_align1,.text,0x20
138*56bb7041Schristos
139*56bb7041Schristos	cie_zPR		zPR1,0x00,foo
140*56bb7041Schristos	fde_zPR		zPR1,.text,0x10
141*56bb7041Schristos	fde_zPR		zPR1,.discard,0x20
142*56bb7041Schristos
143*56bb7041Schristos	cie_zPR		zPR2,0x00,foo
144*56bb7041Schristos	fde_zPR		zPR2,.text,0x30
145*56bb7041Schristos	fde_zPR		zPR2,.text,0x40
146*56bb7041Schristos
147*56bb7041Schristos	cie_basic	basic5
148*56bb7041Schristos	fde_basic	basic5,.text,0x10
149*56bb7041Schristos
150*56bb7041Schristos	.if alignment == 2
151*56bb7041Schristos	.section	.gcc_compiled_long32
152*56bb7041Schristos	.endif
153