From 8ad6ef551e9a1c51a77f3662978c7559556897d6 Mon Sep 17 00:00:00 2001 From: Tyler Murphy <=> Date: Sun, 16 Jul 2023 19:56:56 -0400 Subject: time --- kernel/src/interrupt/idt.asm | 99 ++++++++++++++++++++++++++++++++++++++++++++ kernel/src/interrupt/idt.c | 24 +++++++---- kernel/src/interrupt/isr.asm | 99 -------------------------------------------- 3 files changed, 116 insertions(+), 106 deletions(-) create mode 100644 kernel/src/interrupt/idt.asm delete mode 100644 kernel/src/interrupt/isr.asm (limited to 'kernel/src/interrupt') diff --git a/kernel/src/interrupt/idt.asm b/kernel/src/interrupt/idt.asm new file mode 100644 index 0000000..6cccdc6 --- /dev/null +++ b/kernel/src/interrupt/idt.asm @@ -0,0 +1,99 @@ +extern idt_exception_handler +extern idt_pic_timer +extern idt_pic_keyboard +extern idt_pic_mouse +extern idt_pic_eoi +global isr_stub_table + +%macro ISRErrorStub 1 +isr_stub_%+%1: + push dword %1 + call idt_exception_handler + pop eax + iret +%endmacro + +%macro PICGeneric 1 +isr_stub_%+%1: + push dword %1 + call idt_pic_eoi + pop eax + iret +%endmacro + +%macro PICTimer 1 +isr_stub_%+%1: + call idt_pic_timer + push dword %1 + call idt_pic_eoi + pop eax + iret +%endmacro + +%macro PICKeyboard 1 +isr_stub_%+%1: + call idt_pic_keyboard + push dword %1 + call idt_pic_eoi + pop eax + iret +%endmacro + +%macro PICMouse 1 +isr_stub_%+%1: + call idt_pic_mouse + push dword %1 + call idt_pic_eoi + pop eax + iret +%endmacro + +%macro ISRSyscall 1 +isr_stub_%+%1: + push eax + push ebx + push ecx + push edx + call idt_syscall + add esp, 16 + pop eax + iret +%endmacro + +section .text +align 8 +%assign i 0 +%rep 32 + ISRErrorStub i +%assign i i+1 +%endrep +PICTimer 32 ; 0 +PICKeyboard 33 ; 1 +PICGeneric 34 ; 2 +PICGeneric 35 ; 3 +PICGeneric 36 ; 4 +PICGeneric 37 ; 5 +PICGeneric 38 ; 6 +PICGeneric 39 ; 7 +PICGeneric 40 ; 8 +PICGeneric 41 ; 9 +PICGeneric 42 ; 10 +PICGeneric 43 ; 11 +PICMouse 44 ; 12 +PICGeneric 45 ; 13 +PICGeneric 46 ; 14 +PICGeneric 47 ; 15 +%assign i 48 +%rep 256 - 48 + ISRErrorStub i +%assign i i+1 +%endrep + +section .rodata +align 8 +isr_stub_table: +%assign i 0x00 +%rep 256 + dd isr_stub_%+i +%assign i i+0x01 +%endrep diff --git a/kernel/src/interrupt/idt.c b/kernel/src/interrupt/idt.c index 6df3793..aaa7034 100644 --- a/kernel/src/interrupt/idt.c +++ b/kernel/src/interrupt/idt.c @@ -9,25 +9,35 @@ #include "acpi/acpi.h" #include "drivers/ps2kb.h" #include "drivers/ps2mouse.h" +#include "time.h" #include "tty/color.h" #include "idt.h" #include "pic.h" #include "tty/term.h" -static int timer = 0; +#define WIDTH 30 +static char buf[WIDTH]; +static int timer = -1; void idt_pic_eoi(uint8_t exception) { pic_eoi(exception - PIC_REMAP_OFFSET); } void idt_pic_timer(void) { - uint32_t state = term_save(); - term_setfg(VGA_LIGHT_GREEN); - term_setpos(60, 0); - puts(" "); - term_setpos(60, 0); - printk("%d", timer); + timer += 1; + if (timer % 20 != 0) return; + + uint32_t state = term_save(); + + term_setfg(VGA_LIGHT_GREEN); + term_setpos(TERM_W - WIDTH - 1, 0); + for (size_t i = 0; i < WIDTH; i++) putchar(' '); + term_setpos(TERM_W - WIDTH - 1, 0); + + timetostr(rtc_localtime(), "%a %b %d %Y %H:%M:%S", buf, WIDTH); + printk("%s", buf); + term_load(state); } diff --git a/kernel/src/interrupt/isr.asm b/kernel/src/interrupt/isr.asm deleted file mode 100644 index 6cccdc6..0000000 --- a/kernel/src/interrupt/isr.asm +++ /dev/null @@ -1,99 +0,0 @@ -extern idt_exception_handler -extern idt_pic_timer -extern idt_pic_keyboard -extern idt_pic_mouse -extern idt_pic_eoi -global isr_stub_table - -%macro ISRErrorStub 1 -isr_stub_%+%1: - push dword %1 - call idt_exception_handler - pop eax - iret -%endmacro - -%macro PICGeneric 1 -isr_stub_%+%1: - push dword %1 - call idt_pic_eoi - pop eax - iret -%endmacro - -%macro PICTimer 1 -isr_stub_%+%1: - call idt_pic_timer - push dword %1 - call idt_pic_eoi - pop eax - iret -%endmacro - -%macro PICKeyboard 1 -isr_stub_%+%1: - call idt_pic_keyboard - push dword %1 - call idt_pic_eoi - pop eax - iret -%endmacro - -%macro PICMouse 1 -isr_stub_%+%1: - call idt_pic_mouse - push dword %1 - call idt_pic_eoi - pop eax - iret -%endmacro - -%macro ISRSyscall 1 -isr_stub_%+%1: - push eax - push ebx - push ecx - push edx - call idt_syscall - add esp, 16 - pop eax - iret -%endmacro - -section .text -align 8 -%assign i 0 -%rep 32 - ISRErrorStub i -%assign i i+1 -%endrep -PICTimer 32 ; 0 -PICKeyboard 33 ; 1 -PICGeneric 34 ; 2 -PICGeneric 35 ; 3 -PICGeneric 36 ; 4 -PICGeneric 37 ; 5 -PICGeneric 38 ; 6 -PICGeneric 39 ; 7 -PICGeneric 40 ; 8 -PICGeneric 41 ; 9 -PICGeneric 42 ; 10 -PICGeneric 43 ; 11 -PICMouse 44 ; 12 -PICGeneric 45 ; 13 -PICGeneric 46 ; 14 -PICGeneric 47 ; 15 -%assign i 48 -%rep 256 - 48 - ISRErrorStub i -%assign i i+1 -%endrep - -section .rodata -align 8 -isr_stub_table: -%assign i 0x00 -%rep 256 - dd isr_stub_%+i -%assign i i+0x01 -%endrep -- cgit v1.2.3-freya