x86asm.pl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/usr/local/bin/perl
  2. # require 'x86asm.pl';
  3. # &asm_init("cpp","des-586.pl");
  4. # XXX
  5. # XXX
  6. # main'asm_finish
  7. sub main'asm_finish
  8. {
  9. &file_end();
  10. &asm_finish_cpp() if $cpp;
  11. print &asm_get_output();
  12. }
  13. sub main'asm_init
  14. {
  15. ($type,$fn,$i386)=@_;
  16. $filename=$fn;
  17. $elf=$cpp=$coff=$aout=$win32=$netware=$mwerks=0;
  18. if ( ($type eq "elf"))
  19. { $elf=1; require "x86unix.pl"; }
  20. elsif ( ($type eq "a.out"))
  21. { $aout=1; require "x86unix.pl"; }
  22. elsif ( ($type eq "coff" or $type eq "gaswin"))
  23. { $coff=1; require "x86unix.pl"; }
  24. elsif ( ($type eq "cpp"))
  25. { $cpp=1; require "x86unix.pl"; }
  26. elsif ( ($type eq "win32"))
  27. { $win32=1; require "x86ms.pl"; }
  28. elsif ( ($type eq "win32n"))
  29. { $win32=1; require "x86nasm.pl"; }
  30. elsif ( ($type eq "nw-nasm"))
  31. { $netware=1; require "x86nasm.pl"; }
  32. elsif ( ($type eq "nw-mwasm"))
  33. { $netware=1; $mwerks=1; require "x86nasm.pl"; }
  34. else
  35. {
  36. print STDERR <<"EOF";
  37. Pick one target type from
  38. elf - Linux, FreeBSD, Solaris x86, etc.
  39. a.out - OpenBSD, DJGPP, etc.
  40. coff - GAS/COFF such as Win32 targets
  41. win32 - Windows 95/Windows NT
  42. win32n - Windows 95/Windows NT NASM format
  43. nw-nasm - NetWare NASM format
  44. nw-mwasm- NetWare Metrowerks Assembler
  45. EOF
  46. exit(1);
  47. }
  48. $pic=0;
  49. for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); }
  50. &asm_init_output();
  51. &comment("Don't even think of reading this code");
  52. &comment("It was automatically generated by $filename");
  53. &comment("Which is a perl program used to generate the x86 assember for");
  54. &comment("any of ELF, a.out, COFF, Win32, ...");
  55. &comment("eric <eay\@cryptsoft.com>");
  56. &comment("");
  57. $filename =~ s/\.pl$//;
  58. &file($filename);
  59. }
  60. sub asm_finish_cpp
  61. {
  62. return unless $cpp;
  63. local($tmp,$i);
  64. foreach $i (&get_labels())
  65. {
  66. $tmp.="#define $i _$i\n";
  67. }
  68. print <<"EOF";
  69. /* Run the C pre-processor over this file with one of the following defined
  70. * ELF - elf object files,
  71. * OUT - a.out object files,
  72. * BSDI - BSDI style a.out object files
  73. * SOL - Solaris style elf
  74. */
  75. #define TYPE(a,b) .type a,b
  76. #define SIZE(a,b) .size a,b
  77. #if defined(OUT) || (defined(BSDI) && !defined(ELF))
  78. $tmp
  79. #endif
  80. #ifdef OUT
  81. #define OK 1
  82. #define ALIGN 4
  83. #if defined(__CYGWIN__) || defined(__DJGPP__) || defined(__MINGW32__)
  84. #undef SIZE
  85. #undef TYPE
  86. #define SIZE(a,b)
  87. #define TYPE(a,b) .def a; .scl 2; .type 32; .endef
  88. #endif /* __CYGWIN || __DJGPP */
  89. #endif
  90. #if defined(BSDI) && !defined(ELF)
  91. #define OK 1
  92. #define ALIGN 4
  93. #undef SIZE
  94. #undef TYPE
  95. #define SIZE(a,b)
  96. #define TYPE(a,b)
  97. #endif
  98. #if defined(ELF) || defined(SOL)
  99. #define OK 1
  100. #define ALIGN 16
  101. #endif
  102. #ifndef OK
  103. You need to define one of
  104. ELF - elf systems - linux-elf, NetBSD and DG-UX
  105. OUT - a.out systems - linux-a.out and FreeBSD
  106. SOL - solaris systems, which are elf with strange comment lines
  107. BSDI - a.out with a very primative version of as.
  108. #endif
  109. /* Let the Assembler begin :-) */
  110. EOF
  111. }
  112. 1;