Home | History | Annotate | Download | only in x86
      1 #
      2 # rep, repe (repz) and repne (repnz) prefixed string instructions
      3 #   only count as one instruction, even though they repeat many times
      4 # This test makes sure the bbv plugin counts these instructions properly
      5 # The answer is validated to hw perf counters.
      6 #
      7 
      8 	.globl _start
      9 _start:
     10 	cld				# we want these to happen forward
     11 
     12 	#===================================
     13 	# Check varied order of the size prefix
     14 	#   with the rep prefix.  Older binutils
     15 	#   did this one way, newer binutils the other
     16 	#===================================
     17 
     18 size_prefix:
     19 	# test 16-bit load
     20 
     21 	mov	$8192, %ecx
     22 	mov	$buffer1, %esi		# set source
     23 	.byte 0x66, 0xf3, 0xad		# lodsw
     24 
     25 	mov	$8192, %ecx
     26 	mov	$buffer1, %esi		# set source
     27 	.byte 0xf3, 0x66, 0xad		# lodsw
     28 
     29 
     30 
     31 
     32 	#===================================
     33 	# Load and Store Instructions
     34 	#===================================
     35 loadstore:
     36 	xor	%eax, %eax
     37 	mov	$0xd, %al		# set eax to d
     38 
     39 	# test 8-bit store
     40 
     41 	mov	$16384, %ecx
     42 	mov	$buffer1, %edi		# set destination
     43 	rep	stosb	    		# store d 16384 times, auto-increment
     44 
     45 	# test 8-bit load
     46 
     47 	mov	$16384, %ecx
     48 	mov	$buffer1, %esi		# set source
     49 	rep	lodsb	    		# load byte 16384 times, auto-increment
     50 
     51 	cmp	$0xd,%al		# if we loaded wrong value
     52 	jne	print_error		# print an error
     53 
     54 	# test 16-bit store
     55 
     56 	mov    	$0x020d,%ax		# store 0x020d
     57 
     58 	mov	$8192, %ecx
     59 	mov	$buffer1, %edi		# set destination
     60 	rep	stosw	    		# store 8192 times, auto-increment
     61 
     62 	# test 16-bit load
     63 
     64 	mov	$8192, %ecx
     65 	mov	$buffer1, %esi		# set source
     66 	rep	lodsw	    		# load 8192 times, auto-increment
     67 
     68 	cmp	$0x020d,%ax		# if we loaded wrong value
     69 	jne	print_error		# print an error
     70 
     71 	# test 32-bit store
     72 
     73 	mov    	$0x0feb1378,%eax	# store 0x0feb1378
     74 
     75 	mov	$4096, %ecx
     76 	mov	$buffer1, %edi		# set destination
     77 	rep	stosl	    		# store 4096 times, auto-increment
     78 
     79 	# test 32-bit load
     80 
     81 	mov	$4096, %ecx
     82 	mov	$buffer1, %esi		# set source
     83 	rep	lodsl	    		# load 4096 times, auto-increment
     84 
     85 	cmp	$0x0feb1378,%eax	# if we loaded wrong value
     86 	jne	print_error		# print an error
     87 
     88 	#=============================
     89 	# Move instructions
     90 	#=============================
     91 moves:
     92 	# test 8-bit move
     93 
     94 	mov    $16384, %ecx
     95 	mov    $buffer1, %esi
     96 	mov    $buffer2, %edi
     97 	rep    movsb
     98 
     99 	# test 16-bit move
    100 
    101 	mov    $8192, %ecx
    102 	mov    $buffer2, %esi
    103 	mov    $buffer1, %edi
    104 	rep    movsw
    105 
    106 	# test 32-bit move
    107 
    108 	mov    $4096, %ecx
    109 	mov    $buffer1, %esi
    110 	mov    $buffer2, %edi
    111 	rep    movsl
    112 
    113 	#==================================
    114 	# Compare equal instructions
    115 	#==================================
    116 compare_equal:
    117 	# first set up the areas to compare
    118 
    119 	mov	$0xa5a5a5a5,%eax
    120 	mov	$buffer1, %edi
    121 	mov	$4096, %ecx
    122 	rep	stosl
    123 
    124 	mov	$0xa5a5a5a5,%eax
    125 	mov	$buffer2, %edi
    126 	mov	$4096, %ecx
    127 	rep	stosl
    128 
    129 	# test 8-bit
    130 
    131 	mov	$buffer1,%esi
    132 	mov	$buffer2,%edi
    133 	mov	$16384, %ecx
    134 	repe	cmpsb
    135 	jnz	print_error
    136 
    137 	# test 16-bit
    138 
    139 	mov	$buffer1,%esi
    140 	mov	$buffer2,%edi
    141 	mov	$8192, %ecx
    142 	repe	cmpsw
    143 	jnz	print_error
    144 
    145 	# test 32-bit
    146 
    147 	mov	$buffer1,%esi
    148 	mov	$buffer2,%edi
    149 	mov	$4096, %ecx
    150 	repe	cmpsl
    151 	jnz	print_error
    152 
    153 	#==================================
    154 	# Compare not equal instructions
    155 	#==================================
    156 compare_noteq:
    157 	# change second buffer
    158 
    159 	mov	$0x5a5a5a5a,%eax
    160 	mov	$buffer2, %edi
    161 	mov	$4096, %ecx
    162 	rep	stosl
    163 
    164 	# test 8-bit
    165 
    166 	mov	$buffer1,%esi
    167 	mov	$buffer2,%edi
    168 	mov	$16384, %ecx
    169 	repne	cmpsb
    170 	je	print_error
    171 
    172 	# test 16-bit
    173 
    174 	mov	$buffer1,%esi
    175 	mov	$buffer2,%edi
    176 	mov	$8192, %ecx
    177 	repne	cmpsw
    178 	je	print_error
    179 
    180 	# test 32-bit
    181 
    182 	mov	$buffer1,%esi
    183 	mov	$buffer2,%edi
    184 	mov	$4096, %ecx
    185 	repne	cmpsl
    186 	je	print_error
    187 
    188 	#====================================
    189 	# Check scan equal instruction
    190 	#====================================
    191 
    192 	# test 8-bit
    193 
    194 	mov     $0xa5,%al
    195 	mov	$buffer1,%edi
    196 	mov	$16384, %ecx
    197 	repe	scasb
    198 	jnz	print_error
    199 
    200 	# test 16-bit
    201 
    202 	mov     $0xa5a5,%ax
    203 	mov	$buffer1,%edi
    204 	mov	$8192, %ecx
    205 	repe	scasw
    206 	jnz	print_error
    207 
    208 	# test 32-bit
    209 
    210 	mov	$0xa5a5a5a5,%eax
    211 	mov	$buffer1,%edi
    212 	mov	$4096, %ecx
    213 	repe	scasl
    214 	jnz	print_error
    215 
    216 	#====================================
    217 	# Check scan not-equal instruction
    218 	#====================================
    219 
    220 	# test 8-bit
    221 
    222 	mov     $0xa5,%al
    223 	mov	$buffer2,%edi
    224 	mov	$16384, %ecx
    225 	repne	scasb
    226 	jz	print_error
    227 
    228 	# test 16-bit
    229 
    230 	mov     $0xa5a5,%ax
    231 	mov	$buffer2,%edi
    232 	mov	$8192, %ecx
    233 	repne	scasw
    234 	jz	print_error
    235 
    236 	# test 32-bit
    237 
    238 	mov	$0xa5a5a5a5,%eax
    239 	mov	$buffer2,%edi
    240 	mov	$4096, %ecx
    241 	repne	scasl
    242 	jz	print_error
    243 
    244 	jmp	exit			# no error, skip to exit
    245 
    246 print_error:
    247 
    248 	mov 	$4, %eax		# Write syscall
    249 #ifdef VGO_darwin
    250 	pushl	$1
    251 	pushl	$error_string
    252 	pushl	$16
    253 #else
    254 	mov	$1, %ebx		# print to stdout
    255 	mov	$error_string, %ecx	# string to print
    256 	mov	$16, %edx      	   	# strlen
    257 #endif
    258 	int	$0x80	 		# call syscall
    259 
    260 	#================================
    261 	# Exit
    262 	#================================
    263 exit:
    264 #ifdef VGO_darwin
    265 	xor     %ebx,%ebx		# we return 0
    266 #else
    267 	pushl	$0			# we return 0
    268 #endif
    269 	xor	%eax,%eax
    270 	inc	%eax	 		# put exit syscall number (1) in eax
    271 	int     $0x80             	# and exit
    272 
    273 
    274 .data
    275 error_string:	.asciz "Error detected!\n"
    276 
    277 #.bss
    278 
    279 .lcomm	buffer1,	16384
    280 .lcomm	buffer2,	16384
    281