diff options
| author | miod <> | 2023-02-01 20:45:04 +0000 |
|---|---|---|
| committer | miod <> | 2023-02-01 20:45:04 +0000 |
| commit | 5957c398bf683b5334ed18dd0f830b1cfffbf027 (patch) | |
| tree | 58219f5c6538172b9d00f33bf48c9a61419ec7a0 /src/lib/libcrypto/perlasm | |
| parent | 093a7a1758207b4e7e2b0d17ec6e5e7ec72e3a44 (diff) | |
| download | openbsd-5957c398bf683b5334ed18dd0f830b1cfffbf027.tar.gz openbsd-5957c398bf683b5334ed18dd0f830b1cfffbf027.tar.bz2 openbsd-5957c398bf683b5334ed18dd0f830b1cfffbf027.zip | |
Move all data blocks from .text to .rodata and cleanup up and homogeneize code
responsible from getting the proper address of those blocks.
ok tb@ jsing@
Diffstat (limited to 'src/lib/libcrypto/perlasm')
| -rw-r--r-- | src/lib/libcrypto/perlasm/cbc.pl | 82 | ||||
| -rw-r--r-- | src/lib/libcrypto/perlasm/x86gas.pl | 92 |
2 files changed, 102 insertions, 72 deletions
diff --git a/src/lib/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl index 24561e759a..392f23e145 100644 --- a/src/lib/libcrypto/perlasm/cbc.pl +++ b/src/lib/libcrypto/perlasm/cbc.pl | |||
| @@ -34,6 +34,15 @@ sub cbc | |||
| 34 | # p1,p2,p3 are the offsets for parameters to be passed to the | 34 | # p1,p2,p3 are the offsets for parameters to be passed to the |
| 35 | # underlying calls. | 35 | # underlying calls. |
| 36 | 36 | ||
| 37 | &static_label("cbc_enc_jmp_table_".$name); | ||
| 38 | &static_label("ej1_".$name); | ||
| 39 | &static_label("ej2_".$name); | ||
| 40 | &static_label("ej3_".$name); | ||
| 41 | &static_label("ej4_".$name); | ||
| 42 | &static_label("ej5_".$name); | ||
| 43 | &static_label("ej6_".$name); | ||
| 44 | &static_label("ej7_".$name); | ||
| 45 | |||
| 37 | &function_begin_B($name,""); | 46 | &function_begin_B($name,""); |
| 38 | &comment(""); | 47 | &comment(""); |
| 39 | 48 | ||
| @@ -146,33 +155,32 @@ sub cbc | |||
| 146 | &mov($count, &wparam(2)); # length | 155 | &mov($count, &wparam(2)); # length |
| 147 | &and($count, 7); | 156 | &and($count, 7); |
| 148 | &jz(&label("finish")); | 157 | &jz(&label("finish")); |
| 149 | &call(&label("PIC_point")); | 158 | |
| 150 | &set_label("PIC_point"); | 159 | &picsetup("edx"); |
| 151 | &blindpop("edx"); | 160 | &picsymbol("ecx", &label("cbc_enc_jmp_table_".$name), "edx") |
| 152 | &lea("ecx",&DWP(&label("cbc_enc_jmp_table")."-".&label("PIC_point"),"edx")); | ||
| 153 | &mov($count,&DWP(0,"ecx",$count,4)); | 161 | &mov($count,&DWP(0,"ecx",$count,4)); |
| 154 | &add($count,"edx"); | 162 | &picadjust($count, "edx"); |
| 163 | |||
| 155 | &xor("ecx","ecx"); | 164 | &xor("ecx","ecx"); |
| 156 | &xor("edx","edx"); | 165 | &xor("edx","edx"); |
| 157 | #&mov($count,&DWP(&label("cbc_enc_jmp_table"),"",$count,4)); | ||
| 158 | &jmp_ptr($count); | 166 | &jmp_ptr($count); |
| 159 | 167 | ||
| 160 | &set_label("ej7"); | 168 | &set_label("ej7_".$name); |
| 161 | &movb(&HB("edx"), &BP(6,$in,"",0)); | 169 | &movb(&HB("edx"), &BP(6,$in,"",0)); |
| 162 | &shl("edx",8); | 170 | &shl("edx",8); |
| 163 | &set_label("ej6"); | 171 | &set_label("ej6_".$name); |
| 164 | &movb(&HB("edx"), &BP(5,$in,"",0)); | 172 | &movb(&HB("edx"), &BP(5,$in,"",0)); |
| 165 | &set_label("ej5"); | 173 | &set_label("ej5_".$name); |
| 166 | &movb(&LB("edx"), &BP(4,$in,"",0)); | 174 | &movb(&LB("edx"), &BP(4,$in,"",0)); |
| 167 | &set_label("ej4"); | 175 | &set_label("ej4_".$name); |
| 168 | &mov("ecx", &DWP(0,$in,"",0)); | 176 | &mov("ecx", &DWP(0,$in,"",0)); |
| 169 | &jmp(&label("ejend")); | 177 | &jmp(&label("ejend")); |
| 170 | &set_label("ej3"); | 178 | &set_label("ej3_".$name); |
| 171 | &movb(&HB("ecx"), &BP(2,$in,"",0)); | 179 | &movb(&HB("ecx"), &BP(2,$in,"",0)); |
| 172 | &shl("ecx",8); | 180 | &shl("ecx",8); |
| 173 | &set_label("ej2"); | 181 | &set_label("ej2_".$name); |
| 174 | &movb(&HB("ecx"), &BP(1,$in,"",0)); | 182 | &movb(&HB("ecx"), &BP(1,$in,"",0)); |
| 175 | &set_label("ej1"); | 183 | &set_label("ej1_".$name); |
| 176 | &movb(&LB("ecx"), &BP(0,$in,"",0)); | 184 | &movb(&LB("ecx"), &BP(0,$in,"",0)); |
| 177 | &set_label("ejend"); | 185 | &set_label("ejend"); |
| 178 | 186 | ||
| @@ -279,30 +287,14 @@ sub cbc | |||
| 279 | &mov("eax", &DWP(0,$in,"",0)); # get old cipher text, | 287 | &mov("eax", &DWP(0,$in,"",0)); # get old cipher text, |
| 280 | &mov("ebx", &DWP(4,$in,"",0)); # next iv actually | 288 | &mov("ebx", &DWP(4,$in,"",0)); # next iv actually |
| 281 | 289 | ||
| 282 | &set_label("dj7"); | ||
| 283 | &rotr("edx", 16); | 290 | &rotr("edx", 16); |
| 284 | &movb(&BP(6,$out,"",0), &LB("edx")); | 291 | &movb(&BP(6,$out,"",0), &LB("edx")); |
| 285 | &shr("edx",16); | 292 | &shr("edx",16); |
| 286 | &set_label("dj6"); | ||
| 287 | &movb(&BP(5,$out,"",0), &HB("edx")); | 293 | &movb(&BP(5,$out,"",0), &HB("edx")); |
| 288 | &set_label("dj5"); | ||
| 289 | &movb(&BP(4,$out,"",0), &LB("edx")); | 294 | &movb(&BP(4,$out,"",0), &LB("edx")); |
| 290 | &set_label("dj4"); | ||
| 291 | &mov(&DWP(0,$out,"",0), "ecx"); | 295 | &mov(&DWP(0,$out,"",0), "ecx"); |
| 292 | &jmp(&label("djend")); | ||
| 293 | &set_label("dj3"); | ||
| 294 | &rotr("ecx", 16); | ||
| 295 | &movb(&BP(2,$out,"",0), &LB("ecx")); | ||
| 296 | &shl("ecx",16); | ||
| 297 | &set_label("dj2"); | ||
| 298 | &movb(&BP(1,$in,"",0), &HB("ecx")); | ||
| 299 | &set_label("dj1"); | ||
| 300 | &movb(&BP(0,$in,"",0), &LB("ecx")); | ||
| 301 | &set_label("djend"); | ||
| 302 | 296 | ||
| 303 | # final iv is still in eax:ebx | 297 | # final iv is still in eax:ebx |
| 304 | &jmp(&label("finish")); | ||
| 305 | |||
| 306 | 298 | ||
| 307 | ############################ FINISH #######################3 | 299 | ############################ FINISH #######################3 |
| 308 | &set_label("finish",1); | 300 | &set_label("finish",1); |
| @@ -319,31 +311,21 @@ sub cbc | |||
| 319 | &mov(&DWP(4,"ecx","",0), "ebx"); # save iv | 311 | &mov(&DWP(4,"ecx","",0), "ebx"); # save iv |
| 320 | 312 | ||
| 321 | &function_end_A($name); | 313 | &function_end_A($name); |
| 314 | &function_end_B($name); | ||
| 322 | 315 | ||
| 316 | &rodataseg(); | ||
| 323 | &align(64); | 317 | &align(64); |
| 324 | &set_label("cbc_enc_jmp_table"); | 318 | &set_label("cbc_enc_jmp_table_".$name); |
| 325 | &data_word("0"); | 319 | &data_word("0"); |
| 326 | &data_word(&label("ej1")."-".&label("PIC_point")); | 320 | &data_word(&code_sym(&label("ej1_".$name))); |
| 327 | &data_word(&label("ej2")."-".&label("PIC_point")); | 321 | &data_word(&code_sym(&label("ej2_".$name))); |
| 328 | &data_word(&label("ej3")."-".&label("PIC_point")); | 322 | &data_word(&code_sym(&label("ej3_".$name))); |
| 329 | &data_word(&label("ej4")."-".&label("PIC_point")); | 323 | &data_word(&code_sym(&label("ej4_".$name))); |
| 330 | &data_word(&label("ej5")."-".&label("PIC_point")); | 324 | &data_word(&code_sym(&label("ej5_".$name))); |
| 331 | &data_word(&label("ej6")."-".&label("PIC_point")); | 325 | &data_word(&code_sym(&label("ej6_".$name))); |
| 332 | &data_word(&label("ej7")."-".&label("PIC_point")); | 326 | &data_word(&code_sym(&label("ej7_".$name))); |
| 333 | # not used | 327 | &previous(); |
| 334 | #&set_label("cbc_dec_jmp_table",1); | ||
| 335 | #&data_word("0"); | ||
| 336 | #&data_word(&label("dj1")."-".&label("PIC_point")); | ||
| 337 | #&data_word(&label("dj2")."-".&label("PIC_point")); | ||
| 338 | #&data_word(&label("dj3")."-".&label("PIC_point")); | ||
| 339 | #&data_word(&label("dj4")."-".&label("PIC_point")); | ||
| 340 | #&data_word(&label("dj5")."-".&label("PIC_point")); | ||
| 341 | #&data_word(&label("dj6")."-".&label("PIC_point")); | ||
| 342 | #&data_word(&label("dj7")."-".&label("PIC_point")); | ||
| 343 | &align(64); | ||
| 344 | 328 | ||
| 345 | &function_end_B($name); | ||
| 346 | |||
| 347 | } | 329 | } |
| 348 | 330 | ||
| 349 | 1; | 331 | 1; |
diff --git a/src/lib/libcrypto/perlasm/x86gas.pl b/src/lib/libcrypto/perlasm/x86gas.pl index ca644ba553..f28a590549 100644 --- a/src/lib/libcrypto/perlasm/x86gas.pl +++ b/src/lib/libcrypto/perlasm/x86gas.pl | |||
| @@ -177,34 +177,52 @@ sub ::align | |||
| 177 | push(@out,".align\t$val\n"); | 177 | push(@out,".align\t$val\n"); |
| 178 | } | 178 | } |
| 179 | 179 | ||
| 180 | sub ::picmeup | 180 | # |
| 181 | { my($dst,$sym,$base,$reflabel)=@_; | 181 | # PIC data access wrappers |
| 182 | 182 | # | |
| 183 | if ($::openbsd) | 183 | # Usage: |
| 184 | { &::emitraw("#if defined(PIC) || defined(__PIC__)"); | 184 | # picsetup($base) |
| 185 | &::emitraw("PIC_PROLOGUE"); | 185 | # - only allowed once per function (because of hardcoded label name), |
| 186 | &::mov($dst, &::DWP("PIC_GOT($sym)")); | 186 | # sets up pic access, uses $base register as temporary |
| 187 | &::emitraw("PIC_EPILOGUE"); | 187 | # picsymbol($dst, $sym, $base) |
| 188 | &::emitraw("#else /* PIC */"); | 188 | # - loads the address of symbol $sym into $dst with the help of $base |
| 189 | &::lea($dst,&::DWP($sym)); | 189 | # initialized by picsetup |
| 190 | &::emitraw("#endif /* PIC */"); | 190 | # picadjust($sym, $base) |
| 191 | } | 191 | # - adjusts a code pointer read from a code_sym table with the help of |
| 192 | elsif (($::pic && ($::elf || $::aout)) || $::macosx) | 192 | # $base initialized by picsetup |
| 193 | { if (!defined($base)) | 193 | # code_sym($sym) |
| 194 | { &::call(&::label("PIC_me_up")); | 194 | # - emits a pointer to the given code symbol, relative to the GOT if |
| 195 | &::set_label("PIC_me_up"); | 195 | # PIC. This pointer will need to be adjusted with picadjust above |
| 196 | &::blindpop($dst); | 196 | # before use. |
| 197 | $base=$dst; | 197 | |
| 198 | $reflabel=&::label("PIC_me_up"); | 198 | sub ::picsetup |
| 199 | } | 199 | { my($base)=@_; |
| 200 | |||
| 201 | if (($::pic && ($::openbsd || $::elf || $::aout)) || $::macosx) | ||
| 202 | { | ||
| 203 | &::call(&::label("PIC_setup")); | ||
| 204 | &::set_label("PIC_setup"); | ||
| 205 | &::blindpop($base); | ||
| 200 | if ($::macosx) | 206 | if ($::macosx) |
| 201 | { my $indirect=&::static_label("$nmdecor$sym\$non_lazy_ptr"); | 207 | { my $indirect=&::static_label("$nmdecor$sym\$non_lazy_ptr"); |
| 202 | &::mov($dst,&::DWP("$indirect-$reflabel",$base)); | ||
| 203 | $non_lazy_ptr{"$nmdecor$sym"}=$indirect; | 208 | $non_lazy_ptr{"$nmdecor$sym"}=$indirect; |
| 204 | } | 209 | } |
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 213 | sub ::picsymbol | ||
| 214 | { my($dst,$sym,$base)=@_; | ||
| 215 | |||
| 216 | if (($::pic && ($::openbsd || $::elf || $::aout)) || $::macosx) | ||
| 217 | { | ||
| 218 | my $reflabel=&::label("PIC_setup"); | ||
| 219 | if ($::macosx) | ||
| 220 | { my $indirect=$non_lazy_ptr{"$nmdecor$sym"}; | ||
| 221 | &::mov($dst,&::DWP("$indirect-$reflabel",$base)); | ||
| 222 | } | ||
| 205 | else | 223 | else |
| 206 | { &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]", | 224 | { &::lea($dst,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]", |
| 207 | $base)); | 225 | $base)); |
| 208 | &::mov($dst,&::DWP("$sym\@GOT",$dst)); | 226 | &::mov($dst,&::DWP("$sym\@GOT",$dst)); |
| 209 | } | 227 | } |
| 210 | } | 228 | } |
| @@ -212,6 +230,30 @@ sub ::picmeup | |||
| 212 | { &::lea($dst,&::DWP($sym)); } | 230 | { &::lea($dst,&::DWP($sym)); } |
| 213 | } | 231 | } |
| 214 | 232 | ||
| 233 | sub ::picadjust | ||
| 234 | { my($sym,$base)=@_; | ||
| 235 | |||
| 236 | if (($::pic && ($::openbsd || $::elf || $::aout)) || $::macosx) | ||
| 237 | { | ||
| 238 | my $reflabel=&::label("PIC_setup"); | ||
| 239 | &::lea($sym,&::DWP("_GLOBAL_OFFSET_TABLE_+[.-$reflabel]", | ||
| 240 | $base,$sym)); | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | sub ::code_sym | ||
| 245 | { my($sym)=@_; | ||
| 246 | |||
| 247 | if (($::pic && ($::openbsd || $::elf || $::aout)) || $::macosx) | ||
| 248 | { | ||
| 249 | $sym."\@GOTOFF"; | ||
| 250 | } | ||
| 251 | else | ||
| 252 | { | ||
| 253 | $sym; | ||
| 254 | } | ||
| 255 | } | ||
| 256 | |||
| 215 | sub ::initseg | 257 | sub ::initseg |
| 216 | { my $f=$nmdecor.shift; | 258 | { my $f=$nmdecor.shift; |
| 217 | 259 | ||
| @@ -264,4 +306,10 @@ ___ | |||
| 264 | sub ::dataseg | 306 | sub ::dataseg |
| 265 | { push(@out,".data\n"); } | 307 | { push(@out,".data\n"); } |
| 266 | 308 | ||
| 309 | sub ::rodataseg | ||
| 310 | { push(@out,".rodata\n"); } | ||
| 311 | |||
| 312 | sub ::previous | ||
| 313 | { push(@out,".previous\n"); } | ||
| 314 | |||
| 267 | 1; | 315 | 1; |
