xref: /titanic_52/usr/src/cmd/sgs/libconv/common/bld_vernote.ksh (revision 4201a95e0468170d576f82c3aa63afecf718497a)
1#! /usr/bin/ksh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# ident	"%Z%%M%	%I%	%E% SMI"
24#
25# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
26# Use is subject to license terms.
27#
28
29usage()
30{
31	echo "usage: bld_vernote -R <revision> -r <release> -o <outfile.s>"
32}
33
34pad_notestring()
35{
36	extra=$1
37	len=$(( ${#notestring} + $extra ))
38	padlen=$(( $len % 4 ))
39	while [[ $(( $len % 4)) != 0 ]]
40	do
41		notestring="${notestring}\0"
42		len=$(( $len + 1 ))
43	done
44}
45
46
47build_sparcnote()
48{
49	notestring="Solaris Link Editors: $release-$revision\0"
50	#
51	# The 'adjustment' is for the '\0'
52	#
53	pad_notestring -1
54
55cat > $notefile <<EOF
56	.section	".note"
57
58#include <sgs.h>
59
60	.align	4
61	.word	.endname - .startname	/* note name size */
62	.word	0			/* note desc size */
63	.word	0			/* note type */
64.startname:
65	.ascii	"$notestring"
66.endname:
67
68	.section	".rodata", #alloc
69	.global		link_ver_string
70link_ver_string:
71	.type		link_ver_string, #object
72	.ascii	"${release}-${revision}\0"
73	.size	link_ver_string, .-link_ver_string
74EOF
75}
76
77build_i386note()
78{
79	notestring="Solaris Link Editors: $release-$revision"
80	#
81	# The 'adjustment' is for the the fact that the x86/amd64
82	# assembler automatically append a '\0' at the end of a string.
83	#
84	pad_notestring -1
85cat > $notefile <<EOF
86	.section	.note
87
88#include <sgs.h>
89
90	.align	4
91	.long	.endname - .startname	/* note name size */
92	.long	0			/* note desc size */
93	.long	0			/* note type */
94.startname:
95	.string	"$notestring"
96.endname:
97
98	.section	.rodata, "a"
99	.globl		link_ver_string
100link_ver_string:
101	.type	link_ver_string,@object
102	.string	"${release}-${revision}\0"
103	.size	link_ver_string, .-link_ver_string
104EOF
105}
106
107
108notefile=""
109release=""
110revision=""
111
112while getopts DR:o:r: c
113do
114	case $c in
115	o)
116		notefile=$OPTARG
117		;;
118	r)
119		release=$OPTARG
120		;;
121	R)
122		revision=$OPTARG
123		;;
124	\?)
125		usage
126		exit 1
127		;;
128	esac
129done
130
131if [[ ( -z $notefile ) || ( -z $release ) || ( -z $revision ) ]]; then
132	usage
133	exit 1
134fi
135
136
137if [[ $MACH = "sparc" ]]; then
138	build_sparcnote
139elif [[ $MACH = "i386" ]]; then
140	build_i386note
141else
142	echo "I don't know how to build a vernote.s for ${MACH}, so sorry"
143	exit 1
144fi
145