1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2012, Richard Lowe.
  14  */
  15 
  16 #define FUNC(x) \
  17         .text; \
  18         .align  16; \
  19         .globl  x; \
  20         .type   x, @function; \
  21 x:
  22 
  23 #define SET_SIZE(x, x_size) \
  24         .size   x, [.-x]; \
  25         .globl x_size; \
  26         .type  x_size, @object; \
  27 x_size:
  28 
  29 /*
  30  * Extracted versions of the functional tests
  31  *
  32  * Named of the form <compiler>-<prologue style>-<nature of test>
  33  * basic                        -- A regular function
  34  * align                        -- odd number of arguments needing save-area
  35  *                                 alignment
  36  * big-struct-ret               -- returns a > 16byte structure by value
  37  * big-struct-ret-and-spill     -- returns a > 16byte structure by value and
  38  *                                 spills args to the stack
  39  * small-struct-ret             -- returns a < 16byte structure by value
  40  * small-struct-ret-and-spill   -- returns a < 16byte structure by value and
  41  *                                 spills args to the stack
  42  * stack-spill                  -- spills arguments to the stack
  43  */
  44 FUNC(gcc_mov_align)
  45 pushq   %rbp
  46 movq    %rsp, %rbp
  47 movq    %rbx, -0x38(%rbp)
  48 movq    %r8, -0x28(%rbp)
  49 movq    %rcx, -0x20(%rbp)
  50 movq    %rdx, -0x18(%rbp)
  51 movq    %rsi, -0x10(%rbp)
  52 movq    %rdi, -0x8(%rbp)
  53 subq    $0x70, %rsp
  54 SET_SIZE(gcc_mov_align, gcc_mov_align_end)
  55 
  56 FUNC(gcc_mov_basic)
  57 pushq   %rbp
  58 movq    %rsp, %rbp
  59 movq    %rbx,-0x28(%rbp)
  60 movq    %rcx,-0x20(%rbp)
  61 movq    %rdx,-0x18(%rbp)
  62 movq    %rsi,-0x10(%rbp)
  63 movq    %rdi,-0x8(%rbp)
  64 subq    $0x50,%rsp
  65 SET_SIZE(gcc_mov_basic, gcc_mov_basic_end)
  66 
  67 FUNC(gcc_mov_big_struct_ret)
  68 pushq   %rbp
  69 movq    %rsp,%rbp
  70 movq    %rbx,-0x28(%rbp)
  71 movq    %r8,-0x20(%rbp)
  72 movq    %rcx,-0x18(%rbp)
  73 movq    %rdx,-0x10(%rbp)
  74 movq    %rsi,-0x8(%rbp)
  75 subq    $0x50,%rsp
  76 SET_SIZE(gcc_mov_big_struct_ret, gcc_mov_big_struct_ret_end)
  77 
  78 FUNC(gcc_mov_big_struct_ret_and_spill)
  79 pushq   %rbp
  80 movq    %rsp,%rbp
  81 movq    %rbx,-0x38(%rbp)
  82 movq    %r9,-0x28(%rbp)
  83 movq    %r8,-0x20(%rbp)
  84 movq    %rcx,-0x18(%rbp)
  85 movq    %rdx,-0x10(%rbp)
  86 movq    %rsi,-0x8(%rbp)
  87 subq    $0x90,%rsp
  88 SET_SIZE(gcc_mov_big_struct_ret_and_spill, gcc_mov_big_struct_ret_and_spill_end)
  89 
  90 FUNC(gcc_mov_small_struct_ret)
  91 pushq   %rbp
  92 movq    %rsp,%rbp
  93 movq    %rbx,-0x28(%rbp)
  94 movq    %rcx,-0x20(%rbp)
  95 movq    %rdx,-0x18(%rbp)
  96 movq    %rsi,-0x10(%rbp)
  97 movq    %rdi,-0x8(%rbp)
  98 subq    $0x50,%rsp
  99 SET_SIZE(gcc_mov_small_struct_ret, gcc_mov_small_struct_ret_end)
 100 
 101 FUNC(gcc_mov_small_struct_ret_and_spill)
 102 pushq   %rbp
 103 movq    %rsp,%rbp
 104 movq    %rbx,-0x38(%rbp)
 105 movq    %r9,-0x30(%rbp)
 106 movq    %r8,-0x28(%rbp)
 107 movq    %rcx,-0x20(%rbp)
 108 movq    %rdx,-0x18(%rbp)
 109 movq    %rsi,-0x10(%rbp)
 110 movq    %rdi,-0x8(%rbp)
 111 subq    $0x90,%rsp
 112 SET_SIZE(gcc_mov_small_struct_ret_and_spill, gcc_mov_small_struct_ret_and_spill_end)
 113 
 114 FUNC(gcc_mov_stack_spill)
 115 pushq   %rbp
 116 movq    %rsp,%rbp
 117 movq    %rbx,-0x38(%rbp)
 118 movq    %r9,-0x30(%rbp)
 119 movq    %r8,-0x28(%rbp)
 120 movq    %rcx,-0x20(%rbp)
 121 movq    %rdx,-0x18(%rbp)
 122 movq    %rsi,-0x10(%rbp)
 123 movq    %rdi,-0x8(%rbp)
 124 subq    $0x90,%rsp
 125 SET_SIZE(gcc_mov_stack_spill, gcc_mov_stack_spill_end)
 126 
 127 FUNC(gcc_push_align)
 128 pushq   %rbp
 129 movq    %rsp,%rbp
 130 pushq   %rdi
 131 pushq   %rsi
 132 pushq   %rdx
 133 pushq   %rcx
 134 pushq   %r8
 135 subq    $0x8,%rsp
 136 subq    $0x30,%rsp
 137 SET_SIZE(gcc_push_align, gcc_push_align_end)
 138 
 139 FUNC(gcc_push_basic)
 140 pushq   %rbp
 141 movq    %rsp,%rbp
 142 pushq   %rdi
 143 pushq   %rsi
 144 pushq   %rdx
 145 pushq   %rcx
 146 subq    $0x20,%rsp
 147 SET_SIZE(gcc_push_basic, gcc_push_basic_end)
 148 
 149 FUNC(gcc_push_big_struct_ret)
 150 pushq   %rbp
 151 movq    %rsp,%rbp
 152 pushq   %rsi
 153 pushq   %rdx
 154 pushq   %rcx
 155 pushq   %r8
 156 subq    $0x30,%rsp
 157 SET_SIZE(gcc_push_big_struct_ret, gcc_push_big_struct_ret_end)
 158 
 159 FUNC(gcc_push_big_struct_ret_and_spill)
 160 pushq   %rbp
 161 movq    %rsp,%rbp
 162 pushq   %rsi
 163 pushq   %rdx
 164 pushq   %rcx
 165 pushq   %r8
 166 pushq   %r9
 167 subq    $0x8,%rsp
 168 subq    $0x50,%rsp
 169 SET_SIZE(gcc_push_big_struct_ret_and_spill, gcc_push_big_struct_ret_and_spill_end)
 170 
 171 FUNC(gcc_push_small_struct_ret)
 172 pushq   %rbp
 173 movq    %rsp,%rbp
 174 pushq   %rdi
 175 pushq   %rsi
 176 pushq   %rdx
 177 pushq   %rcx
 178 subq    $0x20,%rsp
 179 SET_SIZE(gcc_push_small_struct_ret, gcc_push_small_struct_ret_end)
 180 
 181 FUNC(gcc_push_small_struct_ret_and_spill)
 182 pushq   %rbp
 183 movq    %rsp,%rbp
 184 pushq   %rdi
 185 pushq   %rsi
 186 pushq   %rdx
 187 pushq   %rcx
 188 pushq   %r8
 189 pushq   %r9
 190 subq    $0x50,%rsp
 191 SET_SIZE(gcc_push_small_struct_ret_and_spill, gcc_push_small_struct_ret_and_spill_end)
 192 
 193 FUNC(gcc_push_stack_spill)
 194 pushq   %rbp
 195 movq    %rsp,%rbp
 196 pushq   %rdi
 197 pushq   %rsi
 198 pushq   %rdx
 199 pushq   %rcx
 200 pushq   %r8
 201 pushq   %r9
 202 subq    $0x50,%rsp
 203 SET_SIZE(gcc_push_stack_spill, gcc_push_stack_spill_end)
 204 
 205 FUNC(ss_mov_align)
 206 pushq   %rbp
 207 movq    %rsp,%rbp
 208 subq    $0x30,%rsp
 209 movq    %rdi,-0x8(%rbp)
 210 movq    %rsi,-0x10(%rbp)
 211 movq    %rdx,-0x18(%rbp)
 212 movq    %rcx,-0x20(%rbp)
 213 movq    %r8,-0x28(%rbp)
 214 SET_SIZE(ss_mov_align, ss_mov_align_end)
 215 
 216 FUNC(ss_mov_basic)
 217 pushq   %rbp
 218 movq    %rsp,%rbp
 219 subq    $0x20,%rsp
 220 movq    %rdi,-0x8(%rbp)
 221 movq    %rsi,-0x10(%rbp)
 222 movq    %rdx,-0x18(%rbp)
 223 movq    %rcx,-0x20(%rbp)
 224 SET_SIZE(ss_mov_basic, ss_mov_basic_end)
 225 
 226 FUNC(ss_mov_big_struct_ret)
 227 pushq   %rbp
 228 movq    %rsp,%rbp
 229 subq    $0x30,%rsp
 230 movq    %rdi,-0x8(%rbp)
 231 movq    %rsi,-0x10(%rbp)
 232 movq    %rdx,-0x18(%rbp)
 233 movq    %rcx,-0x20(%rbp)
 234 movq    %r8,-0x28(%rbp)
 235 SET_SIZE(ss_mov_big_struct_ret, ss_mov_big_struct_ret_end)
 236 
 237 FUNC(ss_mov_big_struct_ret_and_spill)
 238 pushq   %rbp
 239 movq    %rsp,%rbp
 240 subq    $0x50,%rsp
 241 movq    %rdi,-0x8(%rbp)
 242 movq    %rsi,-0x10(%rbp)
 243 movq    %rdx,-0x18(%rbp)
 244 movq    %rcx,-0x20(%rbp)
 245 movq    %r8,-0x28(%rbp)
 246 movq    %r9,-0x30(%rbp)
 247 SET_SIZE(ss_mov_big_struct_ret_and_spill, ss_mov_big_struct_ret_and_spill_end)
 248 
 249 FUNC(ss_mov_small_struct_ret)
 250 pushq   %rbp
 251 movq    %rsp,%rbp
 252 subq    $0x20,%rsp
 253 movq    %rdi,-0x8(%rbp)
 254 movq    %rsi,-0x10(%rbp)
 255 movq    %rdx,-0x18(%rbp)
 256 movq    %rcx,-0x20(%rbp)
 257 SET_SIZE(ss_mov_small_struct_ret, ss_mov_small_struct_ret_end)
 258 
 259 FUNC(ss_mov_small_struct_ret_and_spill)
 260 pushq   %rbp
 261 movq    %rsp,%rbp
 262 subq    $0x50,%rsp
 263 movq    %rdi,-0x8(%rbp)
 264 movq    %rsi,-0x10(%rbp)
 265 movq    %rdx,-0x18(%rbp)
 266 movq    %rcx,-0x20(%rbp)
 267 movq    %r8,-0x28(%rbp)
 268 movq    %r9,-0x30(%rbp)
 269 SET_SIZE(ss_mov_small_struct_ret_and_spill, ss_mov_small_struct_ret_and_spill_end)
 270 
 271 FUNC(ss_mov_stack_spill)
 272 pushq   %rbp
 273 movq    %rsp,%rbp
 274 subq    $0x50,%rsp
 275 movq    %rdi,-0x8(%rbp)
 276 movq    %rsi,-0x10(%rbp)
 277 movq    %rdx,-0x18(%rbp)
 278 movq    %rcx,-0x20(%rbp)
 279 movq    %r8,-0x28(%rbp)
 280 movq    %r9,-0x30(%rbp)
 281 SET_SIZE(ss_mov_stack_spill, ss_mov_stack_spill_end)
 282 
 283 /* DTrace instrumentation */
 284 FUNC(dtrace_instrumented)
 285 int     $0x3
 286 movq    %rsp, %rbp
 287 movq    %rbx,-0x28(%rbp)
 288 movq    %rcx,-0x20(%rbp)
 289 movq    %rdx,-0x18(%rbp)
 290 movq    %rsi,-0x10(%rbp)
 291 movq    %rdi,-0x8(%rbp)
 292 subq    $0x50,%rsp
 293 SET_SIZE(dtrace_instrumented, dtrace_instrumented_end)
 294 
 295 /*
 296  * System functions with special characteristics, be they non-initial FP save,
 297  * gaps between FP save and argument saving, or gaps between saved arguments.
 298  */
 299 FUNC(kmem_alloc)
 300 leaq    -0x1(%rdi),%rax
 301 pushq   %rbp
 302 movq    %rax,%rdx
 303 movq    %rsp,%rbp
 304 subq    $0x30,%rsp
 305 shrq    $0x3,%rdx
 306 movq    %r12,-0x28(%rbp)
 307 movq    %rbx,-0x30(%rbp)
 308 cmpq    $0x1ff,%rdx
 309 movq    %r13,-0x20(%rbp)
 310 movq    %r14,-0x18(%rbp)
 311 movq    %rsi,-0x10(%rbp)
 312 movq    %rdi,-0x8(%rbp)
 313 movq    %rdi,%r12
 314 SET_SIZE(kmem_alloc, kmem_alloc_end)
 315 
 316 FUNC(uts_kill)
 317 pushq   %rbp
 318 movq    %rsp,%rbp
 319 subq    $0x50,%rsp
 320 movq    %rbx,-0x28(%rbp)
 321 leaq    -0x50(%rbp),%rbx
 322 movq    %r12,-0x20(%rbp)
 323 movq    %r13,-0x18(%rbp)
 324 movq    %rsi,-0x10(%rbp)
 325 movl    %edi,%r12d
 326 movq    %rdi,-0x8(%rbp)
 327 SET_SIZE(uts_kill, uts_kill_end)
 328 
 329 FUNC(av1394_ic_bitreverse)
 330 movq    %rdi,%rdx
 331 movq    $0x5555555555555555,%rax
 332 movq    $0x3333333333333333,%rcx
 333 shrq    $0x1,%rdx
 334 pushq   %rbp
 335 andq    %rax,%rdx
 336 andq    %rdi,%rax
 337 addq    %rax,%rax
 338 movq    %rsp,%rbp
 339 subq    $0x10,%rsp
 340 orq     %rdx,%rax
 341 movq    %rdi,-0x8(%rbp)
 342 SET_SIZE(av1394_ic_bitreverse, av1394_ic_bitreverse_end)
 343 
 344 /* Problematic functions which should not match */
 345 
 346 FUNC(no_fp) /* No frame pointer */
 347 movq    %rdi, %rsi
 348 movq    %rsi, %rdi
 349 movq    %rbx,-0x28(%rbp)
 350 movq    %rcx,-0x20(%rbp)
 351 movq    %rdx,-0x18(%rbp)
 352 movq    %rsi,-0x10(%rbp)
 353 movq    %rdi,-0x8(%rbp)
 354 subq    $0x50,%rsp
 355 SET_SIZE(no_fp, no_fp_end)
 356 
 357 /* Small structure return, but with an SSE type (thus forcing it to the stack) */
 358 FUNC(small_struct_ret_w_float)
 359 pushq   %rbp
 360 movq    %rsp,%rbp
 361 movq    %rdi,-0x8(%rbp)
 362 subq    $0x30,%rsp
 363 SET_SIZE(small_struct_ret_w_float, small_struct_ret_w_float_end)
 364 
 365 /* Big structure return, but with an SSE type */
 366 FUNC(big_struct_ret_w_float)
 367 pushq  %rbp
 368 movq   %rsp,%rbp
 369 movq   %rsi,-0x8(%rbp)
 370 subq   $0x50,%rsp
 371 movq   %rsi,-0x48(%rbp)
 372 movq   -0x48(%rbp),%rax
 373 movq   %rax,%rsi
 374 movl   $0x400f60,%edi
 375 movl   $0x0,%eax
 376 movl   $0x1770,%edi
 377 movl   $0x0,%eax
 378 leave
 379 ret
 380 SET_SIZE(big_struct_ret_w_float, big_struct_ret_w_float_end)
 381 
 382 FUNC(big_struct_arg_by_value)
 383 pushq   %rbp
 384 movq    %rsp,%rbp
 385 movq    %rdi,-0x8(%rbp)
 386 subq    $0x40,%rsp
 387 SET_SIZE(big_struct_arg_by_value, big_struct_arg_by_value_end)
 388 
 389 FUNC(small_struct_arg_by_value)
 390 pushq   %rbp
 391 movq    %rsp,%rbp
 392 movq    %rdx,-0x18(%rbp)
 393 movq    %rsi,-0x10(%rbp)
 394 movq    %rdi,-0x8(%rbp)
 395 subq    $0x50,%rsp
 396 SET_SIZE(small_struct_arg_by_value, small_struct_arg_by_value_end)