diff options
| -rw-r--r-- | asm/int_clock_handler.asm | 23 | ||||
| -rw-r--r-- | driver/serial.c | 1 | ||||
| -rw-r--r-- | kernel/interrupts.c | 3 | ||||
| -rw-r--r-- | kernel/task.c | 7 | ||||
| -rw-r--r-- | kernel/timer.c | 93 | ||||
| -rw-r--r-- | kernel/timer.h | 8 |
6 files changed, 26 insertions, 109 deletions
diff --git a/asm/int_clock_handler.asm b/asm/int_clock_handler.asm deleted file mode 100644 index f6c056a..0000000 --- a/asm/int_clock_handler.asm +++ /dev/null @@ -1,23 +0,0 @@ -global int_clock_handler -[extern task_switch_next] - -[bits 32] - -int_clock_handler: - -pusha ;Push all standard registers - -mov eax, esp ;save current stack pointer in esp -mov esp, 0x7000 ;now put the stack outside of virtual memory in kernel space! - -push eax ;Push pointer to all the stuff we just pushed -call task_switch_next ;Call C code - -mov esp, eax ;Replace the stack with what the C code gave us - -mov al, 0x20 ;Port number AND command number to Acknowledge IRQ -out 0x20, al ;Acknowledge IRQ, so we keep getting interrupts - -popa ;Put the standard registers back - -iretd ;Interrupt-Return diff --git a/driver/serial.c b/driver/serial.c index 6e6a4bb..8747981 100644 --- a/driver/serial.c +++ b/driver/serial.c @@ -15,7 +15,6 @@ void serial_init() x86_outb(PORT + 3, 0x03); // 8 bits, no parity, one stop bit x86_outb(PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold x86_outb(PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set - } static uint32_t serial_received() diff --git a/kernel/interrupts.c b/kernel/interrupts.c index 46883d6..96446f3 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -3,6 +3,7 @@ #include "lib/logger/log.h" // logger facilities #include "asm/asm.h" +#include "asm/pit.h" #include "driver/mouse.h" #include "interrupts.h" #include "asm/x86.h" @@ -152,7 +153,7 @@ void int_init(uint16_t sel) // remember that we shifted all interrupts with the pic by 32 // install PIT interrupt handler (irq 0 => 32) - int_install_ir(32, 0b10001110, 0x08,&int_clock_handler); + int_install_ir(32, 0b10001110, 0x08,&pit_interrupt_handler); // install keyboard interrupt handler (irq 1 => 33) int_install_ir(33, 0b10001110, 0x08,&int_kb_handler); diff --git a/kernel/task.c b/kernel/task.c index 3c1e067..c281821 100644 --- a/kernel/task.c +++ b/kernel/task.c @@ -80,16 +80,9 @@ volatile uint32_t my_scheduler(uint32_t oldesp) // this gets called by our clock interrupt regularly! volatile uint32_t task_switch_next(uint32_t oldesp) { - -// syscall_write(1,"*tick*",10); - timer_tick(); - - // check if multitasking has been started if(current_task<0)return oldesp; - return my_scheduler(oldesp); - } //TODO: free vmem too! diff --git a/kernel/timer.c b/kernel/timer.c index 2bf1592..2d4c7ff 100644 --- a/kernel/timer.c +++ b/kernel/timer.c @@ -3,40 +3,7 @@ #include "asm/x86.h" -//TODO: volatile? spinlock? -static volatile uint64_t task_system_clock=0; static volatile uint64_t task_system_clock_start=0; -static volatile uint8_t interrupts_on = 0; - -// interrupt handler (do NOT call yourself!) -void timer_tick() -{ - task_system_clock++; - interrupts_on=1; -} - -// get value -uint64_t timer_get_ticks() -{ - uint64_t ret; -// x86_cli(); // do not disturb by timer_tick! - ret=task_system_clock; - // if(interrupts_on!=0)x86_sti(); // reenable (if clock was running already) - return ret; -} - -uint64_t timer_get_ms() -{ - uint64_t t=timer_get_ticks(); - uint64_t s=t/25; - uint64_t ms=t*1000/25-s*1000; - return s*1000+ms; -} - -uint64_t timer_get_uptime_ms() -{ - return timer_get_ms()-task_system_clock_start*1000; -} // CMOS RTC @@ -55,16 +22,16 @@ static int get_rtc_update_flag() { // get real time clock rom cmos (seconds since jan) static uint64_t get_rtc_time() { - int CURRENT_YEAR = 2018; // Change this each year! + int CURRENT_YEAR = 2018; // Change this each year! - int century_register = 0x00; // Set by ACPI table parsing code if possible + int century_register = 0x00; // Set by ACPI table parsing code if possible - unsigned char second; - unsigned char minute; - unsigned char hour; - unsigned char day; - unsigned char month; - unsigned int year; + unsigned char second; + unsigned char minute; + unsigned char hour; + unsigned char day; + unsigned char month; + unsigned int year; unsigned char century; unsigned char last_second; @@ -142,8 +109,6 @@ static uint64_t get_rtc_time() if(year < CURRENT_YEAR) year += 100; } - // return ((((uint64_t)year-1970)*356;//+month*30+day)*24+hour*60+minute)*60+second; - // thank you doug16k @ #osdev // https://github.com/doug65536/dgos/blob/eab7080e69360493381669e7ce0ff27587d3127a/kernel/lib/time.cc int days[] = { @@ -182,41 +147,21 @@ static uint64_t get_rtc_time() } -// TODO: put in asm file! -static void timer_config() -{ - __asm__("pusha"); - - __asm__("mov %0, %%dx"::"X" (1193180 / 25)); - - __asm__("mov $0b00110100, %al"); - __asm__("out %al,$0x43"); - - __asm__("mov %dx,%ax"); - - __asm__("out %al, $0x40"); - __asm__("xchg %ah,%al"); - __asm__("out %al, $0x40"); - - __asm__("popa"); - -} - // PIT uint64_t timer_init() { uint64_t epoch_time=get_rtc_time(); + task_system_clock_start=epoch_time*25; // since pit ticks 25times a second + pit_init(); + return epoch_time; +} - task_system_clock_start=epoch_time; - task_system_clock=epoch_time*25; - - timer_config(); +uint64_t timer_get_ms() +{ + return (pit_get_ticks()+task_system_clock_start)*40; +} - // 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. - - //log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"Configured PIT Channel 0 : Mode 2 : 1/25 s."); - return epoch_time; +uint64_t timer_get_uptime_ms() +{ + return pit_get_ticks()*40; } diff --git a/kernel/timer.h b/kernel/timer.h index 15488ff..1e3d066 100644 --- a/kernel/timer.h +++ b/kernel/timer.h @@ -1,9 +1,11 @@ /** * @file -/// PIT /// Timer stuff // CMOS - http://www.brokenthorn.com/Resources/OSDevPit.html - https://wiki.osdev.org/CMOS + * References + * ---------- + * * http://www.brokenthorn.com/Resources/OSDevPit.html + * * https://wiki.osdev.org/CMOS + vcc/gnd - voltage/ground |
