-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
238 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"configurations": [ | ||
{ | ||
"name": "Mac", | ||
"includePath": ["${workspaceFolder}/**"], | ||
"defines": [], | ||
"compilerPath": "/opt/homebrew/bin/i686-elf-gcc", | ||
"compilerArgs": [ | ||
"-ffreestanding", | ||
"-nostdlib", | ||
"-nostartfiles", | ||
"-nodefaultlibs", | ||
"-Iinc" | ||
], | ||
"cStandard": "gnu99", | ||
"intelliSenseMode": "macos-gcc-x86", | ||
"configurationProvider": "ms-vscode.makefile-tools", | ||
"browse": { | ||
"path": ["${workspaceFolder}"], | ||
"limitSymbolsToIncludedHeaders": true | ||
} | ||
} | ||
], | ||
"version": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef CONFIG_H | ||
#define CONFIG_H | ||
|
||
#define KERNEL_CODE_SELECTOR 0x08 | ||
#define KERNEL_DATA_SELECTOR 0x10 | ||
|
||
#define TOTAL_INTERRUPTS 512 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
section .asm | ||
|
||
global idt_load | ||
|
||
idt_load: | ||
push ebp | ||
mov ebp, esp | ||
|
||
mov ebx, [ebp+8] ; first argument passed to this function | ||
lidt [edx] | ||
|
||
pop ebp | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "idt.h" | ||
#include "config.h" | ||
#include "kernel.h" | ||
#include "memory/memory.h" | ||
|
||
struct idt_desc idt_descriptors[TOTAL_INTERRUPTS]; | ||
struct idtr_desc idtr_descriptor; | ||
|
||
extern void idt_load(struct idtr_desc *ptr); | ||
|
||
void idt_zero() | ||
{ | ||
print("Divide by zero error\n"); | ||
} | ||
|
||
void idt_set(int interrupt_number, void *address) | ||
{ | ||
struct idt_desc *desc = &idt_descriptors[interrupt_number]; | ||
|
||
desc->offset_1 = (uint32_t)address & 0xffff; | ||
desc->selector = KERNEL_CODE_SELECTOR; | ||
desc->zero = 0x00; | ||
// Type: 0x0e/0b1110 = 32-bit interrupt gate | ||
// Attribute: Storage Segment = 0 (interrupt) | ||
// DPL (Descriptor Privilege Level) = 0b11 or 3 (Ring 3) | ||
// Present = 1 (0 for unused interrupt) | ||
desc->type_attr = 0x0e | 0xe0; | ||
desc->offset_2 = (uint32_t)address >> 16; | ||
} | ||
|
||
void idt_init() | ||
{ | ||
memset(idt_descriptors, 0, sizeof(idt_descriptors)); | ||
idtr_descriptor.limit = sizeof(idt_descriptors) - 1; | ||
idtr_descriptor.base = (uint32_t)idt_descriptors; | ||
|
||
idt_set(0, idt_zero); | ||
|
||
// Load the IDT | ||
idt_load(&idtr_descriptor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef IDT_H | ||
#define IDT_H | ||
|
||
#include <stdint.h> | ||
|
||
struct idt_desc | ||
{ | ||
uint16_t offset_1; // offset bits 0..15 | ||
uint16_t selector; // a code segment selector in GDT or LDT | ||
uint8_t zero; // unused bits, set to 0 | ||
uint8_t type_attr; // type and attributes | ||
uint16_t offset_2; // offset bits 16..31 | ||
} __attribute__((packed)); // ensures there's no unexpected padding | ||
|
||
struct idtr_desc | ||
{ | ||
uint16_t limit; // The length of the Interrupt Descriptor Table minus one | ||
uint32_t base; // The address of the Interrupt Descriptor Table | ||
} __attribute__((packed)); | ||
|
||
void idt_init(); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.