⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clock.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
字号:
#include	"u.h"#include	"../port/lib.h"#include	"mem.h"#include	"dat.h"#include	"fns.h"#include	"io.h"#include	"axp.h"#include	"ureg.h"voidclockinit(void){}uvlongcycletimer(void){	ulong pcc;	vlong delta;	pcc = rpcc(nil) & 0xFFFFFFFF;	if(m->cpuhz == 0){		/*		 * pcclast is needed to detect wraparound of		 * the cycle timer which is only 32-bits.		 * m->cpuhz is set from the info passed from		 * the firmware.		 * This could be in clockinit if can		 * guarantee no wraparound between then and now.		 *		 * All the clock stuff needs work.		 */		m->cpuhz = hwrpb->cfreq;		m->pcclast = pcc;	}	delta = pcc - m->pcclast;	if(delta < 0)		delta += 0x100000000LL;	m->pcclast = pcc;	m->fastclock += delta;	return MACHP(0)->fastclock;}uvlongfastticks(uvlong* hz){	uvlong ticks;	int x;	x = splhi();	ticks = cycletimer();	splx(x);	if(hz)		*hz = m->cpuhz;	return ticks;}/*   *  performance measurement ticks.  must be low overhead. *  doesn't have to count over a second. */ulongperfticks(void){	return rpcc(nil);}voidtimerset(uvlong){}voidmicrodelay(int us){	uvlong eot;	eot = fastticks(nil) + (m->cpuhz/1000000)*us;	while(fastticks(nil) < eot)		;}voiddelay(int millisecs){	microdelay(millisecs*1000);}voidclock(Ureg *ureg){	static int count;	cycletimer();	/* HZ == 100, timer == 1024Hz.  error < 1ms */	count += 100;	if (count < 1024)		return;	count -= 1024;	timerintr(ureg, 0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -