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