mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2024-11-22 06:06:52 -08:00
Fixed a lot of errors, and redesigned most of the ISR and IDTs.
This commit is contained in:
parent
5c2e3146a6
commit
07c0c99a48
@ -1,29 +0,0 @@
|
||||
---
|
||||
Language: C
|
||||
Standard: C11 (or C17)
|
||||
BasedOnStyle: LLVM
|
||||
IndentWidth: 4
|
||||
UseTab: Never
|
||||
TabWidth: 4
|
||||
BreakBeforeBraces: Allman
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignConsecutiveMacros: true
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortNamespaceContentsOnASingleLine: false
|
||||
AllowShortTemplateFunctionsOnASingleLine: false
|
||||
AllowShortTypeConstraintsOnASingleLine: false
|
||||
AllowShortVariablesOnASingleLine: false
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: true
|
@ -46,6 +46,7 @@ set(DRIVERS_SOURCE_FILES
|
||||
src/drivers/display/display.c
|
||||
src/drivers/display/display.h
|
||||
src/drivers/io/io.c
|
||||
src/drivers/io/io.asm
|
||||
src/drivers/io/io.h
|
||||
src/drivers/keyboard/keyboard.c
|
||||
src/drivers/keyboard/keyboard.h
|
||||
@ -62,9 +63,12 @@ set(KERNEL_SOURCE_FILES
|
||||
src/kernel/arch/x86/gdt.c
|
||||
src/kernel/arch/x86/gdt.c
|
||||
src/kernel/arch/x86/idt.c
|
||||
src/kernel/arch/x86/idt.asm
|
||||
src/kernel/arch/x86/idt.h
|
||||
src/kernel/arch/x86/isr.c
|
||||
src/kernel/arch/x86/isr.h
|
||||
src/kernel/arch/x86/isr/isr.c
|
||||
src/kernel/arch/x86/isr/isr.h
|
||||
src/kernel/arch/x86/isr/exceptions.c
|
||||
src/kernel/arch/x86/isr/exceptions.h
|
||||
src/kernel/kernel.c
|
||||
src/kernel/kernel.h
|
||||
src/kernel/linker.ld
|
||||
@ -101,7 +105,6 @@ add_executable(ClassicOS
|
||||
${GRUB_SOURCE_FILES}
|
||||
${DRIVERS_SOURCE_FILES}
|
||||
${KERNEL_SOURCE_FILES}
|
||||
${UTIL_SOURCE_FILES}
|
||||
)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
@ -55,7 +55,7 @@ double Math::Sqrt(const double from)
|
||||
|
||||
float Math::Sqrt(const float from)
|
||||
{
|
||||
#if defined(ARCH_X64)
|
||||
#if defined(ARCH_X64) || defined(ARCH_X86)
|
||||
if (CPU::HasAVX())
|
||||
return Sqrt_AVX(from);
|
||||
else if (CPU::HasSSE())
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "sys/cpu.h"
|
||||
#include "sys/CPU.h"
|
||||
|
||||
#define LOW_WORD(x) *((int*)&x) + 1
|
||||
|
||||
|
@ -1,61 +1,61 @@
|
||||
global _ZN3lwe4Math8Sqrt_AVXEf
|
||||
global _ZN3lwe4Math8Sqrt_AVXEd
|
||||
global _ZN3lwe4Math8Sqrt_SSEEf
|
||||
global _ZN3lwe4Math9Sqrt_SSE2Ed
|
||||
global _ZN3lwe4Math4NearEf
|
||||
global _ZN3lwe4Math4NearEd
|
||||
global _ZN3lwe4Math5FloorEf
|
||||
global _ZN3lwe4Math5FloorEd
|
||||
global _ZN3lwe4Math4CeilEf
|
||||
global _ZN3lwe4Math4CeilEd
|
||||
global _ZN3lwe4Math5TruncEf
|
||||
global _ZN3lwe4Math5TruncEd
|
||||
global _ZN3Math8Sqrt_AVXEf
|
||||
global _ZN3Math8Sqrt_AVXEd
|
||||
global _ZN3Math8Sqrt_SSEEf
|
||||
global _ZN3Math9Sqrt_SSE2Ed
|
||||
global _ZN3Math4NearEf
|
||||
global _ZN3Math4NearEd
|
||||
global _ZN3Math5FloorEf
|
||||
global _ZN3Math5FloorEd
|
||||
global _ZN3Math4CeilEf
|
||||
global _ZN3Math4CeilEd
|
||||
global _ZN3Math5TruncEf
|
||||
global _ZN3Math5TruncEd
|
||||
|
||||
section .text
|
||||
_ZN3lwe4Math8Sqrt_AVXEf:
|
||||
_ZN3Math8Sqrt_AVXEf:
|
||||
VSQRTPS XMM0, XMM0
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math8Sqrt_AVXEd:
|
||||
_ZN3Math8Sqrt_AVXEd:
|
||||
VSQRTPD XMM0, XMM0
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math8Sqrt_SSEEf:
|
||||
_ZN3Math8Sqrt_SSEEf:
|
||||
SQRTPS XMM0, XMM0
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math9Sqrt_SSE2Ed:
|
||||
_ZN3Math9Sqrt_SSE2Ed:
|
||||
SQRTPD XMM0, XMM0
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math4NearEf:
|
||||
_ZN3Math4NearEf:
|
||||
ROUNDPS XMM0, XMM0, 0
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math4NearEd:
|
||||
_ZN3Math4NearEd:
|
||||
ROUNDPD XMM0, XMM0, 0
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math5FloorEf:
|
||||
_ZN3Math5FloorEf:
|
||||
ROUNDPS XMM0, XMM0, 1
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math5FloorEd:
|
||||
_ZN3Math5FloorEd:
|
||||
ROUNDPD XMM0, XMM0, 1
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math4CeilEf:
|
||||
_ZN3Math4CeilEf:
|
||||
ROUNDPS XMM0, XMM0, 2
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math4CeilEd:
|
||||
_ZN3Math4CeilEd:
|
||||
ROUNDPD XMM0, XMM0, 2
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math5TruncEf:
|
||||
_ZN3Math5TruncEf:
|
||||
ROUNDPS XMM0, XMM0, 3
|
||||
RET
|
||||
|
||||
_ZN3lwe4Math5TruncEd:
|
||||
_ZN3Math5TruncEd:
|
||||
ROUNDPD XMM0, XMM0, 3
|
||||
RET
|
13
src/drivers/io/io.asm
Normal file
13
src/drivers/io/io.asm
Normal file
@ -0,0 +1,13 @@
|
||||
global inb
|
||||
global outb
|
||||
|
||||
inb:
|
||||
MOV DX, WORD [ESP + 16]
|
||||
IN AL, DX
|
||||
RET
|
||||
|
||||
outb:
|
||||
MOV DX, WORD [ESP + 16]
|
||||
MOV AL, BYTE [ESP + 24]
|
||||
OUT DX, AL
|
||||
RET
|
@ -19,8 +19,10 @@ char io_read_lpt();
|
||||
void io_write_lpt(char data);
|
||||
|
||||
// Function declarations for keyboard.c
|
||||
uint8_t inb(uint16_t port);
|
||||
void outb(uint16_t port, uint8_t data);
|
||||
extern uint8_t inb(uint16_t port);
|
||||
|
||||
extern void outb(uint16_t port, uint8_t data);
|
||||
|
||||
void install_interrupt_handler(uint8_t interrupt, void (*handler)(void));
|
||||
|
||||
#endif /* IO_H */
|
@ -21,21 +21,20 @@ static size_t keyboard_buffer_tail = 0;
|
||||
void set_interrupt_vector(uint8_t vector, void (*handler)());
|
||||
void enable_interrupt(uint8_t vector);
|
||||
|
||||
// Keyboard interrupt handler
|
||||
void keyboard_interrupt_handler()
|
||||
void KeyboardInterruptHandler()
|
||||
{
|
||||
uint8_t scancode = inb(KEYBOARD_DATA_PORT);
|
||||
uint8_t scancode = inb(KEYBOARD_DATA_PORT);
|
||||
|
||||
// Add scancode to buffer
|
||||
keyboard_buffer[keyboard_buffer_head] = scancode;
|
||||
keyboard_buffer_head = (keyboard_buffer_head + 1) % KEYBOARD_BUFFER_SIZE;
|
||||
// Add scancode to buffer
|
||||
keyboard_buffer[keyboard_buffer_head] = scancode;
|
||||
keyboard_buffer_head = (keyboard_buffer_head + 1) % KEYBOARD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
// Initialize keyboard
|
||||
void keyboard_init()
|
||||
{
|
||||
// Install keyboard interrupt handler
|
||||
set_interrupt_vector(KEYBOARD_INTERRUPT_VECTOR, keyboard_interrupt_handler);
|
||||
set_interrupt_vector(KEYBOARD_INTERRUPT_VECTOR, KeyboardInterruptHandler);
|
||||
enable_interrupt(KEYBOARD_INTERRUPT_VECTOR);
|
||||
|
||||
// Enable keyboard
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void KeyboardInterruptHandler();
|
||||
|
||||
void keyboard_init();
|
||||
bool keyboard_buffer_empty();
|
||||
uint8_t keyboard_read_scancode();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "gdt.h"
|
||||
#include "idt.h"
|
||||
#include "isr.h"
|
||||
#include "isr/isr.h"
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
@ -90,31 +90,3 @@ extern void system_call();
|
||||
extern void timer();
|
||||
extern void keyboard();
|
||||
extern void device();
|
||||
|
||||
// Register an ISR
|
||||
void isr_register(uint8_t num, void (*handler)(struct isr_regs *))
|
||||
{
|
||||
isr_table[num] = handler;
|
||||
}
|
||||
|
||||
void divide_error(struct idt_regs *regs)
|
||||
{
|
||||
printf("Divide by zero error!\n");
|
||||
// Additional actions can be taken as needed
|
||||
}
|
||||
|
||||
// Initialize the ISR
|
||||
void isr_init()
|
||||
{
|
||||
// Register exception handlers
|
||||
isr_register(0, divide_error);
|
||||
isr_register(PAGE_FAULT, page_fault);
|
||||
isr_register(13, general_protection_fault);
|
||||
isr_register(DOUBLE_FAULT, double_fault);
|
||||
|
||||
// Register interrupt handlers
|
||||
isr_register(SYSTEM_CALL, system_call);
|
||||
isr_register(TIMER, timer);
|
||||
isr_register(0x21, keyboard);
|
||||
isr_register(0x30, device);
|
||||
}
|
||||
|
5
src/kernel/arch/x86/idt.asm
Normal file
5
src/kernel/arch/x86/idt.asm
Normal file
@ -0,0 +1,5 @@
|
||||
global LoadIDT
|
||||
|
||||
LoadIDT:
|
||||
LIDT [ESP + 32]
|
||||
RET
|
@ -1,75 +1,19 @@
|
||||
#include "idt.h"
|
||||
#include "isr.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "isr/isr.h"
|
||||
#include "../../../drivers/keyboard/keyboard.h"
|
||||
|
||||
enum
|
||||
{
|
||||
GDT_ACCESS_PRESENT = 0x80,
|
||||
BASE_MIDDLE_SHIFT = 16,
|
||||
BYTE_MASK = 0xFF
|
||||
};
|
||||
|
||||
// IDT table
|
||||
struct idt_entry idt[256];
|
||||
|
||||
// IDT pointer
|
||||
const struct idt_ptr idtp = {sizeof(idt) - 1, idt};
|
||||
|
||||
// Exception handlers
|
||||
extern void divide_error_handler();
|
||||
extern void page_fault(struct idt_regs *regs);
|
||||
extern void general_protection_fault_handler();
|
||||
extern void double_fault_handler();
|
||||
|
||||
// Interrupt handlers
|
||||
extern void system_call_handler();
|
||||
extern void timer_handler();
|
||||
extern void keyboard_handler();
|
||||
extern void device_handler();
|
||||
extern void network_handler();
|
||||
extern void disk_handler();
|
||||
extern void serial_port_handler();
|
||||
|
||||
// Initialize an IDT entry
|
||||
void idt_set_gate(uint8_t num, void *base, uint16_t sel, uint8_t flags)
|
||||
{
|
||||
uintptr_t base_addr = (uintptr_t)base;
|
||||
idt[num].base_lo = base_addr & BYTE_MASK;
|
||||
idt[num].base_hi = (base_addr >> BASE_MIDDLE_SHIFT) & 0xFFFF;
|
||||
idt[num].sel = sel;
|
||||
idt[num].always0 = 0;
|
||||
idt[num].flags = flags;
|
||||
}
|
||||
extern void LoadIDT(struct idt_entry* entry);
|
||||
|
||||
// Initialize the IDT
|
||||
void idt_init()
|
||||
void InitializeIDT()
|
||||
{
|
||||
// Clear IDT
|
||||
#ifdef __STDC_LIB_EXT1__
|
||||
memset_s(idt, 0, sizeof(idt));
|
||||
#else
|
||||
memset(idt, 0, sizeof(idt));
|
||||
#endif
|
||||
idt[KEYBOARD_INTERRUPT].base_lo = ((uint16_t*)KeyboardInterruptHandler)[0];
|
||||
idt[KEYBOARD_INTERRUPT].sel = 0x08;
|
||||
idt[KEYBOARD_INTERRUPT].always0 = 0x00;
|
||||
idt[KEYBOARD_INTERRUPT].flags = 0x8E;
|
||||
idt[KEYBOARD_INTERRUPT].base_hi = ((uint16_t*)KeyboardInterruptHandler)[1];
|
||||
|
||||
// Set up exception handlers
|
||||
idt_set_gate(0, divide_error_handler, 0x08, 0x8E);
|
||||
idt_set_gate(14, page_fault, 0x08, 0x8E);
|
||||
idt_set_gate(13, general_protection_fault_handler, 0x08, 0x8E);
|
||||
idt_set_gate(8, double_fault_handler, 0x08, 0x8E);
|
||||
|
||||
// Set up interrupt handlers
|
||||
idt_set_gate(0x80, system_call_handler, 0x08, 0xEE);
|
||||
idt_set_gate(0x20, timer_handler, 0x08, 0x8E);
|
||||
idt_set_gate(0x21, keyboard_handler, 0x08, 0x8E);
|
||||
idt_set_gate(0x22, network_handler, 0x08, 0x8E);
|
||||
idt_set_gate(0x23, disk_handler, 0x08, 0x8E);
|
||||
idt_set_gate(0x24, serial_port_handler, 0x08, 0x8E);
|
||||
|
||||
// Load IDT
|
||||
__asm__ volatile("lidt %0" : : "m"(idtp));
|
||||
LoadIDT(&idt[KEYBOARD_INTERRUPT]);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
#ifndef IDT_H
|
||||
#define IDT_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "isr.h"
|
||||
#include "include/types.h"
|
||||
|
||||
// IDT entry structure
|
||||
struct idt_entry
|
||||
{
|
||||
@ -13,26 +13,9 @@ struct idt_entry
|
||||
uint16_t base_hi; // Upper 16 bits of handler function address
|
||||
} __attribute__((packed));
|
||||
|
||||
// IDT pointer structure
|
||||
struct idt_ptr
|
||||
{
|
||||
uint16_t limit; // Size of IDT in bytes - 1
|
||||
struct idt_entry *base; // Address of IDT
|
||||
} __attribute__((packed));
|
||||
|
||||
// Exception handlers
|
||||
void divide_error(struct idt_regs *regs);
|
||||
void double_fault();
|
||||
|
||||
// Interrupt handlers
|
||||
void timer();
|
||||
void keyboard();
|
||||
void device();
|
||||
void network();
|
||||
void disk();
|
||||
void serial_port();
|
||||
extern struct idt_entry idt[256];
|
||||
|
||||
// Initialize the IDT
|
||||
void idt_init();
|
||||
void InitializeIDT();
|
||||
|
||||
#endif /* IDT_H */
|
@ -1,8 +0,0 @@
|
||||
#ifndef INTERRUPT_UTILS_H
|
||||
#define INTERRUPT_UTILS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t read_interrupt_type(void);
|
||||
|
||||
#endif /* INTERRUPT_UTILS_H */
|
@ -1,190 +0,0 @@
|
||||
#include "isr.h"
|
||||
#include "idt.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "./interrupt_utils.h"
|
||||
|
||||
void invalid_opcode(void);
|
||||
void general_protection_fault(struct idt_regs *regs);
|
||||
void page_fault(struct idt_regs *regs);
|
||||
void system_call(struct idt_regs *regs);
|
||||
|
||||
enum
|
||||
{
|
||||
TIMER_INTERRUPT = 0x20,
|
||||
KEYBOARD_INTERRUPT = 0x21,
|
||||
NETWORK_INTERRUPT = 0x22,
|
||||
DISK_INTERRUPT = 0x23,
|
||||
SERIAL_PORT_INTERRUPT = 0x24
|
||||
};
|
||||
|
||||
void dummy_isr(struct isr_regs *regs)
|
||||
{
|
||||
printf("Timer interrupt occurred!\n");
|
||||
}
|
||||
|
||||
// Register an ISR
|
||||
extern void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs))
|
||||
{
|
||||
isr_table[num] = handler;
|
||||
}
|
||||
|
||||
// ISR handler
|
||||
void isr_handler(struct idt_regs *regs)
|
||||
{
|
||||
switch (regs->int_no)
|
||||
{
|
||||
case 0x00:
|
||||
divide_error(regs);
|
||||
break;
|
||||
case 0x06:
|
||||
invalid_opcode();
|
||||
break;
|
||||
case 0x0D:
|
||||
general_protection_fault(regs);
|
||||
break;
|
||||
case 0x0E:
|
||||
page_fault(regs);
|
||||
break;
|
||||
case 0x08:
|
||||
double_fault();
|
||||
break;
|
||||
case 0x80:
|
||||
system_call(regs);
|
||||
break;
|
||||
case 0x20:
|
||||
timer();
|
||||
break;
|
||||
case 0x21:
|
||||
keyboard();
|
||||
break;
|
||||
case 0x2F:
|
||||
device();
|
||||
break;
|
||||
case 0x28:
|
||||
network();
|
||||
break;
|
||||
case 0x2E:
|
||||
disk();
|
||||
break;
|
||||
case 0x24:
|
||||
serial_port();
|
||||
break;
|
||||
default:
|
||||
printf("Unhandled interrupt: %d\n", regs->int_no);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Exception handlers
|
||||
void divide_error(struct idt_regs *regs)
|
||||
{
|
||||
printf("Divide by zero error!\n");
|
||||
// Additional actions can be taken as needed
|
||||
}
|
||||
|
||||
void page_fault(struct idt_regs *regs)
|
||||
{
|
||||
uint32_t faulting_address;
|
||||
|
||||
// Read the CR2 register to get the faulting address
|
||||
__asm__ volatile("mov %%cr2, %0" : "=r"(faulting_address));
|
||||
|
||||
// Print an error message with the faulting address
|
||||
printf("Page fault at 0x%x, virtual address 0x%x\n", regs->eip,
|
||||
faulting_address);
|
||||
|
||||
// Additional actions can be taken as needed
|
||||
}
|
||||
|
||||
void general_protection_fault(struct idt_regs *regs)
|
||||
{
|
||||
printf("General protection fault occurred!\n");
|
||||
// Additional actions can be taken as needed
|
||||
}
|
||||
|
||||
void double_fault()
|
||||
{
|
||||
// Handle double fault exception
|
||||
}
|
||||
|
||||
// Interrupt handlers
|
||||
void system_call(struct idt_regs *regs)
|
||||
{
|
||||
// Get the system call number from the eax register
|
||||
uint32_t syscall_number = regs->eax;
|
||||
|
||||
// Handle different system call numbers
|
||||
switch (syscall_number)
|
||||
{
|
||||
case 1:
|
||||
// Handle open() system call
|
||||
// ...
|
||||
break;
|
||||
case 2:
|
||||
// Handle read() system call
|
||||
// ...
|
||||
break;
|
||||
case 3:
|
||||
// Handle write() system call
|
||||
// ...
|
||||
break;
|
||||
case 4:
|
||||
// Handle close() system call
|
||||
// ...
|
||||
break;
|
||||
// Add more cases for other system calls
|
||||
|
||||
default:
|
||||
// Unknown system call number
|
||||
printf("Unknown system call number: %d\n", syscall_number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void timer()
|
||||
{
|
||||
static int count = 0;
|
||||
printf ("timer expired %d times\n", ++count);
|
||||
}
|
||||
|
||||
void keyboard()
|
||||
{
|
||||
// Handle keyboard interrupt
|
||||
}
|
||||
|
||||
void device()
|
||||
{
|
||||
// Determine the type of device interrupt
|
||||
uint32_t interrupt_type = read_interrupt_type();
|
||||
|
||||
// Call the appropriate interrupt handler
|
||||
switch (interrupt_type)
|
||||
{
|
||||
case TIMER_INTERRUPT:
|
||||
timer();
|
||||
break;
|
||||
case KEYBOARD_INTERRUPT:
|
||||
keyboard();
|
||||
break;
|
||||
case NETWORK_INTERRUPT:
|
||||
network();
|
||||
break;
|
||||
case DISK_INTERRUPT:
|
||||
disk();
|
||||
break;
|
||||
case SERIAL_PORT_INTERRUPT:
|
||||
serial_port();
|
||||
break;
|
||||
// Add more cases for other types of device interrupts
|
||||
|
||||
default:
|
||||
// Unknown interrupt type
|
||||
printf("Unknown device interrupt type: %d\n", interrupt_type);
|
||||
break;
|
||||
}
|
||||
}
|
23
src/kernel/arch/x86/isr/exceptions.c
Normal file
23
src/kernel/arch/x86/isr/exceptions.c
Normal file
@ -0,0 +1,23 @@
|
||||
#include "exceptions.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
void DivideByZero()
|
||||
{
|
||||
printf("Divide By Zero Exception");
|
||||
}
|
||||
|
||||
void DoubleFault()
|
||||
{
|
||||
printf("Double Fault Exception");
|
||||
}
|
||||
|
||||
void PageFault()
|
||||
{
|
||||
printf("Page Fault Exception");
|
||||
}
|
||||
|
||||
void GeneralProtectionFault()
|
||||
{
|
||||
printf("General Protection Fault Exception");
|
||||
}
|
12
src/kernel/arch/x86/isr/exceptions.h
Normal file
12
src/kernel/arch/x86/isr/exceptions.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef EXCEPTIONS_H
|
||||
#define EXCEPTIONS_H
|
||||
|
||||
void DivideByZero();
|
||||
|
||||
void DoubleFault();
|
||||
|
||||
void PageFault();
|
||||
|
||||
void GeneralProtectionFault();
|
||||
|
||||
#endif
|
11
src/kernel/arch/x86/isr/isr.asm
Normal file
11
src/kernel/arch/x86/isr/isr.asm
Normal file
@ -0,0 +1,11 @@
|
||||
global isr_handler
|
||||
global _isr_stub
|
||||
|
||||
_isr_stub:
|
||||
PUSH DWORD [ESP + 8]
|
||||
PUSH DWORD [ESP + 8]
|
||||
|
||||
CALL isr_handler
|
||||
|
||||
ADD ESP, 8
|
||||
IRETD
|
1
src/kernel/arch/x86/isr/isr.c
Normal file
1
src/kernel/arch/x86/isr/isr.c
Normal file
@ -0,0 +1 @@
|
||||
#include "isr.h"
|
@ -1,9 +1,26 @@
|
||||
#ifndef ISR_H
|
||||
#define ISR_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../include/types.h"
|
||||
|
||||
extern void (*isr_table[256])(struct isr_regs *regs);
|
||||
enum ISR_Vector : uint32_t
|
||||
{
|
||||
EXCEPTION_START = 0x00,
|
||||
DIVIDE_BY_ZERO_INTERRUPT = 0x00,
|
||||
DOUBLE_FAULT_INTERRUPT = 0x08,
|
||||
PAGE_FAULT_INTERRUPT = 0x0E,
|
||||
GENERAL_PROTECTION_FAULT_INTERRUPT = 0x0D,
|
||||
EXCEPTION_END = 0x1F,
|
||||
HARDWARE_START = 0x20,
|
||||
TIMER_INTERRUPT = 0x20,
|
||||
KEYBOARD_INTERRUPT = 0x21,
|
||||
NETWORK_INTERRUPT = 0x22,
|
||||
DISK_INTERRUPT = 0x23,
|
||||
SERIAL_PORT_INTERRUPT = 0x24,
|
||||
HARDWARE_END = 0x2F,
|
||||
USER_DEFINED_START = 0x30,
|
||||
SYSTEM_CALL_INTERRUPT = 0x80
|
||||
};
|
||||
|
||||
struct isr_regs
|
||||
{
|
||||
@ -28,7 +45,4 @@ struct idt_regs
|
||||
ss; // Pushed by the processor automatically
|
||||
};
|
||||
|
||||
// ISR handler
|
||||
void isr_handler(struct idt_regs *regs);
|
||||
|
||||
#endif /* ISR_H */
|
@ -404,29 +404,3 @@ bool CPU::HasADX()
|
||||
{
|
||||
return GetExtFeatureBits_1() & 0b00000000000010000000000000000000;
|
||||
}
|
||||
|
||||
/*
|
||||
Str_8 CPU::ToStr()
|
||||
{
|
||||
return "Manufacturer: " + GetManufacturer() + "\r\n" +
|
||||
"Brand: " + GetBrand() + "\r\n" +
|
||||
"Stepping Id: " + Str_8::FromNum(GetSteppingId()) + "\r\n" +
|
||||
"GpuModel Id: " + Str_8::FromNum(GetModelId()) + "\r\n" +
|
||||
"Family Id: " + Str_8::FromNum(GetFamilyId()) + "\r\n" +
|
||||
"Processor Type Id: " + Str_8::FromNum(GetProcessorTypeId()) + "\r\n" +
|
||||
"Extended GpuModel Id: " + Str_8::FromNum(GetExtModelId()) + "\r\n" +
|
||||
"Extended Family Id: " + Str_8::FromNum(GetExtFamilyId()) + "\r\n" +
|
||||
"Has FPU: " + Str_8::FromNum((UInt_8)HasFPU()) + "\r\n" +
|
||||
"Has SSE: " + Str_8::FromNum((UInt_8)HasSSE()) + "\r\n" +
|
||||
"Has SSE 2: " + Str_8::FromNum((UInt_8)HasSSE2()) + "\r\n" +
|
||||
"Has SSE 3: " + Str_8::FromNum((UInt_8)HasSSE3()) + "\r\n" +
|
||||
"Has SSSE 3: " + Str_8::FromNum((UInt_8)HasSSSE3()) + "\r\n" +
|
||||
"Has SSE 4.1: " + Str_8::FromNum((UInt_8)HasSSE4_1()) + "\r\n" +
|
||||
"Has SSE 4.2: " + Str_8::FromNum((UInt_8)HasSSE4_2()) + "\r\n" +
|
||||
"Has AVX: " + Str_8::FromNum((UInt_8)HasAVX()) + "\r\n" +
|
||||
"Has RDRND: " + Str_8::FromNum((UInt_8)HasRDRND()) + "\r\n" +
|
||||
"Has AVX 2: " + Str_8::FromNum((UInt_8)HasAVX2()) + "\r\n" +
|
||||
"Has ADX: " + Str_8::FromNum((UInt_8)HasADX()) + "\r\n" +
|
||||
"Has RDSEED: " + Str_8::FromNum((UInt_8)HasRDSEED());
|
||||
}
|
||||
*/
|
@ -4,7 +4,7 @@
|
||||
#include "../Str.h"
|
||||
#include "../Array.h"
|
||||
|
||||
enum class Architecture : UInt_8
|
||||
enum Architecture : UInt_8
|
||||
{
|
||||
X64,
|
||||
X86,
|
||||
@ -13,7 +13,7 @@ enum class Architecture : UInt_8
|
||||
UNKNOWN
|
||||
};
|
||||
|
||||
enum class Endianness : UInt_8
|
||||
enum Endianness : UInt_8
|
||||
{
|
||||
LE,
|
||||
BE
|
||||
@ -21,9 +21,9 @@ enum class Endianness : UInt_8
|
||||
|
||||
struct TSC
|
||||
{
|
||||
UInt_32 coreId = 0;
|
||||
UInt_32 highCount = 0;
|
||||
UInt_32 lowCount = 0;
|
||||
UInt_32 coreId;
|
||||
UInt_32 highCount;
|
||||
UInt_32 lowCount;
|
||||
};
|
||||
|
||||
class CPU
|
||||
|
@ -1,22 +1,22 @@
|
||||
global _ZN3lwe3CPU6RDTSCPEPNS_3TSCE
|
||||
global _ZN3lwe3CPU15GetManufacturerEPc
|
||||
global _ZN3lwe3CPU11GetInfoBitsEv
|
||||
global _ZN3lwe3CPU16GetFeatureBits_1Ev
|
||||
global _ZN3lwe3CPU16GetFeatureBits_2Ev
|
||||
global _ZN3lwe3CPU19GetExtFeatureBits_1Ev
|
||||
global _ZN3lwe3CPU19GetExtFeatureBits_2Ev
|
||||
global _ZN3lwe3CPU19GetExtFeatureBits_3Ev
|
||||
global _ZN3lwe3CPU8GetBrandEPc
|
||||
global _ZN3CPU6RDTSCPEPNS_3TSCE
|
||||
global _ZN3CPU15GetManufacturerEPc
|
||||
global _ZN3CPU11GetInfoBitsEv
|
||||
global _ZN3CPU16GetFeatureBits_1Ev
|
||||
global _ZN3CPU16GetFeatureBits_2Ev
|
||||
global _ZN3CPU19GetExtFeatureBits_1Ev
|
||||
global _ZN3CPU19GetExtFeatureBits_2Ev
|
||||
global _ZN3CPU19GetExtFeatureBits_3Ev
|
||||
global _ZN3CPU8GetBrandEPc
|
||||
|
||||
section .text
|
||||
_ZN3lwe3CPU6RDTSCPEPNS_3TSCE:
|
||||
_ZN3CPU6RDTSCPEPNS_3TSCE:
|
||||
RDTSCP
|
||||
MOV DWORD [RDI], ECX
|
||||
MOV DWORD [RDI + 4], EDX
|
||||
MOV DWORD [RDI + 8], EAX
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU15GetManufacturerEPc:
|
||||
_ZN3CPU15GetManufacturerEPc:
|
||||
PUSH RBX
|
||||
|
||||
XOR EAX, EAX
|
||||
@ -30,7 +30,7 @@ section .text
|
||||
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU11GetInfoBitsEv:
|
||||
_ZN3CPU11GetInfoBitsEv:
|
||||
PUSH RBX
|
||||
|
||||
MOV EAX, 1
|
||||
@ -40,7 +40,7 @@ section .text
|
||||
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU16GetFeatureBits_1Ev:
|
||||
_ZN3CPU16GetFeatureBits_1Ev:
|
||||
PUSH RBX
|
||||
|
||||
MOV EAX, 1
|
||||
@ -52,7 +52,7 @@ section .text
|
||||
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU16GetFeatureBits_2Ev:
|
||||
_ZN3CPU16GetFeatureBits_2Ev:
|
||||
PUSH RBX
|
||||
|
||||
MOV EAX, 1
|
||||
@ -64,7 +64,7 @@ section .text
|
||||
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU19GetExtFeatureBits_1Ev:
|
||||
_ZN3CPU19GetExtFeatureBits_1Ev:
|
||||
PUSH RBX
|
||||
|
||||
MOV EAX, 7
|
||||
@ -77,7 +77,7 @@ section .text
|
||||
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU19GetExtFeatureBits_2Ev:
|
||||
_ZN3CPU19GetExtFeatureBits_2Ev:
|
||||
PUSH RBX
|
||||
|
||||
MOV EAX, 7
|
||||
@ -90,7 +90,7 @@ section .text
|
||||
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU19GetExtFeatureBits_3Ev:
|
||||
_ZN3CPU19GetExtFeatureBits_3Ev:
|
||||
PUSH RBX
|
||||
|
||||
MOV EAX, 7
|
||||
@ -103,7 +103,7 @@ section .text
|
||||
|
||||
RET
|
||||
|
||||
_ZN3lwe3CPU8GetBrandEPc:
|
||||
_ZN3CPU8GetBrandEPc:
|
||||
PUSH RBX
|
||||
|
||||
MOV EAX, 80000002h
|
||||
|
Loading…
Reference in New Issue
Block a user