diff --git a/kernel/core/cmos.c b/kernel/core/cmos.c new file mode 100644 index 00000000..1ec86594 --- /dev/null +++ b/kernel/core/cmos.c @@ -0,0 +1,23 @@ +#include + +#define from_bcd(val) ((val / 16) * 10 + (val & 0xf)) + +void +get_time( + uint16_t * hours, + 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"); + + *hours = from_bcd(values[4]); + *minutes = from_bcd(values[2]); + *seconds = from_bcd(values[0]); +} diff --git a/kernel/core/kbd.c b/kernel/core/kbd.c index b1cd7bbd..b0ee9ec2 100644 --- a/kernel/core/kbd.c +++ b/kernel/core/kbd.c @@ -123,26 +123,33 @@ void ctlk(int scancode) { } void func(int scancode) { - + kprintf("[NOTICE] Function key %d pressed\n", scancode); +} + +void spec(int scancode) { + if (scancode & 0x80) { + return; + } + kprintf("[NOTICE] Special key %d pressed\n", scancode); } keyboard_handler_t key_method[] = { - /* 00 */ NULL, NULL, norm, norm, norm, norm, norm, norm, + /* 00 */ NULL, spec, norm, norm, norm, norm, norm, norm, /* 08 */ norm, norm, norm, norm, norm, norm, norm, norm, /* 10 */ norm, norm, norm, norm, norm, norm, norm, norm, /* 18 */ norm, norm, norm, norm, norm, ctlk, norm, norm, /* 20 */ norm, norm, norm, norm, norm, norm, norm, norm, /* 28 */ norm, norm, shft, norm, norm, norm, norm, norm, /* 30 */ norm, norm, norm, norm, norm, norm, shft, norm, - /* 38 */ altk, norm, NULL, func, func, func, func, func, - /* 40 */ func, func, func, func, func, NULL, NULL, NULL, - /* 48 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 50 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, func, - /* 58 */ func, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 60 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 68 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 70 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - /* 78 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + /* 38 */ altk, norm, spec, func, func, func, func, func, + /* 40 */ func, func, func, func, func, spec, spec, spec, + /* 48 */ spec, spec, spec, spec, spec, spec, spec, spec, + /* 50 */ spec, spec, spec, spec, spec, spec, spec, func, + /* 58 */ func, spec, spec, spec, spec, spec, spec, spec, + /* 60 */ spec, spec, spec, spec, spec, spec, spec, spec, + /* 68 */ spec, spec, spec, spec, spec, spec, spec, spec, + /* 70 */ spec, spec, spec, spec, spec, spec, spec, spec, + /* 78 */ spec, spec, spec, spec, spec, spec, spec, spec, }; diff --git a/kernel/core/shell.c b/kernel/core/shell.c index d9d83420..f8d44e2b 100644 --- a/kernel/core/shell.c +++ b/kernel/core/shell.c @@ -184,6 +184,8 @@ start_shell() { serial_send('\n'); writech('\n'); } + } else if (!strcmp(cmd, "clear")) { + cls(); } else if (!strcmp(cmd, "crash")) { kprintf("Going to dereference some invalid pointers.\n"); int i = 0xFFFFFFFF; diff --git a/kernel/include/system.h b/kernel/include/system.h index 4c314160..cd6f76ef 100644 --- a/kernel/include/system.h +++ b/kernel/include/system.h @@ -173,4 +173,7 @@ extern uint32_t getpid(); uintptr_t initial_esp; +/* CMOS */ +extern void get_time(uint16_t * hours, uint16_t * minutes, uint16_t * seconds); + #endif diff --git a/kernel/main.c b/kernel/main.c index 325bfc64..8f370651 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -35,9 +35,6 @@ #include #include - -#define from_bcd(val) ((val / 16) * 10 + (val & 0xf)) - /* * kernel entry point * @@ -116,8 +113,6 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp) settextcolor(12, 0); kprintf("[%s %s]\n", KERNEL_UNAME, KERNEL_VERSION_STRING); - - __asm__ __volatile__ ("cli"); if (boot_mode == multiboot) { /* Print multiboot information */ dump_multiboot(mboot_ptr); @@ -131,7 +126,16 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp) } } } - __asm__ __volatile__ ("sti"); + + /* + * All the output we just dumped went to the serial line. + * If you really want it that bad, feel free to remove + * the clear before the rest of the boot process starts. + * + * But really, the kernel shouldn't be outputting all + * sorts of random text on boot up. Only important stuff! + */ + cls(); /* * Aw man... @@ -140,18 +144,8 @@ int main(struct multiboot *mboot_ptr, uint32_t mboot_mag, uintptr_t esp) if (getpid() == 0) { while (1) { - 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 hours = from_bcd(values[4]); - uint16_t minutes = from_bcd(values[2]); - uint16_t seconds = from_bcd(values[0]); + uint16_t hours, minutes, seconds; + get_time(&hours, &minutes, &seconds); __asm__ __volatile__ ("cli"); store_csr();