Created include in i386, tables -> dt
This commit is contained in:
parent
1c7483925c
commit
aea8d99518
|
@ -1,6 +1,4 @@
|
|||
#include "idt.h"
|
||||
|
||||
#include "types/idt_types.h"
|
||||
#include "i386/idt.h"
|
||||
|
||||
/* Data structures used to fill the IDT. */
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
#ifndef TABLES_ISR_TYPES_H_
|
||||
#define TABLES_ISR_TYPES_H_
|
||||
#ifndef CONTEXT_H_
|
||||
#define CONTEXT_H_
|
||||
|
||||
#include "stdint.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/* register_t - data type containg the context before calling an ISR. */
|
||||
/* register_t - data type containg the context before calling an ISR or IRQ. */
|
||||
|
||||
struct registers {
|
||||
struct context {
|
||||
|
||||
uint32_t ds;
|
||||
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
|
||||
|
@ -14,6 +14,6 @@ struct registers {
|
|||
|
||||
} __attribute__((packed));
|
||||
|
||||
typedef struct registers register_t;
|
||||
typedef struct context context_t;
|
||||
|
||||
#endif
|
|
@ -1,13 +1,9 @@
|
|||
#ifndef INTRPT_IDT_H_
|
||||
#define INTRPT_IDT_H_
|
||||
#ifndef INTRPT_H_
|
||||
#define INTRPT_H_
|
||||
|
||||
#include "stdint.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* idt_entry_t - entry in Interrupt Descriptor Table
|
||||
* idt_set_gate - creates an IDT entry
|
||||
*
|
||||
*/
|
||||
/* idt_entry_t - entry in Interrupt Descriptor Table */
|
||||
|
||||
struct idt_entry_struct {
|
||||
|
||||
|
@ -21,6 +17,15 @@ struct idt_entry_struct {
|
|||
|
||||
typedef struct idt_entry_struct idt_entry_t;
|
||||
|
||||
/*
|
||||
* idt_set_gate:
|
||||
* Creates an IDT entry
|
||||
*
|
||||
* @oaram base - Base of the IDT entry
|
||||
* @param sel - Segment selector
|
||||
* @param flags - Flags
|
||||
*
|
||||
*/
|
||||
|
||||
static inline idt_entry_t idt_set_gate(uint32_t base, uint16_t sel, uint8_t flags) {
|
||||
|
||||
|
@ -35,6 +40,7 @@ static inline idt_entry_t idt_set_gate(uint32_t base, uint16_t sel, uint8_t flag
|
|||
return entry;
|
||||
}
|
||||
|
||||
|
||||
/* idt_ptr_t - IDT pointer that will be loaded in CPU */
|
||||
|
||||
struct idt_ptr_struct {
|
||||
|
@ -46,4 +52,13 @@ struct idt_ptr_struct {
|
|||
|
||||
typedef struct idt_ptr_struct idt_ptr_t;
|
||||
|
||||
/*
|
||||
* idt_init:
|
||||
* Creates an array of 256 empty entries that will be loaded in the CPU as
|
||||
* an IDT.
|
||||
*
|
||||
*/
|
||||
|
||||
void idt_init(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,45 @@
|
|||
#ifndef IRQ_H_
|
||||
#define IRQ_H_
|
||||
|
||||
#include "context.h"
|
||||
|
||||
#define IRQ0 32
|
||||
#define IRQ1 33
|
||||
#define IRQ2 34
|
||||
#define IRQ3 35
|
||||
#define IRQ4 36
|
||||
#define IRQ5 37
|
||||
#define IRQ6 38
|
||||
#define IRQ7 39
|
||||
#define IRQ8 40
|
||||
#define IRQ9 41
|
||||
#define IRQ10 42
|
||||
#define IRQ11 43
|
||||
#define IRQ12 44
|
||||
#define IRQ13 45
|
||||
#define IRQ14 46
|
||||
#define IRQ15 47
|
||||
|
||||
/*
|
||||
* irq_init:
|
||||
* Initializes the PIC and puts pointers to IRQ gates in IDT.
|
||||
*
|
||||
*/
|
||||
|
||||
void irq_init(void);
|
||||
|
||||
/* Function typedef for IRQ handlers. */
|
||||
|
||||
typedef void (*irq_t)(context_t);
|
||||
|
||||
/*
|
||||
* register_irq:
|
||||
* Creates a handler for an IRQ with IRQ number irq_no.
|
||||
*
|
||||
* @param irq_no - IRQ number
|
||||
*
|
||||
*/
|
||||
|
||||
void register_irq(uint8_t irq_no, irq_t handler);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,62 @@
|
|||
#ifndef PIC_H_
|
||||
#define PIC_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/memio.h"
|
||||
|
||||
/* Master and slave PIC I/O ports. */
|
||||
|
||||
#define PIC1 0x20
|
||||
#define PIC2 0xA0
|
||||
|
||||
/* Command and data port for each PIC. */
|
||||
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1 + 1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2 + 1)
|
||||
|
||||
/* PIC Initialization Command Words. */
|
||||
|
||||
#define ICW1_ICW4 0x01
|
||||
#define ICW1_SINGLE 0X02
|
||||
#define ICW1_INTERVAL4 0x04
|
||||
#define ICW1_LEVEL 0X08
|
||||
#define ICW1_INIT 0X10
|
||||
|
||||
#define ICW3_SLAVE_IRQ 0x04
|
||||
#define ICW3_SLAVE_ID 0X02
|
||||
|
||||
#define ICW4_8086 0x01
|
||||
#define ICW4_AUTO 0x02
|
||||
#define ICW4_BUF_SLAVE 0x08
|
||||
#define ICW4_BUF_MASTER 0x0C
|
||||
#define ICW4_SFNM 0x10
|
||||
|
||||
/* End of Interrupt. */
|
||||
|
||||
#define PIC_EOI 0X20
|
||||
|
||||
/*
|
||||
* pic_remap:
|
||||
* Initializes and remaps the master and slave PICs.
|
||||
*
|
||||
* @param offset1 - offset for master PIC in IDT
|
||||
* @param offset2 - offset for slave PIC in IDT
|
||||
*
|
||||
*/
|
||||
|
||||
void pic_remap(uint8_t offset1, uint8_t offset2);
|
||||
|
||||
/*
|
||||
* pic_send_eoi:
|
||||
* Sends EOI signal to PICs.
|
||||
*
|
||||
* @param irq - IRQ number
|
||||
*
|
||||
*/
|
||||
|
||||
void pic_send_eoi(uint8_t irq);
|
||||
|
||||
#endif
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef INTRPT_H_
|
||||
#define INTRPT_H_
|
||||
|
||||
/*
|
||||
* idt_init:
|
||||
* Creates an array of 256 empty entries that will be loaded in the CPU as
|
||||
* an IDT.
|
||||
*
|
||||
*/
|
||||
|
||||
void idt_init(void);
|
||||
|
||||
#endif
|
|
@ -1,143 +0,0 @@
|
|||
#include "isr.h"
|
||||
#include "idt.h"
|
||||
#include "types/idt_types.h"
|
||||
#include "types/isr_types.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Extern symbol defined in idt.c */
|
||||
|
||||
extern idt_entry_t idt_entries[256];
|
||||
|
||||
/* External Interrupt Service Routines. */
|
||||
|
||||
extern void isr0();
|
||||
extern void isr1();
|
||||
extern void isr2();
|
||||
extern void isr3();
|
||||
extern void isr4();
|
||||
extern void isr5();
|
||||
extern void isr6();
|
||||
extern void isr7();
|
||||
extern void isr8();
|
||||
extern void isr9();
|
||||
extern void isr10();
|
||||
extern void isr11();
|
||||
extern void isr12();
|
||||
extern void isr13();
|
||||
extern void isr14();
|
||||
extern void isr15();
|
||||
extern void isr16();
|
||||
extern void isr17();
|
||||
extern void isr18();
|
||||
extern void isr19();
|
||||
extern void isr20();
|
||||
extern void isr21();
|
||||
extern void isr22();
|
||||
extern void isr23();
|
||||
extern void isr24();
|
||||
extern void isr25();
|
||||
extern void isr26();
|
||||
extern void isr27();
|
||||
extern void isr28();
|
||||
extern void isr29();
|
||||
extern void isr30();
|
||||
extern void isr31();
|
||||
|
||||
/*
|
||||
* isr_init:
|
||||
* ---------
|
||||
*
|
||||
* Fill the first 32 entries in IDT.
|
||||
*
|
||||
*/
|
||||
|
||||
void isr_init(void) {
|
||||
|
||||
idt_entries[0] = idt_set_gate((uint32_t) isr0, 0x08, 0x8E);
|
||||
idt_entries[1] = idt_set_gate((uint32_t) isr1, 0x08, 0x8E);
|
||||
idt_entries[2] = idt_set_gate((uint32_t) isr2, 0x08, 0x8E);
|
||||
idt_entries[3] = idt_set_gate((uint32_t) isr3, 0x08, 0x8E);
|
||||
idt_entries[4] = idt_set_gate((uint32_t) isr4, 0x08, 0x8E);
|
||||
idt_entries[5] = idt_set_gate((uint32_t) isr5, 0x08, 0x8E);
|
||||
idt_entries[6] = idt_set_gate((uint32_t) isr6, 0x08, 0x8E);
|
||||
idt_entries[7] = idt_set_gate((uint32_t) isr7, 0x08, 0x8E);
|
||||
idt_entries[8] = idt_set_gate((uint32_t) isr8, 0x08, 0x8E);
|
||||
idt_entries[9] = idt_set_gate((uint32_t) isr9, 0x08, 0x8E);
|
||||
idt_entries[10] = idt_set_gate( (uint32_t) isr10, 0x08, 0x8E);
|
||||
idt_entries[11] = idt_set_gate( (uint32_t) isr11, 0x08, 0x8E);
|
||||
idt_entries[12] = idt_set_gate( (uint32_t) isr12, 0x08, 0x8E);
|
||||
idt_entries[13] = idt_set_gate( (uint32_t) isr13, 0x08, 0x8E);
|
||||
idt_entries[14] = idt_set_gate( (uint32_t) isr14, 0x08, 0x8E);
|
||||
idt_entries[15] = idt_set_gate( (uint32_t) isr15, 0x08, 0x8E);
|
||||
idt_entries[16] = idt_set_gate( (uint32_t) isr16, 0x08, 0x8E);
|
||||
idt_entries[17] = idt_set_gate( (uint32_t) isr17, 0x08, 0x8E);
|
||||
idt_entries[18] = idt_set_gate( (uint32_t) isr18, 0x08, 0x8E);
|
||||
idt_entries[19] = idt_set_gate( (uint32_t) isr19, 0x08, 0x8E);
|
||||
idt_entries[20] = idt_set_gate( (uint32_t) isr20, 0x08, 0x8E);
|
||||
idt_entries[21] = idt_set_gate( (uint32_t) isr21, 0x08, 0x8E);
|
||||
idt_entries[22] = idt_set_gate( (uint32_t) isr22, 0x08, 0x8E);
|
||||
idt_entries[23] = idt_set_gate( (uint32_t) isr23, 0x08, 0x8E);
|
||||
idt_entries[24] = idt_set_gate( (uint32_t) isr24, 0x08, 0x8E);
|
||||
idt_entries[25] = idt_set_gate( (uint32_t) isr25, 0x08, 0x8E);
|
||||
idt_entries[26] = idt_set_gate( (uint32_t) isr26, 0x08, 0x8E);
|
||||
idt_entries[27] = idt_set_gate( (uint32_t) isr27, 0x08, 0x8E);
|
||||
idt_entries[28] = idt_set_gate( (uint32_t) isr28, 0x08, 0x8E);
|
||||
idt_entries[29] = idt_set_gate( (uint32_t) isr29, 0x08, 0x8E);
|
||||
idt_entries[30] = idt_set_gate( (uint32_t) isr30, 0x08, 0x8E);
|
||||
idt_entries[31] = idt_set_gate( (uint32_t) isr31, 0x08, 0x8E);
|
||||
|
||||
}
|
||||
|
||||
/* Exception messages for unhandled faults. */
|
||||
|
||||
char *exception_messages[] = {
|
||||
"Division by zero",
|
||||
"Debug",
|
||||
"Non-maskable interrupt",
|
||||
"Breakpoint",
|
||||
"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"
|
||||
};
|
||||
|
||||
/* isr_handler:
|
||||
* Handles an incomming request by calling the appropiate handler or printing
|
||||
* an exception message.
|
||||
*
|
||||
* @param context - the context of the caller
|
||||
*
|
||||
*/
|
||||
|
||||
void isr_handler(register_t context) {
|
||||
|
||||
printf("Unhandled exception: %s\n", exception_messages[context.int_no]);
|
||||
|
||||
}
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
.extern isr_handler
|
||||
|
||||
/* Macros that define the entry point in ISRs with and without an error code. */
|
||||
|
||||
.macro ISR_NO_ERRCODE _isr_nr
|
||||
.global isr\_isr_nr
|
||||
isr\_isr_nr:
|
||||
cli
|
||||
push $0x00
|
||||
push $\_isr_nr
|
||||
jmp isr_common_stub
|
||||
.endm
|
||||
|
||||
.macro ISR_ERRCODE _isr_nr
|
||||
.global isr\_isr_nr
|
||||
isr\_isr_nr:
|
||||
cli
|
||||
push $\_isr_nr
|
||||
jmp isr_common_stub
|
||||
.endm
|
||||
|
||||
/* Expandation of the above mentioned macros. */
|
||||
|
||||
ISR_NO_ERRCODE 0
|
||||
ISR_NO_ERRCODE 1
|
||||
ISR_NO_ERRCODE 2
|
||||
ISR_NO_ERRCODE 3
|
||||
ISR_NO_ERRCODE 4
|
||||
ISR_NO_ERRCODE 5
|
||||
ISR_NO_ERRCODE 6
|
||||
ISR_NO_ERRCODE 7
|
||||
ISR_ERRCODE 8
|
||||
ISR_NO_ERRCODE 9
|
||||
ISR_ERRCODE 10
|
||||
ISR_ERRCODE 11
|
||||
ISR_ERRCODE 12
|
||||
ISR_ERRCODE 13
|
||||
ISR_ERRCODE 14
|
||||
ISR_NO_ERRCODE 15
|
||||
ISR_NO_ERRCODE 16
|
||||
ISR_NO_ERRCODE 17
|
||||
ISR_NO_ERRCODE 18
|
||||
ISR_NO_ERRCODE 19
|
||||
ISR_NO_ERRCODE 20
|
||||
ISR_NO_ERRCODE 21
|
||||
ISR_NO_ERRCODE 22
|
||||
ISR_NO_ERRCODE 23
|
||||
ISR_NO_ERRCODE 24
|
||||
ISR_NO_ERRCODE 25
|
||||
ISR_NO_ERRCODE 26
|
||||
ISR_NO_ERRCODE 27
|
||||
ISR_NO_ERRCODE 28
|
||||
ISR_NO_ERRCODE 29
|
||||
ISR_NO_ERRCODE 30
|
||||
ISR_NO_ERRCODE 31
|
||||
|
||||
/*
|
||||
* Stub for ISRs. It must push the context on the stack and change the PL.
|
||||
* After the isr_handler was called the context will be restored and the
|
||||
* error code and the request number will be cleared from the stack.
|
||||
*
|
||||
*/
|
||||
|
||||
isr_common_stub:
|
||||
|
||||
pusha
|
||||
|
||||
mov %ds, %ax
|
||||
push %eax
|
||||
|
||||
mov $0x10, %ax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %fs
|
||||
mov %ax, %gs
|
||||
|
||||
call isr_handler
|
||||
|
||||
pop %eax
|
||||
mov %ax, %ds
|
||||
mov %ax, %es
|
||||
mov %ax, %fs
|
||||
mov %ax, %gs
|
||||
|
||||
popa
|
||||
add $0x08, %esp
|
||||
|
||||
sti
|
||||
iret
|
Loading…
Reference in New Issue