From df4adf66f769f5b5da3aac541fa239b4c2bcc298 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sat, 19 Oct 2013 08:50:21 +0200 Subject: [PATCH] Add Programmable Interval Timer support Add uptime command --- src/commands.asm | 21 +++++++++++++++++++++ src/kernel.asm | 3 +++ src/timer.asm | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/timer.asm diff --git a/src/commands.asm b/src/commands.asm index 801853df..69e7ad9a 100644 --- a/src/commands.asm +++ b/src/commands.asm @@ -4,6 +4,7 @@ sysinfo_command_str db 'sysinfo', 0 reboot_command_str db 'reboot', 0 clear_command_str db 'clear', 0 help_command_str db 'help', 0 +uptime_command_str db 'uptime', 0 STRING sysinfo_vendor_id, "Vendor ID: " STRING sysinfo_stepping, "Stepping: " @@ -25,6 +26,7 @@ STRING sysinfo_ht, "ht " STRING sysinfo_fpu, "fpu " STRING sysinfo_aes, "aes " +STRING uptime_message, "Uptime (s): " STRING available_commands, "Available commands: " STRING tab, " " @@ -42,6 +44,9 @@ command_table: dq clear_command_str dq clear_command + dq uptime_command_str + dq uptime_command + dq help_command_str dq help_command @@ -333,6 +338,22 @@ help_command: ret +uptime_command: + push r8 + push r9 + + mov r8, uptime_message + mov r9, uptime_message_length + call print_normal + + mov r8, [timer_seconds] + call print_int_normal + + pop r9 + pop r8 + + ret + reboot_command: ; Reboot using the 8042 keyboard controller ; by pulsing the CPU's reset pin diff --git a/src/kernel.asm b/src/kernel.asm index 87faff35..3cfa458c 100644 --- a/src/kernel.asm +++ b/src/kernel.asm @@ -97,6 +97,8 @@ lm_start: sti + call install_timer + ; Enter the shell call shell_start @@ -107,6 +109,7 @@ lm_start: %include "src/utils/macros.asm" %include "src/utils/console.asm" +%include "src/timer.asm" %include "src/interrupts.asm" %include "src/shell.asm" diff --git a/src/timer.asm b/src/timer.asm new file mode 100644 index 00000000..cd8fd7de --- /dev/null +++ b/src/timer.asm @@ -0,0 +1,47 @@ + +install_timer: + mov r8, 1193180 / 1000 + + mov al, 0x36 + out 0x43, al ; Command byte + + mov rax, r8 + out 0x40, al ; low bytes of divisor + + mov rax, r8 + shr rax, 8 + out 0x40, al ; high bytes of divisor + + mov r8, 0 + mov r9, irq_timer_handler + call register_irq_handler + + ret + +irq_timer_handler: + push rax + + mov rax, [timer_ticks] + inc rax + mov [timer_ticks], rax + + xor rdx, rdx + mov rcx, 1000 + div rcx + cmp rdx, 0 + jnz .end + + mov rax, [timer_seconds] + inc rax + mov [timer_seconds], rax + + .end: + + pop r8 + + ret + +; Variables + +timer_ticks dq 0 +timer_seconds dq 0