[cmos] Fix userspace clock
This commit is contained in:
parent
1a2cb28fc1
commit
d73d2e2361
@ -67,18 +67,74 @@ get_time(
|
||||
*seconds = from_bcd(values[0]);
|
||||
}
|
||||
|
||||
uint32_t secs_of_years(int years) {
|
||||
uint32_t days = 0;
|
||||
years += 2000;
|
||||
while (years > 1969) {
|
||||
days += 365;
|
||||
if (years % 4 == 0) {
|
||||
if (years % 100 == 0) {
|
||||
if (years % 400 == 0) {
|
||||
days++;
|
||||
}
|
||||
} else {
|
||||
days++;
|
||||
}
|
||||
}
|
||||
years--;
|
||||
}
|
||||
return days * 86400;
|
||||
}
|
||||
|
||||
uint32_t secs_of_month(int months, int year) {
|
||||
year += 2000;
|
||||
|
||||
uint32_t days = 0;
|
||||
switch(months) {
|
||||
case 11:
|
||||
days += 30;
|
||||
case 10:
|
||||
days += 31;
|
||||
case 9:
|
||||
days += 30;
|
||||
case 8:
|
||||
days += 31;
|
||||
case 7:
|
||||
days += 31;
|
||||
case 6:
|
||||
days += 30;
|
||||
case 5:
|
||||
days += 31;
|
||||
case 4:
|
||||
days += 30;
|
||||
case 3:
|
||||
days += 31;
|
||||
case 2:
|
||||
days += 28;
|
||||
if (year % 4 && year % 100 != 0) {
|
||||
days++;
|
||||
}
|
||||
case 1:
|
||||
days += 31;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return days * 86400;
|
||||
}
|
||||
|
||||
int
|
||||
gettimeofday(struct timeval * t, void *z) {
|
||||
uint16_t values[128];
|
||||
cmos_dump(values);
|
||||
|
||||
/* Math Time */
|
||||
uint32_t time = (from_bcd(values[9]) - 70) * 31556926 +
|
||||
from_bcd(values[8]) * 2629743 +
|
||||
from_bcd(values[7]) * 87400 +
|
||||
from_bcd(values[4]) * 3600 +
|
||||
from_bcd(values[2]) * 60 +
|
||||
from_bcd(values[0]);
|
||||
uint32_t time = secs_of_years(from_bcd(values[9]) - 1) +
|
||||
secs_of_month(from_bcd(values[8]) - 1, from_bcd(values[9])) +
|
||||
(from_bcd(values[7]) - 1) * 86400 +
|
||||
(from_bcd(values[4])) * 3600 +
|
||||
(from_bcd(values[2])) * 60 +
|
||||
from_bcd(values[0]) +
|
||||
0;
|
||||
t->tv_sec = time;
|
||||
t->tv_usec = 0;
|
||||
return 0;
|
||||
|
@ -2,10 +2,14 @@
|
||||
*
|
||||
* Low-level keyboard interrupt driver.
|
||||
*
|
||||
* Part of the ToAruOS Kernel
|
||||
* (C) 2011 Kevin Lange
|
||||
* Creates a device file (keyboard_pipe) that can be read
|
||||
* to retreive keyboard events.
|
||||
*
|
||||
* TODO: Move this to a server.
|
||||
* Part of the ToAruOS Kernel
|
||||
* Copyright 2011-2012 Kevin Lange
|
||||
*
|
||||
* TODO: Move this to a server
|
||||
* TODO: Better handling of function keys
|
||||
*/
|
||||
|
||||
#include <system.h>
|
||||
@ -254,29 +258,39 @@ keyboard_handler(
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Install the keyboard driver and initialize the
|
||||
* pipe device for userspace.
|
||||
*/
|
||||
void
|
||||
keyboard_install() {
|
||||
blog("Initializing PS/2 keyboard driver...");
|
||||
LOG(INFO, "Initializing PS/2 keyboard driver");
|
||||
/* IRQ installer */
|
||||
|
||||
/* Clear the buffer handlers */
|
||||
keyboard_buffer_handler = NULL;
|
||||
keyboard_direct_handler = NULL;
|
||||
|
||||
/* Create a device pipe */
|
||||
keyboard_pipe = make_pipe(128);
|
||||
current_process->fds.entries[0] = keyboard_pipe;
|
||||
|
||||
/* Install the interrupt handler */
|
||||
irq_install_handler(1, keyboard_handler);
|
||||
|
||||
bfinish(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait on the keyboard.
|
||||
*/
|
||||
void
|
||||
keyboard_wait() {
|
||||
while(inportb(KEY_PENDING) & 2);
|
||||
}
|
||||
|
||||
/*
|
||||
* putch
|
||||
* Add a character to the device buffer.
|
||||
*/
|
||||
void
|
||||
putch(
|
||||
|
@ -131,7 +131,9 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
|
||||
initrd_mount((uintptr_t)ramdisk, ramdisk_top);
|
||||
}
|
||||
|
||||
//mouse_install(); /* Mouse driver */
|
||||
#if 0
|
||||
mouse_install(); /* Mouse driver */
|
||||
#endif
|
||||
|
||||
if (cmdline) {
|
||||
parse_args(cmdline);
|
||||
@ -142,7 +144,7 @@ int main(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp)
|
||||
*/
|
||||
char * argv[] = {
|
||||
"terminal",
|
||||
#if 0
|
||||
#if 1
|
||||
"-f",
|
||||
#endif
|
||||
NULL
|
||||
|
@ -41,6 +41,9 @@ int readline(char * buf, size_t size) {
|
||||
char * cmd = malloc(2);
|
||||
size_t nread = fread(cmd, 1, 1, stdin);
|
||||
if (nread > 0) {
|
||||
if (cmd[0] < 10 || (cmd[0] > 10 && cmd[0] < 32) || cmd[0] > 126) {
|
||||
continue;
|
||||
}
|
||||
buf[collected] = cmd[0];
|
||||
printf("%c", cmd[0]);
|
||||
fflush(stdout);
|
||||
@ -57,8 +60,6 @@ _done:
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
printf("I am pid %d\n", getpid());
|
||||
|
||||
int pid = getpid();
|
||||
int nowait = 0;
|
||||
int free_cmd = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user