Subversion Repositories DevTools

Rev

Rev 239 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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