uplink-x86_64.pl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #! /usr/bin/env perl
  2. # Copyright 2008-2024 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. # $output is the last argument if it looks like a file (it has an extension)
  9. $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
  10. $flavour = $#ARGV >= 0 && $ARGV[0] !~ m|\.| ? shift : undef;
  11. $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
  12. open OUT,"| \"$^X\" \"${dir}../crypto/perlasm/x86_64-xlate.pl\" $flavour \"$output\""
  13. or die "can't call ${dir}../crypto/perlasm/x86_64-xlate.pl: $!";
  14. *STDOUT=*OUT;
  15. push(@INC,"${dir}.");
  16. require "uplink-common.pl";
  17. $prefix="_lazy";
  18. print <<___;
  19. .text
  20. .extern OPENSSL_Uplink
  21. .globl OPENSSL_UplinkTable
  22. ___
  23. for ($i=1;$i<=$N;$i++) {
  24. print <<___;
  25. .type $prefix${i},\@abi-omnipotent
  26. .align 16
  27. $prefix${i}:
  28. .byte 0x48,0x83,0xEC,0x28 # sub rsp,40
  29. mov %rcx,48(%rsp)
  30. mov %rdx,56(%rsp)
  31. mov %r8,64(%rsp)
  32. mov %r9,72(%rsp)
  33. lea OPENSSL_UplinkTable(%rip),%rcx
  34. mov \$$i,%rdx
  35. call OPENSSL_Uplink
  36. mov 48(%rsp),%rcx
  37. mov 56(%rsp),%rdx
  38. mov 64(%rsp),%r8
  39. mov 72(%rsp),%r9
  40. lea OPENSSL_UplinkTable(%rip),%rax
  41. add \$40,%rsp
  42. jmp *8*$i(%rax)
  43. $prefix${i}_end:
  44. .size $prefix${i},.-$prefix${i}
  45. ___
  46. }
  47. print <<___;
  48. .data
  49. OPENSSL_UplinkTable:
  50. .quad $N
  51. ___
  52. for ($i=1;$i<=$N;$i++) { print " .quad $prefix$i\n"; }
  53. print <<___;
  54. .section .pdata,"r"
  55. .align 4
  56. ___
  57. for ($i=1;$i<=$N;$i++) {
  58. print <<___;
  59. .rva $prefix${i},$prefix${i}_end,${prefix}_unwind_info
  60. ___
  61. }
  62. print <<___;
  63. .section .xdata,"r"
  64. .align 8
  65. ${prefix}_unwind_info:
  66. .byte 0x01,0x04,0x01,0x00
  67. .byte 0x04,0x42,0x00,0x00
  68. ___
  69. close STDOUT;