diff options
author | ryker <> | 1998-10-05 20:13:15 +0000 |
---|---|---|
committer | ryker <> | 1998-10-05 20:13:15 +0000 |
commit | 536c76cbb863bab152f19842ab88772c01e922c7 (patch) | |
tree | dfecec371a097b73d605aae665887946d9982219 /src/lib/libcrypto/perlasm | |
download | openbsd-536c76cbb863bab152f19842ab88772c01e922c7.tar.gz openbsd-536c76cbb863bab152f19842ab88772c01e922c7.tar.bz2 openbsd-536c76cbb863bab152f19842ab88772c01e922c7.zip |
Import of SSLeay-0.9.0b with RSA and IDEA stubbed + OpenBSD build
functionality for shared libs.
Note that routines such as sslv2_init and friends that use RSA will
not work due to lack of RSA in this library.
Needs documentation and help from ports for easy upgrade to full
functionality where legally possible.
Diffstat (limited to 'src/lib/libcrypto/perlasm')
-rw-r--r-- | src/lib/libcrypto/perlasm/x86ms.pl | 348 | ||||
-rw-r--r-- | src/lib/libcrypto/perlasm/x86unix.pl | 429 |
2 files changed, 777 insertions, 0 deletions
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl new file mode 100644 index 0000000000..893b50b1a4 --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86ms.pl | |||
@@ -0,0 +1,348 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | package x86ms; | ||
4 | |||
5 | $label="L000"; | ||
6 | |||
7 | %lb=( 'eax', 'al', | ||
8 | 'ebx', 'bl', | ||
9 | 'ecx', 'cl', | ||
10 | 'edx', 'dl', | ||
11 | 'ax', 'al', | ||
12 | 'bx', 'bl', | ||
13 | 'cx', 'cl', | ||
14 | 'dx', 'dl', | ||
15 | ); | ||
16 | |||
17 | %hb=( 'eax', 'ah', | ||
18 | 'ebx', 'bh', | ||
19 | 'ecx', 'ch', | ||
20 | 'edx', 'dh', | ||
21 | 'ax', 'ah', | ||
22 | 'bx', 'bh', | ||
23 | 'cx', 'ch', | ||
24 | 'dx', 'dh', | ||
25 | ); | ||
26 | |||
27 | sub main'asm_init_output { @out=(); } | ||
28 | sub main'asm_get_output { return(@out); } | ||
29 | sub main'get_labels { return(@labels); } | ||
30 | sub main'external_label { push(@labels,@_); } | ||
31 | |||
32 | sub main'LB | ||
33 | { | ||
34 | (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; | ||
35 | return($lb{$_[0]}); | ||
36 | } | ||
37 | |||
38 | sub main'HB | ||
39 | { | ||
40 | (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; | ||
41 | return($hb{$_[0]}); | ||
42 | } | ||
43 | |||
44 | sub main'BP | ||
45 | { | ||
46 | &get_mem("BYTE",@_); | ||
47 | } | ||
48 | |||
49 | sub main'DWP | ||
50 | { | ||
51 | &get_mem("DWORD",@_); | ||
52 | } | ||
53 | |||
54 | sub main'stack_push | ||
55 | { | ||
56 | local($num)=@_; | ||
57 | $stack+=$num*4; | ||
58 | &main'sub("esp",$num*4); | ||
59 | } | ||
60 | |||
61 | sub main'stack_pop | ||
62 | { | ||
63 | local($num)=@_; | ||
64 | $stack-=$num*4; | ||
65 | &main'add("esp",$num*4); | ||
66 | } | ||
67 | |||
68 | sub get_mem | ||
69 | { | ||
70 | local($size,$addr,$reg1,$reg2,$idx)=@_; | ||
71 | local($t,$post); | ||
72 | local($ret)="$size PTR "; | ||
73 | |||
74 | $addr =~ s/^\s+//; | ||
75 | if ($addr =~ /^(.+)\+(.+)$/) | ||
76 | { | ||
77 | $reg2=&conv($1); | ||
78 | $addr="_$2"; | ||
79 | } | ||
80 | elsif ($addr =~ /^[_a-zA-Z]/) | ||
81 | { | ||
82 | $addr="_$addr"; | ||
83 | } | ||
84 | |||
85 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
86 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
87 | if (($addr ne "") && ($addr ne 0)) | ||
88 | { | ||
89 | if ($addr !~ /^-/) | ||
90 | { $ret.=$addr; } | ||
91 | else { $post=$addr; } | ||
92 | } | ||
93 | if ($reg2 ne "") | ||
94 | { | ||
95 | $t=""; | ||
96 | $t="*$idx" if ($idx != 0); | ||
97 | $reg1="+".$reg1 if ("$reg1$post" ne ""); | ||
98 | $ret.="[$reg2$t$reg1$post]"; | ||
99 | } | ||
100 | else | ||
101 | { | ||
102 | $ret.="[$reg1$post]" | ||
103 | } | ||
104 | return($ret); | ||
105 | } | ||
106 | |||
107 | sub main'mov { &out2("mov",@_); } | ||
108 | sub main'movb { &out2("mov",@_); } | ||
109 | sub main'and { &out2("and",@_); } | ||
110 | sub main'or { &out2("or",@_); } | ||
111 | sub main'shl { &out2("shl",@_); } | ||
112 | sub main'shr { &out2("shr",@_); } | ||
113 | sub main'xor { &out2("xor",@_); } | ||
114 | sub main'xorb { &out2("xor",@_); } | ||
115 | sub main'add { &out2("add",@_); } | ||
116 | sub main'adc { &out2("adc",@_); } | ||
117 | sub main'sub { &out2("sub",@_); } | ||
118 | sub main'rotl { &out2("rol",@_); } | ||
119 | sub main'rotr { &out2("ror",@_); } | ||
120 | sub main'exch { &out2("xchg",@_); } | ||
121 | sub main'cmp { &out2("cmp",@_); } | ||
122 | sub main'lea { &out2("lea",@_); } | ||
123 | sub main'mul { &out1("mul",@_); } | ||
124 | sub main'div { &out1("div",@_); } | ||
125 | sub main'dec { &out1("dec",@_); } | ||
126 | sub main'inc { &out1("inc",@_); } | ||
127 | sub main'jmp { &out1("jmp",@_); } | ||
128 | sub main'jmp_ptr { &out1p("jmp",@_); } | ||
129 | sub main'je { &out1("je",@_); } | ||
130 | sub main'jle { &out1("jle",@_); } | ||
131 | sub main'jz { &out1("jz",@_); } | ||
132 | sub main'jge { &out1("jge",@_); } | ||
133 | sub main'jl { &out1("jl",@_); } | ||
134 | sub main'jb { &out1("jb",@_); } | ||
135 | sub main'jc { &out1("jc",@_); } | ||
136 | sub main'jnc { &out1("jnc",@_); } | ||
137 | sub main'jnz { &out1("jnz",@_); } | ||
138 | sub main'jne { &out1("jne",@_); } | ||
139 | sub main'jno { &out1("jno",@_); } | ||
140 | sub main'push { &out1("push",@_); $stack+=4; } | ||
141 | sub main'pop { &out1("pop",@_); $stack-=4; } | ||
142 | sub main'bswap { &out1("bswap",@_); &using486(); } | ||
143 | sub main'not { &out1("not",@_); } | ||
144 | sub main'call { &out1("call",'_'.$_[0]); } | ||
145 | sub main'ret { &out0("ret"); } | ||
146 | sub main'nop { &out0("nop"); } | ||
147 | |||
148 | sub out2 | ||
149 | { | ||
150 | local($name,$p1,$p2)=@_; | ||
151 | local($l,$t); | ||
152 | |||
153 | push(@out,"\t$name\t"); | ||
154 | $t=&conv($p1).","; | ||
155 | $l=length($t); | ||
156 | push(@out,$t); | ||
157 | $l=4-($l+9)/8; | ||
158 | push(@out,"\t" x $l); | ||
159 | push(@out,&conv($p2)); | ||
160 | push(@out,"\n"); | ||
161 | } | ||
162 | |||
163 | sub out0 | ||
164 | { | ||
165 | local($name)=@_; | ||
166 | |||
167 | push(@out,"\t$name\n"); | ||
168 | } | ||
169 | |||
170 | sub out1 | ||
171 | { | ||
172 | local($name,$p1)=@_; | ||
173 | local($l,$t); | ||
174 | |||
175 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
176 | } | ||
177 | |||
178 | sub conv | ||
179 | { | ||
180 | local($p)=@_; | ||
181 | |||
182 | $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; | ||
183 | return $p; | ||
184 | } | ||
185 | |||
186 | sub using486 | ||
187 | { | ||
188 | return if $using486; | ||
189 | $using486++; | ||
190 | grep(s/\.386/\.486/,@out); | ||
191 | } | ||
192 | |||
193 | sub main'file | ||
194 | { | ||
195 | local($file)=@_; | ||
196 | |||
197 | local($tmp)=<<"EOF"; | ||
198 | TITLE $file.asm | ||
199 | .386 | ||
200 | .model FLAT | ||
201 | EOF | ||
202 | push(@out,$tmp); | ||
203 | } | ||
204 | |||
205 | sub main'function_begin | ||
206 | { | ||
207 | local($func,$extra)=@_; | ||
208 | |||
209 | push(@labels,$func); | ||
210 | |||
211 | local($tmp)=<<"EOF"; | ||
212 | _TEXT SEGMENT | ||
213 | PUBLIC _$func | ||
214 | $extra | ||
215 | _$func PROC NEAR | ||
216 | push ebp | ||
217 | push ebx | ||
218 | push esi | ||
219 | push edi | ||
220 | EOF | ||
221 | push(@out,$tmp); | ||
222 | $stack=20; | ||
223 | } | ||
224 | |||
225 | sub main'function_begin_B | ||
226 | { | ||
227 | local($func,$extra)=@_; | ||
228 | |||
229 | local($tmp)=<<"EOF"; | ||
230 | _TEXT SEGMENT | ||
231 | PUBLIC _$func | ||
232 | $extra | ||
233 | _$func PROC NEAR | ||
234 | EOF | ||
235 | push(@out,$tmp); | ||
236 | $stack=4; | ||
237 | } | ||
238 | |||
239 | sub main'function_end | ||
240 | { | ||
241 | local($func)=@_; | ||
242 | |||
243 | local($tmp)=<<"EOF"; | ||
244 | pop edi | ||
245 | pop esi | ||
246 | pop ebx | ||
247 | pop ebp | ||
248 | ret | ||
249 | _$func ENDP | ||
250 | _TEXT ENDS | ||
251 | EOF | ||
252 | push(@out,$tmp); | ||
253 | $stack=0; | ||
254 | %label=(); | ||
255 | } | ||
256 | |||
257 | sub main'function_end_B | ||
258 | { | ||
259 | local($func)=@_; | ||
260 | |||
261 | local($tmp)=<<"EOF"; | ||
262 | _$func ENDP | ||
263 | _TEXT ENDS | ||
264 | EOF | ||
265 | push(@out,$tmp); | ||
266 | $stack=0; | ||
267 | %label=(); | ||
268 | } | ||
269 | |||
270 | sub main'function_end_A | ||
271 | { | ||
272 | local($func)=@_; | ||
273 | |||
274 | local($tmp)=<<"EOF"; | ||
275 | pop edi | ||
276 | pop esi | ||
277 | pop ebx | ||
278 | pop ebp | ||
279 | ret | ||
280 | EOF | ||
281 | push(@out,$tmp); | ||
282 | } | ||
283 | |||
284 | sub main'file_end | ||
285 | { | ||
286 | push(@out,"END\n"); | ||
287 | } | ||
288 | |||
289 | sub main'wparam | ||
290 | { | ||
291 | local($num)=@_; | ||
292 | |||
293 | return(&main'DWP($stack+$num*4,"esp","",0)); | ||
294 | } | ||
295 | |||
296 | sub main'swtmp | ||
297 | { | ||
298 | return(&main'DWP($_[0]*4,"esp","",0)); | ||
299 | } | ||
300 | |||
301 | # Should use swtmp, which is above esp. Linix can trash the stack above esp | ||
302 | #sub main'wtmp | ||
303 | # { | ||
304 | # local($num)=@_; | ||
305 | # | ||
306 | # return(&main'DWP(-(($num+1)*4),"esp","",0)); | ||
307 | # } | ||
308 | |||
309 | sub main'comment | ||
310 | { | ||
311 | foreach (@_) | ||
312 | { | ||
313 | push(@out,"\t; $_\n"); | ||
314 | } | ||
315 | } | ||
316 | |||
317 | sub main'label | ||
318 | { | ||
319 | if (!defined($label{$_[0]})) | ||
320 | { | ||
321 | $label{$_[0]}="\$${label}${_[0]}"; | ||
322 | $label++; | ||
323 | } | ||
324 | return($label{$_[0]}); | ||
325 | } | ||
326 | |||
327 | sub main'set_label | ||
328 | { | ||
329 | if (!defined($label{$_[0]})) | ||
330 | { | ||
331 | $label{$_[0]}="${label}${_[0]}"; | ||
332 | $label++; | ||
333 | } | ||
334 | push(@out,"$label{$_[0]}:\n"); | ||
335 | } | ||
336 | |||
337 | sub main'data_word | ||
338 | { | ||
339 | push(@out,"\tDD\t$_[0]\n"); | ||
340 | } | ||
341 | |||
342 | sub out1p | ||
343 | { | ||
344 | local($name,$p1)=@_; | ||
345 | local($l,$t); | ||
346 | |||
347 | push(@out,"\t$name\t ".&conv($p1)."\n"); | ||
348 | } | ||
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl new file mode 100644 index 0000000000..6ee4dd3245 --- /dev/null +++ b/src/lib/libcrypto/perlasm/x86unix.pl | |||
@@ -0,0 +1,429 @@ | |||
1 | #!/usr/bin/perl | ||
2 | |||
3 | # Because the bswapl instruction is not supported for old assembers | ||
4 | # (it was a new instruction for the 486), I've added .byte xxxx code | ||
5 | # to put it in. | ||
6 | # eric 24-Apr-1998 | ||
7 | # | ||
8 | |||
9 | package x86unix; | ||
10 | |||
11 | $label="L000"; | ||
12 | |||
13 | $align=($main'aout)?"4":"16"; | ||
14 | $under=($main'aout)?"_":""; | ||
15 | $com_start=($main'sol)?"/":"#"; | ||
16 | |||
17 | sub main'asm_init_output { @out=(); } | ||
18 | sub main'asm_get_output { return(@out); } | ||
19 | sub main'get_labels { return(@labels); } | ||
20 | sub main'external_label { push(@labels,@_); } | ||
21 | |||
22 | if ($main'cpp) | ||
23 | { | ||
24 | $align="ALIGN"; | ||
25 | $under=""; | ||
26 | $com_start='/*'; | ||
27 | $com_end='*/'; | ||
28 | } | ||
29 | |||
30 | %lb=( 'eax', '%al', | ||
31 | 'ebx', '%bl', | ||
32 | 'ecx', '%cl', | ||
33 | 'edx', '%dl', | ||
34 | 'ax', '%al', | ||
35 | 'bx', '%bl', | ||
36 | 'cx', '%cl', | ||
37 | 'dx', '%dl', | ||
38 | ); | ||
39 | |||
40 | %hb=( 'eax', '%ah', | ||
41 | 'ebx', '%bh', | ||
42 | 'ecx', '%ch', | ||
43 | 'edx', '%dh', | ||
44 | 'ax', '%ah', | ||
45 | 'bx', '%bh', | ||
46 | 'cx', '%ch', | ||
47 | 'dx', '%dh', | ||
48 | ); | ||
49 | |||
50 | %regs=( 'eax', '%eax', | ||
51 | 'ebx', '%ebx', | ||
52 | 'ecx', '%ecx', | ||
53 | 'edx', '%edx', | ||
54 | 'esi', '%esi', | ||
55 | 'edi', '%edi', | ||
56 | 'ebp', '%ebp', | ||
57 | 'esp', '%esp', | ||
58 | ); | ||
59 | |||
60 | %reg_val=( | ||
61 | 'eax', 0x00, | ||
62 | 'ebx', 0x03, | ||
63 | 'ecx', 0x01, | ||
64 | 'edx', 0x02, | ||
65 | 'esi', 0x06, | ||
66 | 'edi', 0x07, | ||
67 | 'ebp', 0x05, | ||
68 | 'esp', 0x04, | ||
69 | ); | ||
70 | |||
71 | sub main'LB | ||
72 | { | ||
73 | (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n"; | ||
74 | return($lb{$_[0]}); | ||
75 | } | ||
76 | |||
77 | sub main'HB | ||
78 | { | ||
79 | (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n"; | ||
80 | return($hb{$_[0]}); | ||
81 | } | ||
82 | |||
83 | sub main'DWP | ||
84 | { | ||
85 | local($addr,$reg1,$reg2,$idx)=@_; | ||
86 | |||
87 | $ret=""; | ||
88 | $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/; | ||
89 | $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
90 | $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
91 | $ret.=$addr if ($addr ne "") && ($addr ne 0); | ||
92 | if ($reg2 ne "") | ||
93 | { $ret.="($reg1,$reg2,$idx)"; } | ||
94 | else | ||
95 | { $ret.="($reg1)" } | ||
96 | return($ret); | ||
97 | } | ||
98 | |||
99 | sub main'BP | ||
100 | { | ||
101 | return(&main'DWP(@_)); | ||
102 | } | ||
103 | |||
104 | #sub main'BP | ||
105 | # { | ||
106 | # local($addr,$reg1,$reg2,$idx)=@_; | ||
107 | # | ||
108 | # $ret=""; | ||
109 | # | ||
110 | # $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/; | ||
111 | # $reg1="$regs{$reg1}" if defined($regs{$reg1}); | ||
112 | # $reg2="$regs{$reg2}" if defined($regs{$reg2}); | ||
113 | # $ret.=$addr if ($addr ne "") && ($addr ne 0); | ||
114 | # if ($reg2 ne "") | ||
115 | # { $ret.="($reg1,$reg2,$idx)"; } | ||
116 | # else | ||
117 | # { $ret.="($reg1)" } | ||
118 | # return($ret); | ||
119 | # } | ||
120 | |||
121 | sub main'mov { &out2("movl",@_); } | ||
122 | sub main'movb { &out2("movb",@_); } | ||
123 | sub main'and { &out2("andl",@_); } | ||
124 | sub main'or { &out2("orl",@_); } | ||
125 | sub main'shl { &out2("sall",@_); } | ||
126 | sub main'shr { &out2("shrl",@_); } | ||
127 | sub main'xor { &out2("xorl",@_); } | ||
128 | sub main'xorb { &out2("xorb",@_); } | ||
129 | sub main'add { &out2("addl",@_); } | ||
130 | sub main'adc { &out2("adcl",@_); } | ||
131 | sub main'sub { &out2("subl",@_); } | ||
132 | sub main'rotl { &out2("roll",@_); } | ||
133 | sub main'rotr { &out2("rorl",@_); } | ||
134 | sub main'exch { &out2("xchg",@_); } | ||
135 | sub main'cmp { &out2("cmpl",@_); } | ||
136 | sub main'lea { &out2("leal",@_); } | ||
137 | sub main'mul { &out1("mull",@_); } | ||
138 | sub main'div { &out1("divl",@_); } | ||
139 | sub main'jmp { &out1("jmp",@_); } | ||
140 | sub main'jmp_ptr { &out1p("jmp",@_); } | ||
141 | sub main'je { &out1("je",@_); } | ||
142 | sub main'jle { &out1("jle",@_); } | ||
143 | sub main'jne { &out1("jne",@_); } | ||
144 | sub main'jnz { &out1("jnz",@_); } | ||
145 | sub main'jz { &out1("jz",@_); } | ||
146 | sub main'jge { &out1("jge",@_); } | ||
147 | sub main'jl { &out1("jl",@_); } | ||
148 | sub main'jb { &out1("jb",@_); } | ||
149 | sub main'jc { &out1("jc",@_); } | ||
150 | sub main'jnc { &out1("jnc",@_); } | ||
151 | sub main'jno { &out1("jno",@_); } | ||
152 | sub main'dec { &out1("decl",@_); } | ||
153 | sub main'inc { &out1("incl",@_); } | ||
154 | sub main'push { &out1("pushl",@_); $stack+=4; } | ||
155 | sub main'pop { &out1("popl",@_); $stack-=4; } | ||
156 | sub main'bswap { &out1("bswapl",@_); } | ||
157 | sub main'not { &out1("notl",@_); } | ||
158 | sub main'call { &out1("call",$under.$_[0]); } | ||
159 | sub main'ret { &out0("ret"); } | ||
160 | sub main'nop { &out0("nop"); } | ||
161 | |||
162 | sub out2 | ||
163 | { | ||
164 | local($name,$p1,$p2)=@_; | ||
165 | local($l,$ll,$t); | ||
166 | local(%special)=( "roll",0xD1C0,"rorl",0xD1C8, | ||
167 | "rcll",0xD1D0,"rcrl",0xD1D8, | ||
168 | "shll",0xD1E0,"shrl",0xD1E8, | ||
169 | "sarl",0xD1F8); | ||
170 | |||
171 | if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1)) | ||
172 | { | ||
173 | $op=$special{$name}|$reg_val{$p1}; | ||
174 | $tmp1=sprintf(".byte %d\n",($op>>8)&0xff); | ||
175 | $tmp2=sprintf(".byte %d\t",$op &0xff); | ||
176 | push(@out,$tmp1); | ||
177 | push(@out,$tmp2); | ||
178 | |||
179 | $p2=&conv($p2); | ||
180 | $p1=&conv($p1); | ||
181 | &main'comment("$name $p2 $p1"); | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | push(@out,"\t$name\t"); | ||
186 | $t=&conv($p2).","; | ||
187 | $l=length($t); | ||
188 | push(@out,$t); | ||
189 | $ll=4-($l+9)/8; | ||
190 | $tmp1=sprintf("\t" x $ll); | ||
191 | push(@out,$tmp1); | ||
192 | push(@out,&conv($p1)."\n"); | ||
193 | } | ||
194 | |||
195 | sub out1 | ||
196 | { | ||
197 | local($name,$p1)=@_; | ||
198 | local($l,$t); | ||
199 | local(%special)=("bswapl",0x0FC8); | ||
200 | |||
201 | if ((defined($special{$name})) && defined($regs{$p1})) | ||
202 | { | ||
203 | $op=$special{$name}|$reg_val{$p1}; | ||
204 | $tmp1=sprintf(".byte %d\n",($op>>8)&0xff); | ||
205 | $tmp2=sprintf(".byte %d\t",$op &0xff); | ||
206 | push(@out,$tmp1); | ||
207 | push(@out,$tmp2); | ||
208 | |||
209 | $p2=&conv($p2); | ||
210 | $p1=&conv($p1); | ||
211 | &main'comment("$name $p2 $p1"); | ||
212 | return; | ||
213 | } | ||
214 | |||
215 | push(@out,"\t$name\t".&conv($p1)."\n"); | ||
216 | } | ||
217 | |||
218 | sub out1p | ||
219 | { | ||
220 | local($name,$p1)=@_; | ||
221 | local($l,$t); | ||
222 | |||
223 | push(@out,"\t$name\t*".&conv($p1)."\n"); | ||
224 | } | ||
225 | |||
226 | sub out0 | ||
227 | { | ||
228 | push(@out,"\t$_[0]\n"); | ||
229 | } | ||
230 | |||
231 | sub conv | ||
232 | { | ||
233 | local($p)=@_; | ||
234 | |||
235 | # $p =~ s/0x([0-9A-Fa-f]+)/0$1h/; | ||
236 | |||
237 | $p=$regs{$p} if (defined($regs{$p})); | ||
238 | |||
239 | $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/; | ||
240 | $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/; | ||
241 | return $p; | ||
242 | } | ||
243 | |||
244 | sub main'file | ||
245 | { | ||
246 | local($file)=@_; | ||
247 | |||
248 | local($tmp)=<<"EOF"; | ||
249 | .file "$file.s" | ||
250 | .version "01.01" | ||
251 | gcc2_compiled.: | ||
252 | EOF | ||
253 | push(@out,$tmp); | ||
254 | } | ||
255 | |||
256 | sub main'function_begin | ||
257 | { | ||
258 | local($func)=@_; | ||
259 | |||
260 | &main'external_label($func); | ||
261 | $func=$under.$func; | ||
262 | |||
263 | local($tmp)=<<"EOF"; | ||
264 | .text | ||
265 | .align $align | ||
266 | .globl $func | ||
267 | EOF | ||
268 | push(@out,$tmp); | ||
269 | if ($main'cpp) | ||
270 | { $tmp=push(@out,"\tTYPE($func,\@function)\n"); } | ||
271 | else { $tmp=push(@out,"\t.type\t$func,\@function\n"); } | ||
272 | push(@out,"$func:\n"); | ||
273 | $tmp=<<"EOF"; | ||
274 | pushl %ebp | ||
275 | pushl %ebx | ||
276 | pushl %esi | ||
277 | pushl %edi | ||
278 | |||
279 | EOF | ||
280 | push(@out,$tmp); | ||
281 | $stack=20; | ||
282 | } | ||
283 | |||
284 | sub main'function_begin_B | ||
285 | { | ||
286 | local($func,$extra)=@_; | ||
287 | |||
288 | &main'external_label($func); | ||
289 | $func=$under.$func; | ||
290 | |||
291 | local($tmp)=<<"EOF"; | ||
292 | .text | ||
293 | .align $align | ||
294 | .globl $func | ||
295 | EOF | ||
296 | push(@out,$tmp); | ||
297 | if ($main'cpp) | ||
298 | { push(@out,"\tTYPE($func,\@function)\n"); } | ||
299 | else { push(@out,"\t.type $func,\@function\n"); } | ||
300 | push(@out,"$func:\n"); | ||
301 | $stack=4; | ||
302 | } | ||
303 | |||
304 | sub main'function_end | ||
305 | { | ||
306 | local($func)=@_; | ||
307 | |||
308 | $func=$under.$func; | ||
309 | |||
310 | local($tmp)=<<"EOF"; | ||
311 | popl %edi | ||
312 | popl %esi | ||
313 | popl %ebx | ||
314 | popl %ebp | ||
315 | ret | ||
316 | .${func}_end: | ||
317 | EOF | ||
318 | push(@out,$tmp); | ||
319 | if ($main'cpp) | ||
320 | { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } | ||
321 | else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } | ||
322 | push(@out,".ident \"$func\"\n"); | ||
323 | $stack=0; | ||
324 | %label=(); | ||
325 | } | ||
326 | |||
327 | sub main'function_end_A | ||
328 | { | ||
329 | local($func)=@_; | ||
330 | |||
331 | local($tmp)=<<"EOF"; | ||
332 | popl %edi | ||
333 | popl %esi | ||
334 | popl %ebx | ||
335 | popl %ebp | ||
336 | ret | ||
337 | EOF | ||
338 | push(@out,$tmp); | ||
339 | } | ||
340 | |||
341 | sub main'function_end_B | ||
342 | { | ||
343 | local($func)=@_; | ||
344 | |||
345 | $func=$under.$func; | ||
346 | |||
347 | push(@out,".${func}_end:\n"); | ||
348 | if ($main'cpp) | ||
349 | { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); } | ||
350 | else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); } | ||
351 | push(@out,".ident \"desasm.pl\"\n"); | ||
352 | $stack=0; | ||
353 | %label=(); | ||
354 | } | ||
355 | |||
356 | sub main'wparam | ||
357 | { | ||
358 | local($num)=@_; | ||
359 | |||
360 | return(&main'DWP($stack+$num*4,"esp","",0)); | ||
361 | } | ||
362 | |||
363 | sub main'stack_push | ||
364 | { | ||
365 | local($num)=@_; | ||
366 | $stack+=$num*4; | ||
367 | &main'sub("esp",$num*4); | ||
368 | } | ||
369 | |||
370 | sub main'stack_pop | ||
371 | { | ||
372 | local($num)=@_; | ||
373 | $stack-=$num*4; | ||
374 | &main'add("esp",$num*4); | ||
375 | } | ||
376 | |||
377 | sub main'swtmp | ||
378 | { | ||
379 | return(&main'DWP($_[0]*4,"esp","",0)); | ||
380 | } | ||
381 | |||
382 | # Should use swtmp, which is above esp. Linix can trash the stack above esp | ||
383 | #sub main'wtmp | ||
384 | # { | ||
385 | # local($num)=@_; | ||
386 | # | ||
387 | # return(&main'DWP(-($num+1)*4,"esp","",0)); | ||
388 | # } | ||
389 | |||
390 | sub main'comment | ||
391 | { | ||
392 | foreach (@_) | ||
393 | { | ||
394 | if (/^\s*$/) | ||
395 | { push(@out,"\n"); } | ||
396 | else | ||
397 | { push(@out,"\t$com_start $_ $com_end\n"); } | ||
398 | } | ||
399 | } | ||
400 | |||
401 | sub main'label | ||
402 | { | ||
403 | if (!defined($label{$_[0]})) | ||
404 | { | ||
405 | $label{$_[0]}=".${label}${_[0]}"; | ||
406 | $label++; | ||
407 | } | ||
408 | return($label{$_[0]}); | ||
409 | } | ||
410 | |||
411 | sub main'set_label | ||
412 | { | ||
413 | if (!defined($label{$_[0]})) | ||
414 | { | ||
415 | $label{$_[0]}=".${label}${_[0]}"; | ||
416 | $label++; | ||
417 | } | ||
418 | push(@out,".align $align\n") if ($_[1] != 0); | ||
419 | push(@out,"$label{$_[0]}:\n"); | ||
420 | } | ||
421 | |||
422 | sub main'file_end | ||
423 | { | ||
424 | } | ||
425 | |||
426 | sub main'data_word | ||
427 | { | ||
428 | push(@out,"\t.long $_[0]\n"); | ||
429 | } | ||