Module Name: src
Committed By: nakayama
Date: Sat May 16 19:15:34 UTC 2009
Modified Files:
src/sys/arch/sparc64/include: cpu.h cpu_counter.h ctlreg.h psl.h
src/sys/arch/sparc64/sparc64: clock.c ipifuncs.c trap.c
Log Message:
- move definition of tick() from ctlreg.h to psl.h and rename to gettick()
for consistency with other functions for reading/writing ASRs.
- move definition of tl() from trap.c to psl.h as same as above.
- define settick() in psl.h and use it in clock.c.
- cosmetic chages in psl.h.
To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/sparc64/include/cpu.h
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/sparc64/include/cpu_counter.h
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/sparc64/include/ctlreg.h
cvs rdiff -u -r1.40 -r1.41 src/sys/arch/sparc64/include/psl.h
cvs rdiff -u -r1.99 -r1.100 src/sys/arch/sparc64/sparc64/clock.c
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/sparc64/sparc64/ipifuncs.c
cvs rdiff -u -r1.156 -r1.157 src/sys/arch/sparc64/sparc64/trap.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/sparc64/include/cpu.h
diff -u src/sys/arch/sparc64/include/cpu.h:1.84 src/sys/arch/sparc64/include/cpu.h:1.85
--- src/sys/arch/sparc64/include/cpu.h:1.84 Sun Oct 5 01:53:05 2008
+++ src/sys/arch/sparc64/include/cpu.h Sat May 16 19:15:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.84 2008/10/05 01:53:05 nakayama Exp $ */
+/* $NetBSD: cpu.h,v 1.85 2009/05/16 19:15:34 nakayama Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -343,6 +343,7 @@
void snapshot(struct pcb *);
struct frame *getfp(void);
void switchtoctx(int);
+void next_tick(long);
/* trap.c */
void kill_user_windows(struct lwp *);
int rwindow_save(struct lwp *);
Index: src/sys/arch/sparc64/include/cpu_counter.h
diff -u src/sys/arch/sparc64/include/cpu_counter.h:1.7 src/sys/arch/sparc64/include/cpu_counter.h:1.8
--- src/sys/arch/sparc64/include/cpu_counter.h:1.7 Mon Apr 28 20:23:37 2008
+++ src/sys/arch/sparc64/include/cpu_counter.h Sat May 16 19:15:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_counter.h,v 1.7 2008/04/28 20:23:37 martin Exp $ */
+/* $NetBSD: cpu_counter.h,v 1.8 2009/05/16 19:15:34 nakayama Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -39,7 +39,6 @@
#ifdef _KERNEL
#include <machine/cpu.h>
-#include <machine/ctlreg.h>
#define cpu_hascounter() (1)
@@ -47,14 +46,14 @@
cpu_counter(void)
{
- return (tick());
+ return (gettick());
}
static __inline uint32_t
cpu_counter32(void)
{
- return (tick() & 0xffffffffUL);
+ return (gettick() & 0xffffffffUL);
}
static __inline uint64_t
Index: src/sys/arch/sparc64/include/ctlreg.h
diff -u src/sys/arch/sparc64/include/ctlreg.h:1.44 src/sys/arch/sparc64/include/ctlreg.h:1.45
--- src/sys/arch/sparc64/include/ctlreg.h:1.44 Sat Mar 31 13:04:21 2007
+++ src/sys/arch/sparc64/include/ctlreg.h Sat May 16 19:15:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: ctlreg.h,v 1.44 2007/03/31 13:04:21 hannken Exp $ */
+/* $NetBSD: ctlreg.h,v 1.45 2009/05/16 19:15:34 nakayama Exp $ */
/*
* Copyright (c) 1996-2002 Eduardo Horvath
@@ -1159,24 +1159,6 @@
#define membar_load() __asm volatile("membar #LoadLoad | #LoadStore" : :)
#define membar_store() __asm volatile("membar #LoadStore | #StoreStore" : :)
-#ifdef __arch64__
-/* read 64-bit %tick register */
-#define tick() ({ \
- register u_long _tick_tmp; \
- __asm volatile("rdpr %%tick, %0" : "=r" (_tick_tmp) :); \
- _tick_tmp; \
-})
-#else
-/* read 64-bit %tick register on 32-bit system */
-#define tick() ({ \
- register u_int _tick_hi = 0, _tick_lo = 0; \
- __asm volatile("rdpr %%tick, %0; srl %0,0,%1; srlx %0,32,%0 " \
- : "=r" (_tick_hi), "=r" (_tick_lo) : ); \
- (((uint64_t)_tick_hi)<<32)|((uint64_t)_tick_lo); \
-})
-#endif
-
-extern void next_tick(long);
#endif
#endif /* _SPARC_CTLREG_H_ */
Index: src/sys/arch/sparc64/include/psl.h
diff -u src/sys/arch/sparc64/include/psl.h:1.40 src/sys/arch/sparc64/include/psl.h:1.41
--- src/sys/arch/sparc64/include/psl.h:1.40 Sun Mar 2 15:07:02 2008
+++ src/sys/arch/sparc64/include/psl.h Sat May 16 19:15:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: psl.h,v 1.40 2008/03/02 15:07:02 nakayama Exp $ */
+/* $NetBSD: psl.h,v 1.41 2009/05/16 19:15:34 nakayama Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -251,13 +251,44 @@
/*
* Inlines for manipulating privileged registers
*/
+static __inline uint64_t
+gettick(void)
+{
+#ifdef __arch64__
+ uint64_t tick;
+
+ __asm volatile("rdpr %%tick, %0" : "=r" (tick));
+ return tick;
+#else
+ uint32_t tick_hi, tick_lo;
+
+ __asm volatile("rdpr %%tick, %0; srl %0,0,%1; srlx %0,32,%0"
+ : "=r" (tick_hi), "=r" (tick_lo));
+ return ((uint64_t)tick_hi << 32) | tick_lo;
+#endif
+}
+
+static __inline void
+settick(uint64_t newtick)
+{
+#ifdef __arch64__
+ __asm volatile("wrpr %0, 0, %%tick" : : "r" (newtick) : "memory");
+#else
+ uint32_t tick_hi = newtick >> 32, tick_lo = newtick;
+
+ __asm volatile("sllx %1,32,%0; or %0,%2,%0; wrpr %0, 0, %%tick"
+ : "=&r" (tick_hi) /* scratch register */
+ : "r" (tick_hi), "r" (tick_lo) : "memory");
+#endif
+}
+
static __inline int
getpstate(void)
{
int pstate;
__asm volatile("rdpr %%pstate,%0" : "=r" (pstate));
- return (pstate);
+ return pstate;
}
static __inline void
@@ -267,12 +298,21 @@
}
static __inline int
+gettl(void)
+{
+ int tl;
+
+ __asm volatile("rdpr %%tl, %0" : "=r" (tl));
+ return tl;
+}
+
+static __inline int
getcwp(void)
{
int cwp;
__asm volatile("rdpr %%cwp,%0" : "=r" (cwp));
- return (cwp);
+ return cwp;
}
static __inline void
@@ -284,10 +324,18 @@
static __inline uint64_t
getver(void)
{
+#ifdef __arch64__
uint64_t ver;
__asm volatile("rdpr %%ver,%0" : "=r" (ver));
- return (ver);
+ return ver;
+#else
+ uint32_t ver_hi, ver_lo;
+
+ __asm volatile("rdpr %%ver,%0; srl %0,0,%1; srlx %0,32,%0"
+ : "=r" (ver_hi), "=r" (ver_lo));
+ return (uint64_t)ver_hi << 32 | ver_lo;
+#endif
}
static __inline int
@@ -296,7 +344,7 @@
int pstate = getpstate();
setpstate(pstate & ~PSTATE_IE);
- return (pstate);
+ return pstate;
}
static __inline void
@@ -388,10 +436,10 @@
* NetBSD/sparc64's IPL_* constants equate directly to the
* corresponding PIL_* names; no need to map them here.
*/
- __asm __volatile("rdpr %%pil,%0" : "=r" (oldpil));
+ __asm volatile("rdpr %%pil,%0" : "=r" (oldpil));
if (newpil <= oldpil)
return (oldpil);
- __asm __volatile("wrpr %0,0,%%pil" : : "r" (newpil) : "memory");
+ __asm volatile("wrpr %0,0,%%pil" : : "r" (newpil) : "memory");
return (oldpil);
}
Index: src/sys/arch/sparc64/sparc64/clock.c
diff -u src/sys/arch/sparc64/sparc64/clock.c:1.99 src/sys/arch/sparc64/sparc64/clock.c:1.100
--- src/sys/arch/sparc64/sparc64/clock.c:1.99 Wed Mar 18 10:22:37 2009
+++ src/sys/arch/sparc64/sparc64/clock.c Sat May 16 19:15:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: clock.c,v 1.99 2009/03/18 10:22:37 cegger Exp $ */
+/* $NetBSD: clock.c,v 1.100 2009/05/16 19:15:34 nakayama Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.99 2009/03/18 10:22:37 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.100 2009/05/16 19:15:34 nakayama Exp $");
#include "opt_multiprocessor.h"
@@ -348,7 +348,6 @@
#ifndef MULTIPROCESSOR
int statint, minint;
#endif
- uint64_t start_time = 0;
#ifdef DEBUG
extern int intrdebug;
#endif
@@ -374,18 +373,9 @@
curcpu()->ci_cpu_clockrate[0] = 200000000;
curcpu()->ci_cpu_clockrate[1] = 200000000 / 1000000;
}
-
+
/* Initialize the %tick register */
-#ifdef __arch64__
- __asm volatile("wrpr %0, 0, %%tick" : : "r" (start_time));
-#else
- {
- int start_hi = (start_time>>32), start_lo = start_time;
- __asm volatile("sllx %1,32,%0; or %0,%2,%0; wrpr %0, 0, %%tick"
- : "=&r" (start_hi) /* scratch register */
- : "r" ((int)(start_hi)), "r" ((int)(start_lo)));
- }
-#endif
+ settick(0);
tick_timecounter.tc_frequency = curcpu()->ci_cpu_clockrate[0];
tc_init(&tick_timecounter);
@@ -493,7 +483,7 @@
#ifdef DEBUG
static int64_t tick_base = 0;
struct timeval ctime;
- int64_t t = (uint64_t)tick();
+ int64_t t = gettick();
microtime(&ctime);
if (!tick_base) {
Index: src/sys/arch/sparc64/sparc64/ipifuncs.c
diff -u src/sys/arch/sparc64/sparc64/ipifuncs.c:1.23 src/sys/arch/sparc64/sparc64/ipifuncs.c:1.24
--- src/sys/arch/sparc64/sparc64/ipifuncs.c:1.23 Wed Mar 18 10:22:37 2009
+++ src/sys/arch/sparc64/sparc64/ipifuncs.c Sat May 16 19:15:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: ipifuncs.c,v 1.23 2009/03/18 10:22:37 cegger Exp $ */
+/* $NetBSD: ipifuncs.c,v 1.24 2009/05/16 19:15:34 nakayama Exp $ */
/*-
* Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.23 2009/03/18 10:22:37 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipifuncs.c,v 1.24 2009/05/16 19:15:34 nakayama Exp $");
#include "opt_ddb.h"
@@ -242,9 +242,9 @@
int
sparc64_ipi_wait(sparc64_cpuset_t volatile *cpus_watchset, sparc64_cpuset_t cpus_mask)
{
- uint64_t limit = tick() + cpu_frequency(curcpu());
+ uint64_t limit = gettick() + cpu_frequency(curcpu());
- while (tick() < limit) {
+ while (gettick() < limit) {
membar_sync();
if (CPUSET_EQUAL(*cpus_watchset, cpus_mask))
return 0;
Index: src/sys/arch/sparc64/sparc64/trap.c
diff -u src/sys/arch/sparc64/sparc64/trap.c:1.156 src/sys/arch/sparc64/sparc64/trap.c:1.157
--- src/sys/arch/sparc64/sparc64/trap.c:1.156 Tue Dec 16 22:35:27 2008
+++ src/sys/arch/sparc64/sparc64/trap.c Sat May 16 19:15:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: trap.c,v 1.156 2008/12/16 22:35:27 christos Exp $ */
+/* $NetBSD: trap.c,v 1.157 2009/05/16 19:15:34 nakayama Exp $ */
/*
* Copyright (c) 1996-2002 Eduardo Horvath. All rights reserved.
@@ -50,7 +50,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.156 2008/12/16 22:35:27 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.157 2009/05/16 19:15:34 nakayama Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@@ -100,15 +100,6 @@
#define offsetof(s, f) ((size_t)&((s *)0)->f)
#endif
-#ifdef DEBUG
-/* What trap level are we running? */
-#define tl() ({ \
- int _l; \
- __asm volatile("rdpr %%tl, %0" : "=r" (_l) :); \
- _l; \
-})
-#endif
-
#ifdef TRAPSTATS
/* trapstats */
int protfix = 0;
@@ -467,13 +458,13 @@
((type == T_RWRET) ? "rwret" : T)));
}
if ((trapdebug & (TDB_FOLLOW | TDB_TRAP)) ||
- ((trapdebug & TDB_TL) && tl())) {
+ ((trapdebug & TDB_TL) && gettl())) {
char sbuf[sizeof(PSTATE_BITS) + 64];
extern int trap_trace_dis;
trap_trace_dis = 1;
printf("trap: type 0x%x: lvl=%d pc=%lx &tf=%p",
- type, (int)tl(), pc, tf);
+ type, gettl(), pc, tf);
snprintb(sbuf, sizeof(sbuf), PSTATE_BITS, pstate);
printf(" npc=%lx pstate=%s %s\n",
(long)tf->tf_npc, sbuf,
@@ -1031,7 +1022,7 @@
if (trapdebug & TDB_FRAME) {
print_trapframe(tf);
}
- if ((trapdebug & TDB_TL) && tl()) {
+ if ((trapdebug & TDB_TL) && gettl()) {
printf("%ld: data_access_fault(%p, %x, %p, %p, %lx, %lx) "
"nsaved=%d\n",
(long)(curproc?curproc->p_pid:-1), tf, type,
@@ -1304,13 +1295,13 @@
if (trapdebug & TDB_FRAME) {
print_trapframe(tf);
}
- if ((trapdebug & TDB_TL) && tl()) {
+ if ((trapdebug & TDB_TL) && gettl()) {
char buf[768];
snprintb(buf, sizeof buf, SFSR_BITS, sfsr);
- printf("%d tl %ld data_access_error(%lx, %lx, %lx, %p)="
+ printf("%d tl %d data_access_error(%lx, %lx, %lx, %p)="
"%lx @ %lx %s\n",
- curproc ? curproc->p_pid : -1, (long)tl(),
+ curproc ? curproc->p_pid : -1, gettl(),
(long)type, (long)sfva, (long)afva, tf,
(long)tf->tf_tstate,
(long)tf->tf_pc, buf);
@@ -1457,9 +1448,9 @@
if (trapdebug & TDB_FRAME) {
print_trapframe(tf);
}
- if ((trapdebug & TDB_TL) && tl()) {
+ if ((trapdebug & TDB_TL) && gettl()) {
printf("%d tl %d text_access_fault(%x, %lx, %p)\n",
- curproc?curproc->p_pid:-1, tl(), type, pc, tf);
+ curproc?curproc->p_pid:-1, gettl(), type, pc, tf);
Debugger();
}
if (trapdebug & TDB_STOPCALL) {
@@ -1600,10 +1591,10 @@
if (trapdebug & TDB_FRAME) {
print_trapframe(tf);
}
- if ((trapdebug & TDB_TL) && tl()) {
+ if ((trapdebug & TDB_TL) && gettl()) {
snprintb(buf, sizeof buf, SFSR_BITS, sfsr);
- printf("%ld tl %ld text_access_error(%lx, %lx, %lx, %p)=%lx @ %lx %s\n",
- (long)(curproc?curproc->p_pid:-1), (long)tl(),
+ printf("%d tl %d text_access_error(%lx, %lx, %lx, %p)=%lx @ %lx %s\n",
+ curproc?curproc->p_pid:-1, gettl(),
(long)type, (long)pc, (long)afva, tf,
(long)tf->tf_tstate, (long)tf->tf_pc, buf);
Debugger();