CTAOS v6
This commit is contained in:
217
SysCore/drivers/cpu/isrs/isrs.asm
Normal file
217
SysCore/drivers/cpu/isrs/isrs.asm
Normal file
@@ -0,0 +1,217 @@
|
||||
bits 32
|
||||
|
||||
; !!! ISRs !!!
|
||||
global _i86_isr0
|
||||
global _i86_isr1
|
||||
global _i86_isr2
|
||||
global _i86_isr3
|
||||
global _i86_isr4
|
||||
global _i86_isr5
|
||||
global _i86_isr6
|
||||
global _i86_isr7
|
||||
global _i86_isr8
|
||||
global _i86_isr9
|
||||
global _i86_isr10
|
||||
global _i86_isr11
|
||||
global _i86_isr12
|
||||
global _i86_isr13
|
||||
global _i86_isr14
|
||||
global _i86_isr15
|
||||
global _i86_isr16
|
||||
global _i86_isr17
|
||||
global _i86_isr18
|
||||
global _i86_isr19
|
||||
global _i86_isr20
|
||||
global _i86_isr21
|
||||
global _i86_isr22
|
||||
global _i86_isr23
|
||||
global _i86_isr24
|
||||
global _i86_isr25
|
||||
global _i86_isr26
|
||||
global _i86_isr27
|
||||
global _i86_isr28
|
||||
global _i86_isr29
|
||||
global _i86_isr30
|
||||
global _i86_isr31
|
||||
|
||||
_i86_isr0:
|
||||
cli
|
||||
push byte 0; A normal ISR stub that pops a dummy error code to keep a
|
||||
; uniform stack frame
|
||||
push byte 0
|
||||
jmp isr_common_stub
|
||||
_i86_isr1:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 1
|
||||
jmp isr_common_stub
|
||||
_i86_isr2:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 2
|
||||
jmp isr_common_stub
|
||||
_i86_isr3:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 3
|
||||
jmp isr_common_stub
|
||||
_i86_isr4:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 4
|
||||
jmp isr_common_stub
|
||||
_i86_isr5:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 5
|
||||
jmp isr_common_stub
|
||||
_i86_isr6:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 6
|
||||
jmp isr_common_stub
|
||||
_i86_isr7:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 7
|
||||
jmp isr_common_stub
|
||||
_i86_isr8:
|
||||
cli
|
||||
push byte 8
|
||||
jmp isr_common_stub
|
||||
_i86_isr9:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 9
|
||||
jmp isr_common_stub
|
||||
_i86_isr10:
|
||||
cli
|
||||
push byte 10
|
||||
jmp isr_common_stub
|
||||
_i86_isr11:
|
||||
cli
|
||||
push byte 11
|
||||
jmp isr_common_stub
|
||||
_i86_isr12:
|
||||
cli
|
||||
push byte 12
|
||||
jmp isr_common_stub
|
||||
_i86_isr13:
|
||||
cli
|
||||
push byte 13
|
||||
jmp isr_common_stub
|
||||
_i86_isr14:
|
||||
cli
|
||||
push byte 14
|
||||
jmp isr_common_stub
|
||||
_i86_isr15:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 15
|
||||
jmp isr_common_stub
|
||||
_i86_isr16:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 16
|
||||
jmp isr_common_stub
|
||||
_i86_isr17:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 17
|
||||
jmp isr_common_stub
|
||||
_i86_isr18:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 18
|
||||
jmp isr_common_stub
|
||||
_i86_isr19:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 19
|
||||
jmp isr_common_stub
|
||||
_i86_isr20:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 20
|
||||
jmp isr_common_stub
|
||||
_i86_isr21:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 21
|
||||
jmp isr_common_stub
|
||||
_i86_isr22:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 22
|
||||
jmp isr_common_stub
|
||||
_i86_isr23:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 23
|
||||
jmp isr_common_stub
|
||||
_i86_isr24:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 24
|
||||
jmp isr_common_stub
|
||||
_i86_isr25:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 25
|
||||
jmp isr_common_stub
|
||||
_i86_isr26:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 26
|
||||
jmp isr_common_stub
|
||||
_i86_isr27:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 27
|
||||
jmp isr_common_stub
|
||||
_i86_isr28:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 28
|
||||
jmp isr_common_stub
|
||||
_i86_isr29:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 29
|
||||
jmp isr_common_stub
|
||||
_i86_isr30:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 30
|
||||
jmp isr_common_stub
|
||||
_i86_isr31:
|
||||
cli
|
||||
push byte 0
|
||||
push byte 31
|
||||
jmp isr_common_stub
|
||||
|
||||
extern _i86_FaultHandler
|
||||
|
||||
isr_common_stub:
|
||||
pusha
|
||||
push ds
|
||||
push es
|
||||
push fs
|
||||
push gs
|
||||
mov ax, 0x10 ; Load the Kernel Data Segment descriptor!
|
||||
mov ds, ax
|
||||
mov es, ax
|
||||
mov fs, ax
|
||||
mov gs, ax
|
||||
mov eax, esp ; Push us the stack
|
||||
push eax
|
||||
mov eax, _i86_FaultHandler
|
||||
call eax ; A special call, preserves the 'eip' register
|
||||
pop eax
|
||||
pop gs
|
||||
pop fs
|
||||
pop es
|
||||
pop ds
|
||||
popa
|
||||
add esp, 8 ; Cleans up the pushed error code and pushed ISR number
|
||||
iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP!
|
115
SysCore/drivers/cpu/isrs/isrs.c
Normal file
115
SysCore/drivers/cpu/isrs/isrs.c
Normal file
@@ -0,0 +1,115 @@
|
||||
#include <system.h>
|
||||
#include <conio.h>
|
||||
#include "isrs.h"
|
||||
#include "../idt/idt.h"
|
||||
|
||||
// Assembly coded
|
||||
extern void i86_isr0();
|
||||
extern void i86_isr1();
|
||||
extern void i86_isr2();
|
||||
extern void i86_isr3();
|
||||
extern void i86_isr4();
|
||||
extern void i86_isr5();
|
||||
extern void i86_isr6();
|
||||
extern void i86_isr7();
|
||||
extern void i86_isr8();
|
||||
extern void i86_isr9();
|
||||
extern void i86_isr10();
|
||||
extern void i86_isr11();
|
||||
extern void i86_isr12();
|
||||
extern void i86_isr13();
|
||||
extern void i86_isr14();
|
||||
extern void i86_isr15();
|
||||
extern void i86_isr16();
|
||||
extern void i86_isr17();
|
||||
extern void i86_isr18();
|
||||
extern void i86_isr19();
|
||||
extern void i86_isr20();
|
||||
extern void i86_isr21();
|
||||
extern void i86_isr22();
|
||||
extern void i86_isr23();
|
||||
extern void i86_isr24();
|
||||
extern void i86_isr25();
|
||||
extern void i86_isr26();
|
||||
extern void i86_isr27();
|
||||
extern void i86_isr28();
|
||||
extern void i86_isr29();
|
||||
extern void i86_isr30();
|
||||
extern void i86_isr31();
|
||||
|
||||
|
||||
void* IdtFaultHandlers[32] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
void i86_IsrsInstall()
|
||||
{
|
||||
i86_IdtSetGate(0, (unsigned)i86_isr0, 0x08, 0x8E);
|
||||
i86_IdtSetGate(1, (unsigned)i86_isr1, 0x08, 0x8E);
|
||||
i86_IdtSetGate(2, (unsigned)i86_isr2, 0x08, 0x8E);
|
||||
i86_IdtSetGate(3, (unsigned)i86_isr3, 0x08, 0x8E);
|
||||
i86_IdtSetGate(4, (unsigned)i86_isr4, 0x08, 0x8E);
|
||||
i86_IdtSetGate(5, (unsigned)i86_isr5, 0x08, 0x8E);
|
||||
i86_IdtSetGate(6, (unsigned)i86_isr6, 0x08, 0x8E);
|
||||
i86_IdtSetGate(7, (unsigned)i86_isr7, 0x08, 0x8E);
|
||||
i86_IdtSetGate(8, (unsigned)i86_isr8, 0x08, 0x8E);
|
||||
i86_IdtSetGate(9, (unsigned)i86_isr9, 0x08, 0x8E);
|
||||
i86_IdtSetGate(10, (unsigned)i86_isr10, 0x08, 0x8E);
|
||||
i86_IdtSetGate(11, (unsigned)i86_isr11, 0x08, 0x8E);
|
||||
i86_IdtSetGate(12, (unsigned)i86_isr12, 0x08, 0x8E);
|
||||
i86_IdtSetGate(13, (unsigned)i86_isr13, 0x08, 0x8E);
|
||||
i86_IdtSetGate(14, (unsigned)i86_isr14, 0x08, 0x8E);
|
||||
i86_IdtSetGate(15, (unsigned)i86_isr15, 0x08, 0x8E);
|
||||
i86_IdtSetGate(16, (unsigned)i86_isr16, 0x08, 0x8E);
|
||||
i86_IdtSetGate(17, (unsigned)i86_isr17, 0x08, 0x8E);
|
||||
i86_IdtSetGate(18, (unsigned)i86_isr18, 0x08, 0x8E);
|
||||
i86_IdtSetGate(19, (unsigned)i86_isr19, 0x08, 0x8E);
|
||||
i86_IdtSetGate(20, (unsigned)i86_isr20, 0x08, 0x8E);
|
||||
i86_IdtSetGate(21, (unsigned)i86_isr21, 0x08, 0x8E);
|
||||
i86_IdtSetGate(22, (unsigned)i86_isr22, 0x08, 0x8E);
|
||||
i86_IdtSetGate(23, (unsigned)i86_isr23, 0x08, 0x8E);
|
||||
i86_IdtSetGate(24, (unsigned)i86_isr24, 0x08, 0x8E);
|
||||
i86_IdtSetGate(25, (unsigned)i86_isr25, 0x08, 0x8E);
|
||||
i86_IdtSetGate(26, (unsigned)i86_isr26, 0x08, 0x8E);
|
||||
i86_IdtSetGate(27, (unsigned)i86_isr27, 0x08, 0x8E);
|
||||
i86_IdtSetGate(28, (unsigned)i86_isr28, 0x08, 0x8E);
|
||||
i86_IdtSetGate(29, (unsigned)i86_isr29, 0x08, 0x8E);
|
||||
i86_IdtSetGate(30, (unsigned)i86_isr30, 0x08, 0x8E);
|
||||
i86_IdtSetGate(31, (unsigned)i86_isr31, 0x08, 0x8E);
|
||||
}
|
||||
|
||||
|
||||
void i86_IsrsInstallHandler(int interr, void (*function)(ISR_stack_regs *r))
|
||||
{
|
||||
if (interr < 32) IdtFaultHandlers[interr] = function;
|
||||
}
|
||||
|
||||
void i86_IsrsUninstallHandler(int interr)
|
||||
{
|
||||
if (interr < 32) IdtFaultHandlers[interr] = 0;
|
||||
}
|
||||
|
||||
/* All of our Exception handling Interrupt Service Routines will
|
||||
* point to this function. This will tell us what exception has
|
||||
* happened! Right now, we simply halt the system by hitting an
|
||||
* endless loop. All ISRs disable interrupts while they are being
|
||||
* serviced as a 'locking' mechanism to prevent an IRQ from
|
||||
* happening and messing up kernel data structures */
|
||||
void i86_FaultHandler(ISR_stack_regs *r)
|
||||
{
|
||||
/* Is this a fault whose number is from 0 to 31? */
|
||||
if (r->int_no < 32)
|
||||
{
|
||||
void (*func)(ISR_stack_regs *r);
|
||||
func = IdtFaultHandlers[r->int_no];
|
||||
|
||||
// Halt system if unhandled
|
||||
if (!func) {
|
||||
cprintf("%#0C*** %#0EFatal error: Unhandled interrupt (INT%u)", r->int_no);
|
||||
for(;;);
|
||||
}
|
||||
|
||||
else (*func)(r);
|
||||
}
|
||||
}
|
8
SysCore/drivers/cpu/isrs/isrs.h
Normal file
8
SysCore/drivers/cpu/isrs/isrs.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef __ISRS_H_
|
||||
#define __ISRS_H_
|
||||
|
||||
extern void i86_IsrsInstall();
|
||||
extern void i86_IsrsInstallHandler(int interr, void (*function)(ISR_stack_regs *r));
|
||||
extern void i86_IsrsUninstallHandler(int interr);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user