2018-09-28 20:35:51 +02:00
|
|
|
/*******************************************************************************/
|
|
|
|
/* COS2000 - Compatible Operating System - LGPL v3 - Hordé Nicolas */
|
|
|
|
/* */
|
2018-08-17 16:46:56 +02:00
|
|
|
#include "interrupts.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "asm.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "video.h"
|
2018-10-02 02:16:14 +02:00
|
|
|
#include "gdt.h"
|
2018-10-02 13:49:10 +02:00
|
|
|
#include "system.h"
|
2018-10-09 18:13:04 +02:00
|
|
|
#include "debug.h"
|
2018-12-10 17:03:52 +01:00
|
|
|
#include "process.h"
|
2018-12-15 19:13:26 +01:00
|
|
|
#include "handlers.h"
|
2018-08-17 16:46:56 +02:00
|
|
|
|
2018-10-02 02:16:14 +02:00
|
|
|
#define IDT_SIZE 256 /* nombre de descripteurs */
|
2018-09-01 22:58:05 +02:00
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
/* registre idt */
|
2018-08-31 02:48:03 +02:00
|
|
|
static struct idtr idtreg;
|
2018-08-17 16:46:56 +02:00
|
|
|
|
|
|
|
/* table de IDT */
|
2018-10-02 02:16:14 +02:00
|
|
|
static idtdes idt[IDT_SIZE];
|
2018-08-17 16:46:56 +02:00
|
|
|
|
2018-10-02 13:49:10 +02:00
|
|
|
static u32 retry_address;
|
|
|
|
|
2018-12-16 01:50:03 +01:00
|
|
|
extern wrapper_exception0;
|
|
|
|
extern wrapper_exception1;
|
|
|
|
extern wrapper_exception2;
|
|
|
|
extern wrapper_exception3;
|
|
|
|
extern wrapper_exception4;
|
|
|
|
extern wrapper_exception5;
|
|
|
|
extern wrapper_exception6;
|
|
|
|
extern wrapper_exception7;
|
|
|
|
extern wrapper_exception8;
|
|
|
|
extern wrapper_exception9;
|
|
|
|
extern wrapper_exception10;
|
|
|
|
extern wrapper_exception11;
|
|
|
|
extern wrapper_exception12;
|
|
|
|
extern wrapper_exception13;
|
|
|
|
extern wrapper_exception14;
|
|
|
|
extern wrapper_exception15;
|
|
|
|
extern wrapper_exception16;
|
|
|
|
extern wrapper_exception17;
|
|
|
|
extern wrapper_exception18;
|
2018-12-19 16:13:47 +01:00
|
|
|
extern wrapper_interruption;
|
2018-10-02 13:49:10 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Initialise la reprise après erreur */
|
|
|
|
|
|
|
|
void initretry(u32 address)
|
|
|
|
{
|
2018-12-12 15:25:04 +01:00
|
|
|
retry_address = address;
|
2018-10-02 13:49:10 +02:00
|
|
|
}
|
|
|
|
|
2018-12-12 10:14:31 +01:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Récupère l'adresse de reprise après erreur */
|
|
|
|
|
|
|
|
u32 getinitretry(void)
|
|
|
|
{
|
2018-12-12 15:25:04 +01:00
|
|
|
return retry_address;
|
2018-12-12 10:14:31 +01:00
|
|
|
}
|
|
|
|
|
2018-08-17 16:46:56 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
/* Initialise le controleur d'interruption 8259A */
|
|
|
|
|
|
|
|
void initpic(void)
|
|
|
|
{
|
|
|
|
/* MASTER */
|
|
|
|
/* Initialisation de ICW1 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC1_CMD, ICW1_INIT + ICW1_ICW4);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* Initialisation de ICW2 - vecteur de depart = 32 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC1_DATA, 0x20);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* Initialisation de ICW3 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC1_DATA, 0x04);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* Initialisation de ICW4 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC1_DATA, ICW4_8086);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* masquage des interruptions */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC1_DATA, 0xFF);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* SLAVE */
|
|
|
|
/* Initialisation de ICW1 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC2_CMD, ICW1_INIT + ICW1_ICW4);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* Initialisation de ICW2 - vecteur de depart = 96 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC2_DATA, 0x60);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* Initialisation de ICW3 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC2_DATA, 0x02);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* Initialisation de ICW4 */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC2_DATA, ICW4_8086);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* masquage des interruptions */
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC2_DATA, 0xFF);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
/* Demasquage des irqs sauf clavier
|
2018-08-28 15:22:43 +02:00
|
|
|
outb(PIC1_DATA,0xFD);
|
2018-08-17 16:46:56 +02:00
|
|
|
nop();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Active une IRQ */
|
|
|
|
|
|
|
|
void enableirq(u8 irq)
|
|
|
|
{
|
2018-12-12 15:25:04 +01:00
|
|
|
u16 port;
|
2018-08-17 16:46:56 +02:00
|
|
|
cli();
|
2018-08-28 15:22:43 +02:00
|
|
|
port = (((irq & 0x08) << 4) + PIC1_DATA);
|
2018-08-17 16:46:56 +02:00
|
|
|
outb(port, inb(port) & ~(1 << (irq & 7)));
|
|
|
|
sti();
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Désactive une IRQ */
|
|
|
|
|
|
|
|
void disableirq(u8 irq)
|
|
|
|
{
|
2018-12-12 15:25:04 +01:00
|
|
|
u16 port;
|
2018-08-17 16:46:56 +02:00
|
|
|
cli();
|
2018-08-28 15:22:43 +02:00
|
|
|
port = (((irq & 0x08) << 4) + PIC1_DATA);
|
2018-08-17 16:46:56 +02:00
|
|
|
outb(port, inb(port) | (1 << (irq & 7)));
|
|
|
|
sti();
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
/* Créé un descripteur pour l'IDT */
|
|
|
|
|
|
|
|
void makeidtdes(u32 offset, u16 select, u16 type, idtdes * desc)
|
|
|
|
{
|
|
|
|
desc->offset0_15 = (offset & 0xffff);
|
|
|
|
desc->select = select;
|
|
|
|
desc->type = type;
|
|
|
|
desc->offset16_31 = (offset & 0xffff0000) >> 16;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Change une entrée dans l'IDT */
|
|
|
|
|
|
|
|
void setidt(u32 offset, u16 select, u16 type, u16 index)
|
|
|
|
{
|
|
|
|
cli();
|
|
|
|
idtdes *desc;
|
|
|
|
desc = idtreg.base;
|
|
|
|
desc[index].offset0_15 = (offset & 0xffff);
|
|
|
|
desc[index].select = select;
|
|
|
|
desc[index].type = type;
|
|
|
|
desc[index].offset16_31 = (offset & 0xffff0000) >> 16;
|
|
|
|
sti();
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Met une entrée dans l'IDT */
|
|
|
|
|
|
|
|
void putidt(u32 offset, u16 select, u16 type, u16 index)
|
|
|
|
{
|
2018-12-12 15:25:04 +01:00
|
|
|
idtdes temp;
|
2018-08-17 16:46:56 +02:00
|
|
|
makeidtdes(offset, select, type, &temp);
|
|
|
|
idt[index] = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* Initialise une IDT */
|
|
|
|
|
|
|
|
void initidt(void)
|
|
|
|
{
|
2018-12-12 15:25:04 +01:00
|
|
|
u16 i;
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception0, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 0);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception1, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 1);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception2, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 2);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception3, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 3);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception4, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 4);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception5, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 5);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception6, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 6);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception7, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 7);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception8, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 8);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception9, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 9);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception10, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 10);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception11, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 11);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception12, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 12);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception13, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 13);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception14, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 14);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception15, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 15);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception16, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 16);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception17, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 17);
|
2018-12-16 01:50:03 +01:00
|
|
|
putidt((u32) &wrapper_exception18, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 18);
|
|
|
|
for (i = 19; i < 32; i++)
|
|
|
|
{
|
2018-12-19 16:13:47 +01:00
|
|
|
putidt((u32) &wrapper_interruption, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING3 | TRAPGATE, i);
|
2018-08-17 16:46:56 +02:00
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
putidt((u32) irq0, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 32);
|
|
|
|
putidt((u32) irq1, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 33);
|
|
|
|
putidt((u32) irq2, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 34);
|
|
|
|
putidt((u32) irq3, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 35);
|
|
|
|
putidt((u32) irq4, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 36);
|
|
|
|
putidt((u32) irq5, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 37);
|
|
|
|
putidt((u32) irq6, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 38);
|
|
|
|
putidt((u32) irq7, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 39);
|
|
|
|
for (i = 40; i < 96; i++)
|
|
|
|
{
|
2018-12-19 16:13:47 +01:00
|
|
|
putidt((u32) &wrapper_interruption, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING3 | TRAPGATE, i);
|
2018-08-17 16:46:56 +02:00
|
|
|
}
|
2018-12-12 15:25:04 +01:00
|
|
|
putidt((u32) irq8, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 96);
|
|
|
|
putidt((u32) irq9, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 97);
|
|
|
|
putidt((u32) irq10, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 98);
|
|
|
|
putidt((u32) irq11, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 99);
|
|
|
|
putidt((u32) irq12, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 100);
|
|
|
|
putidt((u32) irq13, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 101);
|
|
|
|
putidt((u32) irq14, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 102);
|
|
|
|
putidt((u32) irq15, SEL_KERNEL_CODE,
|
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | INTGATE, 103);
|
|
|
|
for (i = 104; i < IDT_SIZE; i++)
|
|
|
|
{
|
2018-12-19 16:13:47 +01:00
|
|
|
putidt((u32) &wrapper_interruption, SEL_KERNEL_CODE,
|
2018-12-12 15:25:04 +01:00
|
|
|
ENTRY_PRESENT | ENTRY_RING0 | TRAPGATE, i);
|
2018-08-17 16:46:56 +02:00
|
|
|
}
|
|
|
|
/* initialise le registre idt */
|
2018-10-04 14:55:41 +02:00
|
|
|
idtreg.limite = IDT_SIZE * sizeof(idtdes);
|
2018-10-02 02:16:14 +02:00
|
|
|
idtreg.base = IDT_ADDR;
|
2018-08-17 16:46:56 +02:00
|
|
|
/* recopie de la IDT a son adresse */
|
|
|
|
memcpy(&idt, (u8 *) idtreg.base, idtreg.limite, 1);
|
|
|
|
/* chargement du registre IDTR */
|
2018-12-25 19:22:56 +01:00
|
|
|
lidt(idtreg);
|
2018-08-17 16:46:56 +02:00
|
|
|
}
|
2018-08-28 15:22:43 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
/* 8253/8254 PIT (Programmable Interval Timer) Timer ajustable */
|
|
|
|
|
2018-09-28 20:35:51 +02:00
|
|
|
void inittimer(void)
|
2018-08-28 15:22:43 +02:00
|
|
|
{
|
2018-12-12 15:25:04 +01:00
|
|
|
u32 divisor = TIMER_FREQ / HZ;
|
2018-09-27 17:47:27 +02:00
|
|
|
outb(TIMER_MODE, RATE_GENERATOR);
|
2018-11-14 22:23:10 +01:00
|
|
|
outb(TIMER0, (u8) divisor);
|
|
|
|
outb(TIMER0, (u8) (divisor >> 8));
|
2018-08-28 15:22:43 +02:00
|
|
|
}
|
2018-09-28 20:35:51 +02:00
|
|
|
/*******************************************************************************/
|