view include/tod.h @ 99:2a0aa3efc228

The shell script will now theroretically load the program into memory, will not run it. The shell script loads a program into memory and displays the address but as of now does not jump to it (though it does display the address it would jump to) Added a memset function Added a python script (credit for its writing to Jeff) that sets up a filesystem
author Jonathan Pevarnek <pevarnj@gmail.com>
date Sat, 14 May 2011 19:40:18 -0400
parents 3b73044b740f
children
line wrap: on
line source

#ifndef __TOD_H
#define __TOD_H

/*
 * The Time Of Day (TOD) hardware adds 1 to the 51st bit every microsecond.
 * The TOD value 0 is defined as 00:00:00 on Jan 1, 1900.
 *
 * Here are the TOD values for each of the leap seconds, as well as the
 * beginning of UTC (Jan 1, 1970).
 *
 * Year  Month  Day  Leap Sec.  Clock Setting (Hex)
 * ------------------------------------------------
 * 1900      1    1       N/A   0000 0000 0000 0000
 * 1972      1    1       N/A   8126 D60E 4600 0000
 * 1972      7    1         1   820B A981 1E24 0000
 * 1973      1    1         2   82F3 00AE E248 0000
 * 1974      1    1         3   84BD E971 146C 0000
 * 1975      1    1         4   8688 D233 4690 0000
 * 1976      1    1         5   8853 BAF5 78B4 0000
 * 1977      1    1         6   8A1F E595 20D8 0000
 * 1978      1    1         7   8BEA CE57 52FC 0000
 * 1979      1    1         8   8DB5 B719 8520 0000
 * 1980      1    1         9   8F80 9FDB B744 0000
 * 1981      7    1        10   9230 5C0F CD68 0000
 * 1982      7    1        11   93FB 44D1 FF8C 0000
 * 1983      7    1        12   95C6 2D94 31B0 0000
 * 1985      7    1        13   995D 40F5 17D4 0000
 * 1988      1    1        14   9DDA 69A5 57F8 0000
 * 1990      1    1        15   A171 7D06 3E1C 0000
 * 1991      1    1        16   A33C 65C8 7040 0000
 * 1992      7    1        17   A5EC 21FC 8664 0000
 * 1993      7    1        18   A7B7 0ABE B888 0000
 * 1994      7    1        19   A981 F380 EAAC 0000
 * 1996      1    1        20   AC34 336F ECD0 0000
 * 1997      7    1        21   AEE3 EFA4 02F4 0000
 * 1999      1    1        22   B196 2F93 0518 0000
 * 2006      1    1        23   BE25 1097 973C 0000
 * 2009      1    1        24   C387 0CB9 BB60 0000
 */

#define TOD_MICROSEC		0x0000000000001000UL
#define TOD_SEC			0x0000000f4240000ULL
#define TOD_MIN			0x000003938700000ULL
#define TOD_HOUR		0x0000d693a400000ULL
#define TOD_DAY			0x00141dd76000000ULL
#define TOD_YEAR		0x1cae8c13e000000ULL /* not leap */
#define TOD_FOURYEARS		0x72ce4e26e000000ULL

/*
 * Stores (if possible) the current TOD value.
 *
 * Returns:
 *   0 on success, *tod contains current time & date
 *                 *tod == 0 is midnight, Jan 1, 1900
 *   1 on success, *tod contains uptime
 *                 *tod == 0 is the instant the system powered on
 *   2 or 3 on failure, value of *tod is unpredictable
 */
static inline ErrCode get_tod(u64 *tod)
{
	int cc;
	ErrCode ret = 0;

	asm volatile(
		"stck	%0\n"
		"ipm	%1\n"
		"srl	%1,28\n"
	: /* output */
	  "=m" (*tod),
	  "=d" (cc)
	: /* input */
	: /* clobber */
	  "cc"
	);
	switch(cc) {
		case 0:
			ret = 0;
			break;
		case 1:
			ret = mkError(MODTOD, UPTIME, WARN);
			break;
		case 2:
		case 3:
			ret = mkError(MODTOD, INVALID, ERROR);
			break;
	}

	return ret;
}

#endif