xref: /csrg-svn/sys/vax/uba/kgclock.c (revision 12825)
1*12825Ssam /*	kgclock.c	4.4	83/05/30	*/
211357Smckusick 
3*12825Ssam #include "kg.h"
4*12825Ssam #if NKG > 0
5*12825Ssam /*
6*12825Ssam  * KL-11 as profiling clock
7*12825Ssam  */
8*12825Ssam #include "../machine/pte.h"
9*12825Ssam #include "../machine/psl.h"
1011357Smckusick 
1111393Ssam #include "../h/param.h"
1211357Smckusick #include "../h/map.h"
1311357Smckusick #include "../h/buf.h"
14*12825Ssam #include "../h/time.h"
15*12825Ssam #include "../h/kernel.h"
16*12825Ssam 
1711393Ssam #include "../vaxuba/ubavar.h"
1811357Smckusick 
1911357Smckusick int	kgprobe(), kgattach();
2011357Smckusick struct	uba_device *kginfo[1];
2111357Smckusick u_short	kgstd[] = { 0177560, 0 };
2211357Smckusick struct	uba_driver kgdriver =
2311357Smckusick     { kgprobe, 0, kgattach, 0, kgstd, "kg", kginfo };
2411357Smckusick 
2511357Smckusick struct klregs {
2611357Smckusick 	u_short	fill[2];
2711357Smckusick 	u_short	tcsr;
2811357Smckusick 	u_short	tbuf;
2911357Smckusick };
3011357Smckusick #define	KLSTRT	0300		/* intr enbl + done */
3111357Smckusick struct	klregs *klbase;
3211357Smckusick 
3311357Smckusick kgprobe(reg)
34*12825Ssam 	caddr_t reg;
3511357Smckusick {
3611357Smckusick 	register int br, cvec;	/* value-result */
3711357Smckusick 	register struct klregs *klp = (struct klregs *)reg;
3811357Smckusick 
3911357Smckusick 	klp->tcsr = KLSTRT;
4011357Smckusick 	DELAY(100000);
4111357Smckusick 	klp->tcsr = 0;
4211357Smckusick }
4311357Smckusick 
4411357Smckusick kgattach(ui)
4511393Ssam 	struct uba_device *ui;
4611357Smckusick {
4711393Ssam 
4811357Smckusick 	klbase = (struct klregs *)ui->ui_addr;
4911357Smckusick }
5011357Smckusick 
5111357Smckusick /*
5211357Smckusick  * start the sampling clock
5311357Smckusick  */
5411357Smckusick startkgclock()
5511357Smckusick {
5611393Ssam 
5711357Smckusick 	if (klbase)
5811357Smckusick 		klbase->tcsr = KLSTRT;	/* enable interrupts */
5911357Smckusick }
6011357Smckusick 
6111357Smckusick /* ARGSUSED */
6211357Smckusick kgclock(dev, r0, r1, r2, r3, r4 ,r5, pc, ps)
6311393Ssam 	caddr_t pc;
6411393Ssam 	int ps;
6511357Smckusick {
6611357Smckusick 	register int k;
67*12825Ssam 	static long otime;
68*12825Ssam 	static long calibrate;
6911357Smckusick 
7011357Smckusick 	klbase->tbuf = 0377;	/* reprime clock (scope sync too) */
7111358Smckusick 	if (phz == 0) {
7211358Smckusick 		if (otime == 0) {
73*12825Ssam 			otime = time.tv_sec + 1;
7411358Smckusick 			calibrate = 0;
7511358Smckusick 		}
76*12825Ssam 		if (time.tv_sec >= otime)
7711358Smckusick 			calibrate++;
78*12825Ssam 		if (time.tv_sec >= otime + 4) {
7911358Smckusick 			phz = calibrate / 4;
8011358Smckusick 			otime = 0;
8111358Smckusick 		}
8211358Smckusick 		return;
8311358Smckusick 	}
8411393Ssam 	gatherstats(pc, ps);	/* this routine lives in kern_clock.c */
8511357Smckusick }
86*12825Ssam #endif
87