xref: /csrg-svn/sys/vax/uba/kgclock.c (revision 24960)
123330Smckusick /*
223330Smckusick  * Copyright (c) 1982 Regents of the University of California.
323330Smckusick  * All rights reserved.  The Berkeley software License Agreement
423330Smckusick  * specifies the terms and conditions for redistribution.
523330Smckusick  *
6*24960Skarels  *	@(#)kgclock.c	6.5 (Berkeley) 09/19/85
723330Smckusick  */
811357Smckusick 
912825Ssam #include "kg.h"
1012825Ssam #if NKG > 0
1112825Ssam /*
1212825Ssam  * KL-11 as profiling clock
1312825Ssam  */
1412825Ssam #include "../machine/pte.h"
1512825Ssam #include "../machine/psl.h"
1611357Smckusick 
1717074Sbloom #include "param.h"
1817074Sbloom #include "map.h"
1917074Sbloom #include "buf.h"
2017074Sbloom #include "time.h"
2117074Sbloom #include "kernel.h"
2212825Ssam 
2317074Sbloom #include "ubavar.h"
2411357Smckusick 
2511357Smckusick int	kgprobe(), kgattach();
2611357Smckusick struct	uba_device *kginfo[1];
2711357Smckusick u_short	kgstd[] = { 0177560, 0 };
2811357Smckusick struct	uba_driver kgdriver =
2911357Smckusick     { kgprobe, 0, kgattach, 0, kgstd, "kg", kginfo };
3011357Smckusick 
3111357Smckusick struct klregs {
3211357Smckusick 	u_short	fill[2];
3311357Smckusick 	u_short	tcsr;
3411357Smckusick 	u_short	tbuf;
3511357Smckusick };
3611357Smckusick #define	KLSTRT	0300		/* intr enbl + done */
3711357Smckusick struct	klregs *klbase;
3811357Smckusick 
3916972Skarels int	usekgclock = 1;		/* if zero, kgclock is disabled */
4016972Skarels 
4111357Smckusick kgprobe(reg)
4212825Ssam 	caddr_t reg;
4311357Smckusick {
4411357Smckusick 	register int br, cvec;	/* value-result */
4511357Smckusick 	register struct klregs *klp = (struct klregs *)reg;
4611357Smckusick 
4711357Smckusick 	klp->tcsr = KLSTRT;
4811357Smckusick 	DELAY(100000);
4911357Smckusick 	klp->tcsr = 0;
50*24960Skarels 	return (sizeof(struct klregs));
5111357Smckusick }
5211357Smckusick 
5311357Smckusick kgattach(ui)
5411393Ssam 	struct uba_device *ui;
5511357Smckusick {
5611393Ssam 
5711357Smckusick 	klbase = (struct klregs *)ui->ui_addr;
5811357Smckusick }
5911357Smckusick 
6011357Smckusick /*
6111357Smckusick  * start the sampling clock
6211357Smckusick  */
6311357Smckusick startkgclock()
6411357Smckusick {
6511393Ssam 
6616972Skarels 	if (klbase && usekgclock && phz == 0)
6711357Smckusick 		klbase->tcsr = KLSTRT;	/* enable interrupts */
6811357Smckusick }
6911357Smckusick 
7011357Smckusick /* ARGSUSED */
7111357Smckusick kgclock(dev, r0, r1, r2, r3, r4 ,r5, pc, ps)
7211393Ssam 	caddr_t pc;
7311393Ssam 	int ps;
7411357Smckusick {
7511357Smckusick 	register int k;
7612825Ssam 	static long otime;
7712825Ssam 	static long calibrate;
7811357Smckusick 
7916972Skarels 	if (usekgclock == 0) {
8016972Skarels 		phz = 0;
8116972Skarels 		otime = 0;
8216972Skarels 		return;
8316972Skarels 	}
8411357Smckusick 	klbase->tbuf = 0377;	/* reprime clock (scope sync too) */
8511358Smckusick 	if (phz == 0) {
8611358Smckusick 		if (otime == 0) {
8712825Ssam 			otime = time.tv_sec + 1;
8811358Smckusick 			calibrate = 0;
8911358Smckusick 		}
9012825Ssam 		if (time.tv_sec >= otime)
9111358Smckusick 			calibrate++;
9212825Ssam 		if (time.tv_sec >= otime + 4) {
9311358Smckusick 			phz = calibrate / 4;
9411358Smckusick 			otime = 0;
9511358Smckusick 		}
9611358Smckusick 		return;
9711358Smckusick 	}
9811393Ssam 	gatherstats(pc, ps);	/* this routine lives in kern_clock.c */
9911357Smckusick }
10012825Ssam #endif
101