#include #include #include const char *days[] = { NULL, "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; const char *month[] = { NULL, "Jan", "Feb", "Mar", "Apr", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static int getbiosbyte(int address); static void setbiosbyte(int address, int value); static int unbcd(int bcdbyte); int main() { if (ioperm(0x70, 2, 1) != 0) { perror("Cannot set IO permissions"); return EXIT_FAILURE; } printf("%s %s. %02d 20%02d %02d:%02d:%02d\n", days[getbiosbyte(0x06)], month[unbcd(getbiosbyte(0x08))], unbcd(getbiosbyte(0x07)), unbcd(getbiosbyte(0x09)), unbcd(getbiosbyte(0x04)), unbcd(getbiosbyte(0x02)), unbcd(getbiosbyte(0x00)) ); return EXIT_SUCCESS; } static int getbiosbyte(int address) { outb(address, 0x70); return inb(0x71); } static void setbiosbyte(int address, int value) { outb(address, 0x70); outb(value, 0x71); } /* convert a BCD byte into an int */ static int unbcd(int bcdbyte) { // return (bcdbyte & 0xf) + 10 * (bcdbyte >> 8 & 0xf); return bcdbyte; }