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