OpenCores
URL https://opencores.org/ocsvn/or1k_soc_on_altera_embedded_dev_kit/or1k_soc_on_altera_embedded_dev_kit/trunk

Subversion Repositories or1k_soc_on_altera_embedded_dev_kit

[/] [or1k_soc_on_altera_embedded_dev_kit/] [trunk/] [soc/] [sw/] [utils/] [hex2mif.pl] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 xianfeng
#!/usr/bin/perl
2
# 2005 - David Grant.
3
# Take an ihex input from STDIN, and write a .mif file to STDOUT
4
# This script could probably be implemented with something like:
5
#    $#!@_%^$@%$@%$_!^$@#^@%$#@_%$@^&!%$_!%!%&$*(#^#@%^) 
6
# But I perfer the somewhat readable version.
7
 
8
# Flow from within the Nios2 SDK Shell:
9
# nios2-elf-as file.asm -o file.o
10
# nios2-elf-objcopy file.o --target ihex file.hex
11
# cat file.hex | perl hex2mif.pl > file.mif
12
 
13
sub conv {
14
        my ($in) = @_;
15
#       $out = substr($in,6,2).substr($in,4,2).substr($in,2,2).substr($in,0,2);
16
        $out = substr($in,0,2).substr($in,2,2).substr($in,4,2).substr($in,6,2);
17
        return hex $out;
18
}
19
 
20
my @code = ();
21
 
22
while (<STDIN>) {
23
        $l = $_;
24
        $count = (hex substr($l, 1, 2)) / 4;
25
        $addr = (hex substr($l, 3, 4)) / 4;
26
        $type = (hex substr($l, 7, 2));
27
        last if $type eq 1;
28
        for($x=0; $x<$count; $x++) {
29
                $code[$addr + $x] = conv(substr($l, 9+8*$x, 8)) ;
30
        }
31
}
32
 
33
print("WIDTH=32;\n");
34
print("DEPTH=".@code.";\n");
35
print("CONTENT BEGIN\n");
36
for($x=0; $x<@code; $x++) {
37
        printf("\t%08x : %08x;\n", $x, $code[$x]);
38
}
39
print("END;\n");
40
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.