diff --git a/sys/arch/mips/mips/mips_mcclock.c b/sys/arch/mips/mips/mips_mcclock.c index 4ca29fe92568..373ec2c065d4 100644 --- a/sys/arch/mips/mips/mips_mcclock.c +++ b/sys/arch/mips/mips/mips_mcclock.c @@ -1,4 +1,4 @@ -/* $NetBSD: mips_mcclock.c,v 1.11 2002/03/05 15:54:33 simonb Exp $ */ +/* $NetBSD: mips_mcclock.c,v 1.12 2005/01/01 09:48:39 simonb Exp $ */ /* * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author) @@ -34,7 +34,7 @@ #include /* RCS ID & Copyright macro defns */ -__KERNEL_RCSID(0, "$NetBSD: mips_mcclock.c,v 1.11 2002/03/05 15:54:33 simonb Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mips_mcclock.c,v 1.12 2005/01/01 09:48:39 simonb Exp $"); #include #include @@ -146,7 +146,7 @@ mips_mcclock_tickloop(mcclock_addr, clockmask) void *mcclock_addr; int clockmask; { - int iters = 0; + int iters; volatile int junk; volatile struct mcclock_pad32_clockdatum *clk = mcclock_addr; @@ -164,19 +164,12 @@ mips_mcclock_tickloop(mcclock_addr, clockmask) junk++; junk++; junk++; junk++; /* Count loops until next tick-interrupt request occurs (4ms). */ - if (MIPS_HAS_CLOCK) { - while ((mips_cp0_cause_read() & clockmask) == 0) { - __asm __volatile ("nop; nop; nop; nop"); - iters++; - } - } else { - while ((mips_cp0_cause_read() & clockmask) == 0) { - __asm __volatile ("nop; nop;"); - iters++; - } - } + if (MIPS_HAS_CLOCK) + iters = mips_mcclock_loop_with_clock(clockmask); + else + iters = mips_mcclock_loop_without_clock(clockmask); - /* Ack the interrupt from the just-gone-off tick */ + /* Ack the interrupt from the just-gone-off tick */ junk = clk[MC_REGC].datum; return (iters); diff --git a/sys/arch/mips/mips/mips_mcclock.h b/sys/arch/mips/mips/mips_mcclock.h index 19d6950a079a..a4117ed7ed96 100644 --- a/sys/arch/mips/mips/mips_mcclock.h +++ b/sys/arch/mips/mips/mips_mcclock.h @@ -1,4 +1,4 @@ -/* $NetBSD: mips_mcclock.h,v 1.3 2002/03/05 14:12:30 simonb Exp $ */ +/* $NetBSD: mips_mcclock.h,v 1.4 2005/01/01 09:48:39 simonb Exp $ */ /* * Copyright (c) 1997 Jonathan Stone (hereinafter referred to as the author) @@ -40,10 +40,11 @@ * counting iterations of an loop between successive ticks. */ unsigned mc_cpuspeed(vaddr_t, int); +int mips_mcclock_loop_with_clock(int); +int mips_mcclock_loop_without_clock(int); /* * CPU speed in MHz, as estimated by mc_cpuspeed(). Read-only. */ extern int cpu_mhz; - #endif diff --git a/sys/arch/mips/mips/mips_mcclock_loop.S b/sys/arch/mips/mips/mips_mcclock_loop.S new file mode 100644 index 000000000000..5b483a6ce7a2 --- /dev/null +++ b/sys/arch/mips/mips/mips_mcclock_loop.S @@ -0,0 +1,102 @@ +/* $NetBSD: mips_mcclock_loop.S,v 1.1 2005/01/01 09:48:39 simonb Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Simon Burge. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + + .set noreorder + +/* + * Provide assembly versions of the clock timing calculation loops that + * aren't effected by changes in compiler optimisation. + * + * These two functions are not profiled! + */ + + +LEAF_NOPROFILE(mips_mcclock_loop_with_clock) + subu sp, CALLFRAME_SIZ + sw s0, 0(sp) + sw ra, CALLFRAME_RA(sp) + j 2f + move s0, zero # iters = 0; +1: + .set push + .set mips32 + ssnop # asm ("ssnop;ssnop;ssnop;ssnop"); + ssnop + ssnop + ssnop + .set pop + + addu s0, 1 # iters++; +2: jal mips_cp0_cause_read # v0 = mips_cp0_cause_read(); + nop + and v0, a0 # v0 &= clockmask; + beqz v0, 1b # if zero then repeat + move v0, s0 # return iters + lw ra, CALLFRAME_RA(sp) + lw s0, 0(sp) + j ra + addu sp, CALLFRAME_SIZ +END(mips_mcclock_loop_with_clock) + +LEAF_NOPROFILE(mips_mcclock_loop_without_clock) + subu sp, CALLFRAME_SIZ + sw s0, 0(sp) + sw ra, CALLFRAME_RA(sp) + j 2f + move s0, zero # iters = 0; +1: + .set push + .set mips32 + ssnop # asm ("ssnop;ssnop"); + ssnop + .set pop + + addu s0, 1 # iters++; +2: jal mips_cp0_cause_read # v0 = mips_cp0_cause_read(); + nop + and v0, a0 # v0 &= clockmask; + beqz v0, 1b # if zero then repeat + move v0, s0 # return iters + lw ra, CALLFRAME_RA(sp) + lw s0, 0(sp) + j ra + addu sp, CALLFRAME_SIZ +END(mips_mcclock_loop_without_clock) diff --git a/sys/arch/pmax/conf/files.pmax b/sys/arch/pmax/conf/files.pmax index 7cc2daadde27..51e8e1b6562d 100644 --- a/sys/arch/pmax/conf/files.pmax +++ b/sys/arch/pmax/conf/files.pmax @@ -1,4 +1,4 @@ -# $NetBSD: files.pmax,v 1.107 2003/12/13 23:04:37 ad Exp $ +# $NetBSD: files.pmax,v 1.108 2005/01/01 09:48:39 simonb Exp $ # DECstation-specific configuration info # maxpartitions must be first item in files.${ARCH}. @@ -81,11 +81,12 @@ device mcclock attach mcclock at ioasic with mcclock_ioasic attach mcclock at ibus with mcclock_ibus file arch/pmax/pmax/clock.c -file dev/dec/mcclock.c mcclock -file dev/dec/mcclock_pad32.c mcclock -file arch/pmax/tc/mcclock_ioasic.c mcclock_ioasic -file arch/pmax/ibus/mcclock_ibus.c mcclock_ibus -file arch/mips/mips/mips_mcclock.c mcclock # CPU speed via mcclock +file dev/dec/mcclock.c mcclock +file dev/dec/mcclock_pad32.c mcclock +file arch/pmax/tc/mcclock_ioasic.c mcclock_ioasic +file arch/pmax/ibus/mcclock_ibus.c mcclock_ibus +file arch/mips/mips/mips_mcclock.c mcclock # CPU speed via mcclock +file arch/mips/mips/mips_mcclock_loop.S mcclock # CPU speed via mcclock include "dev/scsipi/files.scsipi"