...
This commit is contained in:
@@ -43,13 +43,15 @@ static const char* exception_messages[32] = {
|
||||
|
||||
static irq_handler_t irq_handlers[16] = {0};
|
||||
|
||||
bool cpu_has_apic() {
|
||||
bool cpu_has_apic()
|
||||
{
|
||||
uint32_t eax, edx;
|
||||
cpuid(1, &eax, &edx);
|
||||
return (edx & CPUID_FEAT_EDX_APIC) != 0;
|
||||
}
|
||||
|
||||
void enable_apic() {
|
||||
void enable_apic()
|
||||
{
|
||||
uint64_t apic_base = rdmsr(0x1B);
|
||||
apic_base |= (1 << 11);
|
||||
wrmsr(0x1B, apic_base);
|
||||
@@ -75,7 +77,8 @@ void remap_pic()
|
||||
kprintf("PIC remapped\n");
|
||||
}
|
||||
|
||||
void disable_pic() {
|
||||
void disable_pic()
|
||||
{
|
||||
outb(PIC1_DATA, 0xFF);
|
||||
outb(PIC2_DATA, 0xFF);
|
||||
kprintf("PIC disabled\n");
|
||||
@@ -83,7 +86,8 @@ void disable_pic() {
|
||||
|
||||
void handle_exception(const isr_frame_t* frame)
|
||||
{
|
||||
kprintf("exception[%d]: %s, error code: %d\n", frame->int_no, exception_messages[frame->int_no], frame->err_code);
|
||||
kprintf("exception[%d]: %s, error code: %d\n", frame->int_no, exception_messages[frame->int_no],
|
||||
frame->err_code);
|
||||
kpanic();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "kernel.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "kernel.h"
|
||||
#include "interrupts.h"
|
||||
#include "keyboard.h"
|
||||
#include "multiboot.h"
|
||||
#include "string.h"
|
||||
#include "vga.h"
|
||||
#include <stdarg.h>
|
||||
#include "multiboot.h"
|
||||
|
||||
void handle_keypress(const keyboard_event_t* event)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ static inline void khalt()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
__asm__ volatile ("hlt");
|
||||
__asm__ volatile("hlt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "keyboard.h"
|
||||
#include "interrupts.h"
|
||||
#include "kernel.h"
|
||||
#include "vga.h"
|
||||
#include "util.h"
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int strcmp(const char* a, const char* b);
|
||||
void reverse(char* str, size_t length);
|
||||
|
||||
12
src/util.h
12
src/util.h
@@ -2,7 +2,8 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum {
|
||||
enum
|
||||
{
|
||||
CPUID_FEAT_ECX_SSE3 = 1 << 0,
|
||||
CPUID_FEAT_ECX_PCLMUL = 1 << 1,
|
||||
CPUID_FEAT_ECX_DTES64 = 1 << 2,
|
||||
@@ -84,17 +85,20 @@ static inline void io_wait()
|
||||
outb(0x80, 0);
|
||||
}
|
||||
|
||||
static inline void cpuid(uint32_t code, uint32_t* a, uint32_t* d) {
|
||||
static inline void cpuid(uint32_t code, uint32_t* a, uint32_t* d)
|
||||
{
|
||||
__asm__ volatile("cpuid" : "=a"(*a), "=d"(*d) : "a"(code) : "ecx", "ebx");
|
||||
}
|
||||
|
||||
static inline uint64_t rdmsr(uint32_t msr) {
|
||||
static inline uint64_t rdmsr(uint32_t msr)
|
||||
{
|
||||
uint32_t lo, hi;
|
||||
__asm__ volatile("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr));
|
||||
return ((uint64_t)hi << 32) | lo;
|
||||
}
|
||||
|
||||
static inline void wrmsr(uint32_t msr, uint64_t value) {
|
||||
static inline void wrmsr(uint32_t msr, uint64_t value)
|
||||
{
|
||||
uint32_t lo = (uint32_t)value;
|
||||
uint32_t hi = (uint32_t)(value >> 32);
|
||||
__asm__ volatile("wrmsr" : : "c"(msr), "a"(lo), "d"(hi));
|
||||
|
||||
Reference in New Issue
Block a user