xref: /freebsd/contrib/ntp/html/hints/solaris.xtra.patchfreq (revision 416ba5c74546f32a993436a99516d35008e9f384)
1*2b15cb3dSCy Schubert#!/bin/ksh
2*2b15cb3dSCy Schubert
3*2b15cb3dSCy Schubert#
4*2b15cb3dSCy Schubert# File:         patchfreq
5*2b15cb3dSCy Schubert# Author:       Bryan Cantrill (bmc@eng.sun.com), Solaris Performance
6*2b15cb3dSCy Schubert# Modified:     Sat Apr 26 04:00:59 PDT 1997
7*2b15cb3dSCy Schubert#
8*2b15cb3dSCy Schubert# This is a little script to patch a 5.5 or 5.5.1 kernel to get around
9*2b15cb3dSCy Schubert# the cpu_tick_freq inaccuracy.  Before running this script, one must
10*2b15cb3dSCy Schubert# know the true frequency of one's CPU;  this can be derived by NTP,
11*2b15cb3dSCy Schubert# or by observing the clock relative to the time-of-day chip over a
12*2b15cb3dSCy Schubert# long period of time (the TOD will pull system time when it drifts
13*2b15cb3dSCy Schubert# by more than two seconds).
14*2b15cb3dSCy Schubert#
15*2b15cb3dSCy Schubert# Patching a kernel can render a machine unbootable;  do not run this
16*2b15cb3dSCy Schubert# script unless you are prepared to accept that possibility.  It
17*2b15cb3dSCy Schubert# is advisable to have a backout path (e.g. net booting, an alternate
18*2b15cb3dSCy Schubert# boot disk, an installation CD) should your machine fail to boot.
19*2b15cb3dSCy Schubert#
20*2b15cb3dSCy Schubert# This is not a product of Sun Microsystems, and is provided "as is",
21*2b15cb3dSCy Schubert# without warranty of any kind expressed or implied including, but not
22*2b15cb3dSCy Schubert# limited to, the suitability of this script for any purpose.
23*2b15cb3dSCy Schubert#
24*2b15cb3dSCy Schubert
25*2b15cb3dSCy Schubertif [ $# -eq 0 ]; then
26*2b15cb3dSCy Schubert        echo "Usage:  $0 cpu_tick_freq [ alternate_kernel ]"
27*2b15cb3dSCy Schubert        exit 1
28*2b15cb3dSCy Schubertfi
29*2b15cb3dSCy Schubert
30*2b15cb3dSCy Schubertcpu_tick_freq=$1
31*2b15cb3dSCy Schubertkernel=/platform/sun4u/kernel/unix
32*2b15cb3dSCy Schubert
33*2b15cb3dSCy Schubertif [ $# -eq 2 ]; then
34*2b15cb3dSCy Schubert        kernel=$2
35*2b15cb3dSCy Schubertfi
36*2b15cb3dSCy Schubert
37*2b15cb3dSCy Schubertif [ ! -w $kernel ]; then
38*2b15cb3dSCy Schubert        echo "$0:  Cannot open $kernel for writing."
39*2b15cb3dSCy Schubert        exit 1
40*2b15cb3dSCy Schubertfi
41*2b15cb3dSCy Schubert
42*2b15cb3dSCy Schubertarch=`echo utsname+404?s | adb $kernel | cut -d: -f2`
43*2b15cb3dSCy Schubert
44*2b15cb3dSCy Schubertif [ ! $arch = "sun4u" ]; then
45*2b15cb3dSCy Schubert        echo "Patch only applies to sun4u"
46*2b15cb3dSCy Schubert        exit 1
47*2b15cb3dSCy Schubertfi
48*2b15cb3dSCy Schubert
49*2b15cb3dSCy Schubertrel=`echo utsname+202?s | adb $kernel | cut -d: -f2`
50*2b15cb3dSCy Schubert
51*2b15cb3dSCy Schubertif [ ! $rel = "5.5" ] && [ ! $rel = "5.5.1" ]; then
52*2b15cb3dSCy Schubert        echo "Patch only applies to 5.5 or 5.5.1..."
53*2b15cb3dSCy Schubert        exit 1
54*2b15cb3dSCy Schubertfi
55*2b15cb3dSCy Schubert
56*2b15cb3dSCy Schubertnop="1000000"           # nop
57*2b15cb3dSCy Schubertstore_mask="ffffe000"   # mask out low 13 bits
58*2b15cb3dSCy Schubertstore="da256000"        # st      %o5, [%l5 + offset]
59*2b15cb3dSCy Schubert
60*2b15cb3dSCy Schubertinstr=`echo setcpudelay+34?X | adb $kernel | cut -d: -f 2 | nawk '{ print $1 }'`
61*2b15cb3dSCy Schubert
62*2b15cb3dSCy Schubertif [ $instr = $nop ]; then
63*2b15cb3dSCy Schubert        echo "Instruction already patched..."
64*2b15cb3dSCy Schubertelse
65*2b15cb3dSCy Schubert        let masked="(16#$store_mask & 16#$instr) - 16#$store"
66*2b15cb3dSCy Schubert        if [ $masked -ne 0 ]; then
67*2b15cb3dSCy Schubert                echo "Couldn't find instruction to patch;  aborting."
68*2b15cb3dSCy Schubert                exit 1
69*2b15cb3dSCy Schubert        fi
70*2b15cb3dSCy Schubert
71*2b15cb3dSCy Schubert        if ! echo setcpudelay+34?W $nop | adb -w $kernel 1> /dev/null
72*2b15cb3dSCy Schubert        then
73*2b15cb3dSCy Schubert                echo "adb returned an unexpected error;  aborting."
74*2b15cb3dSCy Schubert        fi
75*2b15cb3dSCy Schubertfi
76*2b15cb3dSCy Schubert
77*2b15cb3dSCy Schubertecho "Patching cpu_tick_freq to $cpu_tick_freq..."
78*2b15cb3dSCy Schubert
79*2b15cb3dSCy Schubertif ! echo cpu_tick_freq?W 0t$cpu_tick_freq | adb -w $kernel 1> /dev/null; then
80*2b15cb3dSCy Schubert        echo "adb returned an unexpected error;  aborting."
81*2b15cb3dSCy Schubert        exit 1
82*2b15cb3dSCy Schubertfi
83*2b15cb3dSCy Schubert
84*2b15cb3dSCy Schubertecho "$kernel successfully patched."
85*2b15cb3dSCy Schubertexit 0
86