summaryrefslogtreecommitdiff
path: root/devel/cpuflags/files/subr_NetBSD
blob: 06cd26a0b107abcdbe0a44e1e452aed67996ab7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# $NetBSD: subr_NetBSD,v 1.8 2008/12/10 23:27:17 abs Exp $

AWK=awk
SED=sed

display_hw_details()
    {
    cat <<END
OS		: '$(uname)'
OS version	: '$(uname -r)'
hw.model	: '$hw_model'
hw.machine	: '$hw_machine'
hw.machine_arch : '$hw_machine_arch'
CPU		: '$cpu'
END
    extract_x86_cpu_vars
    echo "$cpu_details"
    }

extract_hw_details()
    {
    hw_model=$(sysctl -n hw.model | $SED 's/^  *//')
    hw_machine=$(sysctl -n hw.machine)
    hw_machine_arch=$(sysctl -n hw.machine_arch)
    if [ "$hw_machine_arch" = i386 -o "$hw_machine_arch" = x86_64 ] ; then
	if [ -x /usr/sbin/cpuctl ] ; then
	    cpu_details="$(cpuctl identify 0 | grep ^cpu0:)"
	else
	    cpu_details="$(grep ^cpu0: /var/run/dmesg.boot)"
	fi
	eval $(extract_x86_cpu_vars)
    fi

    # We're almost certainly crosscompiling
    if [ -n "$MACHINE" -a $hw_machine != "$MACHINE" ]; then
	echo
	exit
    fi
    }

extract_x86_cpu_vars()
    {
    # Set: cpu_feature_FOO=1 for each 'FOO' feature reported
    #      cpu_name="NAME" taken from the first cpu0: line
    #      cpu_brand="BRAND" the CPU branding string
    echo "$cpu_details" | $AWK -F , '
    { if (/cpu0:/ && !n) { sub("cpu0: ",""); n=1; print "cpu_name=\""$0"\"" } }
    /cpu0: ".*"/ { sub("[^\"]*", ""); print "cpu_brand="$0 }
    /cpu0: features/ {
	sub(".*<","");
	sub(">.*","");
	gsub("[^,A-Z0-9]","_");
	for (i = 1; i < NR; i++) { print "cpu_feature_"$i"=1" }
	}
    '
    }

determine_arch()
    {
    ARCH=
    # When adding $hw_model tests use maximum context (such as trailing space)
    case $hw_machine_arch in

    alpha)
	# cpu0 at mainbus0: ID 0 (primary), 21164A-0 (unknown ...
	case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
	    *[\(\ ]2106[46][-A\ \)]*)	ARCH="-mcpu=21064"	;;
	    *[\(\ ]21164[-\ \)]*)	ARCH="-mcpu=21164"	;;
	    *[\(\ ]21164A[-\ \)]*)	ARCH="-mcpu=21164a"	;;
	    *[\(\ ]21264[-\ \)]*)	ARCH="-mcpu=21264"	;;
	    *[\(\ ]21264[AB][-\ \)]*)	ARCH="-mcpu=21264a"	;;
	    *\ PCA56-2)			ARCH="-mcpu=21164pc"	;;
	esac
	;;

    arm | arm32) case $hw_model in
	ARM610*)		ARCH="-mcpu=arm610"		;; # risc pc
	ARM710*)		ARCH="-mcpu=arm710"		;; # risc pc
	i80321\ *)		ARCH="-mcpu=xscale"		;; # iyonix
	SA-110*)	
	    case $hw_machine in			 # arm32 split post 1.5
		cats|shark|hpcarm|netwinder)
		    ARCH="-mcpu=strongarm110" ;;
		acorn32)
		    ARCH="-march=armv3m -mtune=strongarm" ;;
		*)
		    # memorybus in strongarm risc pc machines cannot support
		    # certain strongarm instructions, but in 1.5 and earlier
		    # all strongarm machines are 'arm32', so uname and sysctl
		    # no use
		    if egrep -q 'ofbus0|footbridge0' /var/run/dmesg.boot \
							    2>/dev/null ; then
			ARCH="-mcpu=strongarm110"		   # shark/cats
		    else
			ARCH="-march=armv3m -mtune=strongarm"	   # risc pc
		    fi
	    esac ;;
	esac ;;

    hppa)
	case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
	   *\ PA7100\ *)       ARCH="-march=1.1 -mschedule=7100" ;; # untested
	   *\ PA7150\ *)       ARCH="-march=1.1 -mschedule=7100" ;; # untested
	   *\ PA7100LC\ *)     ARCH="-march=1.1 -mschedule=7100LC" ;; # untested
	   *\ PA7200\ *)       ARCH="-march=1.1 -mschedule=7200" ;; # untested
	   *\ PA7300LC\ *)     ARCH="-march=1.1 -mschedule=7300" ;; # B180L
	   *\ PA8*)	       ARCH="-march=2.0 -mschedule=8000" ;; # untested
	esac
	;;

    i386 | x86_64)
	include subr_x86	# this provides map_x86_brand_string()
	ARCH=$(map_x86_brand_string "$cpu_brand")
	if [ -z "$ARCH" ] ; then
	case "$cpu_name" in
	'AMD Athlon 64 X2 (686-class)'*)	   ARCH='-march=athlon64' ;;
	'AMD Athlon 64 or Athlon 64 FX or Opteron '*) ARCH='-march=opteron' ;;
	'AMD Athlon 64 or Sempron (686-class)'*)   ARCH='-march=athlon64' ;;
	'AMD Athlon Model 4 (Thunderbird) '*)	   ARCH='-march=athlon-tbird' ;;
	'AMD Dual-Core Opteron or Athlon 64 X2 '*) ARCH='-march=opteron' ;;
	'AMD Family 10h (686-class)'*)   	   ARCH='-march=amdfam10' ;;
	'AMD K6-2 (586-class)'*) 		   ARCH="-march=k6-2" ;;

	# Intel PIII & earlier - later Intel handled by map_x86_brand_string
	'Intel (686-class)'*)			   ARCH='-march=pentiumpro' ;;
	'Intel Pentium II (686-class)'*)	   ARCH='-march=pentium2' ;;
	'Intel Pentium III (686-class)'*)	   ARCH='-march=pentium3' ;;
	'Intel Pentium III (Katmai) (686-class)'*) ARCH='-march=pentium3' ;;
	'Intel Pentium III Xeon (686-class)'*)	   ARCH='-march=pentium3' ;;

	# Fallback classes
	*'(586-class)'*)			   ARCH='-march=pentium' ;;
	*'(486-class)'*)			   ARCH='-march=i486' ;;
	esac
	fi
	;;

    m68k) case $hw_model in				   # Examples
	*\(68020*|*\ MC68020\ *) ARCH='-m68020' ;; # Untested
	*\(68030*|*\ MC68030\ *) ARCH='-m68030' ;; # Mac LC III
	*\(68040*|*\ MC68040\ *) ARCH='-m68040' ;; # Untested
	*\(68060*|*\ MC68060\ *) ARCH='-m68060' ;; # Upgraded amiga 3000
    esac
    ;;

    mipseb|mipsel)
	# cpu0 at mainbus0: QED R4600 Orion CPU (0x2020) Rev. 2.0 with ...
	case $hw_model in
	    Infineon\ ADM5120)		ARCH='-march=4kc' ;;
	    *)
	    case "$(egrep '^cpu0 ' /var/run/dmesg.boot)" in
		*\ MIPS\ R2000\ *)	ARCH="-march=r2000" ;;
		*\ MIPS\ R3000\ *)	ARCH="-march=r3000" ;;
		*\ MIPS\ R3000A\ *)	ARCH="-march=r3000" ;;
		*\ Toshiba\ TX3912\ *)	ARCH="-march=r3900" ;;
		*\ Toshiba\ TX392[27]\ *) ARCH="-march=r3900" ;;
		*\ MIPS\ R4000\ *)	ARCH="-mtune=r4000 -mips2" ;; # mips3
		*\ MIPS\ R4400\ *)	ARCH="-mtune=r4400 -mips2" ;; # mips3
		*\ NEC\ VR4100\ *)	ARCH="-mtune=r4100 -mips2" ;; # mips3
		*\ NEC\ VR4300\ *)	ARCH="-mtune=r4300 -mips2" ;; # mips3
		*\ QED\ R4600\ *)	ARCH="-mtune=r4600 -mips2" ;; # mips3
		*\ MIPS\ R5000\ *)	ARCH="-mtune=r5000 -mips2" ;; # mips4
		*\ QED\ RM5200\ *)	ARCH="-mtune=r5000 -mips2" ;; # mips4
		*\ MIPS\ R6000\ *)	ARCH="-mtune=r6000 -mips2" ;;
		*\ MIPS\ R8000\ *)	ARCH="-mtune=r8000 -mips2" ;; # mips4
		*\ MIPS\ R10000\ *)	ARCH="-march=mips4 -mabi=32" ;; # mips4
	    esac ;;
	esac
	;;

    powerpc) case $hw_model in				   # Examples
	601\ *)			ARCH='-mcpu=601'	;; # Untested
	602\ *)			ARCH='-mcpu=602'	;; # Untested
	603\ *)			ARCH='-mcpu=603'	;; # Untested
	603e\ *|603ev\ *)	ARCH='-mcpu=603e'	;; # Umax C500 / PM4400
	604\ *)			ARCH='-mcpu=604'	;; # Mac 8500
	604e\ *)		ARCH='-mcpu=604e'	;; # upgr B&W G3
	604ev\ *)		ARCH='-mcpu=604e'	;; # usually 604e
	620\ *)			ARCH='-mcpu=620'	;; # Untested
	7400\ *)		ARCH='-mcpu=7400'	;; # AGP G4/400 Mac
	740\ *)			ARCH='-mcpu=740'	;; # Untested
	7410\ *)		ARCH='-mcpu=7400'	;; # powerbook g4
	7447A\ *)		ARCH='-mcpu=7450'	;; #
	7450\ *)		ARCH='-mcpu=7450'	;; # tibook 550
	750\ *)		       ARCH='-mcpu=750'	      ;; # orig. iBook

    esac ;;

    sparc | sparc64) case " $hw_model" in			   # Examples
	*[\ \(]MB86900/1A*)	ARCH='-mcpu=cypress'		;; # ss1+
	*[\ \(]L64811*)		ARCH='-mcpu=cypress'		;; # sun4/sun4c
	*[\ \(]CY7C601*)	ARCH='-mcpu=cypress'		;; # ss2
	*[\ \(]W8601/8701*)	ARCH='-mcpu=cypress'		;; # elc
	*[\ \(]MB86904*)	ARCH='-mcpu=supersparc' ;; # ss5 usparc
	*[\ \(]MB86907*)	ARCH='-mcpu=supersparc' ;; # ss5 usparc
	*[\ \(]TMS390S10*)	ARCH='-mcpu=supersparc' ;; # classic  "
	*[\ \(]TMS390Z50*)	ARCH='-mcpu=supersparc' ;; # ss10/ss20
	*[\ \(]RT620/625*)	ARCH='-mcpu=hypersparc' ;; # ss20 ross
	*[\ \(]MB86930*)	ARCH='-mcpu=sparclite'		;; # from gcc
	*[\ \(]MB86934*)	ARCH='-mcpu=sparclite'		;; # from gcc
	# under 1.5.1 -mcpu=ultrasparc chokes egcs-2.91.66 compiling perl
	*[\ \(]SUNW,UltraSPARC*) ARCH='-mcpu=v9'		;; # Ultra
    esac ;;

    vax) # No VAX specific gcc optimisations available
	NOARCH=1
	;;

    esac
    echo $ARCH
    }

determine_features()
    {
    FEATURES=

    case $hw_machine_arch in
	i386 | x86_64)
	    if [ -n "$cpu_feature_SSE3" ] ; then
		FEATURES="-mfpmath=sse -msse3"
	    elif [ -n "$cpu_feature_SSE2" ] ; then
		FEATURES="-mfpmath=sse -msse2"
	    elif [ -n "$cpu_feature_SSE" ] ; then
		FEATURES="-mfpmath=sse -msse"
	    fi
	    ;;
	m68k)
	    case "$(egrep '^fpu0 ' /var/run/dmesg.boot)" in
		*\(emulator\)*)		FEATURES="-msoft-float" ;;
		*\(no\ math\ support\)*) FEATURES="-msoft-float" ;;
	    esac
	    ;;
    esac
    echo $FEATURES
    }