xref: /titanic_41/usr/src/cmd/sgs/libconv/common/bld_vernote.ksh (revision e521049d0fdbd76727f036cb77c99c98d7ee1125)
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#
24# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28usage()
29{
30	echo "usage: bld_vernote -R <revision> -r <release> -o <outfile.s>"
31}
32
33pad_notestring()
34{
35	extra=$1
36	len=$(( ${#notestring} + $extra ))
37	padlen=$(( $len % 4 ))
38	while [[ $(( $len % 4)) != 0 ]]
39	do
40		notestring="${notestring}\0"
41		len=$(( $len + 1 ))
42	done
43}
44
45
46build_sparcnote()
47{
48	notestring="Solaris Link Editors: $release-$revision (illumos)\0"
49	#
50	# The 'adjustment' is for the '\0'
51	#
52	pad_notestring -1
53
54cat > $notefile <<EOF
55	.section	".note"
56
57#include <sgs.h>
58
59	.align	4
60	.word	.endname - .startname	/* note name size */
61	.word	0			/* note desc size */
62	.word	0			/* note type */
63.startname:
64	.ascii	"$notestring"
65.endname:
66
67	.section	".rodata", #alloc
68	.global		link_ver_string
69link_ver_string:
70	.type		link_ver_string, #object
71	.ascii	"${release}-${revision} (illumos)\0"
72	.size	link_ver_string, .-link_ver_string
73EOF
74}
75
76build_i386note()
77{
78	notestring="Solaris Link Editors: $release-$revision (illumos)"
79	#
80	# The 'adjustment' is for the the fact that the x86/amd64
81	# assembler automatically append a '\0' at the end of a string.
82	#
83	pad_notestring -1
84cat > $notefile <<EOF
85	.section	.note
86
87#include <sgs.h>
88
89	.align	4
90	.long	.endname - .startname	/* note name size */
91	.long	0			/* note desc size */
92	.long	0			/* note type */
93.startname:
94	.string	"$notestring"
95.endname:
96
97	.section	.rodata, "a"
98	.globl		link_ver_string
99link_ver_string:
100	.type	link_ver_string,@object
101	.string	"${release}-${revision} (illumos)\0"
102	.size	link_ver_string, .-link_ver_string
103EOF
104}
105
106
107notefile=""
108release=""
109revision=""
110
111while getopts R:o:r: c
112do
113	case $c in
114	o)
115		notefile=$OPTARG
116		;;
117	r)
118		release=$OPTARG
119		;;
120	R)
121		revision=$OPTARG
122		;;
123	\?)
124		usage
125		exit 1
126		;;
127	esac
128done
129
130if [[ ( -z $notefile ) || ( -z $release ) || ( -z $revision ) ]]; then
131	usage
132	exit 1
133fi
134
135
136if [[ $MACH = "sparc" ]]; then
137	build_sparcnote
138elif [[ $MACH = "i386" ]]; then
139	build_i386note
140else
141	echo "I don't know how to build a vernote.s for ${MACH}, so sorry"
142	exit 1
143fi
144