Subversion Repositories DevTools

Rev

Rev 5709 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
227 dpurdie 1
# -*- mode: perl; tabs: 8; indent-width: 4; show-tabs: yes; -*-
6177 dpurdie 2
# COPYRIGHT - VIX IP PTY LTD ("VIX"). ALL RIGHTS RESERVED.
227 dpurdie 3
#
4
# Module name   : mos_mri
5
# Module type   : Makefile system
6
# Compiler(s)   : ANSI C
7
# Environment(s): MOS
8
#
9
# Description:
10
#       MRI 68k/CF toolset for MOS
11
#       This file provides Toolset initialisation and plugin functions
12
#       to makelib.pl2
13
#
14
# Contents:     MRI 68k/CF rules as used for the MOS
15
#
16
# Revision History:
17
#       12-Feb-04   DDP     Started Work
18
#............................................................................#
19
 
20
use strict;
21
use warnings;
22
 
23
#
24
#   Toolset Global variables
25
#
26
my $Toolset_DebugCode;
27
my $Toolset_DebugData;
28
my $Toolset_Product = '';
239 dpurdie 29
my $Toolset_Production_Only;
227 dpurdie 30
 
31
 
32
##############################################################################
33
#   ToolsetInit()
34
#       Runtime initialisation
35
#
36
##############################################################################
37
 
38
ToolsetInit();
39
 
40
sub ToolsetInit
41
{
42
    my( $version, $flavour );
43
    my $no_defines;
44
    my( @defines );
45
    my $board = '';
46
 
47
#.. Parse Toolset arguments
48
#
49
    Debug( "mos_mri(@::ScmToolsetArgs)\n" );
50
 
51
    $version = 0;                               # Default (not great)
52
    $flavour = '68k';
53
    foreach $_ ( @::ScmToolsetArgs ) {
54
        if (/^--Version=(.*)/) {                # Compiler version
55
            $version = "$1";
56
        } elsif (/^--68k/) {                    # Compiler flavour
57
            $flavour = '68k';
58
        } elsif (/^--coldfire/) {               # Compiler flavour
59
            $flavour = 'cf';
60
        } elsif (/^--NoDefines/) {               # Vanila defines
61
            $no_defines = 1;
62
        } else {
63
            Message( "mos_mri: unknown toolset argument $_ -- ignored" );
64
        }
65
    }
66
 
67
#.. Parse Platform Arguments
68
#
69
    foreach $_ ( @::ScmPlatformArgs ) {
70
        if (/^--product=(.*)/) {                # GBE product
71
            $Toolset_Product = $1;
72
        } elsif (/^--board=(.*)/) {             # Board subtypes
73
            $board = $1;
74
        } else {
75
            Message( "mos_mri: unknown platform argument $_ -- ignored" );
76
        }
77
    }
78
 
79
#
239 dpurdie 80
#   Is this a ProductionOnly build, then we don't need the debug code and data
81
#   when building a THX. Determine, if this is a ProductionOnly build.
82
#
83
foreach  ( @{$::BUILDINFO{$::ScmPlatform}{ARGS}} )
84
{
85
    if ( m~^--OnlyProd~ )
86
    {
87
        $Toolset_Production_Only = 1;
88
        last;
89
    }
90
}
91
 
92
#
227 dpurdie 93
#   Definitions common to all platforms
94
#   These will be picked up when no platform has been defined: ie when
95
#   simply building for MOS68K or MOSCF
96
#
97
#   Note: _MICROTEC     is predefined by the compiler
98
#
99
    unless ( $no_defines )
100
    {
101
        push @defines, 'MOS';
102
        push @defines, '_MOS';
103
        push @defines, '_MOS_=1';
104
        push @defines, '_MOS_PERTH_=1';
105
        push @defines, 'MICROTEC=1';
106
        push @defines, 'MRI=1';
107
        push @defines, 'BIG_ENDIAN=1';
108
        push @defines, 'CcCpuBigEndian=1';
109
        push @defines, 'CcSupervisor=$(MODE_CCSUPERVISOR)';
110
        push @defines, 'CcCpu=$(mri_cpu_code)';
111
    }
112
 
113
#
114
#   Platform specific definitions
115
#   Set default code and data for development purposes only
116
#   This can be overridden
117
#
118
    if ( $Toolset_Product eq "GAK" || $Toolset_Product eq "TPT" )
119
    {
120
        # Example only
121
        #push @defines, '	SSM_DV';
122
        #push @defines, '	DES_ALIGN_CHECK';
123
        #push @defines, '	AMCCIF=15';
124
        #push @defines, '	PACKED=packed';
125
 
126
        if ( $flavour eq  '68k' )
127
        {
128
            $Toolset_DebugCode = "08100000H";
129
            $Toolset_DebugData = "0800800CH";
130
        }
131
        else
132
        {
133
            $Toolset_DebugCode = "08200000H";
134
            $Toolset_DebugData = "0800800CH";
135
        }
136
    }
137
    elsif ( $Toolset_Product eq "PCP" )
138
    {
139
        $board = "08200000H,0800800CH" if ( $board =~ m/development/i );
140
        $Toolset_DebugCode = "08100000H";
141
        $Toolset_DebugData = "0800800CH";
142
    }
143
    elsif ( $Toolset_Product eq "VCP" )
144
    {
145
        $Toolset_DebugCode = "08100000H";
146
        $Toolset_DebugData = "0800800CH";
147
    }
303 dpurdie 148
    elsif ( $Toolset_Product eq "TP5" or $Toolset_Product eq "PICP" )
227 dpurdie 149
    {
150
        $board = "08000000H,0400800CH" if ( $board =~ m/green/i );
151
        $Toolset_DebugCode = "05C00000H";
152
        $Toolset_DebugData = "0400800CH";
153
    }
154
    elsif ( $Toolset_Product eq "SSU" )
155
    {
156
    #    $Toolset_DebugCode = "08100000H";
157
    #    $Toolset_DebugData = "0800800CH";
158
    }
159
    elsif ( $Toolset_Product eq "DDU" )
160
    {
161
    #    $Toolset_DebugCode = "08100000H";
162
    #    $Toolset_DebugData = "0800800CH";
163
    }
164
    elsif ( $Toolset_Product eq "HCP" )
165
    {
166
    #    $Toolset_DebugCode = "08100000H";
167
    #    $Toolset_DebugData = "0800800CH";
168
    }
169
    elsif ( $Toolset_Product eq "OBFTP" )
170
    {
171
        $Toolset_DebugCode = "08200000H";
172
        $Toolset_DebugData = "0800800CH";
173
    }
174
    elsif ( $Toolset_Product )
175
    {
303 dpurdie 176
        Message( "mos_mri: Unknown product: $Toolset_Product -- ignored" )
177
            unless ( $board );
227 dpurdie 178
    }
179
 
180
    #
181
    #   Decode any --board option
182
    #   This will override any defaults
183
    #
184
    if ($board )
185
    {
186
        if ( $board =~ m~(0[0-9A-F]+H),(0[0-9A-F]+H)~i )
187
        {
188
            $Toolset_DebugCode = $1;
189
            $Toolset_DebugData = $2;
190
            Message("Building for a $Toolset_Product DEVELOPMENT board: Code:$Toolset_DebugCode, Data:$Toolset_DebugData");
191
        }
192
        else
193
        {
194
            Error( "Bad board definition: $board",
195
                   "Expecting two hex numbers of the form 012345H" );
196
        }
197
    }
198
 
199
 
200
if ( $Toolset_Product && (! $Toolset_DebugCode || ! $Toolset_DebugData ))
201
{
202
    Message( "mos_mri: $Toolset_Product: Debug Code and Data not specified" );
203
}
204
 
205
#.. Standard.rul requirements
206
#
207
    $::s = 'asm';             # Assembler source file
208
    $::o = 'obj';             # Object file
209
    $::a = 'lib';             # Library file
210
    $::so = 'thx';            # Shared library
211
    $::exe = '.abs';          # Dummy, Cannot generate executables
212
 
213
#.. Toolset configuration
214
#
215
    $::ScmToolsetVersion = "1.0.0";               # our version
216
    $::ScmToolsetGenerate = 0;                    # generate optional
323 dpurdie 217
    $::ScmToolsetProgDependancies = 0;            # handle Prog dependancies myself		7 "I:\jats_cbuilder\JATS\MASS_Dev_Infra\core_devl\CFG\TOOLSET\ACEX.PL"
227 dpurdie 218
 
219
#.. Define MRI environment
220
#
221
    #
222
    #   Define initialisation targets
223
    #   These will be used to ensure that correct versions of the toolset are present
224
    #
225
    Init( "mri", "mri2" );
226
 
227
    ToolsetDefine ( "#################################################" );
228
    ToolsetDefine ( "# MOS MRI compiler version" );
229
    ToolsetDefine ( "#" );
230
    ToolsetDefine ( "mri_ver         = $version" );
231
    ToolsetDefine ( "mri_type        = $flavour" );
232
    ToolsetDefine ( "" );
233
    ToolsetDefine ( "#" );
234
    ToolsetDefines( "mos_mri_${flavour}.def" );
235
    ToolsetRules  ( "mos_mri.rul" );
236
    ToolsetRules  ( "standard.rul" );
237
 
238
    PlatformEntry( "MRI_DEFINES\t=",    "\n", "\\\n\t", "", @defines )
239
        if ( scalar @defines );
240
 
241
    #
242
    #   Other toolsets used
243
    #
244
    PlatformDefine ("LINT_COFILE\t= MOS_MRI.LNT");
245
    PlatformDefine ("LINT_PRJ_FILE\t=lint.mri");
246
    ToolsetRequire( "pclint" );                 # using pclint
247
 
248
#
249
#   The debug files need to be compiled up with absolute paths to the source files
250
#   The easiest way to do this is with the makefile rules created with absolute
251
#   paths. Set a global flag to enable this option
252
#
253
    $::UseAbsObjects = 1;
254
 
255
 
256
#.. Extend the CompilerOption directive
257
#   Create a standard data structure
258
#   This is a hash of hashes
259
#       The first hash is keyed by CompileOption keyword
260
#       The second hash contains pairs of values to set or remove
261
#
262
    %::ScmToolsetCompilerOptions =
263
    (
264
        'ccsupervisor'          => { 'MODE_CCSUPERVISOR' , '1' },
265
 
266
        #
267
        #   When using MOS fast intermodule calls the optimizer will preload commonly
268
        #   used memory addresses into a register BEFORE the GDP has been correctly set
269
        #   up. Use the following option to supress this optimisation
270
        #
271
        'noglobaloptimization'  => { 'NO_OPT_GLOBAL' , '1' },
272
 
273
        #
274
        #   To enable 32-bit relative PC addressing on platforms that
275
        #   don't have this as a default
276
        #
277
        'longrelative'    => { 'USE_32BIT_RELATIVE' , '1' },
278
        'nolongrelative'  => { 'USE_32BIT_RELATIVE' , undef },
279
 
280
    );
281
 
282
    #
283
    #   Set default options
284
    #       $::ScmCompilerOpts{'xxxx'} = 'yyy';
285
    $::ScmCompilerOpts{'MODE_CCSUPERVISOR'} = '0';
286
    $::ScmCompilerOpts{'NO_OPT_GLOBAL'} = undef;
287
    $::ScmCompilerOpts{'USE_32BIT_RELATIVE'} = undef;
288
}
289
 
290
##############################################################################
291
#   ToolsetPreprocess()
292
#       Process collected data before the makefile is generated
293
#       This, optional, routine is called from within MakefileGenerate()
294
#       It allows the toolset to massage any of the collected data before
295
#       the makefile is created
296
#
297
##############################################################################
298
 
299
sub ToolsetPreprocess
300
{
301
    #
302
    #   If the user has specified a Prog or Shared library, then the
303
    #   tools within this file will need to be able to access
304
    #   a few external resouces. These will be provided by packages
305
    #   that should exist
306
    #
307
    #
308
    if ( $#::TESTPROGS >= 0 || $#::PROGS >= 0 || $#::SHLIBS >= 0)
309
    {
310
        my %need = ( "brt.exe"          => "TOOL_BRT",
311
                     "modcrc.exe"       => "TOOL_MODCRC",
312
                     "rel.exe"          => "TOOL_REL",
313
                     "vclickpaths.exe"  => "TOOL_VPATHS"
314
                   );
315
        my %found = ();
316
 
317
        #
318
        #   Locate the required files
319
        #
320
        for my $program ( keys( %need ))
321
        {
322
            if ( my $path = ToolExtensionProgram( $program ) )
323
            {
324
                $found{ $need{$program} } = $path;
325
                delete( $need{$program} );
326
            }
327
        }
328
 
329
        ::Error( "Tool program(s) required by toolset not found:",
330
                  sort( keys %need),
331
                  "Check that the daf_tools and mos_tools packages are present" )
332
            if ( scalar keys %need );
333
 
334
        #
335
        #   Generate the definitions
336
        #
337
 
338
        ToolsetDefine ( "#################################################" );
339
        ToolsetDefine ( "#  The path to tools required to build MOS Programs" );
340
        ToolsetDefine ( "#" );
341
        for my $defn ( keys %found )
342
        {
343
            ToolsetDefine ( "$defn := $found{$defn}" );
344
        }
345
        ToolsetDefine ( "" );
346
        ToolsetDefine ( "#  The drive path to prefix to the vision click paths" );
347
        EnvImport( "GBE_DRV" );
348
        ToolsetDefine ( "GBE_VCLICKDRV = $::GBE_DRV" );
349
    }
350
}
351
 
352
###############################################################################
353
#   ToolsetCC( $source, $obj, \@args )
354
#       This subroutine takes the user options and builds the rule(s)
355
#       required to compile the source file 'source' to 'obj'
356
#
357
#   Implementation Note:
358
#   The MRI compilers that are being used have a problem.
359
#   If the source filename is relative and longer that ~80 characters and the
360
#   -Gf switch is being used, then the compiler warns that the pathname is
361
#   too long to be stored in the ABS file. It then stores the relative name to
362
#   the file in thr ABS file. This confuses visionclick and vclickpaths
363
#
364
#   If the source file is an absolute path, then none of these problems
365
#   occur, BUT the displayed error messages get chopped so that the user
366
#   cannot determine the file being compiled.
367
#
368
#   Solution:
369
#       * Give the compiler an absolute path name
370
#       * Display a shortened filename on the JATS output
371
#
372
###############################################################################
373
 
374
sub ToolsetCC
375
{
376
    MakePrint( "\n\t\$(CC)\n" );
377
}
378
 
379
###############################################################################
380
#   ToolsetCCDepend( $depend, \@sources )
381
#       This subroutine takes the user options and builds the
382
#       rule(s) required to build the dependencies for the source
383
#       files 'sources' to 'depend'.
384
#
385
###############################################################################
386
 
387
sub ToolsetCCDepend
388
{
389
    MakePrint( "\t\$(CCDEPEND)\n" );
390
}
391
 
392
 
393
###############################################################################
394
#   ToolsetCXX( $source, $obj, \@args )
395
#       This subroutine takes the user options and builds the rule(s)
396
#       required to compile the source file 'source' to 'obj'
397
#
398
###############################################################################
399
 
400
sub ToolsetCXX
401
{
402
    MakePrint( "\n\t\$(CXX)\n" );
403
}
404
 
405
###############################################################################
406
#   ToolsetCXXDepend( $depend, \@sources )
407
#       This subroutine takes the user options and builds the
408
#       rule(s) required to build the dependencies for the source
409
#       files 'sources' to 'depend'.
410
#
411
###############################################################################
412
 
413
sub ToolsetCXXDepend
414
{
287 dpurdie 415
    ToolsetCCDepend();
227 dpurdie 416
}
417
 
418
 
419
###############################################################################
420
#   ToolsetAS( $source, $obj, \@args )
421
#       This subroutine takes the user options and builds the rule(s)
422
#       required to compile the source file 'source' to 'obj'
423
#
424
###############################################################################
425
 
426
sub ToolsetAS
427
{
428
    MakePrint( "\n\t\$(AS)\n" );
429
}
430
 
431
sub ToolsetASDepend
432
{
433
}
434
 
435
###############################################################################
436
#   ToolsetAR( $name, \@args, \@objs )
437
#       This subroutine takes the user options and builds the rules
438
#       required to build the library 'name'.
439
 
440
#
441
#   Arguments:
442
#       --xxx                   No arguments currently defined
443
#
444
#   Output:
445
#       [ $(BINDIR)/name$.${a}:   .... ]
446
#           $(AR)
447
#
448
###############################################################################
449
 
450
sub ToolsetAR
451
{
452
    my( $name, $pArgs, $pObjs ) = @_;
453
    my $lib_file = "${name}\$(GBE_TYPE)";
454
    my $lib_base = "\$(LIBDIR)/$lib_file";
455
    my $lib_name = "$lib_base.${a}";
456
 
457
    Debug("ToolsetAR");
458
 
459
#.. Parse arguments
460
#
461
    foreach $_ ( @$pArgs ) {
462
        if (/^--/) {
463
            Message( "AR: unknown option $_ -- ignored" );
464
        }
465
    }
466
 
467
#.. Target
468
#
469
    MakeEntry( "$lib_name:\t", "", "\\\n\t\t", ".$::o", @$pObjs );
470
    MakePrint( "\n\t\$(AR)\n\n" );
471
 
472
}
473
 
474
###############################################################################
475
#   ToolsetARLINT( $name, \@args, \@objs )
476
#       This subroutine takes the user options and builds the rules
477
#       required to build the library 'name'.
478
#
479
#   Arguments:
480
#       --xxx                   No arguments currently defined
481
#
482
#   Output:
483
#       [ $(LIBDIR)/name$_lint:   .... ]
484
#           $(ARLINT)
485
#
486
###############################################################################
487
 
488
sub ToolsetARLINT
489
{
490
    PCLintAR( @_ );
491
}
492
 
493
###############################################################################
494
#   ToolsetARMerge()
495
#       Generate the recipe to merge libraries.
496
#       The dependency list is created by the caller.
497
#
498
###############################################################################
499
 
500
sub ToolsetARMerge
501
{
502
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
503
}
504
 
505
 
506
###############################################################################
507
#   ToolsetSHLD $name, \@args, \@objs, \@libraries )
508
#       This subroutine takes the user options and builds the rules
509
#       required to link a shared library with any associated stub files
510
#
511
#   Arguments:
512
#       --xxx                   No Arguments currently specified
513
#
514
#       Linker specific:
515
#       --Data                  Generate a Data Module
516
#       --Debug                 Generate a debug module
517
#       --DebugCode=nnnnnH      Generate a debug module with code at address
518
#       --DebugData=nnnnnH      Generate a debug module with data at address
519
#       --Rel=file              Specify the Release file
520
#       --Implib=objfile        Specify an import library object
521
#       --StubOnly              Only generate the stub library
522
#       --BinaryImage           Generate binary image instead of a THX file
523
#
524
#   Output:
525
#
526
#       name.thx                - Loadable module
527
#       name.lib                - Module interface stub library
528
#       name.abs                - Precursor to .thx
529
#       name_o.abs              - Used to generate relocation information
530
#       name_0.abs              - Used to generate relocation information
531
#
532
#       name_debug.bdx          - File for debugger
533
#       name_debug.ab           - File for debugger
534
#       name_debug.abs          - Precursor to .bdx and .ab files
535
#
536
#       This is a very complicated process:
537
#           Generate stub library
538
#           Create module header object file
539
#           Link all at one address
540
#           Link all at another address
541
#           Determine relocation information
542
#           Compile up relocation information
543
#           Link all with relocation information
544
#           Create VisionClick debug files
545
#           Generate CRC over module
546
#
547
#   $(LIBDIR)/name.thx $(BINDIR)/name.bdx $(BINDIR)/name.ab :
548
#                       $(BINDIR)/name.abs
549
#
550
#   $(LIBDIR)/name.abs :
551
#                       objs ....
552
#                       libs ....
553
#                       $(OBJDIR)/linker_cmd_file
554
#
555
#   $(LIBDIR)/linker_cmd_file :
556
#                       $(GBE_PLATFORM).mk
557
#                       ...
558
###############################################################################
559
 
560
sub ToolsetSHLD
561
{
562
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
563
    my $module_type = '';
564
    my $debug_code = $Toolset_DebugCode || 0;
565
    my $debug_data = $Toolset_DebugData || 0;
566
    my( $u_rel_file, $rel_file, $head_file, $implib, $stub_only, $bin_image);
567
    my $pSlibs;
568
 
569
 
570
#.. Parse arguments
571
#
572
    foreach $_ ( @$pArgs )
573
    {
574
 
575
    #.. Target specific
576
    #
577
 
578
    #.. Toolset specific
579
    #
580
        if (/^--Data$/) {                       # Generate a data module
581
            $module_type  = "data";
582
 
583
        } elsif (/^--Acon$/) {                  # Generate an ACON  module
584
            $module_type  = "acon";
585
 
586
        } elsif (/^--Rel=(.*)/) {               # The base REL file
587
            $u_rel_file = $1;
588
 
589
        } elsif (/^--Implib=(.*)/) {            # The import library object file
590
            $implib = $1;
591
 
592
        } elsif (/^--Stubonly/) {               # Only generate the stub library
593
            $stub_only = 1;
594
 
595
        } elsif (/^--BinaryImage/) {            # Generate binary image instead of a THX file
596
            $bin_image = 1;
597
 
598
        } elsif (/^--DebugData=(.*)/) {         # Generate a debug module
599
            $debug_data = $1;
600
            $module_type  = "debug";
601
 
602
        } elsif (/^--DebugCode=(.*)/) {         # Generate a debug module
603
            $debug_code = $1;
604
            $module_type  = "debug";
605
 
606
        } else {
607
            Message( "Prog: unknown option $_ -- ignored" );
608
        }
609
    }
610
 
611
#
239 dpurdie 612
#   Cannot create binaries unless we know where to place them
227 dpurdie 613
#   This error could be detected earlier, but by detecting it only when
614
#   we need the values so that we can add new product groups without
615
#   knowning all the details.
616
#
239 dpurdie 617
unless ( $Toolset_Production_Only )
618
{
619
    Error( "mos_mri: $Toolset_Product: Debug Code and Data not specified" )
620
        if ( ! $debug_data || ! $debug_code );
227 dpurdie 621
 
239 dpurdie 622
}
227 dpurdie 623
 
624
#
625
#   Sanity check
626
#       - Ensure the use has provided a REL file
627
#
628
unless ( $u_rel_file )
629
{
630
    $u_rel_file = "$name.rel";
631
    Warning( "Prog: Rel file not provided. Using $u_rel_file" );
632
}
633
 
634
#
635
#   Locate the true path of the provided REL file
636
#   If it is a generate file so it will be in the SRCS hash
637
#   Other wise the use will have to use Src to locate the file
638
#
639
    $rel_file = MakeSrcResolve ( $u_rel_file );
640
 
641
#
642
#   Locate the true path of the head.asm file
643
#   This WILL be located within an external package as it is provided
644
#   by the MOS hardware package.
645
#
646
    $head_file = MakeSrcResolveExtended ( 1, "head.asm" );
647
 
648
#
649
#   If we are also creating an import (stub) library then remove
650
#   the stub library object file from the list of user provided objects
651
#   Done to allow the use of @OBJS in a library object list
652
#
653
if ( $implib )
654
{
655
    my @newobjs;
656
    for ( @$pObjs )
657
    {
658
        push @newobjs, $_
659
            unless ( m~/$implib$~ );
660
    }
661
    $pObjs = \@newobjs;
662
}
663
 
664
#
665
#   Extend the list of libraries with MOS specific libraries
666
#   This list may need multiple passes and will be replicated. Do not include
667
#   the compiler RTL library in this list as it will cause problems. It must be
668
#   linked last and linked only once.
669
#
670
    push( @$pLibs, 'glob' );
671
 
672
#   Create a list of system (RTL) libraries
673
#   We only want to use the compiler RTL library as a last resort and will only
674
#   make one pass over it.
675
#
676
    push( @$pSlibs, '$(mri_linker_lib)' );
677
 
678
#
679
#   Create a ABSRuleGenerator
680
#   This inherits from a a ToolsetPrinter and extends it to
681
#   allow addition data to be held
682
#
683
    my ($io) = ABSRuleGenerator::New( $name, $pObjs, $pLibs, $pSlibs );
684
 
685
 
686
########################################################################
687
#
688
#   Create a stub library to allow inter-module calls
689
#
690
if ( $implib )
691
{
692
    $io->Label( "Import(stub) library", $name );
693
    my $stub_lib = "\$(LIBDIR)/${name}\$(GBE_TYPE).${a}";
694
 
695
    #
696
    #   Rules and recipe to generate the stub library
697
    #
698
    #   If the implib was not named in the object list to this SharedLib
699
    #   then it will not be in OBJSOURCE and will not have a rule
700
    #
701
    #
702
    $::OBJSOURCE{"$name/$implib"} = $::OBJSOURCE{"$implib"}
703
        unless( $::OBJSOURCE{"$name/$implib"} );
704
    $io->Prt( "$stub_lib:\t\$(OBJDIR)/$name/$implib.$::o\n" );
705
    $io->Prt( "\t\$(AR)\n" );
706
    $io->Newline();
707
 
708
    #
709
    #   Files to be cleanup up
710
    #
711
    ToolsetGenerate( $stub_lib );
712
 
713
    #
714
    #   If the THX is being packaged/installed then add the static
715
    #   stub library to the packaging lists as a static library.
716
    #   This will allow the stub library to be installed with the
717
    #   static libraries and thus allow DLL's with mutual imports
718
    #
719
    PackageShlibAddLibFiles ($name, $stub_lib );
720
 
721
    #
722
    #   Add the stub library to the list of libraries being created
723
    #
724
    push @::LIBS, $name;
725
 
726
}
727
 
728
#
729
#   If we are only creating a sub library, then out work is done
730
#
731
if ( $stub_only )
732
{
733
    Error ("Request for stub library without specifying the Import file")
734
        unless ($implib);
735
    return;
736
}
737
 
738
########################################################################
739
#
740
#   Create the module header
741
#   This is a two step process
742
#       1) Create the head.inc file from the modules REL file
743
#       2) Compile the head.asm file
744
#
745
#   Note: "head.inc" is a fixed filename. It is created on demand
746
#         and left around
747
#
748
 
749
    $io->Label( "Module Header", $name );
750
    $io->Prt( "\$(OBJDIR)/${name}/head.$::o: $head_file $rel_file");
751
    $io->Prt( "\n\t\$(call AS_HEAD,$rel_file,$head_file,\$(OBJDIR)/${name}/head.$::o,\$(OBJDIR)/${name}/head.inc)\n" );
752
    $io->Newline();
753
 
754
    ToolsetObj     ( "\$(OBJDIR)/${name}/head" );
755
    ToolsetGenerate( "\$(OBJDIR)/${name}/head.inc" );
756
    ToolsetGenerate( "\$(OBJDIR)/head.inc" );
757
 
758
#
759
#   Create rules and recipes to generate two .abs files that are
760
#   used to generate relocation information
761
#
762
    $io->GenAbsFile( "OBJDIR", "_o", "S[3]", $module_type, "800000H", "100000H" );
763
    $io->GenAbsFile( "OBJDIR", "_0", "S[3]", $module_type, "400000H", "000000H" );
764
 
765
    #
766
    #   Create the relocation information from the two .abs files
767
    #   This file will be used to add to other abs files
768
    #
769
 
770
    $io->Prt( "\$(OBJDIR)/${name}_rtab_d.asm \$(OBJDIR)/${name}_rtab_cd.asm: BRTROOT=${name}\n" );
771
    $io->Entry( "\$(OBJDIR)/${name}_rtab_d.asm \$(OBJDIR)/${name}_rtab_cd.asm:\t", "", "\\\n\t\t\$(OBJDIR)/", ".abs ", ( "${name}_o", "${name}_0" ) );
772
    $io->Prt( "\n\t\$(BRT)\n" );
773
    $io->Newline();
774
 
775
    ToolsetGenerate( "\$(OBJDIR)/${name}_rtab_d.asm" );
776
    ToolsetGenerate( "\$(OBJDIR)/${name}_rtab_cd.asm" );
777
 
778
    #
779
    #   Rules to allow the two assembler files to be created
780
    #   Override user assembler flags to control the assembler environment
781
    #
782
    $io->Prt( "\$(OBJDIR)/${name}_rtab_d.$::o: ASFLAGS=-fNOPCR -frel32\n");
783
    $io->Prt( "\$(OBJDIR)/${name}_rtab_d.$::o: \$(OBJDIR)/${name}_rtab_d.asm");
784
    $io->Prt( "\n\t\$(AS)\n" );
785
    $io->Newline();
786
 
787
    $io->Prt( "\$(OBJDIR)/head.$::o: ASFLAGS=-fNOPCR -frel32\n");
788
    $io->Prt( "\$(OBJDIR)/${name}_rtab_cd.$::o: ASFLAGS=-fNOPCR -frel32\n");
789
    $io->Prt( "\$(OBJDIR)/${name}_rtab_cd.$::o: \$(OBJDIR)/${name}_rtab_cd.asm");
790
    $io->Prt( "\n\t\$(AS)\n" );
791
    $io->Newline();
792
 
793
    ToolsetObj( "\$(OBJDIR)/${name}_rtab_d" );
794
    ToolsetObj( "\$(OBJDIR)/${name}_rtab_cd" );
795
 
796
 
797
#
798
#   Create rules and recipes to generate the final .abs file which will feed into
799
#   the required .thx file. this file will now have embedded relocation information
800
#
801
    $io->GenAbsFile( "LIBDIR", "\$(GBE_TYPE)", "S[3]", $module_type, "400000H", "000000H", "\$(OBJDIR)/${name}_rtab_cd"  );
802
 
803
#
804
#   Create rules and recipes to generate a debug-able .abs file
805
#   This is a totally different beast and is then used to
806
#   create some debugger friendly files
807
#
808
    $io->GenAbsFile( "LIBDIR", "\$(GBE_TYPE)_debug", "IEEE", "debug", $debug_data, $debug_code, "\$(OBJDIR)/${name}_rtab_d" );
809
 
810
 
811
########################################################################
812
#
813
#   VisionClick support
814
#   Physivcal files will not be generated if the tool it not available
815
#   Either generate the files or provide phony targets
816
#
817
    $io->Label( "VisionClick support", $name );
818
    $io->Prt( "ifdef VISIONCLICK\n".
819
              "\$(LIBDIR)/${name}\$(GBE_TYPE)_vpaths.txt ".
820
              "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.bdx ".
821
              "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abx ".
822
              "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.ab: ".
823
              "\\\n\t\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abs".
824
              "\n\t\t\$(call VCLICK, \$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abs,\\".
825
              "\n\t\t               \$(LIBDIR)/${name}\$(GBE_TYPE)_vpaths.txt,\\".
826
              "\n\t\t               \$(GBE_VCLICKDRV) )".
827
              "\nelse".
828
              "\n.PHONY:\t\$(LIBDIR)/${name}\$(GBE_TYPE)_vpaths.txt".
829
              "\n.PHONY:\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.bdx".
830
              "\n.PHONY:\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abx".
831
              "\n.PHONY:\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.ab".
832
              "\nendif\n\n" );
833
 
834
    #
835
    #   Vision Click files for cleanup
836
    #
837
    ToolsetGenerate( "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.bdx" );
838
    ToolsetGenerate( "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.ab" );
839
    ToolsetGenerate( "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abx" );
840
    ToolsetGenerate( "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abg" );
841
    ToolsetGenerate( "\$(LIBDIR)/${name}\$(GBE_TYPE)_vpaths.txt" );
842
 
843
    #
844
    #   Add the Visionclick files to the package lists
845
    #   These will only be packaged if VISIONCLICK is defined
846
    #
847
    PackageShlibAddFiles( $name, "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.bdx" , 'defined=VISIONCLICK', 'Class=debug' );
848
    PackageShlibAddFiles( $name, "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.ab"  , 'defined=VISIONCLICK', 'Class=debug' );
849
    PackageShlibAddFiles( $name, "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abx" , 'defined=VISIONCLICK', 'Class=debug' );
850
    PackageShlibAddFiles( $name, "\$(LIBDIR)/${name}\$(GBE_TYPE)_vpaths.txt", 'defined=VISIONCLICK', 'Class=debug' );
851
 
852
 
853
########################################################################
854
#
855
#   Rules and recipes to create the .THX (.BIN) file
856
#   This ties together all the previous components
857
#
858
#
859
    my $sh_ext = $bin_image ? 'bin' : $::so;
860
 
861
    $io->Label( "MOS Module", $name );
862
    $io->Prt( "\$(LIBDIR)/${name}\$(GBE_TYPE).$sh_ext :" .
863
              "\\\n\t\t\$(OBJDIR)/${name}_o.abs " .
864
              "\\\n\t\t\$(OBJDIR)/${name}_0.abs " .
865
              "\\\n\t\t\$(OBJDIR)/${name}_rtab_cd.asm " .
866
              "\\\n\t\t\$(OBJDIR)/${name}_rtab_d.asm " .
867
              "\\\n\t\t\$(LIBDIR)/${name}\$(GBE_TYPE).abs " .
868
              "\\\n\t\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abs " .
869
              "\\\n\t\t\$(LIBDIR)/${name}\$(GBE_TYPE)_vpaths.txt ".
870
              "\\\n\t\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.bdx ".
871
              "\\\n\t\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abx ".
872
              "\\\n\t\t\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.ab "
873
            );
874
 
875
    if ( $bin_image)
876
    {
877
        $io->Prt( "\n\t\t\$(MODCRC_BIN)\n");
878
    }
879
    else
880
    {
881
        $io->Prt( "\n\t\t\$(MODCRC)\n");
882
    }
883
 
884
    #
885
    #   Register generated file for cleanup
886
    #   The MODCRC process generates a .bak file. Ensure that it gets removed
887
    #
888
    ToolsetGenerate( "\$(LIBDIR)/${name}\$(GBE_TYPE).$sh_ext" );
889
    ToolsetGenerate( "\$(LIBDIR)/${name}\$(GBE_TYPE).bak" );
890
 
891
    #
892
    #   Specify the files to be packaged as part of the shared library
893
    #
894
    PackageShlibAddFiles( $name, "\$(LIBDIR)/${name}\$(GBE_TYPE).$sh_ext" );
895
    PackageShlibAddFiles( $name, "\$(LIBDIR)/${name}\$(GBE_TYPE)_debug.abs", 'Class=debug' );
896
}
897
 
898
 
899
#-------------------------------------------------------------------------------
900
# package       : ABSRuleGenerator
901
#
902
# Description   : Package to contain data to generate rules to create
903
#                 ABS files.
904
#
905
#                 This is implemented as a class to allow blocks of
906
#                 data to be simply maintained
907
#
908
#                 This class ISA ToolsetPrinter too
909
#
910
# Parameters    : name      - Basic name of the library
911
#                 pObjs     - Ref to an array of object files to be linked
912
#                 pLibs     - Ref to an array of librarus to be linked
913
#                 pSlibs    - Ref to an array of system libraries to be linked
914
#                             These libraries will only be linked ONCE
915
#
916
package ABSRuleGenerator;
917
 
918
    use vars qw(@ISA);
919
    @ISA = ("ToolsetPrinter");
920
 
921
sub New
922
{
923
    my ($name, $pObjs, $pLibs, $pSlibs) = @_;
924
 
925
    my $self = ToolsetPrinter::New();
926
 
927
    $self->{name}  = $name;
928
    $self->{pObjs} = $pObjs;
929
    $self->{pLibs} = $pLibs;
930
    $self->{sLibs} = $pSlibs;
931
 
932
    return bless $self, __PACKAGE__;
933
}
934
 
935
#-------------------------------------------------------------------------------
936
# Function        : GenAbsFile
937
#
938
# Description     : Internal helper function to generate an ABS file
939
#                   with desirable characteristics
940
#
941
#                   Note: This function is not within the ToolsetSHLD to
942
#                         make closure problems obvious
943
#
944
# Inputs          : $1      - Name of the output directory (LIBDIR or OBJDIR)
945
#                   $2      - basename of the output file
946
#                   $3      - basename sufix
947
#                   $4      - Type of output IEEE /S[3]
948
#                   $5      - Kind of module - "acon", "data", "debug" or ""
949
#                   $6      - Base of the data segment
950
#                   $7      - Base of the code segment
951
#                   $8      - Extra (internal) object file to be linked in
952
#
953
# Returns         :
954
#
955
sub GenAbsFile
956
{
957
    my ( $io, $dir, $suf, $otype, $kind, $data_base, $code_base, $eObjs ) = @_;
958
    my $name  = $io->{'name'};
959
    my $pLibs = $io->{'pLibs'};
960
    my $pSlibs = $io->{'sLibs'};
335 dpurdie 961
    my $lib = $name . $suf;
227 dpurdie 962
 
963
    #
964
    #   Generate a full list of object files
965
    #
966
    my @allObjs = @{$io->{'pObjs'}};
967
    push @allObjs, $eObjs
968
        if ( $eObjs);
969
 
970
#
971
#.. Linker command file
972
#
973
#   Piecing together a variable $(name_ld) which ends up in the command file.
974
#   This bit of magic will be performed by the LDABS recipe
975
#
335 dpurdie 976
    $io->Reset();                                   # Reset internal state
977
    $io->SetTag( "${lib}_shld" );                   # macro tag
978
    $io->Label( "Linker commands", $lib );          # label
227 dpurdie 979
 
980
    $io->Cmd("FORMAT      $otype" );
981
    $io->Cmd("CHIP	    \$(mri_cpu_type)" );
982
    $io->Cmd("LISTMAP     CROSSREF,INTERNALS,PUBLICS" );
983
 
984
    $io->Cmd("DEBUG_SYMBOLS" )        if ( $kind eq "debug" );
985
 
986
    unless ( $kind eq "acon" || $kind eq "data" )
987
    {
988
        $io->Cmd("MERGE vars  StartPixInit,pixinit,EndPixInit" );
989
        $io->Cmd("MERGE vars  StartInitFini,initfini,EndInitFini" );
990
        $io->Cmd("MERGE vars  cxx_rtti,cxx_edt" );
991
        $io->Cmd("INITDATA    vars" );
992
        $io->Cmd("INDEX       ?A5,zerovars" );
993
        $io->Cmd("EXTERN      __mosSoftTrap" );
994
    }
995
 
996
    if ( $kind eq "data" )
997
    {
998
        $io->Cmd("SECT        header = 0H" );
999
        $io->Cmd("ORDER       header,ascode,code,const" );
1000
        $io->Cmd("ORDER       modtitle,lastsync" );
1001
    }
1002
    elsif ( $kind eq "acon" )
1003
    {
1004
        $io->Cmd("SECT        header = 0H" );
1005
        $io->Cmd("ORDER       header,const,code,ascode" );
1006
        $io->Cmd("ORDER       modtitle,lastsync" );
1007
    }
1008
    else
1009
    {
1010
        $io->Cmd("SECT        zerovars = $data_base" );
1011
        $io->Cmd("SECT        header = $code_base" );
1012
 
1013
        $io->Cmd("ORDER       zerovars,vars,uninivars" )      if ( $kind eq "debug" );
1014
        $io->Cmd("ORDER       header,ascode,code" );
1015
        $io->Cmd("ORDER       literals,strings,const" );
1016
        $io->Cmd("ORDER       ??INITDATA,modtitle,rellist,lastsync" );
1017
        $io->Cmd("ORDER       zerovars,vars,uninivars" )      unless ( $kind eq "debug" );
1018
        $io->Cmd("ORDER       stack" )                        if ( $kind eq "debug" );
1019
    }
1020
    $io->Cmd("ALIGN       lastsync,4" );
1021
    $io->Newline();
1022
 
1023
    #
1024
    #   Must load GLOB.LIB first so that "well-known" variables
1025
    #   in zerovars are at a known location
1026
    #
1027
    $io->Prt("#   Load the Global Library first\n");
1028
    $io->Newline();
1029
    $io->LibList( $name, ["glob"], \&ToolsetLibRecipe );
1030
    $io->Newline();
1031
 
1032
    $io->Prt("#   Load the module header and target specfic library\n");
1033
    $io->Prt("#\n");
1034
    $io->Cmd("LOAD    \$(OBJDIR)/${name}/head.$::o" );
1035
    $io->Newline();
1036
 
1037
    $io->Prt("#   List all the object files to be loaded\n");
1038
    $io->Prt("#\n");
1039
 
1040
    $io->ObjList( $name, \@allObjs, \&ToolsetObjRecipe );
1041
    $io->Newline();
1042
 
1043
    $io->Prt("#   Load the library files twice to overcome single pass linker problems\n");
1044
    $io->Prt("#\n");
1045
 
1046
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
1047
    $io->Newline();
1048
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
1049
    $io->Newline();
1050
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
1051
    $io->Newline();
1052
 
1053
    $io->LibList( $name, $pSlibs, \&ToolsetLibRecipe );
1054
    $io->Newline();
1055
 
1056
    $io->Prt("#.. Map file options\n");
1057
    $io->Cmd("LISTMAP	LENGTH 64");
1058
    $io->Cmd("LISTMAP	CROSSREF,INTERNALS,PUBLICS/by_addr");
1059
    $io->Cmd("END");
1060
    $io->Newline();
1061
 
335 dpurdie 1062
    #
1063
    #   Create the shared library dependency information
1064
    #
1065
    my $dep = $io->SetShldTarget( $lib, $dir );
227 dpurdie 1066
 
1067
    #
1068
    #   Create the rules and recipes to create the required file
1069
    #
335 dpurdie 1070
    $io->Prt( "\$($dir)/$lib.abs:\tSHBASE=${name}${suf}\n" );
1071
    $io->Prt( "\$($dir)/$lib.abs:\tSHNAME=${name}${suf}\n" );
1072
    $io->Prt( "\$($dir)/$lib.abs:\t\$(SCM_MAKEFILE)" );
1073
    $io->Prt( "\\\n\t\t$dep " );
323 dpurdie 1074
    $io->Entry( "", "", "\\\n\t\t", ".$::o ", @allObjs );
227 dpurdie 1075
    $io->Prt( "\\\n\t\t\$(OBJDIR)/${name}/head.$::o " );
1076
    $io->Prt( "\n\t\$(SHLDABS)\n" );
1077
    $io->Newline();
1078
 
1079
 
1080
    #.. Dependency link,
335 dpurdie 1081
    #   Create a library dependency file
1082
    #       Create command file to build applicaton dependency list
1083
    #       from the list of dependent libraries
227 dpurdie 1084
    #
335 dpurdie 1085
    #       Create makefile directives to include the dependency
1086
    #       list into the makefile.
227 dpurdie 1087
    #
335 dpurdie 1088
    $io->DepRules( $pLibs, \&ToolsetLibRecipe, "\$($dir)/$lib.abs" );
1089
    $io->DepRules( $pSlibs,\&ToolsetLibRecipe, "\$($dir)/$lib.abs" );
1090
    $io->SHLDDEPEND( $lib, $lib );
227 dpurdie 1091
 
1092
#.. Cleanup rules
1093
#
335 dpurdie 1094
    ::ToolsetGenerate( "\$($dir)/$lib.ld" );
1095
    ::ToolsetGenerate( "\$($dir)/$lib.abs" );
1096
    ::ToolsetGenerate( "\$($dir)/$lib.map" );
227 dpurdie 1097
 
1098
}
1099
 
1100
########################################################################
1101
#
1102
#   Generate a linker object recipe.  This is a helper function used 
1103
#   within this toolset.
1104
#
1105
#   Arguments:
1106
#       $io         I/O stream
1107
#
1108
#       $target     Name of the target
1109
#
1110
#       $obj        Library specification
1111
#
1112
########################################################################
1113
 
1114
sub ToolsetObjRecipe
1115
{
1116
    my ($io, $target, $obj) = @_;
1117
 
1118
    $io->Cmd("LOAD	$obj.$::o");
1119
}
1120
 
1121
########################################################################
1122
#
1123
#   Generate a linker/depend library recipe.  This is a helper function
1124
#   used within this toolset.
1125
#
1126
#   Arguments:
1127
#       $io         I/O stream
1128
#
1129
#       $target     Name of the target
1130
#
1131
#       $lib        Library specification
1132
#
1133
#       $dp         If building a depend list, the full target name.
1134
#
1135
########################################################################
1136
 
1137
sub ToolsetLibRecipe
1138
{
1139
    my ($io, $target, $lib, $dp) = @_;
1140
 
1141
    if ( !defined($dp) ) {                      # linker
1142
        $io->Cmd("LOAD	@(vpath2,$lib.$::a,MRI_LIB)" );
1143
 
1144
    } else {                                    # depend
1145
        $io->Cmd( "$dp:\t@(vlib2,$lib.$::a,MRI_LIB)" );
1146
    }
1147
}
1148
 
1149
package main;
1150
 
1151
###############################################################################
1152
#   ToolsetSHLDLINT $name, \@args, \@objs, \@libraries )
1153
#       This subroutine takes the user options and builds the rules
1154
#       required to lint the program 'name'.
1155
#
1156
#   Arguments:
1157
#       (none)
1158
#
1159
#   Output:
1160
#       [ $(LIBDIR)/$name_lint:   .... ]
1161
#           $(SHLIBLINT)
1162
#
1163
###############################################################################
1164
 
1165
sub ToolsetSHLDLINT
1166
{
1167
    PCLintSHLIB( @_ );
1168
}
1169
 
1170
 
1171
#.. Successful termination
1172
1;
1173