dol: fix shm_t contain the shm-buffers
[jump.git] / hdf2arch / bsp2arch.pl
1 #!/usr/bin/perl -w
2 use strict;
3 use v5.010;
4
5 use XML::Simple qw(:strict);
6 use Data::Dumper;
7
8 # argument evaluation
9 my $infile  = shift;
10 my $outfile = shift;
11 if(!$infile || !$outfile) {
12         say "Usage: bsp2arch.pl <infile> <outfile>";
13         say "\tinfile:  Epiphany Platform Description";
14         say "\toutfile: DOL Architecture Specification";
15         say "\tUse \'-\' for standard input/output.";
16         exit 1;
17 }
18
19 # parse input xml file
20 my $input = XMLin($infile, ForceArray => '1', KeyAttr => ['chips']);
21
22 # output content
23 my @processors;
24 my @memories;
25 my @hw_channels;
26
27 # per-core definitions
28 foreach my $chips ($input->{'chips'}->[0]->{'chip'}) {
29         foreach my $chip (@$chips) {
30                 $chip->{'id'} =~ /\((\d+),(\d+)\)/;
31                 my @origin    = ($1, $2);
32                 my $version   = $chip->{'version'};
33
34                 foreach my $row (1..$chip->{'rows'}) {
35                         foreach my $col (1..$chip->{'cols'}) {
36                                 my $newrow  = $origin[0] + $row - 1;
37                                 my $newcol  = $origin[1] + $col - 1;
38                                 my $memsize = $chip->{'core_memory_size'};
39                                 $memsize = "0x8000" unless($memsize);
40
41                                 # eCore
42                                 push @processors, {
43                                         'name' => "core_${newrow}_${newcol}",
44                                         'type' => 'RISC',
45                                         'configuration' => [
46                                                 { 'name'  => 'version',
47                                                   'value' => $version },
48                                         ],
49                                 };
50
51                                 # eCore local memory
52                                 push @memories, {
53                                         'name' => "mem_${newrow}_${newcol}",
54                                         'type' => 'RAM',
55                                         'configuration' => [
56                                                 { 'name'  => 'size',
57                                                   'value' => $memsize },
58                                         ],
59                                 };
60
61                                 # eCore register file
62                                 push @memories, {
63                                         'name' => "regs_${newrow}_${newcol}",
64                                         'type' => 'REG',
65                                         'configuration' => [
66                                                 { 'name'  => 'size',
67                                                   'value' => '0x7FF' },
68                                         ],
69                                 }
70                         }
71                 }
72         }
73 }
74
75 # ARM host processor
76 push @processors, {
77         'name' => 'arm_0',
78         'type' => 'RISC',
79         'configuration' => [
80                 { 'name'  => 'cores',
81                   'value' => '2' },
82         ]
83 };
84
85 # external memory
86 foreach my $banks ($input->{'external_memory'}->[0]->{'bank'}) {
87         my $counter = 0;
88         foreach my $bank (@$banks) {
89                 # DOL doesn't need to know the epiphany-internal address
90                 next if($bank->{'name'} eq 'EPIPHANY_DRAM');
91
92                 if($bank->{'name'} eq 'EXTERNAL_DRAM') {
93                         push @memories, {
94                                 'name' => "emem_${counter}",
95                                 'type' => 'DXM',
96                                 'configuration' => [
97                                         { 'name'  => 'size',
98                                           'value' => $bank->{'size'} },
99                                         { 'name'  => 'start',
100                                           'value' => $bank->{'start'} }
101                                 ]
102                         };
103                         next;
104                         say "Warning: Unknown Extmem $bank->{'name'}!";
105                 }
106         }
107 }
108
109 # TODO: add hw_channels data
110
111 # generate XML output
112 my $output = {
113         'architecture' => {
114                 'xmlns' => "http://www.tik.ee.ethz.ch/~shapes/schema/ARCHITECTURE",
115                 'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
116                 'xsi:schemaLocation' => 'http://www.tik.ee.ethz.ch/~shapes/schema/ARCHITECTURE http://www.tik.ee.ethz.ch/~shapes/schema/architecture.xsd',
117                 'name' => 'Adapteva Parallella Architecture',
118
119                 'processor' => \@processors,
120                 'memory' => \@memories,
121                 'hw_channel' => \@hw_channels,
122         },
123 };
124 my $outxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n".
125                 XMLout($output, KeyAttr => [], KeepRoot => 1);
126
127 # save XML output
128 if($outfile eq '-') {
129         print $outxml;
130         exit 0;
131 } else {
132         open (FH, ">$outfile");
133         print FH $outxml;
134         close (FH);
135 }
136