On 2014-03-17 14:28:13 +0200, Martin Storsjö wrote:
> This does some rudimentary conversions of instructions that aren't
> available in thumb mode.
> 
> This allows building OpenH264 for Windows Phone 8 (and Windows RT),
> which only supports thumb mode, and the OpenH264 arm assembly is
> hardcoded for arm mode.
> 
> This is similar to how libvpx supports assembling in thumb mode - the
> source itself is arm mode only, but a perl script can replace
> instruction combinations that aren't supported in thumb mode. This
> is a small subset of those conversions.
> ---
>  gas-preprocessor.pl | 28 ++++++++++++++++++++++++++++
>  1 file changed, 28 insertions(+)
> 
> diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
> index eefe571..36cef69 100755
> --- a/gas-preprocessor.pl
> +++ b/gas-preprocessor.pl
> @@ -27,6 +27,7 @@ my $arch;
>  my $as_type = "apple-gas";
>  
>  my $fix_unreq = $^O eq "darwin";
> +my $force_thumb = 0;
>  
>  my $arm_cond_codes = "eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|hs|lo";
>  
> @@ -45,6 +46,9 @@ command. Following options are currently supported:
>      -as-type      - one value out of {{,apple-}{gas,clang},armasm}
>      -fix-unreq
>      -no-fix-unreq
> +    -force-thumb  - assemble as thumb regardless of the input source
> +                    (note, this is incomplete and only works for sources
> +                    it explicitly was tested with)
>  ";
>  
>  sub usage() {
> @@ -76,6 +80,8 @@ while (@options) {
>      my $opt = shift @options;
>      if ($opt =~ /^-(no-)?fix-unreq$/) {
>          $fix_unreq = $1 ne "no-";
> +    } elsif ($opt eq "-force-thumb") {
> +        $force_thumb = 1;
>      } elsif ($opt eq "-arch") {
>          $arch = shift @options;
>          die "unknown arch: '$arch'\n" if not exists $comments{$arch};
> @@ -215,6 +221,10 @@ my @ifstack;
>  
>  my %symbols;
>  
> +if ($force_thumb) {
> +    parse_line(".thumb\n");
> +}
> +
>  # pass 1: parse .macro
>  # note that the handling of arguments is probably overly permissive vs. gas
>  # but it should be the same for valid cases
> @@ -885,6 +895,24 @@ sub handle_serialized_line {
>          $line =~ s/&0x/& 0x/g;
>      }
>  
> +    if ($force_thumb) {
> +        # Convert register post indexing to a separate add instruction.
> +        # This converts e.g. "ldr r0, [r1], r2" into "ldr r0, [r1]",
> +        # "add r1, r1, r2".
> +        $line =~ s/(ldr|str)\s+(\w+),\s*\[(\w+)\],\s*(\w+)/$1 $2, 
> [$3]\n\tadd $3, $3, $4/g;

yes, that's much better. thanks

> +
> +        # Convert "mov pc, lr" into "bx lr", since the former only works
> +        # for switching from arm to thumb (and only in armv7), but not
> +        # from thumb to arm.
> +        s/mov\s*pc\s*,\s*lr/bx lr/g;
> +
> +        # Convert stmdb/ldmia with only one register into a plain str/ldr 
> with post-increment/decrement
> +        $line =~ s/stmdb\s+sp!\s*,\s*\{([^,-]+)\}/str $1, [sp, #-4]!/g;
> +        $line =~ s/ldmia\s+sp!\s*,\s*\{([^,-]+)\}/ldr $1, [sp], #4/g;
> +
> +        $line =~ s/\.arm/.thumb/x;
> +    }
> +
>      # comment out unsupported directives
>      $line =~ s/\.type/$comm$&/x        if $as_type =~ /^(apple-|armasm)/;
>      $line =~ s/\.func/$comm$&/x        if $as_type =~ /^(apple-|clang)/;

ok

Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to