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