From 07c0c99a487396f48252cbc25f77cfcff455ae2e Mon Sep 17 00:00:00 2001 From: karutoh Date: Tue, 31 Oct 2023 04:32:41 -0700 Subject: [PATCH] Fixed a lot of errors, and redesigned most of the ISR and IDTs. --- .clang-format | 29 ---- CMakeLists.txt | 9 +- src/Math.cpp | 2 +- src/Math.h | 2 +- src/Math_GCC_AMD64.s | 48 +++---- src/drivers/io/io.asm | 13 ++ src/drivers/io/io.h | 6 +- src/drivers/keyboard/keyboard.c | 13 +- src/drivers/keyboard/keyboard.h | 2 + src/kernel/arch/x86/gdt.c | 32 +---- src/kernel/arch/x86/idt.asm | 5 + src/kernel/arch/x86/idt.c | 76 ++--------- src/kernel/arch/x86/idt.h | 25 +--- src/kernel/arch/x86/interrupt_utils.h | 8 -- src/kernel/arch/x86/isr.c | 190 -------------------------- src/kernel/arch/x86/isr/exceptions.c | 23 ++++ src/kernel/arch/x86/isr/exceptions.h | 12 ++ src/kernel/arch/x86/isr/isr.asm | 11 ++ src/kernel/arch/x86/isr/isr.c | 1 + src/kernel/arch/x86/{ => isr}/isr.h | 24 +++- src/sys/CPU.cpp | 28 +--- src/sys/CPU.h | 10 +- src/sys/CPU_GCC_AMD64.asm | 36 ++--- 23 files changed, 168 insertions(+), 437 deletions(-) delete mode 100644 .clang-format create mode 100644 src/drivers/io/io.asm create mode 100644 src/kernel/arch/x86/idt.asm delete mode 100644 src/kernel/arch/x86/interrupt_utils.h delete mode 100644 src/kernel/arch/x86/isr.c create mode 100644 src/kernel/arch/x86/isr/exceptions.c create mode 100644 src/kernel/arch/x86/isr/exceptions.h create mode 100644 src/kernel/arch/x86/isr/isr.asm create mode 100644 src/kernel/arch/x86/isr/isr.c rename src/kernel/arch/x86/{ => isr}/isr.h (57%) diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 160f7c1..0000000 --- a/.clang-format +++ /dev/null @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f13f29..56a3195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/src/Math.cpp b/src/Math.cpp index bc46d12..7f5b911 100644 --- a/src/Math.cpp +++ b/src/Math.cpp @@ -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()) diff --git a/src/Math.h b/src/Math.h index d294ee3..bef7ef7 100644 --- a/src/Math.h +++ b/src/Math.h @@ -1,6 +1,6 @@ #pragma once -#include "sys/cpu.h" +#include "sys/CPU.h" #define LOW_WORD(x) *((int*)&x) + 1 diff --git a/src/Math_GCC_AMD64.s b/src/Math_GCC_AMD64.s index b08777f..625ca66 100644 --- a/src/Math_GCC_AMD64.s +++ b/src/Math_GCC_AMD64.s @@ -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 \ No newline at end of file diff --git a/src/drivers/io/io.asm b/src/drivers/io/io.asm new file mode 100644 index 0000000..92bae92 --- /dev/null +++ b/src/drivers/io/io.asm @@ -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 \ No newline at end of file diff --git a/src/drivers/io/io.h b/src/drivers/io/io.h index 000407c..09bd4bc 100644 --- a/src/drivers/io/io.h +++ b/src/drivers/io/io.h @@ -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 */ \ No newline at end of file diff --git a/src/drivers/keyboard/keyboard.c b/src/drivers/keyboard/keyboard.c index 39fde6a..f7191fd 100644 --- a/src/drivers/keyboard/keyboard.c +++ b/src/drivers/keyboard/keyboard.c @@ -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 diff --git a/src/drivers/keyboard/keyboard.h b/src/drivers/keyboard/keyboard.h index ab08abd..17e9309 100644 --- a/src/drivers/keyboard/keyboard.h +++ b/src/drivers/keyboard/keyboard.h @@ -4,6 +4,8 @@ #include #include +void KeyboardInterruptHandler(); + void keyboard_init(); bool keyboard_buffer_empty(); uint8_t keyboard_read_scancode(); diff --git a/src/kernel/arch/x86/gdt.c b/src/kernel/arch/x86/gdt.c index bf04da6..752592f 100644 --- a/src/kernel/arch/x86/gdt.c +++ b/src/kernel/arch/x86/gdt.c @@ -1,6 +1,6 @@ #include "gdt.h" #include "idt.h" -#include "isr.h" +#include "isr/isr.h" #include #include #include @@ -89,32 +89,4 @@ extern void double_fault(); 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); -} +extern void device(); \ No newline at end of file diff --git a/src/kernel/arch/x86/idt.asm b/src/kernel/arch/x86/idt.asm new file mode 100644 index 0000000..70c6361 --- /dev/null +++ b/src/kernel/arch/x86/idt.asm @@ -0,0 +1,5 @@ +global LoadIDT + +LoadIDT: + LIDT [ESP + 32] + RET \ No newline at end of file diff --git a/src/kernel/arch/x86/idt.c b/src/kernel/arch/x86/idt.c index b6af69e..a93854d 100644 --- a/src/kernel/arch/x86/idt.c +++ b/src/kernel/arch/x86/idt.c @@ -1,75 +1,19 @@ #include "idt.h" -#include "isr.h" -#include -#include -#include -#include -#include -#include +#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]); } \ No newline at end of file diff --git a/src/kernel/arch/x86/idt.h b/src/kernel/arch/x86/idt.h index 5abc491..feb83c4 100644 --- a/src/kernel/arch/x86/idt.h +++ b/src/kernel/arch/x86/idt.h @@ -1,8 +1,8 @@ #ifndef IDT_H #define IDT_H -#include -#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 */ \ No newline at end of file diff --git a/src/kernel/arch/x86/interrupt_utils.h b/src/kernel/arch/x86/interrupt_utils.h deleted file mode 100644 index 0a46a52..0000000 --- a/src/kernel/arch/x86/interrupt_utils.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef INTERRUPT_UTILS_H -#define INTERRUPT_UTILS_H - -#include - -uint32_t read_interrupt_type(void); - -#endif /* INTERRUPT_UTILS_H */ diff --git a/src/kernel/arch/x86/isr.c b/src/kernel/arch/x86/isr.c deleted file mode 100644 index 482ad76..0000000 --- a/src/kernel/arch/x86/isr.c +++ /dev/null @@ -1,190 +0,0 @@ -#include "isr.h" -#include "idt.h" -#include -#include -#include -#include -#include - -#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; - } -} diff --git a/src/kernel/arch/x86/isr/exceptions.c b/src/kernel/arch/x86/isr/exceptions.c new file mode 100644 index 0000000..2cde176 --- /dev/null +++ b/src/kernel/arch/x86/isr/exceptions.c @@ -0,0 +1,23 @@ +#include "exceptions.h" + +#include + +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"); +} \ No newline at end of file diff --git a/src/kernel/arch/x86/isr/exceptions.h b/src/kernel/arch/x86/isr/exceptions.h new file mode 100644 index 0000000..83ead4f --- /dev/null +++ b/src/kernel/arch/x86/isr/exceptions.h @@ -0,0 +1,12 @@ +#ifndef EXCEPTIONS_H +#define EXCEPTIONS_H + +void DivideByZero(); + +void DoubleFault(); + +void PageFault(); + +void GeneralProtectionFault(); + +#endif diff --git a/src/kernel/arch/x86/isr/isr.asm b/src/kernel/arch/x86/isr/isr.asm new file mode 100644 index 0000000..bdfeacc --- /dev/null +++ b/src/kernel/arch/x86/isr/isr.asm @@ -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 \ No newline at end of file diff --git a/src/kernel/arch/x86/isr/isr.c b/src/kernel/arch/x86/isr/isr.c new file mode 100644 index 0000000..ecb5624 --- /dev/null +++ b/src/kernel/arch/x86/isr/isr.c @@ -0,0 +1 @@ +#include "isr.h" diff --git a/src/kernel/arch/x86/isr.h b/src/kernel/arch/x86/isr/isr.h similarity index 57% rename from src/kernel/arch/x86/isr.h rename to src/kernel/arch/x86/isr/isr.h index b6223fa..987c0f0 100644 --- a/src/kernel/arch/x86/isr.h +++ b/src/kernel/arch/x86/isr/isr.h @@ -1,9 +1,26 @@ #ifndef ISR_H #define ISR_H -#include +#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 */ \ No newline at end of file diff --git a/src/sys/CPU.cpp b/src/sys/CPU.cpp index 8f0f9b4..b6dae76 100644 --- a/src/sys/CPU.cpp +++ b/src/sys/CPU.cpp @@ -403,30 +403,4 @@ bool CPU::HasRDSEED() 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()); -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/sys/CPU.h b/src/sys/CPU.h index 03577e8..4b749c3 100644 --- a/src/sys/CPU.h +++ b/src/sys/CPU.h @@ -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 diff --git a/src/sys/CPU_GCC_AMD64.asm b/src/sys/CPU_GCC_AMD64.asm index 98a5cc0..e6224d2 100644 --- a/src/sys/CPU_GCC_AMD64.asm +++ b/src/sys/CPU_GCC_AMD64.asm @@ -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