[cmos] Make a single function to dump the CMOS
This commit is contained in:
parent
c551734e0c
commit
d1676852d8
@ -1,13 +1,25 @@
|
||||
/*
|
||||
* CMOS Driver
|
||||
*
|
||||
* Part of the ToAruOS Kernel
|
||||
* (C) 2011 Kevin Lange
|
||||
*/
|
||||
|
||||
#include <system.h>
|
||||
|
||||
/* CMOS values are stored like so:
|
||||
* Say it's 8:42 AM, then the values are stored as:
|
||||
* 0x08, 0x42... why this was a good idea, I have no
|
||||
* clue, but that's how it usually is.
|
||||
*
|
||||
* This function will convert between this "BCD" format
|
||||
* and regular decimal integers. */
|
||||
#define from_bcd(val) ((val / 16) * 10 + (val & 0xf))
|
||||
|
||||
void
|
||||
get_date(
|
||||
uint16_t * month,
|
||||
uint16_t * day
|
||||
cmos_dump(
|
||||
uint16_t * values
|
||||
) {
|
||||
uint16_t values[128];
|
||||
uint16_t index;
|
||||
__asm__ __volatile__ ("cli");
|
||||
for (index = 0; index < 128; ++index) {
|
||||
@ -15,6 +27,21 @@ get_date(
|
||||
values[index] = inportb(0x71);
|
||||
}
|
||||
__asm__ __volatile__ ("sti");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current month and day.
|
||||
*
|
||||
* @param month Pointer to a short to store the month
|
||||
* @param day Pointer to a short to store the day
|
||||
*/
|
||||
void
|
||||
get_date(
|
||||
uint16_t * month,
|
||||
uint16_t * day
|
||||
) {
|
||||
uint16_t values[128]; /* CMOS dump */
|
||||
cmos_dump(values);
|
||||
*month = from_bcd(values[8]);
|
||||
*day = from_bcd(values[7]);
|
||||
}
|
||||
@ -25,16 +52,15 @@ get_time(
|
||||
uint16_t * minutes,
|
||||
uint16_t * seconds
|
||||
) {
|
||||
uint16_t values[128];
|
||||
uint16_t index;
|
||||
__asm__ __volatile__ ("cli");
|
||||
for (index = 0; index < 128; ++index) {
|
||||
outportb(0x70, index);
|
||||
values[index] = inportb(0x71);
|
||||
}
|
||||
__asm__ __volatile__ ("sti");
|
||||
uint16_t values[128]; /* CMOS dump */
|
||||
cmos_dump(values);
|
||||
|
||||
*hours = from_bcd(values[4]);
|
||||
*minutes = from_bcd(values[2]);
|
||||
*seconds = from_bcd(values[0]);
|
||||
}
|
||||
|
||||
/*
|
||||
* vim:tabstop=4
|
||||
* vim:noexpandtab
|
||||
*/
|
||||
|
@ -92,7 +92,7 @@ exec(
|
||||
close_fs(file);
|
||||
|
||||
/* Go go go */
|
||||
enter_user_jmp(e_entry, argc, argv);
|
||||
enter_user_jmp(entry, argc, argv);
|
||||
|
||||
/* We should never reach this code */
|
||||
kexit(0x5ADFACE);
|
||||
|
Loading…
Reference in New Issue
Block a user