forked from Github_Repos/cvw
		
	Reverted back the exe2memfile.pl script changes. Something I changed broke the load tests.
This commit is contained in:
		
							parent
							
								
									31a0387136
								
							
						
					
					
						commit
						467a463c13
					
				@ -18,7 +18,7 @@ my $maxaddress = 0;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
STDOUT->autoflush(1);
 | 
					STDOUT->autoflush(1);
 | 
				
			||||||
# *** Ross Thompson I think there is a bug here needs to be +1
 | 
					# *** Ross Thompson I think there is a bug here needs to be +1
 | 
				
			||||||
print ("Processing $#ARGV memfiles: \n");
 | 
					print ("Processing $#ARGV memfiles: ");
 | 
				
			||||||
my $frac = $#ARGV/10;
 | 
					my $frac = $#ARGV/10;
 | 
				
			||||||
for(my $i=0; $i<=$#ARGV; $i++) {
 | 
					for(my $i=0; $i<=$#ARGV; $i++) {
 | 
				
			||||||
    if ($i < 10 || $i % $frac == 0) { print ("$i ") };
 | 
					    if ($i < 10 || $i % $frac == 0) { print ("$i ") };
 | 
				
			||||||
@ -40,114 +40,61 @@ for(my $i=0; $i<=$#ARGV; $i++) {
 | 
				
			|||||||
    if ($needsprocessing == 1) {
 | 
					    if ($needsprocessing == 1) {
 | 
				
			||||||
        open(FILE, $ofile) || die("Can't read $ofile");
 | 
					        open(FILE, $ofile) || die("Can't read $ofile");
 | 
				
			||||||
        my $mode = 0; # parse for code
 | 
					        my $mode = 0; # parse for code
 | 
				
			||||||
	my $section = "";
 | 
					 | 
				
			||||||
	my $data = "";
 | 
					 | 
				
			||||||
        my $address;
 | 
					        my $address;
 | 
				
			||||||
	my $first = 0;
 | 
					 | 
				
			||||||
	my $firstAddress;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # initialize to all zeros;
 | 
					    # initialize to all zeros;
 | 
				
			||||||
	# *** need to fix the zeroing range.  Not always 64K
 | 
					 | 
				
			||||||
        for (my $i=0; $i < 65536*4; $i++) {
 | 
					        for (my $i=0; $i < 65536*4; $i++) {
 | 
				
			||||||
            $memfilebytes[$i] = "00";
 | 
					            $memfilebytes[$i] = "00";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while(<FILE>) {
 | 
					        while(<FILE>) {
 | 
				
			||||||
	    # objdump fill is divided into several .sections of which only some we want to actually process.
 | 
					            if ($mode == 0) { # Parse code
 | 
				
			||||||
	    # In general we want everything except the .comment and .*attributes
 | 
					    #	    print("Examining $_\n");
 | 
				
			||||||
	    if (/Disassembly of section (.*):/) {
 | 
					            if (/^\s*(\S\S\S\S\S\S\S\S):\s+(\S+)\s+/) {
 | 
				
			||||||
		$section = $1;
 | 
					 | 
				
			||||||
		print ("setting section to $section\n");
 | 
					 | 
				
			||||||
	    } else {
 | 
					 | 
				
			||||||
		# now check if the section is one we are interested in processing.
 | 
					 | 
				
			||||||
		#if ($section ne ".comment" && $section ne ".riscv.attributes" && $section =~ /\.debug.*/) {
 | 
					 | 
				
			||||||
		if ($section =~ "\.init|\.text|\..*data|\..*bss") {
 | 
					 | 
				
			||||||
		    # the structure is: possible space(s) hex number: possible space(s) hex number space(s) junk
 | 
					 | 
				
			||||||
		    # there are also lines we need to skip: possible  space(s) hex number <string>:
 | 
					 | 
				
			||||||
		    if (/^\s*([0-9A-Fa-f]{1,16}):\s+([0-9A-Fa-f]+).*$/) {
 | 
					 | 
				
			||||||
                    $address = &fixadr($1);
 | 
					                    $address = &fixadr($1);
 | 
				
			||||||
			if ($first == 0) {
 | 
					                    my $instr = $2;
 | 
				
			||||||
			    $first = 1;
 | 
					                    my $len = length($instr);
 | 
				
			||||||
			    $firstAddress = $address;
 | 
					                    for (my $i=0; $i<$len/2; $i++) {
 | 
				
			||||||
 | 
					                        $memfilebytes[$address+$i] = substr($instr, $len-2-2*$i, 2);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
			$data = $2;
 | 
					 | 
				
			||||||
			&emitData($address, $data);
 | 
					 | 
				
			||||||
			# my $len = length($data);
 | 
					 | 
				
			||||||
			# for (my $i=0; $i<$len/2; $i++) {
 | 
					 | 
				
			||||||
			#     $memfilebytes[$address+$i] = substr($data, $len-2-2*$i, 2);
 | 
					 | 
				
			||||||
			# }
 | 
					 | 
				
			||||||
#			print ("Addr $address $data\n");
 | 
					 | 
				
			||||||
#		    } elsif (/^\s*\.\.\./) {
 | 
					 | 
				
			||||||
#			print ("Got ...\n");
 | 
					 | 
				
			||||||
#		    } else {
 | 
					 | 
				
			||||||
#			print ("No match\n");
 | 
					 | 
				
			||||||
		    }
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	    }
 | 
					 | 
				
			||||||
# 	    # *** this mode stuff does not work if a section is missing or reordered.
 | 
					 | 
				
			||||||
#             if ($mode == 0) { # Parse code
 | 
					 | 
				
			||||||
# #	    print("Examining $_\n");
 | 
					 | 
				
			||||||
# 		if (/^\s*(\S{1,16}):\s+(\S+)\s+/) {
 | 
					 | 
				
			||||||
#                     $address = &fixadr($1);
 | 
					 | 
				
			||||||
#                     my $instr = $2;
 | 
					 | 
				
			||||||
#                     my $len = length($instr);
 | 
					 | 
				
			||||||
#                     for (my $i=0; $i<$len/2; $i++) {
 | 
					 | 
				
			||||||
#                         $memfilebytes[$address+$i] = substr($instr, $len-2-2*$i, 2);
 | 
					 | 
				
			||||||
#                     }
 | 
					 | 
				
			||||||
    #                print ("address $address $instr\n");
 | 
					    #                print ("address $address $instr\n");
 | 
				
			||||||
# 		}
 | 
					            }
 | 
				
			||||||
# 		if (/Disassembly of section .data:/) { $mode = 1;}
 | 
					                if (/Disassembly of section .data:/) { $mode = 1;}
 | 
				
			||||||
#             } elsif ($mode == 1) { # Parse data segment
 | 
					            } elsif ($mode == 1) { # Parse data segment
 | 
				
			||||||
#                 if (/^\s*(\S{1,16}):\s+(.*)/) {
 | 
					                if (/^\s*(\S\S\S\S\S\S\S\S):\s+(.*)/) {
 | 
				
			||||||
#                     $address = &fixadr($1);
 | 
					                    $address = &fixadr($1);
 | 
				
			||||||
# #		        print "addresss $address maxaddress $maxaddress\n";
 | 
					    #		print "addresss $address maxaddress $maxaddress\n";
 | 
				
			||||||
# 		    if ($address > $maxaddress) { $maxaddress = $address; }
 | 
					            if ($address > $maxaddress) { $maxaddress = $address; }
 | 
				
			||||||
#                     my $line = $2;
 | 
					                    my $line = $2;
 | 
				
			||||||
#                     # merge chunks with spaces
 | 
					                    # merge chunks with spaces
 | 
				
			||||||
# 		    # *** might need to change
 | 
					                    $line =~ s/(\S)\s(\S)/$1$2/g;
 | 
				
			||||||
#                     $line =~ s/(\S)\s(\S)/$1$2/g;
 | 
					                    # strip off comments
 | 
				
			||||||
#                     # strip off comments
 | 
					                    $line =~ /^(\S*)/;
 | 
				
			||||||
#                     $line =~ /^(\S*)/;
 | 
					                    $payload = $1;
 | 
				
			||||||
#                     $payload = $1;
 | 
					                    &emitData($address, $payload);
 | 
				
			||||||
#                     &emitData($address, $payload);
 | 
					                }
 | 
				
			||||||
#                 }
 | 
					                if (/Disassembly of section .riscv.attributes:/) { $mode = 2; }
 | 
				
			||||||
#                 if (/Disassembly of section .comment:/) { $mode = 2; }
 | 
					            }
 | 
				
			||||||
# 	    } elsif ($mode == 2) { # parse the comment section
 | 
					 | 
				
			||||||
#                 if (/Disassembly of section .riscv.attributes:/) { $mode = 3; }
 | 
					 | 
				
			||||||
#             }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        close(FILE);
 | 
					        close(FILE);
 | 
				
			||||||
        $maxaddress = $address + 32; # pad some zeros at the end
 | 
					        $maxaddress += 32; # pad some zeros at the end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # print to memory file
 | 
					        # print to memory file
 | 
				
			||||||
	# *** this is a problem
 | 
					 | 
				
			||||||
        if ($fname =~ /rv32/) {
 | 
					        if ($fname =~ /rv32/) {
 | 
				
			||||||
        open(MEMFILE, ">$memfile") || die("Can't write $memfile");
 | 
					        open(MEMFILE, ">$memfile") || die("Can't write $memfile");
 | 
				
			||||||
        for (my $i=$firstAddress; $i<= $maxaddress; $i = $i + 4) {
 | 
					        for (my $i=0; $i<= $maxaddress; $i = $i + 4) {
 | 
				
			||||||
            for ($j=3; $j>=0; $j--) {
 | 
					            for ($j=3; $j>=0; $j--) {
 | 
				
			||||||
		no warnings 'uninitialized';
 | 
					 | 
				
			||||||
		my $value = $memfilebytes[$i+$j];
 | 
					 | 
				
			||||||
		if ($value eq ""){
 | 
					 | 
				
			||||||
		    print MEMFILE "00";
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
            print MEMFILE "$memfilebytes[$i+$j]";
 | 
					            print MEMFILE "$memfilebytes[$i+$j]";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            print MEMFILE "\n";
 | 
					            print MEMFILE "\n";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        close(MEMFILE);
 | 
					        close(MEMFILE);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
        open(MEMFILE, ">$memfile") || die("Can't write $memfile");
 | 
					        open(MEMFILE, ">$memfile") || die("Can't write $memfile");
 | 
				
			||||||
        for (my $i=$firstAddress; $i<= $maxaddress; $i = $i + 8) {
 | 
					        for (my $i=0; $i<= $maxaddress; $i = $i + 8) {
 | 
				
			||||||
            for ($j=7; $j>=0; $j--) {
 | 
					            for ($j=7; $j>=0; $j--) {
 | 
				
			||||||
		no warnings 'uninitialized';
 | 
					 | 
				
			||||||
		my $value = $memfilebytes[$i+$j];
 | 
					 | 
				
			||||||
		if ($value eq ""){
 | 
					 | 
				
			||||||
		    print MEMFILE "00";
 | 
					 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
            print MEMFILE "$memfilebytes[$i+$j]";
 | 
					            print MEMFILE "$memfilebytes[$i+$j]";
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            print MEMFILE "\n";
 | 
					            print MEMFILE "\n";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        close(MEMFILE);
 | 
					        close(MEMFILE);
 | 
				
			||||||
@ -186,15 +133,7 @@ sub emitData {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
sub fixadr {
 | 
					sub fixadr {
 | 
				
			||||||
    # strip off leading 8 from address and convert to decimal
 | 
					    # strip off leading 8 from address and convert to decimal
 | 
				
			||||||
    # if the leading 8 is not present don't remove.
 | 
					 | 
				
			||||||
    my $adr = shift;
 | 
					    my $adr = shift;
 | 
				
			||||||
    #print "addr $adr\n";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # start at 0
 | 
					 | 
				
			||||||
    #return hex($adr);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    # start at 8
 | 
					 | 
				
			||||||
    if ($adr =~ s/^8/0/) { return hex($adr); }
 | 
					    if ($adr =~ s/^8/0/) { return hex($adr); }
 | 
				
			||||||
    else { return hex($adr) }
 | 
					    else { die("address $adr lacks leading 8\n"); }
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user