i need a break
This commit is contained in:
@ -23,6 +23,6 @@ loader:
|
|||||||
|
|
||||||
call kmain
|
call kmain
|
||||||
|
|
||||||
cli
|
;cli
|
||||||
loop: hlt
|
loop: hlt
|
||||||
jmp loop
|
jmp loop
|
||||||
|
@ -26,6 +26,14 @@ uint64_t create_descriptor(uint32_t base, uint32_t limit, uint16_t flag)
|
|||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void dump_gdt(void)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < GDT_SIZE; i++) {
|
||||||
|
printf("GDT_ENTRY %d: %4 | %2\n", i, gdt[i], gdt[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void gdt_init(void)
|
void gdt_init(void)
|
||||||
{
|
{
|
||||||
#ifdef __TESTING__
|
#ifdef __TESTING__
|
||||||
@ -45,9 +53,4 @@ void gdt_init(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void dump_gdt(void)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < GDT_SIZE; i++) {
|
|
||||||
printf("GDT_ENTRY %d: %1 | %2\n", i, gdt[i], gdt[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
#ifdef __TESTING__
|
#ifdef __TESTING__
|
||||||
#include <kernel/_kernel.h>
|
#include <kernel/_kernel.h>
|
||||||
|
#include <stdio.h>
|
||||||
#endif
|
#endif
|
||||||
#include <kernel/x86/idt.h>
|
#include <kernel/x86/idt.h>
|
||||||
|
#include <kernel/x86/pic.h>
|
||||||
|
|
||||||
__attribute__((aligned(0x10)))
|
__attribute__((aligned(0x10)))
|
||||||
static idt_entry_t idt[256];
|
static idt_entry_t idt[256];
|
||||||
@ -12,8 +14,12 @@ static idtr_t idtr;
|
|||||||
|
|
||||||
static bool vectors[IDT_MAX_DESCRIPTORS];
|
static bool vectors[IDT_MAX_DESCRIPTORS];
|
||||||
|
|
||||||
void exception_handler()
|
void exception_handler(unsigned int i)
|
||||||
{
|
{
|
||||||
|
#ifdef __TESTING__
|
||||||
|
kerror("EXCEPTION");
|
||||||
|
printf("Exeption: %u\n", i);
|
||||||
|
#endif
|
||||||
__asm__ volatile ("cli; hlt"); // hangs the computer
|
__asm__ volatile ("cli; hlt"); // hangs the computer
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,7 +34,6 @@ void idt_set_descriptor(uint8_t vector, void *isr, uint8_t flags)
|
|||||||
descriptor->reserved = 0;
|
descriptor->reserved = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern void* isr_stub_table[];
|
extern void* isr_stub_table[];
|
||||||
void idt_init(void)
|
void idt_init(void)
|
||||||
{
|
{
|
||||||
@ -38,16 +43,19 @@ void idt_init(void)
|
|||||||
idtr.base = (uintptr_t)&idt[0];
|
idtr.base = (uintptr_t)&idt[0];
|
||||||
idtr.limit = (uint16_t) sizeof(idt_entry_t) * IDT_MAX_DESCRIPTORS - 1;
|
idtr.limit = (uint16_t) sizeof(idt_entry_t) * IDT_MAX_DESCRIPTORS - 1;
|
||||||
|
|
||||||
for (uint8_t vector = 0; vector < 32; vector++) {
|
for (uint8_t vector = 0; vector < IDT_MAX_DESCRIPTORS; vector++) {
|
||||||
idt_set_descriptor(vector, isr_stub_table[vector], 0x8E);
|
idt_set_descriptor(vector, isr_stub_table[vector], 0x8E);
|
||||||
vectors[vector] = true;
|
vectors[vector] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The "m" indicates actual data, not a pointer
|
// The "m" indicates actual data, not a pointer
|
||||||
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
|
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
|
||||||
|
|
||||||
|
PIC_remap(0x20, 0x28);
|
||||||
|
IRQ_set_mask(0xfd); // unmask IRQ1
|
||||||
|
|
||||||
__asm__ volatile("sti"); // set the interrupt flag
|
__asm__ volatile("sti"); // set the interrupt flag
|
||||||
#ifdef __TESTING__
|
#ifdef __TESTING__
|
||||||
kinfo("Initialized the IDT");
|
kinfo("Initialized the IDT");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,13 +2,19 @@ extern exception_handler
|
|||||||
|
|
||||||
%macro isr_err_stub 1
|
%macro isr_err_stub 1
|
||||||
isr_stub_%+%1:
|
isr_stub_%+%1:
|
||||||
|
pushad
|
||||||
|
push dword %1
|
||||||
call exception_handler
|
call exception_handler
|
||||||
|
popad
|
||||||
iret
|
iret
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
%macro isr_no_err_stub 1
|
%macro isr_no_err_stub 1
|
||||||
isr_stub_%+%1:
|
isr_stub_%+%1:
|
||||||
|
pushad
|
||||||
|
push dword %1
|
||||||
call exception_handler
|
call exception_handler
|
||||||
|
popad
|
||||||
iret
|
iret
|
||||||
%endmacro
|
%endmacro
|
||||||
|
|
||||||
@ -44,11 +50,28 @@ isr_no_err_stub 28
|
|||||||
isr_no_err_stub 29
|
isr_no_err_stub 29
|
||||||
isr_err_stub 30
|
isr_err_stub 30
|
||||||
isr_no_err_stub 31
|
isr_no_err_stub 31
|
||||||
|
isr_no_err_stub 32
|
||||||
|
isr_no_err_stub 33
|
||||||
|
isr_no_err_stub 34
|
||||||
|
isr_no_err_stub 35
|
||||||
|
isr_no_err_stub 36
|
||||||
|
isr_no_err_stub 37
|
||||||
|
isr_no_err_stub 38
|
||||||
|
isr_no_err_stub 39
|
||||||
|
isr_no_err_stub 40
|
||||||
|
isr_no_err_stub 41
|
||||||
|
isr_no_err_stub 42
|
||||||
|
isr_no_err_stub 43
|
||||||
|
isr_no_err_stub 44
|
||||||
|
isr_no_err_stub 45
|
||||||
|
isr_no_err_stub 46
|
||||||
|
isr_no_err_stub 47
|
||||||
|
|
||||||
|
|
||||||
global isr_stub_table
|
global isr_stub_table
|
||||||
isr_stub_table:
|
isr_stub_table:
|
||||||
%assign i 0
|
%assign i 0
|
||||||
%rep 32
|
%rep 48
|
||||||
dd isr_stub_%+i
|
dd isr_stub_%+i
|
||||||
%assign i i+1
|
%assign i i+1
|
||||||
%endrep
|
%endrep
|
||||||
|
@ -58,8 +58,6 @@ uint64_t create_descriptor(uint32_t base, uint32_t limit, uint16_t flag);
|
|||||||
|
|
||||||
void gdt_init(void);
|
void gdt_init(void);
|
||||||
|
|
||||||
void dump_gdt(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,9 +3,32 @@
|
|||||||
#ifndef ARCH_IDT_H
|
#ifndef ARCH_IDT_H
|
||||||
#define ARCH_IDT_H
|
#define ARCH_IDT_H
|
||||||
|
|
||||||
#define IDT_MAX_DESCRIPTORS 32 // number of entries in the idt table, 32 i believe
|
#define IDT_MAX_DESCRIPTORS 48 // number of entries in the idt table
|
||||||
|
|
||||||
void exception_handler(void);
|
|
||||||
|
#define EXCEPT_DIV_ERR 0
|
||||||
|
#define EXCEPT_DEBUG 1
|
||||||
|
#define EXCEPT_NMI 2
|
||||||
|
#define EXCEPT_BREAKPOINT 3
|
||||||
|
#define EXCEPT_OVERFLOW 4
|
||||||
|
#define EXCEPT_BOUND_RANGE_EXCEEDED 5
|
||||||
|
#define EXCEPT_INVALID_OPCODE 6
|
||||||
|
#define EXCEPT_DEVICE_NOT_AVAILABLE 7
|
||||||
|
#define EXCEPT_DOUBLE_FAULT 8
|
||||||
|
#define EXCEPT_SEG_OVERRUN 9
|
||||||
|
#define EXCEPT_INVALID_TSS 10
|
||||||
|
#define EXCEPT_SEG_NOT_PRESENT 11
|
||||||
|
#define EXCEPT_STACK_SEG_FAULT 12
|
||||||
|
#define EXCEPT_GENERAL_PROTECTION 13
|
||||||
|
#define EXCEPT_PAGE_FAULT 14
|
||||||
|
#define EXCEPT_FLOATING_POINT_ERR_FPU 16
|
||||||
|
#define EXCEPT_ALIGNMENT_CHECK 17
|
||||||
|
#define EXCEPT_MACHINE_CHECK 18
|
||||||
|
#define EXCEPT_FLOATING_POINT_ERR_SIMD 19
|
||||||
|
#define EXCEPT_VIRT 20
|
||||||
|
#define EXCEPT_CTRL_PROT 21
|
||||||
|
|
||||||
|
void exception_handler(unsigned int i);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint16_t isr_low; // The lower 16 bits of the ISR's address
|
uint16_t isr_low; // The lower 16 bits of the ISR's address
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
#include <kernel/serial.h>
|
#include <kernel/serial.h>
|
||||||
#include <kernel/x86/gdt.h>
|
#include <kernel/x86/gdt.h>
|
||||||
#include <kernel/x86/idt.h>
|
#include <kernel/x86/idt.h>
|
||||||
#include <kernel/x86/pic.h>
|
#include <kernel/x86/io.h>
|
||||||
|
|
||||||
void kmain(void)
|
void kmain(void)
|
||||||
{
|
{
|
||||||
@ -16,18 +16,10 @@ void kmain(void)
|
|||||||
#endif
|
#endif
|
||||||
gdt_init();
|
gdt_init();
|
||||||
idt_init();
|
idt_init();
|
||||||
PIC_remap(0x20, 0x28);
|
|
||||||
|
|
||||||
#ifndef __TESTING__
|
#ifndef __TESTING__
|
||||||
terminal_initialize();
|
terminal_initialize();
|
||||||
serial_initialize();
|
serial_initialize();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t a = 2;
|
|
||||||
uint16_t b = 3;
|
|
||||||
int c = 4;
|
|
||||||
|
|
||||||
uint64_t d = 10;
|
|
||||||
|
|
||||||
printf("%d, %d, %d, %3", a, b, c, d);
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user