139 lines
3.1 KiB
C
139 lines
3.1 KiB
C
/*
|
|
Copyright 2022 Mattia Giambirtone & Contributors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
#ifndef TSOS_CPU_ISR_H
|
|
#define TSOS_CPU_ISR_H
|
|
|
|
#include "kernel/types.h"
|
|
|
|
/*
|
|
The first 32 ISRs are reserved for CPU exceptions, so we
|
|
manually forward-declare them. They will be implemented in
|
|
assembly (hence why "extern" is explicit here, despite it
|
|
being the default for C functions)
|
|
*/
|
|
|
|
extern void isr0(void);
|
|
extern void isr1(void);
|
|
extern void isr2(void);
|
|
extern void isr3(void);
|
|
extern void isr4(void);
|
|
extern void isr5(void);
|
|
extern void isr6(void);
|
|
extern void isr7(void);
|
|
extern void isr8(void);
|
|
extern void isr9(void);
|
|
extern void isr10(void);
|
|
extern void isr11(void);
|
|
extern void isr12(void);
|
|
extern void isr13(void);
|
|
extern void isr14(void);
|
|
extern void isr15(void);
|
|
extern void isr16(void);
|
|
extern void isr17(void);
|
|
extern void isr18(void);
|
|
extern void isr19(void);
|
|
extern void isr20(void);
|
|
extern void isr21(void);
|
|
extern void isr22(void);
|
|
extern void isr23(void);
|
|
extern void isr24(void);
|
|
extern void isr25(void);
|
|
extern void isr26(void);
|
|
extern void isr27(void);
|
|
extern void isr28(void);
|
|
extern void isr29(void);
|
|
extern void isr30(void);
|
|
extern void isr31(void);
|
|
|
|
|
|
typedef struct {
|
|
/*
|
|
A wrapper around the metadata
|
|
that we pass to ISRs (from asm)
|
|
when they're called
|
|
*/
|
|
|
|
u32 ds; /* The DS register */
|
|
/* General Purpose registers saved by pusha */
|
|
u32 edi;
|
|
u32 esi;
|
|
u32 ebp;
|
|
u32 esp;
|
|
u32 ebx;
|
|
u32 edx;
|
|
u32 ecx;
|
|
u32 eax;
|
|
u32 kind; /* The interrupt number */
|
|
u32 err; /* The interrupt's error code (optional, may be zero) */
|
|
/*
|
|
These are pushed by the processor automatically when an interrupt
|
|
is triggered
|
|
*/
|
|
u32 eip;
|
|
u32 cs;
|
|
u32 eflags;
|
|
u32 useresp;
|
|
u32 ss;
|
|
} ISRMetadata;
|
|
|
|
|
|
void installDefaultHandlers(void);
|
|
void interruptHandler(ISRMetadata data);
|
|
|
|
// Maps each builtin ISR number to an error message
|
|
char* errorMessages[] = {
|
|
"Division By Zero",
|
|
"Debug",
|
|
"Non Maskable Interrupt",
|
|
"Breakpoint",
|
|
"Into Detected Overflow",
|
|
"Out of Bounds",
|
|
"Invalid Opcode",
|
|
"No Coprocessor",
|
|
|
|
"Double Fault",
|
|
"Coprocessor Segment Overrun",
|
|
"Bad TSS",
|
|
"Segment Not Present",
|
|
"Stack Fault",
|
|
"General Protection Fault",
|
|
"Page Fault",
|
|
"Unknown Interrupt",
|
|
|
|
"Coprocessor Fault",
|
|
"Alignment Check",
|
|
"Machine Check",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved",
|
|
"Reserved"
|
|
};
|
|
|
|
#define interruptMessage(x) errorMessages[x]
|
|
|
|
|
|
#endif |