Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Dec 2000 15:17:57 +1100
From:      Benno Rice <benno@FreeBSD.org>
To:        Marcel Moolenaar <marcel@cup.hp.com>
Cc:        arch@FreeBSD.org
Subject:   Re: A perlified gensetdefs
Message-ID:  <20001217151757.D73676@rafe.jeamland.net>
In-Reply-To: <20001217144036.A73676@rafe.jeamland.net>; from benno@FreeBSD.org on Sun, Dec 17, 2000 at 02:40:36PM %2B1100
References:  <3A3C0C70.848F5057@cup.hp.com> <20001217144036.A73676@rafe.jeamland.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--fUYQa+Pmc3FrFX/N
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Sun, Dec 17, 2000 at 02:40:36PM +1100, Benno Rice wrote:
> 
> I don't have that much objection to it, as it makes supporting big-endian
> architectures (eg, PowerPC =)) a fair bit easier.  I have however made
> the following changes to the script:
> 	* Turned on warnings and 'use strict', and made all changes to silence
> 	  the resultant warnings (mainly use of 'my' in more places).
> 	* Renamed some variables to make their purpose clearer.
> 	* Reworked a few blocks to make them easier to comprehend.
> 	* Added some comments.

Oops, and this time I actually attached the script.

-- 
Benno Rice
benno@FreeBSD.org

--fUYQa+Pmc3FrFX/N
Content-Type: application/x-perl
Content-Disposition: attachment; filename="gensetdefs.pl"

#!/usr/bin/perl -w

use strict;

my %sets = ();
my $pointersize = 0;
my $objdump = 'objdump';

# Allow objdump to be overridden by the environment.
if (defined $ENV{'OBJDUMP'}) {
    $objdump = $ENV{'OBJDUMP'};
}

# Run objdump over each object file to find all defined linker sets.
foreach my $objfile (@ARGV) {
    open(SECTION, "$objdump -h $objfile |");
    while(my $line = <SECTION>) {
        my ($index, $name, $size, $vma, $lma, $offset, $align) =
            split(" ", $line);

        next if not defined $name;

        if ($name =~ /^.set./) {
            # We've found a set.
            $name =~ s/^.set.//;

            # Initialise it if needed.
            if (not defined $sets{$name}) {
            	$sets{$name} = 0;
            }

            # Add the size of this entry.
            $sets{$name} = $sets{$name} + eval "0x$size";

            if ($pointersize < eval $align) {
            	$pointersize = eval $align;
            }
        }
    }
    close SECTION;
}

# Generate our list of set definitions
my @setdefs;
while (my ($name, $size) = each %sets) {
    my $elements = $size / $pointersize;
    push @setdefs, "DEFINE_SET($name, $elements);\n";
}

# Create setdefs.h
open(SETDEFS_H, "> setdefs.h");

foreach my $setdef (sort @setdefs) {
    print SETDEFS_H $setdef;
}

close SETDEFS_H;

# Create setdef0.c
open(SETDEF0_C, "> setdef0.c");

print SETDEF0_C <<END;
/* THIS FILE IS GENERATED, DO NOT EDIT. */

#define DEFINE_SET(set, count)			\\
__asm__(".section .set." #set ",\\"aw\\"");	\\
__asm__(".globl " #set);			\\
__asm__(".type " #set ",\@object");		\\
__asm__(".p2align 3");				\\
__asm__(#set ":");				\\
__asm__(".quad " #count);			\\
__asm__(".previous")

#include "setdefs.h"
END

close SETDEF0_C;

# Create setdef1.c
open(SETDEF1_C, "> setdef1.c");

print SETDEF1_C <<END;
/* THIS FILE IS GENERATED, DO NOT EDIT. */

#define DEFINE_SET(set, count)			\\
__asm__(".section .set." #set ",\\"aw\\"");	\\
__asm__(".quad 0");				\\
__asm__(".previous")

#include "setdefs.h"
END

close SETDEF1_C;

--fUYQa+Pmc3FrFX/N--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001217151757.D73676>