Subversion Repositories DevTools

Rev

Rev 5709 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
369 dpurdie 1
########################################################################
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
369 dpurdie 3
#
4
# Module name   : MSP430.PL
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Toolset for the Texas Instruments CC Studio
10
#
11
#......................................................................#
12
 
13
use strict;
14
use JatsVersionUtils;
15
 
16
our $s;
17
our $o;
18
our $so;
19
our $exe;
20
our $tool_vxp430img;
383 dpurdie 21
our $itp_mode;
3559 dpurdie 22
our $msp430_procdef;
369 dpurdie 23
 
24
##############################################################################
25
#   ToolsetInit()
26
#       Runtime initialisation
27
#
28
##############################################################################
29
 
30
ToolsetInit();
31
 
32
sub ToolsetInit
33
{
34
    my( $version, $product, @defines, @dirs, @flags, @asflags, @asdefines );
35
 
36
    #.. Parse Toolset Arguments
37
    #
38
    Debug( "msp430(@::ScmToolsetArgs)\n" );
39
 
40
    foreach $_ ( @::ScmToolsetArgs ) {
41
        if (/^--Version=(.*)/) {                # Compiler version
3559 dpurdie 42
            $version = $1;
383 dpurdie 43
        } elsif ( /^--itp/ ) {
44
            $itp_mode = 1;
3559 dpurdie 45
        } elsif ( /^--procFlags=(.+)/ ) {
46
            $msp430_procdef = $1;
369 dpurdie 47
        } else {
48
            Message( "msp430: unknown toolset argument $_ -- ignored\n" );
49
        }
50
    }
51
 
52
    #.. Parse Platform Arguments
53
    #
54
    foreach $_ ( @::ScmPlatformArgs ) {
55
        Message( "msp430: unknown platform argument $_ -- ignored\n" );
56
    }
57
 
58
 
59
    #.. Standard.rul requirements
60
    #
61
    $s = 'asm';             # Assembler source file
62
    $o = 'obj';             # Object file
63
    $a = 'lib';             # Library file
64
    $so = '';               # Shared library
65
    $exe = '.out';          # Linked binary images
66
 
67
    AddSourceType( ".$s", '.asm' );
68
 
69
 
70
    #.. Toolset configuration
71
    #
72
    $::ScmToolsetVersion = "1.0.0";               # our version
73
    $::ScmToolsetGenerate = 0;                    # generate optional
74
    $::ScmToolsetProgDependancies = 0;            # handle Prog dependancies myself
75
 
76
#.. Cleanup rules
77
#
78
#
79
#    ToolsetGenerate( "SomeFile" );
80
 
81
 
82
    #.. Define toolchain environment
83
    #
84
    #
85
    #   Define initialisation targets
86
    #   These will be used to ensure that correct versions of the toolset are present
87
    #
88
    Init( "msp430" );
89
 
90
    ToolsetDefine ( "#################################################" );
91
    ToolsetDefine ( "# MSP430 compiler version" );
92
    ToolsetDefine ( "#" );
93
    ToolsetDefine ( "msp430_ver         = $version" );
94
    ToolsetDefine ( "" );
95
    ToolsetDefine ( "#" );
96
    ToolsetDefines( "msp430.def" );
97
    ToolsetRules  ( "msp430.rul" );
98
    ToolsetRules  ( "standard.rul" );
99
 
3559 dpurdie 100
    # Support for ITP and different processor types
383 dpurdie 101
    ToolsetDefine ( "ITP_MODE = 1" )    if $itp_mode;
3559 dpurdie 102
    ToolsetDefine ( "MSP430_PROCDEF = $msp430_procdef" )    if $msp430_procdef;
383 dpurdie 103
 
369 dpurdie 104
}
105
 
106
 
107
##############################################################################
108
#   ToolsetPreprocess()
109
#       Process collected data before the makefile is generated
110
#       This, optional, routine is called from within MakefileGenerate()
111
#       It allows the toolset to massage any of the collected data before
112
#       the makefile is created
113
#
114
##############################################################################
115
 
116
#sub ToolsetPreprocess
117
#{
118
#}
119
 
120
###############################################################################
121
#   ToolsetCC( $source, $obj, \@args )
122
#       This subroutine takes the user options and builds the rule(s)
123
#       required to compile the source file 'source' to 'obj'
124
#
125
###############################################################################
126
 
127
sub ToolsetCC
128
{
129
    MakePrint( "\n\t\$(CC)\n" );
130
 
131
    #
132
    #   Mark generated assembler files to be deleted
133
    #
134
    ToolsetGenerate( "\$(OBJDIR)/$_[1].asm" );
135
}
136
 
137
###############################################################################
138
#   ToolsetCCDepend( $depend, \@sources )
139
#       This subroutine takes the user options and builds the
140
#       rule(s) required to build the dependencies for the source
141
#       files 'sources' to 'depend'.
142
#
143
###############################################################################
144
 
145
sub ToolsetCCDepend
146
{
147
    MakePrint( "\t\$(CCDEPEND)\n" );
148
}
149
 
150
 
151
###############################################################################
152
#   ToolsetCXX( $source, $obj, \@args )
153
#       This subroutine takes the user options and builds the rule(s)
154
#       required to compile the source file 'source' to 'obj'
155
#
156
###############################################################################
157
 
158
sub ToolsetCXX
159
{
160
    MakePrint( "\n\t\$(CC)\n" );
161
}
162
 
163
###############################################################################
164
#   ToolsetCXXDepend( $depend, \@sources )
165
#       This subroutine takes the user options and builds the
166
#       rule(s) required to build the dependencies for the source
167
#       files 'sources' to 'depend'.
168
#
169
###############################################################################
170
 
171
sub ToolsetCXXDepend
172
{
173
    ToolsetCCDepend();
174
}
175
 
176
 
177
###############################################################################
178
#   ToolsetAS( $source, $obj, \@args )
179
#       This subroutine takes the user options and builds the rule(s)
180
#       required to compile the source file 'source' to 'obj'
181
#
182
###############################################################################
183
 
184
sub ToolsetAS
185
{
186
    MakePrint( "\n\t\$(CC)\n" );
187
}
188
 
189
sub ToolsetASDepend
190
{
191
}
192
 
193
###############################################################################
194
#   ToolsetAR( $name, \@args, \@objs )
195
#       This subroutine takes the user options and builds the rules
196
#       required to build the library 'name'.
197
 
198
#
199
#   Arguments:
200
#       --xxx                   No arguments currently defined
201
#
202
#   Output:
203
#       [ $(BINDIR)/name$.${a}:   .... ]
204
#           $(AR)
205
#
206
###############################################################################
207
 
208
sub ToolsetAR
209
{
210
    my( $name, $pArgs, $pObjs ) = @_;
211
 
212
    Debug("ToolsetAR");
213
 
214
#.. Parse arguments
215
#
216
    foreach $_ ( @$pArgs ) {
217
        if (/^--/) {
218
            Message( "AR: unknown option $_ -- ignored\n" );
219
        }
220
    }
221
 
222
#.. Target
223
#
224
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t", "", " \\\n\t\t", ".${o}", @$pObjs );
225
 
226
#.. Build library rule (just append to standard rule)
227
#
228
    MakePrint( "\n\t\$(AR)\n\n" );
229
}
230
 
231
 
232
###############################################################################
233
#   ToolsetARMerge()
234
#       Generate the recipe to merge libraries.
235
#       The dependency list is created by the caller.
236
#
237
###############################################################################
238
 
239
#sub ToolsetARMerge
240
#   Currently not supported
241
#   Add only if required
242
#
243
#{
244
#    MakePrint( "\n\t\$(ARMERGE)\n\n" );
245
#}
246
 
247
 
248
###############################################################################
249
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
250
#       This subroutine takes the user options and builds the rules
251
#       required to link the program 'name'.
252
#
253
#   Arguments:
254
#       --xxx                   No Arguments currently specified
255
#
256
#       Linker specific:
257
#       --Script=filename   Specify the name of a linker script file
258
#       --NoImg             Do not create IMG file, only COFF
259
#
260
#   Output:
261
#
262
#       name.map                - Map file
263
#       name.???
264
#       name.???
265
#       name.???
266
#
267
###############################################################################
268
 
269
sub ToolsetLD
270
{
271
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
371 dpurdie 272
    my $progName = $name;
273
    my $script;
383 dpurdie 274
    my $img_file = 1 unless $itp_mode;
385 dpurdie 275
    my $hex_file = 1 if $itp_mode;
371 dpurdie 276
    my $noVersion;
369 dpurdie 277
 
278
 
385 dpurdie 279
 
369 dpurdie 280
#.. Parse arguments
281
#
282
    foreach $_ ( @$pArgs )
283
    {
284
    #.. Target specific
285
    #
286
 
287
    #.. Toolset specific
288
    #
289
        if (/^--Script=(.*)/) {           # External file
290
            $script = $1;
291
            $script .= ".cmd" unless ( $script =~ m~\.cmd$~ );
292
 
293
        } elsif (/^--NoImg/i ) {
294
            $img_file = undef;
295
 
385 dpurdie 296
        } elsif (/^--NoHex/i ) {
297
            $hex_file = undef;
298
 
371 dpurdie 299
        } elsif (/^--NoVersion/i ) {
300
            $noVersion = 1;
301
 
369 dpurdie 302
        } else {
303
            Message( "Prog: unknown option $_ -- ignored\n" );
304
        }
305
    }
306
 
307
#
308
#   Sanity check
309
#       - Ensure a linker script has been provided
310
#
385 dpurdie 311
Error ("Cannot generate 'image' and 'hex' at the same time") if $hex_file and $img_file;
369 dpurdie 312
unless ( $script )
313
{
383 dpurdie 314
    $script = "$name.cmd";
369 dpurdie 315
    Warning( "Prog: Linker Script file not provided. Using $script" );
316
}
317
 
318
#
319
#   Locate the true path of the provided script file
320
#   If it is a generate file so it will be in the SRCS hash
321
#   Other wise the use will have to use Src to locate the file
322
#
323
    $script = MakeSrcResolve ( $script );
324
 
325
#
326
#   If creating an IMG file, then ensure that the tools are available
327
#
328
if ( $img_file )
329
{
330
    unless ( defined $tool_vxp430img )
331
    {
332
        $tool_vxp430img = ToolExtensionProgram( 'vxp430img', '.exe', '' );
333
        if ( $tool_vxp430img )
334
        {
335
            MakePrint ( "#################################################\n" );
336
            MakePrint ( "#  The path to tools required to build programs\n" );
337
            MakePrint ( "#\n" );
338
            MakePrint ( "TOOL_VXP430IMG := $tool_vxp430img\n" );
339
            MakePrint ( "\n" );
340
        }
341
        else
342
        {
343
            Error( 'Tool program required by toolset not found:',
344
                   'vxp430img',
345
                   'Check that the vxp430img package is present' );
346
        }
347
    }
348
}
349
 
350
#
371 dpurdie 351
#   Insert version number into the output name
352
#
353
    unless ( $noVersion )
354
    {
355
        $name .= "_\$(BUILDVERNUM)";
356
    }
357
 
358
#
369 dpurdie 359
#   Create a ToolsetPrinter
360
#
361
    my ($io) = ToolsetPrinter::New();
362
    my $dep = $io->SetLdTarget( $name );
363
 
364
#
371 dpurdie 365
#   Determine the target output name(s)
369 dpurdie 366
#
371 dpurdie 367
    my $root = "\$(BINDIR)/${name}";
368
    my $phonyProgName = "\$(BINDIR)/${progName}" . $::exe;
369 dpurdie 369
    my $full = $root . $::exe;
370
    my $img = $img_file ? $root . '.img' : '';
371 dpurdie 371
    my $hex = $root . '.hex';
369 dpurdie 372
    my $map = $root . '.map';
373
 
374
#
375
#   Add runtime support libaries
376
#   These are transparent to the user
377
#
378
    push @$pLibs, 'libc.a';
379
 
380
########################################################################
381
#
382
#   Before this function was called, makelib.pl2 has generated a
383
#   partial rule consisting of:
384
#
385
#       $(BINDIR)/${name}${exe} :
386
#               All the specified object files
387
#
388
#   Add the names of all the other files required in the process
389
#   This will then serve as a target fo all things that need to be
390
#   created when a "program" is required
391
#
392
#       These are:
393
#               User linker script file
394
#               Library dependency file
371 dpurdie 395
#
396
    unless ( $noVersion )
397
    {
398
        $io->Label( "Program", $progName );                     # label
399
        $io->Prt( ".PHONY:\t$phonyProgName\n" );                # Mark as phony
400
        $io->Prt( "$phonyProgName: \t$full\n" );                # Dependencies
401
        $io->Newline();
402
    }
403
 
404
    #
405
    #   Rules to generate the program
406
    #
369 dpurdie 407
    $io->Label( "Program", $name );                     # label
385 dpurdie 408
    $io->Prt( "$full $img $hex: \t$dep" );                   # Dependencies
369 dpurdie 409
    $io->Prt( "\\\n\t\t$script" );
410
    $io->Entry( "", "", "\\\n\t", ".$::o ", @$pObjs );  # Object Files
411
    $io->Prt( "\n\t\$(LD)" );
412
    $io->Prt( "\n\t\$(call COFF2IMG,$full,$img,\$(BUILDVER))\n" ) if ($img);
385 dpurdie 413
    $io->Prt( "\n\t\$(call COFF2HEX,$full,$hex)\n" ) if ($hex_file);
369 dpurdie 414
    $io->Newline();
415
 
416
    #
417
    #   Specify files created by the linker
418
    #   These will be added to the clean list
419
    #
371 dpurdie 420
    ToolsetGenerate( $full );
369 dpurdie 421
    ToolsetGenerate( $map );
422
    ToolsetGenerate( $root . '.ld' );
385 dpurdie 423
    ToolsetGenerate( $hex ) if ( $img || $hex_file) ;
424
    ToolsetGenerate( $img ) if ($img );
369 dpurdie 425
 
426
    #
427
    #   Create a linker command file
428
    #   Piecing together a variable $(name_ld) which ends up in the command file.
429
    #   This bit of magic will be performed by the LD recipe
430
    #
431
    $io->SetTag( "${name}_ld" );                            # macro tag
432
    $io->Label( "Linker commands", $name );                 # label
385 dpurdie 433
    unless ( $itp_mode )
434
    {
435
        $io->Cmd("--stack_size=160");
436
        $io->Cmd("--heap_size=160");
437
        $io->Cmd("--use_hw_mpy=F5");
438
        $io->Cmd("--entry_point=main" );                        # Fixed entry point
439
    }
440
    else
441
    {
442
        $io->Cmd("--stack_size=50");
443
        $io->Cmd("--heap_size=0");
444
#        $io->Cmd("--symdebug:dwarf");
445
        $io->Cmd("--rom_model");
369 dpurdie 446
 
385 dpurdie 447
    }
448
        $io->Cmd("--warn_sections" );                           # Warn if creating unused sections
449
        $io->Cmd("-o $full" );                                  # Output file
450
        $io->Cmd("-m $map" );                                   # Map file
451
        $io->Cmd("--reread_libs" );                             # Multipass on lib files
452
        $io->Cmd("-l $script" );                                # User script file
453
 
369 dpurdie 454
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );      # Object files
455
 
456
    #
457
    #   Specify the library files
458
    #
459
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );      # Specify the libraries too
460
    $io->Newline();
461
 
462
    #.. Dependency link,
463
    #   Create a library dependency file
464
    #       Create command file to build applicaton dependency list
465
    #       from the list of dependent libraries
466
    #
467
    #       Create makefile directives to include the dependency
468
    #       list into the makefile.
469
    #
470
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, $full );
471
    $io->LDDEPEND(); 
472
 
473
    #
474
    #   Add the MAP file to the program package
475
    #
371 dpurdie 476
    PackageProgAddFiles ( $progName, $full );
477
    PackageProgAddFiles ( $progName, $img ) if ($img);
385 dpurdie 478
    PackageProgAddFiles ( $progName, $hex ) if ($img || $hex_file );
371 dpurdie 479
    PackageProgAddFiles ( $progName, $map , 'Class=map' );
369 dpurdie 480
}
481
 
482
########################################################################
483
#
484
#   Generate a linker object recipe.  This is a helper function used 
485
#   within this toolset.
486
#
487
#   Arguments:
488
#       $io         I/O stream
489
#
490
#       $target     Name of the target
491
#
492
#       $obj        Library specification
493
#
494
########################################################################
495
 
496
sub ToolsetObjRecipe
497
{
498
    my ($io, $target, $obj) = @_;
499
 
500
    $io->Cmd("$obj.$::o" );
501
}
502
 
503
########################################################################
504
#
505
#   Generate a linker/depend library recipe.  This is a helper function
506
#   used within this toolset.
507
#
508
#   Arguments:
509
#       $io         I/O stream
510
#
511
#       $target     Name of the target
512
#
513
#       $lib        Library specification
514
#
515
#       $dp         If building a depend list, the full target name.
516
#
517
########################################################################
518
 
519
sub ToolsetLibRecipe
520
{
521
    my ($io, $target, $lib, $dp) = @_;
522
 
523
    #
524
    #   Run time libraries will have a .a suffix
525
    #   Do not append .lib if this is the case
526
    #
527
    $lib .= '.' . $::a unless ( $lib =~ m~\.a$~ );
528
 
529
 
530
    if ( !defined($dp) ) {                      # linker
531
        $io->Cmd("\"@(vpath2,\"$lib\",LIB,\\)\"" );
532
    } else {                                    # depend
533
        $io->Cmd( "$dp:\t@(vlib2,\"$lib\",LIB)" );
534
    }
535
}
536
 
537
#.. Successful termination
538
1;
539