|
1 # |
|
2 # Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of the License "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # changes the paging/unpaged configuration of binaries a generated |
|
16 # OBY file according to the list in configpaging.lst |
|
17 # use |
|
18 # externaltool=configpaging.pm |
|
19 # in oby file to enable |
|
20 # use |
|
21 # tool=configpaging \epoc32\rom\myconfigpaging.lst |
|
22 # to change the default configpaging.lst |
|
23 # |
|
24 |
|
25 package configpaging; |
|
26 |
|
27 use strict; |
|
28 |
|
29 our @EXPORT=qw( |
|
30 configpaging_info |
|
31 configpaging_initialize |
|
32 configpaging_single |
|
33 configpaging_multiple |
|
34 ); |
|
35 use Exporter; |
|
36 our @ISA=qw(Exporter); |
|
37 |
|
38 # |
|
39 # Initialisation |
|
40 # |
|
41 use constant CONSTANT_UNPAGED => "unpaged"; |
|
42 use constant CONSTANT_PAGED => "paged"; |
|
43 use constant CONSTANT_UNPAGEDCODE => "unpagedcode"; |
|
44 use constant CONSTANT_PAGEDCODE => "pagedcode"; |
|
45 use constant CONSTANT_UNPAGEDDATA => "unpageddata"; |
|
46 use constant CONSTANT_PAGEDDATA => "pageddata"; |
|
47 use constant CONSTANT_CONFIG_PATH => "epoc32\\rom\\configpaging\\"; |
|
48 my $epocroot = $ENV{EPOCROOT}; |
|
49 my $configlist = $epocroot.CONSTANT_CONFIG_PATH."configpaging.cfg"; |
|
50 |
|
51 |
|
52 # routine to provide information about the tool |
|
53 sub configpaging_info () |
|
54 { |
|
55 my %toolinfo; |
|
56 $toolinfo{'name'} = "configpaging"; |
|
57 $toolinfo{'invocation'} = "InvocationPoint2"; |
|
58 $toolinfo{'initialize'} = \&configpaging_initialize; |
|
59 $toolinfo{'multiple'} = \&configpaging_multiple; |
|
60 $toolinfo{'single'} = \&configpaging_single; |
|
61 return \%toolinfo; |
|
62 } |
|
63 |
|
64 sub configpaging_initialize |
|
65 { |
|
66 my ($cmdLine) = @_; |
|
67 if (defined ($cmdLine)) |
|
68 { |
|
69 print "configpaging.pm: Initializing with $cmdLine\n"; |
|
70 $configlist = $epocroot.CONSTANT_CONFIG_PATH.$cmdLine; |
|
71 } |
|
72 } |
|
73 |
|
74 # routine to handle multiple invocation |
|
75 sub configpaging_multiple |
|
76 { |
|
77 my ($line) = @_; |
|
78 my @args=split /[=\s]/, $line; |
|
79 $configlist=$args[2]; |
|
80 return "REM configpaging.pm: Using $configlist"; |
|
81 } |
|
82 |
|
83 |
|
84 sub isobystatement |
|
85 { |
|
86 my ($li) = @_; |
|
87 if ($li =~ /^\s*data(=|\s+)/i) { return 1;} |
|
88 if ($li =~ /^\s*file(=|\s+)/i) { return 1;} |
|
89 if ($li =~ /^\s*dll(=|\s+)/i) { return 1;} |
|
90 if ($li =~ /^\s*secondary(=|\s+)/i) { return 1;} |
|
91 |
|
92 return 0; |
|
93 } |
|
94 |
|
95 #codepaging is codepagingoverride setting |
|
96 #datapaging is datapagingoverride setting |
|
97 #listref is ref to an associated array keyed by <executable regex>, |
|
98 #and the value is another associated array keyed (un)?paged(code|data)? |
|
99 #the value is 1 if set, undeffed if not. |
|
100 sub readConfigFile |
|
101 { |
|
102 my ($codepagingref, $datapagingref, $listref, $configfilename) = @_; |
|
103 my $filecodepaging = ""; |
|
104 my $filedatapaging = ""; |
|
105 |
|
106 local *FILE; # need a filehandle local to this invocation |
|
107 if(!open FILE, $configfilename) |
|
108 { |
|
109 print ("Configpaging Warning: Can't open $configfilename\n"); |
|
110 return; |
|
111 } |
|
112 |
|
113 # parse the configfilename |
|
114 # insert the files listed into the listref and set the paging info accordingly. |
|
115 while (my $line=<FILE>) |
|
116 { |
|
117 if ($line !~ /\S/ ) { next; } |
|
118 if ($line =~ /^\s*#/ ) { next; } |
|
119 chomp $line; |
|
120 if ($line =~ /^\s*(code|data)?pagingoverride=(.*)\s*/i) { |
|
121 if ($1 eq undef) { |
|
122 if (lc($2) eq "defaultpaged") { |
|
123 $$codepagingref = CONSTANT_PAGED; |
|
124 $$datapagingref = CONSTANT_PAGED; |
|
125 } elsif (lc($2) eq "defaultunpaged") { |
|
126 $$codepagingref = CONSTANT_UNPAGED; |
|
127 $$datapagingref = CONSTANT_UNPAGED; |
|
128 } else { |
|
129 print ("Configpaging Warning: invalid pagingoverride setting:$2\n"); |
|
130 } |
|
131 } elsif (lc($1) eq "code") { |
|
132 if (lc($2) eq "defaultpaged") { |
|
133 $$codepagingref = CONSTANT_PAGED; |
|
134 } elsif (lc($2) eq "defaultunpaged") { |
|
135 $$codepagingref = CONSTANT_UNPAGED; |
|
136 } else { |
|
137 print ("Configpaging Warning: invalid codepagingoverride setting:$2\n"); |
|
138 } |
|
139 } elsif ($1 eq "data") { |
|
140 if (lc($2) eq "defaultpaged") { |
|
141 $$datapagingref = CONSTANT_PAGED; |
|
142 } elsif (lc($2) eq "defaultunpaged") { |
|
143 $$datapagingref = CONSTANT_UNPAGED; |
|
144 } else { |
|
145 print ("Configpaging Warning: invalid datapagingoverride setting:$2\n"); |
|
146 } |
|
147 } else { |
|
148 print ("configpaging Warning: invalid keyword: $1" . "pagingoverride\n"); |
|
149 } |
|
150 } |
|
151 elsif ($line =~ /^\s*(un)?paged(code|data)?(\s+(un)?paged(code|data)?)?:/i ) { |
|
152 $filecodepaging = ""; |
|
153 $filedatapaging = ""; |
|
154 if ($1 eq undef) { |
|
155 if ($2 eq undef) { |
|
156 $filecodepaging = CONSTANT_PAGED; |
|
157 $filedatapaging = CONSTANT_PAGED; |
|
158 }elsif (lc($2) eq "code") { |
|
159 $filecodepaging = CONSTANT_PAGED; |
|
160 } elsif(lc($2) eq "data") { |
|
161 $filedatapaging = CONSTANT_PAGED; |
|
162 } else { |
|
163 print ("Configpaging Warning: unrecognized line:$line\n"); |
|
164 } |
|
165 } elsif (lc($1) eq "un") { |
|
166 if ($2 eq undef) { |
|
167 $filecodepaging = CONSTANT_UNPAGED; |
|
168 $filedatapaging = CONSTANT_UNPAGED; |
|
169 }elsif (lc($2) eq "code") { |
|
170 $filecodepaging = CONSTANT_UNPAGED; |
|
171 } elsif(lc($2) eq "data") { |
|
172 $filedatapaging = CONSTANT_UNPAGED; |
|
173 } else { |
|
174 print ("Configpaging Warning: unrecognized line:$line\n"); |
|
175 } |
|
176 } else { |
|
177 print ("Configpaging Warning: unrecognized line:$line\n"); |
|
178 } |
|
179 if ($3 ne undef){ |
|
180 if ($4 eq undef) { |
|
181 if ($5 eq undef) { |
|
182 $filecodepaging = CONSTANT_PAGED; |
|
183 $filedatapaging = CONSTANT_PAGED; |
|
184 }elsif (lc($5) eq "code") { |
|
185 $filecodepaging = CONSTANT_PAGED; |
|
186 } elsif(lc($5) eq "data") { |
|
187 $filedatapaging = CONSTANT_PAGED; |
|
188 } else { |
|
189 print ("Configpaging Warning: unrecognized line:$line\n"); |
|
190 } |
|
191 } elsif (lc($4) eq "un") { |
|
192 if ($5 eq undef) { |
|
193 $filecodepaging = CONSTANT_UNPAGED; |
|
194 $filedatapaging = CONSTANT_UNPAGED; |
|
195 }elsif (lc($5) eq "code") { |
|
196 $filecodepaging = CONSTANT_UNPAGED; |
|
197 } elsif(lc($5) eq "data") { |
|
198 $filedatapaging = CONSTANT_UNPAGED; |
|
199 } else { |
|
200 print ("Configpaging Warning: unrecognized line:$line\n"); |
|
201 } |
|
202 } else { |
|
203 print ("Configpaging Warning: unrecognized line:$line\n"); |
|
204 } |
|
205 } |
|
206 } |
|
207 elsif ($line =~ /^\s*include\s*\"(.*)\"/i) |
|
208 { readConfigFile($codepagingref, $datapagingref, $listref, $epocroot.CONSTANT_CONFIG_PATH.$1); } # go recursive |
|
209 elsif ($line =~ /\s*(\S+)(\s+(un)?paged(code|data)?(\s+(un)?paged(code|data)?)?)?/i){ |
|
210 my %element; |
|
211 $element{code} = $$codepagingref; |
|
212 $element{data} = $$datapagingref; |
|
213 if ($2 eq undef){ |
|
214 if ($filecodepaging ne "") { |
|
215 $element{code} = $filecodepaging; |
|
216 } |
|
217 if ($filedatapaging ne "") { |
|
218 $element{data} = $filedatapaging; |
|
219 } |
|
220 } else { |
|
221 if ($4 eq undef){ |
|
222 if ($3 eq undef) { |
|
223 $element{code} = CONSTANT_PAGED; |
|
224 $element{data} = CONSTANT_PAGED; |
|
225 } elsif (lc($3) eq "un") { |
|
226 $element{code} = CONSTANT_UNPAGED; |
|
227 $element{data} = CONSTANT_UNPAGED; |
|
228 } |
|
229 } elsif (lc($4) eq "code") { |
|
230 if ($3 eq undef) { |
|
231 $element{code} = CONSTANT_PAGED; |
|
232 } elsif (lc($3) eq "un") { |
|
233 $element{code} = CONSTANT_UNPAGED; |
|
234 } |
|
235 } elsif (lc($4) eq "data") { |
|
236 if ($3 eq undef) { |
|
237 $element{data} = CONSTANT_PAGED; |
|
238 } elsif (lc($3) eq "un") { |
|
239 $element{data} = CONSTANT_UNPAGED; |
|
240 } |
|
241 } else { |
|
242 print ("Configpaging Warning: unrecognized attribute in line: $line\n"); |
|
243 } |
|
244 if ($5 ne undef){ |
|
245 if ($7 eq undef){ |
|
246 if ($6 eq undef) { |
|
247 $element{code} = CONSTANT_PAGED; |
|
248 $element{data} = CONSTANT_PAGED; |
|
249 } elsif (lc($6) eq "un") { |
|
250 $element{code} = CONSTANT_UNPAGED; |
|
251 $element{data} = CONSTANT_UNPAGED; |
|
252 } |
|
253 } elsif (lc($7) eq "code") { |
|
254 if ($6 eq undef) { |
|
255 $element{code} = CONSTANT_PAGED; |
|
256 } elsif (lc($6) eq "un") { |
|
257 $element{code} = CONSTANT_UNPAGED; |
|
258 } |
|
259 } elsif (lc($7) eq "data") { |
|
260 if ($6 eq undef) { |
|
261 $element{data} = CONSTANT_PAGED; |
|
262 } elsif (lc($6) eq "un") { |
|
263 $element{data} = CONSTANT_UNPAGED; |
|
264 } |
|
265 } else { |
|
266 print ("Configpaging Warning: unrecognized attribute in line: $line\n"); |
|
267 } |
|
268 } |
|
269 } |
|
270 $$listref{$1} = \%element; |
|
271 } else { |
|
272 print ("ConfigPaging Warning: unrecognized line:$line\n"); |
|
273 } |
|
274 } |
|
275 close FILE; |
|
276 } |
|
277 |
|
278 # routine to handle single invocation |
|
279 sub configpaging_single |
|
280 { |
|
281 my $codepaging=""; |
|
282 my $datapaging=""; |
|
283 my %list; |
|
284 my @keys; |
|
285 my ($oby) = @_; |
|
286 |
|
287 print "configpaging.pm: Modifying demand paging configuration using $configlist\n"; |
|
288 readConfigFile(\$codepaging, \$datapaging, \%list, $configlist); |
|
289 # read the oby file that was handed to us |
|
290 # find matches between each oby line and any files in the paged or unpaged list |
|
291 # modify the attributes of the oby line as appropriate |
|
292 my @newlines; |
|
293 my %element; |
|
294 @keys = keys %list; |
|
295 foreach my $line (@$oby) |
|
296 { |
|
297 my $codepagingadd=""; |
|
298 my $datapagingadd=""; |
|
299 chomp $line; |
|
300 if (isobystatement($line)) |
|
301 { |
|
302 my $lcline = lc($line); |
|
303 for(my $index=@keys - 1; $index>=0; $index--) { |
|
304 my $match = $keys[$index]; |
|
305 if ($lcline =~ /(\s+|\"|\\|=)$match(\s+|\"|$)/) { |
|
306 %element = %{$list{$match}}; |
|
307 if ($element{code} eq CONSTANT_PAGED) { |
|
308 $codepagingadd .= " " . CONSTANT_PAGEDCODE; |
|
309 } elsif ($element{code} eq CONSTANT_UNPAGED) { |
|
310 $codepagingadd .= " " . CONSTANT_UNPAGEDCODE; |
|
311 } |
|
312 if ($element{data} eq CONSTANT_PAGED) { |
|
313 $datapagingadd .= " " . CONSTANT_PAGEDDATA; |
|
314 } elsif ($element{data} eq CONSTANT_UNPAGED) { |
|
315 $datapagingadd .= " " . CONSTANT_UNPAGEDDATA; |
|
316 } |
|
317 last; |
|
318 } |
|
319 } |
|
320 if (!$codepagingadd and $codepaging) { |
|
321 $codepagingadd = " " . $codepaging . "code"; |
|
322 } |
|
323 if (!$datapagingadd and $datapaging) { |
|
324 $datapagingadd = " " . $datapaging . "data"; |
|
325 } |
|
326 if ($codepagingadd and !$datapagingadd){ |
|
327 if ($line =~ /\b(un)?paged(data)?\b\s*$/) { |
|
328 $datapagingadd = " " . $1 . "pageddata"; |
|
329 } |
|
330 } elsif ($datapagingadd and !$codepagingadd) { |
|
331 if ($line =~ /\b(un)?paged(code)?\b\s*$/) { |
|
332 $codepagingadd = " " . $1 . "pagedcode"; |
|
333 } |
|
334 } |
|
335 if ($datapagingadd or $datapagingadd) { |
|
336 $line =~ s/\b(un)?paged(code|data)?\b/ /ig; |
|
337 } |
|
338 } |
|
339 push @newlines, "$line$codepagingadd$datapagingadd\n"; |
|
340 } |
|
341 @$oby = @newlines; |
|
342 } |
|
343 |
|
344 1; |