From 8a5fbdabb24250a76feed770bce64d7e3e4f61de Mon Sep 17 00:00:00 2001 From: Miguel Date: Tue, 21 Aug 2018 01:24:14 +0200 Subject: adding new pit code --- asm/asm.h | 4 +++- asm/pit.h | 25 +++++++++++++++++++++++++ asm/pit.s | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 asm/pit.h create mode 100644 asm/pit.s diff --git a/asm/asm.h b/asm/asm.h index cc1d99d..8433e4e 100644 --- a/asm/asm.h +++ b/asm/asm.h @@ -1,9 +1,11 @@ void pic_setup(); + void int_kb_handler(); void int_mouse_handler(); void int_default_handler(); -void int_clock_handler(); + void int_syscall_handler(); + void int_irq0(); void int_irq1(); void int_irq2(); diff --git a/asm/pit.h b/asm/pit.h new file mode 100644 index 0000000..0bec3c4 --- /dev/null +++ b/asm/pit.h @@ -0,0 +1,25 @@ +/** + * @file + * + * PIT - Programmable Interval Timer + * + * config out timer on channel 0 : mode 2 (sys timer) + * * http://en.wikipedia.org/wiki/Intel_8253#Control_Word_Register + * * http://www.brokenthorn.com/Resources/OSDevPit.html + * int0 will be triggered ~25 times a second. + * + * The most magic is performed in pit_interrupt_handler which calls + * the c function responsible for task switching doing vary bad ass + * magic... + */ + +#include + +/** Init PIT - 25 times a second*/ +void pit_init(); + +/** install this interrupt handler to your Interrupt Vector Table */ +void pit_interrupt_handler(); + +/** get number of ticks */ +uint32_t pit_get_ticks(); diff --git a/asm/pit.s b/asm/pit.s new file mode 100644 index 0000000..ab8dcdb --- /dev/null +++ b/asm/pit.s @@ -0,0 +1,59 @@ +.global pit_init +.global pit_interrupt_handler +.global pit_get_ticks + +ticks: +.int 0 + +pit_get_ticks: + + mov (ticks),%eax + ret + +pit_interrupt_handler: + + // increase tick counter + push %eax + mov $ticks, %eax + incl (%eax) + pop %eax + + //// + + pusha //Push all standard registers + + mov %esp, %eax //save current stack pointer (pointing to registers!) + + movl $stack_top, %esp //use stack from multiboot.s(16Kb) + + // call our scheduler passing it the old stack addres (pointing to pushed registers (pusha)) + push %eax + call task_switch_next + + // the scheduler returned the new stack pointer (after taskswitch) + mov %eax, %esp //Replace the stack with what the C code gave us + + // acknowlege irq + mov $0x20,%al + out %al,$0x20 + + popa //Put the standard registers back + + iret + +pit_init: + + // configure ticking 25 times a second + // 1193180 / 25 = 47727.2 + mov $47727, %dx + + mov $0b00110100, %al + outb %al,$0x43 + + mov %dx,%ax + + out %al, $0x40 + xchg %ah,%al + out %al, $0x40 + + ret -- cgit v1.2.3