Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / bin / bin2obj
CommitLineData
920dae64
AT
1#!/bin/sh
2# ========== Copyright Header Begin ==========================================
3#
4# Hypervisor Software File: bin2obj
5#
6# Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
7#
8# - Do no alter or remove copyright notices
9#
10# - Redistribution and use of this software in source and binary forms, with
11# or without modification, are permitted provided that the following
12# conditions are met:
13#
14# - Redistribution of source code must retain the above copyright notice,
15# this list of conditions and the following disclaimer.
16#
17# - Redistribution in binary form must reproduce the above copyright notice,
18# this list of conditions and the following disclaimer in the
19# documentation and/or other materials provided with the distribution.
20#
21# Neither the name of Sun Microsystems, Inc. or the names of contributors
22# may be used to endorse or promote products derived from this software
23# without specific prior written permission.
24#
25# This software is provided "AS IS," without a warranty of any kind.
26# ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
27# INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
28# PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
29# MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
30# ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
31# DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
32# OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
33# FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
34# DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
35# ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
36# SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
37#
38# You acknowledge that this software is not designed, licensed or
39# intended for use in the design, construction, operation or maintenance of
40# any nuclear facility.
41#
42# ========== Copyright Header End ============================================
43# id: @(#)bin2obj.sh 1.7 03/04/01
44# purpose: Convert a binary file into native object ( .o ) file
45# Copyright 1992-1997,2003 Sun Microsystems, Inc. All Rights Reserved
46# Use is subject to license terms.
47
48#
49# Usage: bin2obj symbol-name input-file output-file
50#
51
52usage() {
53 echo Usage: bin2obj [ -start ssymbol ] [ -end esymbol ] [ -64 ] \
54 input-file output-file
55 exit 1;
56}
57
58add_symbol() {
59cat << END >> $TMP
60.seg "data"
61.global $1,
62$1:
63END
64 if [ -x /usr/ccs/bin/as ]
65 then
66 cat << END >> $TMP
67.type $1, #object; .size $1, 1
68END
69 fi
70}
71
72cleanup() {
73 $RM -f $TMP
74}
75
76trap cleanup 1 2 3 10
77
78if test $# -lt 2
79 then
80 usage
81fi
82
83
84while [ x"$1" != x"" ]
85do
86case $1 in
87 -end)
88 shift
89 ENDSYM=$1
90 shift
91 ;;
92 -start)
93 shift
94 STARTSYM=$1
95 shift
96 ;;
97 -64)
98 ASARG="-xarch=v9"
99 shift
100 ;;
101 *)
102 if [ "$infile" = "" ] ;
103 then
104 infile=$1;
105 shift
106 else
107 if [ "$outfile" = "" ] ;
108 then
109 outfile=$1
110 shift
111 else
112 usage
113 fi
114 fi
115 ;;
116esac
117done
118
119if [ ! -f $infile ] ;
120then
121 echo Can\'t open input file: $infile
122 exit 1;
123fi
124
125RM=/usr/bin/rm
126AS=/usr/bin/as
127OD=/usr/bin/od
128AWK=/usr/bin/awk
129
130# On Solaris 2.x assembler is in /usr/ccs/bin
131if [ -x /usr/ccs/bin/as ]
132then
133 AS=/usr/ccs/bin/as
134fi
135
136TMP=/tmp/$$.s
137
138$RM -f $TMP
139
140if [ "$STARTSYM" != "" ] ;
141then
142 add_symbol $STARTSYM
143fi
144
145$OD -Xv $infile | $AWK '{ if ( NF == 5 ) \
146{ printf ".word 0x%s, 0x%s, 0x%s, 0x%s\n", $2, $3, $4, $5 ;} \
147else { for ( i = 2 ; i <= NF; i++ ) \
148{ printf ".word 0x%s\n", $i ; } }}' >> $TMP
149
150if [ "$ENDSYM" != "" ] ;
151then
152 add_symbol $ENDSYM
153fi
154
155$AS $ASARG $TMP -o $outfile
156
157cleanup
158