2018-12-19 16:13:47 +01:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
|
|
|
/* */
|
|
|
|
#include "interrupts.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "asm.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "vga.h"
|
|
|
|
#include "gdt.h"
|
2018-12-20 16:29:04 +01:00
|
|
|
#include "process.h"
|
2018-12-19 16:13:47 +01:00
|
|
|
|
|
|
|
static u8 curs[4] = { "-\\|/" };
|
|
|
|
|
|
|
|
static u8 curspos = 0;
|
|
|
|
|
|
|
|
static u32 time = 0;
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Récupère la valeur du timer */
|
|
|
|
/* SYSCALL
|
|
|
|
{
|
|
|
|
"ID":4,
|
|
|
|
"NAME":"getticks",
|
|
|
|
"LIBRARY":"libsys",
|
|
|
|
"INTERNALNAME":"gettimer",
|
|
|
|
"DESCRIPTION":"Return the internal value of the timer",
|
|
|
|
"ARGS": [],
|
|
|
|
"RETURN":"u32"
|
|
|
|
}
|
|
|
|
END */
|
|
|
|
|
|
|
|
u32 gettimer(void)
|
|
|
|
{
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Handler d'interruption du timer IRQ 0 */
|
|
|
|
|
|
|
|
__attribute__ ((noreturn)) void timer_handler(regs *dump)
|
|
|
|
{
|
|
|
|
exception_stack_noerror *caller = (exception_stack_noerror*) ((u32*)dump->esp+1);
|
|
|
|
bool noerror,user;
|
|
|
|
if (caller->cs==SEL_KERNEL_CODE || caller->cs==SEL_USER_CODE)
|
|
|
|
{
|
|
|
|
noerror=true;
|
|
|
|
dump->eip = caller->eip;
|
|
|
|
dump->cs = caller->cs;
|
|
|
|
dump->eflags = caller->eflags;
|
|
|
|
if (dump->cs==SEL_KERNEL_CODE)
|
|
|
|
{
|
|
|
|
dump->esp = (u32) caller + sizeof(exception_stack_noerror);
|
|
|
|
user=false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dump->esp = (u32) ((exception_stack_noerror_user*) caller)->esp;
|
|
|
|
dump->ss = (u32) ((exception_stack_noerror_user*) caller)->ss;
|
|
|
|
user=true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
noerror=false;
|
|
|
|
dump->eip = ((exception_stack*)caller)->eip;
|
|
|
|
dump->cs = ((exception_stack*)caller)->cs;
|
|
|
|
if (dump->cs==SEL_KERNEL_CODE)
|
|
|
|
{
|
|
|
|
dump->esp = (u32) caller + sizeof(exception_stack);
|
|
|
|
user=false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dump->esp = (u32) ((exception_stack_user*) caller)->esp;
|
|
|
|
dump->ss = (u32) ((exception_stack_user*) caller)->ss;
|
|
|
|
user=true;
|
|
|
|
}
|
|
|
|
}
|
2018-12-20 16:29:04 +01:00
|
|
|
irqendmaster();
|
2018-12-19 16:13:47 +01:00
|
|
|
showchar(0, 0, curs[curspos], 7);
|
|
|
|
curspos = (curspos + 1) & 0x3;
|
|
|
|
time++;
|
2018-12-22 00:19:34 +01:00
|
|
|
task *new=getschedule();
|
2018-12-20 16:29:04 +01:00
|
|
|
if (new!=NULL)
|
|
|
|
{
|
|
|
|
task *old=findcurrenttask();
|
2018-12-22 00:19:34 +01:00
|
|
|
memcpy(dump, &old->dump, sizeof(regs), 0);
|
2018-12-20 16:29:04 +01:00
|
|
|
switchtask(new->tid);
|
|
|
|
}
|
2018-12-19 16:13:47 +01:00
|
|
|
if (dump->cs==SEL_KERNEL_CODE)
|
2018-12-20 16:29:04 +01:00
|
|
|
{
|
|
|
|
setESP(dump);
|
|
|
|
restcpu_kernel();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setESP(dump);
|
|
|
|
restcpu_user();
|
|
|
|
iret();
|
|
|
|
}
|
2018-12-19 16:13:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************/
|