did some restructuring, got multitasking almost working
This commit is contained in:
@@ -1,23 +1,61 @@
|
||||
#include "lib/print.h"
|
||||
#include <stdint.h>
|
||||
|
||||
extern void send_eoi_master(void);
|
||||
extern void send_eoi_slave(void);
|
||||
extern uint8_t read_isr_master(void);
|
||||
extern uint8_t read_isr_slave(void);
|
||||
#include <lib/print.h>
|
||||
|
||||
extern uint8_t ps2_read_data();
|
||||
#include "syscall.h"
|
||||
|
||||
struct registers {
|
||||
#include <drivers/pic/pic.h>
|
||||
#include <drivers/ps2/ps2.h>
|
||||
|
||||
#define IDT_MAX_DESCRIPTORS 256
|
||||
#define ATTR_KERN_32 0x8E // active(1), ring 0 (00), interrupt gate(0), 32 bit (1110)
|
||||
#define ATTR_USER_32 0xEE // active, ring 3, 32bit
|
||||
#define SEGMENT_KERN 0x08
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t isr_low;
|
||||
uint16_t selector;
|
||||
uint8_t reserved;
|
||||
uint8_t attributes;
|
||||
uint16_t isr_high;
|
||||
} idt_entry;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint16_t limit;
|
||||
uint32_t base;
|
||||
} idt_ptr;
|
||||
|
||||
typedef struct __attribute__((packed)) {
|
||||
uint32_t edi, esi, ebp, esp_dummy, ebx, edx, ecx, eax;
|
||||
|
||||
uint32_t int_no;
|
||||
uint32_t error_code;
|
||||
|
||||
uint32_t eip, cs, eflags, useresp, ss;
|
||||
} registers;
|
||||
|
||||
extern void load_idt(void);
|
||||
|
||||
// isr stubs
|
||||
extern void isr0();
|
||||
extern void isr1();
|
||||
extern void isr8();
|
||||
extern void isr13();
|
||||
extern void isr14();
|
||||
extern void isr32();
|
||||
extern void isr33();
|
||||
|
||||
static void* isr_stub_table[256] = {
|
||||
[0] = isr0,
|
||||
[1] = isr1,
|
||||
[8] = isr8,
|
||||
[13] = isr13,
|
||||
[14] = isr14,
|
||||
[32] = isr32,
|
||||
[33] = isr33,
|
||||
};
|
||||
|
||||
const char* err_messages[32] = {
|
||||
static const char* err_messages[32] = {
|
||||
[0] = "Divide by 0",
|
||||
[1] = "",
|
||||
[8] = "",
|
||||
@@ -25,7 +63,37 @@ const char* err_messages[32] = {
|
||||
[14] = "Page Fault",
|
||||
};
|
||||
|
||||
void common_interrupt_handler(struct registers *args) {
|
||||
idt_entry idt[IDT_MAX_DESCRIPTORS];
|
||||
idt_ptr idtr;
|
||||
|
||||
static void set_idtr(uint8_t vector, void* isr, uint16_t sel, uint8_t attributes) {
|
||||
idt_entry* desc = &idt[vector];
|
||||
|
||||
desc->isr_low = (uint32_t)isr & 0xFFFF;
|
||||
desc->selector = SEGMENT_KERN;
|
||||
desc->reserved = 0;
|
||||
desc->attributes = attributes;
|
||||
desc->isr_high = ((uint32_t)isr >> 16) & 0xFFFF;
|
||||
}
|
||||
|
||||
void init_idt() {
|
||||
idtr.limit = (sizeof(idt_entry) * IDT_MAX_DESCRIPTORS) - 1;
|
||||
idtr.base = (uint32_t)&idt;
|
||||
|
||||
for (int i = 0; i < IDT_MAX_DESCRIPTORS; i++) {
|
||||
if (isr_stub_table[i] != 0) {
|
||||
set_idtr(i, isr_stub_table[i], SEGMENT_KERN, ATTR_KERN_32);
|
||||
} else {
|
||||
set_idtr(i, 0, SEGMENT_KERN, 0);
|
||||
}
|
||||
}
|
||||
|
||||
set_idtr(0x80, syscall_handler, SEGMENT_KERN, ATTR_USER_32);
|
||||
|
||||
load_idt();
|
||||
}
|
||||
|
||||
void common_interrupt_handler(registers *args) {
|
||||
switch (args->int_no) {
|
||||
case 0:
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user