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